From ce9d80db7c9e094349fc04277487693da61ab08e Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 23 Feb 2024 21:19:48 -0800 Subject: [PATCH 1/6] Use proper compiler --- Makefile | 7 ++- yamls/us/main.yaml | 138 ++++++++++++++++++++++----------------------- 2 files changed, 73 insertions(+), 72 deletions(-) diff --git a/Makefile b/Makefile index 097bde8..6fdf41e 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,8 @@ ifeq ($(NON_MATCHING),1) endif CPPFLAGS += -fno-dollars-in-identifiers -P -LDFLAGS := --no-check-sections --accept-unknown-input-arch --emit-relocs +# TODO: Remove muldefs when all of libultra matches +LDFLAGS := --no-check-sections --accept-unknown-input-arch --emit-relocs -z muldefs ifeq ($(DETECTED_OS), macos) CPPFLAGS += -xc++ @@ -254,7 +255,7 @@ setup: $(MAKE) -C tools lib: - $(MAKE) -C lib/ultralib VERSION=$(ULTRALIB_VERSION) TARGET=$(ULTRALIB_TARGET) COMPARE=0 CROSS=$(CROSS) CC=../../$(CC) + $(MAKE) -C lib/ultralib VERSION=$(ULTRALIB_VERSION) TARGET=$(ULTRALIB_TARGET) COMPARE=0 CROSS=$(CROSS) CC=../../$(CC_OLD) extract: $(RM) -r asm/$(VERSION) assets/$(VERSION) @@ -296,7 +297,7 @@ $(ROM): $(ELF) $(ELF): $(O_FILES) $(LIBULTRA_LIB) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld $(LD) $(LDFLAGS) -T $(LDSCRIPT) \ -T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld \ - -Map $(MAP) $(LIBULTRA_LIB) -o $@ + -Map $(MAP) --whole-archive $(LIBULTRA_LIB) -o $@ $(LDSCRIPT): linker_scripts/$(VERSION)/yoshisstory.ld cp $< $@ diff --git a/yamls/us/main.yaml b/yamls/us/main.yaml index e4aecc2..f08156e 100644 --- a/yamls/us/main.yaml +++ b/yamls/us/main.yaml @@ -108,27 +108,27 @@ - [0x830B0, lib, libultra, recvmesg] - [0x831F0, lib, libultra, setintmask] - [0x83290, lib, libultra, scale] - - [0x83330, asm, ../lib/ultralib/src/gu/sinf] # - [0x83330, lib, libultra, sinf] - - [0x834F0, asm, ../lib/ultralib/src/gu/sins] # - [0x834F0, lib, libultra, sins] - - [0x83560, asm, ../lib/ultralib/src/io/sptask] # - [0x83560, lib, libultra, sptask] + - [0x83330, lib, libultra, sinf] + - [0x834F0, lib, libultra, sins] + - [0x83560, asm, ../lib/ultralib/src/io/sptask] # [0x83560, lib, libultra, sptask] - [0x83820, lib, libultra, ll] - - [0x83AE0, asm, ../lib/ultralib/src/gu/us2dex_emu] # - [0x83AE0, lib, libultra, us2dex_emu] + - [0x83AE0, asm, ../lib/ultralib/src/gu/us2dex_emu] # [0x83AE0, lib, libultra, us2dex_emu] - [0x849D0, lib, libultra, exceptasm] - [0x852E0, lib, libultra, thread] - - [0x85320, asm, ../lib/ultralib/src/os/destroythread] # - [0x85320, lib, libultra, destroythread] + - [0x85320, asm, ../lib/ultralib/src/os/destroythread] # [0x85320, lib, libultra, destroythread] - [0x85420, lib, libultra, bzero] - [0x854C0, lib, libultra, leointerrupt] - - [0x85D40, asm, ../lib/ultralib/src/io/controller] # - [0x85D40, lib, libultra, controller] + - [0x85D40, asm, ../lib/ultralib/src/io/controller] # [0x85D40, lib, libultra, controller] - [0x86100, lib, libultra, siacs] - - [0x861C0, asm, ../lib/ultralib/src/io/conteepwrite] # - [0x861C0, lib, libultra, conteepwrite] + - [0x861C0, asm, ../lib/ultralib/src/io/conteepwrite] # [0x861C0, lib, libultra, conteepwrite] - [0x86710, lib, libultra, createthread] - - [0x86860, asm, ../lib/ultralib/src/io/contreaddata] # - [0x86860, asm, ../lib/ultralib/src/io/contreaddata] + - [0x86860, lib, libultra, contreaddata] - [0x86A80, lib, libultra, driverominit] - [0x86B60, lib, libultra, virtualtophysical] - [0x86BE0, lib, libultra, writebackdcache] - - [0x86C60, asm, ../lib/ultralib/src/os/initialize] # - [0x86C60, lib, libultra, initialize] + - [0x86C60, lib, libultra, initialize] - [0x86EF0, lib, libultra, pirawread] - - [0x86F50, asm, ../lib/ultralib/src/os/parameters] # - [0x86F50, lib, libultra, parameters] + - [0x86F50, lib, libultra, parameters] - [0x86FB0, lib, libultra, setsr] - [0x86FC0, lib, libultra, getsr] - [0x86FD0, lib, libultra, perspective] @@ -138,15 +138,15 @@ - [0x87410, lib, libultra, sirawread] - [0x87460, lib, libultra, sptaskyield] - [0x87480, lib, libultra, getthreadid] - - [0x874A0, asm, ../lib/ultralib/src/io/pfsreadwritefile] # - [0x874A0, lib, libultra, pfsreadwritefile] - - [0x879A0, asm, ../lib/ultralib/src/gu/mtxutil] # - [0x879A0, lib, libultra, mtxutil] + - [0x874A0, asm, ../lib/ultralib/src/io/pfsreadwritefile] # [0x874A0, lib, libultra, pfsreadwritefile] + - [0x879A0, asm, ../lib/ultralib/src/gu/mtxutil] # [0x879A0, lib, libultra, mtxutil] - [0x87C10, lib, libultra, visetmode] - [0x87C80, lib, libultra, lookat] - - [0x87FB0, asm, ../lib/ultralib/src/io/motor] # - [0x87FB0, lib, libultra, motor] + - [0x87FB0, lib, libultra, motor] - [0x88750, lib, libultra, pfsallocatefile] - [0x88F00, lib, libultra, probetlb] - [0x88FC0, lib, libultra, getcount] - - [0x88FD0, asm, ../lib/ultralib/src/io/contpfs] # - [0x88FD0, lib, libultra, contpfs] + - [0x88FD0, lib, libultra, contpfs] - [0x89D30, lib, libultra, conteepprobe] - [0x89DD0, lib, libultra, pidma] - [0x89EE0, lib, libultra, pfssearchfile] @@ -154,12 +154,12 @@ - [0x8A230, lib, libultra, cartrominit] - [0x8A330, lib, libultra, piacs] - [0x8A3F0, pad] - - [0x8A400, asm, ../lib/ultralib/src/io/devmgr] # - [0x8A400, lib, libultra, devmgr] + - [0x8A400, lib, libultra, devmgr] - [0x8A890, lib, libultra, pirawdma] - [0x8A970, lib, libultra, seteventmesg] - [0x8A9E0, lib, libultra, sqrtf] - [0x8A9F0, lib, libultra, contquery] - - [0x8AAA0, asm, ../lib/ultralib/src/libc/xprintf] # - [0x8AAA0, lib, libultra, xprintf] + - [0x8AAA0, lib, libultra, xprintf] - [0x8B760, lib, libultra, epidma] - [0x8B840, lib, libultra, leodiskinit] - [0x8B940, lib, libultra, syncprintf] @@ -173,65 +173,65 @@ - [0x8BD30, lib, libultra, setthreadpri] - [0x8BE10, lib, libultra, getthreadpri] - [0x8BE30, lib, libultra, viswapbuf] - - [0x8BE80, asm, ../lib/ultralib/src/gu/mtxcatl] # - [0x8BEE0, lib, libultra, mtxcatl] - - [0x8BF40, asm, ../lib/ultralib/src/gu/mtxcatf] # - [0x8BF40, lib, libultra, mtxcatf] + - [0x8BEE0, lib, libultra, mtxcatl] + - [0x8BF40, lib, libultra, mtxcatf] - [0x8C150, lib, libultra, epirawdma] - [0x8C380, lib, libultra, sptaskyielded] - [0x8C400, lib, libultra, bcmp] - [0x8C520, lib, libultra, gettime] - [0x8C5B0, lib, libultra, timerintr] - [0x8C9B0, lib, libultra, setglobalintmask] - - [0x8CA00, asm, ../lib/ultralib/src/io/aisetfreq] # - [0x8CA00, lib, libultra, aisetfreq] + - [0x8CA00, lib, libultra, aisetfreq] - [0x8CB60, lib, libultra, dpctr] - - [0x8CBB0, asm, ../lib/ultralib/src/io/crc] # - [0x8CBB0, lib, libultra, crc] + - [0x8CBB0, lib, libultra, crc] - [0x8CD30, lib, libultra, getactivequeue] - [0x8CD40, lib, libultra, setcompare] - [0x8CD50, lib, libultra, normalize] - [0x8CDE0, lib, libultra, dpsetstat] - [0x8CDF0, lib, libultra, bcopy] - [0x8D100, lib, libultra, resetglobalintmask] - - [0x8D160, asm, ../lib/ultralib/src/io/pfsdeletefile] # - [0x8D160, lib, libultra, pfsdeletefile] + - [0x8D160, lib, libultra, pfsdeletefile] - [0x8D780, lib, libultra, ortho] - [0x8D940, lib, libultra, interrupt] - [0x8D980, lib, libultra, vi] - - [0x8DAC0, asm, ../lib/ultralib/src/io/viswapcontext] # - [0x8DAC0, lib, libultra, viswapcontext] + - [0x8DAC0, lib, libultra, viswapcontext] - [0x8DE20, lib, libultra, pigetcmdq] - [0x8DE50, lib, libultra, cosf] - - [0x8DFC0, asm, ../lib/ultralib/src/gu/coss] # - [0x8DFC0, lib, libultra, coss] + - [0x8DFC0, lib, libultra, coss] - [0x8DFF0, lib, libultra, visetspecial] - [0x8E1B0, lib, libultra, visetevent] - - [0x8E220, asm, ../lib/ultralib/src/io/pfsisplug] # - [0x8E220, lib, libultra, pfsisplug] + - [0x8E220, lib, libultra, pfsisplug] - [0x8E560, lib, libultra, pfsnumfiles] - - [0x8E6B0, asm, ../lib/ultralib/src/gu/us2dex] # - [0x8E6B0, lib, libultra, us2dex] + - [0x8E6B0, lib, libultra, us2dex] - [0x8E830, lib, libultra, contsetch] - [0x8E8A0, lib, libultra, setfpccsr] - - [0x8E8B0, asm, ../lib/ultralib/src/io/pfsfilestate] # - [0x8E8B0, lib, libultra, pfsfilestate] + - [0x8E8B0, lib, libultra, pfsfilestate] - [0x8EBA0, lib, libultra, pfsinitpak] - - [0x8EE40, asm, ../lib/ultralib/src/io/pfsgetstatus] # - [0x8EE40, lib, libultra, pfsgetstatus] - - [0x8F080, asm, ../lib/ultralib/src/io/pfschecker] # - [0x8F080, lib, libultra, pfschecker] + - [0x8EE40, lib, libultra, pfsgetstatus] + - [0x8F080, lib, libultra, pfschecker] - [0x8FAE0, lib, libultra, aigetlen] - [0x8FAF0, lib, libultra, epirawread] - [0x8FC90, lib, libultra, maptlbrdb] - [0x8FCF0, lib, libultra, yieldthread] - [0x8FD40, lib, libultra, translate] - - [0x8FDE0, asm, ../lib/ultralib/src/io/contramwrite] # - [0x8FDE0, lib, libultra, contramwrite] + - [0x8FDE0, lib, libultra, contramwrite] - [0x90140, lib, libultra, epirawwrite] - [0x902D0, lib, libultra, settimer] - - [0x903B0, asm, ../lib/ultralib/src/libc/xldtob] # - [0x903B0, lib, libultra, xldtob] - - [0x90E70, asm, ../lib/ultralib/src/libc/ldiv] # - [0x90E70, lib, libultra, ldiv] - - [0x91000, asm, ../lib/ultralib/src/libc/xlitob] # - [0x91000, lib, libultra, xlitob] + - [0x903B0, lib, libultra, xldtob] + - [0x90E70, lib, libultra, ldiv] + - [0x91000, lib, libultra, xlitob] - [0x912A0, lib, libultra, sirawwrite] - [0x912F0, lib, libultra, spsetstat] - [0x91300, lib, libultra, spgetstat] - [0x91310, lib, libultra, writebackdcacheall] - [0x91340, lib, libultra, getcurrfaultthread] - - [0x91350, asm, ../lib/ultralib/src/io/contramread] # - [0x91350, lib, libultra, contramread] + - [0x91350, lib, libultra, contramread] - [0x916B0, lib, libultra, llcvt] - [0x918C0, lib, libultra, startthread] - [0x91A10, pad] - [0x91A20, lib, libultra, vimgr] - [0x91D80, lib, libultra, vigetcurrcontext] - - [0x91D90, asm, ../lib/ultralib/src/io/conteepread] # - [0x91D90, lib, libultra, conteepread] + - [0x91D90, asm, ../lib/ultralib/src/io/conteepread] # [0x91D90, lib, libultra, conteepread] - [0x920F0, lib, libultra, vigetcurrframebuf] - [0x92130, lib, libultra, spsetpc] @@ -255,24 +255,24 @@ - [0xAAFA0, .data, O2/stackcheck] # Libultra - - [0xAAFB0, data, ../lib/ultralib/src/gu/sins] # - [0xAAFB0, lib, libultra, sins, .data] - - [0xAB7B0, data, ../lib/ultralib/src/gu/us2dex_emu] # - [0xAB7B0, lib, libultra, us2dex_emu, .data] + - [0xAAFB0, lib, libultra, sins, .data] + - [0xAB7B0, data, ../lib/ultralib/src/gu/us2dex_emu] # [0xAB7B0, lib, libultra, us2dex_emu, .data] - [0xAB7E0, lib, libultra, exceptasm, .data] - [0xAB800, lib, libultra, thread, .data] - - [0xAB820, data, ../lib/ultralib/src/io/controller] # - [0xAB820, lib, libultra, controller, .data] + - [0xAB820, data, ../lib/ultralib/src/io/controller] # [0xAB820, lib, libultra, controller, .data] - [0xAB830, lib, libultra, siacs, .data] - - [0xAB840, data, ../lib/ultralib/src/os/initialize] # - [0xAB840, lib, libultra, initialize, .data] + - [0xAB840, lib, libultra, initialize, .data] - [0xAB860, lib, libultra, vitbl, .data] - - [0xAC580, data, ../lib/ultralib/src/io/motor] # - [0xAC580, lib, libultra, motor, .data] + - [0xAC580, lib, libultra, motor, .data] - [0xAC590, lib, libultra, pimgr, .data] - [0xAC5C0, lib, libultra, piacs, .data] - - [0xAC5D0, data, ../lib/ultralib/src/libc/xprintf] # - [0xAC5D0, lib, libultra, xprintf, .data] + - [0xAC5D0, lib, libultra, xprintf, .data] - [0xAC620, lib, libultra, timerintr, .data] - [0xAC630, lib, libultra, vimodentsclan1, .data] - [0xAC680, lib, libultra, vi, .data] - [0xAC6F0, lib, libultra, vimodepallan1, .data] - [0xAC740, lib, libultra, vimodempallan1, .data] - - [0xAC790, data, ../lib/ultralib/src/libc/xlitob] # - [0xAC790, lib, libultra, xlitob, .data] + - [0xAC790, lib, libultra, xlitob, .data] - [0xAC7C0, lib, libultra, vimgr, .data] @@ -362,14 +362,14 @@ # Libultra - [0xB3DA0, lib, libultra, setintmask, .rodata] - - [0xB3E20, rodata, ../lib/ultralib/src/gu/sinf] # - [0xB3E20, lib, libultra, sinf, .rodata] + - [0xB3E20, lib, libultra, sinf, .rodata] - [0xB3E70, lib, libultra, exceptasm, .rodata] - [0xB3EC0, lib, libultra, perspective, .rodata] - - [0xB3ED0, rodata, ../lib/ultralib/src/io/devmgr] # - [0xB3ED0, lib, libultra, devmgr, .rodata] - - [0xB3EF0, rodata, ../lib/ultralib/src/libc/xprintf] # - [0xB3EF0, lib, libultra, xprintf, .rodata] + - [0xB3ED0, lib, libultra, devmgr, .rodata] + - [0xB3EF0, lib, libultra, xprintf, .rodata] - [0xB3FF0, lib, libultra, cosf, .rodata] - [0xB4040, lib, libultra, libm_vals, .rodata] - - [0xB4050, rodata, ../lib/ultralib/src/libc/xldtob] # - [0xB4050, lib, libultra, xldtob, .rodata] + - [0xB4050, lib, libultra, xldtob, .rodata] - [0xB40B0, lib, libultra, llcvt, .rodata] - [0xB40C0, rodata] @@ -377,29 +377,29 @@ - [0xB5460, rodata] - [0xB5880, rodata] - - - {start: 0xB58B0, type: bss, vram: 0x800B4CB0, name: 800B4CB0} - - {start: 0xB58B0, type: .bss, vram: 0x80108630, name: fault} - - {start: 0xB58B0, type: bss, vram: 0x801090D0, name: 801090D0} - - {start: 0xB58B0, type: .bss, vram: 0x8010E840, name: dmamgr} - - {start: 0xB58B0, type: .bss, vram: 0x8010ED90, name: 7EFD0} + - [0xB58B0] + - {type: bss, vram: 0x800B4CB0, name: 800B4CB0} + - {type: .bss, vram: 0x80108630, name: fault} + - {type: bss, vram: 0x801090D0, name: 801090D0} + - {type: .bss, vram: 0x8010E840, name: dmamgr} + - {type: .bss, vram: 0x8010ED90, name: 7EFD0} # Libultra - - {start: 0xB58B0, type: bss, vram: 0x8010F0C0, name: ../lib/ultralib/src/io/sptask} # - {start: 0xB58B0, type: lib, vram: 0x8010F0C0, name: libultra, object: sptask, section: .bss} - - {start: 0xB58B0, type: bss, vram: 0x8010F100, name: ../lib/ultralib/src/gu/us2dex_emu} # - {start: 0xB58B0, type: lib, vram: 0x8010F100, name: libultra, object: us2dex_emu, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x8010F120, name: libultra, object: leointerrupt, section: .bss} - - {start: 0xB58B0, type: bss, vram: 0x80110120, name: ../lib/ultralib/src/io/controller} # - {start: 0xB58B0, type: lib, vram: 0x80110120, name: libultra, object: controller, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x801101B0, name: libultra, object: siacs, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x801101D0, name: libultra, object: driverominit, section: .bss} - - {start: 0xB58B0, type: bss, vram: 0x80110250, name: ../lib/ultralib/src/os/initialize} # - {start: 0xB58B0, type: lib, vram: 0x80110250, name: libultra, object: initialize, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x80110260, name: libultra, object: kdebugserver, section: .bss} - - {start: 0xB58B0, type: bss, vram: 0x80110410, name: ../lib/ultralib/src/io/motor} # - {start: 0xB58B0, type: lib, vram: 0x80110410, name: libultra, object: motor, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x80110650, name: libultra, object: pimgr, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x80111820, name: libultra, object: cartrominit, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x801118A0, name: libultra, object: piacs, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x801118C0, name: libultra, object: seteventmesg, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x80111940, name: libultra, object: leodiskinit, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x801119C0, name: libultra, object: timerintr, section: .bss} - - {start: 0xB58B0, type: bss, vram: 0x80111A00, name: ../lib/ultralib/src/io/pfsisplug} # - {start: 0xB58B0, type: lib, vram: 0x80111A00, name: libultra, object: pfsisplug, section: .bss} - - {start: 0xB58B0, type: lib, vram: 0x80111A40, name: libultra, object: vimgr, section: .bss} - - {start: 0xB58B0, type: bss, vram: 0x80112C60, name: ../lib/ultralib/src/io/conteepread} # - {start: 0xB58B0, type: lib, vram: 0x80112C60, name: libultra, object: conteepread, section: .bss} + - {type: bss, vram: 0x8010F0C0, name: ../lib/ultralib/src/io/sptask} # {type: lib, vram: 0x8010F0C0, name: libultra, object: sptask, section: .bss} + - {type: bss, vram: 0x8010F100, name: ../lib/ultralib/src/gu/us2dex_emu} # {type: lib, vram: 0x8010F100, name: libultra, object: us2dex_emu, section: .bss} + - {type: lib, vram: 0x8010F120, name: libultra, object: leointerrupt, section: .bss} + - {type: bss, vram: 0x80110120, name: ../lib/ultralib/src/io/controller} # {type: lib, vram: 0x80110120, name: libultra, object: controller, section: .bss} + - {type: lib, vram: 0x801101B0, name: libultra, object: siacs, section: .bss} + - {type: lib, vram: 0x801101D0, name: libultra, object: driverominit, section: .bss} + - {type: lib, vram: 0x80110250, name: libultra, object: initialize, section: .bss} + - {type: lib, vram: 0x80110260, name: libultra, object: kdebugserver, section: .bss} + - {type: lib, vram: 0x80110410, name: libultra, object: motor, section: .bss} + - {type: lib, vram: 0x80110650, name: libultra, object: pimgr, section: .bss} + - {type: lib, vram: 0x80111820, name: libultra, object: cartrominit, section: .bss} + - {type: lib, vram: 0x801118A0, name: libultra, object: piacs, section: .bss} + - {type: lib, vram: 0x801118C0, name: libultra, object: seteventmesg, section: .bss} + - {type: lib, vram: 0x80111940, name: libultra, object: leodiskinit, section: .bss} + - {type: lib, vram: 0x801119C0, name: libultra, object: timerintr, section: .bss} + - {type: lib, vram: 0x80111A00, name: libultra, object: pfsisplug, section: .bss} + - {type: lib, vram: 0x80111A40, name: libultra, object: vimgr, section: .bss} + - {type: bss, vram: 0x80112C60, name: ../lib/ultralib/src/io/conteepread} # {type: lib, vram: 0x80112C60, name: libultra, object: conteepread, section: .bss} From b7f9f752b4ee57f7a79e236aabf7157e21eb89c8 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sat, 24 Feb 2024 09:46:01 -0800 Subject: [PATCH 2/6] Remove pif syms --- Makefile | 4 ++-- linker_scripts/us/pif_syms.ld | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 linker_scripts/us/pif_syms.ld diff --git a/Makefile b/Makefile index 6fdf41e..f419c2d 100644 --- a/Makefile +++ b/Makefile @@ -294,9 +294,9 @@ $(ROM): $(ELF) # TODO: update rom header checksum # TODO: avoid using auto/undefined -$(ELF): $(O_FILES) $(LIBULTRA_LIB) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld +$(ELF): $(O_FILES) $(LIBULTRA_LIB) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(LD) $(LDFLAGS) -T $(LDSCRIPT) \ - -T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld \ + -T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld \ -Map $(MAP) --whole-archive $(LIBULTRA_LIB) -o $@ $(LDSCRIPT): linker_scripts/$(VERSION)/yoshisstory.ld diff --git a/linker_scripts/us/pif_syms.ld b/linker_scripts/us/pif_syms.ld deleted file mode 100644 index d2af85f..0000000 --- a/linker_scripts/us/pif_syms.ld +++ /dev/null @@ -1,10 +0,0 @@ -// libultra OS symbols - -osTvType = 0x80000300; -osRomType = 0x80000304; -osRomBase = 0x80000308; -osResetType = 0x8000030C; -osCicId = 0x80000310; -osVersion = 0x80000314; -osMemSize = 0x80000318; -osAppNMIBuffer = 0x8000031C; From fc6efa18e7057a9984242d45e856e0a8b1769240 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sat, 24 Feb 2024 10:40:46 -0800 Subject: [PATCH 3/6] unused_syms.ld --- Makefile | 9 ++++----- linker_scripts/us/unused_syms.ld | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 linker_scripts/us/unused_syms.ld diff --git a/Makefile b/Makefile index f419c2d..68ed40c 100644 --- a/Makefile +++ b/Makefile @@ -92,8 +92,7 @@ ifeq ($(NON_MATCHING),1) endif CPPFLAGS += -fno-dollars-in-identifiers -P -# TODO: Remove muldefs when all of libultra matches -LDFLAGS := --no-check-sections --accept-unknown-input-arch --emit-relocs -z muldefs +LDFLAGS := --no-check-sections --accept-unknown-input-arch --emit-relocs ifeq ($(DETECTED_OS), macos) CPPFLAGS += -xc++ @@ -294,10 +293,10 @@ $(ROM): $(ELF) # TODO: update rom header checksum # TODO: avoid using auto/undefined -$(ELF): $(O_FILES) $(LIBULTRA_LIB) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld +$(ELF): $(O_FILES) $(LIBULTRA_LIB) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/unused_syms.ld $(LD) $(LDFLAGS) -T $(LDSCRIPT) \ - -T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld \ - -Map $(MAP) --whole-archive $(LIBULTRA_LIB) -o $@ + -T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/unused_syms.ld \ + -Map $(MAP) $(LIBULTRA_LIB) -o $@ $(LDSCRIPT): linker_scripts/$(VERSION)/yoshisstory.ld cp $< $@ diff --git a/linker_scripts/us/unused_syms.ld b/linker_scripts/us/unused_syms.ld new file mode 100644 index 0000000..9399c58 --- /dev/null +++ b/linker_scripts/us/unused_syms.ld @@ -0,0 +1,5 @@ +EXTERN(guMtxCatL); +ASSERT(DEFINED(guMtxCatL), "Error: guMtxCatL was not linked"); + +EXTERN(guS2DEmuSetScissor); +ASSERT(DEFINED(guS2DEmuSetScissor), "Error: guS2DEmuSetScissor was not linked"); From a3476fcc3a0fc47aa0c31f3ef04d08181daf3050 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sat, 24 Feb 2024 18:09:45 -0800 Subject: [PATCH 4/6] Remove ultralib --- lib/ultralib/.github/workflows/ci_egcs.txt | 42 - lib/ultralib/.github/workflows/ci_gcc.yml | 41 - lib/ultralib/.github/workflows/ci_ido.yml | 41 - lib/ultralib/.gitignore | 28 - lib/ultralib/.gitrepo | 12 - lib/ultralib/Makefile | 224 - lib/ultralib/Makefile.gcc | 67 - lib/ultralib/Makefile.ido | 60 - lib/ultralib/README.md | 65 - lib/ultralib/base/I/libgultra.txt | 1 - lib/ultralib/base/I/libgultra_d.txt | 1 - lib/ultralib/base/I/libgultra_rom.txt | 1 - lib/ultralib/base/I/libultra.txt | 1 - lib/ultralib/base/I/libultra_d.txt | 1 - lib/ultralib/base/I/libultra_rom.txt | 1 - lib/ultralib/base/J/libgultra.txt | 1 - lib/ultralib/base/J/libgultra_d.txt | 1 - lib/ultralib/base/J/libgultra_rom.txt | 1 - lib/ultralib/base/J/libultra.txt | 1 - lib/ultralib/base/J/libultra_d.txt | 1 - lib/ultralib/base/J/libultra_rom.txt | 1 - lib/ultralib/base/K/libgultra.txt | 1 - lib/ultralib/base/K/libgultra_d.txt | 1 - lib/ultralib/base/K/libgultra_rom.txt | 1 - lib/ultralib/base/K/libultra.txt | 1 - lib/ultralib/base/K/libultra_d.txt | 1 - lib/ultralib/base/K/libultra_rom.txt | 1 - lib/ultralib/base/L/libgultra.txt | 1 - lib/ultralib/base/L/libgultra_d.txt | 1 - lib/ultralib/base/L/libgultra_rom.txt | 1 - lib/ultralib/base/L/libultra.txt | 1 - lib/ultralib/base/L/libultra_d.txt | 1 - lib/ultralib/base/L/libultra_rom.txt | 1 - lib/ultralib/include/PR/R4300.h | 453 -- lib/ultralib/include/PR/abi.h | 410 -- lib/ultralib/include/PR/gbi.h | 4572 ----------------- lib/ultralib/include/PR/gs2dex.h | 392 -- lib/ultralib/include/PR/gt.h | 365 -- lib/ultralib/include/PR/gu.h | 270 - lib/ultralib/include/PR/libaudio.h | 947 ---- lib/ultralib/include/PR/mbi.h | 100 - lib/ultralib/include/PR/os.h | 108 - lib/ultralib/include/PR/os_ai.h | 92 - lib/ultralib/include/PR/os_cache.h | 96 - lib/ultralib/include/PR/os_cont.h | 208 - lib/ultralib/include/PR/os_convert.h | 111 - lib/ultralib/include/PR/os_debug.h | 117 - lib/ultralib/include/PR/os_eeprom.h | 107 - lib/ultralib/include/PR/os_error.h | 86 - lib/ultralib/include/PR/os_exception.h | 86 - lib/ultralib/include/PR/os_flash.h | 77 - lib/ultralib/include/PR/os_gbpak.h | 107 - lib/ultralib/include/PR/os_gio.h | 86 - lib/ultralib/include/PR/os_host.h | 166 - lib/ultralib/include/PR/os_internal.h | 49 - lib/ultralib/include/PR/os_internal_debug.h | 43 - lib/ultralib/include/PR/os_internal_error.h | 45 - .../include/PR/os_internal_exception.h | 57 - lib/ultralib/include/PR/os_internal_flash.h | 40 - lib/ultralib/include/PR/os_internal_gio.h | 45 - lib/ultralib/include/PR/os_internal_host.h | 42 - lib/ultralib/include/PR/os_internal_reg.h | 57 - lib/ultralib/include/PR/os_internal_rsp.h | 48 - lib/ultralib/include/PR/os_internal_si.h | 46 - lib/ultralib/include/PR/os_internal_thread.h | 43 - lib/ultralib/include/PR/os_internal_tlb.h | 47 - lib/ultralib/include/PR/os_libc.h | 100 - lib/ultralib/include/PR/os_message.h | 162 - lib/ultralib/include/PR/os_motor.h | 84 - lib/ultralib/include/PR/os_pfs.h | 200 - lib/ultralib/include/PR/os_pi.h | 221 - lib/ultralib/include/PR/os_rdp.h | 92 - lib/ultralib/include/PR/os_reg.h | 90 - lib/ultralib/include/PR/os_rsp.h | 86 - lib/ultralib/include/PR/os_si.h | 86 - lib/ultralib/include/PR/os_system.h | 118 - lib/ultralib/include/PR/os_thread.h | 161 - lib/ultralib/include/PR/os_time.h | 114 - lib/ultralib/include/PR/os_tlb.h | 107 - lib/ultralib/include/PR/os_version.h | 26 - lib/ultralib/include/PR/os_vi.h | 298 -- lib/ultralib/include/PR/os_voice.h | 108 - lib/ultralib/include/PR/ramrom.h | 113 - lib/ultralib/include/PR/rcp.h | 848 --- lib/ultralib/include/PR/rdb.h | 93 - lib/ultralib/include/PR/region.h | 123 - lib/ultralib/include/PR/rmon.h | 39 - lib/ultralib/include/PR/sched.h | 115 - lib/ultralib/include/PR/sp.h | 196 - lib/ultralib/include/PR/sptask.h | 201 - lib/ultralib/include/PR/ucode.h | 192 - lib/ultralib/include/PR/ultraerror.h | 165 - lib/ultralib/include/PR/ultralog.h | 74 - lib/ultralib/include/PR/ultratypes.h | 85 - lib/ultralib/include/asm.h | 1 - lib/ultralib/include/assert.h | 12 - lib/ultralib/include/dbgdefs.h | 8 - lib/ultralib/include/dbgproto.h | 402 -- lib/ultralib/include/fpregdef.h | 0 lib/ultralib/include/gcc/math.h | 1 - lib/ultralib/include/gcc/memory.h | 23 - lib/ultralib/include/gcc/sgidefs.h | 44 - lib/ultralib/include/gcc/stdarg.h | 121 - lib/ultralib/include/gcc/stdio.h | 1 - lib/ultralib/include/gcc/stdlib.h | 81 - lib/ultralib/include/gcc/string.h | 42 - lib/ultralib/include/ido/math.h | 1 - lib/ultralib/include/ido/memory.h | 23 - lib/ultralib/include/ido/stdarg.h | 33 - lib/ultralib/include/ido/stdio.h | 1 - lib/ultralib/include/ido/stdlib.h | 81 - lib/ultralib/include/ido/string.h | 42 - lib/ultralib/include/macros.h | 16 - lib/ultralib/include/regdef.h | 3 - lib/ultralib/include/sgidefs.h | 3 - lib/ultralib/include/sys/asm.h | 116 - lib/ultralib/include/sys/fpregdef.h | 0 lib/ultralib/include/sys/regdef.h | 187 - lib/ultralib/include/ultra64.h | 40 - lib/ultralib/include/ultrahost.h | 59 - lib/ultralib/src/audio/Makefile | 120 - lib/ultralib/src/audio/auxbus.c | 65 - lib/ultralib/src/audio/bnkf.c | 143 - lib/ultralib/src/audio/cents2ratio.c | 33 - lib/ultralib/src/audio/copy.c | 35 - lib/ultralib/src/audio/cseq.c | 409 -- lib/ultralib/src/audio/cseq.h | 11 - lib/ultralib/src/audio/cseqp.h | 10 - lib/ultralib/src/audio/cspdelete.c | 29 - lib/ultralib/src/audio/cspgetchlvol.c | 27 - lib/ultralib/src/audio/cspgetfxmix.c | 27 - lib/ultralib/src/audio/cspgetpan.c | 27 - lib/ultralib/src/audio/cspgetpriority.c | 26 - lib/ultralib/src/audio/cspgetprogram.c | 42 - lib/ultralib/src/audio/cspgetseq.c | 29 - lib/ultralib/src/audio/cspgetstate.c | 29 - lib/ultralib/src/audio/cspgettempo.c | 31 - lib/ultralib/src/audio/cspgetvol.c | 27 - lib/ultralib/src/audio/csplayer.c | 882 ---- lib/ultralib/src/audio/cspplay.c | 34 - lib/ultralib/src/audio/cspsendmidi.c | 40 - lib/ultralib/src/audio/cspsetbank.c | 32 - lib/ultralib/src/audio/cspsetchlvol.c | 35 - lib/ultralib/src/audio/cspsetfxmix.c | 35 - lib/ultralib/src/audio/cspsetpan.c | 35 - lib/ultralib/src/audio/cspsetpriority.c | 32 - lib/ultralib/src/audio/cspsetprogram.c | 35 - lib/ultralib/src/audio/cspsetseq.c | 34 - lib/ultralib/src/audio/cspsettempo.c | 36 - lib/ultralib/src/audio/cspsetvol.c | 32 - lib/ultralib/src/audio/cspstop.c | 32 - lib/ultralib/src/audio/drvrnew.c | 303 -- lib/ultralib/src/audio/env.c | 591 --- lib/ultralib/src/audio/event.c | 272 - lib/ultralib/src/audio/filter.c | 32 - lib/ultralib/src/audio/heapalloc.c | 65 - lib/ultralib/src/audio/heapcheck.c | 71 - lib/ultralib/src/audio/heapinit.c | 37 - lib/ultralib/src/audio/initfx.h | 59 - lib/ultralib/src/audio/load.c | 471 -- lib/ultralib/src/audio/mainbus.c | 67 - lib/ultralib/src/audio/parse_abi.c | 47 - lib/ultralib/src/audio/resample.c | 150 - lib/ultralib/src/audio/reverb.c | 452 -- lib/ultralib/src/audio/save.c | 70 - lib/ultralib/src/audio/seq.c | 343 -- lib/ultralib/src/audio/seq.h | 9 - lib/ultralib/src/audio/seqp.h | 37 - lib/ultralib/src/audio/seqpdelete.c | 39 - lib/ultralib/src/audio/seqpgetchlvol.c | 27 - lib/ultralib/src/audio/seqpgetfxmix.c | 27 - lib/ultralib/src/audio/seqpgetpan.c | 27 - lib/ultralib/src/audio/seqpgetpriority.c | 26 - lib/ultralib/src/audio/seqpgetprogram.c | 42 - lib/ultralib/src/audio/seqpgetseq.c | 29 - lib/ultralib/src/audio/seqpgetstate.c | 29 - lib/ultralib/src/audio/seqpgettempo.c | 31 - lib/ultralib/src/audio/seqpgetvol.c | 27 - lib/ultralib/src/audio/seqplayer.c | 1228 ----- lib/ultralib/src/audio/seqploop.c | 35 - lib/ultralib/src/audio/seqpplay.c | 48 - lib/ultralib/src/audio/seqpsendmidi.c | 40 - lib/ultralib/src/audio/seqpsetbank.c | 32 - lib/ultralib/src/audio/seqpsetchlvol.c | 35 - lib/ultralib/src/audio/seqpsetfxmix.c | 35 - lib/ultralib/src/audio/seqpsetpan.c | 35 - lib/ultralib/src/audio/seqpsetpriority.c | 32 - lib/ultralib/src/audio/seqpsetprogram.c | 36 - lib/ultralib/src/audio/seqpsetseq.c | 34 - lib/ultralib/src/audio/seqpsettempo.c | 36 - lib/ultralib/src/audio/seqpsetvol.c | 32 - lib/ultralib/src/audio/seqpstop.c | 33 - lib/ultralib/src/audio/sl.c | 65 - lib/ultralib/src/audio/sndp.h | 102 - lib/ultralib/src/audio/sndpallocate.c | 43 - lib/ultralib/src/audio/sndpdeallocate.c | 35 - lib/ultralib/src/audio/sndpdelete.c | 44 - lib/ultralib/src/audio/sndpgetsound.c | 27 - lib/ultralib/src/audio/sndpgetstate.c | 29 - lib/ultralib/src/audio/sndplayer.c | 297 -- lib/ultralib/src/audio/sndpplay.c | 36 - lib/ultralib/src/audio/sndpplayat.c | 32 - lib/ultralib/src/audio/sndpsetfxmix.c | 42 - lib/ultralib/src/audio/sndpsetpan.c | 42 - lib/ultralib/src/audio/sndpsetpitch.c | 48 - lib/ultralib/src/audio/sndpsetpriority.c | 38 - lib/ultralib/src/audio/sndpsetsound.c | 36 - lib/ultralib/src/audio/sndpsetvol.c | 42 - lib/ultralib/src/audio/sndpstop.c | 35 - lib/ultralib/src/audio/synaddplayer.c | 34 - lib/ultralib/src/audio/synallocfx.c | 32 - lib/ultralib/src/audio/synallocvoice.c | 132 - lib/ultralib/src/audio/syndelete.c | 27 - lib/ultralib/src/audio/synfreefx.c | 26 - lib/ultralib/src/audio/synfreevoice.c | 54 - lib/ultralib/src/audio/syngetfxref.c | 33 - lib/ultralib/src/audio/syngetpriority.c | 27 - lib/ultralib/src/audio/synremoveplayer.c | 49 - lib/ultralib/src/audio/synsetfxmix.c | 60 - lib/ultralib/src/audio/synsetfxparam.c | 29 - lib/ultralib/src/audio/synsetpan.c | 50 - lib/ultralib/src/audio/synsetpitch.c | 50 - lib/ultralib/src/audio/synsetpriority.c | 27 - lib/ultralib/src/audio/synsetvol.c | 50 - lib/ultralib/src/audio/synstartvoice.c | 48 - lib/ultralib/src/audio/synstartvoiceparam.c | 75 - lib/ultralib/src/audio/synstopvoice.c | 44 - lib/ultralib/src/audio/synthInternals.h | 344 -- lib/ultralib/src/audio/synthesizer.c | 323 -- lib/ultralib/src/debug/assert.c | 12 - lib/ultralib/src/debug/assertbreak.s | 14 - lib/ultralib/src/debug/atomic.c | 16 - lib/ultralib/src/debug/kdebugserver.c | 96 - lib/ultralib/src/debug/osint_debug.h | 11 - lib/ultralib/src/debug/profile.c | 176 - lib/ultralib/src/debug/threadprofile.c | 22 - lib/ultralib/src/debug/threadprofileclear.c | 11 - lib/ultralib/src/debug/threadprofileinit.c | 16 - .../src/debug/threadprofilereadcount.c | 39 - .../src/debug/threadprofilereadtime.c | 51 - lib/ultralib/src/debug/threadprofilestart.c | 22 - lib/ultralib/src/debug/threadprofilestop.c | 47 - lib/ultralib/src/error/commonerror.c | 193 - lib/ultralib/src/error/error.c | 30 - lib/ultralib/src/error/errorasm.s | 33 - lib/ultralib/src/flash/flashallerase.c | 33 - lib/ultralib/src/flash/flashallerasethrough.c | 8 - lib/ultralib/src/flash/flashchange.c | 8 - lib/ultralib/src/flash/flashcheckeraseend.c | 23 - lib/ultralib/src/flash/flashclearstatus.c | 10 - lib/ultralib/src/flash/flashgetaddr.c | 15 - lib/ultralib/src/flash/flashinit.c | 44 - lib/ultralib/src/flash/flashreadarray.c | 51 - lib/ultralib/src/flash/flashreadid.c | 27 - lib/ultralib/src/flash/flashreadstatus.c | 17 - lib/ultralib/src/flash/flashreinit.c | 14 - lib/ultralib/src/flash/flashsectorerase.c | 32 - .../src/flash/flashsectorerasethrough.c | 8 - lib/ultralib/src/flash/flashwritearray.c | 34 - lib/ultralib/src/flash/flashwritebuffer.c | 20 - lib/ultralib/src/gio/giointerrupt.c | 8 - lib/ultralib/src/gio/giorawinterrupt.c | 13 - lib/ultralib/src/gt/Makefile | 19 - lib/ultralib/src/gt/dumpturbo.c | 260 - lib/ultralib/src/gt/gt.c | 155 - lib/ultralib/src/gt/gtint.h | 36 - lib/ultralib/src/gu/Makefile | 52 - lib/ultralib/src/gu/align.c | 75 - lib/ultralib/src/gu/cosf.c | 137 - lib/ultralib/src/gu/coss.c | 45 - lib/ultralib/src/gu/dump_gbi.c | 274 - lib/ultralib/src/gu/frustum.c | 42 - lib/ultralib/src/gu/guint.h | 42 - lib/ultralib/src/gu/guloadtile_bug.c | 235 - lib/ultralib/src/gu/libm_vals.s | 5 - lib/ultralib/src/gu/loadtextureblockmipmap.c | 717 --- lib/ultralib/src/gu/lookat.c | 83 - lib/ultralib/src/gu/lookathil.c | 185 - lib/ultralib/src/gu/lookatref.c | 111 - lib/ultralib/src/gu/lookatstereo.c | 111 - lib/ultralib/src/gu/mtxcatf.c | 63 - lib/ultralib/src/gu/mtxcatl.c | 57 - lib/ultralib/src/gu/mtxutil.c | 73 - lib/ultralib/src/gu/normalize.c | 23 - lib/ultralib/src/gu/ortho.c | 41 - lib/ultralib/src/gu/parse_gbi.c | 139 - lib/ultralib/src/gu/parse_rdp.c | 36 - lib/ultralib/src/gu/parse_string.c | 35 - lib/ultralib/src/gu/perspective.c | 58 - lib/ultralib/src/gu/position.c | 73 - lib/ultralib/src/gu/poslight.c | 69 - lib/ultralib/src/gu/poslighthil.c | 168 - lib/ultralib/src/gu/random.c | 33 - lib/ultralib/src/gu/readme.txt | 17 - lib/ultralib/src/gu/rotate.c | 72 - lib/ultralib/src/gu/rotaterpy.c | 58 - lib/ultralib/src/gu/scale.c | 32 - lib/ultralib/src/gu/sinf.c | 157 - lib/ultralib/src/gu/sins.c | 61 - lib/ultralib/src/gu/sintable.h | 1031 ---- lib/ultralib/src/gu/sqrtf.s | 25 - lib/ultralib/src/gu/translate.c | 31 - lib/ultralib/src/gu/us2dex.c | 73 - lib/ultralib/src/gu/us2dex2_emu.c | 12 - lib/ultralib/src/gu/us2dex_emu.c | 521 -- lib/ultralib/src/gu/usprite.c | 39 - lib/ultralib/src/host/host_ptn64.c | 209 - lib/ultralib/src/host/readhost.c | 36 - lib/ultralib/src/host/writehost.c | 57 - lib/ultralib/src/io/ai.c | 15 - lib/ultralib/src/io/aigetlen.c | 8 - lib/ultralib/src/io/aigetstat.c | 8 - lib/ultralib/src/io/aisetfreq.c | 53 - lib/ultralib/src/io/aisetnextbuf.c | 52 - lib/ultralib/src/io/cartrominit.c | 95 - lib/ultralib/src/io/contchannelreset.c | 28 - lib/ultralib/src/io/conteeplongread.c | 15 - lib/ultralib/src/io/conteeplongwrite.c | 17 - lib/ultralib/src/io/conteepprobe.c | 34 - lib/ultralib/src/io/conteepread.c | 139 - lib/ultralib/src/io/conteepwrite.c | 203 - lib/ultralib/src/io/contpfs.c | 393 -- lib/ultralib/src/io/contquery.c | 25 - lib/ultralib/src/io/contramread.c | 163 - lib/ultralib/src/io/contramwrite.c | 165 - lib/ultralib/src/io/contreaddata.c | 68 - lib/ultralib/src/io/contreset.c | 51 - lib/ultralib/src/io/controller.c | 101 - lib/ultralib/src/io/controller.h | 290 -- lib/ultralib/src/io/controller_gbpak.h | 8 - lib/ultralib/src/io/controller_voice.h | 59 - lib/ultralib/src/io/contsetch.c | 19 - lib/ultralib/src/io/crc.c | 114 - lib/ultralib/src/io/devmgr.c | 108 - lib/ultralib/src/io/dp.c | 15 - lib/ultralib/src/io/dpctr.c | 9 - lib/ultralib/src/io/dpgetstat.c | 9 - lib/ultralib/src/io/dpsetnextbuf.c | 39 - lib/ultralib/src/io/dpsetstat.c | 9 - lib/ultralib/src/io/driverominit.c | 31 - lib/ultralib/src/io/epidma.c | 61 - lib/ultralib/src/io/epigettype.c | 7 - lib/ultralib/src/io/epilinkhandle.c | 11 - lib/ultralib/src/io/epirawdma.c | 53 - lib/ultralib/src/io/epirawread.c | 48 - lib/ultralib/src/io/epirawwrite.c | 22 - lib/ultralib/src/io/epiread.c | 19 - lib/ultralib/src/io/epiwrite.c | 19 - lib/ultralib/src/io/gbpakcheckconnector.c | 131 - lib/ultralib/src/io/gbpakgetbank.c | 28 - lib/ultralib/src/io/gbpakgetstatus.c | 39 - lib/ultralib/src/io/gbpakinit.c | 90 - lib/ultralib/src/io/gbpakpower.c | 34 - lib/ultralib/src/io/gbpakreadid.c | 97 - lib/ultralib/src/io/gbpakreadwrite.c | 74 - lib/ultralib/src/io/gbpaksetbank.c | 35 - lib/ultralib/src/io/leodiskinit.c | 36 - lib/ultralib/src/io/leointerrupt.c | 194 - lib/ultralib/src/io/motor.c | 332 -- lib/ultralib/src/io/pfsallocatefile.c | 371 -- lib/ultralib/src/io/pfschecker.c | 258 - lib/ultralib/src/io/pfsdeletefile.c | 180 - lib/ultralib/src/io/pfsfilestate.c | 112 - lib/ultralib/src/io/pfsfreeblocks.c | 31 - lib/ultralib/src/io/pfsgetlabel.c | 25 - lib/ultralib/src/io/pfsgetstatus.c | 100 - lib/ultralib/src/io/pfsinit.c | 25 - lib/ultralib/src/io/pfsinitpak.c | 129 - lib/ultralib/src/io/pfsisplug.c | 97 - lib/ultralib/src/io/pfsnumfiles.c | 34 - lib/ultralib/src/io/pfsreadwritefile.c | 124 - lib/ultralib/src/io/pfsreformat.c | 71 - lib/ultralib/src/io/pfsrepairid.c | 73 - lib/ultralib/src/io/pfssearchfile.c | 56 - lib/ultralib/src/io/pfsselectbank.c | 22 - lib/ultralib/src/io/pfssetlabel.c | 41 - lib/ultralib/src/io/pi.c | 15 - lib/ultralib/src/io/piacs.c | 25 - lib/ultralib/src/io/pidma.c | 66 - lib/ultralib/src/io/pigetcmdq.c | 10 - lib/ultralib/src/io/pigetstat.c | 9 - lib/ultralib/src/io/pigettype.c | 8 - lib/ultralib/src/io/piint.h | 197 - lib/ultralib/src/io/pimgr.c | 114 - lib/ultralib/src/io/pirawdma.c | 53 - lib/ultralib/src/io/pirawread.c | 66 - lib/ultralib/src/io/pirawwrite.c | 21 - lib/ultralib/src/io/piread.c | 19 - lib/ultralib/src/io/piwrite.c | 19 - lib/ultralib/src/io/si.c | 15 - lib/ultralib/src/io/siacs.c | 25 - lib/ultralib/src/io/sigetstat.c | 9 - lib/ultralib/src/io/siint.h | 15 - lib/ultralib/src/io/sirawdma.c | 85 - lib/ultralib/src/io/sirawread.c | 62 - lib/ultralib/src/io/sirawwrite.c | 61 - lib/ultralib/src/io/sp.c | 17 - lib/ultralib/src/io/spgetstat.c | 9 - lib/ultralib/src/io/sprawdma.c | 77 - lib/ultralib/src/io/sprawread.c | 61 - lib/ultralib/src/io/sprawwrite.c | 61 - lib/ultralib/src/io/spsetpc.c | 15 - lib/ultralib/src/io/spsetstat.c | 9 - lib/ultralib/src/io/sptask.c | 82 - lib/ultralib/src/io/sptaskyield.c | 6 - lib/ultralib/src/io/sptaskyielded.c | 18 - lib/ultralib/src/io/vi.c | 39 - lib/ultralib/src/io/viblack.c | 17 - lib/ultralib/src/io/viextendvstart.c | 19 - lib/ultralib/src/io/vifade.c | 18 - lib/ultralib/src/io/vigetcurrcontext.c | 9 - lib/ultralib/src/io/vigetcurrframebuf.c | 20 - lib/ultralib/src/io/vigetfield.c | 6 - lib/ultralib/src/io/vigetline.c | 6 - lib/ultralib/src/io/vigetmode.c | 21 - lib/ultralib/src/io/vigetnextcontext.c | 6 - lib/ultralib/src/io/vigetnextframebuf.c | 20 - lib/ultralib/src/io/vigetstat.c | 6 - lib/ultralib/src/io/viint.h | 71 - lib/ultralib/src/io/vimgr.c | 126 - lib/ultralib/src/io/virepeatline.c | 17 - lib/ultralib/src/io/visetevent.c | 70 - lib/ultralib/src/io/visetmode.c | 67 - lib/ultralib/src/io/visetspecial.c | 72 - lib/ultralib/src/io/visetxscale.c | 37 - lib/ultralib/src/io/visetyscale.c | 34 - lib/ultralib/src/io/viswapbuf.c | 75 - lib/ultralib/src/io/viswapcontext.c | 80 - lib/ultralib/src/io/vitbl.c | 1740 ------- lib/ultralib/src/libc/bcmp.s | 96 - lib/ultralib/src/libc/bcopy.s | 220 - lib/ultralib/src/libc/bzero.s | 64 - lib/ultralib/src/libc/ldiv.c | 34 - lib/ultralib/src/libc/ll.c | 48 - lib/ultralib/src/libc/llbit.c | 52 - lib/ultralib/src/libc/llcvt.c | 31 - lib/ultralib/src/libc/sprintf.c | 22 - lib/ultralib/src/libc/string.c | 36 - lib/ultralib/src/libc/syncprintf.c | 154 - lib/ultralib/src/libc/xldtob.c | 309 -- lib/ultralib/src/libc/xlitob.c | 58 - lib/ultralib/src/libc/xprintf.c | 257 - lib/ultralib/src/libc/xstdio.h | 37 - lib/ultralib/src/log/delay.s | 24 - lib/ultralib/src/log/log.c | 124 - lib/ultralib/src/log/logfloat.c | 11 - lib/ultralib/src/mgu/Makefile | 36 - lib/ultralib/src/mgu/asm.h | 49 - lib/ultralib/src/mgu/mtxcatf.s | 103 - lib/ultralib/src/mgu/mtxcatl.c | 44 - lib/ultralib/src/mgu/mtxf2l.s | 80 - lib/ultralib/src/mgu/mtxident.s | 60 - lib/ultralib/src/mgu/mtxidentf.s | 60 - lib/ultralib/src/mgu/mtxl2f.s | 80 - lib/ultralib/src/mgu/mtxxfmf.c | 40 - lib/ultralib/src/mgu/mtxxfml.c | 41 - lib/ultralib/src/mgu/normalize.s | 56 - lib/ultralib/src/mgu/regdef.h | 187 - lib/ultralib/src/mgu/rotate.c | 73 - lib/ultralib/src/mgu/scale.s | 85 - lib/ultralib/src/mgu/scalef.s | 57 - lib/ultralib/src/mgu/translate.s | 101 - lib/ultralib/src/mgu/translatef.s | 58 - lib/ultralib/src/monutil.s | 188 - lib/ultralib/src/os/ackramromread.c | 16 - lib/ultralib/src/os/ackramromwrite.c | 15 - lib/ultralib/src/os/afterprenmi.c | 5 - lib/ultralib/src/os/atomic.c | 16 - lib/ultralib/src/os/createmesgqueue.c | 20 - lib/ultralib/src/os/createthread.c | 54 - lib/ultralib/src/os/destroythread.c | 49 - lib/ultralib/src/os/exceptasm.h | 29 - lib/ultralib/src/os/exceptasm.s | 1069 ---- lib/ultralib/src/os/exit.c | 9 - lib/ultralib/src/os/getactivequeue.c | 6 - lib/ultralib/src/os/getcause.s | 9 - lib/ultralib/src/os/getcompare.s | 9 - lib/ultralib/src/os/getconfig.s | 9 - lib/ultralib/src/os/getcount.s | 9 - lib/ultralib/src/os/getcurrfaultthread.c | 6 - lib/ultralib/src/os/getfpccsr.s | 9 - lib/ultralib/src/os/gethwinterrupt.c | 21 - lib/ultralib/src/os/getintmask.s | 33 - lib/ultralib/src/os/getmemsize.c | 53 - lib/ultralib/src/os/getnextfaultthread.c | 23 - lib/ultralib/src/os/getsr.s | 9 - lib/ultralib/src/os/getthreadid.c | 10 - lib/ultralib/src/os/getthreadpri.c | 10 - lib/ultralib/src/os/gettime.c | 25 - lib/ultralib/src/os/gettlbasid.s | 11 - lib/ultralib/src/os/gettlbhi.s | 17 - lib/ultralib/src/os/gettlblo0.s | 17 - lib/ultralib/src/os/gettlblo1.s | 17 - lib/ultralib/src/os/gettlbpagemask.s | 17 - lib/ultralib/src/os/getwatchlo.s | 9 - lib/ultralib/src/os/initialize.c | 224 - lib/ultralib/src/os/initialize_emu.c | 27 - lib/ultralib/src/os/initialize_isv.c | 175 - lib/ultralib/src/os/initialize_kmc.c | 152 - lib/ultralib/src/os/initialize_msp.c | 152 - lib/ultralib/src/os/initrdb.c | 31 - lib/ultralib/src/os/interrupt.s | 52 - lib/ultralib/src/os/invaldcache.s | 58 - lib/ultralib/src/os/invalicache.s | 41 - lib/ultralib/src/os/jammesg.c | 37 - lib/ultralib/src/os/maptlb.s | 111 - lib/ultralib/src/os/maptlbrdb.s | 30 - lib/ultralib/src/os/osint.h | 58 - lib/ultralib/src/os/parameters.s | 17 - lib/ultralib/src/os/physicaltovirtual.c | 6 - lib/ultralib/src/os/probetlb.s | 54 - lib/ultralib/src/os/rdbsend.c | 76 - lib/ultralib/src/os/recvmesg.c | 40 - lib/ultralib/src/os/resetglobalintmask.c | 9 - lib/ultralib/src/os/sendmesg.c | 38 - lib/ultralib/src/os/setcause.s | 9 - lib/ultralib/src/os/setcompare.s | 9 - lib/ultralib/src/os/setconfig.s | 9 - lib/ultralib/src/os/setcount.s | 9 - lib/ultralib/src/os/seterrorhandler.c | 10 - lib/ultralib/src/os/seteventmesg.c | 39 - lib/ultralib/src/os/setfpccsr.s | 10 - lib/ultralib/src/os/setglobalintmask.c | 9 - lib/ultralib/src/os/sethwinterrupt.c | 32 - lib/ultralib/src/os/setintmask.s | 124 - lib/ultralib/src/os/setpiinterrupt.c | 16 - lib/ultralib/src/os/setsr.s | 10 - lib/ultralib/src/os/setthreadpri.c | 36 - lib/ultralib/src/os/settime.c | 16 - lib/ultralib/src/os/settimer.c | 56 - lib/ultralib/src/os/settlbasid.s | 32 - lib/ultralib/src/os/setwatchlo.s | 10 - lib/ultralib/src/os/startthread.c | 39 - lib/ultralib/src/os/stopthread.c | 23 - lib/ultralib/src/os/stoptimer.c | 39 - lib/ultralib/src/os/syncputchars.c | 35 - lib/ultralib/src/os/testhost.c | 12 - lib/ultralib/src/os/thread.c | 28 - lib/ultralib/src/os/threadasm.h | 68 - lib/ultralib/src/os/timerintr.c | 141 - lib/ultralib/src/os/unmaptlb.s | 45 - lib/ultralib/src/os/unmaptlball.s | 26 - lib/ultralib/src/os/virtualtophysical.c | 13 - lib/ultralib/src/os/writebackdcache.s | 35 - lib/ultralib/src/os/writebackdcacheall.s | 18 - lib/ultralib/src/os/yieldthread.c | 10 - lib/ultralib/src/rg/free.c | 73 - lib/ultralib/src/rg/getbufcount.c | 57 - lib/ultralib/src/rg/getsize.c | 57 - lib/ultralib/src/rg/malloc.c | 70 - lib/ultralib/src/rg/printregion.c | 27 - lib/ultralib/src/rg/region.c | 232 - lib/ultralib/src/rmon/rmonbrk.c | 432 -- lib/ultralib/src/rmon/rmoncmds.c | 54 - lib/ultralib/src/rmon/rmonint.h | 169 - lib/ultralib/src/rmon/rmonmain.c | 138 - lib/ultralib/src/rmon/rmonmem.c | 283 - lib/ultralib/src/rmon/rmonmisc.c | 76 - lib/ultralib/src/rmon/rmonprint.c | 1 - lib/ultralib/src/rmon/rmonrcp.s | 60 - lib/ultralib/src/rmon/rmonregs.c | 417 -- lib/ultralib/src/rmon/rmonsio.c | 89 - lib/ultralib/src/rmon/rmontask.c | 343 -- lib/ultralib/src/sched/Makefile | 19 - lib/ultralib/src/sched/sched.c | 620 --- lib/ultralib/src/sched/sched_log.fmt | 19 - lib/ultralib/src/sp/Makefile | 30 - lib/ultralib/src/sp/clearattribute.c | 35 - lib/ultralib/src/sp/color.c | 39 - lib/ultralib/src/sp/hide.c | 35 - lib/ultralib/src/sp/setattribute.c | 35 - lib/ultralib/src/sp/show.c | 35 - lib/ultralib/src/sp/sprite.c | 761 --- lib/ultralib/src/sp/spriteex.c | 2 - lib/ultralib/src/sp/spriteex2.c | 2 - lib/ultralib/src/sp/spscale.c | 42 - lib/ultralib/src/vimodes/vimodefpalhaf1.c | 37 - lib/ultralib/src/vimodes/vimodefpalhan1.c | 37 - lib/ultralib/src/vimodes/vimodefpalhpf1.c | 37 - lib/ultralib/src/vimodes/vimodefpalhpf2.c | 37 - lib/ultralib/src/vimodes/vimodefpalhpn1.c | 37 - lib/ultralib/src/vimodes/vimodefpalhpn2.c | 37 - lib/ultralib/src/vimodes/vimodefpallaf1.c | 37 - lib/ultralib/src/vimodes/vimodefpallaf2.c | 37 - lib/ultralib/src/vimodes/vimodefpallan1.c | 37 - lib/ultralib/src/vimodes/vimodefpallan2.c | 36 - lib/ultralib/src/vimodes/vimodefpallpf1.c | 37 - lib/ultralib/src/vimodes/vimodefpallpf2.c | 37 - lib/ultralib/src/vimodes/vimodefpallpn1.c | 37 - lib/ultralib/src/vimodes/vimodefpallpn2.c | 37 - lib/ultralib/src/vimodes/vimodempalhaf1.c | 37 - lib/ultralib/src/vimodes/vimodempalhan1.c | 37 - lib/ultralib/src/vimodes/vimodempalhpf1.c | 37 - lib/ultralib/src/vimodes/vimodempalhpf2.c | 37 - lib/ultralib/src/vimodes/vimodempalhpn1.c | 37 - lib/ultralib/src/vimodes/vimodempalhpn2.c | 37 - lib/ultralib/src/vimodes/vimodempallaf1.c | 37 - lib/ultralib/src/vimodes/vimodempallaf2.c | 37 - lib/ultralib/src/vimodes/vimodempallan1.c | 37 - lib/ultralib/src/vimodes/vimodempallan2.c | 36 - lib/ultralib/src/vimodes/vimodempallpf1.c | 37 - lib/ultralib/src/vimodes/vimodempallpf2.c | 37 - lib/ultralib/src/vimodes/vimodempallpn1.c | 37 - lib/ultralib/src/vimodes/vimodempallpn2.c | 37 - lib/ultralib/src/vimodes/vimodentschaf1.c | 37 - lib/ultralib/src/vimodes/vimodentschan1.c | 37 - lib/ultralib/src/vimodes/vimodentschpf1.c | 37 - lib/ultralib/src/vimodes/vimodentschpf2.c | 37 - lib/ultralib/src/vimodes/vimodentschpn1.c | 37 - lib/ultralib/src/vimodes/vimodentschpn2.c | 37 - lib/ultralib/src/vimodes/vimodentsclaf1.c | 37 - lib/ultralib/src/vimodes/vimodentsclaf2.c | 37 - lib/ultralib/src/vimodes/vimodentsclan1.c | 37 - lib/ultralib/src/vimodes/vimodentsclan2.c | 36 - lib/ultralib/src/vimodes/vimodentsclpf1.c | 37 - lib/ultralib/src/vimodes/vimodentsclpf2.c | 37 - lib/ultralib/src/vimodes/vimodentsclpn1.c | 37 - lib/ultralib/src/vimodes/vimodentsclpn2.c | 37 - lib/ultralib/src/vimodes/vimodepalhaf1.c | 37 - lib/ultralib/src/vimodes/vimodepalhan1.c | 37 - lib/ultralib/src/vimodes/vimodepalhpf1.c | 37 - lib/ultralib/src/vimodes/vimodepalhpf2.c | 37 - lib/ultralib/src/vimodes/vimodepalhpn1.c | 37 - lib/ultralib/src/vimodes/vimodepalhpn2.c | 37 - lib/ultralib/src/vimodes/vimodepallaf1.c | 37 - lib/ultralib/src/vimodes/vimodepallaf2.c | 37 - lib/ultralib/src/vimodes/vimodepallan1.c | 37 - lib/ultralib/src/vimodes/vimodepallan2.c | 36 - lib/ultralib/src/vimodes/vimodepallpf1.c | 37 - lib/ultralib/src/vimodes/vimodepallpf2.c | 37 - lib/ultralib/src/vimodes/vimodepallpn1.c | 37 - lib/ultralib/src/vimodes/vimodepallpn2.c | 37 - lib/ultralib/src/voice/voicecheckresult.c | 28 - lib/ultralib/src/voice/voicecheckword.c | 80 - lib/ultralib/src/voice/voicecleardictionary.c | 29 - lib/ultralib/src/voice/voicecontread2.c | 73 - lib/ultralib/src/voice/voicecontread36.c | 73 - lib/ultralib/src/voice/voicecontrolgain.c | 28 - lib/ultralib/src/voice/voicecontwrite20.c | 74 - lib/ultralib/src/voice/voicecontwrite4.c | 74 - lib/ultralib/src/voice/voicecountsyllables.c | 55 - lib/ultralib/src/voice/voicecrc.c | 40 - lib/ultralib/src/voice/voicegetreaddata.c | 94 - lib/ultralib/src/voice/voicegetstatus.c | 62 - lib/ultralib/src/voice/voiceinit.c | 42 - lib/ultralib/src/voice/voiceinternal.h | 18 - lib/ultralib/src/voice/voicemaskdictionary.c | 48 - lib/ultralib/src/voice/voicesetadconverter.c | 69 - lib/ultralib/src/voice/voicesetword.c | 54 - lib/ultralib/src/voice/voicestartreaddata.c | 36 - lib/ultralib/src/voice/voicestopreaddata.c | 59 - lib/ultralib/tools/Makefile | 46 - lib/ultralib/tools/ar.py | 476 -- lib/ultralib/tools/asm_differ/.gitignore | 2 - lib/ultralib/tools/asm_differ/.gitrepo | 12 - .../tools/asm_differ/.pre-commit-config.yaml | 6 - lib/ultralib/tools/asm_differ/LICENSE | 24 - lib/ultralib/tools/asm_differ/README.md | 56 - .../tools/asm_differ/diff-stylesheet.css | 67 - lib/ultralib/tools/asm_differ/diff.py | 2923 ----------- .../tools/asm_differ/diff_settings.py | 11 - lib/ultralib/tools/asm_differ/mypy.ini | 17 - lib/ultralib/tools/asm_differ/screenshot.png | Bin 99842 -> 0 bytes lib/ultralib/tools/compile_sjis.py | 28 - lib/ultralib/tools/disassemble_elf.py | 312 -- lib/ultralib/tools/fix_objfile.py | 68 - lib/ultralib/tools/libdiff.py | 150 - lib/ultralib/tools/libelf.py | 1181 ----- lib/ultralib/tools/m2ctx.py | 76 - lib/ultralib/tools/mdebug.py | 938 ---- lib/ultralib/tools/mips_isa.py | 1309 ----- lib/ultralib/tools/patch_ar_meta.py | 90 - lib/ultralib/tools/print_mdebug.py | 589 --- lib/ultralib/tools/set_o32abi_bit.py | 25 - lib/ultralib/tools/shiftjis_conv.py | 58 - lib/ultralib/tools/strip_debug.sh | 10 - lib/ultralib/tools/util.py | 44 - 677 files changed, 64852 deletions(-) delete mode 100644 lib/ultralib/.github/workflows/ci_egcs.txt delete mode 100644 lib/ultralib/.github/workflows/ci_gcc.yml delete mode 100644 lib/ultralib/.github/workflows/ci_ido.yml delete mode 100644 lib/ultralib/.gitignore delete mode 100644 lib/ultralib/.gitrepo delete mode 100644 lib/ultralib/Makefile delete mode 100644 lib/ultralib/Makefile.gcc delete mode 100644 lib/ultralib/Makefile.ido delete mode 100644 lib/ultralib/README.md delete mode 100644 lib/ultralib/base/I/libgultra.txt delete mode 100644 lib/ultralib/base/I/libgultra_d.txt delete mode 100644 lib/ultralib/base/I/libgultra_rom.txt delete mode 100644 lib/ultralib/base/I/libultra.txt delete mode 100644 lib/ultralib/base/I/libultra_d.txt delete mode 100644 lib/ultralib/base/I/libultra_rom.txt delete mode 100644 lib/ultralib/base/J/libgultra.txt delete mode 100644 lib/ultralib/base/J/libgultra_d.txt delete mode 100644 lib/ultralib/base/J/libgultra_rom.txt delete mode 100644 lib/ultralib/base/J/libultra.txt delete mode 100644 lib/ultralib/base/J/libultra_d.txt delete mode 100644 lib/ultralib/base/J/libultra_rom.txt delete mode 100644 lib/ultralib/base/K/libgultra.txt delete mode 100644 lib/ultralib/base/K/libgultra_d.txt delete mode 100644 lib/ultralib/base/K/libgultra_rom.txt delete mode 100644 lib/ultralib/base/K/libultra.txt delete mode 100644 lib/ultralib/base/K/libultra_d.txt delete mode 100644 lib/ultralib/base/K/libultra_rom.txt delete mode 100644 lib/ultralib/base/L/libgultra.txt delete mode 100644 lib/ultralib/base/L/libgultra_d.txt delete mode 100644 lib/ultralib/base/L/libgultra_rom.txt delete mode 100644 lib/ultralib/base/L/libultra.txt delete mode 100644 lib/ultralib/base/L/libultra_d.txt delete mode 100644 lib/ultralib/base/L/libultra_rom.txt delete mode 100644 lib/ultralib/include/PR/R4300.h delete mode 100644 lib/ultralib/include/PR/abi.h delete mode 100644 lib/ultralib/include/PR/gbi.h delete mode 100644 lib/ultralib/include/PR/gs2dex.h delete mode 100644 lib/ultralib/include/PR/gt.h delete mode 100644 lib/ultralib/include/PR/gu.h delete mode 100644 lib/ultralib/include/PR/libaudio.h delete mode 100644 lib/ultralib/include/PR/mbi.h delete mode 100644 lib/ultralib/include/PR/os.h delete mode 100644 lib/ultralib/include/PR/os_ai.h delete mode 100644 lib/ultralib/include/PR/os_cache.h delete mode 100644 lib/ultralib/include/PR/os_cont.h delete mode 100644 lib/ultralib/include/PR/os_convert.h delete mode 100644 lib/ultralib/include/PR/os_debug.h delete mode 100644 lib/ultralib/include/PR/os_eeprom.h delete mode 100644 lib/ultralib/include/PR/os_error.h delete mode 100644 lib/ultralib/include/PR/os_exception.h delete mode 100644 lib/ultralib/include/PR/os_flash.h delete mode 100644 lib/ultralib/include/PR/os_gbpak.h delete mode 100644 lib/ultralib/include/PR/os_gio.h delete mode 100644 lib/ultralib/include/PR/os_host.h delete mode 100644 lib/ultralib/include/PR/os_internal.h delete mode 100644 lib/ultralib/include/PR/os_internal_debug.h delete mode 100644 lib/ultralib/include/PR/os_internal_error.h delete mode 100644 lib/ultralib/include/PR/os_internal_exception.h delete mode 100644 lib/ultralib/include/PR/os_internal_flash.h delete mode 100644 lib/ultralib/include/PR/os_internal_gio.h delete mode 100644 lib/ultralib/include/PR/os_internal_host.h delete mode 100644 lib/ultralib/include/PR/os_internal_reg.h delete mode 100644 lib/ultralib/include/PR/os_internal_rsp.h delete mode 100644 lib/ultralib/include/PR/os_internal_si.h delete mode 100644 lib/ultralib/include/PR/os_internal_thread.h delete mode 100644 lib/ultralib/include/PR/os_internal_tlb.h delete mode 100644 lib/ultralib/include/PR/os_libc.h delete mode 100644 lib/ultralib/include/PR/os_message.h delete mode 100644 lib/ultralib/include/PR/os_motor.h delete mode 100644 lib/ultralib/include/PR/os_pfs.h delete mode 100644 lib/ultralib/include/PR/os_pi.h delete mode 100644 lib/ultralib/include/PR/os_rdp.h delete mode 100644 lib/ultralib/include/PR/os_reg.h delete mode 100644 lib/ultralib/include/PR/os_rsp.h delete mode 100644 lib/ultralib/include/PR/os_si.h delete mode 100644 lib/ultralib/include/PR/os_system.h delete mode 100644 lib/ultralib/include/PR/os_thread.h delete mode 100644 lib/ultralib/include/PR/os_time.h delete mode 100644 lib/ultralib/include/PR/os_tlb.h delete mode 100644 lib/ultralib/include/PR/os_version.h delete mode 100644 lib/ultralib/include/PR/os_vi.h delete mode 100644 lib/ultralib/include/PR/os_voice.h delete mode 100644 lib/ultralib/include/PR/ramrom.h delete mode 100644 lib/ultralib/include/PR/rcp.h delete mode 100644 lib/ultralib/include/PR/rdb.h delete mode 100644 lib/ultralib/include/PR/region.h delete mode 100644 lib/ultralib/include/PR/rmon.h delete mode 100644 lib/ultralib/include/PR/sched.h delete mode 100644 lib/ultralib/include/PR/sp.h delete mode 100644 lib/ultralib/include/PR/sptask.h delete mode 100644 lib/ultralib/include/PR/ucode.h delete mode 100644 lib/ultralib/include/PR/ultraerror.h delete mode 100644 lib/ultralib/include/PR/ultralog.h delete mode 100644 lib/ultralib/include/PR/ultratypes.h delete mode 100644 lib/ultralib/include/asm.h delete mode 100644 lib/ultralib/include/assert.h delete mode 100644 lib/ultralib/include/dbgdefs.h delete mode 100644 lib/ultralib/include/dbgproto.h delete mode 100644 lib/ultralib/include/fpregdef.h delete mode 100644 lib/ultralib/include/gcc/math.h delete mode 100644 lib/ultralib/include/gcc/memory.h delete mode 100644 lib/ultralib/include/gcc/sgidefs.h delete mode 100644 lib/ultralib/include/gcc/stdarg.h delete mode 100644 lib/ultralib/include/gcc/stdio.h delete mode 100644 lib/ultralib/include/gcc/stdlib.h delete mode 100644 lib/ultralib/include/gcc/string.h delete mode 100644 lib/ultralib/include/ido/math.h delete mode 100644 lib/ultralib/include/ido/memory.h delete mode 100644 lib/ultralib/include/ido/stdarg.h delete mode 100644 lib/ultralib/include/ido/stdio.h delete mode 100644 lib/ultralib/include/ido/stdlib.h delete mode 100644 lib/ultralib/include/ido/string.h delete mode 100644 lib/ultralib/include/macros.h delete mode 100644 lib/ultralib/include/regdef.h delete mode 100644 lib/ultralib/include/sgidefs.h delete mode 100644 lib/ultralib/include/sys/asm.h delete mode 100644 lib/ultralib/include/sys/fpregdef.h delete mode 100644 lib/ultralib/include/sys/regdef.h delete mode 100644 lib/ultralib/include/ultra64.h delete mode 100644 lib/ultralib/include/ultrahost.h delete mode 100644 lib/ultralib/src/audio/Makefile delete mode 100644 lib/ultralib/src/audio/auxbus.c delete mode 100644 lib/ultralib/src/audio/bnkf.c delete mode 100644 lib/ultralib/src/audio/cents2ratio.c delete mode 100644 lib/ultralib/src/audio/copy.c delete mode 100644 lib/ultralib/src/audio/cseq.c delete mode 100644 lib/ultralib/src/audio/cseq.h delete mode 100644 lib/ultralib/src/audio/cseqp.h delete mode 100644 lib/ultralib/src/audio/cspdelete.c delete mode 100644 lib/ultralib/src/audio/cspgetchlvol.c delete mode 100644 lib/ultralib/src/audio/cspgetfxmix.c delete mode 100644 lib/ultralib/src/audio/cspgetpan.c delete mode 100644 lib/ultralib/src/audio/cspgetpriority.c delete mode 100644 lib/ultralib/src/audio/cspgetprogram.c delete mode 100644 lib/ultralib/src/audio/cspgetseq.c delete mode 100644 lib/ultralib/src/audio/cspgetstate.c delete mode 100644 lib/ultralib/src/audio/cspgettempo.c delete mode 100644 lib/ultralib/src/audio/cspgetvol.c delete mode 100644 lib/ultralib/src/audio/csplayer.c delete mode 100644 lib/ultralib/src/audio/cspplay.c delete mode 100644 lib/ultralib/src/audio/cspsendmidi.c delete mode 100644 lib/ultralib/src/audio/cspsetbank.c delete mode 100644 lib/ultralib/src/audio/cspsetchlvol.c delete mode 100644 lib/ultralib/src/audio/cspsetfxmix.c delete mode 100644 lib/ultralib/src/audio/cspsetpan.c delete mode 100644 lib/ultralib/src/audio/cspsetpriority.c delete mode 100644 lib/ultralib/src/audio/cspsetprogram.c delete mode 100644 lib/ultralib/src/audio/cspsetseq.c delete mode 100644 lib/ultralib/src/audio/cspsettempo.c delete mode 100644 lib/ultralib/src/audio/cspsetvol.c delete mode 100644 lib/ultralib/src/audio/cspstop.c delete mode 100644 lib/ultralib/src/audio/drvrnew.c delete mode 100644 lib/ultralib/src/audio/env.c delete mode 100644 lib/ultralib/src/audio/event.c delete mode 100644 lib/ultralib/src/audio/filter.c delete mode 100644 lib/ultralib/src/audio/heapalloc.c delete mode 100644 lib/ultralib/src/audio/heapcheck.c delete mode 100644 lib/ultralib/src/audio/heapinit.c delete mode 100644 lib/ultralib/src/audio/initfx.h delete mode 100644 lib/ultralib/src/audio/load.c delete mode 100644 lib/ultralib/src/audio/mainbus.c delete mode 100644 lib/ultralib/src/audio/parse_abi.c delete mode 100644 lib/ultralib/src/audio/resample.c delete mode 100644 lib/ultralib/src/audio/reverb.c delete mode 100644 lib/ultralib/src/audio/save.c delete mode 100644 lib/ultralib/src/audio/seq.c delete mode 100644 lib/ultralib/src/audio/seq.h delete mode 100644 lib/ultralib/src/audio/seqp.h delete mode 100644 lib/ultralib/src/audio/seqpdelete.c delete mode 100644 lib/ultralib/src/audio/seqpgetchlvol.c delete mode 100644 lib/ultralib/src/audio/seqpgetfxmix.c delete mode 100644 lib/ultralib/src/audio/seqpgetpan.c delete mode 100644 lib/ultralib/src/audio/seqpgetpriority.c delete mode 100644 lib/ultralib/src/audio/seqpgetprogram.c delete mode 100644 lib/ultralib/src/audio/seqpgetseq.c delete mode 100644 lib/ultralib/src/audio/seqpgetstate.c delete mode 100644 lib/ultralib/src/audio/seqpgettempo.c delete mode 100644 lib/ultralib/src/audio/seqpgetvol.c delete mode 100644 lib/ultralib/src/audio/seqplayer.c delete mode 100644 lib/ultralib/src/audio/seqploop.c delete mode 100644 lib/ultralib/src/audio/seqpplay.c delete mode 100644 lib/ultralib/src/audio/seqpsendmidi.c delete mode 100644 lib/ultralib/src/audio/seqpsetbank.c delete mode 100644 lib/ultralib/src/audio/seqpsetchlvol.c delete mode 100644 lib/ultralib/src/audio/seqpsetfxmix.c delete mode 100644 lib/ultralib/src/audio/seqpsetpan.c delete mode 100644 lib/ultralib/src/audio/seqpsetpriority.c delete mode 100644 lib/ultralib/src/audio/seqpsetprogram.c delete mode 100644 lib/ultralib/src/audio/seqpsetseq.c delete mode 100644 lib/ultralib/src/audio/seqpsettempo.c delete mode 100644 lib/ultralib/src/audio/seqpsetvol.c delete mode 100644 lib/ultralib/src/audio/seqpstop.c delete mode 100644 lib/ultralib/src/audio/sl.c delete mode 100644 lib/ultralib/src/audio/sndp.h delete mode 100644 lib/ultralib/src/audio/sndpallocate.c delete mode 100644 lib/ultralib/src/audio/sndpdeallocate.c delete mode 100644 lib/ultralib/src/audio/sndpdelete.c delete mode 100644 lib/ultralib/src/audio/sndpgetsound.c delete mode 100644 lib/ultralib/src/audio/sndpgetstate.c delete mode 100644 lib/ultralib/src/audio/sndplayer.c delete mode 100644 lib/ultralib/src/audio/sndpplay.c delete mode 100644 lib/ultralib/src/audio/sndpplayat.c delete mode 100644 lib/ultralib/src/audio/sndpsetfxmix.c delete mode 100644 lib/ultralib/src/audio/sndpsetpan.c delete mode 100644 lib/ultralib/src/audio/sndpsetpitch.c delete mode 100644 lib/ultralib/src/audio/sndpsetpriority.c delete mode 100644 lib/ultralib/src/audio/sndpsetsound.c delete mode 100644 lib/ultralib/src/audio/sndpsetvol.c delete mode 100644 lib/ultralib/src/audio/sndpstop.c delete mode 100644 lib/ultralib/src/audio/synaddplayer.c delete mode 100644 lib/ultralib/src/audio/synallocfx.c delete mode 100644 lib/ultralib/src/audio/synallocvoice.c delete mode 100644 lib/ultralib/src/audio/syndelete.c delete mode 100644 lib/ultralib/src/audio/synfreefx.c delete mode 100644 lib/ultralib/src/audio/synfreevoice.c delete mode 100644 lib/ultralib/src/audio/syngetfxref.c delete mode 100644 lib/ultralib/src/audio/syngetpriority.c delete mode 100644 lib/ultralib/src/audio/synremoveplayer.c delete mode 100644 lib/ultralib/src/audio/synsetfxmix.c delete mode 100644 lib/ultralib/src/audio/synsetfxparam.c delete mode 100644 lib/ultralib/src/audio/synsetpan.c delete mode 100644 lib/ultralib/src/audio/synsetpitch.c delete mode 100644 lib/ultralib/src/audio/synsetpriority.c delete mode 100644 lib/ultralib/src/audio/synsetvol.c delete mode 100644 lib/ultralib/src/audio/synstartvoice.c delete mode 100644 lib/ultralib/src/audio/synstartvoiceparam.c delete mode 100644 lib/ultralib/src/audio/synstopvoice.c delete mode 100644 lib/ultralib/src/audio/synthInternals.h delete mode 100644 lib/ultralib/src/audio/synthesizer.c delete mode 100644 lib/ultralib/src/debug/assert.c delete mode 100644 lib/ultralib/src/debug/assertbreak.s delete mode 100644 lib/ultralib/src/debug/atomic.c delete mode 100644 lib/ultralib/src/debug/kdebugserver.c delete mode 100644 lib/ultralib/src/debug/osint_debug.h delete mode 100644 lib/ultralib/src/debug/profile.c delete mode 100644 lib/ultralib/src/debug/threadprofile.c delete mode 100644 lib/ultralib/src/debug/threadprofileclear.c delete mode 100644 lib/ultralib/src/debug/threadprofileinit.c delete mode 100644 lib/ultralib/src/debug/threadprofilereadcount.c delete mode 100644 lib/ultralib/src/debug/threadprofilereadtime.c delete mode 100644 lib/ultralib/src/debug/threadprofilestart.c delete mode 100644 lib/ultralib/src/debug/threadprofilestop.c delete mode 100644 lib/ultralib/src/error/commonerror.c delete mode 100644 lib/ultralib/src/error/error.c delete mode 100644 lib/ultralib/src/error/errorasm.s delete mode 100644 lib/ultralib/src/flash/flashallerase.c delete mode 100644 lib/ultralib/src/flash/flashallerasethrough.c delete mode 100644 lib/ultralib/src/flash/flashchange.c delete mode 100644 lib/ultralib/src/flash/flashcheckeraseend.c delete mode 100644 lib/ultralib/src/flash/flashclearstatus.c delete mode 100644 lib/ultralib/src/flash/flashgetaddr.c delete mode 100644 lib/ultralib/src/flash/flashinit.c delete mode 100644 lib/ultralib/src/flash/flashreadarray.c delete mode 100644 lib/ultralib/src/flash/flashreadid.c delete mode 100644 lib/ultralib/src/flash/flashreadstatus.c delete mode 100644 lib/ultralib/src/flash/flashreinit.c delete mode 100644 lib/ultralib/src/flash/flashsectorerase.c delete mode 100644 lib/ultralib/src/flash/flashsectorerasethrough.c delete mode 100644 lib/ultralib/src/flash/flashwritearray.c delete mode 100644 lib/ultralib/src/flash/flashwritebuffer.c delete mode 100644 lib/ultralib/src/gio/giointerrupt.c delete mode 100644 lib/ultralib/src/gio/giorawinterrupt.c delete mode 100644 lib/ultralib/src/gt/Makefile delete mode 100644 lib/ultralib/src/gt/dumpturbo.c delete mode 100644 lib/ultralib/src/gt/gt.c delete mode 100644 lib/ultralib/src/gt/gtint.h delete mode 100644 lib/ultralib/src/gu/Makefile delete mode 100644 lib/ultralib/src/gu/align.c delete mode 100644 lib/ultralib/src/gu/cosf.c delete mode 100644 lib/ultralib/src/gu/coss.c delete mode 100644 lib/ultralib/src/gu/dump_gbi.c delete mode 100644 lib/ultralib/src/gu/frustum.c delete mode 100644 lib/ultralib/src/gu/guint.h delete mode 100644 lib/ultralib/src/gu/guloadtile_bug.c delete mode 100644 lib/ultralib/src/gu/libm_vals.s delete mode 100644 lib/ultralib/src/gu/loadtextureblockmipmap.c delete mode 100644 lib/ultralib/src/gu/lookat.c delete mode 100644 lib/ultralib/src/gu/lookathil.c delete mode 100644 lib/ultralib/src/gu/lookatref.c delete mode 100644 lib/ultralib/src/gu/lookatstereo.c delete mode 100644 lib/ultralib/src/gu/mtxcatf.c delete mode 100644 lib/ultralib/src/gu/mtxcatl.c delete mode 100644 lib/ultralib/src/gu/mtxutil.c delete mode 100644 lib/ultralib/src/gu/normalize.c delete mode 100644 lib/ultralib/src/gu/ortho.c delete mode 100644 lib/ultralib/src/gu/parse_gbi.c delete mode 100644 lib/ultralib/src/gu/parse_rdp.c delete mode 100644 lib/ultralib/src/gu/parse_string.c delete mode 100644 lib/ultralib/src/gu/perspective.c delete mode 100644 lib/ultralib/src/gu/position.c delete mode 100644 lib/ultralib/src/gu/poslight.c delete mode 100644 lib/ultralib/src/gu/poslighthil.c delete mode 100644 lib/ultralib/src/gu/random.c delete mode 100644 lib/ultralib/src/gu/readme.txt delete mode 100644 lib/ultralib/src/gu/rotate.c delete mode 100644 lib/ultralib/src/gu/rotaterpy.c delete mode 100644 lib/ultralib/src/gu/scale.c delete mode 100644 lib/ultralib/src/gu/sinf.c delete mode 100644 lib/ultralib/src/gu/sins.c delete mode 100644 lib/ultralib/src/gu/sintable.h delete mode 100644 lib/ultralib/src/gu/sqrtf.s delete mode 100644 lib/ultralib/src/gu/translate.c delete mode 100644 lib/ultralib/src/gu/us2dex.c delete mode 100644 lib/ultralib/src/gu/us2dex2_emu.c delete mode 100644 lib/ultralib/src/gu/us2dex_emu.c delete mode 100644 lib/ultralib/src/gu/usprite.c delete mode 100644 lib/ultralib/src/host/host_ptn64.c delete mode 100644 lib/ultralib/src/host/readhost.c delete mode 100644 lib/ultralib/src/host/writehost.c delete mode 100644 lib/ultralib/src/io/ai.c delete mode 100644 lib/ultralib/src/io/aigetlen.c delete mode 100644 lib/ultralib/src/io/aigetstat.c delete mode 100644 lib/ultralib/src/io/aisetfreq.c delete mode 100644 lib/ultralib/src/io/aisetnextbuf.c delete mode 100644 lib/ultralib/src/io/cartrominit.c delete mode 100644 lib/ultralib/src/io/contchannelreset.c delete mode 100644 lib/ultralib/src/io/conteeplongread.c delete mode 100644 lib/ultralib/src/io/conteeplongwrite.c delete mode 100644 lib/ultralib/src/io/conteepprobe.c delete mode 100644 lib/ultralib/src/io/conteepread.c delete mode 100644 lib/ultralib/src/io/conteepwrite.c delete mode 100644 lib/ultralib/src/io/contpfs.c delete mode 100644 lib/ultralib/src/io/contquery.c delete mode 100644 lib/ultralib/src/io/contramread.c delete mode 100644 lib/ultralib/src/io/contramwrite.c delete mode 100644 lib/ultralib/src/io/contreaddata.c delete mode 100644 lib/ultralib/src/io/contreset.c delete mode 100644 lib/ultralib/src/io/controller.c delete mode 100644 lib/ultralib/src/io/controller.h delete mode 100644 lib/ultralib/src/io/controller_gbpak.h delete mode 100644 lib/ultralib/src/io/controller_voice.h delete mode 100644 lib/ultralib/src/io/contsetch.c delete mode 100644 lib/ultralib/src/io/crc.c delete mode 100644 lib/ultralib/src/io/devmgr.c delete mode 100644 lib/ultralib/src/io/dp.c delete mode 100644 lib/ultralib/src/io/dpctr.c delete mode 100644 lib/ultralib/src/io/dpgetstat.c delete mode 100644 lib/ultralib/src/io/dpsetnextbuf.c delete mode 100644 lib/ultralib/src/io/dpsetstat.c delete mode 100644 lib/ultralib/src/io/driverominit.c delete mode 100644 lib/ultralib/src/io/epidma.c delete mode 100644 lib/ultralib/src/io/epigettype.c delete mode 100644 lib/ultralib/src/io/epilinkhandle.c delete mode 100644 lib/ultralib/src/io/epirawdma.c delete mode 100644 lib/ultralib/src/io/epirawread.c delete mode 100644 lib/ultralib/src/io/epirawwrite.c delete mode 100644 lib/ultralib/src/io/epiread.c delete mode 100644 lib/ultralib/src/io/epiwrite.c delete mode 100644 lib/ultralib/src/io/gbpakcheckconnector.c delete mode 100644 lib/ultralib/src/io/gbpakgetbank.c delete mode 100644 lib/ultralib/src/io/gbpakgetstatus.c delete mode 100644 lib/ultralib/src/io/gbpakinit.c delete mode 100644 lib/ultralib/src/io/gbpakpower.c delete mode 100644 lib/ultralib/src/io/gbpakreadid.c delete mode 100644 lib/ultralib/src/io/gbpakreadwrite.c delete mode 100644 lib/ultralib/src/io/gbpaksetbank.c delete mode 100644 lib/ultralib/src/io/leodiskinit.c delete mode 100644 lib/ultralib/src/io/leointerrupt.c delete mode 100644 lib/ultralib/src/io/motor.c delete mode 100644 lib/ultralib/src/io/pfsallocatefile.c delete mode 100644 lib/ultralib/src/io/pfschecker.c delete mode 100644 lib/ultralib/src/io/pfsdeletefile.c delete mode 100644 lib/ultralib/src/io/pfsfilestate.c delete mode 100644 lib/ultralib/src/io/pfsfreeblocks.c delete mode 100644 lib/ultralib/src/io/pfsgetlabel.c delete mode 100644 lib/ultralib/src/io/pfsgetstatus.c delete mode 100644 lib/ultralib/src/io/pfsinit.c delete mode 100644 lib/ultralib/src/io/pfsinitpak.c delete mode 100644 lib/ultralib/src/io/pfsisplug.c delete mode 100644 lib/ultralib/src/io/pfsnumfiles.c delete mode 100644 lib/ultralib/src/io/pfsreadwritefile.c delete mode 100644 lib/ultralib/src/io/pfsreformat.c delete mode 100644 lib/ultralib/src/io/pfsrepairid.c delete mode 100644 lib/ultralib/src/io/pfssearchfile.c delete mode 100644 lib/ultralib/src/io/pfsselectbank.c delete mode 100644 lib/ultralib/src/io/pfssetlabel.c delete mode 100644 lib/ultralib/src/io/pi.c delete mode 100644 lib/ultralib/src/io/piacs.c delete mode 100644 lib/ultralib/src/io/pidma.c delete mode 100644 lib/ultralib/src/io/pigetcmdq.c delete mode 100644 lib/ultralib/src/io/pigetstat.c delete mode 100644 lib/ultralib/src/io/pigettype.c delete mode 100644 lib/ultralib/src/io/piint.h delete mode 100644 lib/ultralib/src/io/pimgr.c delete mode 100644 lib/ultralib/src/io/pirawdma.c delete mode 100644 lib/ultralib/src/io/pirawread.c delete mode 100644 lib/ultralib/src/io/pirawwrite.c delete mode 100644 lib/ultralib/src/io/piread.c delete mode 100644 lib/ultralib/src/io/piwrite.c delete mode 100644 lib/ultralib/src/io/si.c delete mode 100644 lib/ultralib/src/io/siacs.c delete mode 100644 lib/ultralib/src/io/sigetstat.c delete mode 100644 lib/ultralib/src/io/siint.h delete mode 100644 lib/ultralib/src/io/sirawdma.c delete mode 100644 lib/ultralib/src/io/sirawread.c delete mode 100644 lib/ultralib/src/io/sirawwrite.c delete mode 100644 lib/ultralib/src/io/sp.c delete mode 100644 lib/ultralib/src/io/spgetstat.c delete mode 100644 lib/ultralib/src/io/sprawdma.c delete mode 100644 lib/ultralib/src/io/sprawread.c delete mode 100644 lib/ultralib/src/io/sprawwrite.c delete mode 100644 lib/ultralib/src/io/spsetpc.c delete mode 100644 lib/ultralib/src/io/spsetstat.c delete mode 100644 lib/ultralib/src/io/sptask.c delete mode 100644 lib/ultralib/src/io/sptaskyield.c delete mode 100644 lib/ultralib/src/io/sptaskyielded.c delete mode 100644 lib/ultralib/src/io/vi.c delete mode 100644 lib/ultralib/src/io/viblack.c delete mode 100644 lib/ultralib/src/io/viextendvstart.c delete mode 100644 lib/ultralib/src/io/vifade.c delete mode 100644 lib/ultralib/src/io/vigetcurrcontext.c delete mode 100644 lib/ultralib/src/io/vigetcurrframebuf.c delete mode 100644 lib/ultralib/src/io/vigetfield.c delete mode 100644 lib/ultralib/src/io/vigetline.c delete mode 100644 lib/ultralib/src/io/vigetmode.c delete mode 100644 lib/ultralib/src/io/vigetnextcontext.c delete mode 100644 lib/ultralib/src/io/vigetnextframebuf.c delete mode 100644 lib/ultralib/src/io/vigetstat.c delete mode 100644 lib/ultralib/src/io/viint.h delete mode 100644 lib/ultralib/src/io/vimgr.c delete mode 100644 lib/ultralib/src/io/virepeatline.c delete mode 100644 lib/ultralib/src/io/visetevent.c delete mode 100644 lib/ultralib/src/io/visetmode.c delete mode 100644 lib/ultralib/src/io/visetspecial.c delete mode 100644 lib/ultralib/src/io/visetxscale.c delete mode 100644 lib/ultralib/src/io/visetyscale.c delete mode 100644 lib/ultralib/src/io/viswapbuf.c delete mode 100644 lib/ultralib/src/io/viswapcontext.c delete mode 100644 lib/ultralib/src/io/vitbl.c delete mode 100644 lib/ultralib/src/libc/bcmp.s delete mode 100644 lib/ultralib/src/libc/bcopy.s delete mode 100644 lib/ultralib/src/libc/bzero.s delete mode 100644 lib/ultralib/src/libc/ldiv.c delete mode 100644 lib/ultralib/src/libc/ll.c delete mode 100644 lib/ultralib/src/libc/llbit.c delete mode 100644 lib/ultralib/src/libc/llcvt.c delete mode 100644 lib/ultralib/src/libc/sprintf.c delete mode 100644 lib/ultralib/src/libc/string.c delete mode 100644 lib/ultralib/src/libc/syncprintf.c delete mode 100644 lib/ultralib/src/libc/xldtob.c delete mode 100644 lib/ultralib/src/libc/xlitob.c delete mode 100644 lib/ultralib/src/libc/xprintf.c delete mode 100644 lib/ultralib/src/libc/xstdio.h delete mode 100644 lib/ultralib/src/log/delay.s delete mode 100644 lib/ultralib/src/log/log.c delete mode 100644 lib/ultralib/src/log/logfloat.c delete mode 100644 lib/ultralib/src/mgu/Makefile delete mode 100644 lib/ultralib/src/mgu/asm.h delete mode 100644 lib/ultralib/src/mgu/mtxcatf.s delete mode 100644 lib/ultralib/src/mgu/mtxcatl.c delete mode 100644 lib/ultralib/src/mgu/mtxf2l.s delete mode 100644 lib/ultralib/src/mgu/mtxident.s delete mode 100644 lib/ultralib/src/mgu/mtxidentf.s delete mode 100644 lib/ultralib/src/mgu/mtxl2f.s delete mode 100644 lib/ultralib/src/mgu/mtxxfmf.c delete mode 100644 lib/ultralib/src/mgu/mtxxfml.c delete mode 100644 lib/ultralib/src/mgu/normalize.s delete mode 100644 lib/ultralib/src/mgu/regdef.h delete mode 100644 lib/ultralib/src/mgu/rotate.c delete mode 100644 lib/ultralib/src/mgu/scale.s delete mode 100644 lib/ultralib/src/mgu/scalef.s delete mode 100644 lib/ultralib/src/mgu/translate.s delete mode 100644 lib/ultralib/src/mgu/translatef.s delete mode 100644 lib/ultralib/src/monutil.s delete mode 100644 lib/ultralib/src/os/ackramromread.c delete mode 100644 lib/ultralib/src/os/ackramromwrite.c delete mode 100644 lib/ultralib/src/os/afterprenmi.c delete mode 100644 lib/ultralib/src/os/atomic.c delete mode 100644 lib/ultralib/src/os/createmesgqueue.c delete mode 100644 lib/ultralib/src/os/createthread.c delete mode 100644 lib/ultralib/src/os/destroythread.c delete mode 100644 lib/ultralib/src/os/exceptasm.h delete mode 100644 lib/ultralib/src/os/exceptasm.s delete mode 100644 lib/ultralib/src/os/exit.c delete mode 100644 lib/ultralib/src/os/getactivequeue.c delete mode 100644 lib/ultralib/src/os/getcause.s delete mode 100644 lib/ultralib/src/os/getcompare.s delete mode 100644 lib/ultralib/src/os/getconfig.s delete mode 100644 lib/ultralib/src/os/getcount.s delete mode 100644 lib/ultralib/src/os/getcurrfaultthread.c delete mode 100644 lib/ultralib/src/os/getfpccsr.s delete mode 100644 lib/ultralib/src/os/gethwinterrupt.c delete mode 100644 lib/ultralib/src/os/getintmask.s delete mode 100644 lib/ultralib/src/os/getmemsize.c delete mode 100644 lib/ultralib/src/os/getnextfaultthread.c delete mode 100644 lib/ultralib/src/os/getsr.s delete mode 100644 lib/ultralib/src/os/getthreadid.c delete mode 100644 lib/ultralib/src/os/getthreadpri.c delete mode 100644 lib/ultralib/src/os/gettime.c delete mode 100644 lib/ultralib/src/os/gettlbasid.s delete mode 100644 lib/ultralib/src/os/gettlbhi.s delete mode 100644 lib/ultralib/src/os/gettlblo0.s delete mode 100644 lib/ultralib/src/os/gettlblo1.s delete mode 100644 lib/ultralib/src/os/gettlbpagemask.s delete mode 100644 lib/ultralib/src/os/getwatchlo.s delete mode 100644 lib/ultralib/src/os/initialize.c delete mode 100644 lib/ultralib/src/os/initialize_emu.c delete mode 100644 lib/ultralib/src/os/initialize_isv.c delete mode 100644 lib/ultralib/src/os/initialize_kmc.c delete mode 100644 lib/ultralib/src/os/initialize_msp.c delete mode 100644 lib/ultralib/src/os/initrdb.c delete mode 100644 lib/ultralib/src/os/interrupt.s delete mode 100644 lib/ultralib/src/os/invaldcache.s delete mode 100644 lib/ultralib/src/os/invalicache.s delete mode 100644 lib/ultralib/src/os/jammesg.c delete mode 100644 lib/ultralib/src/os/maptlb.s delete mode 100644 lib/ultralib/src/os/maptlbrdb.s delete mode 100644 lib/ultralib/src/os/osint.h delete mode 100644 lib/ultralib/src/os/parameters.s delete mode 100644 lib/ultralib/src/os/physicaltovirtual.c delete mode 100644 lib/ultralib/src/os/probetlb.s delete mode 100644 lib/ultralib/src/os/rdbsend.c delete mode 100644 lib/ultralib/src/os/recvmesg.c delete mode 100644 lib/ultralib/src/os/resetglobalintmask.c delete mode 100644 lib/ultralib/src/os/sendmesg.c delete mode 100644 lib/ultralib/src/os/setcause.s delete mode 100644 lib/ultralib/src/os/setcompare.s delete mode 100644 lib/ultralib/src/os/setconfig.s delete mode 100644 lib/ultralib/src/os/setcount.s delete mode 100644 lib/ultralib/src/os/seterrorhandler.c delete mode 100644 lib/ultralib/src/os/seteventmesg.c delete mode 100644 lib/ultralib/src/os/setfpccsr.s delete mode 100644 lib/ultralib/src/os/setglobalintmask.c delete mode 100644 lib/ultralib/src/os/sethwinterrupt.c delete mode 100644 lib/ultralib/src/os/setintmask.s delete mode 100644 lib/ultralib/src/os/setpiinterrupt.c delete mode 100644 lib/ultralib/src/os/setsr.s delete mode 100644 lib/ultralib/src/os/setthreadpri.c delete mode 100644 lib/ultralib/src/os/settime.c delete mode 100644 lib/ultralib/src/os/settimer.c delete mode 100644 lib/ultralib/src/os/settlbasid.s delete mode 100644 lib/ultralib/src/os/setwatchlo.s delete mode 100644 lib/ultralib/src/os/startthread.c delete mode 100644 lib/ultralib/src/os/stopthread.c delete mode 100644 lib/ultralib/src/os/stoptimer.c delete mode 100644 lib/ultralib/src/os/syncputchars.c delete mode 100644 lib/ultralib/src/os/testhost.c delete mode 100644 lib/ultralib/src/os/thread.c delete mode 100644 lib/ultralib/src/os/threadasm.h delete mode 100644 lib/ultralib/src/os/timerintr.c delete mode 100644 lib/ultralib/src/os/unmaptlb.s delete mode 100644 lib/ultralib/src/os/unmaptlball.s delete mode 100644 lib/ultralib/src/os/virtualtophysical.c delete mode 100644 lib/ultralib/src/os/writebackdcache.s delete mode 100644 lib/ultralib/src/os/writebackdcacheall.s delete mode 100644 lib/ultralib/src/os/yieldthread.c delete mode 100644 lib/ultralib/src/rg/free.c delete mode 100644 lib/ultralib/src/rg/getbufcount.c delete mode 100644 lib/ultralib/src/rg/getsize.c delete mode 100644 lib/ultralib/src/rg/malloc.c delete mode 100644 lib/ultralib/src/rg/printregion.c delete mode 100644 lib/ultralib/src/rg/region.c delete mode 100644 lib/ultralib/src/rmon/rmonbrk.c delete mode 100644 lib/ultralib/src/rmon/rmoncmds.c delete mode 100644 lib/ultralib/src/rmon/rmonint.h delete mode 100644 lib/ultralib/src/rmon/rmonmain.c delete mode 100644 lib/ultralib/src/rmon/rmonmem.c delete mode 100644 lib/ultralib/src/rmon/rmonmisc.c delete mode 100644 lib/ultralib/src/rmon/rmonprint.c delete mode 100644 lib/ultralib/src/rmon/rmonrcp.s delete mode 100644 lib/ultralib/src/rmon/rmonregs.c delete mode 100644 lib/ultralib/src/rmon/rmonsio.c delete mode 100644 lib/ultralib/src/rmon/rmontask.c delete mode 100644 lib/ultralib/src/sched/Makefile delete mode 100644 lib/ultralib/src/sched/sched.c delete mode 100644 lib/ultralib/src/sched/sched_log.fmt delete mode 100644 lib/ultralib/src/sp/Makefile delete mode 100644 lib/ultralib/src/sp/clearattribute.c delete mode 100644 lib/ultralib/src/sp/color.c delete mode 100644 lib/ultralib/src/sp/hide.c delete mode 100644 lib/ultralib/src/sp/setattribute.c delete mode 100644 lib/ultralib/src/sp/show.c delete mode 100644 lib/ultralib/src/sp/sprite.c delete mode 100644 lib/ultralib/src/sp/spriteex.c delete mode 100644 lib/ultralib/src/sp/spriteex2.c delete mode 100644 lib/ultralib/src/sp/spscale.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpalhaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpalhan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpalhpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpalhpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpalhpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpalhpn2.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallaf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallan2.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodefpallpn2.c delete mode 100644 lib/ultralib/src/vimodes/vimodempalhaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempalhan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempalhpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempalhpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodempalhpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempalhpn2.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallaf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallan2.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodempallpn2.c delete mode 100644 lib/ultralib/src/vimodes/vimodentschaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentschan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentschpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentschpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodentschpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentschpn2.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclaf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclan2.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodentsclpn2.c delete mode 100644 lib/ultralib/src/vimodes/vimodepalhaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepalhan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepalhpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepalhpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodepalhpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepalhpn2.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallaf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallaf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallan1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallan2.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallpf1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallpf2.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallpn1.c delete mode 100644 lib/ultralib/src/vimodes/vimodepallpn2.c delete mode 100644 lib/ultralib/src/voice/voicecheckresult.c delete mode 100644 lib/ultralib/src/voice/voicecheckword.c delete mode 100644 lib/ultralib/src/voice/voicecleardictionary.c delete mode 100644 lib/ultralib/src/voice/voicecontread2.c delete mode 100644 lib/ultralib/src/voice/voicecontread36.c delete mode 100644 lib/ultralib/src/voice/voicecontrolgain.c delete mode 100644 lib/ultralib/src/voice/voicecontwrite20.c delete mode 100644 lib/ultralib/src/voice/voicecontwrite4.c delete mode 100644 lib/ultralib/src/voice/voicecountsyllables.c delete mode 100644 lib/ultralib/src/voice/voicecrc.c delete mode 100644 lib/ultralib/src/voice/voicegetreaddata.c delete mode 100644 lib/ultralib/src/voice/voicegetstatus.c delete mode 100644 lib/ultralib/src/voice/voiceinit.c delete mode 100644 lib/ultralib/src/voice/voiceinternal.h delete mode 100644 lib/ultralib/src/voice/voicemaskdictionary.c delete mode 100644 lib/ultralib/src/voice/voicesetadconverter.c delete mode 100644 lib/ultralib/src/voice/voicesetword.c delete mode 100644 lib/ultralib/src/voice/voicestartreaddata.c delete mode 100644 lib/ultralib/src/voice/voicestopreaddata.c delete mode 100644 lib/ultralib/tools/Makefile delete mode 100755 lib/ultralib/tools/ar.py delete mode 100644 lib/ultralib/tools/asm_differ/.gitignore delete mode 100644 lib/ultralib/tools/asm_differ/.gitrepo delete mode 100644 lib/ultralib/tools/asm_differ/.pre-commit-config.yaml delete mode 100644 lib/ultralib/tools/asm_differ/LICENSE delete mode 100644 lib/ultralib/tools/asm_differ/README.md delete mode 100644 lib/ultralib/tools/asm_differ/diff-stylesheet.css delete mode 100755 lib/ultralib/tools/asm_differ/diff.py delete mode 100644 lib/ultralib/tools/asm_differ/diff_settings.py delete mode 100644 lib/ultralib/tools/asm_differ/mypy.ini delete mode 100644 lib/ultralib/tools/asm_differ/screenshot.png delete mode 100755 lib/ultralib/tools/compile_sjis.py delete mode 100755 lib/ultralib/tools/disassemble_elf.py delete mode 100755 lib/ultralib/tools/fix_objfile.py delete mode 100755 lib/ultralib/tools/libdiff.py delete mode 100755 lib/ultralib/tools/libelf.py delete mode 100755 lib/ultralib/tools/m2ctx.py delete mode 100644 lib/ultralib/tools/mdebug.py delete mode 100644 lib/ultralib/tools/mips_isa.py delete mode 100755 lib/ultralib/tools/patch_ar_meta.py delete mode 100755 lib/ultralib/tools/print_mdebug.py delete mode 100755 lib/ultralib/tools/set_o32abi_bit.py delete mode 100755 lib/ultralib/tools/shiftjis_conv.py delete mode 100755 lib/ultralib/tools/strip_debug.sh delete mode 100644 lib/ultralib/tools/util.py diff --git a/lib/ultralib/.github/workflows/ci_egcs.txt b/lib/ultralib/.github/workflows/ci_egcs.txt deleted file mode 100644 index b6d8fe7..0000000 --- a/lib/ultralib/.github/workflows/ci_egcs.txt +++ /dev/null @@ -1,42 +0,0 @@ -# CI file for EGCS builds -# TODO: rename to `ci_egcs.yml` when the repo has EGCS / iQue support - -name: Build EGCS libultra - -# Build on every branch push, tag push, and pull request change: -on: [push, pull_request_target] - -jobs: - build_repo: - name: Build repo - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - version: [ique_v1.5] - suffix: [_rom] # [~, _d, _rom] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Install package requirements - run: sudo apt-get install -y build-essential python3 - - - name: Get extra dependencies - uses: actions/checkout@v3 - with: - repository: ${{ secrets.SECRETREPO }} - token: ${{ secrets.SECRETTOKEN }} - path: deps_repo - - name: Get the dependency - run: cp deps_repo/libultra/${{ matrix.version }}/* . - - - name: Setup - run: make setup -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} - - - name: Build libultra${{ matrix.suffix }} ${{ matrix.version }} - run: make -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} diff --git a/lib/ultralib/.github/workflows/ci_gcc.yml b/lib/ultralib/.github/workflows/ci_gcc.yml deleted file mode 100644 index 31efff8..0000000 --- a/lib/ultralib/.github/workflows/ci_gcc.yml +++ /dev/null @@ -1,41 +0,0 @@ -# CI file for GCC/KMC builds - -name: Build GCC libgultra - -# Build on every branch push, tag push, and pull request change: -on: [push, pull_request_target] - -jobs: - build_repo: - name: Build repo - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - version: [I, J, K, L] # [H, I, I_patch, J, K, L] - suffix: [~, _d, _rom] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Install package requirements - run: sudo apt-get install -y build-essential python3 - - - name: Get extra dependencies - uses: actions/checkout@v3 - with: - repository: ${{ secrets.SECRETREPO }} - token: ${{ secrets.SECRETTOKEN }} - path: deps_repo - - name: Get the dependency - run: cp deps_repo/libultra/${{ matrix.version }}/* base/${{ matrix.version }} - - - name: Setup - run: make setup -j $(nproc) TARGET=libgultra${{ matrix.suffix }} VERSION=${{ matrix.version }} - - - name: Build libgultra${{ matrix.suffix }} ${{ matrix.version }} - run: make -j $(nproc) TARGET=libgultra${{ matrix.suffix }} VERSION=${{ matrix.version }} diff --git a/lib/ultralib/.github/workflows/ci_ido.yml b/lib/ultralib/.github/workflows/ci_ido.yml deleted file mode 100644 index 1410108..0000000 --- a/lib/ultralib/.github/workflows/ci_ido.yml +++ /dev/null @@ -1,41 +0,0 @@ -# CI file for IDO builds - -name: Build IDO libultra - -# Build on every branch push, tag push, and pull request change: -on: [push, pull_request_target] - -jobs: - build_repo: - name: Build repo - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - version: [I, J, K, L] # [E, F, G, H, I, I_patch, J, K, L] - suffix: [~, _rom] # [~, _d, _rom] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Install package requirements - run: sudo apt-get install -y build-essential python3 binutils-mips-linux-gnu - - - name: Get extra dependencies - uses: actions/checkout@v3 - with: - repository: ${{ secrets.SECRETREPO }} - token: ${{ secrets.SECRETTOKEN }} - path: deps_repo - - name: Get the dependency - run: cp deps_repo/libultra/${{ matrix.version }}/* base/${{ matrix.version }} - - - name: Setup - run: make setup -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} - - - name: Build libultra${{ matrix.suffix }} ${{ matrix.version }} - run: make -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} diff --git a/lib/ultralib/.gitignore b/lib/ultralib/.gitignore deleted file mode 100644 index 5dfa062..0000000 --- a/lib/ultralib/.gitignore +++ /dev/null @@ -1,28 +0,0 @@ -# Cache files -__pycache__/ -.pyc -.DS_Store - -# Text editor remnants -.vscode/ -.vs/ -.idea/ -CMakeLists.txt -cmake-build-debug -venv/ - -# Project-specific ignores -base_*/ -build/ -expected/ -notes/ -tools/gcc -tools/ido -*.elf -*.o -*.a - -# Tool artifacts -ctx.c - -libultra_collection/ diff --git a/lib/ultralib/.gitrepo b/lib/ultralib/.gitrepo deleted file mode 100644 index f8c9503..0000000 --- a/lib/ultralib/.gitrepo +++ /dev/null @@ -1,12 +0,0 @@ -; DO NOT EDIT (unless you know what you are doing) -; -; This subdirectory is a git "subrepo", and this file is maintained by the -; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme -; -[subrepo] - remote = git@github.com:decompals/ultralib.git - branch = main - commit = 6c1f3067a1ae4466338bf2aba0e1110d10f5291b - parent = 12e706521a72a8d197cd38937a2282d675997e50 - method = merge - cmdver = 0.4.6 diff --git a/lib/ultralib/Makefile b/lib/ultralib/Makefile deleted file mode 100644 index eca1b44..0000000 --- a/lib/ultralib/Makefile +++ /dev/null @@ -1,224 +0,0 @@ -COMPARE ?= 1 - -# One of: -# libgultra_rom, libgultra_d, libgultra -# libultra_rom, libultra_d, libultra -TARGET ?= libgultra_rom -VERSION ?= L -CROSS ?= mips-linux-gnu- - -BASE_DIR := extracted/$(VERSION)/$(TARGET) -BASE_AR := base/$(VERSION)/$(TARGET).a -BUILD_ROOT := build -BUILD_DIR := $(BUILD_ROOT)/$(VERSION)/$(TARGET) -BUILD_AR := $(BUILD_DIR)/$(TARGET).a - -WORKING_DIR := $(shell pwd) - -CPP := cpp -P -AR := ar - -VERSION_D := 1 -VERSION_E := 2 -VERSION_F := 3 -VERSION_G := 4 -VERSION_H := 5 -VERSION_I := 6 -VERSION_J := 7 -VERSION_K := 8 -VERSION_L := 9 - -VERSION_DEFINE := -DBUILD_VERSION=$(VERSION_$(VERSION)) -DBUILD_VERSION_STRING=\"2.0$(VERSION)\" - -ifeq ($(findstring _d,$(TARGET)),_d) -DEBUGFLAG := -D_DEBUG -else -DEBUGFLAG := -DNDEBUG -endif - -ifeq ($(findstring libgultra,$(TARGET)),libgultra) --include Makefile.gcc -else ifeq ($(findstring libultra,$(TARGET)),libultra) --include Makefile.ido -else -$(error Invalid Target) -endif - -ifeq ($(findstring _rom,$(TARGET)),_rom) -CPPFLAGS += -D_FINALROM -endif - -SRC_DIRS := $(shell find src -type d) -ASM_DIRS := $(shell find asm -type d) -C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) -S_FILES := $(foreach dir,$(SRC_DIRS) $(ASM_DIRS),$(wildcard $(dir)/*.s)) - -# Versions J and below used the C matrix math implementations -MGU_MATRIX_FILES := mtxcatf normalize scale translate -ifneq ($(filter $(VERSION),D E F G H I J),) -S_FILES := $(filter-out $(addprefix src/mgu/,$(MGU_MATRIX_FILES:=.s)),$(S_FILES)) -else -C_FILES := $(filter-out $(addprefix src/gu/,$(MGU_MATRIX_FILES:=.c)),$(C_FILES)) -endif - -C_O_FILES := $(foreach f,$(C_FILES:.c=.o),$(BUILD_DIR)/$f) -S_O_FILES := $(foreach f,$(S_FILES:.s=.o),$(BUILD_DIR)/$f) -O_FILES := $(S_O_FILES) $(C_O_FILES) -# Because we patch the object file timestamps, we can't use them as the targets since they'll always be older than the C file -# Therefore instead we use marker files that have actual timestamps as the dependencies for the archive -C_MARKER_FILES := $(C_O_FILES:.o=.marker) -S_MARKER_FILES := $(S_O_FILES:.o=.marker) -S_MARKER_FILES := $(filter-out $(MDEBUG_FILES),$(S_MARKER_FILES)) -MARKER_FILES := $(C_MARKER_FILES) $(S_MARKER_FILES) $(MDEBUG_FILES) - -ifneq ($(COMPARE),0) -COMPARE_OBJ = cmp $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o) && echo "$(@:.marker=.o): OK" -COMPARE_AR = cmp $(BASE_AR) $@ && echo "$@: OK" -ifeq ($(COMPILER),ido) -COMPARE_OBJ = $(CROSS)objcopy -p --strip-debug $(WORKING_DIR)/$(@:.marker=.o) $(WORKING_DIR)/$(@:.marker=.cmp.o) && \ - cmp $(BASE_DIR)/.cmp/$(@F:.marker=.cmp.o) $(WORKING_DIR)/$(@:.marker=.cmp.o) && echo "$(@:.marker=.o): OK" -COMPARE_AR = echo "$@: Cannot compare archive currently" -endif -else -COMPARE_OBJ := -COMPARE_AR := -AR_OLD := $(AR) -endif - -BASE_OBJS := $(wildcard $(BASE_DIR)/*.o) - -# Check to make sure the current version has been set up -ifneq ($(COMPARE),0) -ifeq ($(BASE_OBJS),) -# Ignore this check if the user is currently running setup, clean or distclean -ifeq ($(filter $(MAKECMDGOALS),setup clean distclean),) -$(error Current version ($(TARGET) 2.0$(VERSION)) has not been setup!) -endif -endif -endif - -AR_OBJECTS := $(shell cat base/$(VERSION)/$(TARGET).txt) -# If the version and target doesn't have a text file yet, resort back to using the base archive to get objects -ifeq ($(AR_OBJECTS),) -AR_OBJECTS := $(shell ar t $(BASE_AR)) -endif - - -# Try to find a file corresponding to an archive file in any of src/ asm/ or the base directory, prioritizing src then asm then the original file -AR_ORDER = $(foreach f,$(AR_OBJECTS),$(shell find $(BUILD_DIR)/src $(BUILD_DIR)/asm $(BASE_DIR) -iname $f -type f -print -quit)) -MATCHED_OBJS = $(filter-out $(BASE_DIR)/%,$(AR_ORDER)) -UNMATCHED_OBJS = $(filter-out $(MATCHED_OBJS),$(AR_ORDER)) -NUM_OBJS = $(words $(AR_ORDER)) -NUM_OBJS_MATCHED = $(words $(MATCHED_OBJS)) -NUM_OBJS_UNMATCHED = $(words $(UNMATCHED_OBJS)) - -$(shell mkdir -p asm $(BASE_DIR) src $(foreach dir,$(ASM_DIRS) $(SRC_DIRS),$(BUILD_DIR)/$(dir))) - -.PHONY: all clean distclean setup -all: $(BUILD_AR) - -$(BUILD_AR): $(MARKER_FILES) - $(AR_OLD) rcs $@ $(AR_ORDER) -ifneq ($(COMPARE),0) -# patch archive creation time and individual files' ownership & permissions - dd bs=1 skip=24 seek=24 count=12 conv=notrunc if=$(BASE_AR) of=$@ status=none - python3 tools/patch_ar_meta.py $@ $(BASE_AR) $(PATCH_AR_FLAGS) - @$(COMPARE_AR) - @echo "Matched: $(NUM_OBJS_MATCHED)/$(NUM_OBJS)" -endif - -clean: - $(RM) -rf $(BUILD_DIR) - -distclean: - $(MAKE) -C tools distclean - $(RM) -rf extracted/ $(BUILD_ROOT) - -setup: - $(MAKE) -C tools -ifneq ($(COMPARE),0) - cd $(BASE_DIR) && $(AR) xo $(WORKING_DIR)/$(BASE_AR) - chmod -R +rw $(BASE_DIR) -ifeq ($(COMPILER),ido) - export CROSS=$(CROSS) && ./tools/strip_debug.sh $(BASE_DIR) -endif -endif - -$(BUILD_DIR)/$(BASE_DIR)/%.marker: $(BASE_DIR)/%.o - cp $< $(@:.marker=.o) -ifneq ($(COMPARE),0) -# change file timestamps to match original - @touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o) - @$(COMPARE_OBJ) - @touch $@ -endif - -GBIDEFINE := -DF3DEX_GBI - -$(BUILD_DIR)/src/gu/parse_gbi.marker: GBIDEFINE := -DF3D_GBI -$(BUILD_DIR)/src/gu/us2dex_emu.marker: GBIDEFINE := -$(BUILD_DIR)/src/gu/us2dex2_emu.marker: GBIDEFINE := -$(BUILD_DIR)/src/sp/sprite.marker: GBIDEFINE := -DF3D_GBI -$(BUILD_DIR)/src/sp/spriteex.marker: GBIDEFINE := -$(BUILD_DIR)/src/sp/spriteex2.marker: GBIDEFINE := -$(BUILD_DIR)/src/voice/%.marker: OPTFLAGS += -DLANG_JAPANESE -I$(WORKING_DIR)/src -I$(WORKING_DIR)/src/voice -$(BUILD_DIR)/src/voice/%.marker: CC := tools/compile_sjis.py -D__CC=$(WORKING_DIR)/$(CC) -D__BUILD_DIR=$(BUILD_DIR) - -$(C_MARKER_FILES): $(BUILD_DIR)/%.marker: %.c - cd $( - -/* - * Segment base addresses and sizes - */ -#define KUBASE 0 -#define KUSIZE 0x80000000 -#define K0BASE 0x80000000 -#define K0SIZE 0x20000000 -#define K1BASE 0xA0000000 -#define K1SIZE 0x20000000 -#define K2BASE 0xC0000000 -#define K2SIZE 0x20000000 - -/* - * Exception vectors - */ -#define SIZE_EXCVEC 0x80 /* Size of an exc. vec */ -#define UT_VEC K0BASE /* utlbmiss vector */ -#define R_VEC (K1BASE+0x1fc00000) /* reset vector */ -#define XUT_VEC (K0BASE+0x80) /* extended address tlbmiss */ -#define ECC_VEC (K0BASE+0x100) /* Ecc exception vector */ -#define E_VEC (K0BASE+0x180) /* Gen. exception vector */ - -/* - * Address conversion macros - */ -#ifdef _LANGUAGE_ASSEMBLY - -#define K0_TO_K1(x) ((x)|0xA0000000) /* kseg0 to kseg1 */ -#define K1_TO_K0(x) ((x)&0x9FFFFFFF) /* kseg1 to kseg0 */ -#define K0_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg0 to physical */ -#define K1_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg1 to physical */ -#define KDM_TO_PHYS(x) ((x)&0x1FFFFFFF) /* direct mapped to physical */ -#define PHYS_TO_K0(x) ((x)|0x80000000) /* physical to kseg0 */ -#define PHYS_TO_K1(x) ((x)|0xA0000000) /* physical to kseg1 */ - -#else /* _LANGUAGE_C */ - -#define K0_TO_K1(x) ((u32)(x)|0xA0000000) /* kseg0 to kseg1 */ -#define K1_TO_K0(x) ((u32)(x)&0x9FFFFFFF) /* kseg1 to kseg0 */ -#define K0_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg0 to physical */ -#define K1_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg1 to physical */ -#define KDM_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* direct mapped to physical */ -#define PHYS_TO_K0(x) ((u32)(x)|0x80000000) /* physical to kseg0 */ -#define PHYS_TO_K1(x) ((u32)(x)|0xA0000000) /* physical to kseg1 */ - -#endif /* _LANGUAGE_ASSEMBLY */ - -/* - * Address predicates - */ -#define IS_KSEG0(x) ((u32)(x) >= K0BASE && (u32)(x) < K1BASE) -#define IS_KSEG1(x) ((u32)(x) >= K1BASE && (u32)(x) < K2BASE) -#define IS_KSEGDM(x) ((u32)(x) >= K0BASE && (u32)(x) < K2BASE) -#define IS_KSEG2(x) ((u32)(x) >= K2BASE && (u32)(x) < KPTE_SHDUBASE) -#define IS_KPTESEG(x) ((u32)(x) >= KPTE_SHDUBASE) -#define IS_KUSEG(x) ((u32)(x) < K0BASE) - -/* - * TLB size constants - */ - -#define NTLBENTRIES 31 /* entry 31 is reserved by rdb */ - -#define TLBHI_VPN2MASK 0xffffe000 -#define TLBHI_VPN2SHIFT 13 -#define TLBHI_PIDMASK 0xff -#define TLBHI_PIDSHIFT 0 -#define TLBHI_NPID 255 /* 255 to fit in 8 bits */ - -#define TLBLO_PFNMASK 0x3fffffc0 -#define TLBLO_PFNSHIFT 6 -#define TLBLO_CACHMASK 0x38 /* cache coherency algorithm */ -#define TLBLO_CACHSHIFT 3 -#define TLBLO_UNCACHED 0x10 /* not cached */ -#define TLBLO_NONCOHRNT 0x18 /* Cacheable non-coherent */ -#define TLBLO_EXLWR 0x28 /* Exclusive write */ -#define TLBLO_D 0x4 /* writeable */ -#define TLBLO_V 0x2 /* valid bit */ -#define TLBLO_G 0x1 /* global access bit */ - -#define TLBINX_PROBE 0x80000000 -#define TLBINX_INXMASK 0x3f -#define TLBINX_INXSHIFT 0 - -#define TLBRAND_RANDMASK 0x3f -#define TLBRAND_RANDSHIFT 0 - -#define TLBWIRED_WIREDMASK 0x3f - -#define TLBCTXT_BASEMASK 0xff800000 -#define TLBCTXT_BASESHIFT 23 -#define TLBCTXT_BASEBITS 9 - -#define TLBCTXT_VPNMASK 0x7ffff0 -#define TLBCTXT_VPNSHIFT 4 - -#define TLBPGMASK_4K 0x0 -#define TLBPGMASK_16K 0x6000 -#define TLBPGMASK_64K 0x1e000 - -/* - * Status register - */ -#define SR_CUMASK 0xf0000000 /* coproc usable bits */ - -#define SR_CU3 0x80000000 /* Coprocessor 3 usable */ -#define SR_CU2 0x40000000 /* Coprocessor 2 usable */ -#define SR_CU1 0x20000000 /* Coprocessor 1 usable */ -#define SR_CU0 0x10000000 /* Coprocessor 0 usable */ -#define SR_RP 0x08000000 /* Reduced power (quarter speed) */ -#define SR_FR 0x04000000 /* MIPS III FP register mode */ -#define SR_RE 0x02000000 /* Reverse endian */ -#define SR_ITS 0x01000000 /* Instruction trace support */ -#define SR_BEV 0x00400000 /* Use boot exception vectors */ -#define SR_TS 0x00200000 /* TLB shutdown */ -#define SR_SR 0x00100000 /* Soft reset occured */ -#define SR_CH 0x00040000 /* Cache hit for last 'cache' op */ -#define SR_CE 0x00020000 /* Create ECC */ -#define SR_DE 0x00010000 /* ECC of parity does not cause error */ - -/* - * Interrupt enable bits - * (NOTE: bits set to 1 enable the corresponding level interrupt) - */ -#define SR_IMASK 0x0000ff00 /* Interrupt mask */ -#define SR_IMASK8 0x00000000 /* mask level 8 */ -#define SR_IMASK7 0x00008000 /* mask level 7 */ -#define SR_IMASK6 0x0000c000 /* mask level 6 */ -#define SR_IMASK5 0x0000e000 /* mask level 5 */ -#define SR_IMASK4 0x0000f000 /* mask level 4 */ -#define SR_IMASK3 0x0000f800 /* mask level 3 */ -#define SR_IMASK2 0x0000fc00 /* mask level 2 */ -#define SR_IMASK1 0x0000fe00 /* mask level 1 */ -#define SR_IMASK0 0x0000ff00 /* mask level 0 */ - -#define SR_IBIT8 0x00008000 /* bit level 8 */ -#define SR_IBIT7 0x00004000 /* bit level 7 */ -#define SR_IBIT6 0x00002000 /* bit level 6 */ -#define SR_IBIT5 0x00001000 /* bit level 5 */ -#define SR_IBIT4 0x00000800 /* bit level 4 */ -#define SR_IBIT3 0x00000400 /* bit level 3 */ -#define SR_IBIT2 0x00000200 /* bit level 2 */ -#define SR_IBIT1 0x00000100 /* bit level 1 */ - -#define SR_IMASKSHIFT 8 - -#define SR_KX 0x00000080 /* extended-addr TLB vec in kernel */ -#define SR_SX 0x00000040 /* xtended-addr TLB vec supervisor */ -#define SR_UX 0x00000020 /* xtended-addr TLB vec in user mode */ -#define SR_KSU_MASK 0x00000018 /* mode mask */ -#define SR_KSU_USR 0x00000010 /* user mode */ -#define SR_KSU_SUP 0x00000008 /* supervisor mode */ -#define SR_KSU_KER 0x00000000 /* kernel mode */ -#define SR_ERL 0x00000004 /* Error level, 1=>cache error */ -#define SR_EXL 0x00000002 /* Exception level, 1=>exception */ -#define SR_IE 0x00000001 /* interrupt enable, 1=>enable */ - -/* - * Cause Register - */ -#define CAUSE_BD 0x80000000 /* Branch delay slot */ -#define CAUSE_CEMASK 0x30000000 /* coprocessor error */ -#define CAUSE_CESHIFT 28 - -/* Interrupt pending bits */ -#define CAUSE_IP8 0x00008000 /* External level 8 pending - COMPARE */ -#define CAUSE_IP7 0x00004000 /* External level 7 pending - INT4 */ -#define CAUSE_IP6 0x00002000 /* External level 6 pending - INT3 */ -#define CAUSE_IP5 0x00001000 /* External level 5 pending - INT2 */ -#define CAUSE_IP4 0x00000800 /* External level 4 pending - INT1 */ -#define CAUSE_IP3 0x00000400 /* External level 3 pending - INT0 */ -#define CAUSE_SW2 0x00000200 /* Software level 2 pending */ -#define CAUSE_SW1 0x00000100 /* Software level 1 pending */ - -#define CAUSE_IPMASK 0x0000FF00 /* Pending interrupt mask */ -#define CAUSE_IPSHIFT 8 - -#define CAUSE_EXCMASK 0x0000007C /* Cause code bits */ - -#define CAUSE_EXCSHIFT 2 - -/* Cause register exception codes */ - -#define EXC_CODE(x) ((x)<<2) - -/* Hardware exception codes */ -#define EXC_INT EXC_CODE(0) /* interrupt */ -#define EXC_MOD EXC_CODE(1) /* TLB mod */ -#define EXC_RMISS EXC_CODE(2) /* Read TLB Miss */ -#define EXC_WMISS EXC_CODE(3) /* Write TLB Miss */ -#define EXC_RADE EXC_CODE(4) /* Read Address Error */ -#define EXC_WADE EXC_CODE(5) /* Write Address Error */ -#define EXC_IBE EXC_CODE(6) /* Instruction Bus Error */ -#define EXC_DBE EXC_CODE(7) /* Data Bus Error */ -#define EXC_SYSCALL EXC_CODE(8) /* SYSCALL */ -#define EXC_BREAK EXC_CODE(9) /* BREAKpoint */ -#define EXC_II EXC_CODE(10) /* Illegal Instruction */ -#define EXC_CPU EXC_CODE(11) /* CoProcessor Unusable */ -#define EXC_OV EXC_CODE(12) /* OVerflow */ -#define EXC_TRAP EXC_CODE(13) /* Trap exception */ -#define EXC_VCEI EXC_CODE(14) /* Virt. Coherency on Inst. fetch */ -#define EXC_FPE EXC_CODE(15) /* Floating Point Exception */ -#define EXC_WATCH EXC_CODE(23) /* Watchpoint reference */ -#define EXC_VCED EXC_CODE(31) /* Virt. Coherency on data read */ - -/* C0_PRID Defines */ -#define C0_IMPMASK 0xff00 -#define C0_IMPSHIFT 8 -#define C0_REVMASK 0xff -#define C0_MAJREVMASK 0xf0 -#define C0_MAJREVSHIFT 4 -#define C0_MINREVMASK 0xf - -/* - * Coprocessor 0 operations - */ -#define C0_READI 0x1 /* read ITLB entry addressed by C0_INDEX */ -#define C0_WRITEI 0x2 /* write ITLB entry addressed by C0_INDEX */ -#define C0_WRITER 0x6 /* write ITLB entry addressed by C0_RAND */ -#define C0_PROBE 0x8 /* probe for ITLB entry addressed by TLBHI */ -#define C0_RFE 0x10 /* restore for exception */ - -/* - * 'cache' instruction definitions - */ - -/* Target cache */ -#define CACH_PI 0x0 /* specifies primary inst. cache */ -#define CACH_PD 0x1 /* primary data cache */ -#define CACH_SI 0x2 /* secondary instruction cache */ -#define CACH_SD 0x3 /* secondary data cache */ - -/* Cache operations */ -#define C_IINV 0x0 /* index invalidate (inst, 2nd inst) */ -#define C_IWBINV 0x0 /* index writeback inval (d, sd) */ -#define C_ILT 0x4 /* index load tag (all) */ -#define C_IST 0x8 /* index store tag (all) */ -#define C_CDX 0xc /* create dirty exclusive (d, sd) */ -#define C_HINV 0x10 /* hit invalidate (all) */ -#define C_HWBINV 0x14 /* hit writeback inv. (d, sd) */ -#define C_FILL 0x14 /* fill (i) */ -#define C_HWB 0x18 /* hit writeback (i, d, sd) */ -#define C_HSV 0x1c /* hit set virt. (si, sd) */ - -/* - * Cache size definitions - */ -#define ICACHE_SIZE 0x4000 /* 16K */ -#define ICACHE_LINESIZE 32 /* 8 words */ -#define ICACHE_LINEMASK (ICACHE_LINESIZE-1) - -#define DCACHE_SIZE 0x2000 /* 8K */ -#define DCACHE_LINESIZE 16 /* 4 words */ -#define DCACHE_LINEMASK (DCACHE_LINESIZE-1) - -/* - * C0_CONFIG register definitions - */ -#define CONFIG_CM 0x80000000 /* 1 == Master-Checker enabled */ -#define CONFIG_EC 0x70000000 /* System Clock ratio */ -#define CONFIG_EC_1_1 0x6 /* System Clock ratio 1 :1 */ -#define CONFIG_EC_3_2 0x7 /* System Clock ratio 1.5 :1 */ -#define CONFIG_EC_2_1 0x0 /* System Clock ratio 2 :1 */ -#define CONFIG_EC_3_1 0x1 /* System Clock ratio 3 :1 */ -#define CONFIG_EP 0x0f000000 /* Transmit Data Pattern */ -#define CONFIG_SB 0x00c00000 /* Secondary cache block size */ - -#define CONFIG_SS 0x00200000 /* Split scache: 0 == I&D combined */ -#define CONFIG_SW 0x00100000 /* scache port: 0==128, 1==64 */ -#define CONFIG_EW 0x000c0000 /* System Port width: 0==64, 1==32 */ -#define CONFIG_SC 0x00020000 /* 0 -> 2nd cache present */ -#define CONFIG_SM 0x00010000 /* 0 -> Dirty Shared Coherency enabled*/ -#define CONFIG_BE 0x00008000 /* Endian-ness: 1 --> BE */ -#define CONFIG_EM 0x00004000 /* 1 -> ECC mode, 0 -> parity */ -#define CONFIG_EB 0x00002000 /* Block order:1->sequent,0->subblock */ - -#define CONFIG_IC 0x00000e00 /* Primary Icache size */ -#define CONFIG_DC 0x000001c0 /* Primary Dcache size */ -#define CONFIG_IB 0x00000020 /* Icache block size */ -#define CONFIG_DB 0x00000010 /* Dcache block size */ -#define CONFIG_CU 0x00000008 /* Update on Store-conditional */ -#define CONFIG_K0 0x00000007 /* K0SEG Coherency algorithm */ - -#define CONFIG_UNCACHED 0x00000002 /* K0 is uncached */ -#define CONFIG_NONCOHRNT 0x00000003 -#define CONFIG_COHRNT_EXLWR 0x00000005 -#define CONFIG_SB_SHFT 22 /* shift SB to bit position 0 */ -#define CONFIG_IC_SHFT 9 /* shift IC to bit position 0 */ -#define CONFIG_DC_SHFT 6 /* shift DC to bit position 0 */ -#define CONFIG_BE_SHFT 15 /* shift BE to bit position 0 */ - -/* - * C0_TAGLO definitions for setting/getting cache states and physaddr bits - */ -#define SADDRMASK 0xFFFFE000 /* 31..13 -> scache paddr bits 35..17 */ -#define SVINDEXMASK 0x00000380 /* 9..7: prim virt index bits 14..12 */ -#define SSTATEMASK 0x00001c00 /* bits 12..10 hold scache line state */ -#define SINVALID 0x00000000 /* invalid --> 000 == state 0 */ -#define SCLEANEXCL 0x00001000 /* clean exclusive --> 100 == state 4 */ -#define SDIRTYEXCL 0x00001400 /* dirty exclusive --> 101 == state 5 */ -#define SECC_MASK 0x0000007f /* low 7 bits are ecc for the tag */ -#define SADDR_SHIFT 4 /* shift STagLo (31..13) to 35..17 */ - -#define PADDRMASK 0xFFFFFF00 /* PTagLo31..8->prim paddr bits35..12 */ -#define PADDR_SHIFT 4 /* roll bits 35..12 down to 31..8 */ -#define PSTATEMASK 0x00C0 /* bits 7..6 hold primary line state */ -#define PINVALID 0x0000 /* invalid --> 000 == state 0 */ -#define PCLEANEXCL 0x0080 /* clean exclusive --> 10 == state 2 */ -#define PDIRTYEXCL 0x00C0 /* dirty exclusive --> 11 == state 3 */ -#define PPARITY_MASK 0x0001 /* low bit is parity bit (even). */ - -/* - * C0_CACHE_ERR definitions. - */ -#define CACHERR_ER 0x80000000 /* 0: inst ref, 1: data ref */ -#define CACHERR_EC 0x40000000 /* 0: primary, 1: secondary */ -#define CACHERR_ED 0x20000000 /* 1: data error */ -#define CACHERR_ET 0x10000000 /* 1: tag error */ -#define CACHERR_ES 0x08000000 /* 1: external ref, e.g. snoop*/ -#define CACHERR_EE 0x04000000 /* error on SysAD bus */ -#define CACHERR_EB 0x02000000 /* complicated, see spec. */ -#define CACHERR_EI 0x01000000 /* complicated, see spec. */ -#define CACHERR_SIDX_MASK 0x003ffff8 /* secondary cache index */ -#define CACHERR_PIDX_MASK 0x00000007 /* primary cache index */ -#define CACHERR_PIDX_SHIFT 12 /* bits 2..0 are paddr14..12 */ - -/* R4000 family supports hardware watchpoints: - * C0_WATCHLO: - * bits 31..3 are bits 31..3 of physaddr to watch - * bit 2: reserved; must be written as 0. - * bit 1: when set causes a watchpoint trap on load accesses to paddr. - * bit 0: when set traps on stores to paddr; - * C0_WATCHHI - * bits 31..4 are reserved and must be written as zeros. - * bits 3..0 are bits 35..32 of the physaddr to watch - */ -#define WATCHLO_WTRAP 0x00000001 -#define WATCHLO_RTRAP 0x00000002 -#define WATCHLO_ADDRMASK 0xfffffff8 -#define WATCHLO_VALIDMASK 0xfffffffb -#define WATCHHI_VALIDMASK 0x0000000f - -/* - * Coprocessor 0 registers - */ -#ifdef _LANGUAGE_ASSEMBLY -#define C0_INX $0 -#define C0_RAND $1 -#define C0_ENTRYLO0 $2 -#define C0_ENTRYLO1 $3 -#define C0_CONTEXT $4 -#define C0_PAGEMASK $5 /* page mask */ -#define C0_WIRED $6 /* # wired entries in tlb */ -#define C0_BADVADDR $8 -#define C0_COUNT $9 /* free-running counter */ -#define C0_ENTRYHI $10 -#define C0_SR $12 -#define C0_CAUSE $13 -#define C0_EPC $14 -#define C0_PRID $15 /* revision identifier */ -#define C0_COMPARE $11 /* counter comparison reg. */ -#define C0_CONFIG $16 /* hardware configuration */ -#define C0_LLADDR $17 /* load linked address */ -#define C0_WATCHLO $18 /* watchpoint */ -#define C0_WATCHHI $19 /* watchpoint */ -#define C0_ECC $26 /* S-cache ECC and primary parity */ -#define C0_CACHE_ERR $27 /* cache error status */ -#define C0_TAGLO $28 /* cache operations */ -#define C0_TAGHI $29 /* cache operations */ -#define C0_ERROR_EPC $30 /* ECC error prg. counter */ - -# else /* ! _LANGUAGE_ASSEMBLY */ - -#define C0_INX 0 -#define C0_RAND 1 -#define C0_ENTRYLO0 2 -#define C0_ENTRYLO1 3 -#define C0_CONTEXT 4 -#define C0_PAGEMASK 5 /* page mask */ -#define C0_WIRED 6 /* # wired entries in tlb */ -#define C0_BADVADDR 8 -#define C0_COUNT 9 /* free-running counter */ -#define C0_ENTRYHI 10 -#define C0_SR 12 -#define C0_CAUSE 13 -#define C0_EPC 14 -#define C0_PRID 15 /* revision identifier */ -#define C0_COMPARE 11 /* counter comparison reg. */ -#define C0_CONFIG 16 /* hardware configuration */ -#define C0_LLADDR 17 /* load linked address */ -#define C0_WATCHLO 18 /* watchpoint */ -#define C0_WATCHHI 19 /* watchpoint */ -#define C0_ECC 26 /* S-cache ECC and primary parity */ -#define C0_CACHE_ERR 27 /* cache error status */ -#define C0_TAGLO 28 /* cache operations */ -#define C0_TAGHI 29 /* cache operations */ -#define C0_ERROR_EPC 30 /* ECC error prg. counter */ - -#endif /* _LANGUAGE_ASSEMBLY */ - -/* - * floating-point status register - */ -#define FPCSR_FS 0x01000000 /* flush denorm to zero */ -#define FPCSR_C 0x00800000 /* condition bit */ -#define FPCSR_CE 0x00020000 /* cause: unimplemented operation */ -#define FPCSR_CV 0x00010000 /* cause: invalid operation */ -#define FPCSR_CZ 0x00008000 /* cause: division by zero */ -#define FPCSR_CO 0x00004000 /* cause: overflow */ -#define FPCSR_CU 0x00002000 /* cause: underflow */ -#define FPCSR_CI 0x00001000 /* cause: inexact operation */ -#define FPCSR_EV 0x00000800 /* enable: invalid operation */ -#define FPCSR_EZ 0x00000400 /* enable: division by zero */ -#define FPCSR_EO 0x00000200 /* enable: overflow */ -#define FPCSR_EU 0x00000100 /* enable: underflow */ -#define FPCSR_EI 0x00000080 /* enable: inexact operation */ -#define FPCSR_FV 0x00000040 /* flag: invalid operation */ -#define FPCSR_FZ 0x00000020 /* flag: division by zero */ -#define FPCSR_FO 0x00000010 /* flag: overflow */ -#define FPCSR_FU 0x00000008 /* flag: underflow */ -#define FPCSR_FI 0x00000004 /* flag: inexact operation */ -#define FPCSR_RM_MASK 0x00000003 /* rounding mode mask */ -#define FPCSR_RM_RN 0x00000000 /* round to nearest */ -#define FPCSR_RM_RZ 0x00000001 /* round to zero */ -#define FPCSR_RM_RP 0x00000002 /* round to positive infinity */ -#define FPCSR_RM_RM 0x00000003 /* round to negative infinity */ - -#endif /* __R4300_H */ diff --git a/lib/ultralib/include/PR/abi.h b/lib/ultralib/include/PR/abi.h deleted file mode 100644 index e121526..0000000 --- a/lib/ultralib/include/PR/abi.h +++ /dev/null @@ -1,410 +0,0 @@ -#ifndef _ABI_H_ -#define _ABI_H_ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.32 $ - * $Date: 1997/02/11 08:16:37 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/abi.h,v $ - * - **************************************************************************/ - -/* - * Header file for the Audio Binary Interface. - * This is included in the Media Binary Interface file - * mbi.h. - * - * This file follows the framework used for graphics. - * - */ - -/* Audio commands: */ -#define A_SPNOOP 0 -#define A_ADPCM 1 -#define A_CLEARBUFF 2 -#define A_ENVMIXER 3 -#define A_LOADBUFF 4 -#define A_RESAMPLE 5 -#define A_SAVEBUFF 6 -#define A_SEGMENT 7 -#define A_SETBUFF 8 -#define A_SETVOL 9 -#define A_DMEMMOVE 10 -#define A_LOADADPCM 11 -#define A_MIXER 12 -#define A_INTERLEAVE 13 -#define A_POLEF 14 -#define A_SETLOOP 15 - -#define ACMD_SIZE 32 -/* - * Audio flags - */ - -#define A_INIT 0x01 -#define A_CONTINUE 0x00 -#define A_LOOP 0x02 -#define A_OUT 0x02 -#define A_LEFT 0x02 -#define A_RIGHT 0x00 -#define A_VOL 0x04 -#define A_RATE 0x00 -#define A_AUX 0x08 -#define A_NOAUX 0x00 -#define A_MAIN 0x00 -#define A_MIX 0x10 - -/* - * BEGIN C-specific section: (typedef's) - */ -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* - * Data Structures. - */ - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int addr; -} Aadpcm; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int addr; -} Apolef; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; -} Aenvelope; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int dmem:16; - unsigned int pad2:16; - unsigned int count:16; -} Aclearbuff; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int pad2:16; - unsigned int inL:16; - unsigned int inR:16; -} Ainterleave; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int addr; -} Aloadbuff; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; -} Aenvmixer; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int dmemi:16; - unsigned int dmemo:16; -} Amixer; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int dmem2:16; - unsigned int addr; -} Apan; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pitch:16; - unsigned int addr; -} Aresample; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; -} Areverb; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int addr; -} Asavebuff; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int pad2:2; - unsigned int number:4; - unsigned int base:24; -} Asegment; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int dmemin:16; - unsigned int dmemout:16; - unsigned int count:16; -} Asetbuff; - -typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int vol:16; - unsigned int voltgt:16; - unsigned int volrate:16; -} Asetvol; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int dmemin:16; - unsigned int dmemout:16; - unsigned int count:16; -} Admemmove; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int count:16; - unsigned int addr; -} Aloadadpcm; - -typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int pad2:16; - unsigned int addr; -} Asetloop; - -/* - * Generic Acmd Packet - */ - -typedef struct { - unsigned int w0; - unsigned int w1; -} Awords; - -typedef union { - Awords words; - Aadpcm adpcm; - Apolef polef; - Aclearbuff clearbuff; - Aenvelope envelope; - Ainterleave interleave; - Aloadbuff loadbuff; - Aenvmixer envmixer; - Aresample resample; - Areverb reverb; - Asavebuff savebuff; - Asegment segment; - Asetbuff setbuff; - Asetvol setvol; - Admemmove dmemmove; - Aloadadpcm loadadpcm; - Amixer mixer; - Asetloop setloop; - long long int force_union_align; /* dummy, force alignment */ -} Acmd; - -/* - * ADPCM State - */ -#define ADPCMVSIZE 8 -#define ADPCMFSIZE 16 -typedef short ADPCM_STATE[ADPCMFSIZE]; - -/* - * Pole filter state - */ -typedef short POLEF_STATE[4]; - -/* - * Resampler state - */ -typedef short RESAMPLE_STATE[16]; - -/* - * Resampler constants - */ -#define UNITY_PITCH 0x8000 -#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */ - -/* - * Enveloper/Mixer state - */ -typedef short ENVMIX_STATE[40]; - -/* - * Macros to assemble the audio command list - */ - -#define aADPCMdec(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (unsigned int)(s); \ -} - -#define aPoleFilter(pkt, f, g, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ -} - -#define aClearBuffer(pkt, d, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_CLEARBUFF, 24, 8) | _SHIFTL(d, 0, 24); \ - _a->words.w1 = (unsigned int)(c); \ -} - -#define aEnvMixer(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ENVMIXER, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (unsigned int)(s); \ -} - -#define aInterleave(pkt, l, r) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8); \ - _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ -} - -#define aLoadBuffer(pkt, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8); \ - _a->words.w1 = (unsigned int)(s); \ -} - -#define aMix(pkt, f, g, i, o) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = _SHIFTL(i,16, 16) | _SHIFTL(o, 0, 16); \ -} - -#define aPan(pkt, f, d, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(d, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ -} - -#define aResample(pkt, f, p, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | _SHIFTL(f, 16, 8) |\ - _SHIFTL(p, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ -} - -#define aSaveBuffer(pkt, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8); \ - _a->words.w1 = (unsigned int)(s); \ -} - -#define aSegment(pkt, s, b) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ - _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ -} - -#define aSetBuffer(pkt, f, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(i, 0, 16)); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ -} - -#define aSetVolume(pkt, f, v, t, r) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ - _SHIFTL(v, 0, 16)); \ - _a->words.w1 = _SHIFTL(t, 16, 16) | _SHIFTL(r, 0, 16); \ -} - -#define aSetLoop(pkt, a) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - _a->words.w0 = _SHIFTL(A_SETLOOP, 24, 8); \ - _a->words.w1 = (unsigned int)(a); \ -} - -#define aDMEMMove(pkt, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ -} - -#define aLoadADPCM(pkt, c, d) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ - _a->words.w1 = (unsigned int) d; \ -} - -#endif /* _LANGUAGE_C */ - -#endif /* !_ABI_H_ */ - - - diff --git a/lib/ultralib/include/PR/gbi.h b/lib/ultralib/include/PR/gbi.h deleted file mode 100644 index 80ba602..0000000 --- a/lib/ultralib/include/PR/gbi.h +++ /dev/null @@ -1,4572 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ -/************************************************************************** - * - * $Revision: 1.141 $ - * $Date: 1999/09/03 03:43:08 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gbi.h,v $ - * - **************************************************************************/ - -#ifndef _GBI_H_ -#define _GBI_H_ - -#include - -/* - * To use the F3DEX ucodes, define F3DEX_GBI before include this file. - * - * #define F3DEX_GBI - * #include - * - * or - * - * cc -c -DF3DEX_GBI -I.... foo.c - * - */ - -/************************************************************************** - * - * Graphics Binary Interface - * - **************************************************************************/ - -/* - * Graphics Commands, 'xxx' parts may be generated from ucode - * - * The command format is - * - * |00xxxxxx| = DMA 0,..,127 - * |10xxxxxx| = Immediate Mode -65,..,-128 - * |11xxxxxx| = RDP cmds -1,..,-64 - * - * Note: in order for the RSP microcode to process RDP commands opaquely, - * we need to further identify those RDP commands that need DRAM address - * "fixup". To do this, we have the dummy command G_RDP_ADDR_FIXUP, and - * all |RDP commands| less than this are commands with embedded DRAM - * addresses. Further, the format of these commands should be similar so - * only one fixup routine is needed. - * - * Further explanation: - * The names of the commands are somewhat misleading. Here is clarification: - * - * - a 'DMA' type command has a pointer to additional data and - * causes a DMA transfer to bring that into DMEM. - * - * - an 'Immediate' type command isn't really 'immediate', in the - * traditional sense. This just means that the entire command fits - * in the 64-bit word, and the ucode can execute it 'immediately' - * without additional memory transfers. - * - * - an 'RDP' command is identified as such because the RDP - * commands can be passed-thru the RSP and sent to the RDP - * directly. One further confusing thing, is that some 'DP' - * macros below actually generate immediate commands, not - * not direct DP commands. - * - * IMPLEMENTATION NOTE: - * There is another group of RDP commands that includes the triangle commands - * generated by the RSP code. These are the raw commands the rasterizer - * hardware chews on, with slope info, etc. They will follow the RDP - * ordering... - * - * IMPLEMENTATION NOTE: - * The RDP hardware has some of these bit patterns wired up. If the hardware - * changes, we must adjust this table, likewise we can't change/add things - * once the hardware is frozen. (actually, the RDP hardware only looks at - * the lower 6 bits of the command byte) - * - */ - -#ifdef F3DEX_GBI_2 -# ifndef F3DEX_GBI -# define F3DEX_GBI -# endif -#define G_NOOP 0x00 -#define G_RDPHALF_2 0xf1 -#define G_SETOTHERMODE_H 0xe3 -#define G_SETOTHERMODE_L 0xe2 -#define G_RDPHALF_1 0xe1 -#define G_SPNOOP 0xe0 -#define G_ENDDL 0xdf -#define G_DL 0xde -#define G_LOAD_UCODE 0xdd -#define G_MOVEMEM 0xdc -#define G_MOVEWORD 0xdb -#define G_MTX 0xda -#define G_GEOMETRYMODE 0xd9 -#define G_POPMTX 0xd8 -#define G_TEXTURE 0xd7 -#define G_DMA_IO 0xd6 -#define G_SPECIAL_1 0xd5 -#define G_SPECIAL_2 0xd4 -#define G_SPECIAL_3 0xd3 - -#define G_VTX 0x01 -#define G_MODIFYVTX 0x02 -#define G_CULLDL 0x03 -#define G_BRANCH_Z 0x04 -#define G_TRI1 0x05 -#define G_TRI2 0x06 -#define G_QUAD 0x07 -#define G_LINE3D 0x08 -#else /* F3DEX_GBI_2 */ - -/* DMA commands: */ -#define G_SPNOOP 0 /* handle 0 gracefully */ -#define G_MTX 1 -#define G_RESERVED0 2 /* not implemeted */ -#define G_MOVEMEM 3 /* move a block of memory (up to 4 words) to dmem */ -#define G_VTX 4 -#define G_RESERVED1 5 /* not implemeted */ -#define G_DL 6 -#define G_RESERVED2 7 /* not implemeted */ -#define G_RESERVED3 8 /* not implemeted */ -#define G_SPRITE2D_BASE 9 /* sprite command */ - -/* IMMEDIATE commands: */ -#define G_IMMFIRST -65 -#define G_TRI1 (G_IMMFIRST-0) -#define G_CULLDL (G_IMMFIRST-1) -#define G_POPMTX (G_IMMFIRST-2) -#define G_MOVEWORD (G_IMMFIRST-3) -#define G_TEXTURE (G_IMMFIRST-4) -#define G_SETOTHERMODE_H (G_IMMFIRST-5) -#define G_SETOTHERMODE_L (G_IMMFIRST-6) -#define G_ENDDL (G_IMMFIRST-7) -#define G_SETGEOMETRYMODE (G_IMMFIRST-8) -#define G_CLEARGEOMETRYMODE (G_IMMFIRST-9) -#define G_LINE3D (G_IMMFIRST-10) -#define G_RDPHALF_1 (G_IMMFIRST-11) -#define G_RDPHALF_2 (G_IMMFIRST-12) -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define G_MODIFYVTX (G_IMMFIRST-13) -# define G_TRI2 (G_IMMFIRST-14) -# define G_BRANCH_Z (G_IMMFIRST-15) -# define G_LOAD_UCODE (G_IMMFIRST-16) -#else -# define G_RDPHALF_CONT (G_IMMFIRST-13) -#endif - -/* We are overloading 2 of the immediate commands - to keep the byte alignment of dmem the same */ - -#define G_SPRITE2D_SCALEFLIP (G_IMMFIRST-1) -#define G_SPRITE2D_DRAW (G_IMMFIRST-2) - -/* RDP commands: */ -#define G_NOOP 0xc0 /* 0 */ - -#endif /* F3DEX_GBI_2 */ - -/* RDP commands: */ -#define G_SETCIMG 0xff /* -1 */ -#define G_SETZIMG 0xfe /* -2 */ -#define G_SETTIMG 0xfd /* -3 */ -#define G_SETCOMBINE 0xfc /* -4 */ -#define G_SETENVCOLOR 0xfb /* -5 */ -#define G_SETPRIMCOLOR 0xfa /* -6 */ -#define G_SETBLENDCOLOR 0xf9 /* -7 */ -#define G_SETFOGCOLOR 0xf8 /* -8 */ -#define G_SETFILLCOLOR 0xf7 /* -9 */ -#define G_FILLRECT 0xf6 /* -10 */ -#define G_SETTILE 0xf5 /* -11 */ -#define G_LOADTILE 0xf4 /* -12 */ -#define G_LOADBLOCK 0xf3 /* -13 */ -#define G_SETTILESIZE 0xf2 /* -14 */ -#define G_LOADTLUT 0xf0 /* -16 */ -#define G_RDPSETOTHERMODE 0xef /* -17 */ -#define G_SETPRIMDEPTH 0xee /* -18 */ -#define G_SETSCISSOR 0xed /* -19 */ -#define G_SETCONVERT 0xec /* -20 */ -#define G_SETKEYR 0xeb /* -21 */ -#define G_SETKEYGB 0xea /* -22 */ -#define G_RDPFULLSYNC 0xe9 /* -23 */ -#define G_RDPTILESYNC 0xe8 /* -24 */ -#define G_RDPPIPESYNC 0xe7 /* -25 */ -#define G_RDPLOADSYNC 0xe6 /* -26 */ -#define G_TEXRECTFLIP 0xe5 /* -27 */ -#define G_TEXRECT 0xe4 /* -28 */ - - -/* - * The following commands are the "generated" RDP commands; the user - * never sees them, the RSP microcode generates them. - * - * The layout of the bits is magical, to save work in the ucode. - * These id's are -56, -52, -54, -50, -55, -51, -53, -49, ... - * edge, shade, texture, zbuff bits: estz - */ -#define G_TRI_FILL 0xc8 /* fill triangle: 11001000 */ -#define G_TRI_SHADE 0xcc /* shade triangle: 11001100 */ -#define G_TRI_TXTR 0xca /* texture triangle: 11001010 */ -#define G_TRI_SHADE_TXTR 0xce /* shade, texture triangle: 11001110 */ -#define G_TRI_FILL_ZBUFF 0xc9 /* fill, zbuff triangle: 11001001 */ -#define G_TRI_SHADE_ZBUFF 0xcd /* shade, zbuff triangle: 11001101 */ -#define G_TRI_TXTR_ZBUFF 0xcb /* texture, zbuff triangle: 11001011 */ -#define G_TRI_SHADE_TXTR_ZBUFF 0xcf /* shade, txtr, zbuff trngl: 11001111 */ - -/* - * A TRI_FILL triangle is just the edges. You need to set the DP - * to use primcolor, in order to see anything. (it is NOT a triangle - * that gets rendered in 'fill mode'. Triangles can't be rendered - * in 'fill mode') - * - * A TRI_SHADE is a gouraud triangle that has colors interpolated. - * Flat-shaded triangles (from the software) are still gouraud shaded, - * it's just the colors are all the same and the deltas are 0. - * - * Other triangle types, and combinations are more obvious. - */ - -/* masks to build RDP triangle commands: */ -#define G_RDP_TRI_FILL_MASK 0x08 -#define G_RDP_TRI_SHADE_MASK 0x04 -#define G_RDP_TRI_TXTR_MASK 0x02 -#define G_RDP_TRI_ZBUFF_MASK 0x01 - -/* - * HACK: - * This is a dreadful hack. For version 1.0 hardware, there are still - * some 'bowtie' hangs. This parameter can be increased to avoid - * the hangs. Every increase of 4 chops one scanline off of every - * triangle. Values of 4,8,12 should be sufficient to avoid any - * bowtie hang. - * - * Change this value, then recompile ALL of your program (including static - * display lists!) - * - * THIS WILL BE REMOVED FOR HARDWARE VERSION 2.0! - */ -#define BOWTIE_VAL 0 - - -/* gets added to RDP command, in order to test for addres fixup: */ -#define G_RDP_ADDR_FIXUP 3 /* |RDP cmds| <= this, do addr fixup */ -#ifdef _LANGUAGE_ASSEMBLY -#define G_RDP_TEXRECT_CHECK ((-1*G_TEXRECTFLIP)& 0xff) -#endif - -/* macros for command parsing: */ -#define GDMACMD(x) (x) -#define GIMMCMD(x) (G_IMMFIRST-(x)) -#define GRDPCMD(x) (0xff-(x)) - -#define G_DMACMDSIZ 128 -#define G_IMMCMDSIZ 64 -#define G_RDPCMDSIZ 64 - -/* - * Coordinate shift values, number of bits of fraction - */ -#define G_TEXTURE_IMAGE_FRAC 2 -#define G_TEXTURE_SCALE_FRAC 16 -#define G_SCALE_FRAC 8 -#define G_ROTATE_FRAC 16 - -/* - * Parameters to graphics commands - */ - -/* - * Data packing macros - */ - -/* - * Maximum z-buffer value, used to initialize the z-buffer. - * Note : this number is NOT the viewport z-scale constant. - * See the comment next to G_MAXZ for more info. - */ -#define G_MAXFBZ 0x3fff /* 3b exp, 11b mantissa */ - -#define GPACK_RGBA5551(r, g, b, a) ((((r)<<8) & 0xf800) | \ - (((g)<<3) & 0x7c0) | \ - (((b)>>2) & 0x3e) | ((a) & 0x1)) -#define GPACK_ZDZ(z, dz) ((z) << 2 | (dz)) - -/* - * G_MTX: parameter flags - */ -#ifdef F3DEX_GBI_2 -# define G_MTX_MODELVIEW 0x00 /* matrix types */ -# define G_MTX_PROJECTION 0x04 -# define G_MTX_MUL 0x00 /* concat or load */ -# define G_MTX_LOAD 0x02 -# define G_MTX_NOPUSH 0x00 /* push or not */ -# define G_MTX_PUSH 0x01 -#else /* F3DEX_GBI_2 */ -# define G_MTX_MODELVIEW 0x00 /* matrix types */ -# define G_MTX_PROJECTION 0x01 -# define G_MTX_MUL 0x00 /* concat or load */ -# define G_MTX_LOAD 0x02 -# define G_MTX_NOPUSH 0x00 /* push or not */ -# define G_MTX_PUSH 0x04 -#endif /* F3DEX_GBI_2 */ - -/* - * flags for G_SETGEOMETRYMODE - * (this rendering state is maintained in RSP) - * - * DO NOT USE THE LOW 8 BITS OF GEOMETRYMODE: - * The weird bit-ordering is for the micro-code: the lower byte - * can be OR'd in with G_TRI_SHADE (11001100) to construct - * the triangle command directly. Don't break it... - * - * DO NOT USE THE HIGH 8 BITS OF GEOMETRYMODE: - * The high byte is OR'd with 0x703 to form the clip code mask. - * If it is set to 0x04, this will cause near clipping to occur. - * If it is zero, near clipping will not occur. - * - * Further explanation: - * G_SHADE is necessary in order to see the color that you passed - * down with the vertex. If G_SHADE isn't set, you need to set the DP - * appropriately and use primcolor to see anything. - * - * G_SHADING_SMOOTH enabled means use all 3 colors of the triangle. - * If it is not set, then do 'flat shading', where only one vertex color - * is used (and all 3 vertices are set to that same color by the ucode) - * See the man page for gSP1Triangle(). - * - */ -#define G_ZBUFFER 0x00000001 -#define G_SHADE 0x00000004 /* enable Gouraud interp */ -/* rest of low byte reserved for setup ucode */ -#ifdef F3DEX_GBI_2 -# define G_TEXTURE_ENABLE 0x00000000 /* Ignored */ -# define G_SHADING_SMOOTH 0x00200000 /* flat or smooth shaded */ -# define G_CULL_FRONT 0x00000200 -# define G_CULL_BACK 0x00000400 -# define G_CULL_BOTH 0x00000600 /* To make code cleaner */ -#else -# define G_TEXTURE_ENABLE 0x00000002 /* Microcode use only */ -# define G_SHADING_SMOOTH 0x00000200 /* flat or smooth shaded */ -# define G_CULL_FRONT 0x00001000 -# define G_CULL_BACK 0x00002000 -# define G_CULL_BOTH 0x00003000 /* To make code cleaner */ -#endif -#define G_FOG 0x00010000 -#define G_LIGHTING 0x00020000 -#define G_TEXTURE_GEN 0x00040000 -#define G_TEXTURE_GEN_LINEAR 0x00080000 -#define G_LOD 0x00100000 /* NOT IMPLEMENTED */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define G_CLIPPING 0x00800000 -#else -# define G_CLIPPING 0x00000000 -#endif - -#ifdef _LANGUAGE_ASSEMBLY -#define G_FOG_H (G_FOG/0x10000) -#define G_LIGHTING_H (G_LIGHTING/0x10000) -#define G_TEXTURE_GEN_H (G_TEXTURE_GEN/0x10000) -#define G_TEXTURE_GEN_LINEAR_H (G_TEXTURE_GEN_LINEAR/0x10000) -#define G_LOD_H (G_LOD/0x10000) /* NOT IMPLEMENTED */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define G_CLIPPING_H (G_CLIPPING/0x10000) -#endif -#endif - -/* Need these defined for Sprite Microcode */ -#ifdef _LANGUAGE_ASSEMBLY -#define G_TX_LOADTILE 7 -#define G_TX_RENDERTILE 0 - -#define G_TX_NOMIRROR 0 -#define G_TX_WRAP 0 -#define G_TX_MIRROR 0x1 -#define G_TX_CLAMP 0x2 -#define G_TX_NOMASK 0 -#define G_TX_NOLOD 0 -#endif - -/* - * G_SETIMG fmt: set image formats - */ -#define G_IM_FMT_RGBA 0 -#define G_IM_FMT_YUV 1 -#define G_IM_FMT_CI 2 -#define G_IM_FMT_IA 3 -#define G_IM_FMT_I 4 - -/* - * G_SETIMG siz: set image pixel size - */ -#define G_IM_SIZ_4b 0 -#define G_IM_SIZ_8b 1 -#define G_IM_SIZ_16b 2 -#define G_IM_SIZ_32b 3 -#define G_IM_SIZ_DD 5 - -#define G_IM_SIZ_4b_BYTES 0 -#define G_IM_SIZ_4b_TILE_BYTES G_IM_SIZ_4b_BYTES -#define G_IM_SIZ_4b_LINE_BYTES G_IM_SIZ_4b_BYTES - -#define G_IM_SIZ_8b_BYTES 1 -#define G_IM_SIZ_8b_TILE_BYTES G_IM_SIZ_8b_BYTES -#define G_IM_SIZ_8b_LINE_BYTES G_IM_SIZ_8b_BYTES - -#define G_IM_SIZ_16b_BYTES 2 -#define G_IM_SIZ_16b_TILE_BYTES G_IM_SIZ_16b_BYTES -#define G_IM_SIZ_16b_LINE_BYTES G_IM_SIZ_16b_BYTES - -#define G_IM_SIZ_32b_BYTES 4 -#define G_IM_SIZ_32b_TILE_BYTES 2 -#define G_IM_SIZ_32b_LINE_BYTES 2 - -#define G_IM_SIZ_4b_LOAD_BLOCK G_IM_SIZ_16b -#define G_IM_SIZ_8b_LOAD_BLOCK G_IM_SIZ_16b -#define G_IM_SIZ_16b_LOAD_BLOCK G_IM_SIZ_16b -#define G_IM_SIZ_32b_LOAD_BLOCK G_IM_SIZ_32b - -#define G_IM_SIZ_4b_SHIFT 2 -#define G_IM_SIZ_8b_SHIFT 1 -#define G_IM_SIZ_16b_SHIFT 0 -#define G_IM_SIZ_32b_SHIFT 0 - -#define G_IM_SIZ_4b_INCR 3 -#define G_IM_SIZ_8b_INCR 1 -#define G_IM_SIZ_16b_INCR 0 -#define G_IM_SIZ_32b_INCR 0 - -/* - * G_SETCOMBINE: color combine modes - */ -/* Color combiner constants: */ -#define G_CCMUX_COMBINED 0 -#define G_CCMUX_TEXEL0 1 -#define G_CCMUX_TEXEL1 2 -#define G_CCMUX_PRIMITIVE 3 -#define G_CCMUX_SHADE 4 -#define G_CCMUX_ENVIRONMENT 5 -#define G_CCMUX_CENTER 6 -#define G_CCMUX_SCALE 6 -#define G_CCMUX_COMBINED_ALPHA 7 -#define G_CCMUX_TEXEL0_ALPHA 8 -#define G_CCMUX_TEXEL1_ALPHA 9 -#define G_CCMUX_PRIMITIVE_ALPHA 10 -#define G_CCMUX_SHADE_ALPHA 11 -#define G_CCMUX_ENV_ALPHA 12 -#define G_CCMUX_LOD_FRACTION 13 -#define G_CCMUX_PRIM_LOD_FRAC 14 -#define G_CCMUX_NOISE 7 -#define G_CCMUX_K4 7 -#define G_CCMUX_K5 15 -#define G_CCMUX_1 6 -#define G_CCMUX_0 31 - -/* Alpha combiner constants: */ -#define G_ACMUX_COMBINED 0 -#define G_ACMUX_TEXEL0 1 -#define G_ACMUX_TEXEL1 2 -#define G_ACMUX_PRIMITIVE 3 -#define G_ACMUX_SHADE 4 -#define G_ACMUX_ENVIRONMENT 5 -#define G_ACMUX_LOD_FRACTION 0 -#define G_ACMUX_PRIM_LOD_FRAC 6 -#define G_ACMUX_1 6 -#define G_ACMUX_0 7 - -/* typical CC cycle 1 modes */ -#define G_CC_PRIMITIVE 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE -#define G_CC_SHADE 0, 0, 0, SHADE, 0, 0, 0, SHADE -#define G_CC_MODULATEI TEXEL0, 0, SHADE, 0, 0, 0, 0, SHADE -#define G_CC_MODULATEIA TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0 -#define G_CC_MODULATEIDECALA TEXEL0, 0, SHADE, 0, 0, 0, 0, TEXEL0 -#define G_CC_MODULATERGB G_CC_MODULATEI -#define G_CC_MODULATERGBA G_CC_MODULATEIA -#define G_CC_MODULATERGBDECALA G_CC_MODULATEIDECALA -#define G_CC_MODULATEI_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE -#define G_CC_MODULATEIA_PRIM TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0 -#define G_CC_MODULATEIDECALA_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0 -#define G_CC_MODULATERGB_PRIM G_CC_MODULATEI_PRIM -#define G_CC_MODULATERGBA_PRIM G_CC_MODULATEIA_PRIM -#define G_CC_MODULATERGBDECALA_PRIM G_CC_MODULATEIDECALA_PRIM -#define G_CC_DECALRGB 0, 0, 0, TEXEL0, 0, 0, 0, SHADE -#define G_CC_DECALRGBA 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0 -#define G_CC_BLENDI ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDIA ENVIRONMENT, SHADE, TEXEL0, SHADE, TEXEL0, 0, SHADE, 0 -#define G_CC_BLENDIDECALA ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_BLENDRGBA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDRGBDECALA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_ADDRGB 1, 0, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_ADDRGBDECALA 1, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_REFLECTRGB ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_REFLECTRGBDECALA ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_HILITERGB PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_HILITERGBA PRIMITIVE, SHADE, TEXEL0, SHADE, PRIMITIVE, SHADE, TEXEL0, SHADE -#define G_CC_HILITERGBDECALA PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_SHADEDECALA 0, 0, 0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_BLENDPE PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, SHADE, 0 -#define G_CC_BLENDPEDECALA PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, TEXEL0 - -/* oddball modes */ -#define _G_CC_BLENDPE ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, SHADE, 0 -#define _G_CC_BLENDPEDECALA ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, 0, 0, 0, TEXEL0 -#define _G_CC_TWOCOLORTEX PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE -/* used for 1-cycle sparse mip-maps, primitive color has color of lowest LOD */ -#define _G_CC_SPARSEST PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0, PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0 -#define G_CC_TEMPLERP TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0 - -/* typical CC cycle 1 modes, usually followed by other cycle 2 modes */ -#define G_CC_TRILERP TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0, TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0 -#define G_CC_INTERFERENCE TEXEL0, 0, TEXEL1, 0, TEXEL0, 0, TEXEL1, 0 - -/* - * One-cycle color convert operation - */ -#define G_CC_1CYUV2RGB TEXEL0, K4, K5, TEXEL0, 0, 0, 0, SHADE - -/* - * NOTE: YUV2RGB expects TF step1 color conversion to occur in 2nd clock. - * Therefore, CC looks for step1 results in TEXEL1 - */ -#define G_CC_YUV2RGB TEXEL1, K4, K5, TEXEL1, 0, 0, 0, 0 - -/* typical CC cycle 2 modes */ -#define G_CC_PASS2 0, 0, 0, COMBINED, 0, 0, 0, COMBINED -#define G_CC_MODULATEI2 COMBINED, 0, SHADE, 0, 0, 0, 0, SHADE -#define G_CC_MODULATEIA2 COMBINED, 0, SHADE, 0, COMBINED, 0, SHADE, 0 -#define G_CC_MODULATERGB2 G_CC_MODULATEI2 -#define G_CC_MODULATERGBA2 G_CC_MODULATEIA2 -#define G_CC_MODULATEI_PRIM2 COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE -#define G_CC_MODULATEIA_PRIM2 COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0 -#define G_CC_MODULATERGB_PRIM2 G_CC_MODULATEI_PRIM2 -#define G_CC_MODULATERGBA_PRIM2 G_CC_MODULATEIA_PRIM2 -#define G_CC_DECALRGB2 0, 0, 0, COMBINED, 0, 0, 0, SHADE -/* - * ? -#define G_CC_DECALRGBA2 COMBINED, SHADE, COMBINED_ALPHA, SHADE, 0, 0, 0, SHADE -*/ -#define G_CC_BLENDI2 ENVIRONMENT, SHADE, COMBINED, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDIA2 ENVIRONMENT, SHADE, COMBINED, SHADE, COMBINED, 0, SHADE, 0 -#define G_CC_CHROMA_KEY2 TEXEL0, CENTER, SCALE, 0, 0, 0, 0, 0 -#define G_CC_HILITERGB2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, SHADE -#define G_CC_HILITERGBA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, ENVIRONMENT, COMBINED, TEXEL0, COMBINED -#define G_CC_HILITERGBDECALA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, TEXEL0 -#define G_CC_HILITERGBPASSA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, COMBINED - -/* - * G_SETOTHERMODE_L sft: shift count - */ -#define G_MDSFT_ALPHACOMPARE 0 -#define G_MDSFT_ZSRCSEL 2 -#define G_MDSFT_RENDERMODE 3 -#define G_MDSFT_BLENDER 16 - -/* - * G_SETOTHERMODE_H sft: shift count - */ -#define G_MDSFT_BLENDMASK 0 /* unsupported */ -#define G_MDSFT_ALPHADITHER 4 -#define G_MDSFT_RGBDITHER 6 - -#define G_MDSFT_COMBKEY 8 -#define G_MDSFT_TEXTCONV 9 -#define G_MDSFT_TEXTFILT 12 -#define G_MDSFT_TEXTLUT 14 -#define G_MDSFT_TEXTLOD 16 -#define G_MDSFT_TEXTDETAIL 17 -#define G_MDSFT_TEXTPERSP 19 -#define G_MDSFT_CYCLETYPE 20 -#define G_MDSFT_COLORDITHER 22 /* unsupported in HW 2.0 */ -#define G_MDSFT_PIPELINE 23 - -/* G_SETOTHERMODE_H gPipelineMode */ -#define G_PM_1PRIMITIVE (1 << G_MDSFT_PIPELINE) -#define G_PM_NPRIMITIVE (0 << G_MDSFT_PIPELINE) - -/* G_SETOTHERMODE_H gSetCycleType */ -#define G_CYC_1CYCLE (0 << G_MDSFT_CYCLETYPE) -#define G_CYC_2CYCLE (1 << G_MDSFT_CYCLETYPE) -#define G_CYC_COPY (2 << G_MDSFT_CYCLETYPE) -#define G_CYC_FILL (3 << G_MDSFT_CYCLETYPE) - -/* G_SETOTHERMODE_H gSetTexturePersp */ -#define G_TP_NONE (0 << G_MDSFT_TEXTPERSP) -#define G_TP_PERSP (1 << G_MDSFT_TEXTPERSP) - -/* G_SETOTHERMODE_H gSetTextureDetail */ -#define G_TD_CLAMP (0 << G_MDSFT_TEXTDETAIL) -#define G_TD_SHARPEN (1 << G_MDSFT_TEXTDETAIL) -#define G_TD_DETAIL (2 << G_MDSFT_TEXTDETAIL) - -/* G_SETOTHERMODE_H gSetTextureLOD */ -#define G_TL_TILE (0 << G_MDSFT_TEXTLOD) -#define G_TL_LOD (1 << G_MDSFT_TEXTLOD) - -/* G_SETOTHERMODE_H gSetTextureLUT */ -#define G_TT_NONE (0 << G_MDSFT_TEXTLUT) -#define G_TT_RGBA16 (2 << G_MDSFT_TEXTLUT) -#define G_TT_IA16 (3 << G_MDSFT_TEXTLUT) - -/* G_SETOTHERMODE_H gSetTextureFilter */ -#define G_TF_POINT (0 << G_MDSFT_TEXTFILT) -#define G_TF_AVERAGE (3 << G_MDSFT_TEXTFILT) -#define G_TF_BILERP (2 << G_MDSFT_TEXTFILT) - -/* G_SETOTHERMODE_H gSetTextureConvert */ -#define G_TC_CONV (0 << G_MDSFT_TEXTCONV) -#define G_TC_FILTCONV (5 << G_MDSFT_TEXTCONV) -#define G_TC_FILT (6 << G_MDSFT_TEXTCONV) - -/* G_SETOTHERMODE_H gSetCombineKey */ -#define G_CK_NONE (0 << G_MDSFT_COMBKEY) -#define G_CK_KEY (1 << G_MDSFT_COMBKEY) - -/* G_SETOTHERMODE_H gSetColorDither */ -#define G_CD_MAGICSQ (0 << G_MDSFT_RGBDITHER) -#define G_CD_BAYER (1 << G_MDSFT_RGBDITHER) -#define G_CD_NOISE (2 << G_MDSFT_RGBDITHER) - -#ifndef _HW_VERSION_1 -#define G_CD_DISABLE (3 << G_MDSFT_RGBDITHER) -#define G_CD_ENABLE G_CD_NOISE /* HW 1.0 compatibility mode */ -#else -#define G_CD_ENABLE (1 << G_MDSFT_COLORDITHER) -#define G_CD_DISABLE (0 << G_MDSFT_COLORDITHER) -#endif - -/* G_SETOTHERMODE_H gSetAlphaDither */ -#define G_AD_PATTERN (0 << G_MDSFT_ALPHADITHER) -#define G_AD_NOTPATTERN (1 << G_MDSFT_ALPHADITHER) -#define G_AD_NOISE (2 << G_MDSFT_ALPHADITHER) -#define G_AD_DISABLE (3 << G_MDSFT_ALPHADITHER) - -/* G_SETOTHERMODE_L gSetAlphaCompare */ -#define G_AC_NONE (0 << G_MDSFT_ALPHACOMPARE) -#define G_AC_THRESHOLD (1 << G_MDSFT_ALPHACOMPARE) -#define G_AC_DITHER (3 << G_MDSFT_ALPHACOMPARE) - -/* G_SETOTHERMODE_L gSetDepthSource */ -#define G_ZS_PIXEL (0 << G_MDSFT_ZSRCSEL) -#define G_ZS_PRIM (1 << G_MDSFT_ZSRCSEL) - -/* G_SETOTHERMODE_L gSetRenderMode */ -#define AA_EN 0x8 -#define Z_CMP 0x10 -#define Z_UPD 0x20 -#define IM_RD 0x40 -#define CLR_ON_CVG 0x80 -#define CVG_DST_CLAMP 0 -#define CVG_DST_WRAP 0x100 -#define CVG_DST_FULL 0x200 -#define CVG_DST_SAVE 0x300 -#define ZMODE_OPA 0 -#define ZMODE_INTER 0x400 -#define ZMODE_XLU 0x800 -#define ZMODE_DEC 0xc00 -#define CVG_X_ALPHA 0x1000 -#define ALPHA_CVG_SEL 0x2000 -#define FORCE_BL 0x4000 -#define TEX_EDGE 0x0000 /* used to be 0x8000 */ - -#define G_BL_CLR_IN 0 -#define G_BL_CLR_MEM 1 -#define G_BL_CLR_BL 2 -#define G_BL_CLR_FOG 3 -#define G_BL_1MA 0 -#define G_BL_A_MEM 1 -#define G_BL_A_IN 0 -#define G_BL_A_FOG 1 -#define G_BL_A_SHADE 2 -#define G_BL_1 2 -#define G_BL_0 3 - -#define GBL_c1(m1a, m1b, m2a, m2b) \ - (m1a) << 30 | (m1b) << 26 | (m2a) << 22 | (m2b) << 18 -#define GBL_c2(m1a, m1b, m2a, m2b) \ - (m1a) << 28 | (m1b) << 24 | (m2a) << 20 | (m2b) << 16 - -#define RM_AA_ZB_OPA_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_RA_ZB_OPA_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_ZB_XLU_SURF(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ - FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_OPA_DECAL(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | ALPHA_CVG_SEL | \ - ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_RA_ZB_OPA_DECAL(clk) \ - AA_EN | Z_CMP | CVG_DST_WRAP | ALPHA_CVG_SEL | \ - ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_ZB_XLU_DECAL(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ - FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_OPA_INTER(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ALPHA_CVG_SEL | ZMODE_INTER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_RA_ZB_OPA_INTER(clk) \ - AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ - ALPHA_CVG_SEL | ZMODE_INTER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_ZB_XLU_INTER(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ - FORCE_BL | ZMODE_INTER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_XLU_LINE(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_DEC_LINE(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_TEX_EDGE(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_ZB_TEX_INTER(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_INTER | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_ZB_SUB_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_ZB_PCL_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_OPA_TERR(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_TEX_TERR(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_ZB_SUB_TERR(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - - -#define RM_AA_OPA_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_RA_OPA_SURF(clk) \ - AA_EN | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_XLU_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | \ - ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_XLU_LINE(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_DEC_LINE(clk) \ - AA_EN | IM_RD | CVG_DST_FULL | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_TEX_EDGE(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_SUB_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_AA_PCL_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_OPA_TERR(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_TEX_TERR(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_AA_SUB_TERR(clk) \ - AA_EN | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - - -#define RM_ZB_OPA_SURF(clk) \ - Z_CMP | Z_UPD | CVG_DST_FULL | ALPHA_CVG_SEL | \ - ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_ZB_XLU_SURF(clk) \ - Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_ZB_OPA_DECAL(clk) \ - Z_CMP | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - -#define RM_ZB_XLU_DECAL(clk) \ - Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_ZB_CLD_SURF(clk) \ - Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_ZB_OVL_SURF(clk) \ - Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_ZB_PCL_SURF(clk) \ - Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \ - G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) - - -#define RM_OPA_SURF(clk) \ - CVG_DST_CLAMP | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) - -#define RM_XLU_SURF(clk) \ - IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_TEX_EDGE(clk) \ - CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL |\ - ZMODE_OPA | TEX_EDGE | AA_EN | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) - -#define RM_CLD_SURF(clk) \ - IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define RM_PCL_SURF(clk) \ - CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ - G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) - -#define RM_ADD(clk) \ - IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_1) - -#define RM_NOOP(clk) \ - GBL_c##clk(0, 0, 0, 0) - -#define RM_VISCVG(clk) \ - IM_RD | FORCE_BL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_BL, G_BL_A_MEM) - -/* for rendering to an 8-bit framebuffer */ -#define RM_OPA_CI(clk) \ - CVG_DST_CLAMP | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) - - - -#define G_RM_AA_ZB_OPA_SURF RM_AA_ZB_OPA_SURF(1) -#define G_RM_AA_ZB_OPA_SURF2 RM_AA_ZB_OPA_SURF(2) -#define G_RM_AA_ZB_XLU_SURF RM_AA_ZB_XLU_SURF(1) -#define G_RM_AA_ZB_XLU_SURF2 RM_AA_ZB_XLU_SURF(2) -#define G_RM_AA_ZB_OPA_DECAL RM_AA_ZB_OPA_DECAL(1) -#define G_RM_AA_ZB_OPA_DECAL2 RM_AA_ZB_OPA_DECAL(2) -#define G_RM_AA_ZB_XLU_DECAL RM_AA_ZB_XLU_DECAL(1) -#define G_RM_AA_ZB_XLU_DECAL2 RM_AA_ZB_XLU_DECAL(2) -#define G_RM_AA_ZB_OPA_INTER RM_AA_ZB_OPA_INTER(1) -#define G_RM_AA_ZB_OPA_INTER2 RM_AA_ZB_OPA_INTER(2) -#define G_RM_AA_ZB_XLU_INTER RM_AA_ZB_XLU_INTER(1) -#define G_RM_AA_ZB_XLU_INTER2 RM_AA_ZB_XLU_INTER(2) -#define G_RM_AA_ZB_XLU_LINE RM_AA_ZB_XLU_LINE(1) -#define G_RM_AA_ZB_XLU_LINE2 RM_AA_ZB_XLU_LINE(2) -#define G_RM_AA_ZB_DEC_LINE RM_AA_ZB_DEC_LINE(1) -#define G_RM_AA_ZB_DEC_LINE2 RM_AA_ZB_DEC_LINE(2) -#define G_RM_AA_ZB_TEX_EDGE RM_AA_ZB_TEX_EDGE(1) -#define G_RM_AA_ZB_TEX_EDGE2 RM_AA_ZB_TEX_EDGE(2) -#define G_RM_AA_ZB_TEX_INTER RM_AA_ZB_TEX_INTER(1) -#define G_RM_AA_ZB_TEX_INTER2 RM_AA_ZB_TEX_INTER(2) -#define G_RM_AA_ZB_SUB_SURF RM_AA_ZB_SUB_SURF(1) -#define G_RM_AA_ZB_SUB_SURF2 RM_AA_ZB_SUB_SURF(2) -#define G_RM_AA_ZB_PCL_SURF RM_AA_ZB_PCL_SURF(1) -#define G_RM_AA_ZB_PCL_SURF2 RM_AA_ZB_PCL_SURF(2) -#define G_RM_AA_ZB_OPA_TERR RM_AA_ZB_OPA_TERR(1) -#define G_RM_AA_ZB_OPA_TERR2 RM_AA_ZB_OPA_TERR(2) -#define G_RM_AA_ZB_TEX_TERR RM_AA_ZB_TEX_TERR(1) -#define G_RM_AA_ZB_TEX_TERR2 RM_AA_ZB_TEX_TERR(2) -#define G_RM_AA_ZB_SUB_TERR RM_AA_ZB_SUB_TERR(1) -#define G_RM_AA_ZB_SUB_TERR2 RM_AA_ZB_SUB_TERR(2) - -#define G_RM_RA_ZB_OPA_SURF RM_RA_ZB_OPA_SURF(1) -#define G_RM_RA_ZB_OPA_SURF2 RM_RA_ZB_OPA_SURF(2) -#define G_RM_RA_ZB_OPA_DECAL RM_RA_ZB_OPA_DECAL(1) -#define G_RM_RA_ZB_OPA_DECAL2 RM_RA_ZB_OPA_DECAL(2) -#define G_RM_RA_ZB_OPA_INTER RM_RA_ZB_OPA_INTER(1) -#define G_RM_RA_ZB_OPA_INTER2 RM_RA_ZB_OPA_INTER(2) - -#define G_RM_AA_OPA_SURF RM_AA_OPA_SURF(1) -#define G_RM_AA_OPA_SURF2 RM_AA_OPA_SURF(2) -#define G_RM_AA_XLU_SURF RM_AA_XLU_SURF(1) -#define G_RM_AA_XLU_SURF2 RM_AA_XLU_SURF(2) -#define G_RM_AA_XLU_LINE RM_AA_XLU_LINE(1) -#define G_RM_AA_XLU_LINE2 RM_AA_XLU_LINE(2) -#define G_RM_AA_DEC_LINE RM_AA_DEC_LINE(1) -#define G_RM_AA_DEC_LINE2 RM_AA_DEC_LINE(2) -#define G_RM_AA_TEX_EDGE RM_AA_TEX_EDGE(1) -#define G_RM_AA_TEX_EDGE2 RM_AA_TEX_EDGE(2) -#define G_RM_AA_SUB_SURF RM_AA_SUB_SURF(1) -#define G_RM_AA_SUB_SURF2 RM_AA_SUB_SURF(2) -#define G_RM_AA_PCL_SURF RM_AA_PCL_SURF(1) -#define G_RM_AA_PCL_SURF2 RM_AA_PCL_SURF(2) -#define G_RM_AA_OPA_TERR RM_AA_OPA_TERR(1) -#define G_RM_AA_OPA_TERR2 RM_AA_OPA_TERR(2) -#define G_RM_AA_TEX_TERR RM_AA_TEX_TERR(1) -#define G_RM_AA_TEX_TERR2 RM_AA_TEX_TERR(2) -#define G_RM_AA_SUB_TERR RM_AA_SUB_TERR(1) -#define G_RM_AA_SUB_TERR2 RM_AA_SUB_TERR(2) - -#define G_RM_RA_OPA_SURF RM_RA_OPA_SURF(1) -#define G_RM_RA_OPA_SURF2 RM_RA_OPA_SURF(2) - -#define G_RM_ZB_OPA_SURF RM_ZB_OPA_SURF(1) -#define G_RM_ZB_OPA_SURF2 RM_ZB_OPA_SURF(2) -#define G_RM_ZB_XLU_SURF RM_ZB_XLU_SURF(1) -#define G_RM_ZB_XLU_SURF2 RM_ZB_XLU_SURF(2) -#define G_RM_ZB_OPA_DECAL RM_ZB_OPA_DECAL(1) -#define G_RM_ZB_OPA_DECAL2 RM_ZB_OPA_DECAL(2) -#define G_RM_ZB_XLU_DECAL RM_ZB_XLU_DECAL(1) -#define G_RM_ZB_XLU_DECAL2 RM_ZB_XLU_DECAL(2) -#define G_RM_ZB_CLD_SURF RM_ZB_CLD_SURF(1) -#define G_RM_ZB_CLD_SURF2 RM_ZB_CLD_SURF(2) -#define G_RM_ZB_OVL_SURF RM_ZB_OVL_SURF(1) -#define G_RM_ZB_OVL_SURF2 RM_ZB_OVL_SURF(2) -#define G_RM_ZB_PCL_SURF RM_ZB_PCL_SURF(1) -#define G_RM_ZB_PCL_SURF2 RM_ZB_PCL_SURF(2) - -#define G_RM_OPA_SURF RM_OPA_SURF(1) -#define G_RM_OPA_SURF2 RM_OPA_SURF(2) -#define G_RM_XLU_SURF RM_XLU_SURF(1) -#define G_RM_XLU_SURF2 RM_XLU_SURF(2) -#define G_RM_CLD_SURF RM_CLD_SURF(1) -#define G_RM_CLD_SURF2 RM_CLD_SURF(2) -#define G_RM_TEX_EDGE RM_TEX_EDGE(1) -#define G_RM_TEX_EDGE2 RM_TEX_EDGE(2) -#define G_RM_PCL_SURF RM_PCL_SURF(1) -#define G_RM_PCL_SURF2 RM_PCL_SURF(2) -#define G_RM_ADD RM_ADD(1) -#define G_RM_ADD2 RM_ADD(2) -#define G_RM_NOOP RM_NOOP(1) -#define G_RM_NOOP2 RM_NOOP(2) -#define G_RM_VISCVG RM_VISCVG(1) -#define G_RM_VISCVG2 RM_VISCVG(2) -#define G_RM_OPA_CI RM_OPA_CI(1) -#define G_RM_OPA_CI2 RM_OPA_CI(2) - - -#define G_RM_FOG_SHADE_A GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA) -#define G_RM_FOG_PRIM_A GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA) -#define G_RM_PASS GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) - -/* - * G_SETCONVERT: K0-5 - */ -#define G_CV_K0 175 -#define G_CV_K1 -43 -#define G_CV_K2 -89 -#define G_CV_K3 222 -#define G_CV_K4 114 -#define G_CV_K5 42 - -/* - * G_SETSCISSOR: interlace mode - */ -#define G_SC_NON_INTERLACE 0 -#define G_SC_ODD_INTERLACE 3 -#define G_SC_EVEN_INTERLACE 2 - -/* flags to inhibit pushing of the display list (on branch) */ -#define G_DL_PUSH 0x00 -#define G_DL_NOPUSH 0x01 - -/* - * BEGIN C-specific section: (typedef's) - */ -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* - * Data Structures - * - * NOTE: - * The DMA transfer hardware requires 64-bit aligned, 64-bit multiple- - * sized transfers. This important hardware optimization is unfortunately - * reflected in the programming interface, with some structures - * padded and alignment enforced. - * - * Since structures are aligned to the boundary of the "worst-case" - * element, we can't depend on the C compiler to align things - * properly. - * - * 64-bit structure alignment is enforced by wrapping structures with - * unions that contain a dummy "long long int". Why this works is - * explained in the ANSI C Spec, or on page 186 of the second edition - * of K&R, "The C Programming Language". - * - * The price we pay for this is a little awkwardness referencing the - * structures through the union. There is no memory penalty, since - * all the structures are at least 64-bits the dummy alignment field - * does not increase the size of the union. - * - * Static initialization of these union structures works because - * the ANSI C spec states that static initialization for unions - * works by using the first union element. We put the dummy alignment - * field last for this reason. - * - * (it's possible a newer 64-bit compiler from MIPS might make this - * easier with a flag, but we can't wait for it...) - * - */ - -/* - * Vertex (set up for use with colors) - */ -typedef struct { - short ob[3]; /* x, y, z */ - unsigned short flag; - short tc[2]; /* texture coord */ - unsigned char cn[4]; /* color & alpha */ -} Vtx_t; - -/* - * Vertex (set up for use with normals) - */ -typedef struct { - short ob[3]; /* x, y, z */ - unsigned short flag; - short tc[2]; /* texture coord */ - signed char n[3]; /* normal */ - unsigned char a; /* alpha */ -} Vtx_tn; - -typedef union { - Vtx_t v; /* Use this one for colors */ - Vtx_tn n; /* Use this one for normals */ - long long int force_structure_alignment; -} Vtx; - -/* - * Sprite structure - */ - -typedef struct { - void *SourceImagePointer; - void *TlutPointer; - short Stride; - short SubImageWidth; - short SubImageHeight; - char SourceImageType; - char SourceImageBitSize; - short SourceImageOffsetS; - short SourceImageOffsetT; - /* 20 bytes for above */ - - /* padding to bring structure size to 64 bit allignment */ - char dummy[4]; - -} uSprite_t; - -typedef union { - uSprite_t s; - - /* Need to make sure this is 64 bit aligned */ - long long int force_structure_allignment[3]; -} uSprite; - -/* - * Triangle face - */ -typedef struct { - unsigned char flag; - unsigned char v[3]; -} Tri; - -/* - * 4x4 matrix, fixed point s15.16 format. - * First 8 words are integer portion of the 4x4 matrix - * Last 8 words are the fraction portion of the 4x4 matrix - */ -typedef long Mtx_t[4][4]; - -typedef union { - Mtx_t m; - long long int force_structure_alignment; -} Mtx; - -/* - * Viewport - */ - -/* - * - * This magic value is the maximum INTEGER z-range of the hardware - * (there are also 16-bits of fraction, which are introduced during - * any transformations). This is not just a good idea, it's the law. - * Feeding the hardware eventual z-coordinates (after any transforms - * or scaling) bigger than this, will not work. - * - * This number is DIFFERENT than G_MAXFBZ, which is the maximum value - * you want to use to initialize the z-buffer. - * - * The reason these are different is mildly interesting, but too long - * to explain here. It is basically the result of optimizations in the - * hardware. A more generic API might hide this detail from the users, - * but we don't have the ucode to do that... - * - */ -#define G_MAXZ 0x03ff /* 10 bits of integer screen-Z precision */ - -/* - * The viewport structure elements have 2 bits of fraction, necessary - * to accomodate the sub-pixel positioning scaling for the hardware. - * This can also be exploited to handle odd-sized viewports. - * - * Accounting for these fractional bits, using the default projection - * and viewing matrices, the viewport structure is initialized thusly: - * - * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, G_MAXZ, 0, - * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, 0, 0, - */ -typedef struct { - short vscale[4]; /* scale, 2 bits fraction */ - short vtrans[4]; /* translate, 2 bits fraction */ - /* both the above arrays are padded to 64-bit boundary */ -} Vp_t; - -typedef union { - Vp_t vp; - long long int force_structure_alignment; -} Vp; - -/* - * MOVEMEM indices - * - * Each of these indexes an entry in a dmem table - * which points to a 1-4 word block of dmem in - * which to store a 1-4 word DMA. - * - */ -#ifdef F3DEX_GBI_2 -/* 0,4 are reserved by G_MTX */ -# define G_MV_MMTX 2 -# define G_MV_PMTX 6 -# define G_MV_VIEWPORT 8 -# define G_MV_LIGHT 10 -# define G_MV_POINT 12 -# define G_MV_MATRIX 14 /* NOTE: this is in moveword table */ -# define G_MVO_LOOKATX (0*24) -# define G_MVO_LOOKATY (1*24) -# define G_MVO_L0 (2*24) -# define G_MVO_L1 (3*24) -# define G_MVO_L2 (4*24) -# define G_MVO_L3 (5*24) -# define G_MVO_L4 (6*24) -# define G_MVO_L5 (7*24) -# define G_MVO_L6 (8*24) -# define G_MVO_L7 (9*24) -#else /* F3DEX_GBI_2 */ -# define G_MV_VIEWPORT 0x80 -# define G_MV_LOOKATY 0x82 -# define G_MV_LOOKATX 0x84 -# define G_MV_L0 0x86 -# define G_MV_L1 0x88 -# define G_MV_L2 0x8a -# define G_MV_L3 0x8c -# define G_MV_L4 0x8e -# define G_MV_L5 0x90 -# define G_MV_L6 0x92 -# define G_MV_L7 0x94 -# define G_MV_TXTATT 0x96 -# define G_MV_MATRIX_1 0x9e /* NOTE: this is in moveword table */ -# define G_MV_MATRIX_2 0x98 -# define G_MV_MATRIX_3 0x9a -# define G_MV_MATRIX_4 0x9c -#endif /* F3DEX_GBI_2 */ - -/* - * MOVEWORD indices - * - * Each of these indexes an entry in a dmem table - * which points to a word in dmem in dmem where - * an immediate word will be stored. - * - */ -#define G_MW_MATRIX 0x00 /* NOTE: also used by movemem */ -#define G_MW_NUMLIGHT 0x02 -#define G_MW_CLIP 0x04 -#define G_MW_SEGMENT 0x06 -#define G_MW_FOG 0x08 -#define G_MW_LIGHTCOL 0x0a -#ifdef F3DEX_GBI_2 -# define G_MW_FORCEMTX 0x0c -#else /* F3DEX_GBI_2 */ -# define G_MW_POINTS 0x0c -#endif /* F3DEX_GBI_2 */ -#define G_MW_PERSPNORM 0x0e - -/* - * These are offsets from the address in the dmem table - */ -#define G_MWO_NUMLIGHT 0x00 -#define G_MWO_CLIP_RNX 0x04 -#define G_MWO_CLIP_RNY 0x0c -#define G_MWO_CLIP_RPX 0x14 -#define G_MWO_CLIP_RPY 0x1c -#define G_MWO_SEGMENT_0 0x00 -#define G_MWO_SEGMENT_1 0x01 -#define G_MWO_SEGMENT_2 0x02 -#define G_MWO_SEGMENT_3 0x03 -#define G_MWO_SEGMENT_4 0x04 -#define G_MWO_SEGMENT_5 0x05 -#define G_MWO_SEGMENT_6 0x06 -#define G_MWO_SEGMENT_7 0x07 -#define G_MWO_SEGMENT_8 0x08 -#define G_MWO_SEGMENT_9 0x09 -#define G_MWO_SEGMENT_A 0x0a -#define G_MWO_SEGMENT_B 0x0b -#define G_MWO_SEGMENT_C 0x0c -#define G_MWO_SEGMENT_D 0x0d -#define G_MWO_SEGMENT_E 0x0e -#define G_MWO_SEGMENT_F 0x0f -#define G_MWO_FOG 0x00 -#define G_MWO_aLIGHT_1 0x00 -#define G_MWO_bLIGHT_1 0x04 -#ifdef F3DEX_GBI_2 -#define G_MWO_aLIGHT_2 0x18 -#define G_MWO_bLIGHT_2 0x1c -#define G_MWO_aLIGHT_3 0x30 -#define G_MWO_bLIGHT_3 0x34 -#define G_MWO_aLIGHT_4 0x48 -#define G_MWO_bLIGHT_4 0x4c -#define G_MWO_aLIGHT_5 0x60 -#define G_MWO_bLIGHT_5 0x64 -#define G_MWO_aLIGHT_6 0x78 -#define G_MWO_bLIGHT_6 0x7c -#define G_MWO_aLIGHT_7 0x90 -#define G_MWO_bLIGHT_7 0x94 -#define G_MWO_aLIGHT_8 0xa8 -#define G_MWO_bLIGHT_8 0xac -#else -#define G_MWO_aLIGHT_2 0x20 -#define G_MWO_bLIGHT_2 0x24 -#define G_MWO_aLIGHT_3 0x40 -#define G_MWO_bLIGHT_3 0x44 -#define G_MWO_aLIGHT_4 0x60 -#define G_MWO_bLIGHT_4 0x64 -#define G_MWO_aLIGHT_5 0x80 -#define G_MWO_bLIGHT_5 0x84 -#define G_MWO_aLIGHT_6 0xa0 -#define G_MWO_bLIGHT_6 0xa4 -#define G_MWO_aLIGHT_7 0xc0 -#define G_MWO_bLIGHT_7 0xc4 -#define G_MWO_aLIGHT_8 0xe0 -#define G_MWO_bLIGHT_8 0xe4 -#endif -#define G_MWO_MATRIX_XX_XY_I 0x00 -#define G_MWO_MATRIX_XZ_XW_I 0x04 -#define G_MWO_MATRIX_YX_YY_I 0x08 -#define G_MWO_MATRIX_YZ_YW_I 0x0c -#define G_MWO_MATRIX_ZX_ZY_I 0x10 -#define G_MWO_MATRIX_ZZ_ZW_I 0x14 -#define G_MWO_MATRIX_WX_WY_I 0x18 -#define G_MWO_MATRIX_WZ_WW_I 0x1c -#define G_MWO_MATRIX_XX_XY_F 0x20 -#define G_MWO_MATRIX_XZ_XW_F 0x24 -#define G_MWO_MATRIX_YX_YY_F 0x28 -#define G_MWO_MATRIX_YZ_YW_F 0x2c -#define G_MWO_MATRIX_ZX_ZY_F 0x30 -#define G_MWO_MATRIX_ZZ_ZW_F 0x34 -#define G_MWO_MATRIX_WX_WY_F 0x38 -#define G_MWO_MATRIX_WZ_WW_F 0x3c -#define G_MWO_POINT_RGBA 0x10 -#define G_MWO_POINT_ST 0x14 -#define G_MWO_POINT_XYSCREEN 0x18 -#define G_MWO_POINT_ZSCREEN 0x1c - -/* - * Light structure. - * - * Note: only directional (infinite) lights are currently supported. - * - * Note: the weird order is for the DMEM alignment benefit of - * the microcode. - * - */ - -typedef struct { - unsigned char col[3]; /* diffuse light value (rgba) */ - char pad1; - unsigned char colc[3]; /* copy of diffuse light value (rgba) */ - char pad2; - signed char dir[3]; /* direction of light (normalized) */ - char pad3; -} Light_t; - -typedef struct { - unsigned char col[3]; /* ambient light value (rgba) */ - char pad1; - unsigned char colc[3]; /* copy of ambient light value (rgba) */ - char pad2; -} Ambient_t; - -typedef struct { - int x1,y1,x2,y2; /* texture offsets for highlight 1/2 */ -} Hilite_t; - -typedef union { - Light_t l; - long long int force_structure_alignment[2]; -} Light; - -typedef union { - Ambient_t l; - long long int force_structure_alignment[1]; -} Ambient; - -typedef struct { - Ambient a; - Light l[7]; -} Lightsn; - -typedef struct { - Ambient a; - Light l[1]; -} Lights0; - -typedef struct { - Ambient a; - Light l[1]; -} Lights1; - -typedef struct { - Ambient a; - Light l[2]; -} Lights2; - -typedef struct { - Ambient a; - Light l[3]; -} Lights3; - -typedef struct { - Ambient a; - Light l[4]; -} Lights4; - -typedef struct { - Ambient a; - Light l[5]; -} Lights5; - -typedef struct { - Ambient a; - Light l[6]; -} Lights6; - -typedef struct { - Ambient a; - Light l[7]; -} Lights7; - -typedef struct { - Light l[2]; -} LookAt; - -typedef union { - Hilite_t h; - long int force_structure_alignment[4]; -} Hilite; - -#define gdSPDefLights0(ar,ag,ab) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ { 0, 0, 0},0,{ 0, 0, 0},0,{ 0, 0, 0},0}}} } -#define gdSPDefLights1(ar,ag,ab,r1,g1,b1,x1,y1,z1) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}} } -#define gdSPDefLights2(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ - {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}} } -#define gdSPDefLights3(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ - {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ - {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}} } -#define gdSPDefLights4(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ - {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ - {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ - {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}} } -#define gdSPDefLights5(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ - {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ - {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ - {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ - {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}} } - - -#define gdSPDefLights6(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ - {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ - {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ - {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ - {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \ - {{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}} } - - -#define gdSPDefLights7(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6,r7,g7,b7,x7,y7,z7) \ - { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ - {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ - {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ - {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ - {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ - {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \ - {{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}, \ - {{ {r7,g7,b7},0,{r7,g7,b7},0,{x7,y7,z7},0}}} } - - -#define gdSPDefLookAt(rightx,righty,rightz,upx,upy,upz) \ - { {{ {{0,0,0},0,{0,0,0},0,{rightx,righty,rightz},0}}, \ - { {{0,0x80,0},0,{0,0x80,0},0,{upx,upy,upz},0}}} } - -/* - * Graphics DMA Packet - */ -typedef struct { - int cmd:8; - unsigned int par:8; - unsigned int len:16; - unsigned int addr; -} Gdma; - -/* - * Graphics Immediate Mode Packet types - */ -typedef struct { - int cmd:8; - int pad:24; - Tri tri; -} Gtri; - -typedef struct { - int cmd:8; - int pad1:24; - int pad2:24; - unsigned char param:8; -} Gpopmtx; - -/* - * typedef struct { - * int cmd:8; - * int pad0:24; - * int pad1:4; - * int number:4; - * int base:24; - * } Gsegment; - */ -typedef struct { - int cmd:8; - int pad0:8; - int mw_index:8; - int number:8; - int pad1:8; - int base:24; -} Gsegment; - -typedef struct { - int cmd:8; - int pad0:8; - int sft:8; - int len:8; - unsigned int data:32; -} GsetothermodeL; - -typedef struct { - int cmd:8; - int pad0:8; - int sft:8; - int len:8; - unsigned int data:32; -} GsetothermodeH; - -typedef struct { - unsigned char cmd; - unsigned char lodscale; - unsigned char tile; - unsigned char on; - unsigned short s; - unsigned short t; -} Gtexture; - -typedef struct { - int cmd:8; - int pad:24; - Tri line; -} Gline3D; - -typedef struct { - int cmd:8; - int pad1:24; - short int pad2; - short int scale; -} Gperspnorm; - - -/* - * RDP Packet types - */ -typedef struct { - int cmd:8; - unsigned int fmt:3; - unsigned int siz:2; - unsigned int pad:7; - unsigned int wd:12; /* really only 10 bits, extra */ - unsigned int dram; /* to account for 1024 */ -} Gsetimg; - -typedef struct { - int cmd:8; - unsigned int muxs0:24; - unsigned int muxs1:32; -} Gsetcombine; - -typedef struct { - int cmd:8; - unsigned char pad; - unsigned char prim_min_level; - unsigned char prim_level; - unsigned long color; -} Gsetcolor; - -typedef struct { - int cmd:8; - int x0:10; - int x0frac:2; - int y0:10; - int y0frac:2; - unsigned int pad:8; - int x1:10; - int x1frac:2; - int y1:10; - int y1frac:2; -} Gfillrect; - -typedef struct { - int cmd:8; - unsigned int fmt:3; - unsigned int siz:2; - unsigned int pad0:1; - unsigned int line:9; - unsigned int tmem:9; - unsigned int pad1:5; - unsigned int tile:3; - unsigned int palette:4; - unsigned int ct:1; - unsigned int mt:1; - unsigned int maskt:4; - unsigned int shiftt:4; - unsigned int cs:1; - unsigned int ms:1; - unsigned int masks:4; - unsigned int shifts:4; -} Gsettile; - -typedef struct { - int cmd:8; - unsigned int sl:12; - unsigned int tl:12; - int pad:5; - unsigned int tile:3; - unsigned int sh:12; - unsigned int th:12; -} Gloadtile; - -typedef Gloadtile Gloadblock; - -typedef Gloadtile Gsettilesize; - -typedef Gloadtile Gloadtlut; - -typedef struct { - unsigned int cmd:8; /* command */ - unsigned int xl:12; /* X coordinate of upper left */ - unsigned int yl:12; /* Y coordinate of upper left */ - unsigned int pad1:5; /* Padding */ - unsigned int tile:3; /* Tile descriptor index */ - unsigned int xh:12; /* X coordinate of lower right */ - unsigned int yh:12; /* Y coordinate of lower right */ - unsigned int s:16; /* S texture coord at top left */ - unsigned int t:16; /* T texture coord at top left */ - unsigned int dsdx:16;/* Change in S per change in X */ - unsigned int dtdy:16;/* Change in T per change in Y */ -} Gtexrect; - -#define MakeTexRect(xh,yh,flip,tile,xl,yl,s,t,dsdx,dtdy) \ - G_TEXRECT, xh, yh, 0, flip, 0, tile, xl, yl, s, t, dsdx, dtdy - -/* - * Textured rectangles are 128 bits not 64 bits - */ -typedef struct { - unsigned long w0; - unsigned long w1; - unsigned long w2; - unsigned long w3; -} TexRect; - -/* - * Generic Gfx Packet - */ -typedef struct { - unsigned int w0; - unsigned int w1; -} Gwords; - -/* - * This union is the fundamental type of the display list. - * It is, by law, exactly 64 bits in size. - */ -typedef union { - Gwords words; - Gdma dma; - Gtri tri; - Gline3D line; - Gpopmtx popmtx; - Gsegment segment; - GsetothermodeH setothermodeH; - GsetothermodeL setothermodeL; - Gtexture texture; - Gperspnorm perspnorm; - Gsetimg setimg; - Gsetcombine setcombine; - Gsetcolor setcolor; - Gfillrect fillrect; /* use for setscissor also */ - Gsettile settile; - Gloadtile loadtile; /* use for loadblock also, th is dxt */ - Gsettilesize settilesize; - Gloadtlut loadtlut; - long long int force_structure_alignment; -} Gfx; - -/* - * Macros to assemble the graphics display list - */ - -/* - * DMA macros - */ -#define gDma0p(pkt, c, s, l) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24); \ - _g->words.w1 = (unsigned int)(s); \ -} - -#define gsDma0p(c, s, l) \ -{{ \ - _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24), (unsigned int)(s) \ -}} - -#define gDma1p(pkt, c, s, l, p) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ - _SHIFTL((l), 0, 16)); \ - _g->words.w1 = (unsigned int)(s); \ -} - -#define gsDma1p(c, s, l, p) \ -{{ \ - (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ - _SHIFTL((l), 0, 16)), \ - (unsigned int)(s) \ -}} - -#define gDma2p(pkt, c, adrs, len, idx, ofs) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ - _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)); \ - _g->words.w1 = (unsigned int)(adrs); \ -} -#define gsDma2p(c, adrs, len, idx, ofs) \ -{{ \ - (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ - _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)), \ - (unsigned int)(adrs) \ -}} - -#define gSPNoOp(pkt) gDma0p(pkt, G_SPNOOP, 0, 0) -#define gsSPNoOp() gsDma0p(G_SPNOOP, 0, 0) - -#ifdef F3DEX_GBI_2 -# define gSPMatrix(pkt, m, p) \ - gDma2p((pkt),G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) -# define gsSPMatrix(m, p) \ - gsDma2p( G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) -#else /* F3DEX_GBI_2 */ -# define gSPMatrix(pkt, m, p) gDma1p(pkt, G_MTX, m, sizeof(Mtx), p) -# define gsSPMatrix(m, p) gsDma1p(G_MTX, m, sizeof(Mtx), p) -#endif /* F3DEX_GBI_2 */ - -#if defined(F3DEX_GBI_2) -/* - * F3DEX_GBI_2: G_VTX GBI format was changed. - * - * +--------+----+---+---+----+------+-+ - * G_VTX | cmd:8 |0000| n:8 |0000|v0+n:7|0| - * +-+---+--+----+---+---+----+------+-+ - * | |seg| address | - * +-+---+-----------------------------+ - */ -# define gSPVertex(pkt, v, n, v0) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = \ - _SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7); \ - _g->words.w1 = (unsigned int)(v); \ -} -# define gsSPVertex(v, n, v0) \ -{{ \ - (_SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7)), \ - (unsigned int)(v) \ -}} -#elif (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -/* - * F3DEX_GBI: G_VTX GBI format was changed to support 64 vertice. - * - * +--------+--------+------+----------+ - * G_VTX | cmd:8 | v0:8 | n:6 |length:10 | - * +-+---+--+--------+------+----------+ - * | |seg| address | - * +-+---+-----------------------------+ - */ -# define gSPVertex(pkt, v, n, v0) \ - gDma1p((pkt),G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) -# define gsSPVertex(v, n, v0) \ - gsDma1p(G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) -#else -# define gSPVertex(pkt, v, n, v0) \ - gDma1p(pkt, G_VTX, v, sizeof(Vtx)*(n),((n)-1)<<4|(v0)) -# define gsSPVertex(v, n, v0) \ - gsDma1p(G_VTX, v, sizeof(Vtx)*(n), ((n)-1)<<4|(v0)) -#endif - - -#ifdef F3DEX_GBI_2 -# define gSPViewport(pkt, v) \ - gDma2p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) -# define gsSPViewport(v) \ - gsDma2p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) -#else /* F3DEX_GBI_2 */ -# define gSPViewport(pkt,v) \ - gDma1p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) -# define gsSPViewport(v) \ - gsDma1p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) -#endif /* F3DEX_GBI_2 */ - -#define gSPDisplayList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_PUSH) -#define gsSPDisplayList( dl) gsDma1p( G_DL,dl,0,G_DL_PUSH) - -#define gSPBranchList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_NOPUSH) -#define gsSPBranchList( dl) gsDma1p( G_DL,dl,0,G_DL_NOPUSH) - -#define gSPSprite2DBase(pkt, s) gDma1p(pkt, G_SPRITE2D_BASE, s, sizeof(uSprite), 0) -#define gsSPSprite2DBase(s) gsDma1p(G_SPRITE2D_BASE, s, sizeof(uSprite), 0) - -/* - * RSP short command (no DMA required) macros - */ -#define gImmp0(pkt, c) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ -} - -#define gsImmp0(c) \ -{{ \ - _SHIFTL((c), 24, 8) \ -}} - -#define gImmp1(pkt, c, p0) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ - _g->words.w1 = (unsigned int)(p0); \ -} - -#define gsImmp1(c, p0) \ -{{ \ - _SHIFTL((c), 24, 8), (unsigned int)(p0) \ -}} - -#define gImmp2(pkt, c, p0, p1) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ - _g->words.w1 = _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8); \ -} - -#define gsImmp2(c, p0, p1) \ -{{ \ - _SHIFTL((c), 24, 8), _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8)\ -}} - -#define gImmp3(pkt, c, p0, p1, p2) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ - _g->words.w1 = (_SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8) | \ - _SHIFTL((p2), 0, 8)); \ -} - -#define gsImmp3(c, p0, p1, p2) \ -{{ \ - _SHIFTL((c), 24, 8), (_SHIFTL((p0), 16, 16) | \ - _SHIFTL((p1), 8, 8) | _SHIFTL((p2), 0, 8))\ -}} - -#define gImmp21(pkt, c, p0, p1, dat) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | \ - _SHIFTL((p1), 0, 8)); \ - _g->words.w1 = (unsigned int) (dat); \ -} - -#define gsImmp21(c, p0, p1, dat) \ -{{ \ - _SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | _SHIFTL((p1), 0, 8),\ - (unsigned int) (dat) \ -}} - -#ifdef F3DEX_GBI_2 -#define gMoveWd(pkt, index, offset, data) \ - gDma1p((pkt), G_MOVEWORD, data, offset, index) -#define gsMoveWd( index, offset, data) \ - gsDma1p( G_MOVEWORD, data, offset, index) -#else /* F3DEX_GBI_2 */ -#define gMoveWd(pkt, index, offset, data) \ - gImmp21((pkt), G_MOVEWORD, offset, index, data) -#define gsMoveWd( index, offset, data) \ - gsImmp21( G_MOVEWORD, offset, index, data) -#endif /* F3DEX_GBI_2 */ - -/* Sprite immediate macros, there is also a sprite dma macro above */ - -#define gSPSprite2DScaleFlip(pkt, sx, sy, fx, fy) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ - _SHIFTL((fx), 8, 8) | \ - _SHIFTL((fy), 0, 8)); \ - _g->words.w1 = (_SHIFTL((sx), 16, 16) | \ - _SHIFTL((sy), 0, 16)); \ -} - -#define gsSPSprite2DScaleFlip(sx, sy, fx, fy) \ -{{ \ - (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ - _SHIFTL((fx), 8, 8) | \ - _SHIFTL((fy), 0, 8)), \ - (_SHIFTL((sx), 16, 16) | \ - _SHIFTL((sy), 0, 16)) \ -}} - -#define gSPSprite2DDraw(pkt, px, py) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)); \ - _g->words.w1 = (_SHIFTL((px), 16, 16) | \ - _SHIFTL((py), 0, 16)); \ -} - -#define gsSPSprite2DDraw(px, py) \ -{{ \ - (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)), \ - (_SHIFTL((px), 16, 16) | \ - _SHIFTL((py), 0, 16)) \ -}} - - -/* - * Note: the SP1Triangle() and line macros multiply the vertex indices - * by 10, this is an optimization for the microcode. - */ -#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) -# define __gsSP1Triangle_w1(v0, v1, v2) \ - (_SHIFTL((v0)*2,16,8)|_SHIFTL((v1)*2,8,8)|_SHIFTL((v2)*2,0,8)) -# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v0): \ - __gsSP1Triangle_w1(v2, v0, v1)) -# define __gsSPLine3D_w1(v0, v1, wd) \ - (_SHIFTL((v0)*2,16,8)|_SHIFT((v1)*2,8,8)|_SHIFT((wd),0,8)) -# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ - (((flag) == 0) ? __gsSPLine3D_w1(v0, v1, wd): \ - __gsSPLine3D_w1(v1, v0, wd)) -# define __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v3): \ - ((flag) == 2) ? __gsSP1Triangle_w1(v2, v3, v0): \ - __gsSP1Triangle_w1(v3, v0, v1)) -# define __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v2, v3): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v3, v0): \ - ((flag) == 2) ? __gsSP1Triangle_w1(v2, v0, v1): \ - __gsSP1Triangle_w1(v3, v1, v2)) -#else -# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ - (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ - _SHIFTL((v1)*10, 8,8)|_SHIFTL((v2)*10, 0,8)) -# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ - (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ - _SHIFTL((v1)*10, 8,8)|_SHIFTL((wd), 0,8)) -#endif - -#ifdef F3DEX_GBI_2 -/*** - *** 1 Triangle - ***/ -#define gSP1Triangle(pkt, v0, v1, v2, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_TRI1, 24, 8)| \ - __gsSP1Triangle_w1f(v0, v1, v2, flag); \ - _g->words.w1 = 0; \ -} -#define gsSP1Triangle(v0, v1, v2, flag) \ -{{ \ - _SHIFTL(G_TRI1, 24, 8)|__gsSP1Triangle_w1f(v0, v1, v2, flag), \ - 0 \ -}} - -/*** - *** Line - ***/ -#define gSPLine3D(pkt, v0, v1, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ - __gsSPLine3D_w1f(v0, v1, 0, flag); \ - _g->words.w1 = 0; \ -} -#define gsSPLine3D(v0, v1, flag) \ -{{ \ - _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, 0, flag), \ - 0 \ -}} - -/*** - *** LineW - ***/ -/* these macros are the same as SPLine3D, except they have an - * additional parameter for width. The width is added to the "minimum" - * thickness, which is 1.5 pixels. The units for width are in - * half-pixel units, so a width of 1 translates to (.5 + 1.5) or - * a 2.0 pixels wide line. - */ -#define gSPLineW3D(pkt, v0, v1, wd, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ - __gsSPLine3D_w1f(v0, v1, wd, flag); \ - _g->words.w1 = 0; \ -} -#define gsSPLineW3D(v0, v1, wd, flag) \ -{{ \ - _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, wd, flag), \ - 0 \ -}} - -/*** - *** 1 Quadrangle - ***/ -#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_QUAD, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ - _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ -} - -#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ -{{ \ - (_SHIFTL(G_QUAD, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ - __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ -}} -#else /* F3DEX_GBI_2 */ - -/*** - *** 1 Triangle - ***/ -#define gSP1Triangle(pkt, v0, v1, v2, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_TRI1, 24, 8); \ - _g->words.w1 = __gsSP1Triangle_w1f(v0, v1, v2, flag); \ -} -#define gsSP1Triangle(v0, v1, v2, flag) \ -{{ \ - _SHIFTL(G_TRI1, 24, 8), \ - __gsSP1Triangle_w1f(v0, v1, v2, flag) \ -}} - -/*** - *** Line - ***/ -#define gSPLine3D(pkt, v0, v1, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ - _g->words.w1 = __gsSPLine3D_w1f(v0, v1, 0, flag); \ -} -#define gsSPLine3D(v0, v1, flag) \ -{{ \ - _SHIFTL(G_LINE3D, 24, 8), \ - __gsSPLine3D_w1f(v0, v1, 0, flag) \ -}} - -/*** - *** LineW - ***/ -/* these macros are the same as SPLine3D, except they have an - * additional parameter for width. The width is added to the "minimum" - * thickness, which is 1.5 pixels. The units for width are in - * half-pixel units, so a width of 1 translates to (.5 + 1.5) or - * a 2.0 pixels wide line. - */ -#define gSPLineW3D(pkt, v0, v1, wd, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ - _g->words.w1 = __gsSPLine3D_w1f(v0, v1, wd, flag); \ -} -#define gsSPLineW3D(v0, v1, wd, flag) \ -{{ \ - _SHIFTL(G_LINE3D, 24, 8), \ - __gsSPLine3D_w1f(v0, v1, wd, flag) \ -}} - -/*** - *** 1 Quadrangle - ***/ -#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ - _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ -} - -#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ -{{ \ - (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ - __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ -}} -#endif /* F3DEX_GBI_2 */ - -#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) -/*** - *** 2 Triangles - ***/ -#define gSP2Triangles(pkt, v00, v01, v02, flag0, v10, v11, v12, flag1) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Triangle_w1f(v00, v01, v02, flag0)); \ - _g->words.w1 = __gsSP1Triangle_w1f(v10, v11, v12, flag1); \ -} - -#define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ -{{ \ - (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Triangle_w1f(v00, v01, v02, flag0)), \ - __gsSP1Triangle_w1f(v10, v11, v12, flag1) \ -}} - -#endif /* F3DEX_GBI/F3DLP_GBI */ - -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -#define gSPCullDisplayList(pkt,vstart,vend) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ - _SHIFTL((vstart)*2, 0, 16); \ - _g->words.w1 = _SHIFTL((vend)*2, 0, 16); \ -} - -#define gsSPCullDisplayList(vstart,vend) \ -{{ \ - _SHIFTL(G_CULLDL, 24, 8) | _SHIFTL((vstart)*2, 0, 16), \ - _SHIFTL((vend)*2, 0, 16) \ -}} - -#else -#define gSPCullDisplayList(pkt,vstart,vend) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ - ((0x0f & (vstart))*40); \ - _g->words.w1 = (unsigned int)((0x0f & ((vend)+1))*40); \ -} - -#define gsSPCullDisplayList(vstart,vend) \ -{{ \ - _SHIFTL(G_CULLDL, 24, 8) | ((0x0f & (vstart))*40), \ - ((0x0f & ((vend)+1))*40) \ -}} -#endif - -#define gSPSegment(pkt, segment, base) \ - gMoveWd(pkt, G_MW_SEGMENT, (segment)*4, base) -#define gsSPSegment(segment, base) \ - gsMoveWd( G_MW_SEGMENT, (segment)*4, base) - -/* - * Clipping Macros - */ -#define FR_NEG_FRUSTRATIO_1 0x00000001 -#define FR_POS_FRUSTRATIO_1 0x0000ffff -#define FR_NEG_FRUSTRATIO_2 0x00000002 -#define FR_POS_FRUSTRATIO_2 0x0000fffe -#define FR_NEG_FRUSTRATIO_3 0x00000003 -#define FR_POS_FRUSTRATIO_3 0x0000fffd -#define FR_NEG_FRUSTRATIO_4 0x00000004 -#define FR_POS_FRUSTRATIO_4 0x0000fffc -#define FR_NEG_FRUSTRATIO_5 0x00000005 -#define FR_POS_FRUSTRATIO_5 0x0000fffb -#define FR_NEG_FRUSTRATIO_6 0x00000006 -#define FR_POS_FRUSTRATIO_6 0x0000fffa -/* - * r should be one of: FRUSTRATIO_1, FRUSTRATIO_2, FRUSTRATIO_3, ... FRUSTRATIO_6 - */ -#define gSPClipRatio(pkt, r) \ -{ \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r); \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r); \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r); \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r); \ -} - -#define gsSPClipRatio(r) \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r), \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r), \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r), \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r) - -/* - * Insert values into Matrix - * - * where = element of matrix (byte offset) - * num = new element (32 bit value replacing 2 int or 2 frac matrix - * componants - */ -#ifdef F3DEX_GBI_2 -#define gSPInsertMatrix(pkt, where, num) \ - ERROR!! gSPInsertMatrix is no longer supported. -#define gsSPInsertMatrix(where, num) \ - ERROR!! gsSPInsertMatrix is no longer supported. -#else -#define gSPInsertMatrix(pkt, where, num) \ - gMoveWd(pkt, G_MW_MATRIX, where, num) -#define gsSPInsertMatrix(where, num) \ - gsMoveWd(G_MW_MATRIX, where, num) -#endif - -/* - * Load new matrix directly - * - * mptr = pointer to matrix - */ -#ifdef F3DEX_GBI_2 -#define gSPForceMatrix(pkt, mptr) \ -{ gDma2p((pkt),G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0); \ - gMoveWd((pkt), G_MW_FORCEMTX,0,0x00010000); \ -} -#define gsSPForceMatrix(mptr) \ - gsDma2p(G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0), \ - gsMoveWd(G_MW_FORCEMTX,0,0x00010000) - -#else /* F3DEX_GBI_2 */ -#define gSPForceMatrix(pkt, mptr) \ -{ \ - gDma1p(pkt, G_MOVEMEM, mptr, 16, G_MV_MATRIX_1); \ - gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2); \ - gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3); \ - gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4); \ -} -#define gsSPForceMatrix(mptr) \ - gsDma1p( G_MOVEMEM, mptr, 16, G_MV_MATRIX_1), \ - gsDma1p( G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2), \ - gsDma1p( G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3), \ - gsDma1p( G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4) -#endif /* F3DEX_GBI_2 */ - -/* - * Insert values into Points - * - * point = point number 0-15 - * where = which element of point to modify (byte offset into point) - * num = new value (32 bit) - */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define gSPModifyVertex(pkt, vtx, where, val) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_MODIFYVTX,24,8)| \ - _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16)); \ - _g->words.w1 = (unsigned int)(val); \ -} -# define gsSPModifyVertex(vtx, where, val) \ -{{ \ - _SHIFTL(G_MODIFYVTX,24,8)| \ - _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16), \ - (unsigned int)(val) \ -}} -#else -# define gSPModifyVertex(pkt, vtx, where, val) \ - gMoveWd(pkt, G_MW_POINTS, (vtx)*40+(where), val) -# define gsSPModifyVertex(vtx, where, val) \ - gsMoveWd(G_MW_POINTS, (vtx)*40+(where), val) -#endif - -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -/* - * gSPBranchLessZ Branch DL if (vtx.z) less than or equal (zval). - * - * dl = DL branch to - * vtx = Vertex - * zval = Screen depth - * near = Near plane - * far = Far plane - * flag = G_BZ_PERSP or G_BZ_ORTHO - */ - -#define G_BZ_PERSP 0 -#define G_BZ_ORTHO 1 - -#define G_DEPTOZSrg(zval, near, far, flag, zmin, zmax) \ -(((unsigned int)FTOFIX32(((flag) == G_BZ_PERSP ? \ - (1.0f-(float)(near)/(float)(zval)) / \ - (1.0f-(float)(near)/(float)(far )) : \ - ((float)(zval) - (float)(near)) / \ - ((float)(far ) - (float)(near))))) * \ - (((int)((zmax) - (zmin)))&~1) + (int)FTOFIX32(zmin)) - -#define G_DEPTOZS(zval, near, far, flag) \ - G_DEPTOZSrg(zval, near, far, flag, 0, G_MAXZ) - -#define gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, zmin, zmax) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (unsigned int)(dl); \ - _g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ - _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ - _g->words.w1 = G_DEPTOZSrg(zval, near, far, flag, zmin, zmax); \ -} - -#define gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, zmin, zmax) \ -{{ _SHIFTL(G_RDPHALF_1,24,8), \ - (unsigned int)(dl), }}, \ -{{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ - G_DEPTOZSrg(zval, near, far, flag, zmin, zmax), }} - -#define gSPBranchLessZ(pkt, dl, vtx, zval, near, far, flag) \ - gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, 0, G_MAXZ) -#define gsSPBranchLessZ(dl, vtx, zval, near, far, flag) \ - gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, 0, G_MAXZ) - -/* - * gSPBranchLessZraw Branch DL if (vtx.z) less than or equal (raw zval). - * - * dl = DL branch to - * vtx = Vertex - * zval = Raw value of screen depth - */ -#define gSPBranchLessZraw(pkt, dl, vtx, zval) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (unsigned int)(dl); \ - _g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ - _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ - _g->words.w1 = (unsigned int)(zval); \ -} - -#define gsSPBranchLessZraw(dl, vtx, zval) \ -{{ _SHIFTL(G_RDPHALF_1,24,8), \ - (unsigned int)(dl), }}, \ -{{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ - (unsigned int)(zval), }} - -/* - * gSPLoadUcode RSP loads specified ucode. - * - * uc_start = ucode text section start - * uc_dstart = ucode data section start - */ -#define gSPLoadUcodeEx(pkt, uc_start, uc_dstart, uc_dsize) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (unsigned int)(uc_dstart); \ - _g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_LOAD_UCODE,24,8)| \ - _SHIFTL((int)(uc_dsize)-1,0,16)); \ - _g->words.w1 = (unsigned int)(uc_start); \ -} - -#define gsSPLoadUcodeEx(uc_start, uc_dstart, uc_dsize) \ -{{ _SHIFTL(G_RDPHALF_1,24,8), \ - (unsigned int)(uc_dstart), }}, \ -{{ _SHIFTL(G_LOAD_UCODE,24,8)| \ - _SHIFTL((int)(uc_dsize)-1,0,16), \ - (unsigned int)(uc_start), }} - -#define gSPLoadUcode(pkt, uc_start, uc_dstart) \ - gSPLoadUcodeEx((pkt), (uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) -#define gsSPLoadUcode(uc_start, uc_dstart) \ - gsSPLoadUcodeEx((uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) - -#define gSPLoadUcodeL(pkt, ucode) \ - gSPLoadUcode((pkt), OS_K0_TO_PHYSICAL(&##ucode##TextStart), \ - OS_K0_TO_PHYSICAL(&##ucode##DataStart)) -#define gsSPLoadUcodeL(ucode) \ - gsSPLoadUcode(OS_K0_TO_PHYSICAL(&##ucode##TextStart), \ - OS_K0_TO_PHYSICAL(&##ucode##DataStart)) -#endif - -#ifdef F3DEX_GBI_2 -/* - * gSPDma_io DMA to/from DMEM/IMEM for DEBUG. - */ -#define gSPDma_io(pkt, flag, dmem, dram, size) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ - _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12); \ - _g->words.w1 = (unsigned int)(dram); \ -} - -#define gsSPDma_io(flag, dmem, dram, size) \ -{{ \ - _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ - _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12), \ - (unsigned int)(dram) \ -}} - -#define gSPDmaRead(pkt,dmem,dram,size) gSPDma_io((pkt),0,(dmem),(dram),(size)) -#define gsSPDmaRead(dmem,dram,size) gsSPDma_io(0,(dmem),(dram),(size)) -#define gSPDmaWrite(pkt,dmem,dram,size) gSPDma_io((pkt),1,(dmem),(dram),(size)) -#define gsSPDmaWrite(dmem,dram,size) gsSPDma_io(1,(dmem),(dram),(size)) -#endif - -/* - * Lighting Macros - */ -#ifdef F3DEX_GBI_2 -# define NUML(n) ((n)*24) -#else -# define NUML(n) (((n)+1)*32 + 0x80000000) -#endif -#define NUMLIGHTS_0 1 -#define NUMLIGHTS_1 1 -#define NUMLIGHTS_2 2 -#define NUMLIGHTS_3 3 -#define NUMLIGHTS_4 4 -#define NUMLIGHTS_5 5 -#define NUMLIGHTS_6 6 -#define NUMLIGHTS_7 7 -/* - * n should be one of: NUMLIGHTS_0, NUMLIGHTS_1, ..., NUMLIGHTS_7 - * NOTE: in addition to the number of directional lights specified, - * there is always 1 ambient light - */ -#define gSPNumLights(pkt, n) \ - gMoveWd(pkt, G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) -#define gsSPNumLights(n) \ - gsMoveWd( G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) - -#define LIGHT_1 1 -#define LIGHT_2 2 -#define LIGHT_3 3 -#define LIGHT_4 4 -#define LIGHT_5 5 -#define LIGHT_6 6 -#define LIGHT_7 7 -#define LIGHT_8 8 -/* - * l should point to a Light struct - * n should be one of: LIGHT_1, LIGHT_2, ..., LIGHT_8 - * NOTE: the highest numbered light is always the ambient light (eg if there are - * 3 directional lights defined: gsSPNumLights(NUMLIGHTS_3), then lights - * LIGHT_1 through LIGHT_3 will be the directional lights and light - * LIGHT_4 will be the ambient light. - */ -#ifdef F3DEX_GBI_2 -# define gSPLight(pkt, l, n) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) -# define gsSPLight(l, n) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) -#else /* F3DEX_GBI_2 */ -# define gSPLight(pkt, l, n) \ - gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) -# define gsSPLight(l, n) \ - gsDma1p( G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) -#endif /* F3DEX_GBI_2 */ - -/* - * gSPLightColor changes color of light without recalculating light direction - * col is a 32 bit word with r,g,b,a (alpha is ignored) - * n should be one of LIGHT_1, LIGHT_2, ..., LIGHT_8 - */ -#define gSPLightColor(pkt, n, col) \ -{ \ - gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_a##n, col); \ - gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_b##n, col); \ -} -#define gsSPLightColor(n, col) \ - gsMoveWd(G_MW_LIGHTCOL, G_MWO_a##n, col), \ - gsMoveWd(G_MW_LIGHTCOL, G_MWO_b##n, col) - -/* These macros use a structure "name" which is init'd with the gdSPDefLights macros*/ - -#define gSPSetLights0(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_0); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.a,2); \ -} -#define gsSPSetLights0(name) \ - gsSPNumLights(NUMLIGHTS_0), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.a,2) - -#define gSPSetLights1(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_1); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.a,2); \ -} -#define gsSPSetLights1(name) \ - gsSPNumLights(NUMLIGHTS_1), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.a,2) - -#define gSPSetLights2(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_2); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.a,3); \ -} -#define gsSPSetLights2(name) \ - gsSPNumLights(NUMLIGHTS_2), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.a,3) - -#define gSPSetLights3(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_3); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.a,4); \ -} -#define gsSPSetLights3(name) \ - gsSPNumLights(NUMLIGHTS_3), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.a,4) - -#define gSPSetLights4(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_4); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.a,5); \ -} -#define gsSPSetLights4(name) \ - gsSPNumLights(NUMLIGHTS_4), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.a,5) - -#define gSPSetLights5(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_5); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.l[4],5); \ - gSPLight(pkt,&name.a,6); \ -} - -#define gsSPSetLights5(name) \ - gsSPNumLights(NUMLIGHTS_5), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.l[4],5), \ - gsSPLight(&name.a,6) - -#define gSPSetLights6(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_6); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.l[4],5); \ - gSPLight(pkt,&name.l[5],6); \ - gSPLight(pkt,&name.a,7); \ -} - -#define gsSPSetLights6(name) \ - gsSPNumLights(NUMLIGHTS_6), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.l[4],5), \ - gsSPLight(&name.l[5],6), \ - gsSPLight(&name.a,7) - -#define gSPSetLights7(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_7); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.l[4],5); \ - gSPLight(pkt,&name.l[5],6); \ - gSPLight(pkt,&name.l[6],7); \ - gSPLight(pkt,&name.a,8); \ -} - -#define gsSPSetLights7(name) \ - gsSPNumLights(NUMLIGHTS_7), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.l[4],5), \ - gsSPLight(&name.l[5],6), \ - gsSPLight(&name.l[6],7), \ - gsSPLight(&name.a,8) - -/* - * Reflection/Hiliting Macros - */ -#ifdef F3DEX_GBI_2 -# define gSPLookAtX(pkt, l) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) -# define gsSPLookAtX(l) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) -# define gSPLookAtY(pkt, l) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) -# define gsSPLookAtY(l) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) -#else /* F3DEX_GBI_2 */ -# define gSPLookAtX(pkt, l) \ - gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) -# define gsSPLookAtX(l) \ - gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) -# define gSPLookAtY(pkt, l) \ - gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) -# define gsSPLookAtY(l) \ - gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) -#endif /* F3DEX_GBI_2 */ - -#define gSPLookAt(pkt, la) \ -{ \ - gSPLookAtX(pkt,la) \ - gSPLookAtY(pkt,(char *)(la)+16) \ -} -#define gsSPLookAt(la) \ - gsSPLookAtX(la), \ - gsSPLookAtY((char *)(la)+16) - -#define gDPSetHilite1Tile(pkt, tile, hilite, width, height) \ - gDPSetTileSize(pkt, tile, (hilite)->h.x1 & 0xfff, (hilite)->h.y1 & 0xfff, \ - ((((width)-1)*4)+(hilite)->h.x1) & 0xfff, ((((height)-1)*4)+(hilite)->h.y1) & 0xfff) - -#define gDPSetHilite2Tile(pkt, tile, hilite, width, height) \ - gDPSetTileSize(pkt, tile, (hilite)->h.x2 & 0xfff, (hilite)->h.y2 & 0xfff, \ - ((((width)-1)*4)+(hilite)->h.x2) & 0xfff, ((((height)-1)*4)+(hilite)->h.y2) & 0xfff) - - -/* - * FOG macros - * fm = z multiplier - * fo = z offset - * FOG FORMULA: alpha(fog) = (eyespace z) * fm + fo CLAMPED 0 to 255 - * note: (eyespace z) ranges -1 to 1 - * - * Alternate method of setting fog: - * min, max: range 0 to 1000: 0=nearplane, 1000=farplane - * min is where fog begins (usually less than max and often 0) - * max is where fog is thickest (usually 1000) - * - */ -#define gSPFogFactor(pkt, fm, fo) \ - gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) - -#define gsSPFogFactor(fm, fo) \ - gsMoveWd(G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) - -#define gSPFogPosition(pkt, min, max) \ - gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL((128000/((max)-(min))),16,16) | \ - _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) - -#define gsSPFogPosition(min, max) \ - gsMoveWd(G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL((128000/((max)-(min))),16,16) | \ - _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) - -#ifdef F3DEX_GBI_2 -/* - * Macros to turn texture on/off - */ -# define gSPTexture(pkt, s, t, level, tile, on) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ - _SHIFTL(BOWTIE_VAL,16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ - _SHIFTL((on),1,7)); \ - _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ -} -# define gsSPTexture(s, t, level, tile, on) \ -{{ \ - (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL(BOWTIE_VAL,16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ - (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ -}} -/* - * Different version of SPTexture macro, has an additional parameter - * which is currently reserved in the microcode. - */ -# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ - _SHIFTL((xparam),16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ - _SHIFTL((on),1,7)); \ - _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ -} -# define gsSPTextureL(s, t, level, xparam, tile, on) \ -{{ \ - (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL((xparam),16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ - (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ -}} -#else -/* - * Macros to turn texture on/off - */ -# define gSPTexture(pkt, s, t, level, tile, on) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)|\ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ - _SHIFTL((on),0,8)); \ - _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ -} -# define gsSPTexture(s, t, level, tile, on) \ -{{ \ - (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)| \ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ - (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ -}} -/* - * Different version of SPTexture macro, has an additional parameter - * which is currently reserved in the microcode. - */ -# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ - _SHIFTL((on),0,8)); \ - _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ -} -# define gsSPTextureL(s, t, level, xparam, tile, on) \ -{{ \ - (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ - (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ -}} -#endif - -#define gSPPerspNormalize(pkt, s) gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) -#define gsSPPerspNormalize(s) gsMoveWd( G_MW_PERSPNORM, 0, (s)) - -#ifdef F3DEX_GBI_2 -# define gSPPopMatrixN(pkt, n, num) gDma2p((pkt),G_POPMTX,(num)*64,64,2,0) -# define gsSPPopMatrixN(n, num) gsDma2p( G_POPMTX,(num)*64,64,2,0) -# define gSPPopMatrix(pkt, n) gSPPopMatrixN((pkt), (n), 1) -# define gsSPPopMatrix(n) gsSPPopMatrixN( (n), 1) -#else /* F3DEX_GBI_2 */ -# define gSPPopMatrix(pkt, n) gImmp1(pkt, G_POPMTX, n) -# define gsSPPopMatrix(n) gsImmp1( G_POPMTX, n) -#endif /* F3DEX_GBI_2 */ - -#define gSPEndDisplayList(pkt) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_ENDDL, 24, 8); \ - _g->words.w1 = 0; \ -} - -#define gsSPEndDisplayList() \ -{{ \ - _SHIFTL(G_ENDDL, 24, 8), 0 \ -}} - -#ifdef F3DEX_GBI_2 -/* - * One gSPGeometryMode(pkt,c,s) GBI is equal to these two GBIs. - * - * gSPClearGeometryMode(pkt,c) - * gSPSetGeometryMode(pkt,s) - * - * gSPLoadGeometryMode(pkt, word) sets GeometryMode directly. - */ -#define gSPGeometryMode(pkt, c, s) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24);\ - _g->words.w1 = (u32)(s); \ -} - -#define gsSPGeometryMode(c, s) \ -{{ \ - (_SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24)),(u32)(s) \ -}} -#define gSPSetGeometryMode(pkt, word) gSPGeometryMode((pkt),0,(word)) -#define gsSPSetGeometryMode(word) gsSPGeometryMode(0,(word)) -#define gSPClearGeometryMode(pkt, word) gSPGeometryMode((pkt),(word),0) -#define gsSPClearGeometryMode(word) gsSPGeometryMode((word),0) -#define gSPLoadGeometryMode(pkt, word) gSPGeometryMode((pkt),-1,(word)) -#define gsSPLoadGeometryMode(word) gsSPGeometryMode(-1,(word)) - -#else /* F3DEX_GBI_2 */ -#define gSPSetGeometryMode(pkt, word) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETGEOMETRYMODE, 24, 8); \ - _g->words.w1 = (unsigned int)(word); \ -} - -#define gsSPSetGeometryMode(word) \ -{{ \ - _SHIFTL(G_SETGEOMETRYMODE, 24, 8), (unsigned int)(word) \ -}} - -#define gSPClearGeometryMode(pkt, word) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8); \ - _g->words.w1 = (unsigned int)(word); \ -} - -#define gsSPClearGeometryMode(word) \ -{{ \ - _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8), (unsigned int)(word) \ -}} -#endif /* F3DEX_GBI_2 */ - -#ifdef F3DEX_GBI_2 -#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)| \ - _SHIFTL((len)-1,0,8)); \ - _g->words.w1 = (unsigned int)(data); \ -} - -#define gsSPSetOtherMode(cmd, sft, len, data) \ -{{ \ - _SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)|_SHIFTL((len)-1,0,8), \ - (unsigned int)(data) \ -}} -#else -#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | \ - _SHIFTL(len, 0, 8)); \ - _g->words.w1 = (unsigned int)(data); \ -} - -#define gsSPSetOtherMode(cmd, sft, len, data) \ -{{ \ - _SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | _SHIFTL(len, 0, 8), \ - (unsigned int)(data) \ -}} -#endif - -/* - * RDP setothermode register commands - register shadowed in RSP - */ -#define gDPPipelineMode(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) -#define gsDPPipelineMode(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) - -#define gDPSetCycleType(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) -#define gsDPSetCycleType(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) - -#define gDPSetTexturePersp(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) -#define gsDPSetTexturePersp(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) - -#define gDPSetTextureDetail(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) -#define gsDPSetTextureDetail(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) - -#define gDPSetTextureLOD(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) -#define gsDPSetTextureLOD(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) - -#define gDPSetTextureLUT(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) -#define gsDPSetTextureLUT(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) - -#define gDPSetTextureFilter(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) -#define gsDPSetTextureFilter(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) - -#define gDPSetTextureConvert(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) -#define gsDPSetTextureConvert(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) - -#define gDPSetCombineKey(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) -#define gsDPSetCombineKey(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) - -#ifndef _HW_VERSION_1 -#define gDPSetColorDither(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) -#define gsDPSetColorDither(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) -#else -#define gDPSetColorDither(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) -#define gsDPSetColorDither(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) -#endif - -#ifndef _HW_VERSION_1 -#define gDPSetAlphaDither(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) -#define gsDPSetAlphaDither(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) -#endif - -/* 'blendmask' is not supported anymore. - * The bits are reserved for future use. - * Fri May 26 13:45:55 PDT 1995 - */ -#define gDPSetBlendMask(pkt, mask) gDPNoOp(pkt) -#define gsDPSetBlendMask(mask) gsDPNoOp() - -#define gDPSetAlphaCompare(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) -#define gsDPSetAlphaCompare(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) - -#define gDPSetDepthSource(pkt, src) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) -#define gsDPSetDepthSource(src) \ - gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) - -#define gDPSetRenderMode(pkt, c0, c1) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ - (c0) | (c1)) -#define gsDPSetRenderMode(c0, c1) \ - gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ - (c0) | (c1)) - -#define gSetImage(pkt, cmd, fmt, siz, width, i) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ - _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12); \ - _g->words.w1 = (unsigned int)(i); \ -} - -#define gsSetImage(cmd, fmt, siz, width, i) \ -{{ \ - _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ - _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12), \ - (unsigned int)(i) \ -}} - -#define gDPSetColorImage(pkt, f, s, w, i) gSetImage(pkt, G_SETCIMG, f, s, w, i) -#define gsDPSetColorImage(f, s, w, i) gsSetImage(G_SETCIMG, f, s, w, i) - - -/* use these for new code */ -#define gDPSetDepthImage(pkt, i) gSetImage(pkt, G_SETZIMG, 0, 0, 1, i) -#define gsDPSetDepthImage(i) gsSetImage(G_SETZIMG, 0, 0, 1, i) -/* kept for compatibility */ -#define gDPSetMaskImage(pkt, i) gDPSetDepthImage(pkt, i) -#define gsDPSetMaskImage(i) gsDPSetDepthImage(i) - -#define gDPSetTextureImage(pkt, f, s, w, i) gSetImage(pkt, G_SETTIMG, f, s, w, i) -#define gsDPSetTextureImage(f, s, w, i) gsSetImage(G_SETTIMG, f, s, w, i) - -/* - * RDP macros - */ - -#define gDPSetCombine(pkt, muxs0, muxs1) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24);\ - _g->words.w1 = (unsigned int)(muxs1); \ -} - -#define gsDPSetCombine(muxs0, muxs1) \ -{{ \ - _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24), \ - (unsigned int)(muxs1) \ -}} - -#define GCCc0w0(saRGB0, mRGB0, saA0, mA0) \ - (_SHIFTL((saRGB0), 20, 4) | _SHIFTL((mRGB0), 15, 5) | \ - _SHIFTL((saA0), 12, 3) | _SHIFTL((mA0), 9, 3)) - -#define GCCc1w0(saRGB1, mRGB1) \ - (_SHIFTL((saRGB1), 5, 4) | _SHIFTL((mRGB1), 0, 5)) - -#define GCCc0w1(sbRGB0, aRGB0, sbA0, aA0) \ - (_SHIFTL((sbRGB0), 28, 4) | _SHIFTL((aRGB0), 15, 3) | \ - _SHIFTL((sbA0), 12, 3) | _SHIFTL((aA0), 9, 3)) - -#define GCCc1w1(sbRGB1, saA1, mA1, aRGB1, sbA1, aA1) \ - (_SHIFTL((sbRGB1), 24, 4) | _SHIFTL((saA1), 21, 3) | \ - _SHIFTL((mA1), 18, 3) | _SHIFTL((aRGB1), 6, 3) | \ - _SHIFTL((sbA1), 3, 3) | _SHIFTL((aA1), 0, 3)) - -#define gDPSetCombineLERP(pkt, a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ - a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | \ - _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ - G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ - GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), \ - 0, 24); \ - _g->words.w1 = (unsigned int)(GCCc0w1(G_CCMUX_##b0, \ - G_CCMUX_##d0, \ - G_ACMUX_##Ab0, \ - G_ACMUX_##Ad0) | \ - GCCc1w1(G_CCMUX_##b1, \ - G_ACMUX_##Aa1, \ - G_ACMUX_##Ac1, \ - G_CCMUX_##d1, \ - G_ACMUX_##Ab1, \ - G_ACMUX_##Ad1)); \ -} - -#define gsDPSetCombineLERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ - a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ -{{ \ - _SHIFTL(G_SETCOMBINE, 24, 8) | \ - _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ - G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ - GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), 0, 24), \ - (unsigned int)(GCCc0w1(G_CCMUX_##b0, G_CCMUX_##d0, \ - G_ACMUX_##Ab0, G_ACMUX_##Ad0) | \ - GCCc1w1(G_CCMUX_##b1, G_ACMUX_##Aa1, \ - G_ACMUX_##Ac1, G_CCMUX_##d1, \ - G_ACMUX_##Ab1, G_ACMUX_##Ad1)) \ -}} - -/* - * SetCombineMode macros are NOT redunant. It allow the C preprocessor - * to substitute single parameter which includes commas in the token and - * rescan for higher parameter count macro substitution. - * - * eg. gsDPSetCombineMode(G_CC_MODULATE, G_CC_MODULATE) turns into - * gsDPSetCombineLERP(TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0, - * TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0) - */ - -#define gDPSetCombineMode(pkt, a, b) gDPSetCombineLERP(pkt, a, b) -#define gsDPSetCombineMode(a, b) gsDPSetCombineLERP(a, b) - -#define gDPSetColor(pkt, c, d) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(c, 24, 8); \ - _g->words.w1 = (unsigned int)(d); \ -} - -#define gsDPSetColor(c, d) \ -{{ \ - _SHIFTL(c, 24, 8), (unsigned int)(d) \ -}} - -#define DPRGBColor(pkt, cmd, r, g, b, a) \ - gDPSetColor(pkt, cmd, \ - (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ - _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) -#define sDPRGBColor(cmd, r, g, b, a) \ - gsDPSetColor(cmd, \ - (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ - _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) - -#define gDPSetEnvColor(pkt, r, g, b, a) \ - DPRGBColor(pkt, G_SETENVCOLOR, r,g,b,a) -#define gsDPSetEnvColor(r, g, b, a) \ - sDPRGBColor(G_SETENVCOLOR, r,g,b,a) -#define gDPSetBlendColor(pkt, r, g, b, a) \ - DPRGBColor(pkt, G_SETBLENDCOLOR, r,g,b,a) -#define gsDPSetBlendColor(r, g, b, a) \ - sDPRGBColor(G_SETBLENDCOLOR, r,g,b,a) -#define gDPSetFogColor(pkt, r, g, b, a) \ - DPRGBColor(pkt, G_SETFOGCOLOR, r,g,b,a) -#define gsDPSetFogColor(r, g, b, a) \ - sDPRGBColor(G_SETFOGCOLOR, r,g,b,a) -#define gDPSetFillColor(pkt, d) \ - gDPSetColor(pkt, G_SETFILLCOLOR, (d)) -#define gsDPSetFillColor(d) \ - gsDPSetColor(G_SETFILLCOLOR, (d)) - -#define gDPSetPrimDepth(pkt, z, dz) \ - gDPSetColor(pkt, G_SETPRIMDEPTH, \ - _SHIFTL(z, 16, 16) | _SHIFTL(dz, 0, 16)) -#define gsDPSetPrimDepth(z, dz) \ - gsDPSetColor(G_SETPRIMDEPTH, _SHIFTL(z, 16, 16) | \ - _SHIFTL(dz, 0, 16)) - -#define gDPSetPrimColor(pkt, m, l, r, g, b, a) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | \ - _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)); \ - _g->words.w1 = (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ - _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8)); \ -} - -#define gsDPSetPrimColor(m, l, r, g, b, a) \ -{{ \ - (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | _SHIFTL(m, 8, 8) | \ - _SHIFTL(l, 0, 8)), \ - (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | \ - _SHIFTL(a, 0, 8)) \ -}} - -/* - * gDPSetOtherMode (This is for expert user.) - * - * This command makes all othermode parameters set. - * Do not use this command in the same DL with another g*SPSetOtherMode DLs. - * - * [Usage] - * gDPSetOtherMode(pkt, modeA, modeB) - * - * 'modeA' is described all parameters of GroupA GBI command. - * 'modeB' is also described all parameters of GroupB GBI command. - * - * GroupA: - * gDPPipelineMode, gDPSetCycleType, gSPSetTexturePersp, - * gDPSetTextureDetail, gDPSetTextureLOD, gDPSetTextureLUT, - * gDPSetTextureFilter, gDPSetTextureConvert, gDPSetCombineKey, - * gDPSetColorDither, gDPSetAlphaDither - * - * GroupB: - * gDPSetAlphaCompare, gDPSetDepthSource, gDPSetRenderMode - * - * Use 'OR' operation to get modeA and modeB. - * - * modeA = G_PM_* | G_CYC_* | G_TP_* | G_TD_* | G_TL_* | G_TT_* | G_TF_* - * G_TC_* | G_CK_* | G_CD_* | G_AD_*; - * - * modeB = G_AC_* | G_ZS_* | G_RM_* | G_RM_*2; - */ -#define gDPSetOtherMode(pkt, mode0, mode1) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24);\ - _g->words.w1 = (unsigned int)(mode1); \ -} - -#define gsDPSetOtherMode(mode0, mode1) \ -{{ \ - _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24), \ - (unsigned int)(mode1) \ -}} - -/* - * Texturing macros - */ - -/* These are also defined defined above for Sprite Microcode */ - -#define G_TX_LOADTILE 7 -#define G_TX_RENDERTILE 0 - -#define G_TX_NOMIRROR 0 -#define G_TX_WRAP 0 -#define G_TX_MIRROR 0x1 -#define G_TX_CLAMP 0x2 -#define G_TX_NOMASK 0 -#define G_TX_NOLOD 0 - - -#ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif -/* - * Dxt is the inverse of the number of 64-bit words in a line of - * the texture being loaded using the load_block command. If - * there are any 1's to the right of the 11th fractional bit, - * dxt should be rounded up. The following macros accomplish - * this. The 4b macros are a special case since 4-bit textures - * are loaded as 8-bit textures. Dxt is fixed point 1.11. RJM - */ -#define G_TX_DXT_FRAC 11 - -/* - * For RCP 2.0, the maximum number of texels that can be loaded - * using a load_block command is 2048. In order to load the total - * 4kB of Tmem, change the texel size when loading to be G_IM_SIZ_16b, - * then change the tile to the proper texel size after the load. - * The g*DPLoadTextureBlock macros already do this, so this change - * will be transparent if you use these macros. If you use - * the g*DPLoadBlock macros directly, you will need to handle this - * tile manipulation yourself. RJM. - */ -#ifdef _HW_VERSION_1 -#define G_TX_LDBLK_MAX_TXL 4095 -#else -#define G_TX_LDBLK_MAX_TXL 2047 -#endif /* _HW_VERSION_1 */ - -#define TXL2WORDS(txls, b_txl) MAX(1, ((txls)*(b_txl)/8)) -#define CALC_DXT(width, b_txl) \ - (((1 << G_TX_DXT_FRAC) + TXL2WORDS(width, b_txl) - 1) / \ - TXL2WORDS(width, b_txl)) - -#define TXL2WORDS_4b(txls) MAX(1, ((txls)/16)) -#define CALC_DXT_4b(width) \ - (((1 << G_TX_DXT_FRAC) + TXL2WORDS_4b(width) - 1) / \ - TXL2WORDS_4b(width)) - -#define gDPLoadTileGeneric(pkt, c, tile, uls, ult, lrs, lrt) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | \ - _SHIFTL(ult, 0, 12); \ - _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | \ - _SHIFTL(lrt, 0, 12); \ -} - -#define gsDPLoadTileGeneric(c, tile, uls, ult, lrs, lrt) \ -{{ \ - _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12), \ - _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | _SHIFTL(lrt, 0, 12)\ -}} - -#define gDPSetTileSize(pkt, t, uls, ult, lrs, lrt) \ - gDPLoadTileGeneric(pkt, G_SETTILESIZE, t, uls, ult, lrs, lrt) -#define gsDPSetTileSize(t, uls, ult, lrs, lrt) \ - gsDPLoadTileGeneric(G_SETTILESIZE, t, uls, ult, lrs, lrt) -#define gDPLoadTile(pkt, t, uls, ult, lrs, lrt) \ - gDPLoadTileGeneric(pkt, G_LOADTILE, t, uls, ult, lrs, lrt) -#define gsDPLoadTile(t, uls, ult, lrs, lrt) \ - gsDPLoadTileGeneric(G_LOADTILE, t, uls, ult, lrs, lrt) - -#define gDPSetTile(pkt, fmt, siz, line, tmem, tile, palette, cmt, \ - maskt, shiftt, cms, masks, shifts) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) |\ - _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | \ - _SHIFTL(tmem, 0, 9); \ - _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ - _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ - _SHIFTL(shiftt, 10, 4) |_SHIFTL(cms, 8, 2) | \ - _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4); \ -} - -#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, \ - maskt, shiftt, cms, masks, shifts) \ -{{ \ - (_SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) | \ - _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | _SHIFTL(tmem, 0, 9)),\ - (_SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ - _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ - _SHIFTL(shiftt, 10, 4) | _SHIFTL(cms, 8, 2) | \ - _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4)) \ -}} - -/* - * For RCP 2.0, the maximum number of texels that can be loaded - * using a load_block command is 2048. In order to load the total - * 4kB of Tmem, change the texel size when loading to be G_IM_SIZ_16b, - * then change the tile to the proper texel size after the load. - * The g*DPLoadTextureBlock macros already do this, so this change - * will be transparent if you use these macros. If you use - * the g*DPLoadBlock macros directly, you will need to handle this - * tile manipulation yourself. RJM. - */ -#define gDPLoadBlock(pkt, tile, uls, ult, lrs, dxt) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_LOADBLOCK, 24, 8) | \ - _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | \ - _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) |\ - _SHIFTL(dxt, 0, 12)); \ -} - -#define gsDPLoadBlock(tile, uls, ult, lrs, dxt) \ -{{ \ - (_SHIFTL(G_LOADBLOCK, 24, 8) | _SHIFTL(uls, 12, 12) | \ - _SHIFTL(ult, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | \ - _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) | \ - _SHIFTL(dxt, 0, 12)) \ -}} - -#define gDPLoadTLUTCmd(pkt, tile, count) \ -{ \ - Gfx *_g = (Gfx *)pkt; \ - \ - _g->words.w0 = _SHIFTL(G_LOADTLUT, 24, 8); \ - _g->words.w1 = _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10);\ -} - -#define gsDPLoadTLUTCmd(tile, count) \ -{{ \ - _SHIFTL(G_LOADTLUT, 24, 8), \ - _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10) \ -}} - -#define gDPLoadTextureBlock(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -#define gDPLoadTextureBlockYuv(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * 1)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* Load fix rww 27jun95 */ -/* The S at the end means odd lines are already word Swapped */ - -#define gDPLoadTextureBlockS(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* - * Allow tmem address and render tile to be specified. - * The S at the end means odd lines are already word Swapped - */ -#define gDPLoadMultiBlockS(pkt, timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * siz##_LINE_BYTES)+7)>>3, tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - - -#define gDPLoadTextureBlockYuvS(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * 1)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* - * allows tmem address to be specified - */ -#define _gDPLoadTextureBlock(pkt, timg, tmem, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0, cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ - tmem, G_TX_RENDERTILE, pal, cmt, \ - maskt, shiftt, cms, masks, shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* - * allows tmem address and render tile to be specified - */ -#define _gDPLoadTextureBlockTile(pkt, timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ - tmem, rtile, pal, cmt, \ - maskt, shiftt, cms, masks, shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* - * allows tmem address and render tile to be specified - */ -#define gDPLoadMultiBlock(pkt, timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ - tmem, rtile, pal, cmt, \ - maskt, shiftt, cms, masks, shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ - masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -/* Here is the static form of the pre-swapped texture block loading */ -/* See gDPLoadTextureBlockS() for reference. Basically, just don't - calculate DxT, use 0 */ - -#define gsDPLoadTextureBlockS(timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0 , \ - cmt, maskt,shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -/* - * Allow tmem address to be specified - */ -#define _gsDPLoadTextureBlock(timg, tmem, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, \ - ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - - -/* - * Allow tmem address and render_tile to be specified - */ -#define _gsDPLoadTextureBlockTile(timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, \ - ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - - -/* - * Allow tmem address and render_tile to be specified, useful when loading - * mutilple tiles at a time. - */ -#define gsDPLoadMultiBlock(timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, \ - ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -/* - * Allows tmem and render tile to be specified. Useful when loading - * several tiles at a time. - * - * Here is the static form of the pre-swapped texture block loading - * See gDPLoadTextureBlockS() for reference. Basically, just don't - * calculate DxT, use 0 - */ - -#define gsDPLoadMultiBlockS(timg, tmem, rtile, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0 , \ - cmt, maskt,shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), tmem,\ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - - -#define gDPLoadTextureBlock_4b(pkt, timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* Load fix rww 27jun95 */ -/* The S at the end means odd lines are already word Swapped */ - -#define gDPLoadTextureBlock_4bS(pkt, timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, 0 ); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* - * 4-bit load block. Useful when loading multiple tiles - */ -#define gDPLoadMultiBlock_4b(pkt, timg, tmem, rtile, fmt, width, height,\ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -/* - * 4-bit load block. Allows tmem and render tile to be specified. Useful when - * loading multiple tiles. The S means odd lines are already word swapped. - */ -#define gDPLoadMultiBlock_4bS(pkt, timg, tmem, rtile, fmt, width, height,\ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, 0 ); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - - -#define _gDPLoadTextureBlock_4b(pkt, timg, tmem, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ -} - -#define gsDPLoadTextureBlock_4b(timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -#define gsDPLoadTextureBlock_4bS(timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -/* - * 4-bit load block. Allows tmem address and render tile to be specified. - * Useful when loading multiple tiles. - */ -#define gsDPLoadMultiBlock_4b(timg, tmem, rtile, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - - -/* - * 4-bit load block. Allows tmem address and render tile to be specified. - * Useful when loading multiple tiles. S means odd lines are already swapped. - */ -#define gsDPLoadMultiBlock_4bS(timg, tmem, rtile, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - - -/* - * Allows tmem address to be specified - */ -#define _gsDPLoadTextureBlock_4b(timg, tmem, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -#ifndef _HW_VERSION_1 - -#define gDPLoadTextureTile(pkt, timg, fmt, siz, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz, width, timg); \ - gDPSetTile(pkt, fmt, siz, \ - (((((lrs)-(uls)+1) * siz##_TILE_BYTES)+7)>>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, \ - (uls)<>3), tmem, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, \ - (uls)<>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks,\ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, \ - (uls)<>3), \ - tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ - masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<>3), \ - tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, \ - (uls)<>1), timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, \ - masks, shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, \ - (uls)<>1), timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, \ - (uls)<>1), timg), \ - gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, \ - (uls)<>1), timg), \ - gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ - tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ - masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ - tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, \ - (uls)<words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(uly)*4.0F), 0, 12); \ - _g->words.w1 = _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(lry)*4.0F), 0, 12); \ -} - - -#define gDPSetScissorFrac(pkt, mode, ulx, uly, lrx, lry) \ -{ \ - Gfx *_g = (Gfx *)pkt; \ - \ - _g->words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((ulx)), 12, 12) | \ - _SHIFTL((int)((uly)), 0, 12); \ - _g->words.w1 = _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)((lrx)), 12, 12) | \ - _SHIFTL((int)((lry)), 0, 12); \ -} - -#define gsDPSetScissor(mode, ulx, uly, lrx, lry) \ -{{ \ - _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(uly)*4.0F), 0, 12), \ - _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(lry)*4.0F), 0, 12) \ -}} - -#define gsDPSetScissorFrac(mode, ulx, uly, lrx, lry) \ -{{ \ - _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((ulx)), 12, 12) | \ - _SHIFTL((int)((uly)), 0, 12), \ - _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)(lrx), 12, 12) | \ - _SHIFTL((int)(lry), 0, 12) \ -}} - -/* Fraction never used in fill */ -#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ - _SHIFTL((lrx), 14, 10) | _SHIFTL((lry), 2, 10));\ - _g->words.w1 = (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10));\ -} - -#define gsDPFillRectangle(ulx, uly, lrx, lry) \ -{{ \ - (_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 14, 10) | \ - _SHIFTL((lry), 2, 10)), \ - (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10)) \ -}} - -/* like gDPFillRectangle but accepts negative arguments */ -#define gDPScisFillRectangle(pkt, ulx, uly, lrx, lry) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ - _SHIFTL(MAX((lrx),0), 14, 10) | \ - _SHIFTL(MAX((lry),0), 2, 10)); \ - _g->words.w1 = (_SHIFTL(MAX((ulx),0), 14, 10) | \ - _SHIFTL(MAX((uly),0), 2, 10)); \ -} - -#define gDPSetConvert(pkt, k0, k1, k2, k3, k4, k5) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SETCONVERT, 24, 8) | \ - _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | \ - _SHIFTR(k2, 5, 4)); \ - _g->words.w1 = (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | \ - _SHIFTL(k4, 9, 9) | _SHIFTL(k5, 0, 9)); \ -} - -#define gsDPSetConvert(k0, k1, k2, k3, k4, k5) \ -{{ \ - (_SHIFTL(G_SETCONVERT, 24, 8) | \ - _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | _SHIFTR(k2, 5, 4)), \ - (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | _SHIFTL(k4, 9, 9) | \ - _SHIFTL(k5, 0, 9)) \ -}} - -#define gDPSetKeyR(pkt, cR, sR, wR) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETKEYR, 24, 8); \ - _g->words.w1 = (_SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | \ - _SHIFTL(sR, 0, 8)); \ -} - -#define gsDPSetKeyR(cR, sR, wR) \ -{{ \ - _SHIFTL(G_SETKEYR, 24, 8), \ - _SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | _SHIFTL(sR, 0, 8) \ -}} - -#define gDPSetKeyGB(pkt, cG, sG, wG, cB, sB, wB) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SETKEYGB, 24, 8) | \ - _SHIFTL(wG, 12, 12) | _SHIFTL(wB, 0, 12)); \ - _g->words.w1 = (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | \ - _SHIFTL(cB, 8, 8) | _SHIFTL(sB, 0, 8)); \ -} - -#define gsDPSetKeyGB(cG, sG, wG, cB, sB, wB) \ -{{ \ - (_SHIFTL(G_SETKEYGB, 24, 8) | _SHIFTL(wG, 12, 12) | \ - _SHIFTL(wB, 0, 12)), \ - (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | _SHIFTL(cB, 8, 8) | \ - _SHIFTL(sB, 0, 8)) \ -}} - -#define gDPNoParam(pkt, cmd) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(cmd, 24, 8); \ - _g->words.w1 = 0; \ -} - -#define gsDPNoParam(cmd) \ -{{ \ - _SHIFTL(cmd, 24, 8), 0 \ -}} - -#define gDPParam(pkt, cmd, param) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(cmd, 24, 8); \ - _g->words.w1 = (param); \ -} - -#define gsDPParam(cmd, param) \ -{{ \ - _SHIFTL(cmd, 24, 8), (param) \ -}} - -/* Notice that textured rectangles are 128-bit commands, therefore - * gsDPTextureRectangle() should not be used in display lists - * under normal circumstances (use gsSPTextureRectangle()). - * That is also why there is no gDPTextureRectangle() macros. - */ -#define gsDPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -{{ \ - (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ -}}, \ -{{ \ - _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ - _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ -}} - -#define gDPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - if (pkt); \ - _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - _g ++; \ - _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ - _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ -} - -#define gsDPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -{{ \ - (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ -}}, \ -{{ \ - _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ - _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ -}} - -#define gDPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - if (pkt); \ - _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - _g ++; \ - _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ - _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ -} - -#define gsSPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ - {{(_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)),\ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12))}}, \ - gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ - gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) - -#define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ - gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)));\ -} - -/* like gSPTextureRectangle but accepts negative position arguments */ -#define gSPScisTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | \ - _SHIFTL(MAX((s16)(xh),0), 12, 12) | \ - _SHIFTL(MAX((s16)(yh),0), 0, 12)); \ - _g->words.w1 = (_SHIFTL((tile), 24, 3) | \ - _SHIFTL(MAX((s16)(xl),0), 12, 12) | \ - _SHIFTL(MAX((s16)(yl),0), 0, 12)); \ - gImmp1(pkt, G_RDPHALF_1, \ - (_SHIFTL(((s) - \ - (((s16)(xl) < 0) ? \ - (((s16)(dsdx) < 0) ? \ - (MAX((((s16)(xl)*(s16)(dsdx))>>7),0)) : \ - (MIN((((s16)(xl)*(s16)(dsdx))>>7),0))) : 0)), \ - 16, 16) | \ - _SHIFTL(((t) - \ - (((yl) < 0) ? \ - (((s16)(dtdy) < 0) ? \ - (MAX((((s16)(yl)*(s16)(dtdy))>>7),0)) : \ - (MIN((((s16)(yl)*(s16)(dtdy))>>7),0))) : 0)), \ - 0, 16))); \ - gImmp1(pkt, G_RDPHALF_2, (_SHIFTL((dsdx), 16, 16) | \ - _SHIFTL((dtdy), 0, 16))); \ -} - -#define gsSPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ - {{(_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12))}}, \ - gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ - gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) - -#define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) |\ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ - gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \ -} - -#define gsDPWord(wordhi, wordlo) \ - gsImmp1(G_RDPHALF_1, (unsigned int)(wordhi)), \ - gsImmp1(G_RDPHALF_2, (unsigned int)(wordlo)) - -#define gDPWord(pkt, wordhi, wordlo) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - gImmp1(pkt, G_RDPHALF_1, (unsigned int)(wordhi)); \ - gImmp1(pkt, G_RDPHALF_2, (unsigned int)(wordlo)); \ -} - -#define gDPFullSync(pkt) gDPNoParam(pkt, G_RDPFULLSYNC) -#define gsDPFullSync() gsDPNoParam(G_RDPFULLSYNC) -#define gDPTileSync(pkt) gDPNoParam(pkt, G_RDPTILESYNC) -#define gsDPTileSync() gsDPNoParam(G_RDPTILESYNC) -#define gDPPipeSync(pkt) gDPNoParam(pkt, G_RDPPIPESYNC) -#define gsDPPipeSync() gsDPNoParam(G_RDPPIPESYNC) -#define gDPLoadSync(pkt) gDPNoParam(pkt, G_RDPLOADSYNC) -#define gsDPLoadSync() gsDPNoParam(G_RDPLOADSYNC) -#define gDPNoOp(pkt) gDPNoParam(pkt, G_NOOP) -#define gsDPNoOp() gsDPNoParam(G_NOOP) -#define gDPNoOpTag(pkt, tag) gDPParam(pkt, G_NOOP, tag) -#define gsDPNoOpTag(tag) gsDPParam(G_NOOP, tag) - -#endif /* _LANGUAGE_C */ - - -#endif /* _GBI_H_ */ diff --git a/lib/ultralib/include/PR/gs2dex.h b/lib/ultralib/include/PR/gs2dex.h deleted file mode 100644 index ced4685..0000000 --- a/lib/ultralib/include/PR/gs2dex.h +++ /dev/null @@ -1,392 +0,0 @@ -/*--------------------------------------------------------------------- - Copyright (C) 1997, Nintendo. - - File gs2dex.h - Coded by Yoshitaka Yasumoto. Jul 31, 1997. - Modified by - Comments Header file for S2DEX ucode. - - $Id: gs2dex.h,v 1.21 1998/05/28 00:14:49 has Exp $ - ---------------------------------------------------------------------*/ - -#ifndef _GS2DEX_H_ -#define _GS2DEX_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -/*===========================================================================* - * Macro - *===========================================================================*/ -#define GS_CALC_DXT(line) (((1<< G_TX_DXT_FRAC)-1)/(line)+1) -#define GS_PIX2TMEM(pix, siz) ((pix)>>(4-(siz))) -#define GS_PIX2DXT(pix, siz) GS_CALC_DXT(GS_PIX2TMEM((pix), (siz))) - -/*===========================================================================* - * Data structures for S2DEX microcode - *===========================================================================*/ - -/*---------------------------------------------------------------------------* - * Background - *---------------------------------------------------------------------------*/ -#define G_BGLT_LOADBLOCK 0x0033 -#define G_BGLT_LOADTILE 0xfff4 - -#define G_BG_FLAG_FLIPS 0x01 -#define G_BG_FLAG_FLIPT 0x10 - -/* Non scalable background plane */ -typedef struct { - u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */ - u16 imageW; /* width of the texture (u10.2) */ - s16 frameX; /* upper-left position of transferred frame (s10.2) */ - u16 frameW; /* width of transferred frame (u10.2) */ - - u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */ - u16 imageH; /* height of the texture (u10.2) */ - s16 frameY; /* upper-left position of transferred frame (s10.2) */ - u16 frameH; /* height of transferred frame (u10.2) */ - - u64 *imagePtr; /* texture source address on DRAM */ - u16 imageLoad; /* which to use, LoadBlock or LoadTile */ - u8 imageFmt; /* format of texel - G_IM_FMT_* */ - u8 imageSiz; /* size of texel - G_IM_SIZ_* */ - u16 imagePal; /* pallet number */ - u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ - - /* The following is set in the initialization routine guS2DInitBg(). There is no need for the user to set it. */ - u16 tmemW; /* TMEM width and Word size of frame 1 line. - At LoadBlock, GS_PIX2TMEM(imageW/4,imageSiz) - At LoadTile GS_PIX2TMEM(frameW/4,imageSiz)+1 */ - u16 tmemH; /* height of TMEM loadable at a time (s13.2) 4 times value - When the normal texture, 512/tmemW*4 - When the CI texture, 256/tmemW*4 */ - u16 tmemLoadSH; /* SH value - At LoadBlock, tmemSize/2-1 - At LoadTile, tmemW*16-1 */ - u16 tmemLoadTH; /* TH value or Stride value - At LoadBlock, GS_CALC_DXT(tmemW) - At LoadTile, tmemH-1 */ - u16 tmemSizeW; /* skip value of imagePtr for image 1-line - At LoadBlock, tmemW*2 - At LoadTile, GS_PIX2TMEM(imageW/4,imageSiz)*2 */ - u16 tmemSize; /* skip value of imagePtr for 1-loading - = tmemSizeW*tmemH */ -} uObjBg_t; /* 40 bytes */ - -/* Scalable background plane */ -typedef struct { - u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */ - u16 imageW; /* width of texture (u10.2) */ - s16 frameX; /* upper-left position of transferred frame (s10.2) */ - u16 frameW; /* width of transferred frame (u10.2) */ - - u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */ - u16 imageH; /* height of texture (u10.2) */ - s16 frameY; /* upper-left position of transferred frame (s10.2) */ - u16 frameH; /* height of transferred frame (u10.2) */ - - u64 *imagePtr; /* texture source address on DRAM */ - u16 imageLoad; /* Which to use, LoadBlock or LoadTile? */ - u8 imageFmt; /* format of texel - G_IM_FMT_* */ - u8 imageSiz; /* size of texel - G_IM_SIZ_* */ - u16 imagePal; /* pallet number */ - u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ - - u16 scaleW; /* scale value of X-direction (u5.10) */ - u16 scaleH; /* scale value of Y-direction (u5.10) */ - s32 imageYorig; /* start point of drawing on image (s20.5) */ - - u8 padding[4]; - -} uObjScaleBg_t; /* 40 bytes */ - -typedef union { - uObjBg_t b; - uObjScaleBg_t s; - long long int force_structure_alignment; -} uObjBg; - -/*---------------------------------------------------------------------------* - * 2D Objects - *---------------------------------------------------------------------------*/ -#define G_OBJ_FLAG_FLIPS 1<<0 /* inversion to S-direction */ -#define G_OBJ_FLAG_FLIPT 1<<4 /* nversion to T-direction */ - -typedef struct { - s16 objX; /* s10.2 OBJ x-coordinate of upper-left end */ - u16 scaleW; /* u5.10 Scaling of u5.10 width direction */ - u16 imageW; /* u10.5 width of u10.5 texture (length of S-direction) */ - u16 paddingX; /* Unused - Always 0 */ - s16 objY; /* s10.2 OBJ y-coordinate of s10.2 OBJ upper-left end */ - u16 scaleH; /* u5.10 Scaling of u5.10 height direction */ - u16 imageH; /* u10.5 height of u10.5 texture (length of T-direction) */ - u16 paddingY; /* Unused - Always 0 */ - u16 imageStride; /* folding width of texel (In units of 64bit word) */ - u16 imageAdrs; /* texture header position in TMEM (In units of 64bit word) */ - u8 imageFmt; /* format of texel - G_IM_FMT_* */ - u8 imageSiz; /* size of texel - G_IM_SIZ_* */ - u8 imagePal; /* pallet number (0-7) */ - u8 imageFlags; /* The display flag - G_OBJ_FLAG_FLIP* */ -} uObjSprite_t; /* 24 bytes */ - -typedef union { - uObjSprite_t s; - long long int force_structure_alignment; -} uObjSprite; - -/*---------------------------------------------------------------------------* - * 2D Matrix - *---------------------------------------------------------------------------*/ -typedef struct { - s32 A, B, C, D; /* s15.16 */ - s16 X, Y; /* s10.2 */ - u16 BaseScaleX; /* u5.10 */ - u16 BaseScaleY; /* u5.10 */ -} uObjMtx_t; /* 24 bytes */ - -typedef union { - uObjMtx_t m; - long long int force_structure_alignment; -} uObjMtx; - -typedef struct { - s16 X, Y; /* s10.2 */ - u16 BaseScaleX; /* u5.10 */ - u16 BaseScaleY; /* u5.10 */ -} uObjSubMtx_t; /* 8 bytes */ - -typedef union { - uObjSubMtx_t m; - long long int force_structure_alignment; -} uObjSubMtx; - -/*---------------------------------------------------------------------------* - * Loading into TMEM - *---------------------------------------------------------------------------*/ -#define G_OBJLT_TXTRBLOCK 0x00001033 -#define G_OBJLT_TXTRTILE 0x00fc1034 -#define G_OBJLT_TLUT 0x00000030 - -#define GS_TB_TSIZE(pix,siz) (GS_PIX2TMEM((pix),(siz))-1) -#define GS_TB_TLINE(pix,siz) (GS_CALC_DXT(GS_PIX2TMEM((pix),(siz)))) - -typedef struct { - u32 type; /* G_OBJLT_TXTRBLOCK divided into types */ - u64 *image; /* texture source address on DRAM */ - u16 tmem; /* loaded TMEM word address (8byteWORD) */ - u16 tsize; /* Texture size, Specified by macro GS_TB_TSIZE() */ - u16 tline; /* width of Texture 1-line, Specified by macro GS_TB_TLINE() */ - u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ - u32 flag; /* STATE flag */ - u32 mask; /* STATE mask */ -} uObjTxtrBlock_t; /* 24 bytes */ - -#define GS_TT_TWIDTH(pix,siz) ((GS_PIX2TMEM((pix), (siz))<<2)-1) -#define GS_TT_THEIGHT(pix,siz) (((pix)<<2)-1) - -typedef struct { - u32 type; /* G_OBJLT_TXTRTILE divided into types */ - u64 *image; /* texture source address on DRAM */ - u16 tmem; /* loaded TMEM word address (8byteWORD)*/ - u16 twidth; /* width of Texture (Specified by macro GS_TT_TWIDTH()) */ - u16 theight; /* height of Texture (Specified by macro GS_TT_THEIGHT()) */ - u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ - u32 flag; /* STATE flag */ - u32 mask; /* STATE mask */ -} uObjTxtrTile_t; /* 24 bytes */ - -#define GS_PAL_HEAD(head) ((head)+256) -#define GS_PAL_NUM(num) ((num)-1) - -typedef struct { - u32 type; /* G_OBJLT_TLUT divided into types */ - u64 *image; /* texture source address on DRAM */ - u16 phead; /* pallet number of load header (Between 256 and 511) */ - u16 pnum; /* loading pallet number -1 */ - u16 zero; /* Assign 0 all the time */ - u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12)*/ - u32 flag; /* STATE flag */ - u32 mask; /* STATE mask */ -} uObjTxtrTLUT_t; /* 24 bytes */ - -typedef union { - uObjTxtrBlock_t block; - uObjTxtrTile_t tile; - uObjTxtrTLUT_t tlut; - long long int force_structure_alignment; -} uObjTxtr; - -/*---------------------------------------------------------------------------* - * Loading into TMEM & 2D Objects - *---------------------------------------------------------------------------*/ -typedef struct { - uObjTxtr txtr; - uObjSprite sprite; -} uObjTxSprite; /* 48 bytes */ - -/*===========================================================================* - * GBI Commands for S2DEX microcode - *===========================================================================*/ -/* GBI Header */ -#ifdef F3DEX_GBI_2 -#define G_OBJ_RECTANGLE_R 0xda -#define G_OBJ_MOVEMEM 0xdc -#define G_RDPHALF_0 0xe4 -#define G_OBJ_RECTANGLE 0x01 -#define G_OBJ_SPRITE 0x02 -#define G_SELECT_DL 0x04 -#define G_OBJ_LOADTXTR 0x05 -#define G_OBJ_LDTX_SPRITE 0x06 -#define G_OBJ_LDTX_RECT 0x07 -#define G_OBJ_LDTX_RECT_R 0x08 -#define G_BG_1CYC 0x09 -#define G_BG_COPY 0x0a -#define G_OBJ_RENDERMODE 0x0b -#else -#define G_BG_1CYC 0x01 -#define G_BG_COPY 0x02 -#define G_OBJ_RECTANGLE 0x03 -#define G_OBJ_SPRITE 0x04 -#define G_OBJ_MOVEMEM 0x05 -#define G_SELECT_DL 0xb0 -#define G_OBJ_RENDERMODE 0xb1 -#define G_OBJ_RECTANGLE_R 0xb2 -#define G_OBJ_LOADTXTR 0xc1 -#define G_OBJ_LDTX_SPRITE 0xc2 -#define G_OBJ_LDTX_RECT 0xc3 -#define G_OBJ_LDTX_RECT_R 0xc4 -#define G_RDPHALF_0 0xe4 -#endif - -/*---------------------------------------------------------------------------* - * Background wrapped screen - *---------------------------------------------------------------------------*/ -#define gSPBgRectangle(pkt, m, mptr) gDma0p((pkt),(m),(mptr),0) -#define gsSPBgRectangle(m, mptr) gsDma0p( (m),(mptr),0) -#define gSPBgRectCopy(pkt, mptr) gSPBgRectangle((pkt), G_BG_COPY, (mptr)) -#define gsSPBgRectCopy(mptr) gsSPBgRectangle( G_BG_COPY, (mptr)) -#define gSPBgRect1Cyc(pkt, mptr) gSPBgRectangle((pkt), G_BG_1CYC, (mptr)) -#define gsSPBgRect1Cyc(mptr) gsSPBgRectangle( G_BG_1CYC, (mptr)) - -/*---------------------------------------------------------------------------* - * 2D Objects - *---------------------------------------------------------------------------*/ -#define gSPObjSprite(pkt, mptr) gDma0p((pkt),G_OBJ_SPRITE, (mptr),0) -#define gsSPObjSprite(mptr) gsDma0p( G_OBJ_SPRITE, (mptr),0) -#define gSPObjRectangle(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE, (mptr),0) -#define gsSPObjRectangle(mptr) gsDma0p( G_OBJ_RECTANGLE, (mptr),0) -#define gSPObjRectangleR(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE_R,(mptr),0) -#define gsSPObjRectangleR(mptr) gsDma0p( G_OBJ_RECTANGLE_R,(mptr),0) - -/*---------------------------------------------------------------------------* - * 2D Matrix - *---------------------------------------------------------------------------*/ -#define gSPObjMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),0,23) -#define gsSPObjMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),0,23) -#define gSPObjSubMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),2, 7) -#define gsSPObjSubMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),2, 7) - -/*---------------------------------------------------------------------------* - * Loading into TMEM - *---------------------------------------------------------------------------*/ -#define gSPObjLoadTxtr(pkt, tptr) gDma0p((pkt),G_OBJ_LOADTXTR, (tptr),23) -#define gsSPObjLoadTxtr(tptr) gsDma0p( G_OBJ_LOADTXTR, (tptr),23) -#define gSPObjLoadTxSprite(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_SPRITE,(tptr),47) -#define gsSPObjLoadTxSprite(tptr) gsDma0p( G_OBJ_LDTX_SPRITE,(tptr),47) -#define gSPObjLoadTxRect(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT, (tptr),47) -#define gsSPObjLoadTxRect(tptr) gsDma0p( G_OBJ_LDTX_RECT, (tptr),47) -#define gSPObjLoadTxRectR(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT_R,(tptr),47) -#define gsSPObjLoadTxRectR(tptr) gsDma0p( G_OBJ_LDTX_RECT_R,(tptr),47) - -/*---------------------------------------------------------------------------* - * Select Display List - *---------------------------------------------------------------------------*/ -#define gSPSelectDL(pkt, mptr, sid, flag, mask) \ -{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ - gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } -#define gsSPSelectDL(mptr, sid, flag, mask) \ -{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ - gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } -#define gSPSelectBranchDL(pkt, mptr, sid, flag, mask) \ -{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ - gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } -#define gsSPSelectBranchDL(mptr, sid, flag, mask) \ -{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ - gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } - -/*---------------------------------------------------------------------------* - * Set general status - *---------------------------------------------------------------------------*/ -#define G_MW_GENSTAT 0x08 /* Note that it is the same value of G_MW_FOG */ - -#define gSPSetStatus(pkt, sid, val) \ - gMoveWd((pkt), G_MW_GENSTAT, (sid), (val)) -#define gsSPSetStatus(sid, val) \ - gsMoveWd( G_MW_GENSTAT, (sid), (val)) - -/*---------------------------------------------------------------------------* - * Set Object Render Mode - *---------------------------------------------------------------------------*/ -#define G_OBJRM_NOTXCLAMP 0x01 -#define G_OBJRM_XLU 0x02 /* Ignored */ -#define G_OBJRM_ANTIALIAS 0x04 /* Ignored */ -#define G_OBJRM_BILERP 0x08 -#define G_OBJRM_SHRINKSIZE_1 0x10 -#define G_OBJRM_SHRINKSIZE_2 0x20 -#define G_OBJRM_WIDEN 0x40 - -#define gSPObjRenderMode(pkt, mode) gImmp1((pkt),G_OBJ_RENDERMODE,(mode)) -#define gsSPObjRenderMode(mode) gsImmp1( G_OBJ_RENDERMODE,(mode)) - -/*===========================================================================* - * Render Mode Macro - *===========================================================================*/ -#define RM_RA_SPRITE(clk) \ - AA_EN | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - -#define G_RM_SPRITE G_RM_OPA_SURF -#define G_RM_SPRITE2 G_RM_OPA_SURF2 -#define G_RM_RA_SPRITE RM_RA_SPRITE(1) -#define G_RM_RA_SPRITE2 RM_RA_SPRITE(2) -#define G_RM_AA_SPRITE G_RM_AA_TEX_TERR -#define G_RM_AA_SPRITE2 G_RM_AA_TEX_TERR2 -#define G_RM_XLU_SPRITE G_RM_XLU_SURF -#define G_RM_XLU_SPRITE2 G_RM_XLU_SURF2 -#define G_RM_AA_XLU_SPRITE G_RM_AA_XLU_SURF -#define G_RM_AA_XLU_SPRITE2 G_RM_AA_XLU_SURF2 - -/*===========================================================================* - * External functions - *===========================================================================*/ -extern u64 gspS2DEX_fifoTextStart[], gspS2DEX_fifoTextEnd[]; -extern u64 gspS2DEX_fifoDataStart[], gspS2DEX_fifoDataEnd[]; -extern u64 gspS2DEX_fifo_dTextStart[], gspS2DEX_fifo_dTextEnd[]; -extern u64 gspS2DEX_fifo_dDataStart[], gspS2DEX_fifo_dDataEnd[]; -extern u64 gspS2DEX2_fifoTextStart[], gspS2DEX2_fifoTextEnd[]; -extern u64 gspS2DEX2_fifoDataStart[], gspS2DEX2_fifoDataEnd[]; -extern u64 gspS2DEX2_xbusTextStart[], gspS2DEX2_xbusTextEnd[]; -extern u64 gspS2DEX2_xbusDataStart[], gspS2DEX2_xbusDataEnd[]; -extern void guS2DInitBg(uObjBg *); - -#ifdef F3DEX_GBI_2 -# define guS2DEmuBgRect1Cyc guS2D2EmuBgRect1Cyc /*Wrapper*/ -# define guS2DEmuSetScissor guS2D2EmuSetScissor /*Wrapper*/ - extern void guS2D2EmuSetScissor(u32, u32, u32, u32, u8); - extern void guS2D2EmuBgRect1Cyc(Gfx **, uObjBg *); -#else - extern void guS2DEmuSetScissor(u32, u32, u32, u32, u8); - extern void guS2DEmuBgRect1Cyc(Gfx **, uObjBg *); -#endif - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif -#endif /* _GS2DEX_H_ */ - -/*======== End of gs2dex.h ========*/ diff --git a/lib/ultralib/include/PR/gt.h b/lib/ultralib/include/PR/gt.h deleted file mode 100644 index 09b6ba2..0000000 --- a/lib/ultralib/include/PR/gt.h +++ /dev/null @@ -1,365 +0,0 @@ - -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: gt.h - * Creator: hsa@sgi.com - * Create Date: Thu Oct 12 15:48:14 PDT 1995 - * - * This file defines the GBI for the TURBO 3D graphics microcode. - * The turbo microcode is a special FEATURE-LIMITED microcode designed - * for specific applications. It is not for general use. - * - * (see XXX for more information) - * - */ - -/************************************************************************** - * - * $Revision: 1.16 $ - * $Date: 1998/05/28 00:14:50 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gt.h,v $ - * - **************************************************************************/ - -#ifndef _GT_H_ -#define _GT_H_ - -/* this file should be #included AFTER gbi.h */ - -#include "sptask.h" - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif /* _LANGUAGE_C_PLUS_PLUS */ - -#include - -/* the following #defines seem out of order, but we need them - * for the microcode. - */ - -/* - * object state field: rendState - * - * This flag word is built up out of the bits from a - * subset of the G_SETGEOMETRYMODE flags from gbi.h. - * - * When each of these bits is '1', the comments below explain - * the effect on the triangles. - */ -#define GT_ZBUFFER G_ZBUFFER -#define GT_TEXTURE G_TEXTURE_ENABLE /* texture ON */ -#define GT_CULL_BACK G_CULL_BACK /* reject backfaces */ -#define GT_SHADING_SMOOTH G_SHADING_SMOOTH /* smooth shade ON */ - -/* - * object state field: textureState - * - * The lower 3 bits of this flag word contain the texture tile number - * to be used. All triangles of an object are rendered with the same - * texture tile. - */ - -/* - * object state field: flag - * - * This is a group of what would be pad bits. We use them for some - * flag bits. - */ -#define GT_FLAG_NOMTX 0x01 /* don't load the matrix */ -#define GT_FLAG_NO_XFM 0x02 /* load vtx, use verbatim */ -#define GT_FLAG_XFM_ONLY 0x04 /* xform vtx, write to *TriN */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* turbo 3D ucode: */ -extern long long int gspTurbo3DTextStart[], gspTurbo3DTextEnd[]; -extern long long int gspTurbo3DDataStart[], gspTurbo3DDataEnd[]; -extern long long int gspTurbo3D_dramTextStart[], gspTurbo3D_dramTextEnd[]; -extern long long int gspTurbo3D_dramDataStart[], gspTurbo3D_dramDataEnd[]; -extern long long int gspTurbo3D_fifoTextStart[], gspTurbo3D_fifoTextEnd[]; -extern long long int gspTurbo3D_fifoDataStart[], gspTurbo3D_fifoDataEnd[]; - -/* - * This is the global state structure. It's definition carefully - * matches the ucode, so if this structure changes, you must also change - * the ucode. - */ -typedef struct { - u16 perspNorm; /* persp normalization */ - u16 pad0; - u32 flag; - Gfx rdpOthermode; - u32 segBases[16]; /* table of segment base addrs (SEE NOTE!) */ - Vp viewport; /* the viewport to use */ - Gfx *rdpCmds; /* block of RDP data, process if !NULL - * block terminated by gDPEndDisplayList() - * (This is a segment address) - */ -} gtGlobState_t; - -/* NOTE: - * Although there are 16 segment table entries, the first one (segment 0) - * is reserved for physical memory mapping. You should not segment 0 - * to anything other than 0x0. - */ - -typedef union { - gtGlobState_t sp; - long long int force_structure_alignment; -} gtGlobState; - - -/* - * This is the 'state' structure associated with each object - * to be rendered. It's definition carefully matches the - * ucode, so if this structure changes, you must also change - * the gtoff.c tool and the ucode. - */ -typedef struct { - u32 renderState; /* render state */ - u32 textureState; /* texture state */ - u8 vtxCount; /* how many verts? */ - u8 vtxV0; /* where to load verts? */ - u8 triCount; /* how many tris? */ - u8 flag; - Gfx *rdpCmds; /* ptr (segment address) to RDP DL */ - Gfx rdpOthermode; - Mtx transform; /* the transform matrix to use */ -} gtState_t; - -typedef union { - gtState_t sp; - long long int force_structure_alignment; -} gtState; - -/* gtStateLite : same as gtState, but no matrix (see flags below) */ -/* this structure must be identical to gtState! (bad) */ -typedef struct { - u32 renderState; /* render state */ - u32 textureState; /* texture state */ - u8 vtxCount; /* how many verts? */ - u8 vtxV0; /* where to load verts? */ - u8 triCount; /* how many tris? */ - u8 flag; - Gfx *rdpCmds; /* ptr (segment address) to RDP DL */ - Gfx rdpOthermode; -} gtStateL_t; - -typedef union { - gtStateL_t sp; - long long int force_structure_alignment; -} gtStateL; - -/* - * The vertex list for the turbo display list uses the - * Vtx struct in gbi.h - * - */ - - -/* - * This structure represents a single triangle, part of the - * triangle list of the object to be rendered. - * - * NOTE: The triangle list MUST be aligned to an 8-byte boundary. - * Since this structure is only 4 bytes, we are REQUIRING that - * this structure only be used as an array of triangles, and we - * depend on the MIPS C compiler (which always aligns arrays to - * 8-byte boundaries). THIS IS DANGEROUS!!!! - * - */ -typedef struct { - u8 v0, v1, v2, flag; /* flag is which one for flat shade */ -} gtTriN; - - -/* - * This structure represents the transformed points. It is the format - * of the points written out when GT_FLAG_XFM_ONLY is set, as well as - * the format expected when GT_FLAG_NO_XFM is used. - * - * NOTE: The size and layout of these points is very similar to Vtx, - * except the screen coordinates overwrite the x,y,z,pad fields. - * (we could consider adding to the Vtx union, but we want to keep - * turbo stuff out of gbi.h) - * - * NOTE: The z is a special format. It can be used to compare vertices - * for sorting, but it should not be used for other purposes. If modified, - * the z-buffer hardware might not understand the data. - * - */ -typedef struct { - short int xscrn; /* x,y screen coordinates are SSSS10.2 */ - short int yscrn; - int zscrn; /* z screen is S15.16 */ - - short int s; /* transformed texture coord, S10.5 */ - short int t; - - u8 r; /* color (or normal) */ - u8 g; - u8 b; - u8 a; -} gtVtxOut_t; - -/* see "Data Structure" comment in gbi.h for information about why - * we use this union. - */ -typedef union { - gtVtxOut_t v; - long long int force_structure_alignment; -} gtVtxOut; - - - -/* - * state field: rdpOthermode - * - * This is one of the trickier state fields. The turbo interface - * requires the RDP othermode command to be cached by the host, - * therefore we provide a different interface in libultra to help cache - * this in the gt state (this word is just bits, you could pack them - * on your own). - * - * gtStateSetOthermode() accomplishs this, taking as arguments - * the state, one of the following mode enums, and a piece of data - * (othermode parameters from gbi.h). - * - * By definition, the othermode word from the gt state structure is sent - * to the RDP *before* any RDP commands from the rdpCmds[] field. The - * othermode is *always* sent. - * - * Stated another way, NONE of the gbi RDP othermode commands equivalent - * to those listed here are allowed in the rdpCmd[] field of the - * gt state structure. - * - * Notice also that many of these commands do not make sense for - * the turbo ucode (they control features not supported, like mip-mapping). - * They are only included here for completeness. - * - */ -typedef enum { - GT_CLEAR, /* special gt mode, clears othermode state */ - GT_ALPHACOMPARE, - GT_ZSRCSEL, - GT_RENDERMODE, - GT_ALPHADITHER, - GT_RGBDITHER, - GT_COMBKEY, - GT_TEXTCONV, - GT_TEXTFILT, - GT_TEXTLUT, - GT_TEXTLOD, - GT_TEXTDETAIL, - GT_TEXTPERSP, - GT_CYCLETYPE, - GT_PIPELINE -} gtStateOthermode_t; - -/* - * This call builds up an othermode command word. The 'mode' is one of - * the above modes, the 'data' field comes from gbi.h, it is the data - * field for the equivalent gbi setothermode macro. - */ -extern void gtStateSetOthermode(Gfx *om, gtStateOthermode_t mode, int data); - -/* - * This call dumps a turbo display list for use with gbi2mem and RSPSIM - */ -#define GT_DUMPTURBO_HANGAFTER 64 -#define GT_DUMPTURBO_NOTEXTURES 128 -extern void gtDumpTurbo(OSTask *tp,u8 flags); - -/* - * Special macros to init othermode words to all 0's, a good default - * value. - */ -#define gDPClearOtherMode(pkt) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE, 24, 8); \ - _g->words.w1 = 0x0; \ -} - -#define gsDPClearOtherMode() \ -{ \ - _SHIFTL(G_RDPSETOTHERMODE, 24, 8), 0x0 \ -} - -/* - * Special macros to end DP blocks (see above). These commands - * generate all 0's, which the turbo ucode looks for. They *aren't* - * real DP commands! - */ -#define gDPEndDisplayList(pkt) gSPNoOp(pkt) -#define gsDPEndDisplayList() gsSPNoOp() - -/* - * This structure is a turbo 'object', the turbo display list is - * simply a list of these. - * - * NOTE: All pointers are segment addresses - * - * NOTE: If (statep->flag & GT_FLAG_XFM_ONLY), the trip field is - * interpreted as a pointer to gtVtxOut[] that can be used to store - * the transformed points. (statep->triCount should be 0, else bad - * things could happen...) - * - * NOTE: If (statep->flag & GT_FLAG_NO_XFM), the vtxp field is - * interpreted as a pointer to gtVtxOut[] that can be used to load - * pre-transformed points. - * - */ -typedef struct { - gtGlobState *gstatep; /* global state, usually NULL */ - gtState *statep; /* if this is NULL, end object processing */ - Vtx *vtxp; /* if this is NULL, use points in buffer */ - gtTriN *trip; /* if this is NULL, use tris in buffer */ -} gtGfx_t; - -typedef union { - gtGfx_t obj; - long long int force_structure_alignment; -} gtGfx; - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_ASSEMBLY -#include -#endif /* _LANGUAGE_ASSEMBLY */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif /* _LANGUAGE_C_PLUS_PLUS */ - -#ifdef _LANGUAGE_MAKEROM -#endif /* _LANGUAGE_MAKEROM */ - -#endif /* _GT_H_ */ diff --git a/lib/ultralib/include/PR/gu.h b/lib/ultralib/include/PR/gu.h deleted file mode 100644 index 9a2fa2b..0000000 --- a/lib/ultralib/include/PR/gu.h +++ /dev/null @@ -1,270 +0,0 @@ -#ifndef _GU_H_ -#define _GU_H_ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.48 $ - * $Date: 1999/07/13 08:00:20 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gu.h,v $ - * - **************************************************************************/ - -#include -#include -#include -#include - -#ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) -#endif -#ifndef MIN -#define MIN(a,b) (((a)<(b))?(a):(b)) -#endif - -#define M_PI 3.14159265358979323846 -#define M_DTOR (3.14159265358979323846/180.0) - -#define FTOFIX32(x) (long)((x) * (float)0x00010000) -#define FIX32TOF(x) ((float)(x) * (1.0f / (float)0x00010000)) -#define FTOFRAC8(x) ((int) MIN(((x) * (128.0f)), 127.0f) & 0xff) - -#define FILTER_WRAP 0 -#define FILTER_CLAMP 1 - -#define RAND(x) (guRandom()%x) /* random number between 0 to x */ - -/* - * Data Structures - */ -typedef struct { - unsigned char *base; - int fmt, siz; - int xsize, ysize; - int lsize; - /* current tile info */ - int addr; - int w, h; - int s, t; -} Image; - -typedef struct { - float col[3]; - float pos[3]; - float a1, a2; /* actual color = col/(a1*dist + a2) */ -} PositionalLight; - - -/* - * Function Prototypes - */ - -extern int guLoadTextureBlockMipMap(Gfx **glist, unsigned char *tbuf, Image *im, - unsigned char startTile, unsigned char pal, unsigned char cms, - unsigned char cmt, unsigned char masks, unsigned char maskt, - unsigned char shifts, unsigned char shiftt, unsigned char cfs, - unsigned char cft); - -extern int guGetDPLoadTextureTileSz (int ult, int lrt); -extern void guDPLoadTextureTile (Gfx *glistp, void *timg, - int texl_fmt, int texl_size, - int img_width, int img_height, - int uls, int ult, int lrs, int lrt, - int palette, - int cms, int cmt, - int masks, int maskt, - int shifts, int shiftt); - - -/* - * matrix operations: - * - * The 'F' version is floating point, in case the application wants - * to do matrix manipulations and convert to fixed-point at the last - * minute. - */ -extern void guMtxIdent(Mtx *m); -extern void guMtxIdentF(float mf[4][4]); -extern void guOrtho(Mtx *m, float l, float r, float b, float t, - float n, float f, float scale); -extern void guOrthoF(float mf[4][4], float l, float r, float b, float t, - float n, float f, float scale); -extern void guFrustum(Mtx *m, float l, float r, float b, float t, - float n, float f, float scale); -extern void guFrustumF(float mf[4][4], float l, float r, float b, float t, - float n, float f, float scale); -extern void guPerspective(Mtx *m, u16 *perspNorm, float fovy, - float aspect, float near, float far, float scale); -extern void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, - float aspect, float near, float far, float scale); -extern void guLookAt(Mtx *m, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp); -extern void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp); -extern void guLookAtReflect(Mtx *m, LookAt *l, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp); -extern void guLookAtReflectF(float mf[4][4], LookAt *l, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp); -extern void guLookAtHilite(Mtx *m, LookAt *l, Hilite *h, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, - float xl1, float yl1, float zl1, - float xl2, float yl2, float zl2, - int twidth, int theight); -extern void guLookAtHiliteF(float mf[4][4], LookAt *l, Hilite *h, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, - float xl1, float yl1, float zl1, - float xl2, float yl2, float zl2, - int twidth, int theight); -extern void guLookAtStereo(Mtx *m, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, - float eyedist); -extern void guLookAtStereoF(float mf[4][4], - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, - float eyedist); -extern void guRotate(Mtx *m, float a, float x, float y, float z); -extern void guRotateF(float mf[4][4], float a, float x, float y, float z); -extern void guRotateRPY(Mtx *m, float r, float p, float y); -extern void guRotateRPYF(float mf[4][4], float r, float p, float h); -extern void guAlign(Mtx *m, float a, float x, float y, float z); -extern void guAlignF(float mf[4][4], float a, float x, float y, float z); -extern void guScale(Mtx *m, float x, float y, float z); -extern void guScaleF(float mf[4][4], float x, float y, float z); -extern void guTranslate(Mtx *m, float x, float y, float z); -extern void guTranslateF(float mf[4][4], float x, float y, float z); -extern void guPosition(Mtx *m, float r, float p, float h, float s, - float x, float y, float z); -extern void guPositionF(float mf[4][4], float r, float p, float h, float s, - float x, float y, float z); -extern void guMtxF2L(float mf[4][4], Mtx *m); -extern void guMtxL2F(float mf[4][4], Mtx *m); -extern void guMtxCatF(float m[4][4], float n[4][4], float r[4][4]); -extern void guMtxCatL(Mtx *m, Mtx *n, Mtx *res); -extern void guMtxXFMF(float mf[4][4], float x, float y, float z, - float *ox, float *oy, float *oz); -extern void guMtxXFML(Mtx *m, float x, float y, float z, - float *ox, float *oy, float *oz); - -/* vector utility: */ -extern void guNormalize(float *x, float *y, float *z); - -/* light utilities: */ -void guPosLight(PositionalLight *pl, Light *l, - float xOb, float yOb, float zOb); -void guPosLightHilite(PositionalLight *pl1, PositionalLight *pl2, - Light *l1, Light *l2, - LookAt *l, Hilite *h, - float xEye, float yEye, float zEye, - float xOb, float yOb, float zOb, - float xUp, float yUp, float zUp, - int twidth, int theight); -extern int guRandom(void); - -/* - * Math functions - */ -extern float sinf(float angle); -extern float cosf(float angle); -extern signed short sins (unsigned short angle); -extern signed short coss (unsigned short angle); -extern float sqrtf(float value); -#if defined(__sgi) && BUILD_VERSION >= VERSION_K -#pragma intrinsic(sqrtf); -#endif - -/* - * Dump routines for low-level display lists - */ -/* flag values for guParseRdpDL() */ -#define GU_PARSERDP_VERBOSE 1 -#define GU_PARSERDP_PRAREA 2 -#define GU_PARSERDP_PRHISTO 4 -#define GU_PARSERDP_DUMPONLY 32 /* doesn't need to be same as */ - /* GU_PARSEGBI_DUMPOLNY, but this */ - /* allows app to use interchangeably */ - -extern void guParseRdpDL(u64 *rdp_dl, u64 nbytes, u8 flags); -extern void guParseString(char *StringPointer, u64 nbytes); - -/* - * NO LONGER SUPPORTED, - * use guParseRdpDL with GU_PARSERDP_DUMPONLY flags - */ -/* extern void guDumpRawRdpDL(u64 *rdp_dl, u64 nbytes); */ - -/* flag values for guBlinkRdpDL() */ -#define GU_BLINKRDP_HILITE 1 -#define GU_BLINKRDP_EXTRACT 2 - -extern void -guBlinkRdpDL(u64 *rdp_dl_in, u64 nbytes_in, - u64 *rdp_dl_out, u64 *nbytes_out, - u32 x, u32 y, u32 radius, - u8 red, u8 green, u8 blue, - u8 flags); - -/* flag values for guParseGbiDL() */ -#define GU_PARSEGBI_ROWMAJOR 1 -#define GU_PARSEGBI_NONEST 2 -#define GU_PARSEGBI_FLTMTX 4 -#define GU_PARSEGBI_SHOWDMA 8 -#define GU_PARSEGBI_ALLMTX 16 -#define GU_PARSEGBI_DUMPONLY 32 -/* -#define GU_PARSEGBI_HANGAFTER 64 -#define GU_PARSEGBI_NOTEXTURES 128 -*/ -extern void guParseGbiDL(u64 *gbi_dl, u32 nbytes, u8 flags); -extern void guDumpGbiDL(OSTask *tp,u8 flags); - -#define GU_PARSE_GBI_TYPE 1 -#define GU_PARSE_RDP_TYPE 2 -#define GU_PARSE_READY 3 -#define GU_PARSE_MEM_BLOCK 4 -#define GU_PARSE_ABI_TYPE 5 -#define GU_PARSE_STRING_TYPE 6 - -typedef struct { - int dataSize; - int dlType; - int flags; - u32 paddr; -} guDLPrintCB; - -void guSprite2DInit(uSprite *SpritePointer, - void *SourceImagePointer, - void *TlutPointer, - int Stride, - int SubImageWidth, - int SubImageHeight, - int SourceImageType, - int SourceImageBitSize, - int SourceImageOffsetS, - int SourceImageOffsetT); - -#endif /* !_GU_H_ */ diff --git a/lib/ultralib/include/PR/libaudio.h b/lib/ultralib/include/PR/libaudio.h deleted file mode 100644 index 33017b7..0000000 --- a/lib/ultralib/include/PR/libaudio.h +++ /dev/null @@ -1,947 +0,0 @@ -/*==================================================================== - * libaudio.h - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/************************************************************************** - * - * $Revision: 1.173 $ - * $Date: 1997/12/01 12:42:21 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/libaudio.h,v $ - * - **************************************************************************/ - -#ifndef __LIB_AUDIO__ -#define __LIB_AUDIO__ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include - -/*********************************************************************** - * misc defines - ***********************************************************************/ -#ifndef _EMULATOR -# ifdef AUD_PROFILE - -#define PROFILE_AUD(num, cnt, max, min) \ -{ \ - u32 currCnt = osGetCount(); \ - currCnt -= lastCnt[cnt_index]; \ - cnt_index--; \ - cnt += currCnt; \ - num++; \ - \ - if ( currCnt > max ) max = currCnt; \ - if ( currCnt < min ) min = currCnt; \ -} - -# endif /* AUD_PROFILE */ -#endif /* EMULATOR */ - -#ifndef NULL -#define NULL 0 -#endif - -#define AL_FX_BUFFER_SIZE 8192 -#define AL_FRAME_INIT -1 -#define AL_USEC_PER_FRAME 16000 -#define AL_MAX_PRIORITY 127 -#define AL_GAIN_CHANGE_TIME 1000 - -typedef s32 ALMicroTime; -typedef u8 ALPan; - -#define AL_PAN_CENTER 64 -#define AL_PAN_LEFT 0 -#define AL_PAN_RIGHT 127 -#define AL_VOL_FULL 127 -#define AL_KEY_MIN 0 -#define AL_KEY_MAX 127 -#define AL_DEFAULT_FXMIX 0 -#define AL_SUSTAIN 63 - -/*********************************************************************** - * Error handling - ***********************************************************************/ - -#ifdef _DEBUG -#define ALFailIf(condition, error) \ - if (condition) { \ - __osError(error, 0); \ - return; } - -#else -#define ALFailIf(condition, error) \ - if (condition) { \ - return; } -#endif - -#ifdef _DEBUG -#define ALFlagFailIf(condition, flag, error) \ - if (condition) { \ - if(flag) __osError(error, 0); \ - return; } - -#else -#define ALFlagFailIf(condition, flag, error) \ - if (condition) { \ - return; } -#endif - -/*********************************************************************** - * Audio Library global routines - ***********************************************************************/ -typedef struct ALLink_s { - struct ALLink_s *next; - struct ALLink_s *prev; -} ALLink; - -void alUnlink(ALLink *element); -void alLink(ALLink *element, ALLink *after); - -typedef s32 (*ALDMAproc)(s32 addr, s32 len, void *state); -typedef ALDMAproc (*ALDMANew)(void *state); - -void alCopy(void *src, void *dest, s32 len); - -typedef struct { - u8 *base; - u8 *cur; - s32 len; - s32 count; -} ALHeap; - -#define AL_HEAP_DEBUG 1 -#define AL_HEAP_MAGIC 0x20736a73 -#define AL_HEAP_INIT 0 - -void alHeapInit(ALHeap *hp, u8 *base, s32 len); -void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); -s32 alHeapCheck(ALHeap *hp); - -#ifdef _DEBUG -#define alHeapAlloc(hp, elem ,size) alHeapDBAlloc((u8 *) __FILE__,__LINE__,(hp),(elem),(size)) -#else -#define alHeapAlloc(hp, elem ,size) alHeapDBAlloc(0, 0,(hp),(elem),(size)) -#endif - -/*********************************************************************** - * FX Stuff - ***********************************************************************/ -#define AL_FX_NONE 0 -#define AL_FX_SMALLROOM 1 -#define AL_FX_BIGROOM 2 -#define AL_FX_CHORUS 3 -#define AL_FX_FLANGE 4 -#define AL_FX_ECHO 5 -#define AL_FX_CUSTOM 6 - -typedef u8 ALFxId; -typedef void *ALFxRef; - -/*********************************************************************** - * data structures for sound banks - ***********************************************************************/ - -#define AL_BANK_VERSION 0x4231 /* 'B1' */ - -/* Possible wavetable types */ -enum {AL_ADPCM_WAVE = 0, - AL_RAW16_WAVE}; - -typedef struct { - s32 order; - s32 npredictors; - s16 book[1]; /* Actually variable size. Must be 8-byte aligned */ -} ALADPCMBook; - -typedef struct { - u32 start; - u32 end; - u32 count; - ADPCM_STATE state; -} ALADPCMloop; - -typedef struct { - u32 start; - u32 end; - u32 count; -} ALRawLoop; - -typedef struct { - ALMicroTime attackTime; - ALMicroTime decayTime; - ALMicroTime releaseTime; - u8 attackVolume; - u8 decayVolume; -} ALEnvelope; - -typedef struct { - u8 velocityMin; - u8 velocityMax; - u8 keyMin; - u8 keyMax; - u8 keyBase; - s8 detune; -} ALKeyMap; - -typedef struct { - ALADPCMloop *loop; - ALADPCMBook *book; -} ALADPCMWaveInfo; - -typedef struct { - ALRawLoop *loop; -} ALRAWWaveInfo; - -typedef struct ALWaveTable_s { - u8 *base; /* ptr to start of wave data */ - s32 len; /* length of data in bytes */ - u8 type; /* compression type */ - u8 flags; /* offset/address flags */ - union { - ALADPCMWaveInfo adpcmWave; - ALRAWWaveInfo rawWave; - } waveInfo; -} ALWaveTable; - -typedef struct ALSound_s { - ALEnvelope *envelope; - ALKeyMap *keyMap; - ALWaveTable *wavetable; /* offset to wavetable struct */ - ALPan samplePan; - u8 sampleVolume; - u8 flags; -} ALSound; - -typedef struct { - u8 volume; /* overall volume for this instrument */ - ALPan pan; /* 0 = hard left, 127 = hard right */ - u8 priority; /* voice priority for this instrument */ - u8 flags; - u8 tremType; /* the type of tremelo osc. to use */ - u8 tremRate; /* the rate of the tremelo osc. */ - u8 tremDepth; /* the depth of the tremelo osc */ - u8 tremDelay; /* the delay for the tremelo osc */ - u8 vibType; /* the type of tremelo osc. to use */ - u8 vibRate; /* the rate of the tremelo osc. */ - u8 vibDepth; /* the depth of the tremelo osc */ - u8 vibDelay; /* the delay for the tremelo osc */ - s16 bendRange; /* pitch bend range in cents */ - s16 soundCount; /* number of sounds in this array */ - ALSound *soundArray[1]; -} ALInstrument; - -typedef struct ALBank_s { - s16 instCount; /* number of programs in this bank */ - u8 flags; - u8 pad; - s32 sampleRate; /* e.g. 44100, 22050, etc... */ - ALInstrument *percussion; /* default percussion for GM */ - ALInstrument *instArray[1]; /* ARRAY of instruments */ -} ALBank; - -typedef struct { /* Note: sizeof won't be correct */ - s16 revision; /* format revision of this file */ - s16 bankCount; /* number of banks */ - ALBank *bankArray[1]; /* ARRAY of bank offsets */ -} ALBankFile; - -void alBnkfNew(ALBankFile *f, u8 *table); - -/*********************************************************************** - * Sequence Files - ***********************************************************************/ -#define AL_SEQBANK_VERSION 'S1' - -typedef struct { - u8 *offset; - s32 len; -} ALSeqData; - -typedef struct { /* Note: sizeof won't be correct */ - s16 revision; /* format revision of this file */ - s16 seqCount; /* number of sequences */ - ALSeqData seqArray[1]; /* ARRAY of sequence info */ -} ALSeqFile; - -void alSeqFileNew(ALSeqFile *f, u8 *base); - -/*********************************************************************** - * Synthesis driver stuff - ***********************************************************************/ -typedef ALMicroTime (*ALVoiceHandler)(void *); - -typedef struct { - s32 maxVVoices; /* obsolete */ - s32 maxPVoices; - s32 maxUpdates; - s32 maxFXbusses; - void *dmaproc; - ALHeap *heap; - s32 outputRate; /* output sample rate */ - ALFxId fxType; - s32 *params; -} ALSynConfig; - -typedef struct ALPlayer_s { - struct ALPlayer_s *next; - void *clientData; /* storage for client callback */ - ALVoiceHandler handler; /* voice handler for player */ - ALMicroTime callTime; /* usec requested callback */ - s32 samplesLeft; /* usec remaining to callback */ -} ALPlayer; - -typedef struct ALVoice_s { - ALLink node; - struct PVoice_s *pvoice; - ALWaveTable *table; - void *clientPrivate; - s16 state; - s16 priority; - s16 fxBus; - s16 unityPitch; -} ALVoice; - -typedef struct ALVoiceConfig_s { - s16 priority; /* voice priority */ - s16 fxBus; /* bus assignment */ - u8 unityPitch; /* unity pitch flag */ -} ALVoiceConfig; - -typedef struct { - ALPlayer *head; /* client list head */ - ALLink pFreeList; /* list of free physical voices */ - ALLink pAllocList; /* list of allocated physical voices */ - ALLink pLameList; /* list of voices ready to be freed */ - s32 paramSamples; - s32 curSamples; /* samples from start of game */ - ALDMANew dma; - ALHeap *heap; - - struct ALParam_s *paramList; - - struct ALMainBus_s *mainBus; - struct ALAuxBus_s *auxBus; /* ptr to array of aux bus structs */ - struct ALFilter_s *outputFilter; /* last filter in the filter chain */ - - s32 numPVoices; - s32 maxAuxBusses; - s32 outputRate; /* output sample rate */ - s32 maxOutSamples; /* Maximum samples rsp can generate - at one time at output rate */ -} ALSynth; - -void alSynNew(ALSynth *s, ALSynConfig *config); -void alSynDelete(ALSynth *s); - -void alSynAddPlayer(ALSynth *s, ALPlayer *client); -void alSynRemovePlayer(ALSynth *s, ALPlayer *client); - -s32 alSynAllocVoice(ALSynth *s, ALVoice *v, ALVoiceConfig *vc); -void alSynFreeVoice(ALSynth *s, ALVoice *voice); - -void alSynStartVoice(ALSynth *s, ALVoice *voice, ALWaveTable *w); -void alSynStartVoiceParams(ALSynth *s, ALVoice *voice, ALWaveTable *w, - f32 pitch, s16 vol, ALPan pan, u8 fxmix, - ALMicroTime t); -void alSynStopVoice(ALSynth *s, ALVoice *voice); - -void alSynSetVol(ALSynth *s, ALVoice *v, s16 vol, ALMicroTime delta); -void alSynSetPitch(ALSynth *s, ALVoice *voice, f32 ratio); -void alSynSetPan(ALSynth *s, ALVoice *voice, ALPan pan); -void alSynSetFXMix(ALSynth *s, ALVoice *voice, u8 fxmix); -void alSynSetPriority(ALSynth *s, ALVoice *voice, s16 priority); -s16 alSynGetPriority(ALSynth *s, ALVoice *voice); - -ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp); -ALFxRef alSynGetFXRef(ALSynth *s, s16 bus, s16 index); -void alSynFreeFX(ALSynth *s, ALFxRef *fx); -void alSynSetFXParam(ALSynth *s, ALFxRef fx, s16 paramID, void *param); - -/*********************************************************************** - * Audio Library (AL) stuff - ***********************************************************************/ -typedef struct { - ALSynth drvr; -} ALGlobals; - -extern ALGlobals *alGlobals; - -void alInit(ALGlobals *glob, ALSynConfig *c); -void alClose(ALGlobals *glob); - -Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen); - -/*********************************************************************** - * Sequence Player stuff - ***********************************************************************/ - -/* - * Play states - */ -#define AL_STOPPED 0 -#define AL_PLAYING 1 -#define AL_STOPPING 2 - -#define AL_DEFAULT_PRIORITY 5 -#define AL_DEFAULT_VOICE 0 -#define AL_MAX_CHANNELS 16 - -/* - * Audio Library event type definitions - */ -enum ALMsg { - AL_SEQ_REF_EVT, /* Reference to a pending event in the sequence. */ - AL_SEQ_MIDI_EVT, - AL_SEQP_MIDI_EVT, - AL_TEMPO_EVT, - AL_SEQ_END_EVT, - AL_NOTE_END_EVT, - AL_SEQP_ENV_EVT, - AL_SEQP_META_EVT, - AL_SEQP_PROG_EVT, - AL_SEQP_API_EVT, - AL_SEQP_VOL_EVT, - AL_SEQP_LOOP_EVT, - AL_SEQP_PRIORITY_EVT, - AL_SEQP_SEQ_EVT, - AL_SEQP_BANK_EVT, - AL_SEQP_PLAY_EVT, - AL_SEQP_STOP_EVT, - AL_SEQP_STOPPING_EVT, - AL_TRACK_END, - AL_CSP_LOOPSTART, - AL_CSP_LOOPEND, - AL_CSP_NOTEOFF_EVT, - AL_TREM_OSC_EVT, - AL_VIB_OSC_EVT -}; - -/* - * Midi event definitions - */ -#define AL_EVTQ_END 0x7fffffff - -enum AL_MIDIstatus { - /* For distinguishing channel number from status */ - AL_MIDI_ChannelMask = 0x0F, - AL_MIDI_StatusMask = 0xF0, - - /* Channel voice messages */ - AL_MIDI_ChannelVoice = 0x80, - AL_MIDI_NoteOff = 0x80, - AL_MIDI_NoteOn = 0x90, - AL_MIDI_PolyKeyPressure = 0xA0, - AL_MIDI_ControlChange = 0xB0, - AL_MIDI_ChannelModeSelect = 0xB0, - AL_MIDI_ProgramChange = 0xC0, - AL_MIDI_ChannelPressure = 0xD0, - AL_MIDI_PitchBendChange = 0xE0, - - /* System messages */ - AL_MIDI_SysEx = 0xF0, /* System Exclusive */ - - /* System common */ - AL_MIDI_SystemCommon = 0xF1, - AL_MIDI_TimeCodeQuarterFrame = 0xF1, - AL_MIDI_SongPositionPointer = 0xF2, - AL_MIDI_SongSelect = 0xF3, - AL_MIDI_Undefined1 = 0xF4, - AL_MIDI_Undefined2 = 0xF5, - AL_MIDI_TuneRequest = 0xF6, - AL_MIDI_EOX = 0xF7, /* End of System Exclusive */ - - /* System real time */ - AL_MIDI_SystemRealTime = 0xF8, - AL_MIDI_TimingClock = 0xF8, - AL_MIDI_Undefined3 = 0xF9, - AL_MIDI_Start = 0xFA, - AL_MIDI_Continue = 0xFB, - AL_MIDI_Stop = 0xFC, - AL_MIDI_Undefined4 = 0xFD, - AL_MIDI_ActiveSensing = 0xFE, - AL_MIDI_SystemReset = 0xFF, - AL_MIDI_Meta = 0xFF /* MIDI Files only */ -}; - -enum AL_MIDIctrl { - AL_MIDI_VOLUME_CTRL = 0x07, - AL_MIDI_PAN_CTRL = 0x0A, - AL_MIDI_PRIORITY_CTRL = 0x10, /* use general purpose controller for priority */ - AL_MIDI_FX_CTRL_0 = 0x14, - AL_MIDI_FX_CTRL_1 = 0x15, - AL_MIDI_FX_CTRL_2 = 0x16, - AL_MIDI_FX_CTRL_3 = 0x17, - AL_MIDI_FX_CTRL_4 = 0x18, - AL_MIDI_FX_CTRL_5 = 0x19, - AL_MIDI_FX_CTRL_6 = 0x1A, - AL_MIDI_FX_CTRL_7 = 0x1B, - AL_MIDI_FX_CTRL_8 = 0x1C, - AL_MIDI_FX_CTRL_9 = 0x1D, - AL_MIDI_SUSTAIN_CTRL = 0x40, - AL_MIDI_FX1_CTRL = 0x5B, - AL_MIDI_FX3_CTRL = 0x5D -}; - -enum AL_MIDImeta { - AL_MIDI_META_TEMPO = 0x51, - AL_MIDI_META_EOT = 0x2f -}; - - -#define AL_CMIDI_BLOCK_CODE 0xFE -#define AL_CMIDI_LOOPSTART_CODE 0x2E -#define AL_CMIDI_LOOPEND_CODE 0x2D -#define AL_CMIDI_CNTRL_LOOPSTART 102 -#define AL_CMIDI_CNTRL_LOOPEND 103 -#define AL_CMIDI_CNTRL_LOOPCOUNT_SM 104 -#define AL_CMIDI_CNTRL_LOOPCOUNT_BIG 105 - -typedef struct { - u8 *curPtr; /* ptr to the next event */ - s32 lastTicks; /* sequence clock ticks (used by alSeqSetLoc) */ - s32 curTicks; /* sequence clock ticks of next event (used by loop end test) */ - s16 lastStatus; /* the last status msg */ -} ALSeqMarker; - -typedef struct { - s32 ticks; /* MIDI, Tempo and End events must start with ticks */ - u8 status; - u8 byte1; - u8 byte2; - u32 duration; -} ALMIDIEvent; - -typedef struct { - s32 ticks; - u8 status; - u8 type; - u8 len; - u8 byte1; - u8 byte2; - u8 byte3; -} ALTempoEvent; - -typedef struct { - s32 ticks; - u8 status; - u8 type; - u8 len; -} ALEndEvent; - -typedef struct { - struct ALVoice_s *voice; -} ALNoteEvent; - -typedef struct { - struct ALVoice_s *voice; - ALMicroTime delta; - u8 vol; -} ALVolumeEvent; - -typedef struct { - s16 vol; -} ALSeqpVolEvent; - -typedef struct { - ALSeqMarker *start; - ALSeqMarker *end; - s32 count; -} ALSeqpLoopEvent; - -typedef struct { - u8 chan; - u8 priority; -} ALSeqpPriorityEvent; - -typedef struct { - void *seq; /* pointer to a seq (could be an ALSeq or an ALCSeq). */ -} ALSeqpSeqEvent; - -typedef struct { - ALBank *bank; -} ALSeqpBankEvent; - -typedef struct { - struct ALVoiceState_s *vs; - void *oscState; - u8 chan; -} ALOscEvent; - -typedef struct { - s16 type; - union { - ALMIDIEvent midi; - ALTempoEvent tempo; - ALEndEvent end; - ALNoteEvent note; - ALVolumeEvent vol; - ALSeqpLoopEvent loop; - ALSeqpVolEvent spvol; - ALSeqpPriorityEvent sppriority; - ALSeqpSeqEvent spseq; - ALSeqpBankEvent spbank; - ALOscEvent osc; - } msg; -} ALEvent; - -typedef struct { - ALLink node; - ALMicroTime delta; - ALEvent evt; -} ALEventListItem; - -typedef struct { - ALLink freeList; - ALLink allocList; - s32 eventCount; -} ALEventQueue; - -void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, - s32 itemCount); -ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt); -void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, - ALMicroTime delta); -void alEvtqFlush(ALEventQueue *evtq); -void alEvtqFlushType(ALEventQueue *evtq, s16 type); - - -#define AL_PHASE_ATTACK 0 -#define AL_PHASE_NOTEON 0 -#define AL_PHASE_DECAY 1 -#define AL_PHASE_SUSTAIN 2 -#define AL_PHASE_RELEASE 3 -#define AL_PHASE_SUSTREL 4 - -typedef struct ALVoiceState_s { - struct ALVoiceState_s *next;/* MUST be first */ - ALVoice voice; - ALSound *sound; - ALMicroTime envEndTime; /* time of envelope segment end */ - f32 pitch; /* currect pitch ratio */ - f32 vibrato; /* current value of the vibrato */ - u8 envGain; /* current envelope gain */ - u8 channel; /* channel assignment */ - u8 key; /* note on key number */ - u8 velocity; /* note on velocity */ - u8 envPhase; /* what envelope phase */ - u8 phase; - u8 tremelo; /* current value of the tremelo */ - u8 flags; /* bit 0 tremelo flag - bit 1 vibrato flag */ -} ALVoiceState; - -typedef struct { - ALInstrument *instrument; /* instrument assigned to this chan */ - s16 bendRange; /* pitch bend range in cents */ - ALFxId fxId; /* type of fx assigned to this chan */ - ALPan pan; /* overall pan for this chan */ - u8 priority; /* priority for this chan */ - u8 vol; /* current volume for this chan */ - u8 fxmix; /* current fx mix for this chan */ - u8 sustain; /* current sustain pedal state */ - f32 pitchBend; /* current pitch bend val in cents */ -} ALChanState; - -typedef struct ALSeq_s { - u8 *base; /* ptr to start of sequence file */ - u8 *trackStart; /* ptr to first MIDI event */ - u8 *curPtr; /* ptr to next event to read */ - s32 lastTicks; /* MIDI ticks for last event */ - s32 len; /* length of sequence in bytes */ - f32 qnpt; /* qrter notes / tick (1/division) */ - s16 division; /* ticks per quarter note */ - s16 lastStatus; /* for running status */ -} ALSeq; - -typedef struct { - u32 trackOffset[16]; - u32 division; -} ALCMidiHdr; - -typedef struct ALCSeq_s { - ALCMidiHdr *base; /* ptr to start of sequence file */ - u32 validTracks; /* set of flags, showing valid tracks */ - f32 qnpt; /* qrter notes / tick (1/division) */ - u32 lastTicks; /* keep track of ticks incase app wants */ - u32 lastDeltaTicks; /* number of delta ticks of last event */ - u32 deltaFlag; /* flag: set if delta's not subtracted */ - u8 *curLoc[16]; /* ptr to current track location, */ - /* may point to next event, or may point */ - /* to a backup code */ - u8 *curBUPtr[16]; /* ptr to next event if in backup mode */ - u8 curBULen[16]; /* if > 0, then in backup mode */ - u8 lastStatus[16]; /* for running status */ - u32 evtDeltaTicks[16]; /* delta time to next event */ -} ALCSeq; - -typedef struct { - u32 validTracks; - s32 lastTicks; - u32 lastDeltaTicks; - u8 *curLoc[16]; - u8 *curBUPtr[16]; - u8 curBULen[16]; - u8 lastStatus[16]; - u32 evtDeltaTicks[16]; -} ALCSeqMarker; - -#define NO_SOUND_ERR_MASK 0x01 -#define NOTE_OFF_ERR_MASK 0x02 -#define NO_VOICE_ERR_MASK 0x04 - -typedef struct { - s32 maxVoices; /* max number of voices to alloc */ - s32 maxEvents; /* max internal events to support */ - u8 maxChannels; /* max MIDI channels to support (16)*/ - u8 debugFlags; /* control which error get reported */ - ALHeap *heap; /* ptr to initialized heap */ - void *initOsc; - void *updateOsc; - void *stopOsc; -} ALSeqpConfig; - -typedef ALMicroTime (*ALOscInit)(void **oscState,f32 *initVal, u8 oscType, - u8 oscRate, u8 oscDepth, u8 oscDelay); -typedef ALMicroTime (*ALOscUpdate)(void *oscState, f32 *updateVal); -typedef void (*ALOscStop)(void *oscState); - -typedef struct { - ALPlayer node; /* note: must be first in structure */ - ALSynth *drvr; /* reference to the client driver */ - ALSeq *target; /* current sequence */ - ALMicroTime curTime; - ALBank *bank; /* current ALBank */ - s32 uspt; /* microseconds per tick */ - s32 nextDelta; /* microseconds to next callback */ - s32 state; - u16 chanMask; /* active channels */ - s16 vol; /* overall sequence volume */ - u8 maxChannels; /* number of MIDI channels */ - u8 debugFlags; /* control which error get reported */ - ALEvent nextEvent; - ALEventQueue evtq; - ALMicroTime frameTime; - ALChanState *chanState; /* 16 channels for MIDI */ - ALVoiceState *vAllocHead; /* list head for allocated voices */ - ALVoiceState *vAllocTail; /* list tail for allocated voices */ - ALVoiceState *vFreeList; /* list of free voice state structs */ - ALOscInit initOsc; - ALOscUpdate updateOsc; - ALOscStop stopOsc; - ALSeqMarker *loopStart; - ALSeqMarker *loopEnd; - s32 loopCount; /* -1 = loop forever, 0 = no loop */ -} ALSeqPlayer; - -typedef struct { - ALPlayer node; /* note: must be first in structure */ - ALSynth *drvr; /* reference to the client driver */ - ALCSeq *target; /* current sequence */ - ALMicroTime curTime; - ALBank *bank; /* current ALBank */ - s32 uspt; /* microseconds per tick */ - s32 nextDelta; /* microseconds to next callback */ - s32 state; - u16 chanMask; /* active channels */ - s16 vol; /* overall sequence volume */ - u8 maxChannels; /* number of MIDI channels */ - u8 debugFlags; /* control which error get reported */ - ALEvent nextEvent; - ALEventQueue evtq; - ALMicroTime frameTime; - ALChanState *chanState; /* 16 channels for MIDI */ - ALVoiceState *vAllocHead; /* list head for allocated voices */ - ALVoiceState *vAllocTail; /* list tail for allocated voices */ - ALVoiceState *vFreeList; /* list of free voice state structs */ - ALOscInit initOsc; - ALOscUpdate updateOsc; - ALOscStop stopOsc; -} ALCSPlayer; - -/* - * Sequence data representation routines - */ -void alSeqNew(ALSeq *seq, u8 *ptr, s32 len); -void alSeqNextEvent(ALSeq *seq, ALEvent *event); -s32 alSeqGetTicks(ALSeq *seq); -f32 alSeqTicksToSec(ALSeq *seq, s32 ticks, u32 tempo); -u32 alSeqSecToTicks(ALSeq *seq, f32 sec, u32 tempo); -void alSeqNewMarker(ALSeq *seq, ALSeqMarker *m, u32 ticks); -void alSeqSetLoc(ALSeq *seq, ALSeqMarker *marker); -void alSeqGetLoc(ALSeq *seq, ALSeqMarker *marker); -/* - * Compact Sequence data representation routines - */ -void alCSeqNew(ALCSeq *seq, u8 *ptr); -void alCSeqNextEvent(ALCSeq *seq,ALEvent *evt); -s32 alCSeqGetTicks(ALCSeq *seq); -f32 alCSeqTicksToSec(ALCSeq *seq, s32 ticks, u32 tempo); -u32 alCSeqSecToTicks(ALCSeq *seq, f32 sec, u32 tempo); -void alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks); -void alCSeqSetLoc(ALCSeq *seq, ALCSeqMarker *marker); -void alCSeqGetLoc(ALCSeq *seq, ALCSeqMarker *marker); - -/* - * Sequence Player routines - */ -f32 alCents2Ratio(s32 cents); - -void alSeqpNew(ALSeqPlayer *seqp, ALSeqpConfig *config); -void alSeqpDelete(ALSeqPlayer *seqp); -void alSeqpSetSeq(ALSeqPlayer *seqp, ALSeq *seq); -ALSeq *alSeqpGetSeq(ALSeqPlayer *seqp); -void alSeqpPlay(ALSeqPlayer *seqp); -void alSeqpStop(ALSeqPlayer *seqp); -s32 alSeqpGetState(ALSeqPlayer *seqp); -void alSeqpSetBank(ALSeqPlayer *seqp, ALBank *b); -void alSeqpSetTempo(ALSeqPlayer *seqp, s32 tempo); -s32 alSeqpGetTempo(ALSeqPlayer *seqp); -s16 alSeqpGetVol(ALSeqPlayer *seqp); /* Master volume control */ -void alSeqpSetVol(ALSeqPlayer *seqp, s16 vol); -void alSeqpLoop(ALSeqPlayer *seqp, ALSeqMarker *start, ALSeqMarker *end, s32 count); - -void alSeqpSetChlProgram(ALSeqPlayer *seqp, u8 chan, u8 prog); -s32 alSeqpGetChlProgram(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlFXMix(ALSeqPlayer *seqp, u8 chan, u8 fxmix); -u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlVol(ALSeqPlayer *seqp, u8 chan, u8 vol); -u8 alSeqpGetChlVol(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlPan(ALSeqPlayer *seqp, u8 chan, ALPan pan); -ALPan alSeqpGetChlPan(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlPriority(ALSeqPlayer *seqp, u8 chan, u8 priority); -u8 alSeqpGetChlPriority(ALSeqPlayer *seqp, u8 chan); -void alSeqpSendMidi(ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, u8 byte2); - - -/* Maintain backwards compatibility with old routine names. */ -#define alSeqpSetProgram alSeqpSetChlProgram -#define alSeqpGetProgram alSeqpGetChlProgram -#define alSeqpSetFXMix alSeqpSetChlFXMix -#define alSeqpGetFXMix alSeqpGetChlFXMix -#define alSeqpSetPan alSeqpSetChlPan -#define alSeqpGetPan alSeqpGetChlPan -#define alSeqpSetChannelPriority alSeqpSetChlPriority -#define alSeqpGetChannelPriority alSeqpGetChlPriority - - - -/* - * Compressed Sequence Player routines - */ -void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *config); -void alCSPDelete(ALCSPlayer *seqp); -void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq); -ALCSeq *alCSPGetSeq(ALCSPlayer *seqp); -void alCSPPlay(ALCSPlayer *seqp); -void alCSPStop(ALCSPlayer *seqp); -s32 alCSPGetState(ALCSPlayer *seqp); -void alCSPSetBank(ALCSPlayer *seqp, ALBank *b); -void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo); -s32 alCSPGetTempo(ALCSPlayer *seqp); -s16 alCSPGetVol(ALCSPlayer *seqp); -void alCSPSetVol(ALCSPlayer *seqp, s16 vol); - -void alCSPSetChlProgram(ALCSPlayer *seqp, u8 chan, u8 prog); -s32 alCSPGetChlProgram(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlFXMix(ALCSPlayer *seqp, u8 chan, u8 fxmix); -u8 alCSPGetChlFXMix(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan); -ALPan alCSPGetChlPan(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol); -u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlPriority(ALCSPlayer *seqp, u8 chan, u8 priority); -u8 alCSPGetChlPriority(ALCSPlayer *seqp, u8 chan); -void alCSPSendMidi(ALCSPlayer *seqp, s32 ticks, u8 status, - u8 byte1, u8 byte2); - - -/* Maintain backwards compatibility with old routine names. */ -#define alCSPSetProgram alCSPSetChlProgram -#define alCSPGetProgram alCSPGetChlProgram -#define alCSPSetFXMix alCSPSetChlFXMix -#define alCSPGetFXMix alCSPGetChlFXMix -#define alCSPSetPan alCSPSetChlPan -#define alCSPGetPan alCSPGetChlPan -#define alCSPSetChannelPriority alCSPSetChlPriority -#define alCSPGetChannelPriority alCSPGetChlPriority - - - -/*********************************************************************** - * Sound Player stuff - ***********************************************************************/ - -typedef struct { - s32 maxSounds; - s32 maxEvents; - ALHeap *heap; -} ALSndpConfig; - -typedef struct { - ALPlayer node; /* note: must be first in structure */ - ALEventQueue evtq; - ALEvent nextEvent; - ALSynth *drvr; /* reference to the client driver */ - s32 target; - void *sndState; - s32 maxSounds; - ALMicroTime frameTime; - ALMicroTime nextDelta; /* microseconds to next callback */ - ALMicroTime curTime; -} ALSndPlayer; - -typedef s16 ALSndId; - -void alSndpNew(ALSndPlayer *sndp, ALSndpConfig *c); -void alSndpDelete(ALSndPlayer *sndp); - -ALSndId alSndpAllocate(ALSndPlayer *sndp, ALSound *sound); -void alSndpDeallocate(ALSndPlayer *sndp, ALSndId id); - -void alSndpSetSound(ALSndPlayer *sndp, ALSndId id); -ALSndId alSndpGetSound(ALSndPlayer *sndp); - -void alSndpPlay(ALSndPlayer *sndp); -void alSndpPlayAt(ALSndPlayer *sndp, ALMicroTime delta); -void alSndpStop(ALSndPlayer *sndp); - -void alSndpSetVol(ALSndPlayer *sndp, s16 vol); -void alSndpSetPitch(ALSndPlayer *sndp, f32 pitch); -void alSndpSetPan(ALSndPlayer *sndp, ALPan pan); -void alSndpSetPriority(ALSndPlayer *sndp, ALSndId id, u8 priority); - -void alSndpSetFXMix(ALSndPlayer *sndp, u8 mix); -s32 alSndpGetState(ALSndPlayer *sndp); - -#ifndef _FINALROM -void alParseAbiCL(Acmd *cmdList, u32 nbytes); -#endif -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !__LIB_AUDIO__ */ - - - diff --git a/lib/ultralib/include/PR/mbi.h b/lib/ultralib/include/PR/mbi.h deleted file mode 100644 index ac900a5..0000000 --- a/lib/ultralib/include/PR/mbi.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef _MBI_H_ -#define _MBI_H_ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.136 $ - * $Date: 1999/01/05 13:04:00 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/mbi.h,v $ - * - **************************************************************************/ - -/* - * Header file for the Media Binary Interface - * - * NOTE: This file is included by the RSP microcode, so any C-specific - * constructs must be bracketed by #ifdef _LANGUAGE_C - * - */ - - -/* - * the SHIFT macros are used to build display list commands, inserting - * bit-fields into a 32-bit word. They take a value, a shift amount, - * and a width. - * - * For the left shift, the lower bits of the value are masked, - * then shifted left. - * - * For the right shift, the value is shifted right, then the lower bits - * are masked. - * - * (NOTE: _SHIFTL(v, 0, 32) won't work, just use an assignment) - * - */ -#define _SHIFTL(v, s, w) \ - ((unsigned int) (((unsigned int)(v) & ((0x01 << (w)) - 1)) << (s))) -#define _SHIFTR(v, s, w) \ - ((unsigned int)(((unsigned int)(v) >> (s)) & ((0x01 << (w)) - 1))) - -#define _SHIFT _SHIFTL /* old, for compatibility only */ - -#define G_ON (1) -#define G_OFF (0) - -/************************************************************************** - * - * Graphics Binary Interface - * - **************************************************************************/ - -#include - -/************************************************************************** - * - * Audio Binary Interface - * - **************************************************************************/ - -#include - -/************************************************************************** - * - * Task list - * - **************************************************************************/ - -#define M_GFXTASK 1 -#define M_AUDTASK 2 -#define M_VIDTASK 3 -#define M_HVQTASK 6 -#define M_HVQMTASK 7 - -/************************************************************************** - * - * Segment macros and definitions - * - **************************************************************************/ - -#define NUM_SEGMENTS (16) -#define SEGMENT_OFFSET(a) ((unsigned int)(a) & 0x00ffffff) -#define SEGMENT_NUMBER(a) (((unsigned int)(a) << 4) >> 28) -#define SEGMENT_ADDR(num, off) (((num) << 24) + (off)) - -#ifndef NULL -#define NULL 0 -#endif - -#endif /* !_MBI_H_ */ diff --git a/lib/ultralib/include/PR/os.h b/lib/ultralib/include/PR/os.h deleted file mode 100644 index 4b52dfb..0000000 --- a/lib/ultralib/include/PR/os.h +++ /dev/null @@ -1,108 +0,0 @@ - -/*==================================================================== - * os.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os.h,v $ - $Revision: 1.168 $ - $Date: 2000/06/15 06:24:52 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_H_ -#define _OS_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -/************************************************************************** - * - * Global definitions - * - */ - -/* - * Stack size for I/O device managers: PIM (PI Manager), VIM (VI Manager), - * SIM (SI Manager) - * - */ -#define OS_PIM_STACKSIZE 4096 -#define OS_VIM_STACKSIZE 4096 -#define OS_SIM_STACKSIZE 4096 - -#define OS_MIN_STACKSIZE 72 - -/* - * Leo Disk - */ - -/* transfer mode */ - -#define LEO_BLOCK_MODE 1 -#define LEO_TRACK_MODE 2 -#define LEO_SECTOR_MODE 3 - -/* - * Boot addresses - */ -#define BOOT_ADDRESS_ULTRA 0x80000400 -#define BOOT_ADDRESS_COSIM 0x80002000 -#define BOOT_ADDRESS_EMU 0x20010000 -#define BOOT_ADDRESS_INDY 0x88100000 - - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_H */ diff --git a/lib/ultralib/include/PR/os_ai.h b/lib/ultralib/include/PR/os_ai.h deleted file mode 100644 index f89d87c..0000000 --- a/lib/ultralib/include/PR/os_ai.h +++ /dev/null @@ -1,92 +0,0 @@ - -/*==================================================================== - * os_ai.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_ai.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:04 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_AI_H_ -#define _OS_AI_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Audio interface (Ai) */ -extern u32 osAiGetStatus(void); -extern u32 osAiGetLength(void); -extern s32 osAiSetFrequency(u32); -extern s32 osAiSetNextBuffer(void *, u32); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_AI_H_ */ diff --git a/lib/ultralib/include/PR/os_cache.h b/lib/ultralib/include/PR/os_cache.h deleted file mode 100644 index 54ed923..0000000 --- a/lib/ultralib/include/PR/os_cache.h +++ /dev/null @@ -1,96 +0,0 @@ - -/*==================================================================== - * os_cache.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_cache.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:04 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_CACHE_H_ -#define _OS_CACHE_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) -#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Cache operations and macros */ - -extern void osInvalDCache(void *, s32); -extern void osInvalICache(void *, s32); -extern void osWritebackDCache(void *, s32); -extern void osWritebackDCacheAll(void); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_CACHE_H_ */ diff --git a/lib/ultralib/include/PR/os_cont.h b/lib/ultralib/include/PR/os_cont.h deleted file mode 100644 index 2b69330..0000000 --- a/lib/ultralib/include/PR/os_cont.h +++ /dev/null @@ -1,208 +0,0 @@ - -/*==================================================================== - * os_cont.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_cont.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:05 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_CONT_H_ -#define _OS_CONT_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_message.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Structure for controllers - */ - -typedef struct { - u16 type; /* Controller Type */ - u8 status; /* Controller status */ - u8 errno; -}OSContStatus; - -typedef struct { - u16 button; - s8 stick_x; /* -80 <= stick_x <= 80 */ - s8 stick_y; /* -80 <= stick_y <= 80 */ - u8 errno; -} OSContPad; - -typedef struct { - void *address; /* Ram pad Address: 11 bits */ - u8 databuffer[32]; /* address of the data buffer */ - u8 addressCrc; /* CRC code for address */ - u8 dataCrc; /* CRC code for data */ - u8 errno; -} OSContRamIo; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* - * Controllers number - */ - -#ifndef _HW_VERSION_1 -#define MAXCONTROLLERS 4 -#else -#define MAXCONTROLLERS 6 -#endif - -/* controller errors */ -#define CONT_NO_RESPONSE_ERROR 0x8 -#define CONT_OVERRUN_ERROR 0x4 -#define CONT_RANGE_ERROR -1 -#ifdef _HW_VERSION_1 -#define CONT_FRAME_ERROR 0x2 -#define CONT_COLLISION_ERROR 0x1 -#endif - -/* Controller type */ - -#define CONT_ABSOLUTE 0x0001 -#define CONT_RELATIVE 0x0002 -#define CONT_JOYPORT 0x0004 -#define CONT_EEPROM 0x8000 -#define CONT_EEP16K 0x4000 -#define CONT_TYPE_MASK 0x1f07 -#define CONT_TYPE_NORMAL 0x0005 -#define CONT_TYPE_MOUSE 0x0002 -#define CONT_TYPE_VOICE 0x0100 - -/* Controller status */ - -#define CONT_CARD_ON 0x01 -#define CONT_CARD_PULL 0x02 -#define CONT_ADDR_CRC_ER 0x04 -#define CONT_EEPROM_BUSY 0x80 - -/* Buttons */ - -#define CONT_A 0x8000 -#define CONT_B 0x4000 -#define CONT_G 0x2000 -#define CONT_START 0x1000 -#define CONT_UP 0x0800 -#define CONT_DOWN 0x0400 -#define CONT_LEFT 0x0200 -#define CONT_RIGHT 0x0100 -#define CONT_L 0x0020 -#define CONT_R 0x0010 -#define CONT_E 0x0008 -#define CONT_D 0x0004 -#define CONT_C 0x0002 -#define CONT_F 0x0001 - -/* Nintendo's official button names */ - -#define A_BUTTON CONT_A -#define B_BUTTON CONT_B -#define L_TRIG CONT_L -#define R_TRIG CONT_R -#define Z_TRIG CONT_G -#define START_BUTTON CONT_START -#define U_JPAD CONT_UP -#define L_JPAD CONT_LEFT -#define R_JPAD CONT_RIGHT -#define D_JPAD CONT_DOWN -#define U_CBUTTONS CONT_E -#define L_CBUTTONS CONT_C -#define R_CBUTTONS CONT_F -#define D_CBUTTONS CONT_D - -/* Controller error number */ - -#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ -#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ -#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ -#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ -#define CONT_ERR_NOT_READY 12 -#define CONT_ERR_VOICE_MEMORY 13 -#define CONT_ERR_VOICE_WORD 14 -#define CONT_ERR_VOICE_NO_RESPONSE 15 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Controller interface */ - -extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); -extern s32 osContReset(OSMesgQueue *, OSContStatus *); -extern s32 osContStartQuery(OSMesgQueue *); -extern s32 osContStartReadData(OSMesgQueue *); -#ifndef _HW_VERSION_1 -extern s32 osContSetCh(u8); -#endif -extern void osContGetQuery(OSContStatus *); -extern void osContGetReadData(OSContPad *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_CONT_H_ */ diff --git a/lib/ultralib/include/PR/os_convert.h b/lib/ultralib/include/PR/os_convert.h deleted file mode 100644 index 0a5da10..0000000 --- a/lib/ultralib/include/PR/os_convert.h +++ /dev/null @@ -1,111 +0,0 @@ - -/*==================================================================== - * os_convert.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_convert.h,v $ - $Revision: 1.2 $ - $Date: 1999/04/21 02:53:11 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_CONVERT_H_ -#define _OS_CONVERT_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -#define OS_CLOCK_RATE 62500000LL -#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -#define OS_NSEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625000LL))/(1000000000LL/15625000LL)) -#define OS_USEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625LL))/(1000000LL/15625LL)) -#define OS_CYCLES_TO_NSEC(c) (((u64)(c)*(1000000000LL/15625000LL))/(OS_CPU_COUNTER/15625000LL)) -#define OS_CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CPU_COUNTER/15625LL)) - -/* OS_K?_TO_PHYSICAL macro bug fix for CodeWarrior */ -#ifndef __MWERKS__ -#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000)) -#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000)) -#else -#define OS_K0_TO_PHYSICAL(x) ((char *)(x)-0x80000000) -#define OS_K1_TO_PHYSICAL(x) ((char *)(x)-0xa0000000) -#endif - -#define OS_PHYSICAL_TO_K0(x) (void *)(((u32)(x)+0x80000000)) -#define OS_PHYSICAL_TO_K1(x) (void *)(((u32)(x)+0xa0000000)) - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Address translation routines and macros */ - -extern u32 osVirtualToPhysical(void *); -extern void * osPhysicalToVirtual(u32); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_CONVERT_H_ */ diff --git a/lib/ultralib/include/PR/os_debug.h b/lib/ultralib/include/PR/os_debug.h deleted file mode 100644 index f8f5a89..0000000 --- a/lib/ultralib/include/PR/os_debug.h +++ /dev/null @@ -1,117 +0,0 @@ - -/*==================================================================== - * os_debug.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_debug.h,v $ - $Revision: 1.4 $ - $Date: 1999/06/30 03:04:08 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_DEBUG_H_ -#define _OS_DEBUG_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Structure for Profiler - */ -typedef struct { - u16 *histo_base; /* histogram base */ - u32 histo_size; /* histogram size */ - u32 *text_start; /* start of text segment */ - u32 *text_end; /* end of text segment */ -} OSProf; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* - * Profiler constants - */ -#define PROF_MIN_INTERVAL 50 /* microseconds */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Profiler Interface */ - -extern void osProfileInit(OSProf *, u32 profcnt); -extern void osProfileStart(u32); -extern void osProfileFlush(void); -extern void osProfileStop(void); - -/* Thread Profiler Interface */ -extern void osThreadProfileClear(OSId); -extern void osThreadProfileInit(void); -extern void osThreadProfileStart(void); -extern void osThreadProfileStop(void); -extern u32 osThreadProfileReadCount(OSId); -extern u32 osThreadProfileReadCountTh(OSThread*); -extern OSTime osThreadProfileReadTime(OSId); -extern OSTime osThreadProfileReadTimeTh(OSThread*); - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_DEBUG_H_ */ diff --git a/lib/ultralib/include/PR/os_eeprom.h b/lib/ultralib/include/PR/os_eeprom.h deleted file mode 100644 index b3bca81..0000000 --- a/lib/ultralib/include/PR/os_eeprom.h +++ /dev/null @@ -1,107 +0,0 @@ - -/*==================================================================== - * os_eeprom.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_eeprom.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:06 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_EEPROM_H_ -#define _OS_EEPROM_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_message.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* EEPROM TYPE */ - -#define EEPROM_TYPE_4K 0x01 -#define EEPROM_TYPE_16K 0x02 - -/* definition for EEPROM */ - -#define EEPROM_MAXBLOCKS 64 -#define EEP16K_MAXBLOCKS 256 -#define EEPROM_BLOCK_SIZE 8 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* EEPROM interface */ - -extern s32 osEepromProbe(OSMesgQueue *); -extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); -extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); -extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); -extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_EEPROM_H_ */ diff --git a/lib/ultralib/include/PR/os_error.h b/lib/ultralib/include/PR/os_error.h deleted file mode 100644 index f4c3b83..0000000 --- a/lib/ultralib/include/PR/os_error.h +++ /dev/null @@ -1,86 +0,0 @@ - -/*==================================================================== - * os_error.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_error.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:06 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_ERROR_H_ -#define _OS_ERROR_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_ERROR_H_ */ diff --git a/lib/ultralib/include/PR/os_exception.h b/lib/ultralib/include/PR/os_exception.h deleted file mode 100644 index 2457bde..0000000 --- a/lib/ultralib/include/PR/os_exception.h +++ /dev/null @@ -1,86 +0,0 @@ - -/*==================================================================== - * os_exception.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_exception.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:07 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_EXCEPTION_H_ -#define _OS_EXCEPTION_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include "ultratypes.h" - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -typedef u32 OSIntMask; -typedef u32 OSHWIntr; - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/* Flags for debugging purpose */ - -#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ -#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ - -/* Interrupt masks */ - -#define OS_IM_NONE 0x00000001 -#define OS_IM_RCP 0x00000401 -#define OS_IM_SW1 0x00000501 -#define OS_IM_SW2 0x00000601 -#define OS_IM_CART 0x00000c01 -#define OS_IM_PRENMI 0x00001401 -#define OS_IM_RDBWRITE 0x00002401 -#define OS_IM_RDBREAD 0x00004401 -#define OS_IM_COUNTER 0x00008401 -#define OS_IM_CPU 0x0000ff01 -#define OS_IM_SP 0x00010401 -#define OS_IM_SI 0x00020401 -#define OS_IM_AI 0x00040401 -#define OS_IM_VI 0x00080401 -#define OS_IM_PI 0x00100401 -#define OS_IM_DP 0x00200401 -#define OS_IM_ALL 0x003fff01 -#define RCP_IMASK 0x003f0000 -#define RCP_IMASKSHIFT 16 - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Interrupt operations */ - -extern OSIntMask osGetIntMask(void); -extern OSIntMask osSetIntMask(OSIntMask); - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_EXCEPTION_H_ */ diff --git a/lib/ultralib/include/PR/os_flash.h b/lib/ultralib/include/PR/os_flash.h deleted file mode 100644 index 9eb0bf7..0000000 --- a/lib/ultralib/include/PR/os_flash.h +++ /dev/null @@ -1,77 +0,0 @@ -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. - - $RCSfile: os_flash.h,v $ - $Revision: 1.1 $ - $Date: 2000/06/15 06:24:55 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_FLASH_H_ -#define _OS_FLASH_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include "ultratypes.h" -#include "os_pi.h" - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* - * defines for FLASH - */ -#define FLASH_START_ADDR 0x08000000 - -#define FLASH_SIZE 0x20000 - -#define FLASH_LATENCY 0x5 -#define FLASH_PULSE 0x0c -#define FLASH_PAGE_SIZE 0xf -#define FLASH_REL_DURATION 0x2 -#define DEVICE_TYPE_FLASH 8 - -#define FLASH_VERSION_MX_PROTO_A 0x00c20000 -#define FLASH_VERSION_MX_A 0x00c20001 -#define FLASH_VERSION_MX_C 0x00c2001e -#define FLASH_VERSION_MX_B_AND_D 0x00c2001d -#define FLASH_VERSION_MEI 0x003200f1 - -/* OLD_FLASH is MX_PROTO_A, MX_A and MX_C */ -#define OLD_FLASH 0 -/* NEW_FLASH is MX_B_AND_D and MATSUSHITA flash */ -#define NEW_FLASH 1 - -#define FLASH_STATUS_ERASE_BUSY 2 -#define FLASH_STATUS_ERASE_OK 0 -#define FLASH_STATUS_ERASE_ERROR -1 - -#define FLASH_STATUS_WRITE_BUSY 1 -#define FLASH_STATUS_WRITE_OK 0 -#define FLASH_STATUS_WRITE_ERROR -1 - -extern OSPiHandle *osFlashReInit(u8 latency, u8 pulse, - u8 page_size, u8 rel_duration, u32 start); -extern OSPiHandle *osFlashInit(void); -extern void osFlashReadStatus(u8 *flash_status); -extern void osFlashReadId(u32 *flash_type, u32 *flash_maker); -extern void osFlashClearStatus(void); -extern s32 osFlashAllErase(void); -extern s32 osFlashSectorErase(u32 page_num); -extern s32 osFlashWriteBuffer(OSIoMesg *mb, s32 priority, - void *dramAddr, OSMesgQueue *mq); -extern s32 osFlashWriteArray(u32 page_num); -extern s32 osFlashReadArray(OSIoMesg *mb, s32 priority, u32 page_num, - void *dramAddr, u32 n_pages, OSMesgQueue *mq); -extern void osFlashChange(u32 flash_num); -extern void osFlashAllEraseThrough(void); -extern void osFlashSectorEraseThrough(u32 page_num); -extern s32 osFlashCheckEraseEnd(void); - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_FLASH_H_ */ diff --git a/lib/ultralib/include/PR/os_gbpak.h b/lib/ultralib/include/PR/os_gbpak.h deleted file mode 100644 index 0a99994..0000000 --- a/lib/ultralib/include/PR/os_gbpak.h +++ /dev/null @@ -1,107 +0,0 @@ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. - - $RCSfile: os_gbpak.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:07 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_GBPAK_H_ -#define _OS_GBPAK_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_message.h" -#include "os_pfs.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -typedef struct { - u16 fixed1; - u16 start_address; - u8 nintendo_chr[0x30]; - u8 game_title[16]; - u16 company_code; - u8 body_code; - u8 cart_type; - u8 rom_size; - u8 ram_size; - u8 country_code; - u8 fixed2; - u8 version; - u8 isum; - u16 sum; -} OSGbpakId; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* definition for 64GB-PAK */ - -#define OS_GBPAK_POWER 0x01 -#define OS_GBPAK_RSTB_DETECTION 0x04 -#define OS_GBPAK_RSTB_STATUS 0x08 -#define OS_GBPAK_GBCART_PULL 0x40 -#define OS_GBPAK_GBCART_ON 0x80 - -#define OS_GBPAK_POWER_OFF 0x00 /* power of 64GB-PAK */ -#define OS_GBPAK_POWER_ON 0x01 - -#define OS_GBPAK_ROM_ID_SIZE 0x50 /* ID size of GB cartridge */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* 64GB-PAK */ -extern s32 osGbpakInit(OSMesgQueue *, OSPfs *, int); -extern s32 osGbpakPower(OSPfs *, s32); -extern s32 osGbpakGetStatus(OSPfs *, u8 *); -extern s32 osGbpakReadWrite(OSPfs *, u16, u16, u8 *, u16); -extern s32 osGbpakReadId(OSPfs *, OSGbpakId *, u8 *); -extern s32 osGbpakCheckConnector(OSPfs *, u8 *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_GBPAK_H_ */ diff --git a/lib/ultralib/include/PR/os_gio.h b/lib/ultralib/include/PR/os_gio.h deleted file mode 100644 index ad3c020..0000000 --- a/lib/ultralib/include/PR/os_gio.h +++ /dev/null @@ -1,86 +0,0 @@ - -/*==================================================================== - * os_gio.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_gio.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:08 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_GIO_H_ -#define _OS_GIO_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_GIO_H_ */ diff --git a/lib/ultralib/include/PR/os_host.h b/lib/ultralib/include/PR/os_host.h deleted file mode 100644 index 3192f6a..0000000 --- a/lib/ultralib/include/PR/os_host.h +++ /dev/null @@ -1,166 +0,0 @@ - -/*==================================================================== - * os_host.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_host.h,v $ - $Revision: 1.3 $ - $Date: 1999/06/24 09:23:06 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_HOST_H_ -#define _OS_HOST_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -extern void __osInitialize_common(void); - -#if defined(_FINALROM) - -#define osInitialize() __osInitialize_common() - -#else - -/* PARTNER-N64 */ -#if defined(PTN64) -extern void __osInitialize_kmc(void); -#define osReadHost osReadHost_pt -#define osWriteHost osWriteHost_pt -#define osInitialize() \ -{ \ - __osInitialize_common(); \ - __osInitialize_kmc(); \ -} - -/* MONEGI SMART PACK A */ -#elif defined(MWN64) -extern void __osInitialize_msp(void); -#define osReadHost osReadHost_pt -#define osWriteHost osWriteHost_pt -#define osInitialize() \ -{ \ - __osInitialize_common(); \ - __osInitialize_msp(); \ -} - -/* IS-Viewer(for Debugger) */ -#elif defined(ISV64) -extern void __osInitialize_isv(void); -#define osInitialize() \ -{ \ - __osInitialize_common(); \ - __osInitialize_isv(); \ -} - -/* Emulation board for INDY */ -#elif defined(EMU64) -extern void __osInitialize_emu(void); -#define osInitialize() \ -{ \ - __osInitialize_common(); \ - __osInitialize_emu(); \ -} - -#else -/* Default (auto detect) */ -extern void __osInitialize_autodetect(void); -extern void __osInitialize_msp(void); -extern void __osInitialize_kmc(void); -extern void __osInitialize_isv(void); -extern void __osInitialize_emu(void); -#define osInitialize() \ -{ \ - __osInitialize_common(); \ - __osInitialize_autodetect(); \ -} -#endif - -#endif /* _FINAL_ROM */ - -#if BUILD_VERSION < VERSION_K -#undef osInitialize -#endif - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Game <> Host data transfer functions */ - -extern s32 osTestHost(void); -extern void osReadHost(void *, u32); -extern void osWriteHost(void *, u32); -extern void osAckRamromRead(void); -extern void osAckRamromWrite(void); - -/* RDB port operations */ - -extern void osInitRdb(u8 *sendBuf, u32 sendSize); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_HOST_H_ */ diff --git a/lib/ultralib/include/PR/os_internal.h b/lib/ultralib/include/PR/os_internal.h deleted file mode 100644 index 754d1ee..0000000 --- a/lib/ultralib/include/PR/os_internal.h +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal.h,v $ - $Revision: 1.20 $ - $Date: 1998/10/09 08:01:09 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_H_ -#define _OS_INTERNAL_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -#include "os_internal_reg.h" -#include "os_internal_exception.h" -#include "os_internal_tlb.h" -#include "os_internal_si.h" -#include "os_internal_rsp.h" -#include "os_internal_error.h" -#include "os_internal_gio.h" -#include "os_internal_thread.h" -#include "os_internal_debug.h" -#include "os_internal_host.h" - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_H */ diff --git a/lib/ultralib/include/PR/os_internal_debug.h b/lib/ultralib/include/PR/os_internal_debug.h deleted file mode 100644 index 7b307d6..0000000 --- a/lib/ultralib/include/PR/os_internal_debug.h +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_debug.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:09 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_DEBUG_H_ -#define _OS_INTERNAL_DEBUG_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Debug port */ -extern void __osSyncPutChars(int, int, const char *); -extern int __osAtomicDec(unsigned int *p); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_DEBUG_H */ diff --git a/lib/ultralib/include/PR/os_internal_error.h b/lib/ultralib/include/PR/os_internal_error.h deleted file mode 100644 index de188d2..0000000 --- a/lib/ultralib/include/PR/os_internal_error.h +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_error.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:10 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_ERROR_H_ -#define _OS_INTERNAL_ERROR_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Error handling */ - -extern void __osError(s16, s16, ...); -extern OSThread * __osGetCurrFaultedThread(void); -extern OSThread * __osGetNextFaultedThread(OSThread *); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_ERROR_H */ diff --git a/lib/ultralib/include/PR/os_internal_exception.h b/lib/ultralib/include/PR/os_internal_exception.h deleted file mode 100644 index dae8a9f..0000000 --- a/lib/ultralib/include/PR/os_internal_exception.h +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_exception.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:10 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_EXCEPTION_H_ -#define _OS_INTERNAL_EXCEPTION_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include "os.h" -#include "os_version.h" - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Routine for HW interrupt "handler" */ -#if BUILD_VERSION >= VERSION_J -extern void __osSetHWIntrRoutine(OSHWIntr interrupt, - s32 (*handler)(void), void *stackEnd); -extern void __osGetHWIntrRoutine(OSHWIntr interrupt, - s32 (**handler)(void), void **stackEnd); -#else -extern void __osSetHWIntrRoutine(OSHWIntr interrupt, - s32 (*handler)(void)); -extern void __osGetHWIntrRoutine(OSHWIntr interrupt, - s32 (**handler)(void)); -#endif - -/* Routine for global interrupt mask */ -extern void __osSetGlobalIntMask(OSHWIntr); -extern void __osResetGlobalIntMask(OSHWIntr); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_EXCEPTION_H */ diff --git a/lib/ultralib/include/PR/os_internal_flash.h b/lib/ultralib/include/PR/os_internal_flash.h deleted file mode 100644 index 1c6f780..0000000 --- a/lib/ultralib/include/PR/os_internal_flash.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _OS_INTERNAL_FLASH_H_ -#define _OS_INTERNAL_FLASH_H_ - -#include "os_message.h" -#include "os_flash.h" - -#define FLASH_BLOCK_SIZE 128 - -/** - * Flash commands - */ -#define FLASH_CMD_REG 0x10000 - -/* set whole chip erase mode */ -#define FLASH_CMD_CHIP_ERASE 0x3C000000 -/* set sector erase mode */ -#define FLASH_CMD_SECTOR_ERASE 0x4B000000 -/* do erasure */ -#define FLASH_CMD_EXECUTE_ERASE 0x78000000 -/* program selected page */ -#define FLASH_CMD_PROGRAM_PAGE 0xA5000000 -/* set page program mode */ -#define FLASH_CMD_PAGE_PROGRAM 0xB4000000 -/* set status mode */ -#define FLASH_CMD_STATUS 0xD2000000 -/* set silicon id mode */ -#define FLASH_CMD_ID 0xE1000000 -/* set read mode */ -#define FLASH_CMD_READ_ARRAY 0xF0000000 - -extern OSIoMesg __osFlashMsg; -extern OSMesgQueue __osFlashMessageQ; -extern OSPiHandle __osFlashHandler; -extern OSMesg __osFlashMsgBuf[1]; -extern s32 __osFlashVersion; -extern u32 __osFlashID[4]; - -u32 __osFlashGetAddr(u32 page_num); - -#endif diff --git a/lib/ultralib/include/PR/os_internal_gio.h b/lib/ultralib/include/PR/os_internal_gio.h deleted file mode 100644 index ff13385..0000000 --- a/lib/ultralib/include/PR/os_internal_gio.h +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_gio.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:11 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_GIO_H_ -#define _OS_INTERNAL_GIO_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Development board functions */ - -extern void __osGIOInit(s32); -extern void __osGIOInterrupt(s32); -extern void __osGIORawInterrupt(s32); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_GIO_H */ diff --git a/lib/ultralib/include/PR/os_internal_host.h b/lib/ultralib/include/PR/os_internal_host.h deleted file mode 100644 index b6d1951..0000000 --- a/lib/ultralib/include/PR/os_internal_host.h +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_host.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:11 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_HOST_H_ -#define _OS_INTERNAL_HOST_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* routine for rdb port */ -extern u32 __osRdbSend(u8 *buf, u32 size, u32 type); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_HOST_H */ diff --git a/lib/ultralib/include/PR/os_internal_reg.h b/lib/ultralib/include/PR/os_internal_reg.h deleted file mode 100644 index 206b721..0000000 --- a/lib/ultralib/include/PR/os_internal_reg.h +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_reg.h,v $ - $Revision: 1.2 $ - $Date: 1999/03/10 12:19:14 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_REG_H_ -#define _OS_INTERNAL_REG_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include "os.h" - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Routines to get/fetch coprocessor 0 registers */ -extern u32 __osGetCause(void); -extern void __osSetCause(u32); -extern u32 __osGetCompare(void); -extern void __osSetCompare(u32); -extern u32 __osGetConfig(void); -extern void __osSetConfig(u32); -extern void __osSetCount(u32); -extern u32 __osGetSR(void); -extern void __osSetSR(u32); -extern u32 __osDisableInt(void); -extern void __osRestoreInt(u32); -extern u32 __osGetWatchLo(void); -extern void __osSetWatchLo(u32); - -/* Routines to get/set floating-point control and status register */ -extern u32 __osSetFpcCsr(u32); -extern u32 __osGetFpcCsr(void); - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_REG_H */ diff --git a/lib/ultralib/include/PR/os_internal_rsp.h b/lib/ultralib/include/PR/os_internal_rsp.h deleted file mode 100644 index 646e667..0000000 --- a/lib/ultralib/include/PR/os_internal_rsp.h +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_rsp.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:12 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_RSP_H_ -#define _OS_INTERNAL_RSP_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Signal processor interface (Sp) */ - -extern u32 __osSpGetStatus(void); -extern void __osSpSetStatus(u32); -extern s32 __osSpSetPc(u32); -extern s32 __osSpRawWriteIo(u32, u32); -extern s32 __osSpRawReadIo(u32, u32 *); -extern s32 __osSpRawStartDma(s32, u32, void *, u32); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_RSP_H */ diff --git a/lib/ultralib/include/PR/os_internal_si.h b/lib/ultralib/include/PR/os_internal_si.h deleted file mode 100644 index d0eeedc..0000000 --- a/lib/ultralib/include/PR/os_internal_si.h +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_si.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:13 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_SI_H_ -#define _OS_INTERNAL_SI_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Serial interface (Si) */ - -extern u32 __osSiGetStatus(void); -extern s32 __osSiRawWriteIo(u32, u32); -extern s32 __osSiRawReadIo(u32, u32 *); -extern s32 __osSiRawStartDma(s32, void *); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_SI_H */ diff --git a/lib/ultralib/include/PR/os_internal_thread.h b/lib/ultralib/include/PR/os_internal_thread.h deleted file mode 100644 index 1305eb5..0000000 --- a/lib/ultralib/include/PR/os_internal_thread.h +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_thread.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:13 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_THREAD_H_ -#define _OS_INTERNAL_THREAD_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* For debugger use */ - -extern OSThread * __osGetActiveQueue(void); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_THREAD_H */ diff --git a/lib/ultralib/include/PR/os_internal_tlb.h b/lib/ultralib/include/PR/os_internal_tlb.h deleted file mode 100644 index b92918f..0000000 --- a/lib/ultralib/include/PR/os_internal_tlb.h +++ /dev/null @@ -1,47 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_tlb.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:14 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_TLB_H_ -#define _OS_INTERNAL_TLB_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Routines for fetch TLB info */ - -extern u32 __osGetTLBASID(void); -extern u32 __osGetTLBPageMask(s32); -extern u32 __osGetTLBHi(s32); -extern u32 __osGetTLBLo0(s32); -extern u32 __osGetTLBLo1(s32); - - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_TLB_H */ diff --git a/lib/ultralib/include/PR/os_libc.h b/lib/ultralib/include/PR/os_libc.h deleted file mode 100644 index 35d0e8e..0000000 --- a/lib/ultralib/include/PR/os_libc.h +++ /dev/null @@ -1,100 +0,0 @@ - -/*==================================================================== - * os_libc.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_libc.h,v $ - $Revision: 1.3 $ - $Date: 1999/07/13 01:43:47 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_LIBC_H_ -#define _OS_LIBC_H_ - -#include "os_pfs.h" - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* byte string operations */ - - -extern void bcopy(const void *, void *, int); -extern int bcmp(const void *, const void *, int); -extern void bzero(void *, int); - -/* Printf */ - -extern int sprintf(char *s, const char *fmt, ...); -extern void osSyncPrintf(const char *fmt, ...); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_LIBC_H_ */ diff --git a/lib/ultralib/include/PR/os_message.h b/lib/ultralib/include/PR/os_message.h deleted file mode 100644 index 606c5cb..0000000 --- a/lib/ultralib/include/PR/os_message.h +++ /dev/null @@ -1,162 +0,0 @@ - -/*==================================================================== - * os_message.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_message.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:15 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_MESSAGE_H_ -#define _OS_MESSAGE_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include "ultratypes.h" -#include "os_thread.h" - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -typedef u32 OSEvent; - -/* - * Structure for message - */ -typedef void *OSMesg; - -/* - * Structure for message queue - */ -typedef struct OSMesgQueue_s { - OSThread *mtqueue; /* Queue to store threads blocked on empty mailboxes (receive) */ - OSThread *fullqueue; /* Queue to store threads blocked on full mailboxes (send) */ - s32 validCount; /* Contains number of valid message */ - s32 first; /* Points to first valid message */ - s32 msgCount; /* Contains total # of messages */ - OSMesg *msg; /* Points to message buffer array */ -} OSMesgQueue; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* Events */ -#ifdef _FINALROM -#define OS_NUM_EVENTS 15 -#else -#define OS_NUM_EVENTS 23 -#endif - -#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ -#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ -#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ -#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ -#define OS_EVENT_SP 4 /* SP task done interrupt */ -#define OS_EVENT_SI 5 /* SI (controller) interrupt */ -#define OS_EVENT_AI 6 /* AI interrupt */ -#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ -#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ -#define OS_EVENT_DP 9 /* DP full sync interrupt */ -#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ -#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ -#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ -#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ -#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ -#ifndef _FINALROM -#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ -#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ -#define OS_EVENT_RDB_DATA_DONE 17 /* read of hostio data complete */ -#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ -#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ -#define OS_EVENT_RDB_DBG_DONE 20 -#define OS_EVENT_RDB_FLUSH_PROF 21 -#define OS_EVENT_RDB_ACK_PROF 22 -#endif - -/* Flags to turn blocking on/off when sending/receiving message */ - -#define OS_MESG_NOBLOCK 0 -#define OS_MESG_BLOCK 1 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -/* Get count of valid messages in queue */ -#define MQ_GET_COUNT(mq) ((mq)->validCount) - -/* Figure out if message queue is empty or full */ -#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) -#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Message operations */ - -extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32); -extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); - -/* Event operations */ - -extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_MESSAGE_H_ */ diff --git a/lib/ultralib/include/PR/os_motor.h b/lib/ultralib/include/PR/os_motor.h deleted file mode 100644 index 2edb8e6..0000000 --- a/lib/ultralib/include/PR/os_motor.h +++ /dev/null @@ -1,84 +0,0 @@ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. - - $RCSfile: os_motor.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:15 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_MOTOR_H_ -#define _OS_MOTOR_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_message.h" -#include "os_pfs.h" -#include "os_version.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Rumble PAK interface */ - -extern s32 osMotorInit(OSMesgQueue *, OSPfs *, int); -#if BUILD_VERSION >= VERSION_J -#define MOTOR_START 1 -#define MOTOR_STOP 0 -#define osMotorStart(x) __osMotorAccess((x), MOTOR_START) -#define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP) -extern s32 __osMotorAccess(OSPfs *, s32); -#else -extern s32 osMotorStop(OSPfs *); -extern s32 osMotorStart(OSPfs *); -#endif - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_MOTOR_H_ */ diff --git a/lib/ultralib/include/PR/os_pfs.h b/lib/ultralib/include/PR/os_pfs.h deleted file mode 100644 index 9c86e23..0000000 --- a/lib/ultralib/include/PR/os_pfs.h +++ /dev/null @@ -1,200 +0,0 @@ - -/*==================================================================== - * os_pfs.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_pfs.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:16 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_PFS_H_ -#define _OS_PFS_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_message.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Structure for file system - */ -typedef struct { - int status; - OSMesgQueue *queue; - int channel; - u8 id[32]; - u8 label[32]; - int version; - int dir_size; - int inode_table; /* block location */ - int minode_table; /* mirrioring inode_table */ - int dir_table; /* block location */ - int inode_start_page; /* page # */ - u8 banks; - u8 activebank; -} OSPfs; - -typedef struct { - u32 file_size; /* bytes */ - u32 game_code; - u16 company_code; - char ext_name[4]; - char game_name[16]; -} OSPfsState; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -/* File System size */ -#define OS_PFS_VERSION 0x0200 -#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) -#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) - -#define PFS_INODE_SIZE_PER_PAGE 128 -#define PFS_FILE_NAME_LEN 16 -#define PFS_FILE_EXT_LEN 4 -#define BLOCKSIZE 32 /* bytes */ -#define PFS_ONE_PAGE 8 /* blocks */ -#define PFS_MAX_BANKS 62 - -/* File System flag */ - -#define PFS_READ 0 -#define PFS_WRITE 1 -#define PFS_CREATE 2 - -/* File System status */ -#define PFS_INITIALIZED 0x1 -#define PFS_CORRUPTED 0x2 -#define PFS_ID_BROKEN 0x4 -#define PFS_MOTOR_INITIALIZED 0x8 -#define PFS_GBPAK_INITIALIZED 0x10 - -/* Definition for page usage */ -#define PFS_EOF 1 -#define PFS_PAGE_NOT_EXIST 2 -#define PFS_PAGE_NOT_USED 3 - -/* File System error number */ - -#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ -#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a different one */ -#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker*/ -#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR -#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ -#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ -#define PFS_DATA_FULL 7 /* no free pages on ram pack*/ -#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ -#define PFS_ERR_EXIST 9 /* file exists*/ -#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ -#define PFS_ERR_DEVICE 11 /* wrong device type*/ -#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ -#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ - -/* Definition for bank */ -#define PFS_ID_BANK_256K 0 -#define PFS_ID_BANK_1M 4 -#define PFS_BANKS_256K 1 - -#define PFS_WRITTEN 2 -#define DEF_DIR_PAGES 2 - -#define PFS_ID_0AREA 1 -#define PFS_ID_1AREA 3 -#define PFS_ID_2AREA 4 -#define PFS_ID_3AREA 6 -#define PFS_LABEL_AREA 7 -#define PFS_ID_PAGE PFS_ONE_PAGE * 0 - -#define PFS_BANK_LAPPED_BY 8 /* => u8 */ -#define PFS_SECTOR_PER_BANK 32 -#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK) -#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE/PFS_SECTOR_PER_BANK) - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* file system interface */ - -extern s32 osPfsInitPak(OSMesgQueue *, OSPfs *, int); -extern s32 osPfsRepairId(OSPfs *); -extern s32 osPfsInit(OSMesgQueue *, OSPfs *, int); -extern s32 osPfsReFormat(OSPfs *, OSMesgQueue *, int); -extern s32 osPfsChecker(OSPfs *); -extern s32 osPfsAllocateFile(OSPfs *, u16, u32, u8 *, u8 *, int, s32 *); -extern s32 osPfsFindFile(OSPfs *, u16, u32, u8 *, u8 *, s32 *); -extern s32 osPfsDeleteFile(OSPfs *, u16, u32, u8 *, u8 *); -extern s32 osPfsReadWriteFile(OSPfs *, s32, u8, int, int, u8 *); -extern s32 osPfsFileState(OSPfs *, s32, OSPfsState *); -extern s32 osPfsGetLabel(OSPfs *, u8 *, int *); -extern s32 osPfsSetLabel(OSPfs *, u8 *); -extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); -extern s32 osPfsFreeBlocks(OSPfs *, s32 *); -extern s32 osPfsNumFiles(OSPfs *, s32 *, s32 *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_PFS_H_ */ diff --git a/lib/ultralib/include/PR/os_pi.h b/lib/ultralib/include/PR/os_pi.h deleted file mode 100644 index f408d6c..0000000 --- a/lib/ultralib/include/PR/os_pi.h +++ /dev/null @@ -1,221 +0,0 @@ - -/*==================================================================== - * os_pi.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_pi.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:16 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_PI_H_ -#define _OS_PI_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include "ultratypes.h" -#include "os_thread.h" -#include "os_message.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Structure for Enhanced PI interface - */ - -/* - * OSTranxInfo is set up for Leo Disk DMA. This info will be maintained - * by exception handler. This is how the PIMGR and the ISR communicate. - */ - -typedef struct { - u32 errStatus; /* error status */ - void *dramAddr; /* RDRAM buffer address (DMA) */ - void *C2Addr; /* C2 buffer address */ - u32 sectorSize; /* size of transfering sector */ - u32 C1ErrNum; /* total # of C1 errors */ - u32 C1ErrSector[4]; /* error sectors */ -} __OSBlockInfo; - -typedef struct { - u32 cmdType; /* for disk only */ - u16 transferMode; /* Block, Track, or sector? */ - u16 blockNum; /* which block is transfering */ - s32 sectorNum; /* which sector is transfering */ - u32 devAddr; /* Device buffer address */ - u32 bmCtlShadow; /* asic bm_ctl(510) register shadow ram */ - u32 seqCtlShadow; /* asic seq_ctl(518) register shadow ram */ - __OSBlockInfo block[2]; /* bolck transfer info */ -} __OSTranxInfo; - - -typedef struct OSPiHandle_s { - struct OSPiHandle_s *next; /* point to next handle on the table */ - u8 type; /* DEVICE_TYPE_BULK for disk */ - u8 latency; /* domain latency */ - u8 pageSize; /* domain page size */ - u8 relDuration; /* domain release duration */ - u8 pulse; /* domain pulse width */ - u8 domain; /* which domain */ - u32 baseAddress; /* Domain address */ - u32 speed; /* for roms only */ - /* The following are "private" elements" */ - __OSTranxInfo transferInfo; /* for disk only */ -} OSPiHandle; - -typedef struct { - u8 type; - u32 address; -} OSPiInfo; - -/* - * Structure for I/O message block - */ -typedef struct { - u16 type; /* Message type */ - u8 pri; /* Message priority (High or Normal) */ - u8 status; /* Return status */ - OSMesgQueue *retQueue; /* Return message queue to notify I/O completion */ -} OSIoMesgHdr; - -typedef struct { - OSIoMesgHdr hdr; /* Message header */ - void *dramAddr; /* RDRAM buffer address (DMA) */ - u32 devAddr; /* Device buffer address (DMA) */ - u32 size; /* DMA transfer size in bytes */ - OSPiHandle *piHandle; /* PI device handle */ -} OSIoMesg; - -/* - * Structure for device manager block - */ -typedef struct { - s32 active; /* Status flag */ - OSThread *thread; /* Calling thread */ - OSMesgQueue *cmdQueue; /* Command queue */ - OSMesgQueue *evtQueue; /* Event queue */ - OSMesgQueue *acsQueue; /* Access queue */ - /* Raw DMA routine */ - s32 (*dma)(s32, u32, void *, u32); - s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); -} OSDevMgr; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* Flags to indicate direction of data transfer */ - -#define OS_READ 0 /* device -> RDRAM */ -#define OS_WRITE 1 /* device <- RDRAM */ -#define OS_OTHERS 2 /* for Leo disk only */ - -/* - * I/O message types - */ -#define OS_MESG_TYPE_BASE (10) -#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE + 0) -#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE + 1) -#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE + 2) -#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE + 3) -#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE + 4) -#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE + 5) -#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE + 6) - -/* - * I/O message priority - */ -#define OS_MESG_PRI_NORMAL 0 -#define OS_MESG_PRI_HIGH 1 - -/* - * PI/EPI - */ -#define PI_DOMAIN1 0 -#define PI_DOMAIN2 1 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - -extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -extern u32 osPiGetStatus(void); -extern s32 osPiGetDeviceType(void); -extern s32 osPiWriteIo(u32, u32); -extern s32 osPiReadIo(u32, u32 *); -extern s32 osPiStartDma(OSIoMesg *, s32, s32, u32, void *, u32, OSMesgQueue *); -extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32); - -/* Enhanced PI interface */ - -extern OSPiHandle *osCartRomInit(void); -extern OSPiHandle *osLeoDiskInit(void); -extern OSPiHandle *osDriveRomInit(void); - -extern s32 osEPiDeviceType(OSPiHandle *, OSPiInfo *); -extern s32 osEPiWriteIo(OSPiHandle *, u32 , u32 ); -extern s32 osEPiReadIo(OSPiHandle *, u32 , u32 *); -extern s32 osEPiStartDma(OSPiHandle *, OSIoMesg *, s32); -extern s32 osEPiLinkHandle(OSPiHandle *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_PI_H_ */ diff --git a/lib/ultralib/include/PR/os_rdp.h b/lib/ultralib/include/PR/os_rdp.h deleted file mode 100644 index 6b3d288..0000000 --- a/lib/ultralib/include/PR/os_rdp.h +++ /dev/null @@ -1,92 +0,0 @@ - -/*==================================================================== - * os_rdp.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_rdp.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:16 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_RDP_H_ -#define _OS_RDP_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Display processor interface (Dp) */ -extern u32 osDpGetStatus(void); -extern void osDpSetStatus(u32); -extern void osDpGetCounters(u32 *); -extern s32 osDpSetNextBuffer(void *, u64); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_RDP_H_ */ diff --git a/lib/ultralib/include/PR/os_reg.h b/lib/ultralib/include/PR/os_reg.h deleted file mode 100644 index 50aa218..0000000 --- a/lib/ultralib/include/PR/os_reg.h +++ /dev/null @@ -1,90 +0,0 @@ - -/*==================================================================== - * os_reg.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_reg.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:17 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_REG_H_ -#define _OS_REG_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Miscellaneous operations */ - -extern u32 osGetCount(void); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_REG_H_ */ diff --git a/lib/ultralib/include/PR/os_rsp.h b/lib/ultralib/include/PR/os_rsp.h deleted file mode 100644 index 1211605..0000000 --- a/lib/ultralib/include/PR/os_rsp.h +++ /dev/null @@ -1,86 +0,0 @@ - -/*==================================================================== - * os_rsp.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_rsp.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:17 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_RSP_H_ -#define _OS_RSP_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_RSP_H_ */ diff --git a/lib/ultralib/include/PR/os_si.h b/lib/ultralib/include/PR/os_si.h deleted file mode 100644 index 23b07c0..0000000 --- a/lib/ultralib/include/PR/os_si.h +++ /dev/null @@ -1,86 +0,0 @@ - -/*==================================================================== - * os_si.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_si.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:18 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_SI_H_ -#define _OS_SI_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_SI_H_ */ diff --git a/lib/ultralib/include/PR/os_system.h b/lib/ultralib/include/PR/os_system.h deleted file mode 100644 index 1179189..0000000 --- a/lib/ultralib/include/PR/os_system.h +++ /dev/null @@ -1,118 +0,0 @@ - -/*==================================================================== - * os_system.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_system.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:18 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_SYSTEM_H_ -#define _OS_SYSTEM_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* - * Values for osTvType - */ -#define OS_TV_PAL 0 -#define OS_TV_NTSC 1 -#define OS_TV_MPAL 2 - -/* - * Size of buffer the retains contents after NMI - */ -#define OS_APP_NMI_BUFSIZE 64 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - -extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */ -extern void *osRomBase; /* Rom base address of the game image */ -extern s32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */ -extern s32 osResetType; /* 0 = cold reset, 1 = NMI */ -extern s32 osCicId; -extern s32 osVersion; -extern u32 osMemSize; /* Memory Size */ -extern s32 osAppNMIBuffer[]; - -extern u64 osClockRate; - -extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -extern void osInitialize(void); -extern void osExit(void); -extern u32 osGetMemSize(void); - -/* pre-NMI */ -extern s32 osAfterPreNMI(void); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_SYSTEM_H_ */ diff --git a/lib/ultralib/include/PR/os_thread.h b/lib/ultralib/include/PR/os_thread.h deleted file mode 100644 index 68c8e74..0000000 --- a/lib/ultralib/include/PR/os_thread.h +++ /dev/null @@ -1,161 +0,0 @@ - -/*==================================================================== - * os_thread.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_thread.h,v $ - $Revision: 1.3 $ - $Date: 1999/06/15 12:39:40 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_THREAD_H_ -#define _OS_THREAD_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -typedef s32 OSPri; -typedef s32 OSId; - -typedef union { - struct { - f32 f_odd; - f32 f_even; - } f; - f64 d; -} __OSfp; - -typedef struct { - u64 at, v0, v1, a0, a1, a2, a3; - u64 t0, t1, t2, t3, t4, t5, t6, t7; - u64 s0, s1, s2, s3, s4, s5, s6, s7; - u64 t8, t9; - u64 gp, sp, s8, ra; - u64 lo, hi; - u32 sr, pc, cause, badvaddr, rcp; - u32 fpcsr; - __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; - __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; -} __OSThreadContext; - -typedef struct { - u32 flag; - u32 count; - u64 time; -} __OSThreadprofile_s; - -typedef struct OSThread_s { - struct OSThread_s *next; /* run/mesg queue link */ - OSPri priority; /* run/mesg queue priority */ - struct OSThread_s **queue; /* queue thread is on */ - struct OSThread_s *tlnext; /* all threads queue link */ - u16 state; /* OS_STATE_* */ - u16 flags; /* flags for rmon */ - OSId id; /* id for debugging */ - int fp; /* thread has used fp unit */ - __OSThreadprofile_s *thprof; /* workarea for thread profiler */ - __OSThreadContext context; /* register/interrupt mask */ -} OSThread; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* Thread states */ - -#define OS_STATE_STOPPED (1 << 0) -#define OS_STATE_RUNNABLE (1 << 1) -#define OS_STATE_RUNNING (1 << 2) -#define OS_STATE_WAITING (1 << 3) - -/* Recommended thread priorities for the system threads */ - -#define OS_PRIORITY_MAX 255 -#define OS_PRIORITY_VIMGR 254 -#define OS_PRIORITY_RMON 250 -#define OS_PRIORITY_RMONSPIN 200 -#define OS_PRIORITY_PIMGR 150 -#define OS_PRIORITY_SIMGR 140 -#define OS_PRIORITY_APPMAX 127 -#define OS_PRIORITY_IDLE 0 /* Must be 0 */ - -/* For thread profiler */ -#define THPROF_IDMAX 64 -#define THPROF_STACKSIZE 256 - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Thread operations */ - -extern void osCreateThread(OSThread *, OSId, void (*)(void *), void *, void *, OSPri); -extern void osDestroyThread(OSThread *); -extern void osYieldThread(void); -extern void osStartThread(OSThread *); -extern void osStopThread(OSThread *); -extern OSId osGetThreadId(OSThread *); -extern void osSetThreadPri(OSThread *, OSPri); -extern OSPri osGetThreadPri(OSThread *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_THREAD_H_ */ diff --git a/lib/ultralib/include/PR/os_time.h b/lib/ultralib/include/PR/os_time.h deleted file mode 100644 index deaec65..0000000 --- a/lib/ultralib/include/PR/os_time.h +++ /dev/null @@ -1,114 +0,0 @@ - -/*==================================================================== - * os_time.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_time.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:19 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_TIME_H_ -#define _OS_TIME_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_message.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Structure for time value - */ -typedef u64 OSTime; - -/* - * Structure for interval timer - */ -typedef struct OSTimer_s { - struct OSTimer_s *next; /* point to next timer in list */ - struct OSTimer_s *prev; /* point to previous timer in list */ - OSTime interval; /* duration set by user */ - OSTime value; /* time remaining before */ - /* timer fires */ - OSMesgQueue *mq; /* Message Queue */ - OSMesg msg; /* Message to send */ -} OSTimer; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Timer interface */ - -extern OSTime osGetTime(void); -extern void osSetTime(OSTime); -extern int osSetTimer(OSTimer *, OSTime, OSTime, - OSMesgQueue *, OSMesg); -extern int osStopTimer(OSTimer *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_TIME_H_ */ diff --git a/lib/ultralib/include/PR/os_tlb.h b/lib/ultralib/include/PR/os_tlb.h deleted file mode 100644 index 2cdd5c9..0000000 --- a/lib/ultralib/include/PR/os_tlb.h +++ /dev/null @@ -1,107 +0,0 @@ - -/*==================================================================== - * os_tlb.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_tlb.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:20 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_TLB_H_ -#define _OS_TLB_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -typedef u32 OSPageMask; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* - * Page size argument for TLB routines - */ -#define OS_PM_4K 0x0000000 -#define OS_PM_16K 0x0006000 -#define OS_PM_64K 0x001e000 -#define OS_PM_256K 0x007e000 -#define OS_PM_1M 0x01fe000 -#define OS_PM_4M 0x07fe000 -#define OS_PM_16M 0x1ffe000 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* TLB management routines */ - -extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); -extern void osMapTLBRdb(void); -extern void osUnmapTLB(s32); -extern void osUnmapTLBAll(void); -extern void osSetTLBASID(s32); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_TLB_H_ */ diff --git a/lib/ultralib/include/PR/os_version.h b/lib/ultralib/include/PR/os_version.h deleted file mode 100644 index aa10d20..0000000 --- a/lib/ultralib/include/PR/os_version.h +++ /dev/null @@ -1,26 +0,0 @@ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. - - $RCSfile: os_version.h,v $ - $Revision: 1.2 $ - $Date: 1999/06/17 01:33:01 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_VERSION_H_ -#define _OS_VERSION_H_ - -#define VERSION_D 1 -#define VERSION_E 2 -#define VERSION_F 3 -#define VERSION_G 4 -#define VERSION_H 5 -#define VERSION_I 6 -#define VERSION_J 7 -#define VERSION_K 8 -#define VERSION_L 9 - -#define OS_MAJOR_VERSION BUILD_VERSION_STRING /* major version */ -#define OS_MINOR_VERSION 0 /* patch level */ - -#endif /* !_OS_VERSION_H_ */ diff --git a/lib/ultralib/include/PR/os_vi.h b/lib/ultralib/include/PR/os_vi.h deleted file mode 100644 index 5a17f25..0000000 --- a/lib/ultralib/include/PR/os_vi.h +++ /dev/null @@ -1,298 +0,0 @@ - -/*==================================================================== - * os_vi.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_vi.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:20 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_VI_H_ -#define _OS_VI_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_thread.h" -#include "os_message.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Structure to store VI register values that remain the same between 2 fields - */ -typedef struct { - u32 ctrl; - u32 width; - u32 burst; - u32 vSync; - u32 hSync; - u32 leap; - u32 hStart; - u32 xScale; - u32 vCurrent; -} OSViCommonRegs; - - -/* - * Structure to store VI register values that change between fields - */ -typedef struct { - u32 origin; - u32 yScale; - u32 vStart; - u32 vBurst; - u32 vIntr; -} OSViFieldRegs; - - -/* - * Structure for VI mode - */ -typedef struct { - u8 type; /* Mode type */ - OSViCommonRegs comRegs; /* Common registers for both fields */ - OSViFieldRegs fldRegs[2]; /* Registers for Field 1 & 2 */ -} OSViMode; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* - * Video Interface (VI) mode type - */ -#define OS_VI_NTSC_LPN1 0 /* NTSC */ -#define OS_VI_NTSC_LPF1 1 -#define OS_VI_NTSC_LAN1 2 -#define OS_VI_NTSC_LAF1 3 -#define OS_VI_NTSC_LPN2 4 -#define OS_VI_NTSC_LPF2 5 -#define OS_VI_NTSC_LAN2 6 -#define OS_VI_NTSC_LAF2 7 -#define OS_VI_NTSC_HPN1 8 -#define OS_VI_NTSC_HPF1 9 -#define OS_VI_NTSC_HAN1 10 -#define OS_VI_NTSC_HAF1 11 -#define OS_VI_NTSC_HPN2 12 -#define OS_VI_NTSC_HPF2 13 - -#define OS_VI_PAL_LPN1 14 /* PAL */ -#define OS_VI_PAL_LPF1 15 -#define OS_VI_PAL_LAN1 16 -#define OS_VI_PAL_LAF1 17 -#define OS_VI_PAL_LPN2 18 -#define OS_VI_PAL_LPF2 19 -#define OS_VI_PAL_LAN2 20 -#define OS_VI_PAL_LAF2 21 -#define OS_VI_PAL_HPN1 22 -#define OS_VI_PAL_HPF1 23 -#define OS_VI_PAL_HAN1 24 -#define OS_VI_PAL_HAF1 25 -#define OS_VI_PAL_HPN2 26 -#define OS_VI_PAL_HPF2 27 - -#define OS_VI_MPAL_LPN1 28 /* MPAL - mainly Brazil */ -#define OS_VI_MPAL_LPF1 29 -#define OS_VI_MPAL_LAN1 30 -#define OS_VI_MPAL_LAF1 31 -#define OS_VI_MPAL_LPN2 32 -#define OS_VI_MPAL_LPF2 33 -#define OS_VI_MPAL_LAN2 34 -#define OS_VI_MPAL_LAF2 35 -#define OS_VI_MPAL_HPN1 36 -#define OS_VI_MPAL_HPF1 37 -#define OS_VI_MPAL_HAN1 38 -#define OS_VI_MPAL_HAF1 39 -#define OS_VI_MPAL_HPN2 40 -#define OS_VI_MPAL_HPF2 41 - -#define OS_VI_FPAL_LPN1 42 /* FPAL - Full screen PAL */ -#define OS_VI_FPAL_LPF1 43 -#define OS_VI_FPAL_LAN1 44 -#define OS_VI_FPAL_LAF1 45 -#define OS_VI_FPAL_LPN2 46 -#define OS_VI_FPAL_LPF2 47 -#define OS_VI_FPAL_LAN2 48 -#define OS_VI_FPAL_LAF2 49 -#define OS_VI_FPAL_HPN1 50 -#define OS_VI_FPAL_HPF1 51 -#define OS_VI_FPAL_HAN1 52 -#define OS_VI_FPAL_HAF1 53 -#define OS_VI_FPAL_HPN2 54 -#define OS_VI_FPAL_HPF2 55 - -/* - * Video Interface (VI) special features - */ -#define OS_VI_GAMMA_ON 0x0001 -#define OS_VI_GAMMA_OFF 0x0002 -#define OS_VI_GAMMA_DITHER_ON 0x0004 -#define OS_VI_GAMMA_DITHER_OFF 0x0008 -#define OS_VI_DIVOT_ON 0x0010 -#define OS_VI_DIVOT_OFF 0x0020 -#define OS_VI_DITHER_FILTER_ON 0x0040 -#define OS_VI_DITHER_FILTER_OFF 0x0080 - -/* - * Video Interface (VI) mode attribute bit - */ -#define OS_VI_BIT_NONINTERLACE 0x0001 /* lo-res */ -#define OS_VI_BIT_INTERLACE 0x0002 /* lo-res */ -#define OS_VI_BIT_NORMALINTERLACE 0x0004 /* hi-res */ -#define OS_VI_BIT_DEFLICKINTERLACE 0x0008 /* hi-res */ -#define OS_VI_BIT_ANTIALIAS 0x0010 -#define OS_VI_BIT_POINTSAMPLE 0x0020 -#define OS_VI_BIT_16PIXEL 0x0040 -#define OS_VI_BIT_32PIXEL 0x0080 -#define OS_VI_BIT_LORES 0x0100 -#define OS_VI_BIT_HIRES 0x0200 -#define OS_VI_BIT_NTSC 0x0400 -#define OS_VI_BIT_PAL 0x0800 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - -extern OSViMode osViModeTable[]; /* Global VI mode table */ - -extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */ -extern OSViMode osViModeNtscLpf1; -extern OSViMode osViModeNtscLan1; -extern OSViMode osViModeNtscLaf1; -extern OSViMode osViModeNtscLpn2; -extern OSViMode osViModeNtscLpf2; -extern OSViMode osViModeNtscLan2; -extern OSViMode osViModeNtscLaf2; -extern OSViMode osViModeNtscHpn1; -extern OSViMode osViModeNtscHpf1; -extern OSViMode osViModeNtscHan1; -extern OSViMode osViModeNtscHaf1; -extern OSViMode osViModeNtscHpn2; -extern OSViMode osViModeNtscHpf2; - -extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */ -extern OSViMode osViModePalLpf1; -extern OSViMode osViModePalLan1; -extern OSViMode osViModePalLaf1; -extern OSViMode osViModePalLpn2; -extern OSViMode osViModePalLpf2; -extern OSViMode osViModePalLan2; -extern OSViMode osViModePalLaf2; -extern OSViMode osViModePalHpn1; -extern OSViMode osViModePalHpf1; -extern OSViMode osViModePalHan1; -extern OSViMode osViModePalHaf1; -extern OSViMode osViModePalHpn2; -extern OSViMode osViModePalHpf2; - -extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */ -extern OSViMode osViModeMpalLpf1; -extern OSViMode osViModeMpalLan1; -extern OSViMode osViModeMpalLaf1; -extern OSViMode osViModeMpalLpn2; -extern OSViMode osViModeMpalLpf2; -extern OSViMode osViModeMpalLan2; -extern OSViMode osViModeMpalLaf2; -extern OSViMode osViModeMpalHpn1; -extern OSViMode osViModeMpalHpf1; -extern OSViMode osViModeMpalHan1; -extern OSViMode osViModeMpalHaf1; -extern OSViMode osViModeMpalHpn2; -extern OSViMode osViModeMpalHpf2; - -extern OSViMode osViModeFpalLpn1; /* Individual VI FPAL modes */ -extern OSViMode osViModeFpalLpf1; -extern OSViMode osViModeFpalLan1; -extern OSViMode osViModeFpalLaf1; -extern OSViMode osViModeFpalLpn2; -extern OSViMode osViModeFpalLpf2; -extern OSViMode osViModeFpalLan2; -extern OSViMode osViModeFpalLaf2; -extern OSViMode osViModeFpalHpn1; -extern OSViMode osViModeFpalHpf1; -extern OSViMode osViModeFpalHan1; -extern OSViMode osViModeFpalHaf1; -extern OSViMode osViModeFpalHpn2; -extern OSViMode osViModeFpalHpf2; - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Video interface (Vi) */ -extern u32 osViGetStatus(void); -extern u32 osViGetCurrentMode(void); -extern u32 osViGetCurrentLine(void); -extern u32 osViGetCurrentField(void); -extern void *osViGetCurrentFramebuffer(void); -extern void *osViGetNextFramebuffer(void); -extern void osViSetXScale(f32); -extern void osViSetYScale(f32); -extern void osViExtendVStart(u32); -extern void osViSetSpecialFeatures(u32); -extern void osViSetMode(OSViMode *); -extern void osViSetEvent(OSMesgQueue *, OSMesg, u32); -extern void osViSwapBuffer(void *); -extern void osViBlack(u8); -extern void osViFade(u8, u16); -extern void osViRepeatLine(u8); -extern void osCreateViManager(OSPri); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_VI_H_ */ diff --git a/lib/ultralib/include/PR/os_voice.h b/lib/ultralib/include/PR/os_voice.h deleted file mode 100644 index 4e3cf6e..0000000 --- a/lib/ultralib/include/PR/os_voice.h +++ /dev/null @@ -1,108 +0,0 @@ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. - - $RCSfile: os_voice.h,v $ - $Revision: 1.2 $ - $Date: 1999/07/13 08:36:42 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_VOICE_H_ -#define _OS_VOICE_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -typedef struct { /* Voice Recognition System */ - OSMesgQueue *__mq; /* SI Message Queue */ - int __channel; /* Controller Port # */ - s32 __mode; - u8 cmd_status; /* Command Status */ -} OSVoiceHandle; - -typedef struct { /* Voice Recognition System */ - u16 warning; - u16 answer_num; /* 0...5 */ - u16 voice_level; - u16 voice_sn; - u16 voice_time; - u16 answer[5]; - u16 distance[5]; -} OSVoiceData; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* definition for Voice Recognition System */ - -#define VOICE_WARN_TOO_SMALL 0x0400 -#define VOICE_WARN_TOO_LARGE 0x0800 -#define VOICE_WARN_NOT_FIT 0x4000 -#define VOICE_WARN_TOO_NOISY 0x8000 - -#define VOICE_STATUS_READY 0 -#define VOICE_STATUS_START 1 -#define VOICE_STATUS_CANCEL 3 -#define VOICE_STATUS_BUSY 5 -#define VOICE_STATUS_END 7 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Voice Recognition System */ -extern s32 osVoiceInit(OSMesgQueue *, OSVoiceHandle *, int); -extern s32 osVoiceCheckWord(u8 *data); -extern s32 osVoiceClearDictionary(OSVoiceHandle *, u8); -extern s32 osVoiceControlGain(OSVoiceHandle *, s32, s32); -extern s32 osVoiceSetWord(OSVoiceHandle *, u8 *); -extern s32 osVoiceStartReadData(OSVoiceHandle *); -extern s32 osVoiceStopReadData(OSVoiceHandle *); -extern s32 osVoiceGetReadData(OSVoiceHandle *, OSVoiceData *); -extern s32 osVoiceMaskDictionary(OSVoiceHandle *, u8 *, int); -extern void osVoiceCountSyllables(u8 *, u32 *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_VOICE_H_ */ diff --git a/lib/ultralib/include/PR/ramrom.h b/lib/ultralib/include/PR/ramrom.h deleted file mode 100644 index 42e5c2d..0000000 --- a/lib/ultralib/include/PR/ramrom.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef _RAMROM_H -#define _RAMROM_H - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.20 $ - * $Date: 1997/02/11 08:26:47 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ramrom.h,v $ - * - **************************************************************************/ - -/* - * Defines for the GIO card in the Nintendo Development Station - * - * The RAM on the GIO card acts as ROM for the game - * Interrupts available between the game and the Indy host - * - * The last part of the ramrom is used for communication between - * game and host. There are 6 4K buffers defined: - * log, printf, rmon to indy, rmon from indy, app to indy, app from indy - * The last 8 bytes of the buffer are used in the emulator environment - */ - -#define RAMROM_SIZE (0x1000000) - -#define RAMROM_BUF_SIZE (4096) -#define RAMROM_MSG_SIZE (RAMROM_BUF_SIZE*6) -#define RAMROM_MSG_ADDR (RAMROM_SIZE - RAMROM_MSG_SIZE) -#define RAMROM_MSG_HDR_SIZE (3*sizeof(long)) -#define RAMROM_USER_DATA_SIZE (RAMROM_MSG_SIZE-RAMROM_MSG_HDR_SIZE) - -#define RAMROM_APP_READ_ADDR (RAMROM_MSG_ADDR + (0*RAMROM_BUF_SIZE)) -#define RAMROM_APP_WRITE_ADDR (RAMROM_MSG_ADDR + (1*RAMROM_BUF_SIZE)) -#define RAMROM_RMON_READ_ADDR (RAMROM_MSG_ADDR + (2*RAMROM_BUF_SIZE)) -#define RAMROM_RMON_WRITE_ADDR (RAMROM_MSG_ADDR + (3*RAMROM_BUF_SIZE)) -#define RAMROM_PRINTF_ADDR (RAMROM_MSG_ADDR + (4*RAMROM_BUF_SIZE)) -#define RAMROM_LOG_ADDR (RAMROM_MSG_ADDR + (5*RAMROM_BUF_SIZE)) - -/*#define RAMROM_GIO_INTERRUPT (RAMROM_MSG_ADDR + RAMROM_MSG_SIZE - 4)*/ - -/* - * For the initial round of PIF bringup, we will load in a bootstrap loader - * 0x400 bytes into the ramrom, and the rom will be loaded at 0x2000 - */ -#ifndef _HW_VERSION_1 -#define RAMROM_BOOTSTRAP_OFFSET 0x40 -#define RAMROM_GAME_OFFSET 0x1000 -#define RAMROM_FONTDATA_OFFSET 0xb70 -#define RAMROM_FONTDATA_SIZE 1152 -#else -#define RAMROM_BOOTSTRAP_OFFSET 0x400 -#define RAMROM_GAME_OFFSET 0x2000 -#endif -#define RAMROM_CLOCKRATE_OFFSET 0x4 -#define RAMROM_CLOCKRATE_MASK 0xfffffff0 -#define RAMROM_BOOTADDR_OFFSET 0x8 -#define RAMROM_RELEASE_OFFSET 0xc -/* - * Second version of the PIF jumps to location 0x1000, and we'll put a jump to - * location 0x400 into the ramrom (for backwards compatibility). - */ -#define RAMROM_PIF2BOOTSTRAP_OFFSET 0x1000 - -typedef struct { - long type; - long length; /* in bytes of userdata */ - long magic; - char userdata[RAMROM_USER_DATA_SIZE]; -} RamRomBuffer; - -/* - * Interrupt values (must fit in 6 bits!) - * values are used for both request & response - * Transactions initiated by the host start with HOST - * and those initiated by the target start with GAME. - */ - -#define HOST_PIACCESS_REQ 1 -#define HOST_DBG_CMD_READY 2 -#define GAME_DBG_DATA_SEND 3 -#define HOST_DBG_DATA_ACK 4 -#define GAME_PRINTF_SEND 5 -#define HOST_PRINTF_ACK 6 -#define GAME_LOG_SEND 7 -#define HOST_LOG_ACK 8 -#define HOST_APP_CMD_READY 9 -#define GAME_APP_DATA_READY 10 -#define HOST_PROF_REQ 11 -#define GAME_PROF_SEND 12 -#define HOST_PROF_ACK 13 -#define GAME_FAULT_SEND 14 -#define HOST_FAULT_ACK 15 -#define GAME_EXIT 16 -#define HOST_DATA_ACK 17 - -#ifdef _EMULATOR -void __RamRomInit(int key, void *romaddr); -void __RamRomDestroy(int key); -#endif /* _EMULATOR */ - -#endif /* !_RAMROM_H */ diff --git a/lib/ultralib/include/PR/rcp.h b/lib/ultralib/include/PR/rcp.h deleted file mode 100644 index 47c4b34..0000000 --- a/lib/ultralib/include/PR/rcp.h +++ /dev/null @@ -1,848 +0,0 @@ -#ifndef _RCP_H_ -#define _RCP_H_ - -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * File: rcp.h - * - * This file contains register and bit definitions for RCP memory map. - * $Revision: 1.22 $ - * $Date: 1999/05/20 03:01:49 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rcp.h,v $ - * - **************************************************************************/ - -#include "R4300.h" -#include "ultratypes.h" - -/** - * RCP memory map overview: - * - * 0x0000_0000 .. 0x03ef_ffff RDRAM memory - * 0x03f0_0000 .. 0x03ff_ffff RDRAM registers - * - * 0x0400_0000 .. 0x0400_2000 SP memory - * 0x0404_0000 .. 0x040f_ffff SP registers - * 0x0410_0000 .. 0x041f_ffff DP command registers - * 0x0420_0000 .. 0x042f_ffff DP span registers - * 0x0430_0000 .. 0x043f_ffff MI registers - * 0x0440_0000 .. 0x044f_ffff VI registers - * 0x0450_0000 .. 0x045f_ffff AI registers - * 0x0460_0000 .. 0x046f_ffff PI registers - * 0x0470_0000 .. 0x047f_ffff RI registers - * 0x0480_0000 .. 0x048f_ffff SI registers - * 0x0490_0000 .. 0x04ff_ffff unused - * - * 0x0500_0000 .. 0x05ff_ffff cartridge domain 2 - * 0x0600_0000 .. 0x07ff_ffff cartridge domain 1 - * 0x0800_0000 .. 0x0fff_ffff cartridge domain 2 - * 0x1000_0000 .. 0x1fbf_ffff cartridge domain 1 - * - * 0x1fc0_0000 .. 0x1fc0_07bf PIF Boot Rom (1984 bytes) - * 0x1fc0_07c0 .. 0x1fc0_07ff PIF (JoyChannel) RAM (64 bytes) - * 0x1fc0_0800 .. 0x1fcf_ffff Reserved - * 0x1fd0_0000 .. 0x7fff_ffff cartridge domain 1 - * 0x8000_0000 .. 0xffff_ffff external SysAD device - */ - -/** - * RDRAM memory - */ - -#define RDRAM_0_START 0x00000000 -#define RDRAM_0_END 0x001FFFFF -#define RDRAM_1_START 0x00200000 -#define RDRAM_1_END 0x003FFFFF - -#define RDRAM_START RDRAM_0_START -#define RDRAM_END RDRAM_1_END - -/** - * RDRAM registers - */ -#define RDRAM_BASE_REG 0x03F00000 - -#define RDRAM_CONFIG_REG (RDRAM_BASE_REG + 0x00) -#define RDRAM_DEVICE_TYPE_REG (RDRAM_BASE_REG + 0x00) -#define RDRAM_DEVICE_ID_REG (RDRAM_BASE_REG + 0x04) -#define RDRAM_DELAY_REG (RDRAM_BASE_REG + 0x08) -#define RDRAM_MODE_REG (RDRAM_BASE_REG + 0x0c) -#define RDRAM_REF_INTERVAL_REG (RDRAM_BASE_REG + 0x10) -#define RDRAM_REF_ROW_REG (RDRAM_BASE_REG + 0x14) -#define RDRAM_RAS_INTERVAL_REG (RDRAM_BASE_REG + 0x18) -#define RDRAM_MIN_INTERVAL_REG (RDRAM_BASE_REG + 0x1c) -#define RDRAM_ADDR_SELECT_REG (RDRAM_BASE_REG + 0x20) -#define RDRAM_DEVICE_MANUF_REG (RDRAM_BASE_REG + 0x24) - -#define RDRAM_0_DEVICE_ID 0 -#define RDRAM_1_DEVICE_ID 1 - -#define RDRAM_RESET_MODE 0 -#define RDRAM_ACTIVE_MODE 1 -#define RDRAM_STANDBY_MODE 2 - -#define RDRAM_LENGTH (2 * 512 * 2048) -#define RDRAM_0_BASE_ADDRESS (RDRAM_0_DEVICE_ID * RDRAM_LENGTH) -#define RDRAM_1_BASE_ADDRESS (RDRAM_1_DEVICE_ID * RDRAM_LENGTH) - -#define RDRAM_0_CONFIG 0x00000 -#define RDRAM_1_CONFIG 0x00400 -#define RDRAM_GLOBAL_CONFIG 0x80000 - -/** - * PIF Physical memory map (total size = 2 KB) - * - * Size Description Mode - * 1FC007FF +-------+-----------------+-----+ - * | 64 B | JoyChannel RAM | R/W | - * 1FC007C0 +-------+-----------------+-----+ - * |1984 B | Boot ROM | * | * = Reserved - * 1FC00000 +-------+-----------------+-----+ - */ -#define PIF_ROM_START 0x1FC00000 -#define PIF_ROM_END 0x1FC007BF -#define PIF_RAM_START 0x1FC007C0 -#define PIF_RAM_END 0x1FC007FF - - -/** - * Controller channel - * Each game controller channel has 4 error bits that are defined in bit 6-7 of - * the Rx and Tx data size area bytes. Programmers need to clear these bits - * when setting the Tx/Rx size area values for a channel - */ -#define CHNL_ERR_NORESP 0x80 /* Bit 7 (Rx): No response error */ -#define CHNL_ERR_OVERRUN 0x40 /* Bit 6 (Rx): Overrun error */ -#define CHNL_ERR_FRAME 0x80 /* Bit 7 (Tx): Frame error */ -#define CHNL_ERR_COLLISION 0x40 /* Bit 6 (Tx): Collision error */ - -#define CHNL_ERR_MASK 0xC0 /* Bit 6-7: channel errors */ - - -/** - * External device info - */ -#define DEVICE_TYPE_CART 0 /* ROM cartridge */ -#define DEVICE_TYPE_BULK 1 /* ROM bulk */ -#define DEVICE_TYPE_64DD 2 /* 64 Disk Drive */ -#define DEVICE_TYPE_SRAM 3 /* SRAM */ -/* 4-6 are reserved */ -#define DEVICE_TYPE_INIT 7 /* initial value */ -/* 8-14 are reserved */ - -/** - * Signal Processor (SP) Memory - */ -#define SP_DMEM_START 0x04000000 -#define SP_DMEM_END 0x04000FFF -#define SP_IMEM_START 0x04001000 -#define SP_IMEM_END 0x04001FFF - -/** - * Signal Processor (SP) CP0 Registers - */ - -#define SP_BASE_REG 0x04040000 - -/* SP memory address (R/W): [11:0] DMEM/IMEM address, [12] 0=DMEM,1=IMEM */ -#define SP_MEM_ADDR_REG (SP_BASE_REG + 0x00) - -/* SP DRAM DMA address (R/W): [23:0] RDRAM address */ -#define SP_DRAM_ADDR_REG (SP_BASE_REG + 0x04) - -/* SP read DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip; RDRAM -> I/DMEM */ -#define SP_RD_LEN_REG (SP_BASE_REG + 0x08) - -/* SP write DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip; I/DMEM -> RDRAM */ -#define SP_WR_LEN_REG (SP_BASE_REG + 0x0C) - -/* SP status (R/W): [14:0] valid bits; see below for write/read mode */ -#define SP_STATUS_REG (SP_BASE_REG + 0x10) - -/* SP DMA full (R): [0] dma full */ -#define SP_DMA_FULL_REG (SP_BASE_REG + 0x14) - -/* SP DMA busy (R): [0] dma busy */ -#define SP_DMA_BUSY_REG (SP_BASE_REG + 0x18) - -/* SP semaphore (R/W): Read: [0] acquire semaphore; Write: [] release semaphore */ -#define SP_SEMAPHORE_REG (SP_BASE_REG + 0x1C) - -/* SP PC (R/W): [11:0] program counter */ -#define SP_PC_REG 0x04080000 - -/** - * SP_MEM_ADDR_REG: bit 12 - */ -#define SP_DMA_DMEM (0 << 12) -#define SP_DMA_IMEM (1 << 12) - -/** - * SP_STATUS_REG: write bits - */ -#define SP_CLR_HALT (1 << 0) /* clear halt */ -#define SP_SET_HALT (1 << 1) /* set halt */ -#define SP_CLR_BROKE (1 << 2) /* clear broke */ -#define SP_CLR_INTR (1 << 3) /* clear interrupt */ -#define SP_SET_INTR (1 << 4) /* set interrupt */ -#define SP_CLR_SSTEP (1 << 5) /* clear sstep */ -#define SP_SET_SSTEP (1 << 6) /* set sstep */ -#define SP_CLR_INTR_BREAK (1 << 7) /* clear interrupt on break */ -#define SP_SET_INTR_BREAK (1 << 8) /* set interrupt on break */ -#define SP_CLR_SIG0 (1 << 9) /* clear signal 0 */ -#define SP_SET_SIG0 (1 << 10) /* set signal 0 */ -#define SP_CLR_SIG1 (1 << 11) /* clear signal 1 */ -#define SP_SET_SIG1 (1 << 12) /* set signal 1 */ -#define SP_CLR_SIG2 (1 << 13) /* clear signal 2 */ -#define SP_SET_SIG2 (1 << 14) /* set signal 2 */ -#define SP_CLR_SIG3 (1 << 15) /* clear signal 3 */ -#define SP_SET_SIG3 (1 << 16) /* set signal 3 */ -#define SP_CLR_SIG4 (1 << 17) /* clear signal 4 */ -#define SP_SET_SIG4 (1 << 18) /* set signal 4 */ -#define SP_CLR_SIG5 (1 << 19) /* clear signal 5 */ -#define SP_SET_SIG5 (1 << 20) /* set signal 5 */ -#define SP_CLR_SIG6 (1 << 21) /* clear signal 6 */ -#define SP_SET_SIG6 (1 << 22) /* set signal 6 */ -#define SP_CLR_SIG7 (1 << 23) /* clear signal 7 */ -#define SP_SET_SIG7 (1 << 24) /* set signal 7 */ - -/* - * SP_STATUS_REG: read bits - */ -#define SP_STATUS_HALT (1 << 0) -#define SP_STATUS_BROKE (1 << 1) -#define SP_STATUS_DMA_BUSY (1 << 2) -#define SP_STATUS_DMA_FULL (1 << 3) -#define SP_STATUS_IO_FULL (1 << 4) -#define SP_STATUS_SSTEP (1 << 5) -#define SP_STATUS_INTR_BREAK (1 << 6) -#define SP_STATUS_SIG0 (1 << 7) -#define SP_STATUS_SIG1 (1 << 8) -#define SP_STATUS_SIG2 (1 << 9) -#define SP_STATUS_SIG3 (1 << 10) -#define SP_STATUS_SIG4 (1 << 11) -#define SP_STATUS_SIG5 (1 << 12) -#define SP_STATUS_SIG6 (1 << 13) -#define SP_STATUS_SIG7 (1 << 14) - -/* - * SP_STATUS_REG: use of SIG bits - */ -#define SP_CLR_YIELD SP_CLR_SIG0 -#define SP_SET_YIELD SP_SET_SIG0 -#define SP_STATUS_YIELD SP_STATUS_SIG0 -#define SP_CLR_YIELDED SP_CLR_SIG1 -#define SP_SET_YIELDED SP_SET_SIG1 -#define SP_STATUS_YIELDED SP_STATUS_SIG1 -#define SP_CLR_TASKDONE SP_CLR_SIG2 -#define SP_SET_TASKDONE SP_SET_SIG2 -#define SP_STATUS_TASKDONE SP_STATUS_SIG2 -#define SP_CLR_RSPSIGNAL SP_CLR_SIG3 -#define SP_SET_RSPSIGNAL SP_SET_SIG3 -#define SP_STATUS_RSPSIGNAL SP_STATUS_SIG3 -#define SP_CLR_CPUSIGNAL SP_CLR_SIG4 -#define SP_SET_CPUSIGNAL SP_SET_SIG4 -#define SP_STATUS_CPUSIGNAL SP_STATUS_SIG4 - -/* - * SP IMEM BIST REG (R/W): [6:0] BIST status bits; see below for detail - */ -#define SP_IBIST_REG 0x04080004 - -/* - * SP_IBIST_REG: write bits - */ -#define SP_IBIST_CHECK (1 << 0) /* BIST check */ -#define SP_IBIST_GO (1 << 1) /* BIST go */ -#define SP_IBIST_CLEAR (1 << 2) /* BIST clear */ - -/* - * SP_BIST_REG: read bits - * First 2 bits are same as in write mode - */ -#define SP_IBIST_DONE (1 << 2) -#define SP_IBIST_FAILED 0x78 /* bits [6:3], BIST fail */ - -/** - * Display Processor Command (DPC) Registers - */ -#define DPC_BASE_REG 0x04100000 - -/* DP CMD DMA start (R/W): [23:0] DMEM/RDRAM start address */ -#define DPC_START_REG (DPC_BASE_REG + 0x00) - -/* DP CMD DMA end (R/W): [23:0] DMEM/RDRAM end address */ -#define DPC_END_REG (DPC_BASE_REG + 0x04) - -/* DP CMD DMA end (R): [23:0] DMEM/RDRAM current address */ -#define DPC_CURRENT_REG (DPC_BASE_REG + 0x08) - -/* DP CMD status (R/W): [9:0] valid bits - see below for definitions */ -#define DPC_STATUS_REG (DPC_BASE_REG + 0x0C) - -/* DP clock counter (R): [23:0] clock counter */ -#define DPC_CLOCK_REG (DPC_BASE_REG + 0x10) - -/* DP buffer busy counter (R): [23:0] clock counter */ -#define DPC_BUFBUSY_REG (DPC_BASE_REG + 0x14) - -/* DP pipe busy counter (R): [23:0] clock counter */ -#define DPC_PIPEBUSY_REG (DPC_BASE_REG + 0x18) - -/* DP TMEM load counter (R): [23:0] clock counter */ -#define DPC_TMEM_REG (DPC_BASE_REG + 0x1C) - -/** - * DPC_STATUS_REG: write bits - */ -#define DPC_CLR_XBUS_DMEM_DMA (1 << 0) -#define DPC_SET_XBUS_DMEM_DMA (1 << 1) -#define DPC_CLR_FREEZE (1 << 2) -#define DPC_SET_FREEZE (1 << 3) -#define DPC_CLR_FLUSH (1 << 4) -#define DPC_SET_FLUSH (1 << 5) -#define DPC_CLR_TMEM_CTR (1 << 6) -#define DPC_CLR_PIPE_CTR (1 << 7) -#define DPC_CLR_CMD_CTR (1 << 8) -#define DPC_CLR_CLOCK_CTR (1 << 9) - -/** - * DPC_STATUS_REG: read bits - */ -#define DPC_STATUS_XBUS_DMEM_DMA (1 << 0) -#define DPC_STATUS_FREEZE (1 << 1) -#define DPC_STATUS_FLUSH (1 << 2) -#define DPC_STATUS_START_GCLK (1 << 3) -#define DPC_STATUS_TMEM_BUSY (1 << 4) -#define DPC_STATUS_PIPE_BUSY (1 << 5) -#define DPC_STATUS_CMD_BUSY (1 << 6) -#define DPC_STATUS_CBUF_READY (1 << 7) -#define DPC_STATUS_DMA_BUSY (1 << 8) -#define DPC_STATUS_END_VALID (1 << 9) -#define DPC_STATUS_START_VALID (1 << 10) - -/** - * Display Processor Span (DPS) Registers - */ -#define DPS_BASE_REG 0x04200000 - -/* DP tmem built-in self-test (R/W): [10:0] BIST status bits */ -#define DPS_TBIST_REG (DPS_BASE_REG + 0x00) - -/* DP span test mode (R/W): [0] Span buffer test access enable */ -#define DPS_TEST_MODE_REG (DPS_BASE_REG + 0x04) - -/* DP span buffer test address (R/W): [6:0] bits */ -#define DPS_BUFTEST_ADDR_REG (DPS_BASE_REG + 0x08) - -/* DP span buffer test data (R/W): [31:0] span buffer data */ -#define DPS_BUFTEST_DATA_REG (DPS_BASE_REG + 0x0C) - -/* - * DPS_TMEM_BIST_REG: write bits - */ -#define DPS_TBIST_CHECK (1 << 0) -#define DPS_TBIST_GO (1 << 1) -#define DPS_TBIST_CLEAR (1 << 2) - -/* - * DPS_TMEM_BIST_REG: read bits - * First 2 bits are same as in write mode - */ -#define DPS_TBIST_DONE (1 << 2) -#define DPS_TBIST_FAILED 0x7F8 /* bits [10:3], BIST fail */ - -/** - * MIPS Interface (MI) Registers - */ -#define MI_BASE_REG 0x04300000 - -/* - * MI init mode (W): [6:0] init length, [7] clear init mode, [8] set init mode - * [9/10] clear/set ebus test mode, [11] clear DP interrupt - * (R): [6:0] init length, [7] init mode, [8] ebus test mode - */ -#define MI_INIT_MODE_REG (MI_BASE_REG + 0x00) -#define MI_MODE_REG MI_INIT_MODE_REG - -/* - * MI_MODE_REG: write bits - */ -#define MI_CLR_INIT (1 << 7) /* clear init mode */ -#define MI_SET_INIT (1 << 8) /* set init mode */ -#define MI_CLR_EBUS (1 << 9) /* clear ebus test */ -#define MI_SET_EBUS (1 << 10) /* set ebus test mode */ -#define MI_CLR_DP_INTR (1 << 11) /* clear dp interrupt */ -#define MI_CLR_RDRAM (1 << 12) /* clear RDRAM reg */ -#define MI_SET_RDRAM (1 << 13) /* set RDRAM reg mode */ - -/* - * MI_MODE_REG: read bits - */ -#define MI_MODE_INIT (1 << 7) /* init mode */ -#define MI_MODE_EBUS (1 << 8) /* ebus test mode */ -#define MI_MODE_RDRAM (1 << 9) /* RDRAM reg mode */ - -/* MI version (R): [7:0] io, [15:8] rac, [23:16] rdp, [31:24] rsp */ -#define MI_VERSION_REG (MI_BASE_REG + 0x04) -#define MI_NOOP_REG MI_VERSION_REG - -/* MI interrupt (R): [5:0] valid bits - see below for bit patterns */ -#define MI_INTR_REG (MI_BASE_REG + 0x08) - -/* - * MI interrupt mask (W): [11:0] valid bits - see below for bit patterns - * (R): [5:0] valid bits - see below for bit patterns - */ -#define MI_INTR_MASK_REG (MI_BASE_REG + 0x0C) - -/* - * MI_INTR_REG: read bits - */ -#define MI_INTR_SP (1 << 0) /* SP intr */ -#define MI_INTR_SI (1 << 1) /* SI intr */ -#define MI_INTR_AI (1 << 2) /* AI intr */ -#define MI_INTR_VI (1 << 3) /* VI intr */ -#define MI_INTR_PI (1 << 4) /* PI intr */ -#define MI_INTR_DP (1 << 5) /* DP intr */ - -/* - * MI_INTR_MASK_REG: write bits - */ -#define MI_INTR_MASK_CLR_SP (1 << 0) /* clear SP mask */ -#define MI_INTR_MASK_SET_SP (1 << 1) /* set SP mask */ -#define MI_INTR_MASK_CLR_SI (1 << 2) /* clear SI mask */ -#define MI_INTR_MASK_SET_SI (1 << 3) /* set SI mask */ -#define MI_INTR_MASK_CLR_AI (1 << 4) /* clear AI mask */ -#define MI_INTR_MASK_SET_AI (1 << 5) /* set AI mask */ -#define MI_INTR_MASK_CLR_VI (1 << 6) /* clear VI mask */ -#define MI_INTR_MASK_SET_VI (1 << 7) /* set VI mask */ -#define MI_INTR_MASK_CLR_PI (1 << 8) /* clear PI mask */ -#define MI_INTR_MASK_SET_PI (1 << 9) /* set PI mask */ -#define MI_INTR_MASK_CLR_DP (1 << 10) /* clear DP mask */ -#define MI_INTR_MASK_SET_DP (1 << 11) /* set DP mask */ - -/* - * MI_INTR_MASK_REG: read bits - */ -#define MI_INTR_MASK_SP (1 << 0) /* SP intr mask */ -#define MI_INTR_MASK_SI (1 << 1) /* SI intr mask */ -#define MI_INTR_MASK_AI (1 << 2) /* AI intr mask */ -#define MI_INTR_MASK_VI (1 << 3) /* VI intr mask */ -#define MI_INTR_MASK_PI (1 << 4) /* PI intr mask */ -#define MI_INTR_MASK_DP (1 << 5) /* DP intr mask */ - -/** - * Video Interface (VI) Registers - */ -#define VI_BASE_REG 0x04400000 - -/* VI status/control (R/W): [15-0] valid bits: - * [1:0] = type[1:0] (pixel size) - * 0: blank (no data, no sync) - * 1: reserved - * 2: 5/5/5/3 ("16" bit) - * 3: 8/8/8/8 (32 bit) - * [2] = gamma_dither_enable (normally on, unless "special effect") - * [3] = gamma_enable (normally on, unless MPEG/JPEG) - * [4] = divot_enable (normally on if antialiased, unless decal lines) - * [5] = reserved - always off - * [6] = serrate (always on if interlaced, off if not) - * [7] = reserved - diagnostics only - * [9:8] = anti-alias (aa) mode[1:0] - * 0: aa & resamp (always fetch extra lines) - * 1: aa & resamp (fetch extra lines if needed) - * 2: resamp only (treat as all fully covered) - * 3: neither (replicate pixels, no interpolate) - * [11] = reserved - diagnostics only - * [15:12] = reserved - * - */ -#define VI_CONTROL_REG (VI_BASE_REG + 0x00) -#define VI_STATUS_REG VI_CONTROL_REG - -/* VI origin (R/W): [23:0] frame buffer origin in bytes */ -#define VI_ORIGIN_REG (VI_BASE_REG + 0x04) -#define VI_DRAM_ADDR_REG VI_ORIGIN_REG - -/* VI width (R/W): [11:0] frame buffer line width in pixels */ -#define VI_WIDTH_REG (VI_BASE_REG + 0x08) -#define VI_H_WIDTH_REG VI_WIDTH_REG - -/* VI vertical intr (R/W): [9:0] interrupt when current half-line = V_INTR */ -#define VI_INTR_REG (VI_BASE_REG + 0x0C) -#define VI_V_INTR_REG VI_INTR_REG - -/* - * VI current vertical line (R/W): [9:0] current half line, sampled once per - * line (the lsb of V_CURRENT is constant within a field, and in - * interlaced modes gives the field number - which is constant for non- - * interlaced modes) - * - Any write to this register will clear interrupt line - */ -#define VI_CURRENT_REG (VI_BASE_REG + 0x10) -#define VI_V_CURRENT_LINE_REG VI_CURRENT_REG - -/* - * VI video timing (R/W): [ 7: 0] horizontal sync width in pixels, - * [15: 8] color burst width in pixels, - * [19:16] vertical sync width in half lines, - * [29:20] start of color burst in pixels from h-sync - */ -#define VI_BURST_REG (VI_BASE_REG + 0x14) -#define VI_TIMING_REG VI_BURST_REG - -/* VI vertical sync (R/W): [9:0] number of half-lines per field */ -#define VI_V_SYNC_REG (VI_BASE_REG + 0x18) - -/* VI horizontal sync (R/W): [11: 0] total duration of a line in 1/4 pixel - * [20:16] a 5-bit leap pattern used for PAL only - * (h_sync_period) - */ -#define VI_H_SYNC_REG (VI_BASE_REG + 0x1C) - -/* - * VI horizontal sync leap (R/W): [11: 0] identical to h_sync_period - * [27:16] identical to h_sync_period - */ -#define VI_LEAP_REG (VI_BASE_REG + 0x20) -#define VI_H_SYNC_LEAP_REG VI_LEAP_REG - -/* - * VI horizontal video (R/W): [ 9: 0] end of active video in screen pixels - * : [25:16] start of active video in screen pixels - */ -#define VI_H_START_REG (VI_BASE_REG + 0x24) -#define VI_H_VIDEO_REG VI_H_START_REG - -/* - * VI vertical video (R/W): [ 9: 0] end of active video in screen half-lines - * : [25:16] start of active video in screen half-lines - */ -#define VI_V_START_REG (VI_BASE_REG + 0x28) -#define VI_V_VIDEO_REG VI_V_START_REG - -/* - * VI vertical burst (R/W): [ 9: 0] end of color burst enable in half-lines - * : [25:16] start of color burst enable in half-lines - */ -#define VI_V_BURST_REG (VI_BASE_REG + 0x2C) - -/* VI x-scale (R/W): [11: 0] 1/horizontal scale up factor (2.10 format) - * [27:16] horizontal subpixel offset (2.10 format) - */ -#define VI_X_SCALE_REG (VI_BASE_REG + 0x30) - -/* VI y-scale (R/W): [11: 0] 1/vertical scale up factor (2.10 format) - * [27:16] vertical subpixel offset (2.10 format) - */ -#define VI_Y_SCALE_REG (VI_BASE_REG + 0x34) - -/* - * Patterns to interpret VI_CONTROL_REG - */ -#define VI_CTRL_TYPE_16 0x00002 /* [1:0] pixel size: 16 bit */ -#define VI_CTRL_TYPE_32 0x00003 /* [1:0] pixel size: 32 bit */ -#define VI_CTRL_GAMMA_DITHER_ON 0x00004 /* 2: default = on */ -#define VI_CTRL_GAMMA_ON 0x00008 /* 3: default = on */ -#define VI_CTRL_DIVOT_ON 0x00010 /* 4: default = on */ -#define VI_CTRL_SERRATE_ON 0x00040 /* 6: on if interlaced */ -#define VI_CTRL_ANTIALIAS_MASK 0x00300 /* [9:8] anti-alias mode */ -#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ -#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ -#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ -#define VI_CTRL_PIXEL_ADV_MASK 0x01000 /* [15:12] pixel advance mode? */ -#define VI_CTRL_PIXEL_ADV_1 0x01000 /* Bit [15:12] pixel advance mode? */ -#define VI_CTRL_PIXEL_ADV_2 0x02000 /* Bit [15:12] pixel advance mode? */ -#define VI_CTRL_PIXEL_ADV_3 0x03000 /* Bit [15:12] pixel advance mode? */ -#define VI_CTRL_DITHER_FILTER_ON 0x10000 /* 16: dither-filter mode */ - -/* - * Possible video clocks (NTSC or PAL) - */ -#define VI_NTSC_CLOCK 48681812 /* Hz = 48.681812 MHz */ -#define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */ -#define VI_MPAL_CLOCK 48628316 /* Hz = 48.628316 MHz */ - -/** - * The address and length registers are double buffered; that is, they - * can be written twice before becoming full. - * The address must be written before the length. - */ - -/** - * Audio Interface (AI) Registers - */ -#define AI_BASE_REG 0x04500000 - -/* AI DRAM address (W): [23:0] starting RDRAM address (8B-aligned) */ -#define AI_DRAM_ADDR_REG (AI_BASE_REG + 0x00) /* R0: DRAM address */ - -/* AI length (R/W): [14:0] transfer length (v1.0) - Bottom 3 bits are ignored */ -/* [17:0] transfer length (v2.0) - Bottom 3 bits are ignored */ -#define AI_LEN_REG (AI_BASE_REG + 0x04) /* R1: Length */ - -/* AI control (W): [0] DMA enable - if LSB == 1, DMA is enabled */ -#define AI_CONTROL_REG (AI_BASE_REG + 0x08) /* R2: DMA Control */ - -/* Value for control register */ -#define AI_CONTROL_DMA_ON 1 /* LSB = 1: DMA enable*/ -#define AI_CONTROL_DMA_OFF 0 /* LSB = 1: DMA enable*/ - -/* - * AI status (R): [31]/[0] ai_full (addr & len buffer full), [30] ai_busy - * Note that a 1->0 transition in ai_full will set interrupt - * (W): clear audio interrupt - */ -#define AI_STATUS_REG (AI_BASE_REG + 0x0C) /* R3: Status */ - -/* Value for status register */ -#define AI_STATUS_FIFO_FULL (1 << 31) -#define AI_STATUS_DMA_BUSY (1 << 30) - -/* - * AI DAC sample period register (W): [13:0] dac rate - * - vid_clock/(dperiod + 1) is the DAC sample rate - * - (dperiod + 1) >= 66 * (aclockhp + 1) must be true - */ -#define AI_DACRATE_REG (AI_BASE_REG + 0x10) /* R4: DAC rate 14-lsb*/ - -/* DAC rate = video clock / audio frequency - * - DAC rate >= (66 * Bit rate) must be true - */ -#define AI_MAX_DAC_RATE 16384 /* 14-bit+1 */ -#define AI_MIN_DAC_RATE 132 - -/* - * AI bit rate (W): [3:0] bit rate (abus clock half period register - aclockhp) - * - vid_clock/(2 * (aclockhp + 1)) is the DAC clock rate - * - The abus clock stops if aclockhp is zero - */ -#define AI_BITRATE_REG (AI_BASE_REG + 0x14) /* R5: Bit rate 4-lsb */ - -/* Bit rate <= (DAC rate / 66) */ -#define AI_MAX_BIT_RATE 16 /* 4-bit+1 */ -#define AI_MIN_BIT_RATE 2 - -/* - * Maximum and minimum values for audio frequency based on video clocks - * max frequency = (video clock / min dac rate) - * min frequency = (video clock / max dac rate) - */ -#define AI_NTSC_MAX_FREQ 368000 /* 368 KHz */ -#define AI_NTSC_MIN_FREQ 3000 /* 3 KHz ~ 2971 Hz */ - -#define AI_PAL_MAX_FREQ 376000 /* 376 KHz */ -#define AI_PAL_MIN_FREQ 3050 /* 3 KHz ~ 3031 Hz */ - -#define AI_MPAL_MAX_FREQ 368000 /* 368 KHz */ -#define AI_MPAL_MIN_FREQ 3000 /* 3 KHz ~ 2968 Hz */ - -/** - * Peripheral Interface (PI) Registers - */ -#define PI_BASE_REG 0x04600000 - -/* PI DRAM address (R/W): [23:0] starting RDRAM address */ -#define PI_DRAM_ADDR_REG (PI_BASE_REG + 0x00) /* DRAM address */ - -/* PI pbus (cartridge) address (R/W): [31:0] starting AD16 address */ -#define PI_CART_ADDR_REG (PI_BASE_REG + 0x04) - -/* PI read length (R/W): [23:0] read data length */ -#define PI_RD_LEN_REG (PI_BASE_REG + 0x08) - -/* PI write length (R/W): [23:0] write data length */ -#define PI_WR_LEN_REG (PI_BASE_REG + 0x0C) - -/* - * PI status (R): [0] DMA busy, [1] IO busy, [2], error - * (W): [0] reset controller (and abort current op), [1] clear intr - */ -#define PI_STATUS_REG (PI_BASE_REG + 0x10) - -/* PI dom1 latency (R/W): [7:0] domain 1 device latency */ -#define PI_BSD_DOM1_LAT_REG (PI_BASE_REG + 0x14) - -/* PI dom1 pulse width (R/W): [7:0] domain 1 device R/W strobe pulse width */ -#define PI_BSD_DOM1_PWD_REG (PI_BASE_REG + 0x18) - -/* PI dom1 page size (R/W): [3:0] domain 1 device page size */ -#define PI_BSD_DOM1_PGS_REG (PI_BASE_REG + 0x1C) /* page size */ - -/* PI dom1 release (R/W): [1:0] domain 1 device R/W release duration */ -#define PI_BSD_DOM1_RLS_REG (PI_BASE_REG + 0x20) - -/* PI dom2 latency (R/W): [7:0] domain 2 device latency */ -#define PI_BSD_DOM2_LAT_REG (PI_BASE_REG + 0x24) /* Domain 2 latency */ - -/* PI dom2 pulse width (R/W): [7:0] domain 2 device R/W strobe pulse width */ -#define PI_BSD_DOM2_PWD_REG (PI_BASE_REG + 0x28) /* pulse width */ - -/* PI dom2 page size (R/W): [3:0] domain 2 device page size */ -#define PI_BSD_DOM2_PGS_REG (PI_BASE_REG + 0x2C) /* page size */ - -/* PI dom2 release (R/W): [1:0] domain 2 device R/W release duration */ -#define PI_BSD_DOM2_RLS_REG (PI_BASE_REG + 0x30) /* release duration */ - -#define PI_DOMAIN1_REG PI_BSD_DOM1_LAT_REG -#define PI_DOMAIN2_REG PI_BSD_DOM2_LAT_REG - -#define PI_DOM_LAT_OFS 0x00 -#define PI_DOM_PWD_OFS 0x04 -#define PI_DOM_PGS_OFS 0x08 -#define PI_DOM_RLS_OFS 0x0C - -/* - * PI status register has 3 bits active when read from (PI_STATUS_REG - read) - * Bit 0: DMA busy - set when DMA is in progress - * Bit 1: IO busy - set when IO is in progress - * Bit 2: Error - set when CPU issues IO request while DMA is busy - */ -#define PI_STATUS_DMA_BUSY (1 << 0) -#define PI_STATUS_IO_BUSY (1 << 1) -#define PI_STATUS_ERROR (1 << 2) - -/* PI status register has 2 bits active when written to: - * Bit 0: When set, reset PIC - * Bit 1: When set, clear interrupt flag - * The values of the two bits can be ORed together to both reset PIC and - * clear interrupt at the same time. - * - * Note: - * - The PIC does generate an interrupt at the end of each DMA. CPU - * needs to clear the interrupt flag explicitly (from an interrupt - * handler) by writing into the STATUS register with bit 1 set. - * - * - When a DMA completes, the interrupt flag is set. CPU can issue - * another request even while the interrupt flag is set (as long as - * PIC is idle). However, it is the CPU's responsibility for - * maintaining accurate correspondence between DMA completions and - * interrupts. - * - * - When PIC is reset, if PIC happens to be busy, an interrupt will - * be generated as PIC returns to idle. Otherwise, no interrupt will - * be generated and PIC remains idle. - */ - -/* - * PI_STATUS_REG: write bits - */ -#define PI_STATUS_RESET (1 << 0) -#define PI_SET_RESET PI_STATUS_RESET - -#define PI_STATUS_CLR_INTR (1 << 1) -#define PI_CLR_INTR PI_STATUS_CLR_INTR - -#define PI_DMA_BUFFER_SIZE 128 - -#define PI_DOM1_ADDR1 0x06000000 /* to 0x07FFFFFF */ -#define PI_DOM1_ADDR2 0x10000000 /* to 0x1FBFFFFF */ -#define PI_DOM1_ADDR3 0x1FD00000 /* to 0x7FFFFFFF */ -#define PI_DOM2_ADDR1 0x05000000 /* to 0x05FFFFFF */ -#define PI_DOM2_ADDR2 0x08000000 /* to 0x0FFFFFFF */ - -/** - * RDRAM Interface (RI) Registers - */ -#define RI_BASE_REG 0x04700000 - -/* RI mode (R/W): [1:0] operating mode, [2] stop T active, [3] stop R active */ -#define RI_MODE_REG (RI_BASE_REG + 0x00) - -/* RI config (R/W): [5:0] current control input, [6] current control enable */ -#define RI_CONFIG_REG (RI_BASE_REG + 0x04) - -/* RI current load (W): [] any write updates current control register */ -#define RI_CURRENT_LOAD_REG (RI_BASE_REG + 0x08) - -/* RI select (R/W): [2:0] receive select, [2:0] transmit select */ -#define RI_SELECT_REG (RI_BASE_REG + 0x0C) - -/* RI refresh (R/W): [7:0] clean refresh delay, [15:8] dirty refresh delay, - * [16] refresh bank, [17] refresh enable - * [18] refresh optimize - */ -#define RI_REFRESH_REG (RI_BASE_REG + 0x10) -#define RI_COUNT_REG RI_REFRESH_REG - -/* RI latency (R/W): [3:0] DMA latency/overlap */ -#define RI_LATENCY_REG (RI_BASE_REG + 0x14) - -/* RI error (R): [0] nack error, [1] ack error */ -#define RI_RERROR_REG (RI_BASE_REG + 0x18) - -/* RI error (W): [] any write clears all error bits */ -#define RI_WERROR_REG (RI_BASE_REG + 0x1C) - -/** - * Serial Interface (SI) Registers - */ -#define SI_BASE_REG 0x04800000 - -/* SI DRAM address (R/W): [23:0] starting RDRAM address */ -#define SI_DRAM_ADDR_REG (SI_BASE_REG + 0x00) - -/* SI address read 64B (W): [] write begins a 64B DMA write PIF RAM -> RDRAM */ -#define SI_PIF_ADDR_RD64B_REG (SI_BASE_REG + 0x04) - -/* Address SI_BASE_REG + (0x08, 0x0C, 0x14) are reserved */ - -/* SI address write 64B (W): [] write begins a 64B DMA read RDRAM -> PIF RAM */ -#define SI_PIF_ADDR_WR64B_REG (SI_BASE_REG + 0x10) - -/* SI status (R/W): [] any write clears interrupt */ -#define SI_STATUS_REG (SI_BASE_REG + 0x18) - -/* - * SI_STATUS_REG: read bits - */ -#define SI_STATUS_DMA_BUSY (1 << 0) /* DMA in progress */ -#define SI_STATUS_RD_BUSY (1 << 1) /* IO access in progress */ -#define SI_STATUS_DMA_ERROR (1 << 3) /* Overlapping DMA requests */ -#define SI_STATUS_INTERRUPT (1 << 12) /* Interrupt is set */ - -/** - * Development Board GIO Control Registers - */ - -#define GIO_BASE_REG 0x18000000 - -/* Game to Host Interrupt */ -#define GIO_GIO_INTR_REG (GIO_BASE_REG+0x000) - -/* Game to Host SYNC */ -#define GIO_GIO_SYNC_REG (GIO_BASE_REG+0x400) - -/* Host to Game Interrupt */ -#define GIO_CART_INTR_REG (GIO_BASE_REG+0x800) - -/** - * Common macros - */ -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) -#define IO_READ(addr) (*(vu32*)PHYS_TO_K1(addr)) -#define IO_WRITE(addr,data) (*(vu32*)PHYS_TO_K1(addr)=(u32)(data)) -#define RCP_STAT_PRINT \ - rmonPrintf("current=%x start=%x end=%x dpstat=%x spstat=%x\n", \ - IO_READ(DPC_CURRENT_REG), \ - IO_READ(DPC_START_REG), \ - IO_READ(DPC_END_REG), \ - IO_READ(DPC_STATUS_REG), \ - IO_READ(SP_STATUS_REG)) - -#endif - -#endif /* _RCP_H_ */ diff --git a/lib/ultralib/include/PR/rdb.h b/lib/ultralib/include/PR/rdb.h deleted file mode 100644 index e089749..0000000 --- a/lib/ultralib/include/PR/rdb.h +++ /dev/null @@ -1,93 +0,0 @@ - -/************************************************************************** - * - * $Revision: 1.6 $ - * $Date: 1997/02/11 08:29:31 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rdb.h,v $ - * - **************************************************************************/ - -#ifndef _RDB_H -#define _RDB_H - -/* U64 side address */ -#define RDB_BASE_REG 0xc0000000 -#define RDB_WRITE_INTR_REG (RDB_BASE_REG + 0x8) -#define RDB_READ_INTR_REG (RDB_BASE_REG + 0xc) -#define RDB_BASE_VIRTUAL_ADDR 0x80000000 - -/* packet type Have six bits, so can have up to 63 types */ -#define RDB_TYPE_INVALID 0 -#define RDB_TYPE_GtoH_PRINT 1 -#define RDB_TYPE_GtoH_FAULT 2 -#define RDB_TYPE_GtoH_LOG_CT 3 -#define RDB_TYPE_GtoH_LOG 4 -#define RDB_TYPE_GtoH_READY_FOR_DATA 5 -#define RDB_TYPE_GtoH_DATA_CT 6 -#define RDB_TYPE_GtoH_DATA 7 -#define RDB_TYPE_GtoH_DEBUG 8 -#define RDB_TYPE_GtoH_RAMROM 9 -#define RDB_TYPE_GtoH_DEBUG_DONE 10 -#define RDB_TYPE_GtoH_DEBUG_READY 11 -#define RDB_TYPE_GtoH_KDEBUG 12 -#define RDB_TYPE_GtoH_PROF_DATA 22 - - -#define RDB_TYPE_HtoG_LOG_DONE 13 -#define RDB_TYPE_HtoG_DEBUG 14 -#define RDB_TYPE_HtoG_DEBUG_CT 15 -#define RDB_TYPE_HtoG_DATA 16 -#define RDB_TYPE_HtoG_DATA_DONE 17 -#define RDB_TYPE_HtoG_REQ_RAMROM 18 -#define RDB_TYPE_HtoG_FREE_RAMROM 19 -#define RDB_TYPE_HtoG_KDEBUG 20 -#define RDB_TYPE_HtoG_PROF_SIGNAL 21 - - -#define RDB_PROF_ACK_SIG 1 -#define RDB_PROF_FLUSH_SIG 2 -#define PROF_BLOCK_SIZE 2048 - -#define RDB_LOG_MAX_BLOCK_SIZE 0x8000 -#define RDB_DATA_MAX_BLOCK_SIZE 0x8000 - - -/* GIO side address */ -#define GIO_RDB_BASE_REG 0xbf480000 -#define GIO_RDB_WRITE_INTR_REG (GIO_RDB_BASE_REG + 0x8) -#define GIO_RDB_READ_INTR_REG (GIO_RDB_BASE_REG + 0xc) - -/* minor device number */ -#define GIO_RDB_PRINT_MINOR 1 -#define GIO_RDB_DEBUG_MINOR 2 - -/* interrupt bit */ -#define GIO_RDB_WRITE_INTR_BIT 0x80000000 -#define GIO_RDB_READ_INTR_BIT 0x40000000 - -/* debug command */ -#define DEBUG_COMMAND_NULL 0 -#define DEBUG_COMMAND_MEMORY 1 -#define DEBUG_COMMAND_REGISTER 2 -#define DEBUG_COMMAND_INVALID 255 - -/* debug state */ -#define DEBUG_STATE_NULL 0 -#define DEBUG_STATE_RECEIVE 1 -#define DEBUG_STATE_INVALID 255 - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Structure for debug port */ -typedef struct { - unsigned type : 6; /* 0: invalid, 1: print, 2: debug */ - unsigned length : 2; /* 1, 2, or 3 */ - char buf[3]; /* character buffer */ -} rdbPacket; - -extern unsigned int __osRdbWriteOK; -extern unsigned int __osRdbSendMessage; - -#endif /* _LANGUAGE_C */ - -#endif /* !_RDB_H */ diff --git a/lib/ultralib/include/PR/region.h b/lib/ultralib/include/PR/region.h deleted file mode 100644 index 0ac8a25..0000000 --- a/lib/ultralib/include/PR/region.h +++ /dev/null @@ -1,123 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * Module: region.h - * - * $Revision: 1.8 $ - * $Date: 1997/11/26 00:30:56 $ - * $Author: mitu $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/region.h,v $ - * - * Description: - * This file contains macros and structure definitions for the region - * library. - * - **************************************************************************/ - - -#ifndef _REGION_H_ -#define _REGION_H_ - - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - - -/*************************************** - * - * Global defines - * - */ - /* Alignment sizes */ -#define ALIGNSZ (sizeof(long long)) /* 8 bytes */ -#define ALIGNOFFST (ALIGNSZ-1) - - /* size for storing index to free buffer */ -#define BUF_CTRL_SIZE ALIGNSZ - - /* Max bufcount = 32K */ -#define MAX_BUFCOUNT 0x8000 - /* code for last free buffer */ -#define BUF_FREE_WO_NEXT 0x8000 - -/* - * Global defines for alignment size (default is 8-byte alignment) - */ -#define OS_RG_ALIGN_2B 2 /* 2 bytes = 16-bit alignment */ -#define OS_RG_ALIGN_4B 4 /* 4 bytes = 32-bit alignment */ -#define OS_RG_ALIGN_8B 8 /* 8 bytes = 64-bit alignment */ -#define OS_RG_ALIGN_16B 16 /* 16 bytes = 128-bit alignment */ - -#define OS_RG_ALIGN_DEFAULT OS_RG_ALIGN_8B - - -/*************************************** - * - * Macro definitions - * - */ - -/* Perform alignment on input 's' */ -#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1)) - - -/*************************************** - * - * Typedefs & structure definitions - * - */ -/* - * Structure for region header/control area - */ -typedef struct _Region_s { - u8 *r_startBufferAddress; /* start address to data buffer */ - u8 *r_endAddress; /* end address of region */ - s32 r_bufferSize; /* size of buffers for this region */ - s32 r_bufferCount; /* up to 32K entries; MSB is used for - setting end-of-list/used */ - u16 r_freeList; /* point to array index of first - available memory buffer */ - u16 r_alignSize; /* alignment size (# of bytes) */ -} OSRegion; - -/* - * Macro to simplify accessing region header structure - */ -#define RP(x) rp->r_##x - - -/*************************************** - * - * Function prototypes - * - */ -extern void *osCreateRegion(void *, u32, u32, u32); -extern void *osMalloc(void *); -extern void osFree(void *, void *); -extern s32 osGetRegionBufCount(void *); -extern s32 osGetRegionBufSize(void *); - - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - - -#endif /* _REGION_H_ */ - - diff --git a/lib/ultralib/include/PR/rmon.h b/lib/ultralib/include/PR/rmon.h deleted file mode 100644 index 199e569..0000000 --- a/lib/ultralib/include/PR/rmon.h +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.6 $ - * $Date: 1997/02/11 08:30:08 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rmon.h,v $ - * - **************************************************************************/ - -#ifndef _RMON_H_ -#define _RMON_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#define RMON_DBG_BUF_SIZE 2048 -#define RMON_STACKSIZE 0x1000 - -extern void rmonMain( void * ); -extern void rmonPrintf( const char *, ... ); - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_H */ diff --git a/lib/ultralib/include/PR/sched.h b/lib/ultralib/include/PR/sched.h deleted file mode 100644 index 2d305a2..0000000 --- a/lib/ultralib/include/PR/sched.h +++ /dev/null @@ -1,115 +0,0 @@ -/*==================================================================== - * sched.h - * - * Synopsis: - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/************************************************************************** - * - * $Revision: 1.7 $ - * $Date: 1997/02/11 08:32:02 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sched.h,v $ - * - **************************************************************************/ - -#ifndef __sched__ -#define __sched__ - -#include - -#define OS_SC_STACKSIZE 0x2000 - -#define OS_SC_RETRACE_MSG 1 -#define OS_SC_DONE_MSG 2 -#define OS_SC_RDP_DONE_MSG 3 -#define OS_SC_PRE_NMI_MSG 4 -#define OS_SC_LAST_MSG 4 /* this should have highest number */ -#define OS_SC_MAX_MESGS 8 - -typedef struct { - short type; - char misc[30]; -} OSScMsg; - -typedef struct OSScTask_s { - struct OSScTask_s *next; /* note: this must be first */ - u32 state; - u32 flags; - void *framebuffer; /* used by graphics tasks */ - - OSTask list; - OSMesgQueue *msgQ; - OSMesg msg; -#ifndef _FINALROM /* all #ifdef items should */ - OSTime startTime; /* remain at the end!!, or */ - OSTime totalTime; /* possible conflict if */ -#endif /* FINALROM library used with */ -} OSScTask; /* non FINALROM code */ - -/* - * OSScTask flags: - */ -#define OS_SC_NEEDS_RDP 0x0001 /* uses the RDP */ -#define OS_SC_NEEDS_RSP 0x0002 /* uses the RSP */ -#define OS_SC_DRAM_DLIST 0x0004 /* SP & DP communicate through DRAM */ -#define OS_SC_PARALLEL_TASK 0x0010 /* must be first gfx task on list */ -#define OS_SC_LAST_TASK 0x0020 /* last task in queue for frame */ -#define OS_SC_SWAPBUFFER 0x0040 /* swapbuffers when gfx task done */ - -#define OS_SC_RCP_MASK 0x0003 /* mask for needs bits */ -#define OS_SC_TYPE_MASK 0x0007 /* complete type mask */ -/* - * OSScClient: - * - * Data structure used by threads that wish to communicate to the - * scheduling thread - * - */ -typedef struct SCClient_s { - struct SCClient_s *next; /* next client in the list */ - OSMesgQueue *msgQ; /* where to send the frame msg */ -} OSScClient; - -typedef struct { - OSScMsg retraceMsg; - OSScMsg prenmiMsg; - OSMesgQueue interruptQ; - OSMesg intBuf[OS_SC_MAX_MESGS]; - OSMesgQueue cmdQ; - OSMesg cmdMsgBuf[OS_SC_MAX_MESGS]; - OSThread thread; - OSScClient *clientList; - OSScTask *audioListHead; - OSScTask *gfxListHead; - OSScTask *audioListTail; - OSScTask *gfxListTail; - OSScTask *curRSPTask; - OSScTask *curRDPTask; - u32 frameCount; - s32 doAudio; -} OSSched; - -void osCreateScheduler(OSSched *s, void *stack, OSPri priority, - u8 mode, u8 numFields); -void osScAddClient(OSSched *s, OSScClient *c, OSMesgQueue *msgQ); -void osScRemoveClient(OSSched *s, OSScClient *c); -OSMesgQueue *osScGetCmdQ(OSSched *s); - -#endif - diff --git a/lib/ultralib/include/PR/sp.h b/lib/ultralib/include/PR/sp.h deleted file mode 100644 index 8167ca2..0000000 --- a/lib/ultralib/include/PR/sp.h +++ /dev/null @@ -1,196 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * Sprite library include file - * - * $Revision: 1.16 $ - * $Date: 1998/04/17 05:03:46 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sp.h,v $ - * - **************************************************************************/ - -#ifndef _SP_H_ -#define _SP_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include - -struct bitmap { - s16 width; /* Size across to draw in texels */ - /* Done if width = 0 */ - - s16 width_img; /* Size across of bitmap in texels */ - /* Done if width = 0 */ - - s16 s; /* Horizontal offset into bitmap */ - /* if (s > width), then load only! */ - - s16 t; /* Vertical offset into base */ - - void *buf; /* Pointer to bitmap data */ - /* Don't re-load if new buf */ - /* is the same as the old one */ - /* Skip if NULL */ - - s16 actualHeight; /* True Height of this bitmap piece */ - - s16 LUToffset; /* LUT base index */ -}; - -typedef struct bitmap Bitmap; - -struct sprite { - s16 x,y; /* Target position */ - - s16 width, height; /* Target size */ - - f32 scalex, scaley; /* Texel to Pixel scale factor */ - - s16 expx, expy; /* Explosion spacing */ - - u16 attr; /* Attribute Flags */ - s16 zdepth; /* Z Depth */ - - u8 red; /* Red component */ - u8 green; /* Green component */ - u8 blue; /* Blue component */ - u8 alpha; /* Alpha component */ - - s16 startTLUT; /* Lookup Table Entry Starting index */ - s16 nTLUT; /* Total number of Lookup Table Entries */ - - int *LUT; /* Pointer to Lookup Table */ - - s16 istart; /* Starting bitmap index */ - s16 istep; /* Bitmaps index step (see SP_INCY) */ - /* if 0, then variable width bitmaps */ - - s16 nbitmaps; /* Total number of bitmaps */ - s16 ndisplist; /* Total number of display-list words */ - - s16 bmheight; /* Bitmap Texel height (Used) */ - s16 bmHreal; /* Bitmap Texel height (Real) */ - u8 bmfmt; /* Bitmap Format */ - u8 bmsiz; /* Bitmap Texel Size */ - - Bitmap *bitmap; /* Pointer to first bitmap */ - - Gfx *rsp_dl; /* Pointer to RSP display list */ - - Gfx *rsp_dl_next; /* Pointer to next RSP display entry */ - - s16 frac_s, /* Fractional Texture offsets */ - frac_t; /* These have 5 fraction bits */ -}; - -typedef struct sprite Sprite; - -/* - * DANGER! - * This is bad programming. Where the *heck* do these numbers come - * from? - * - * They are obviously 'maximums' from the sprite library, but since - * the sprite library is built on top of gbi.h, which includes macros - * that decode into multiple macros, etc., it is nearly impossible to - * know what these maximums should be. - * - * Worse, there are some gbi macros (texture alignment mostly) that - * decode into *many* macros, so if we choose that as a maximum, we - * are wasting TONS of space... - * - * These numbers work for "reasonable" sprite library usage, and - * there is an assert() in the library to detect when they aren't - * enough. (use the debug version) - */ -#define DL_BM_OVERHEAD (12) -#define DL_SPRITE_OVERHEAD (24) - -#define NUM_DL(nb) ((nb)*DL_BM_OVERHEAD +DL_SPRITE_OVERHEAD) - -/* - * Misc constants - */ - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -/* - * For sprite->attr - */ - -#define SP_TRANSPARENT 0x00000001 -#define SP_CUTOUT 0x00000002 -#define SP_HIDDEN 0x00000004 -#define SP_Z 0x00000008 -#define SP_SCALE 0x00000010 -#define SP_FASTCOPY 0x00000020 -#define SP_OVERLAP 0x00000040 -#define SP_TEXSHIFT 0x00000080 -#define SP_FRACPOS 0x00000100 -#define SP_TEXSHUF 0x00000200 -#define SP_EXTERN 0x00000400 - -/* - * Function wrapper - */ -#if defined(F3DEX_GBI_2) -#define spMove spX2Move -#define spSetZ spX2SetZ -#define spScissor spX2Scissor -#define spDraw spX2Draw -#define spInit spX2Init -#define spFinish spX2Finish -#elif defined(F3DEX_GBI) -#define spMove spXMove -#define spSetZ spXSetZ -#define spScissor spXScissor -#define spDraw spXDraw -#define spInit spXInit -#define spFinish spXFinish -#endif - -/* - * Function prototypes - */ - -void spSetAttribute (Sprite *sp, s32 attr); -void spClearAttribute (Sprite *sp, s32 attr); -void spMove (Sprite *sp, s32 x, s32 y); -void spScale (Sprite *sp, f32 sx, f32 sy); -void spSetZ (Sprite *sp, s32 z ); -void spColor (Sprite *sp, u8 red, u8 green, u8 blue, u8 alpha); -Gfx *spDraw (Sprite *sp); -void spInit( Gfx **glistp ); -void spScissor( s32 xmin, s32 xmax, s32 ymin, s32 ymax ); -void spFinish( Gfx **glistp ); - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* _SP_H_ */ diff --git a/lib/ultralib/include/PR/sptask.h b/lib/ultralib/include/PR/sptask.h deleted file mode 100644 index 960cab9..0000000 --- a/lib/ultralib/include/PR/sptask.h +++ /dev/null @@ -1,201 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.9 $ - * $Date: 1998/03/05 06:40:29 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sptask.h,v $ - * - **************************************************************************/ - -#ifndef _SPTASK_H_ -#define _SPTASK_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Task List Structure. - * - * Things an app might pass to the SP via the task list. - * Not every task ucode would need/use every field, but - * - * - type (audio, gfx, video, ...) - * - flags - * - wait for DP to drain before running new task - * - SEE BIT DEFINITIONS UNDER "Task Flags field" - * - pointer to boot ucode - * - size of boot ucode - * - pointer to ucode - * - size of ucode - * - pointer to initial DMEM data - * - size of initial DMEM data - * - pointer to DRAM stack - * - size of DRAM stack (max) - * - pointer to output buffer - * - pointer to store output buffer length - * - generic data pointer (for display list, etc.) - * - generic data length (for display list, etc.) - * - pointer to buffer where to store saved DMEM (in yield case) - * - size of buffer to store saved DMEM. - * - * IMPORTANT!!! Watch alignment issues. - * - * IMPORTANT!!! Watch data cache issues. The RCP may write data into the - * dram_stack, output_buff, output_buff_size, and the yield_data_ptr areas. - * These buffers should be cache aligned and use the entire line (16 bytes) to - * avoid corruption by writebacks by the CPU (cache tearing). - * - * IMPORTANT!!! all addresses are virtual addresses. Library does - * any necessary translation. - * - */ -typedef struct { - u32 type; - u32 flags; - - u64 *ucode_boot; - u32 ucode_boot_size; - - u64 *ucode; - u32 ucode_size; - - u64 *ucode_data; - u32 ucode_data_size; - - u64 *dram_stack; - u32 dram_stack_size; - - u64 *output_buff; - u64 *output_buff_size; - - u64 *data_ptr; - u32 data_size; - - u64 *yield_data_ptr; - u32 yield_data_size; - -} OSTask_t; - -typedef union { - OSTask_t t; - long long int force_structure_alignment; -} OSTask; - -typedef u32 OSYieldResult; - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_ASSEMBLY - -/* - * For the RSP ucode: - * offsets into the task structure - */ - -#include - -#endif - -/* - * Task Flags field - */ -#define OS_TASK_YIELDED 0x0001 -#define OS_TASK_DP_WAIT 0x0002 -#define OS_TASK_LOADABLE 0x0004 -#define OS_TASK_SP_ONLY 0x0008 -#define OS_TASK_USR0 0x0010 -#define OS_TASK_USR1 0x0020 -#define OS_TASK_USR2 0x0040 -#define OS_TASK_USR3 0x0080 - -/* - * Size of Yield buffer. The taskHdrPtr->t.yield_data_ptr must point to a - * buffer of this size. (The size is in bytes). ONLY If the task will NEVER - * yield it may be a null pointer. The buffer must be aligned to a 64 bit - * boundary. The taskHdrPtr->t.yield_data_ptr must be set to point to the - * buffer BEFORE the task is started. - */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)||defined(F3DEX_GBI_2)) -#define OS_YIELD_DATA_SIZE 0xc00 -#else -#define OS_YIELD_DATA_SIZE 0x900 -#endif -#define OS_YIELD_AUDIO_SIZE 0x400 - -/************************************************************************** - * - * Global definitions - * - */ - - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -/* - * this macro simulates atomic action. - */ -#define osSpTaskStart(tp) \ - { \ - osSpTaskLoad((tp)); \ - osSpTaskStartGo((tp)); \ - } - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* - * break this up into two steps for debugging. - */ -extern void osSpTaskLoad(OSTask *tp); -extern void osSpTaskStartGo(OSTask *tp); - -extern void osSpTaskYield(void); -extern OSYieldResult osSpTaskYielded(OSTask *tp); - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_SPTASK_H */ diff --git a/lib/ultralib/include/PR/ucode.h b/lib/ultralib/include/PR/ucode.h deleted file mode 100644 index e43f52a..0000000 --- a/lib/ultralib/include/PR/ucode.h +++ /dev/null @@ -1,192 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.15 $ - * $Date: 1998/03/31 07:58:57 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ucode.h,v $ - * - **************************************************************************/ - -#ifndef _UCODE_H_ -#define _UCODE_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -/* - * This is the recommended size of the SP DRAM stack area, used - * by the graphics ucode. This stack is used primarily for the - * matrix stack, so it needs to be AT LEAST (10 * 64bytes) in size. - */ -#define SP_DRAM_STACK_SIZE8 (1024) -#define SP_DRAM_STACK_SIZE64 (SP_DRAM_STACK_SIZE8 >> 3) - -/* - * This is the size of the IMEM, which is also the size of the - * graphics microcode. (other ucode might be less) - * This value is used in apps to tell the OS how much ucode to - * load. - */ -#define SP_UCODE_SIZE 4096 - -/* - * This is 1/2 the size of DMEM, which is the maximum amount of - * initialized DMEM data any of the ucode tasks need to start up. - * This value is dependent on all of the task ucodes, and is therefore - * fixed per release. - */ -#define SP_UCODE_DATA_SIZE 2048 - - -/************************************************************************** - * - * Extern variables - * - */ - -/* - * Symbols generated by "rsp2elf", included by "makerom" that indicate - * the location and size of the SP microcode objects. The ucode objects - * are loaded as part of the codesegment (arbitrary, could do other - * ways) - * - */ - -/* standard boot ucode: */ -extern long long int rspbootTextStart[], rspbootTextEnd[]; - -/* standard 3D ucode: */ -extern long long int gspFast3DTextStart[], gspFast3DTextEnd[]; -extern long long int gspFast3DDataStart[], gspFast3DDataEnd[]; - -/* 3D ucode with output to DRAM: */ -extern long long int gspFast3D_dramTextStart[], gspFast3D_dramTextEnd[]; -extern long long int gspFast3D_dramDataStart[], gspFast3D_dramDataEnd[]; - -/* 3D ucode with output through DRAM FIFO to RDP: */ -extern long long int gspFast3D_fifoTextStart[], gspFast3D_fifoTextEnd[]; -extern long long int gspFast3D_fifoDataStart[], gspFast3D_fifoDataEnd[]; - -/* 3D ucode without nearclip: */ -extern long long int gspF3DNoNTextStart[], gspF3DNoNTextEnd[]; -extern long long int gspF3DNoNDataStart[], gspF3DNoNDataEnd[]; - -/* 3D ucode without nearclip with output to DRAM: */ -extern long long int gspF3DNoN_dramTextStart[]; -extern long long int gspF3DNoN_dramTextEnd[]; -extern long long int gspF3DNoN_dramDataStart[]; -extern long long int gspF3DNoN_dramDataEnd[]; - -/* 3D ucode without nearclip with output through DRAM FIFO to RDP: */ -extern long long int gspF3DNoN_fifoTextStart[]; -extern long long int gspF3DNoN_fifoTextEnd[]; -extern long long int gspF3DNoN_fifoDataStart[]; -extern long long int gspF3DNoN_fifoDataEnd[]; - -/* 3D line ucode: */ -extern long long int gspLine3DTextStart[], gspLine3DTextEnd[]; -extern long long int gspLine3DDataStart[], gspLine3DDataEnd[]; - -/* 3D line ucode with output to DRAM: */ -extern long long int gspLine3D_dramTextStart[], gspLine3D_dramTextEnd[]; -extern long long int gspLine3D_dramDataStart[], gspLine3D_dramDataEnd[]; - -/* 3D line ucode with output through DRAM FIFO to RDP: */ -extern long long int gspLine3D_fifoTextStart[], gspLine3D_fifoTextEnd[]; -extern long long int gspLine3D_fifoDataStart[], gspLine3D_fifoDataEnd[]; - -/* 2D sprite ucode: */ -extern long long int gspSprite2DTextStart[], gspSprite2DTextEnd[]; -extern long long int gspSprite2DDataStart[], gspSprite2DDataEnd[]; - -/* 2D sprite ucode with output to DRAM: */ -extern long long int gspSprite2D_dramTextStart[], gspSprite2D_dramTextEnd[]; -extern long long int gspSprite2D_dramDataStart[], gspSprite2D_dramDataEnd[]; - -/* 2D sprite ucode with output through DRAM FIFO to RDP: */ -extern long long int gspSprite2D_fifoTextStart[], gspSprite2D_fifoTextEnd[]; -extern long long int gspSprite2D_fifoDataStart[], gspSprite2D_fifoDataEnd[]; - -/* basic audio ucode: */ -extern long long int aspMainTextStart[], aspMainTextEnd[]; -extern long long int aspMainDataStart[], aspMainDataEnd[]; - -/*========== F3DEX/F3DLX/F3DLP/L3DEX ==========*/ -/* FIFO version only */ -extern long long int gspF3DEX_fifoTextStart[], gspF3DEX_fifoTextEnd[]; -extern long long int gspF3DEX_fifoDataStart[], gspF3DEX_fifoDataEnd[]; -extern long long int gspF3DEX_NoN_fifoTextStart[], gspF3DEX_NoN_fifoTextEnd[]; -extern long long int gspF3DEX_NoN_fifoDataStart[], gspF3DEX_NoN_fifoDataEnd[]; - -extern long long int gspF3DLX_fifoTextStart[], gspF3DLX_fifoTextEnd[]; -extern long long int gspF3DLX_fifoDataStart[], gspF3DLX_fifoDataEnd[]; -extern long long int gspF3DLX_NoN_fifoTextStart[], gspF3DLX_NoN_fifoTextEnd[]; -extern long long int gspF3DLX_NoN_fifoDataStart[], gspF3DLX_NoN_fifoDataEnd[]; -extern long long int gspF3DLX_Rej_fifoTextStart[], gspF3DLX_Rej_fifoTextEnd[]; -extern long long int gspF3DLX_Rej_fifoDataStart[], gspF3DLX_Rej_fifoDataEnd[]; - -extern long long int gspF3DLP_Rej_fifoTextStart[], gspF3DLP_Rej_fifoTextEnd[]; -extern long long int gspF3DLP_Rej_fifoDataStart[], gspF3DLP_Rej_fifoDataEnd[]; -extern long long int gspL3DEX_fifoTextStart[], gspL3DEX_fifoTextEnd[]; -extern long long int gspL3DEX_fifoDataStart[], gspL3DEX_fifoDataEnd[]; - -/*========== F3DEX2/F3DLX2/F3DLP2/L3DEX2 ==========*/ -/* FIFO version */ -extern long long int gspF3DEX2_fifoTextStart[], gspF3DEX2_fifoTextEnd[]; -extern long long int gspF3DEX2_fifoDataStart[], gspF3DEX2_fifoDataEnd[]; -extern long long int gspF3DEX2_NoN_fifoTextStart[],gspF3DEX2_NoN_fifoTextEnd[]; -extern long long int gspF3DEX2_NoN_fifoDataStart[],gspF3DEX2_NoN_fifoDataEnd[]; -extern long long int gspF3DEX2_Rej_fifoTextStart[],gspF3DEX2_Rej_fifoTextEnd[]; -extern long long int gspF3DEX2_Rej_fifoDataStart[],gspF3DEX2_Rej_fifoDataEnd[]; -extern long long int gspF3DLX2_Rej_fifoTextStart[],gspF3DLX2_Rej_fifoTextEnd[]; -extern long long int gspF3DLX2_Rej_fifoDataStart[],gspF3DLX2_Rej_fifoDataEnd[]; -extern long long int gspL3DEX2_fifoTextStart[], gspL3DEX2_fifoTextEnd[]; -extern long long int gspL3DEX2_fifoDataStart[], gspL3DEX2_fifoDataEnd[]; - -/* XBUS version */ -extern long long int gspF3DEX2_xbusTextStart[], gspF3DEX2_xbusTextEnd[]; -extern long long int gspF3DEX2_xbusDataStart[], gspF3DEX2_xbusDataEnd[]; -extern long long int gspF3DEX2_NoN_xbusTextStart[],gspF3DEX2_NoN_xbusTextEnd[]; -extern long long int gspF3DEX2_NoN_xbusDataStart[],gspF3DEX2_NoN_xbusDataEnd[]; -extern long long int gspF3DEX2_Rej_xbusTextStart[],gspF3DEX2_Rej_xbusTextEnd[]; -extern long long int gspF3DEX2_Rej_xbusDataStart[],gspF3DEX2_Rej_xbusDataEnd[]; -extern long long int gspF3DLX2_Rej_xbusTextStart[],gspF3DLX2_Rej_xbusTextEnd[]; -extern long long int gspF3DLX2_Rej_xbusDataStart[],gspF3DLX2_Rej_xbusDataEnd[]; -extern long long int gspL3DEX2_xbusTextStart[], gspL3DEX2_xbusTextEnd[]; -extern long long int gspL3DEX2_xbusDataStart[], gspL3DEX2_xbusDataEnd[]; - -/************************************************************************** - * - * Function prototypes - * - */ - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_UCODE_H */ diff --git a/lib/ultralib/include/PR/ultraerror.h b/lib/ultralib/include/PR/ultraerror.h deleted file mode 100644 index ebaf59a..0000000 --- a/lib/ultralib/include/PR/ultraerror.h +++ /dev/null @@ -1,165 +0,0 @@ -/*==================================================================== - * ultraerror.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/************************************************************************** - * - * $Revision: 1.27 $ - * $Date: 1999/07/14 02:44:00 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultraerror.h,v $ - * - **************************************************************************/ - -#ifndef __ULTRAERROR_H__ -#define __ULTRAERROR_H__ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include "ultratypes.h" - -#define OS_ERROR_FMT "/usr/lib/PR/error.fmt" -#define OS_ERROR_MAGIC 0x6b617479 - -/* OS error codes */ - -#define ERR_OSCREATETHREAD_SP 1 -#define ERR_OSCREATETHREAD_PRI 2 -#define ERR_OSSTARTTHREAD 3 -#define ERR_OSSETTHREADPRI 4 -#define ERR_OSCREATEMESGQUEUE 5 -#define ERR_OSSENDMESG 6 -#define ERR_OSJAMMESG 7 -#define ERR_OSRECVMESG 8 -#define ERR_OSSETEVENTMESG 9 -#define ERR_OSMAPTLB_INDEX 10 -#define ERR_OSMAPTLB_ASID 11 -#define ERR_OSUNMAPTLB 12 -#define ERR_OSSETTLBASID 13 -#define ERR_OSAISETFREQUENCY 14 -#define ERR_OSAISETNEXTBUFFER_ADDR 15 -#define ERR_OSAISETNEXTBUFFER_SIZE 16 -#define ERR_OSDPSETNEXTBUFFER_ADDR 17 -#define ERR_OSDPSETNEXTBUFFER_SIZE 18 -#define ERR_OSPIRAWREADIO 19 -#define ERR_OSPIRAWWRITEIO 20 -#define ERR_OSPIRAWSTARTDMA_DIR 21 -#define ERR_OSPIRAWSTARTDMA_DEVADDR 22 -#define ERR_OSPIRAWSTARTDMA_ADDR 23 -#define ERR_OSPIRAWSTARTDMA_SIZE 24 -#define ERR_OSPIRAWSTARTDMA_RANGE 25 -#define ERR_OSPIREADIO 26 -#define ERR_OSPIWRITEIO 27 -#define ERR_OSPISTARTDMA_PIMGR 28 -#define ERR_OSPISTARTDMA_PRI 29 -#define ERR_OSPISTARTDMA_DIR 30 -#define ERR_OSPISTARTDMA_DEVADDR 31 -#define ERR_OSPISTARTDMA_ADDR 32 -#define ERR_OSPISTARTDMA_SIZE 33 -#define ERR_OSPISTARTDMA_RANGE 34 -#define ERR_OSCREATEPIMANAGER 35 -#define ERR_OSVIGETCURRENTMODE 36 -#define ERR_OSVIGETCURRENTFRAMEBUFFER 37 -#define ERR_OSVIGETNEXTFRAMEBUFFER 38 -#define ERR_OSVISETXSCALE_VALUE 39 -#define ERR_OSVISETXSCALE_VIMGR 40 -#define ERR_OSVISETYSCALE_VALUE 41 -#define ERR_OSVISETYSCALE_VIMGR 42 -#define ERR_OSVISETSPECIAL_VALUE 43 -#define ERR_OSVISETSPECIAL_VIMGR 44 -#define ERR_OSVISETMODE 45 -#define ERR_OSVISETEVENT 46 -#define ERR_OSVISWAPBUFFER_ADDR 47 -#define ERR_OSVISWAPBUFFER_VIMGR 48 -#define ERR_OSCREATEVIMANAGER 49 -#define ERR_OSCREATEREGION_ALIGN 50 -#define ERR_OSCREATEREGION_SIZE 51 -#define ERR_OSMALLOC 52 -#define ERR_OSFREE_REGION 53 -#define ERR_OSFREE_ADDR 54 -#define ERR_OSGETREGIONBUFCOUNT 55 -#define ERR_OSGETREGIONBUFSIZE 56 -#define ERR_OSSPTASKLOAD_DRAM 57 -#define ERR_OSSPTASKLOAD_OUT 58 -#define ERR_OSSPTASKLOAD_OUTSIZE 59 -#define ERR_OSSPTASKLOAD_YIELD 60 -#define ERR_OSPROFILEINIT_STR 61 -#define ERR_OSPROFILEINIT_CNT 62 -#define ERR_OSPROFILEINIT_ALN 63 -#define ERR_OSPROFILEINIT_ORD 64 -#define ERR_OSPROFILEINIT_SIZ 65 -#define ERR_OSPROFILESTART_TIME 66 -#define ERR_OSPROFILESTART_FLAG 67 -#define ERR_OSPROFILESTOP_FLAG 68 -#define ERR_OSPROFILESTOP_TIMER 69 -#define ERR_OSREADHOST_ADDR 70 -#define ERR_OSREADHOST_SIZE 71 -#define ERR_OSWRITEHOST_ADDR 72 -#define ERR_OSWRITEHOST_SIZE 73 -#define ERR_OSGETTIME 74 -#define ERR_OSSETTIME 75 -#define ERR_OSSETTIMER 76 -#define ERR_OSSTOPTIMER 77 -#define ERR_ALSEQP_NO_SOUND 100 -#define ERR_ALSEQP_NO_VOICE 101 -#define ERR_ALSEQP_MAP_VOICE 102 -#define ERR_ALSEQP_OFF_VOICE 103 -#define ERR_ALSEQP_POLY_VOICE 104 -#define ERR_ALSNDP_NO_VOICE 105 -#define ERR_ALSYN_NO_UPDATE 106 -#define ERR_ALSNDPDEALLOCATE 107 -#define ERR_ALSNDPDELETE 108 -#define ERR_ALSNDPPLAY 109 -#define ERR_ALSNDPSETSOUND 110 -#define ERR_ALSNDPSETPRIORITY 111 -#define ERR_ALSNDPSETPAR 112 -#define ERR_ALBNKFNEW 113 -#define ERR_ALSEQNOTMIDI 114 -#define ERR_ALSEQNOTMIDI0 115 -#define ERR_ALSEQNUMTRACKS 116 -#define ERR_ALSEQTIME 117 -#define ERR_ALSEQTRACKHDR 118 -#define ERR_ALSEQSYSEX 119 -#define ERR_ALSEQMETA 120 -#define ERR_ALSEQPINVALIDPROG 121 -#define ERR_ALSEQPUNKNOWNMIDI 122 -#define ERR_ALSEQPUNMAP 123 -#define ERR_ALEVENTNOFREE 124 -#define ERR_ALHEAPNOFREE 125 -#define ERR_ALHEAPCORRUPT 126 -#define ERR_ALHEAPFIRSTBLOCK 127 -#define ERR_ALCSEQZEROSTATUS 128 -#define ERR_ALCSEQZEROVEL 129 -#define ERR_ALCSPVNOTFREE 130 -#define ERR_ALSEQOVERRUN 131 -#define ERR_OSAISETNEXTBUFFER_ENDADDR 132 -#define ERR_ALMODDELAYOVERFLOW 133 - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) -typedef void (*OSErrorHandler)(s16, s16, ...); - -OSErrorHandler osSetErrorHandler(OSErrorHandler); -#endif - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* __ULTRAERROR_H__ */ diff --git a/lib/ultralib/include/PR/ultralog.h b/lib/ultralib/include/PR/ultralog.h deleted file mode 100644 index 48b84b9..0000000 --- a/lib/ultralib/include/PR/ultralog.h +++ /dev/null @@ -1,74 +0,0 @@ -/*==================================================================== - * ultralog.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/************************************************************************** - * - * $Revision: 1.6 $ - * $Date: 1997/02/11 08:39:05 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultralog.h,v $ - * - **************************************************************************/ - -#ifndef __log__ -#define __log__ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#define OS_LOG_MAX_ARGS 16 -#define OS_LOG_MAGIC 0x20736a73 -#define OS_LOG_FLOAT(x) (*(int *) &(x)) -#define OS_LOG_VERSION 1 - -typedef struct { - u32 magic; /* log identifier */ - u32 len; /* length of log data + log structure */ - u32 *base; /* starting addr array */ - s32 startCount; /* read offset from dataBase */ - s32 writeOffset; /* write offset from dataBase */ -} OSLog; - -typedef struct { - u32 magic; - u32 timeStamp; - u16 argCount; - u16 eventID; -} OSLogItem; - -typedef struct { - u32 magic; /* log identifier */ - u32 version; /* 1 */ -} OSLogFileHdr; - -void osCreateLog(OSLog *log, u32 *base, s32 len); -void osLogEvent(OSLog *log, s16 code, s16 numArgs, ...); -void osFlushLog(OSLog *log); -u32 osLogFloat(f32); - -extern void osDelay(int count); - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif diff --git a/lib/ultralib/include/PR/ultratypes.h b/lib/ultralib/include/PR/ultratypes.h deleted file mode 100644 index 235cc73..0000000 --- a/lib/ultralib/include/PR/ultratypes.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _ULTRATYPES_H_ -#define _ULTRATYPES_H_ - - -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - - -/************************************************************************* - * - * File: ultratypes.h - * - * This file contains various types used in Ultra64 interfaces. - * - * $Revision: 1.6 $ - * $Date: 1997/12/17 04:02:06 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultratypes.h,v $ - * - **************************************************************************/ - - - -/********************************************************************** - * General data types for R4300 - */ -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -typedef unsigned char u8; /* unsigned 8-bit */ -typedef unsigned short u16; /* unsigned 16-bit */ -typedef unsigned long u32; /* unsigned 32-bit */ -typedef unsigned long long u64; /* unsigned 64-bit */ - -typedef signed char s8; /* signed 8-bit */ -typedef short s16; /* signed 16-bit */ -typedef long s32; /* signed 32-bit */ -typedef long long s64; /* signed 64-bit */ - -typedef volatile unsigned char vu8; /* unsigned 8-bit */ -typedef volatile unsigned short vu16; /* unsigned 16-bit */ -typedef volatile unsigned long vu32; /* unsigned 32-bit */ -typedef volatile unsigned long long vu64; /* unsigned 64-bit */ - -typedef volatile signed char vs8; /* signed 8-bit */ -typedef volatile short vs16; /* signed 16-bit */ -typedef volatile long vs32; /* signed 32-bit */ -typedef volatile long long vs64; /* signed 64-bit */ - -typedef float f32; /* single prec floating point */ -typedef double f64; /* double prec floating point */ - -#if !defined(_SIZE_T) && !defined(_SIZE_T_) && !defined(_SIZE_T_DEF) -#define _SIZE_T -#define _SIZE_T_DEF /* exeGCC size_t define label */ -#if (_MIPS_SZLONG == 32) -typedef unsigned int size_t; -#endif -#if (_MIPS_SZLONG == 64) -typedef unsigned long size_t; -#endif -#endif - -#endif /* _LANGUAGE_C */ - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef NULL -#define NULL 0 -#endif - -#endif /* _ULTRATYPES_H_ */ diff --git a/lib/ultralib/include/asm.h b/lib/ultralib/include/asm.h deleted file mode 100644 index 1de9f0a..0000000 --- a/lib/ultralib/include/asm.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/lib/ultralib/include/assert.h b/lib/ultralib/include/assert.h deleted file mode 100644 index bfbf255..0000000 --- a/lib/ultralib/include/assert.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __ASSERT_H__ -#define __ASSERT_H__ - -#ifdef NDEBUG -#undef assert -#define assert(EX) ((void)0) -#else -extern void __assert(const char *, const char *, int); -#define assert(EX) ((EX)?((void)0):__assert("EX", __FILE__, __LINE__)) -#endif /* NDEBUG */ - -#endif /* !__ASSERT_H__ */ diff --git a/lib/ultralib/include/dbgdefs.h b/lib/ultralib/include/dbgdefs.h deleted file mode 100644 index f7ead71..0000000 --- a/lib/ultralib/include/dbgdefs.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _DBGDEFS_H__ -#define _DBGDEFS_H__ - -typedef int TVid; -typedef unsigned short TVushort; -typedef char TVuchar; - -#endif diff --git a/lib/ultralib/include/dbgproto.h b/lib/ultralib/include/dbgproto.h deleted file mode 100644 index 2eabf9a..0000000 --- a/lib/ultralib/include/dbgproto.h +++ /dev/null @@ -1,402 +0,0 @@ -#ifndef _DBGPROTO_H__ -#define _DBGPROTO_H__ - -#include "dbgdefs.h" - -#define KK_REV 2 - -#define KK_CODE_THREAD_STATUS 4 - -#define KK_TYPE_REQUEST 0 -#define KK_TYPE_REPLY 1 -#define KK_TYPE_EXCEPTION 2 -#define KK_TYPE_THREAD_EXIT 3 -#define KK_TYPE_PROCESS_EXIT 4 -#define KK_TYPE_CONSOLE 5 - -#define TV_ERROR_NO_ERROR 0 -#define TV_ERROR_ILLEGAL_CALL -1 -#define TV_ERROR_INVALID_ID -2 -#define TV_ERROR_INVALID_TYPE -3 -#define TV_ERROR_OPERATIONS_PROTECTED -4 -#define TV_ERROR_INVALID_ADDRESS -5 -#define TV_ERROR_INVALID_PRIORITY -6 -#define TV_ERROR_INVALID_FLAGS -7 -#define TV_ERROR_INVALID_CAPABILITY -8 -#define TV_ERROR_NO_HANDLER -9 -#define TV_ERROR_NO_MORE_IDS -10 -#define TV_ERROR_NO_MORE_MESSAGES -11 -#define TV_ERROR_NO_MORE_PROCESSES -12 -#define TV_ERROR_NO_MORE_THREADS -13 -#define TV_ERROR_NO_MORE_REGIONS -14 -#define TV_ERROR_NO_MORE_TIMERS -15 -#define TV_ERROR_NO_MORE_LOCKS -16 -#define TV_ERROR_NO_MORE_QUEUES -17 -#define TV_ERROR_NO_MORE_SETS -18 -#define TV_ERROR_NO_MORE_MEMORY -19 -#define TV_ERROR_NOT_LOCKED -20 - -typedef struct __KKTimeStruct { - long seconds; - long nanoseconds; -} KKTimeStruct; - -typedef struct __KKObjsStruct { - TVushort number; - TVid objects[1]; -} KKObjs; - -typedef struct __KKFaultInfoStruct { - unsigned int addr; - short major; - short minor; -} KKFaultInfo; - -typedef struct __KKThreadStatusStruct { - int flags; - short why; - short what; - TVid tid; - TVid pid; - unsigned int instr; - KKFaultInfo info; - int priority; - int start; - int rv; - unsigned int args[6]; -} KKThreadStatus; - -#define KK_RUN_SSTEP (1 << 0) -#define KK_RUN_SETPC (1 << 1) - -typedef struct __KKRunStruct { - int flags; - unsigned int vaddr; -} KKRun; - -typedef struct __KKFaultStruct { - short majorMask; - short minorMask; -} KKFault; - -typedef struct __KKRegionStruct { - unsigned int vaddr; - unsigned int size; - short flags; - unsigned int paddr; -} KKRegion; - -typedef struct __KKGregSetStruct { - unsigned int gregs[37]; -} KKGregSet; - -typedef struct __KKFPregSetStruct { - union { - double dregs[16]; - float fregs[32]; - unsigned int regs[32]; - } fpregs; - unsigned int fpcsr; - unsigned int fppad; -} KKFPregSet; - -typedef struct __KKRegisterContextStruct { - KKGregSet gregs; - KKFPregSet fpregs; -} KKRegisterContext; - -typedef struct __KKCpScalarSetStruct { - unsigned int sregs[40]; -} KKCpScalarRegSet; - -typedef struct __KKCpVectorSetStruct { - unsigned int vregs[128]; -} KKCpVectorRegSet; - -typedef struct __KKCpRegisterContextStruct { - KKCpScalarRegSet sregs; - KKCpVectorRegSet vregs; -} KKCpRegisterContext; - -typedef struct __KKUsageStruct { - KKTimeStruct tstamp; - KKTimeStruct created; - KKTimeStruct states[10]; -} KKUsage; - -typedef struct __KKLogEventSetStruct { - int from; - int to; -} KKLogEventSet; - -typedef struct __KKLogStatusStruct { - int bufferType; - int bufferSize; - int dataSize; - int logState; - int flushLimit; -} KKLogStatus; - -typedef struct __KKProcUsageStruct { - TVid pid; - KKTimeStruct states[10]; -} KKProcUsage; - -typedef struct __KKHeaderStruct { - int length; - char code; - char type; - short error; - char rev; - char method; - short notused2; -} KKHeader; - -typedef struct __KKGetFrameRequestStruct { - KKHeader header; - int height; - int width; - int which; -} KKGetFrameRequest; - -typedef struct __KKLoadExecutableRequestStruct { - KKHeader header; - char str[1]; -} KKLoadExecutableRequest; - -typedef struct __KKObjectRequestStruct { - KKHeader header; - TVid object; -} KKObjectRequest; - -typedef struct __KKRunThreadRequestStruct { - KKHeader header; - TVid tid; - KKRun actions; -} KKRunThreadRequest; - -typedef struct __KKFaultRequestStruct { - KKHeader header; - TVid tid; - KKFault fault; - TVuchar stopAllThreads; -} KKFaultRequest; - -typedef struct __KKGRegsetRequestStruct { - KKHeader header; - TVid tid; - KKGregSet registers; -} KKGRegsetRequest; - -typedef struct __KKFPRegsetRequestStruct { - KKHeader header; - TVid tid; - KKFPregSet registers; -} KKFPRegsetRequest; - -typedef struct __KKCpScalarRegsetRequestStruct { - KKHeader header; - TVid tid; - KKCpScalarRegSet registers; -} KKCpScalarRegsetRequest; - -typedef struct __KKCpVectorRegsetRequestStruct { - KKHeader header; - TVid tid; - KKCpVectorRegSet registers; -} KKCpVectorRegsetRequest; - -typedef struct __KKReadRequestStruct { - KKHeader header; - TVid object; - unsigned int addr; - unsigned int nbytes; -} KKReadRequest; - -typedef struct __KKWriteHeaderStruct { - KKHeader header; - TVid object; - unsigned int addr; - unsigned int nbytes; -} KKWriteHeader; - -typedef struct __KKWriteRequestStruct { - KKWriteHeader writeHeader; - char buffer[1]; -} KKWriteRequest; - -typedef struct __KKSetBkptRequestStruct { - KKHeader header; - TVid object; - unsigned int addr; -} KKSetBkptRequest; - -typedef struct __KKClrBkptRequestStruct { - KKHeader header; - TVid object; - TVid bp; -} KKClrBkptRequest; - -typedef struct __KKWatchRequestStruct { - KKHeader header; - TVid object; - unsigned int number; - KKRegion wp[1]; -} KKWatchRequest; - -typedef struct __KKSetCommRequestStruct { - KKHeader header; - unsigned int how; - unsigned int addr; -} KKSetCommRequest; - -typedef struct __KKSysCallSetStruct { - unsigned int word[8]; -} KKSysCallSet; - -typedef struct __KKSysCallRequestStruct { - KKHeader header; - TVid pid; - KKSysCallSet syscallset; -} KKSysCallRequest; - -typedef struct __KKLogEventRequestStruct { - KKHeader header; - unsigned int numSet; - KKLogEventSet set[1]; -} KKLogEventRequest; - -typedef struct __KKNewLogRequestStruct { - KKHeader header; - char str[1]; -} KKNewLogRequest; - -typedef struct __KKRemoteRequestStruct { - KKHeader header; - int len; - char buf[16]; -} KKRemoteRequest; - -typedef struct __KKFlushLogRequestStruct { - KKHeader header; - int no_block; -} KKFlushLogRequest; - -typedef struct __KKLogControlRequestStruct { - KKHeader header; - int command; - int arg; -} KKLogControlRequest; - -typedef struct __KKSetTrptRequestStruct { - KKSetBkptRequest bpRequest; - unsigned short code; -} KKSetTrptRequest; - -typedef KKClrBkptRequest KKClrTrptRequest; - -typedef struct __KKObjectEventStruct { - KKHeader header; - TVid object; -} KKObjectEvent; - -typedef struct __KKObjsEventStruct { - KKHeader header; - TVid object; - KKObjs objs; -} KKObjsEvent; - -typedef struct __KKBufferEventStruct { - KKHeader header; - TVid object; - char buffer[1]; -} KKBufferEvent; - -typedef struct __KKStatusEventStruct { - KKHeader header; - KKThreadStatus status; -} KKStatusEvent; - -typedef struct __KKFaultEventStruct { - KKHeader header; - TVid tid; - KKFault fault; - TVuchar stopAllThreads; -} KKFaultEvent; - -typedef struct __KKNumberEventStruct { - KKHeader header; - TVid object; - unsigned int number; -} KKNumberEvent; - -typedef struct __KKRegionEventStruct { - KKHeader header; - TVid object; - unsigned int number; - KKRegion regions[1]; -} KKRegionEvent; - -typedef struct __KKGregEventStruct { - KKHeader header; - TVid tid; - KKGregSet registers; -} KKGregEvent; - -typedef struct __KKFPregEventStruct { - KKHeader header; - TVid tid; - KKFPregSet registers; -} KKFPregEvent; - -typedef struct __KKCpSregEventStruct { - KKHeader header; - TVid tid; - KKCpScalarRegSet registers; -} KKCpSregEvent; - -typedef struct __KKCpVregEventStruct { - KKHeader header; - TVid tid; - KKCpVectorRegSet registers; -} KKCpVregEvent; - -typedef struct __KKBkptEventStruct { - KKHeader header; - TVid object; - TVid bp; - unsigned int instruction; -} KKBkptEvent; - -typedef struct __KKUsageEventStruct { - KKHeader header; - TVid tid; - KKUsage usage; -} KKUsageEvent; - -typedef struct __KKFlushEventStruct { - KKHeader header; - int bufferType; - char buffer[1]; -} KKFlushEvent; - -typedef struct __KKLogStatusEventStruct { - KKHeader header; - KKLogStatus status; -} KKLogStatusEvent; - -typedef struct __KKSysUsageEventStruct { - KKHeader header; - KKTimeStruct tstamp; - int numProc; - KKProcUsage usage[1]; -} KKSysUsageEvent; - -typedef struct __KKStringEventStruct { - KKHeader header; - char str[1]; -} KKStringEvent; - -typedef KKSysCallRequest KKSysCallEvent; - -#endif diff --git a/lib/ultralib/include/fpregdef.h b/lib/ultralib/include/fpregdef.h deleted file mode 100644 index e69de29..0000000 diff --git a/lib/ultralib/include/gcc/math.h b/lib/ultralib/include/gcc/math.h deleted file mode 100644 index 3e93ceb..0000000 --- a/lib/ultralib/include/gcc/math.h +++ /dev/null @@ -1 +0,0 @@ -// Nothing needed here diff --git a/lib/ultralib/include/gcc/memory.h b/lib/ultralib/include/gcc/memory.h deleted file mode 100644 index edfff5e..0000000 --- a/lib/ultralib/include/gcc/memory.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _MEMORY_H -#define _MEMORY_H -/* - memory.h -*/ - -#ifndef _SIZE_T_DEF -#define _SIZE_T_DEF -typedef unsigned size_t; -#endif - -void *memccpy(void *,void *,int,size_t); -void *memchr(void *,int,size_t); -int memcmp(const void *,const void *,size_t); -void *memcpy(void *,const void *,size_t); -int memicmp(void *,void *,size_t); -void *memmove(void *,void *,size_t); -void *memset(void *,int,size_t); - -void movmem(void *,void *,unsigned); -void setmem(void *,unsigned,int); - -#endif diff --git a/lib/ultralib/include/gcc/sgidefs.h b/lib/ultralib/include/gcc/sgidefs.h deleted file mode 100644 index 56567e8..0000000 --- a/lib/ultralib/include/gcc/sgidefs.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ralf Baechle . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _SGIDEFS_H -#define _SGIDEFS_H 1 - -/* - * Definitions for the ISA level - */ -#define _MIPS_ISA_MIPS1 1 -#define _MIPS_ISA_MIPS2 2 -#define _MIPS_ISA_MIPS3 3 -#define _MIPS_ISA_MIPS4 4 -#define _MIPS_ISA_MIPS5 5 - -/* - * Subprogram calling convention - * - * At the moment only _MIPS_SIM_ABI32 is in use. This will change rsn. - * Until GCC 2.8.0 is released don't rely on this definitions because the - * 64bit code is essentially using the 32bit interface model just with - * 64bit registers. - */ -#define _MIPS_SIM_ABI32 1 -#define _MIPS_SIM_NABI32 2 -#define _MIPS_SIM_ABI64 3 - -#endif /* sgidefs.h */ diff --git a/lib/ultralib/include/gcc/stdarg.h b/lib/ultralib/include/gcc/stdarg.h deleted file mode 100644 index af337f6..0000000 --- a/lib/ultralib/include/gcc/stdarg.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H -/* ---------------------------------------- */ -/* VARARGS for MIPS/GNU CC */ -/* */ -/* */ -/* */ -/* */ -/* ---------------------------------------- */ - -/* These macros implement varargs for GNU C--either traditional or ANSU. */ - -/* Define __gnuc_va_list. */ - -#ifndef __GNUC_VA_LIST -#define __GNUC_VA_LIST -typedef char * __gnuc_va_list; -#endif /* not __GNUC_VA_LIST */ - -/* If this is for internal libc use, don't define anything but - __gnuc_va_list. */ -#if defined (_STDARG_H) || defined (_VARARGS_H) - -/* In GCC version 2, we want an ellipsis at the end of the declaration - of the argument list. GCC version 1 can't parse it. */ - -#if __GNUC__ > 1 -#define __va_ellipsis ... -#else -#define __va_ellipsis -#endif - -#if __mips>=3 -#define __va_rounded_size(__TYPE) \ - (((sizeof (__TYPE) + 8 - 1) / 8) * 8) -#else -#define __va_rounded_size(__TYPE) \ - (((sizeof (__TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) -#endif - -/* Get definitions for _MIPS_SIM_ABI64 etc. */ -#ifdef _MIPS_SIM -#include -#endif - -#ifdef _STDARG_H -#if defined(_MIPS_SIM) && (_MIPS_SIM == _MIPS_SIM_ABI64) -#define va_start(__AP, __LASTARG) \ - (__AP = __builtin_next_arg (__LASTARG) - 64 \ - + (__builtin_args_info (2) > 8 ? 64 : __builtin_args_info(2) * 8)) -#else -#define va_start(__AP, __LASTARG) \ - (__AP = (__gnuc_va_list) __builtin_next_arg (__LASTARG)) -#endif - -#else -#define va_alist __builtin_va_alist -#if __mips>=3 -/* This assumes that `long long int' is always a 64 bit type. */ -#define va_dcl long long int __builtin_va_alist; __va_ellipsis -#else -#define va_dcl int __builtin_va_alist; __va_ellipsis -#endif -/* Need alternate code for _MIPS_SIM_ABI64, but don't use that symbol - because it may not be defined. */ -#if defined(_MIPS_SIM) && (_MIPS_SIM == _MIPS_SIM_ABI64) -#define va_start(__AP) \ - (__AP = __builtin_next_arg () - 64 \ - + (__builtin_args_info (2) > 8 ? 64 : __builtin_args_info(2) * 8)) -#else -#define va_start(__AP) __AP = (char *) &__builtin_va_alist -#endif -#endif - -#ifndef va_end -void va_end (__gnuc_va_list); /* Defined in libgcc.a */ -#endif -#define va_end(__AP) ((void)0) - -/* We cast to void * and then to TYPE * because this avoids - a warning about increasing the alignment requirement. */ -/* The __mips>=3 cases are reversed from the 32 bit cases, because the standard - 32 bit calling convention left-aligns all parameters smaller than a word, - whereas the __mips>=3 calling convention does not (and hence they are - right aligned). */ -#if __mips>=3 -#ifdef __MIPSEB__ -#define va_arg(__AP, __type) \ - ((__type *) (void *) (__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \ - + __va_rounded_size (__type))))[-1] -#else -#define va_arg(__AP, __type) \ - ((__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \ - + __va_rounded_size (__type))), \ - *(__type *) (void *) (__AP - __va_rounded_size (__type))) -#endif - -#else /* not __mips>=3 */ - -#ifdef __MIPSEB__ -/* For big-endian machines. */ -#define va_arg(__AP, __type) \ - ((__AP = (char *) ((__alignof__ (__type) > 4 \ - ? ((int)__AP + 8 - 1) & -8 \ - : ((int)__AP + 4 - 1) & -4) \ - + __va_rounded_size (__type))), \ - *(__type *) (void *) (__AP - __va_rounded_size (__type))) -#else -/* For little-endian machines. */ -#define va_arg(__AP, __type) \ - ((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4 \ - ? ((int)__AP + 8 - 1) & -8 \ - : ((int)__AP + 4 - 1) & -4) \ - + __va_rounded_size(__type))))[-1] -#endif -#endif - -typedef __gnuc_va_list va_list; - -#endif /* defined (_STDARG_H) || defined (_VARARGS_H) */ -#endif diff --git a/lib/ultralib/include/gcc/stdio.h b/lib/ultralib/include/gcc/stdio.h deleted file mode 100644 index 3e93ceb..0000000 --- a/lib/ultralib/include/gcc/stdio.h +++ /dev/null @@ -1 +0,0 @@ -// Nothing needed here diff --git a/lib/ultralib/include/gcc/stdlib.h b/lib/ultralib/include/gcc/stdlib.h deleted file mode 100644 index 98f8a2e..0000000 --- a/lib/ultralib/include/gcc/stdlib.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _STDLIB_H -#define _STDLIB_H -/* - stdlib.h -*/ - -#ifndef _SIZE_T_DEF -#define _SIZE_T_DEF -typedef unsigned size_t; -#endif - -#ifndef _DIV_T_DEF -#define _DIV_T_DEF -typedef struct DIV_T { - int quot; - int rem; -} div_t; -#endif - -#ifndef _LDIV_T_DEF -#define _LDIV_T_DEF -typedef struct LDIV_T { - long quot; - long rem; -} ldiv_t; -#endif - -#ifndef _LLDIV_T_DEF -#define _LLDIV_T_DEF -typedef struct lldiv_t -{ - long long quot; - long long rem; -} lldiv_t; -#endif - -#ifndef NULL -#define NULL 0 -#endif - -#define _max(a,b) (((a) > (b)) ? (a) : (b)) -#define _min(a,b) (((a) < (b)) ? (a) : (b)) - -#define RAND_MAX 32767 - -int rand(void); -void srand(unsigned); - -int abs(int); -long labs(long); - -div_t div(int,int); -ldiv_t ldiv(long,long); -lldiv_t lldiv(long long, long long); - -int atoi(const char *); -long atol(const char *); - -long strtol(const char *,char **,int); -unsigned long strtoul(const char *,char **,int); - -char *itoa(int,char *,int); -char *ltoa(long,char *,int); -char *ultoa(unsigned long,char *,int); - -double atof(const char *); -double strtod(const char *,char **); - -void qsort(void *,size_t,size_t,int (*)(const void *,const void *)); -void *bsearch(const void *,const void *,size_t,size_t,int (*)(const void *,const void *)); - -void *malloc(size_t); -void *calloc(size_t,size_t); -void *realloc(void *,size_t); -void free(void *); - -void exit(int); - -void abort(void); - -#endif diff --git a/lib/ultralib/include/gcc/string.h b/lib/ultralib/include/gcc/string.h deleted file mode 100644 index d82e1f1..0000000 --- a/lib/ultralib/include/gcc/string.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _STRING_H -#define _STRING_H -/* - string.h -*/ - -#ifndef _SIZE_T_DEF -#define _SIZE_T_DEF -typedef unsigned size_t; -#endif - -#include "memory.h" - -char *stpcpy(char *,const char *); -char *strcat(char *,const char *); -char *strchr(const char *,int); -int strcmp(const char *,const char *); -char *strcpy(char *,const char *); -size_t strcspn(const char *,const char *); -char *strdup(const char *); -char *strerror(int); -int stricmp(const char *,const char *); -size_t strlen(const char *); -char *strlwr(char *); -char *strncat(char *,const char *,size_t); -int strncmp(const char *,const char *,size_t); -char *strncpy(char *,const char *,size_t); -int strnicmp(const char *,const char *,size_t); -char *strnset(char *,int,size_t); -char *strpbrk(const char *,const char *); -char *strrchr(const char *,int); -char *strrev(char *); -char *strset(char *,int); -size_t strspn(const char *,const char *); -char *strstr(const char *,const char *); -char *strtok(char *,const char *); -char *strupr(char *); - -#define strcmpi(s1,s2) stricmp(s1,s2) -#define strncmpi(s1,s2,n) strnicmp(s1,s2,n) - -#endif diff --git a/lib/ultralib/include/ido/math.h b/lib/ultralib/include/ido/math.h deleted file mode 100644 index 3e93ceb..0000000 --- a/lib/ultralib/include/ido/math.h +++ /dev/null @@ -1 +0,0 @@ -// Nothing needed here diff --git a/lib/ultralib/include/ido/memory.h b/lib/ultralib/include/ido/memory.h deleted file mode 100644 index edfff5e..0000000 --- a/lib/ultralib/include/ido/memory.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _MEMORY_H -#define _MEMORY_H -/* - memory.h -*/ - -#ifndef _SIZE_T_DEF -#define _SIZE_T_DEF -typedef unsigned size_t; -#endif - -void *memccpy(void *,void *,int,size_t); -void *memchr(void *,int,size_t); -int memcmp(const void *,const void *,size_t); -void *memcpy(void *,const void *,size_t); -int memicmp(void *,void *,size_t); -void *memmove(void *,void *,size_t); -void *memset(void *,int,size_t); - -void movmem(void *,void *,unsigned); -void setmem(void *,unsigned,int); - -#endif diff --git a/lib/ultralib/include/ido/stdarg.h b/lib/ultralib/include/ido/stdarg.h deleted file mode 100644 index 62f68e0..0000000 --- a/lib/ultralib/include/ido/stdarg.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -typedef char *va_list; -#define _FP 1 -#define _INT 0 -#define _STRUCT 2 - -#define _VA_FP_SAVE_AREA 0x10 -#define _VA_ALIGN(p, a) (((unsigned int)(((char *)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) -#define va_start(vp, parmN) (vp = ((va_list)&parmN + sizeof(parmN))) - -#define __va_stack_arg(list, mode) \ - ( \ - ((list) = (char *)_VA_ALIGN(list, __builtin_alignof(mode)) + \ - _VA_ALIGN(sizeof(mode), 4)), \ - (((char *)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode)))) - -#define __va_double_arg(list, mode) \ - ( \ - (((long)list & 0x1) /* 1 byte aligned? */ \ - ? (list = (char *)((long)list + 7), (char *)((long)list - 6 - _VA_FP_SAVE_AREA)) \ - : (((long)list & 0x2) /* 2 byte aligned? */ \ - ? (list = (char *)((long)list + 10), (char *)((long)list - 24 - _VA_FP_SAVE_AREA)) \ - : __va_stack_arg(list, mode)))) - -#define va_arg(list, mode) ((mode *)(((__builtin_classof(mode) == _FP && \ - __builtin_alignof(mode) == sizeof(double)) \ - ? __va_double_arg(list, mode) \ - : __va_stack_arg(list, mode))))[-1] -#define va_end(__list) - -#endif /* STDARG_H */ diff --git a/lib/ultralib/include/ido/stdio.h b/lib/ultralib/include/ido/stdio.h deleted file mode 100644 index 3e93ceb..0000000 --- a/lib/ultralib/include/ido/stdio.h +++ /dev/null @@ -1 +0,0 @@ -// Nothing needed here diff --git a/lib/ultralib/include/ido/stdlib.h b/lib/ultralib/include/ido/stdlib.h deleted file mode 100644 index 98f8a2e..0000000 --- a/lib/ultralib/include/ido/stdlib.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _STDLIB_H -#define _STDLIB_H -/* - stdlib.h -*/ - -#ifndef _SIZE_T_DEF -#define _SIZE_T_DEF -typedef unsigned size_t; -#endif - -#ifndef _DIV_T_DEF -#define _DIV_T_DEF -typedef struct DIV_T { - int quot; - int rem; -} div_t; -#endif - -#ifndef _LDIV_T_DEF -#define _LDIV_T_DEF -typedef struct LDIV_T { - long quot; - long rem; -} ldiv_t; -#endif - -#ifndef _LLDIV_T_DEF -#define _LLDIV_T_DEF -typedef struct lldiv_t -{ - long long quot; - long long rem; -} lldiv_t; -#endif - -#ifndef NULL -#define NULL 0 -#endif - -#define _max(a,b) (((a) > (b)) ? (a) : (b)) -#define _min(a,b) (((a) < (b)) ? (a) : (b)) - -#define RAND_MAX 32767 - -int rand(void); -void srand(unsigned); - -int abs(int); -long labs(long); - -div_t div(int,int); -ldiv_t ldiv(long,long); -lldiv_t lldiv(long long, long long); - -int atoi(const char *); -long atol(const char *); - -long strtol(const char *,char **,int); -unsigned long strtoul(const char *,char **,int); - -char *itoa(int,char *,int); -char *ltoa(long,char *,int); -char *ultoa(unsigned long,char *,int); - -double atof(const char *); -double strtod(const char *,char **); - -void qsort(void *,size_t,size_t,int (*)(const void *,const void *)); -void *bsearch(const void *,const void *,size_t,size_t,int (*)(const void *,const void *)); - -void *malloc(size_t); -void *calloc(size_t,size_t); -void *realloc(void *,size_t); -void free(void *); - -void exit(int); - -void abort(void); - -#endif diff --git a/lib/ultralib/include/ido/string.h b/lib/ultralib/include/ido/string.h deleted file mode 100644 index d82e1f1..0000000 --- a/lib/ultralib/include/ido/string.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _STRING_H -#define _STRING_H -/* - string.h -*/ - -#ifndef _SIZE_T_DEF -#define _SIZE_T_DEF -typedef unsigned size_t; -#endif - -#include "memory.h" - -char *stpcpy(char *,const char *); -char *strcat(char *,const char *); -char *strchr(const char *,int); -int strcmp(const char *,const char *); -char *strcpy(char *,const char *); -size_t strcspn(const char *,const char *); -char *strdup(const char *); -char *strerror(int); -int stricmp(const char *,const char *); -size_t strlen(const char *); -char *strlwr(char *); -char *strncat(char *,const char *,size_t); -int strncmp(const char *,const char *,size_t); -char *strncpy(char *,const char *,size_t); -int strnicmp(const char *,const char *,size_t); -char *strnset(char *,int,size_t); -char *strpbrk(const char *,const char *); -char *strrchr(const char *,int); -char *strrev(char *); -char *strset(char *,int); -size_t strspn(const char *,const char *); -char *strstr(const char *,const char *); -char *strtok(char *,const char *); -char *strupr(char *); - -#define strcmpi(s1,s2) stricmp(s1,s2) -#define strncmpi(s1,s2,n) strnicmp(s1,s2,n) - -#endif diff --git a/lib/ultralib/include/macros.h b/lib/ultralib/include/macros.h deleted file mode 100644 index 3057fc8..0000000 --- a/lib/ultralib/include/macros.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __MACROS_H__ -#define __MACROS_H__ - -#define ALIGNED(x) __attribute__((aligned(x))) - -#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) - -#define STUBBED_PRINTF(x) ((void)(x)) - -#define UNUSED __attribute__((unused)) - -#ifndef __GNUC__ -#define __attribute__(x) -#endif - -#endif diff --git a/lib/ultralib/include/regdef.h b/lib/ultralib/include/regdef.h deleted file mode 100644 index c29cc69..0000000 --- a/lib/ultralib/include/regdef.h +++ /dev/null @@ -1,3 +0,0 @@ -#include -#include -#include diff --git a/lib/ultralib/include/sgidefs.h b/lib/ultralib/include/sgidefs.h deleted file mode 100644 index 8d4b6e1..0000000 --- a/lib/ultralib/include/sgidefs.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifdef __GNUC__ -#include "gcc/sgidefs.h" -#endif diff --git a/lib/ultralib/include/sys/asm.h b/lib/ultralib/include/sys/asm.h deleted file mode 100644 index 97f8fb2..0000000 --- a/lib/ultralib/include/sys/asm.h +++ /dev/null @@ -1,116 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO Co,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/07/06 13:21:13 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#ifndef __ASM_H__ -#define __ASM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define _MIPS_ISA_MIPS1 1 /* R2/3K */ -#define _MIPS_ISA_MIPS2 2 /* R4K/6K */ -#define _MIPS_ISA_MIPS3 3 /* R4K */ -#define _MIPS_ISA_MIPS4 4 /* TFP */ - -#define _MIPS_SIM_ABI32 1 /* MIPS MSIG calling convention */ -#define _MIPS_SIM_NABI32 2 /* MIPS new 32-bit abi */ - /* NABI32 is 64bit calling convention but 32bit type sizes) */ -#define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ - - -/* libgultra doesn't match with the .type directive but iQue sdk asm.h uses it */ -#ifdef BBPLAYER -#define ASM_TYPE_FUNC(x) .type x, @function -#else -#define ASM_TYPE_FUNC(x) -#endif - -#define LEAF(x) \ - .globl x ;\ - .align 2 ;\ - ASM_TYPE_FUNC(x) ;\ - .ent x,0 ;\ - x: ;\ - .frame sp,0,ra - -#if defined(BBPLAYER) || defined(__sgi) -#define XLEAF(x) \ - .globl x ;\ - .aent x,0 ;\ - x: -#else -#define XLEAF(x) \ - .globl x -#endif - -#ifdef BBPLAYER -#define END(proc) \ - .end proc ;\ - .size proc, . - proc -#else -#define END(proc) \ - .end proc -#endif - -#define ABS(x, y) \ - .globl x ;\ - x = y - -#define EXPORT(x) \ - .globl x ;\ - x: - -#if defined(BBPLAYER) || defined(__sgi) -#define WEAK(x, y) \ - .weakext x, y -#else -#define WEAK(x, y) -#endif - - - -#define STAY1(stmnt) \ - .set noreorder ;\ - stmnt ;\ - .set reorder - -#define STAY2(stmnt, arg1) \ - .set noreorder ;\ - stmnt, arg1 ;\ - .set reorder - -#define STAY3(stmnt, arg1, arg2) \ - .set noreorder ;\ - stmnt, arg1, arg2 ;\ - .set reorder - -#define NOP \ - .set noreorder ;\ - nop ;\ - .set reorder - -#define CACHE(op, reg) \ - .set noreorder ;\ - cache op, reg ;\ - .set reorder - -#ifdef __cplusplus -} -#endif - -#endif /* !__ASM_H__ */ diff --git a/lib/ultralib/include/sys/fpregdef.h b/lib/ultralib/include/sys/fpregdef.h deleted file mode 100644 index e69de29..0000000 diff --git a/lib/ultralib/include/sys/regdef.h b/lib/ultralib/include/sys/regdef.h deleted file mode 100644 index ac9c109..0000000 --- a/lib/ultralib/include/sys/regdef.h +++ /dev/null @@ -1,187 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO Co,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/07/06 13:21:13 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#ifndef __REGDEF_H__ -#define __REGDEF_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef mips - -#if (_MIPS_SIM == _MIPS_SIM_ABI32) -#define zero $0 -#define AT $at -#define v0 $2 -#define v1 $3 -#define a0 $4 -#define a1 $5 -#define a2 $6 -#define a3 $7 -#define t0 $8 -#define t1 $9 -#define t2 $10 -#define t3 $11 -#define t4 $12 -#define ta0 $12 -#define t5 $13 -#define ta1 $13 -#define t6 $14 -#define ta2 $14 -#define t7 $15 -#define ta3 $15 -#define s0 $16 -#define s1 $17 -#define s2 $18 -#define s3 $19 -#define s4 $20 -#define s5 $21 -#define s6 $22 -#define s7 $23 -#define t8 $24 -#define t9 $25 -#define jp $25 -#define k0 $26 -#define k1 $27 -#define gp $28 -#define sp $29 -#define fp $30 -#define s8 $30 -#define ra $31 -#endif - -#if (_MIPS_SIM == _MIPS_SIM_ABI64) -#define zero $0 -#define AT $at -#define v0 $2 -#define v1 $3 -#define a0 $4 -#define a1 $5 -#define a2 $6 -#define a3 $7 -#define a4 $8 -#define ta0 $8 -#define a5 $9 -#define ta1 $9 -#define a6 $10 -#define ta2 $10 -#define a7 $11 -#define ta3 $11 -#define t0 $12 -#define t1 $13 -#define t2 $14 -#define t3 $15 -#define s0 $16 -#define s1 $17 -#define s2 $18 -#define s3 $19 -#define s4 $20 -#define s5 $21 -#define s6 $22 -#define s7 $23 -#define t8 $24 -#define t9 $25 -#define jp $25 -#define k0 $26 -#define k1 $27 -#define gp $28 -#define sp $29 -#define fp $30 -#define s8 $30 -#define ra $31 -#endif - -#if (_MIPS_SIM == _MIPS_SIM_ABI32) -#define fv0 $f0 -#define fv0f $f1 -#define fv1 $f2 -#define fv1f $f3 -#define fa0 $f12 -#define fa0f $f13 -#define fa1 $f14 -#define fa1f $f15 -#define ft0 $f4 -#define ft0f $f5 -#define ft1 $f6 -#define ft1f $f7 -#define ft2 $f8 -#define ft2f $f9 -#define ft3 $f10 -#define ft3f $f11 -#define ft4 $f16 -#define ft4f $f17 -#define ft5 $f18 -#define ft5f $f19 -#define fs0 $f20 -#define fs0f $f21 -#define fs1 $f22 -#define fs1f $f23 -#define fs2 $f24 -#define fs2f $f25 -#define fs3 $f26 -#define fs3f $f27 -#define fs4 $f28 -#define fs4f $f29 -#define fs5 $f30 -#define fs5f $f31 -#endif - -#if (_MIPS_SIM == _MIPS_SIM_ABI64) -#define fv0 $f0 -#define fv1 $f2 -#define fa0 $f12 -#define fa1 $f13 -#define fa2 $f14 -#define fa3 $f15 -#define fa4 $f16 -#define fa5 $f17 -#define fa6 $f18 -#define fa7 $f19 -#define ft0 $f4 -#define ft1 $f5 -#define ft2 $f6 -#define ft3 $f7 -#define ft4 $f8 -#define ft5 $f9 -#define ft6 $f10 -#define ft7 $f11 -#define ft8 $f20 -#define ft9 $f21 -#define ft10 $f22 -#define ft11 $f23 -#define ft12 $f1 -#define ft13 $f3 -#define fs0 $f24 -#define fs1 $f25 -#define fs2 $f26 -#define fs3 $f27 -#define fs4 $f28 -#define fs5 $f29 -#define fs6 $f30 -#define fs7 $f31 -#endif - -#define fcr31 $31 - -#endif /* mips */ - -#ifdef __cplusplus -} -#endif - -#endif /* !__REGDEF_H__ */ diff --git a/lib/ultralib/include/ultra64.h b/lib/ultralib/include/ultra64.h deleted file mode 100644 index 053db38..0000000 --- a/lib/ultralib/include/ultra64.h +++ /dev/null @@ -1,40 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - *************************************************************************/ - -/************************************************************************** - * - * $Revision: 1.10 $ - * $Date: 1997/02/11 08:37:33 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultra64.h,v $ - * - **************************************************************************/ - -#ifndef _ULTRA64_H_ -#define _ULTRA64_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/lib/ultralib/include/ultrahost.h b/lib/ultralib/include/ultrahost.h deleted file mode 100644 index 2c50b95..0000000 --- a/lib/ultralib/include/ultrahost.h +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************** - * - * $Revision: 1.1 $ - * $Date: 1999/07/05 02:16:07 $ - * - **************************************************************************/ - -#ifndef _ULTRAHOST_H_ -#define _ULTRAHOST_H_ - -#ifdef WIN32 /* { */ - -int __stdcall uhOpenGame(char *); -int __stdcall uhCloseGame(int); -int __stdcall uhReadGame(int hfd,void *buf,int count); -int __stdcall uhWriteGame(int hfd,void *buf,int count); -int __stdcall uhReadRamrom(int hfd,void *ramrom_adr,void *buf,int count); -int __stdcall uhWriteRamrom(int hfd,void *ramrom_adr,void *buf,int count); -int __stdcall uhPartnerInit(int hfd); -int __stdcall uhPartnerCmd(int hfd,char *ptcmd); -int __stdcall uhGload(int hfd,char *loadfile); - -#else /* }{ */ -#ifdef PTN64 /* { */ - -#define execl execl_pt - -#define uhOpenGame uhOpenGame_pt -#define uhCloseGame uhCloseGame_pt - -#define uhReadGame uhReadGame_pt -#define uhWriteGame uhWriteGame_pt -#define uhReadRamrom uhReadRamrom_pt -#define uhWriteRamrom uhWriteRamrom_pt -#define uhPartnerCmd uhPartnerCmd_pt -#define uhGload uhGload_pt - -int uhPartnerCmd(int,char *); -int uhGload(int,char *); - -#endif /* } */ - -#ifdef __cplusplus -extern "C" { -#endif -int uhOpenGame(const char *); -int uhCloseGame(int); - -int uhReadGame(int, void *, int); -int uhWriteGame(int, void *, int); -int uhWriteRamrom(int, void *, void*, int); -int uhReadRamrom(int, void *, void*, int); - -#ifdef __cplusplus -} -#endif -#endif /* } */ - -#endif /* ULTRAHOST */ diff --git a/lib/ultralib/src/audio/Makefile b/lib/ultralib/src/audio/Makefile deleted file mode 100644 index d8fdce4..0000000 --- a/lib/ultralib/src/audio/Makefile +++ /dev/null @@ -1,120 +0,0 @@ -#!smake -# -# Makefile for audio library subdirectory -# - -include $(ROOT)/usr/include/make/PRdefs - -# LCOPTS = -mips2 -non_shared -fullwarn -G 0 -LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include - -CFILES = \ - drvrnew.c \ - load.c \ - auxbus.c \ - bnkf.c \ - env.c \ - event.c \ - filter.c \ - mainbus.c \ - resample.c \ - reverb.c \ - save.c \ - seq.c \ - sl.c \ - heapcheck.c \ - heapinit.c \ - heapalloc.c \ - copy.c \ - seqpdelete.c \ - seqpgetfxmix.c \ - seqpgetpan.c \ - seqpgetchlvol.c \ - seqpgetpriority.c \ - seqpgetprogram.c \ - seqpgetseq.c \ - seqpgettempo.c \ - seqpgetvol.c \ - seqpgetstate.c \ - seqploop.c \ - seqpplay.c \ - seqpsendmidi.c \ - seqpsetbank.c \ - seqpsetfxmix.c \ - seqpsetpan.c \ - seqpsetchlvol.c \ - seqpsetpriority.c \ - seqpsetprogram.c \ - seqpsetseq.c \ - seqpsettempo.c \ - seqpsetvol.c \ - seqpstop.c \ - seqplayer.c \ - cseq.c \ - cspdelete.c \ - cspgetfxmix.c \ - cspgetpan.c \ - cspgetchlvol.c \ - cspgetpriority.c \ - cspgetprogram.c \ - cspgetseq.c \ - cspgettempo.c \ - cspgetvol.c \ - cspgetstate.c \ - cspplay.c \ - cspsendmidi.c \ - cspsetbank.c \ - cspsetfxmix.c \ - cspsetpan.c \ - cspsetchlvol.c \ - cspsetpriority.c \ - cspsetprogram.c \ - cspsetseq.c \ - cspsettempo.c \ - cspsetvol.c \ - cspstop.c \ - csplayer.c \ - sndplayer.c \ - sndpdelete.c \ - sndpallocate.c \ - sndpdeallocate.c \ - sndpsetsound.c \ - sndpplay.c \ - sndpplayat.c \ - sndpgetsound.c \ - sndpstop.c \ - sndpgetstate.c \ - sndpsetpitch.c \ - sndpsetpriority.c \ - sndpsetvol.c \ - sndpsetpan.c \ - sndpsetfxmix.c \ - synthesizer.c \ - syndelete.c \ - synaddplayer.c \ - synremoveplayer.c \ - synfreevoice.c \ - synallocvoice.c \ - synstopvoice.c \ - synstartvoice.c \ - synstartvoiceparam.c \ - synsetpitch.c \ - synsetvol.c \ - synsetfxmix.c \ - synsetpan.c \ - syngetpriority.c \ - synsetpriority.c \ - synallocfx.c \ - synfreefx.c \ - syngetfxref.c \ - synsetfxparam.c \ - cents2ratio.c \ - parse_abi.c - -TARGETS = $(CFILES:.c=.o) - -default : $(TARGETS) - -include $(COMMONRULES) - - diff --git a/lib/ultralib/src/audio/auxbus.c b/lib/ultralib/src/audio/auxbus.c deleted file mode 100644 index 471ba41..0000000 --- a/lib/ultralib/src/audio/auxbus.c +++ /dev/null @@ -1,65 +0,0 @@ -/*==================================================================== - * auxbus.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include "synthInternals.h" - -Acmd *alAuxBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, - Acmd *p) -{ - Acmd *ptr = p; - ALAuxBus *m = (ALAuxBus *)filter; - ALFilter **sources = m->sources; - s32 i; - - /* - * clear the output buffers here - */ - aClearBuffer(ptr++, AL_AUX_L_OUT, outCount<<1); - aClearBuffer(ptr++, AL_AUX_R_OUT, outCount<<1); - - for (i = 0; i < m->sourceCount; i++) { - ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset, - ptr); - } - - return ptr; -} - -s32 alAuxBusParam(void *filter, s32 paramID, void *param) -{ - ALAuxBus *m = (ALAuxBus *) filter; - ALFilter **sources = m->sources; - - switch (paramID) { - - case (AL_FILTER_ADD_SOURCE): - sources[m->sourceCount++] = (ALFilter *) param; - break; - - default: - /* ??? */ - break; - } - - return 0; - -} - diff --git a/lib/ultralib/src/audio/bnkf.c b/lib/ultralib/src/audio/bnkf.c deleted file mode 100644 index dfd312f..0000000 --- a/lib/ultralib/src/audio/bnkf.c +++ /dev/null @@ -1,143 +0,0 @@ -/*==================================================================== - * bnkf.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include -#include - -/* - * ### when the file format settles down a little, I'll remove these - * ### for efficiency. - */ -static void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table); -static void _bnkfPatchInst(ALInstrument *i, s32 offset, s32 table); -static void _bnkfPatchSound(ALSound *s, s32 offset, s32 table); -static void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table); - -void alSeqFileNew(ALSeqFile *file, u8 *base) -{ - s32 offset = (s32) base; - s32 i; - - /* - * patch the file so that offsets are pointers - */ - for (i = 0; i < file->seqCount; i++) { - file->seqArray[i].offset = (u8 *)((u8 *)file->seqArray[i].offset + offset); - } -} - -void alBnkfNew(ALBankFile *file, u8 *table) -{ - s32 offset = (s32) file; - s32 woffset = (s32) table; - - s32 i; - - /* - * check the file format revision in debug libraries - */ - ALFailIf(file->revision != AL_BANK_VERSION, ERR_ALBNKFNEW); - - /* - * patch the file so that offsets are pointers - */ - for (i = 0; i < file->bankCount; i++) { - file->bankArray[i] = (ALBank *)((u8 *)file->bankArray[i] + offset); - if(file->bankArray[i]) - _bnkfPatchBank(file->bankArray[i], offset, woffset); - } -} - -void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table) -{ - s32 i; - - if (bank->flags) - return; - - bank->flags = 1; - - if (bank->percussion) { - bank->percussion = (ALInstrument *)((u8 *)bank->percussion + offset); - _bnkfPatchInst(bank->percussion, offset, table); - } - - for (i = 0; i < bank->instCount; i++) { - bank->instArray[i] = (ALInstrument *)((u8 *)bank->instArray[i] + - offset); - if(bank->instArray[i]) - _bnkfPatchInst(bank->instArray[i], offset, table); - } -} - -void _bnkfPatchInst(ALInstrument *inst, s32 offset, s32 table) -{ - s32 i; - - if (inst->flags) - return; - - inst->flags = 1; - - for (i = 0; i < inst->soundCount; i++) { - inst->soundArray[i] = (ALSound *)((u8 *)inst->soundArray[i] + - offset); - _bnkfPatchSound(inst->soundArray[i], offset, table); - - } -} - -void _bnkfPatchSound(ALSound *s, s32 offset, s32 table) -{ - if (s->flags) - return; - - s->flags = 1; - - s->envelope = (ALEnvelope *)((u8 *)s->envelope + offset); - s->keyMap = (ALKeyMap *)((u8 *)s->keyMap + offset); - - s->wavetable = (ALWaveTable *)((u8 *)s->wavetable + offset); - _bnkfPatchWaveTable(s->wavetable, offset, table); -} - -void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table) -{ - if (w->flags) - return; - - w->flags = 1; - - w->base += table; - - /* sct 2/14/96 - patch wavetable loop info based on type. */ - if (w->type == AL_ADPCM_WAVE) - { - w->waveInfo.adpcmWave.book = (ALADPCMBook *)((u8 *)w->waveInfo.adpcmWave.book + offset); - if (w->waveInfo.adpcmWave.loop) - w->waveInfo.adpcmWave.loop = (ALADPCMloop *)((u8 *)w->waveInfo.adpcmWave.loop + offset); - } - else if (w->type == AL_RAW16_WAVE) - { - if (w->waveInfo.rawWave.loop) - w->waveInfo.rawWave.loop = (ALRawLoop *)((u8 *)w->waveInfo.rawWave.loop + offset); - } -} diff --git a/lib/ultralib/src/audio/cents2ratio.c b/lib/ultralib/src/audio/cents2ratio.c deleted file mode 100644 index 55cd2a3..0000000 --- a/lib/ultralib/src/audio/cents2ratio.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * alCents2Ratio() - * - * Calculates the pitch shift ratio from the number of cents according to - * ratio = 2^(cents/1200) - * - * This is accurate to within one cent for ratios up and octave and down - * two ocataves. - */ - -#include - -f32 alCents2Ratio(s32 cents) -{ - f32 x; - f32 ratio = 1.0f; - - if (cents >= 0) { - x = 1.00057779f; /* 2^(1/1200) */ - } else { - x = 0.9994225441f; /* 2^(-1/1200) */ - cents = -cents; - } - - while (cents) { - if (cents & 1) - ratio *= x; - x *= x; - cents >>= 1; - } - - return ratio; -} diff --git a/lib/ultralib/src/audio/copy.c b/lib/ultralib/src/audio/copy.c deleted file mode 100644 index e80a8df..0000000 --- a/lib/ultralib/src/audio/copy.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * copy.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCopy(void *src, void *dest, s32 len) -{ - s32 i; - u8 *s = (u8 *)src; - u8 *d = (u8 *)dest; - - for (i = 0; i < len; i++){ - *d++ = *s++; - } -} - diff --git a/lib/ultralib/src/audio/cseq.c b/lib/ultralib/src/audio/cseq.c deleted file mode 100644 index 9c4b8bd..0000000 --- a/lib/ultralib/src/audio/cseq.c +++ /dev/null @@ -1,409 +0,0 @@ -/*==================================================================== - * cseq.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include -#include -#include "cseq.h" - - -static u32 __readVarLen(ALCSeq *s,u32 track); -static u8 __getTrackByte(ALCSeq *s,u32 track); -static u32 __alCSeqGetTrackEvent(ALCSeq *seq, u32 track, ALEvent *event); - -void alCSeqNew(ALCSeq *seq, u8 *ptr) -{ - u32 i,tmpOff,flagTmp; - - /* load the seqence pointed to by ptr */ - seq->base = (ALCMidiHdr*)ptr; - seq->validTracks = 0; - seq->lastDeltaTicks = 0; - seq->lastTicks = 0; - seq->deltaFlag = 1; - - for(i = 0; i < 16; i++) - { - seq->lastStatus[i] = 0; - seq->curBUPtr[i] = 0; - seq->curBULen[i] = 0; - tmpOff = seq->base->trackOffset[i]; - if(tmpOff) /* if the track is valid */ - { - flagTmp = 1 << i; - seq->validTracks |= flagTmp; - seq->curLoc[i] = (u8*)((u32)ptr + tmpOff); - seq->evtDeltaTicks[i] = __readVarLen(seq,i); - /*__alCSeqGetTrackEvent(seq,i); prime the event buffers */ - } - else - seq->curLoc[i] = 0; - } - - seq->qnpt = 1.0/(f32)seq->base->division; -} - -void alCSeqNextEvent(ALCSeq *seq,ALEvent *evt) -{ - u32 i; - u32 firstTime = 0xFFFFFFFF; - u32 firstTrack; - u32 lastTicks = seq->lastDeltaTicks; - -#ifdef _DEBUG - /* sct 1/17/96 - Warn if we are beyond the end of sequence. */ - if (!seq->validTracks) - __osError(ERR_ALSEQOVERRUN, 0); -#endif - - - for(i = 0; i < 16 ; i++) - { - if((seq->validTracks >> i) & 1) - { - if(seq->deltaFlag) - seq->evtDeltaTicks[i] -= lastTicks; - if(seq->evtDeltaTicks[i] < firstTime) - { - firstTime = seq->evtDeltaTicks[i]; - firstTrack = i; - } - } - } - - __alCSeqGetTrackEvent(seq,firstTrack,evt); - - evt->msg.midi.ticks = firstTime; - seq->lastTicks += firstTime; - seq->lastDeltaTicks = firstTime; - if(evt->type != AL_TRACK_END) - seq->evtDeltaTicks[firstTrack] += __readVarLen(seq,firstTrack); - seq->deltaFlag = 1; - -} - - -/* - Note: If there are no valid tracks (ie. all tracks have - reached the end of their data stream), then return FALSE - to indicate that there is no next event. -*/ -char __alCSeqNextDelta(ALCSeq *seq, s32 *pDeltaTicks) -{ - u32 i; - u32 firstTime = 0xFFFFFFFF; - u32 lastTicks = seq->lastDeltaTicks; - - if (!seq->validTracks) - return FALSE; - - for(i = 0; i < 16 ; i++) - { - if((seq->validTracks >> i) & 1) - { - if(seq->deltaFlag) - seq->evtDeltaTicks[i] -= lastTicks; - - if(seq->evtDeltaTicks[i] < firstTime) - firstTime = seq->evtDeltaTicks[i]; - } - } - - seq->deltaFlag = 0; - *pDeltaTicks = firstTime; - - return TRUE; -} - -/* only call alCSeqGetTrackEvent with a valid track !! */ -static u32 __alCSeqGetTrackEvent(ALCSeq *seq, u32 track, ALEvent *event) -{ - u32 offset; - u8 status, loopCt, curLpCt, *tmpPtr; - - - status = __getTrackByte(seq,track); /* read the status byte */ - - if (status == AL_MIDI_Meta) /* running status not allowed on meta events!! */ - { - u8 type = __getTrackByte(seq,track); - - if (type == AL_MIDI_META_TEMPO) - { - event->type = AL_TEMPO_EVT; - event->msg.tempo.status = status; - event->msg.tempo.type = type; - event->msg.tempo.byte1 = __getTrackByte(seq,track); - event->msg.tempo.byte2 = __getTrackByte(seq,track); - event->msg.tempo.byte3 = __getTrackByte(seq,track); - seq->lastStatus[track] = 0; /* lastStatus not supported after meta */ - } - else if (type == AL_MIDI_META_EOT) - { - u32 flagMask; - - flagMask = 0x01 << track; - seq->validTracks = seq->validTracks ^ flagMask; - - if(seq->validTracks) /* there is music left don't end */ - event->type = AL_TRACK_END; - else /* no more music send AL_SEQ_END_EVT msg */ - event->type = AL_SEQ_END_EVT; - } - else if (type == AL_CMIDI_LOOPSTART_CODE) - { - status = __getTrackByte(seq,track); /* get next two bytes, ignore them */ - status = __getTrackByte(seq,track); - seq->lastStatus[track] = 0; - event->type = AL_CSP_LOOPSTART; - } - else if (type == AL_CMIDI_LOOPEND_CODE) - { - tmpPtr = seq->curLoc[track]; - loopCt = *tmpPtr++; - curLpCt = *tmpPtr; - if(curLpCt == 0) /* done looping */ - { - *tmpPtr = loopCt; /* reset current loop count */ - seq->curLoc[track] = tmpPtr + 5; /* move pointer to end of event */ - } - else - { - if(curLpCt != 0xFF) /* not a loop forever */ - *tmpPtr = curLpCt - 1; /* decrement current loop count */ - tmpPtr++; /* get offset from end of event */ - offset = (*tmpPtr++) << 24; - offset += (*tmpPtr++) << 16; - offset += (*tmpPtr++) << 8; - offset += *tmpPtr++; - seq->curLoc[track] = tmpPtr - offset; - } - seq->lastStatus[track] = 0; - event->type = AL_CSP_LOOPEND; - } - -#ifdef _DEBUG - else - __osError(ERR_ALSEQMETA, 1, type); -#endif - - } - else - { - event->type = AL_SEQ_MIDI_EVT; - if (status & 0x80) /* if high bit is set, then new status */ - { - event->msg.midi.status = status; - event->msg.midi.byte1 = __getTrackByte(seq,track); - seq->lastStatus[track] = status; - } - else /* running status */ - { -#ifdef _DEBUG - if(seq->lastStatus[track] == 0) - __osError(ERR_ALCSEQZEROSTATUS, 1, track); -#endif - event->msg.midi.status = seq->lastStatus[track]; - event->msg.midi.byte1 = status; - } - - if (((event->msg.midi.status & 0xf0) != AL_MIDI_ProgramChange) && - ((event->msg.midi.status & 0xf0) != AL_MIDI_ChannelPressure)) - { - event->msg.midi.byte2 = __getTrackByte(seq,track); - if((event->msg.midi.status & 0xf0) == AL_MIDI_NoteOn) - { - event->msg.midi.duration = __readVarLen(seq,track); -#ifdef _DEBUG - if(event->msg.midi.byte2 == 0) - __osError( ERR_ALCSEQZEROVEL, 1, track); -#endif - } - } - else - event->msg.midi.byte2 = 0; - } - return TRUE; -} - -f32 alCSeqTicksToSec(ALCSeq *seq, s32 ticks, u32 tempo) -{ - return ((f32) (((f32)(ticks) * (f32)(tempo)) / - ((f32)(seq->base->division) * 1000000.0))); -} - -u32 alCSeqSecToTicks(ALCSeq *seq, f32 sec, u32 tempo) -{ - return (u32)(((sec * 1000000.0) * seq->base->division) / tempo); -} - - -s32 alCSeqGetTicks(ALCSeq *seq) -{ - return seq->lastTicks; -} - - -void alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks) -{ - ALEvent evt; - ALCSeq tempSeq; - s32 i; - - - alCSeqNew(&tempSeq, (u8*)seq->base); - - do { - m->validTracks = tempSeq.validTracks; - m->lastTicks = tempSeq.lastTicks; - m->lastDeltaTicks = tempSeq.lastDeltaTicks; - - for(i=0;i<16;i++) - { - m->curLoc[i] = tempSeq.curLoc[i]; - m->curBUPtr[i] = tempSeq.curBUPtr[i]; - m->curBULen[i] = tempSeq.curBULen[i]; - m->lastStatus[i] = tempSeq.lastStatus[i]; - m->evtDeltaTicks[i] = tempSeq.evtDeltaTicks[i]; - } - - alCSeqNextEvent(&tempSeq, &evt); - - if (evt.type == AL_SEQ_END_EVT) - break; - - } while (tempSeq.lastTicks < ticks); - -} - -void alCSeqSetLoc(ALCSeq *seq, ALCSeqMarker *m) -{ - s32 i; - - seq->validTracks = m->validTracks; - seq->lastTicks = m->lastTicks; - seq->lastDeltaTicks = m->lastDeltaTicks; - - for(i=0;i<16;i++) - { - seq->curLoc[i] = m->curLoc[i]; - seq->curBUPtr[i] = m->curBUPtr[i]; - seq->curBULen[i] = m->curBULen[i]; - seq->lastStatus[i] = m->lastStatus[i]; - seq->evtDeltaTicks[i] = m->evtDeltaTicks[i]; - } -} - -void alCSeqGetLoc(ALCSeq *seq, ALCSeqMarker *m) -{ - s32 i; - - m->validTracks = seq->validTracks; - m->lastTicks = seq->lastTicks; - m->lastDeltaTicks = seq->lastDeltaTicks; - - for(i=0;i<16;i++) - { - m->curLoc[i] = seq->curLoc[i]; - m->curBUPtr[i] = seq->curBUPtr[i]; - m->curBULen[i] = seq->curBULen[i]; - m->lastStatus[i] = seq->lastStatus[i]; - m->evtDeltaTicks[i] = seq->evtDeltaTicks[i]; - } -} - -/* non-aligned byte reading routines */ -static u8 __getTrackByte(ALCSeq *seq,u32 track) -{ - u8 theByte; - - - if(seq->curBULen[track]) - { - theByte = *seq->curBUPtr[track]; - seq->curBUPtr[track]++; - seq->curBULen[track]--; - } - else /* need to handle backup mode */ - { - theByte = *seq->curLoc[track]; - seq->curLoc[track]++; - if(theByte == AL_CMIDI_BLOCK_CODE) - { - u8 loBackUp,hiBackUp,theLen,nextByte; - u32 backup; - - nextByte = *seq->curLoc[track]; - seq->curLoc[track]++; - if(nextByte != AL_CMIDI_BLOCK_CODE) - { - /* if here, then got a backup section. get the amount of - backup, and the len of the section. Subtract the amount of - backup from the curLoc ptr, and subtract four more, since - curLoc has been advanced by four while reading the codes. */ - hiBackUp = nextByte; - loBackUp = *seq->curLoc[track]; - seq->curLoc[track]++; - theLen = *seq->curLoc[track]; - seq->curLoc[track]++; - backup = (u32)hiBackUp; - backup = backup << 8; - backup += loBackUp; - seq->curBUPtr[track] = seq->curLoc[track] - (backup + 4); - seq->curBULen[track] = (u32)theLen; - - /* now get the byte */ - theByte = *seq->curBUPtr[track]; - seq->curBUPtr[track]++; - seq->curBULen[track]--; - } - } - } - - return theByte; -} - -static u32 __readVarLen(ALCSeq *seq,u32 track) -{ - u32 value; - u32 c; - - value = (u32)__getTrackByte(seq,track); - if ( value & 0x00000080 ) - { - value &= 0x7f; - do - { - c = (u32)__getTrackByte(seq,track); - value = (value << 7) + (c & 0x7f); - } while (c & 0x80); - } - return (value); -} - - - - - - - - - - diff --git a/lib/ultralib/src/audio/cseq.h b/lib/ultralib/src/audio/cseq.h deleted file mode 100644 index 0342398..0000000 --- a/lib/ultralib/src/audio/cseq.h +++ /dev/null @@ -1,11 +0,0 @@ - - - -#ifndef __cseq__ -#define __cseq__ - - -char __alCSeqNextDelta(ALCSeq *seq, s32 *pDeltaTicks); - - -#endif /* __cseq__ */ diff --git a/lib/ultralib/src/audio/cseqp.h b/lib/ultralib/src/audio/cseqp.h deleted file mode 100644 index bb72541..0000000 --- a/lib/ultralib/src/audio/cseqp.h +++ /dev/null @@ -1,10 +0,0 @@ - - -#ifndef __cseqp__ -#define __cseqp__ - - -void __CSPPostNextSeqEvent(ALCSPlayer *seqp); - - -#endif /* __cseqp__ */ diff --git a/lib/ultralib/src/audio/cspdelete.c b/lib/ultralib/src/audio/cspdelete.c deleted file mode 100644 index 063c543..0000000 --- a/lib/ultralib/src/audio/cspdelete.c +++ /dev/null @@ -1,29 +0,0 @@ -/*==================================================================== - * cspdelete.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPDelete(ALCSPlayer *seqp) -{ - alSynRemovePlayer(seqp->drvr, &seqp->node); -} - diff --git a/lib/ultralib/src/audio/cspgetchlvol.c b/lib/ultralib/src/audio/cspgetchlvol.c deleted file mode 100644 index 23d256e..0000000 --- a/lib/ultralib/src/audio/cspgetchlvol.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * cspgetchlvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].vol; -} - diff --git a/lib/ultralib/src/audio/cspgetfxmix.c b/lib/ultralib/src/audio/cspgetfxmix.c deleted file mode 100644 index c67e033..0000000 --- a/lib/ultralib/src/audio/cspgetfxmix.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * cspgetfxmix.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -u8 alCSPGetChlFXMix(ALCSPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].fxmix; -} - diff --git a/lib/ultralib/src/audio/cspgetpan.c b/lib/ultralib/src/audio/cspgetpan.c deleted file mode 100644 index 5c0e322..0000000 --- a/lib/ultralib/src/audio/cspgetpan.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * cspgetpan.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -ALPan alCSPGetChlPan(ALCSPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].pan; -} - diff --git a/lib/ultralib/src/audio/cspgetpriority.c b/lib/ultralib/src/audio/cspgetpriority.c deleted file mode 100644 index ac38cae..0000000 --- a/lib/ultralib/src/audio/cspgetpriority.c +++ /dev/null @@ -1,26 +0,0 @@ -/*==================================================================== - * cspgetpriority.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -u8 alCSPGetChlPriority(ALCSPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].priority; -} diff --git a/lib/ultralib/src/audio/cspgetprogram.c b/lib/ultralib/src/audio/cspgetprogram.c deleted file mode 100644 index 382616f..0000000 --- a/lib/ultralib/src/audio/cspgetprogram.c +++ /dev/null @@ -1,42 +0,0 @@ -/*==================================================================== - * cspgetprogram.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s32 alCSPGetChlProgram(ALCSPlayer *seqp, u8 chan) - -{ - s32 i; - ALBank *b = seqp->bank; - ALInstrument *inst; - ALChanState s; - - s = seqp->chanState[chan]; - for (i=0; iinstCount; i++){ - inst = b->instArray[i]; - if (inst == s.instrument) - return i; - } - return(-1); - -} - diff --git a/lib/ultralib/src/audio/cspgetseq.c b/lib/ultralib/src/audio/cspgetseq.c deleted file mode 100644 index 85d2545..0000000 --- a/lib/ultralib/src/audio/cspgetseq.c +++ /dev/null @@ -1,29 +0,0 @@ -/*==================================================================== - * cspgetseq.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -ALCSeq *alCSPGetSeq(ALCSPlayer *seqp) -{ - return seqp->target; -} - diff --git a/lib/ultralib/src/audio/cspgetstate.c b/lib/ultralib/src/audio/cspgetstate.c deleted file mode 100644 index 9be7937..0000000 --- a/lib/ultralib/src/audio/cspgetstate.c +++ /dev/null @@ -1,29 +0,0 @@ -/*==================================================================== - * cspgetstate.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s32 alCSPGetState(ALCSPlayer *seqp) -{ - return seqp->state; -} - diff --git a/lib/ultralib/src/audio/cspgettempo.c b/lib/ultralib/src/audio/cspgettempo.c deleted file mode 100644 index ed3dfe2..0000000 --- a/lib/ultralib/src/audio/cspgettempo.c +++ /dev/null @@ -1,31 +0,0 @@ -/*==================================================================== - * cspgettempo.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s32 alCSPGetTempo(ALCSPlayer *seqp) -{ - /* sct 1/8/96 - If no target sequence has been set, just return zero (instead of crashing). */ - if (seqp->target == NULL) - return 0; - - return seqp->uspt/seqp->target->qnpt; -} - diff --git a/lib/ultralib/src/audio/cspgetvol.c b/lib/ultralib/src/audio/cspgetvol.c deleted file mode 100644 index 5353228..0000000 --- a/lib/ultralib/src/audio/cspgetvol.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * cspgetvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s16 alCSPGetVol(ALCSPlayer *seqp) -{ - return seqp->vol; -} - diff --git a/lib/ultralib/src/audio/csplayer.c b/lib/ultralib/src/audio/csplayer.c deleted file mode 100644 index 5cd3df6..0000000 --- a/lib/ultralib/src/audio/csplayer.c +++ /dev/null @@ -1,882 +0,0 @@ -/*==================================================================== - * csplayer.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/* - * Notes: - * - * Controller Numbers: - * 1 Modulation - * 7 Volume - * 10 Pan - * 11 Expression - * 64 Sustain - * 121 Reset All Controllers - * 123 All Notes Off - * - * Registered Parameters - * 0 Pitch Bend Sensitivity - * 1 Fine Tuning - * 2 Coarse Tuning - */ - -#include -#include -#include -#include -#include "seqp.h" -#include "cseqp.h" -#include "cseq.h" -// TODO: this comes from a header -#ident "$Revision: 1.17 $" -static ALMicroTime __CSPVoiceHandler(void *node); -static void __CSPHandleNextSeqEvent(ALCSPlayer *seqp); -static void __CSPHandleMIDIMsg(ALCSPlayer *seqp, ALEvent *event); -static void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event); -static void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item); -static void __setUsptFromTempo(ALCSPlayer *seqp, f32 tempo); /* sct 1/8/96 */ - - -/* - * Sequence Player public functions - */ -void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *c) -{ - s32 i; - ALEventListItem *items; - ALVoiceState *vs; - ALVoiceState *voices; - - ALHeap *hp = c->heap; - - /* - * initialize member variables - */ - seqp->bank = 0; - seqp->target = NULL; - seqp->drvr = &alGlobals->drvr; - seqp->chanMask = 0xff; - seqp->uspt = 488; - seqp->nextDelta = 0; - seqp->state = AL_STOPPED; - seqp->vol = 0x7FFF; /* full volume */ - seqp->frameTime = AL_USEC_PER_FRAME; /* should get this from driver */ - seqp->curTime = 0; - seqp->initOsc = c->initOsc; - seqp->updateOsc = c->updateOsc; - seqp->stopOsc = c->stopOsc; - - seqp->nextEvent.type = AL_SEQP_API_EVT; /* this will start the voice handler "spinning" */ - - /* - * init the channel state - */ - seqp->maxChannels = c->maxChannels; - seqp->chanState = alHeapAlloc(hp, c->maxChannels, sizeof(ALChanState) ); - __initChanState((ALSeqPlayer*)seqp); /* sct 11/6/95 */ - - /* - * init the voice state array - */ - voices = alHeapAlloc(hp, c->maxVoices, sizeof(ALVoiceState)); - seqp->vFreeList = 0; - for (i = 0; i < c->maxVoices; i++) { - vs = &voices[i]; - vs->next = seqp->vFreeList; - seqp->vFreeList = vs; - } - - seqp->vAllocHead = 0; - seqp->vAllocTail = 0; -#if BUILD_VERSION < VERSION_J -#line 109 -#endif - // init the event queue - items = alHeapAlloc(hp, c->maxEvents, sizeof(ALEventListItem)); - alEvtqNew(&seqp->evtq, items, c->maxEvents); - - /* - * add ourselves to the driver - */ - seqp->node.next = NULL; - seqp->node.handler = __CSPVoiceHandler; - seqp->node.clientData = seqp; - alSynAddPlayer(&alGlobals->drvr, &seqp->node); -} - -/************************************************************* - * private routines or driver callback routines - *************************************************************/ -static ALMicroTime __CSPVoiceHandler(void *node) -{ - ALCSPlayer *seqp = (ALCSPlayer *) node; - ALEvent evt; - ALVoice *voice; - ALMicroTime delta; - ALVoiceState *vs; - void *oscState; - f32 oscValue; - u8 chan; - - do { - switch (seqp->nextEvent.type) - { - case (AL_SEQ_REF_EVT): - __CSPHandleNextSeqEvent(seqp); - break; - - case (AL_SEQP_API_EVT): - evt.type = AL_SEQP_API_EVT; - alEvtqPostEvent(&seqp->evtq, (ALEvent *)&evt, seqp->frameTime); - break; - - case (AL_NOTE_END_EVT): - voice = seqp->nextEvent.msg.note.voice; - - alSynStopVoice(seqp->drvr, voice); - alSynFreeVoice(seqp->drvr, voice); - vs = (ALVoiceState *)voice->clientPrivate; - if(vs->flags) - __seqpStopOsc((ALSeqPlayer*)seqp,vs); - __unmapVoice((ALSeqPlayer*)seqp, voice); - break; - - case (AL_SEQP_ENV_EVT): - voice = seqp->nextEvent.msg.vol.voice; - vs = (ALVoiceState *)voice->clientPrivate; - - if(vs->envPhase == AL_PHASE_ATTACK) - vs->envPhase = AL_PHASE_DECAY; - - delta = seqp->nextEvent.msg.vol.delta; - vs->envEndTime = seqp->curTime + delta; - vs->envGain = seqp->nextEvent.msg.vol.vol; - alSynSetVol(seqp->drvr, voice, __vsVol(vs, (ALSeqPlayer*)seqp), delta); - break; - - case (AL_TREM_OSC_EVT): - vs = seqp->nextEvent.msg.osc.vs; - oscState = seqp->nextEvent.msg.osc.oscState; - delta = (*seqp->updateOsc)(oscState,&oscValue); - vs->tremelo = (u8)oscValue; - alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs,(ALSeqPlayer*)seqp), - __vsDelta(vs,seqp->curTime)); - evt.type = AL_TREM_OSC_EVT; - evt.msg.osc.vs = vs; - evt.msg.osc.oscState = oscState; - alEvtqPostEvent(&seqp->evtq, &evt, delta); - break; - - case (AL_VIB_OSC_EVT): - vs = seqp->nextEvent.msg.osc.vs; - oscState = seqp->nextEvent.msg.osc.oscState; - chan = seqp->nextEvent.msg.osc.chan; - delta = (*seqp->updateOsc)(oscState,&oscValue); - vs->vibrato = oscValue; - alSynSetPitch(seqp->drvr, &vs->voice, vs->pitch * vs->vibrato - * seqp->chanState[chan].pitchBend); - evt.type = AL_VIB_OSC_EVT; - evt.msg.osc.vs = vs; - evt.msg.osc.oscState = oscState; - evt.msg.osc.chan = chan; - alEvtqPostEvent(&seqp->evtq, &evt, delta); - break; - - case (AL_SEQP_MIDI_EVT): - case (AL_CSP_NOTEOFF_EVT): /* nextEvent is a note off midi message */ - __CSPHandleMIDIMsg(seqp, &seqp->nextEvent); - break; - - case (AL_SEQP_META_EVT): - __CSPHandleMetaMsg(seqp, &seqp->nextEvent); - break; - - case (AL_SEQP_VOL_EVT): - seqp->vol = seqp->nextEvent.msg.spvol.vol; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - alSynSetVol(seqp->drvr, &vs->voice, - __vsVol(vs, (ALSeqPlayer*)seqp), - __vsDelta(vs, seqp->curTime)); - } - break; - - case (AL_SEQP_PLAY_EVT): - if (seqp->state != AL_PLAYING) - { - seqp->state = AL_PLAYING; - __CSPPostNextSeqEvent(seqp); /* seqp must be AL_PLAYING before we call this routine. */ - } - break; - - case (AL_SEQP_STOP_EVT): - if ( seqp->state == AL_STOPPING ) - { - for (vs = seqp->vAllocHead; vs != 0; vs = seqp->vAllocHead) - { -#ifdef _DEBUG - __osError(ERR_ALCSPVNOTFREE, 2, vs->channel, vs->key); -#endif - alSynStopVoice(seqp->drvr, &vs->voice); - alSynFreeVoice(seqp->drvr, &vs->voice); - if(vs->flags) - __seqpStopOsc((ALSeqPlayer*)seqp,vs); - __unmapVoice((ALSeqPlayer*)seqp, &vs->voice); - } - seqp->state = AL_STOPPED; - - /* alEvtqFlush(&seqp->evtq); - Don't flush event queue - anymore. */ - /* sct 1/3/96 - Don't overwrite nextEvent with - AL_SEQP_API_EVT or set nextDelta to - AL_USEC_PER_FRAME since we're not stopping event - processing. */ - /* sct 1/3/96 - Don't return here since we keep - processing events as usual. */ - } - break; - - case (AL_SEQP_STOPPING_EVT): - if (seqp->state == AL_PLAYING) - { - /* sct 12/29/95 - Remove events associated with the - * stopping sequence. For compact sequence player, - * also remove all queued note off events since they - * are not contained in a compact sequence but are - * generated in response to note ons. Note that - * flushing AL_SEQP_MIDI_EVTs may flush events that - * were posted after the call to alSeqpStop, so the - * application must queue these events either when - * the player is fully stopped, or when it is - * playing. */ - alEvtqFlushType(&seqp->evtq, AL_SEQ_REF_EVT); - alEvtqFlushType(&seqp->evtq, AL_CSP_NOTEOFF_EVT); - alEvtqFlushType(&seqp->evtq, AL_SEQP_MIDI_EVT); - - /* sct 1/3/96 - Check to see which voices need to be - killed and release them. */ - /* Unkilled voices should have note end events - occurring prior to KILL_TIME. */ - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (__voiceNeedsNoteKill ((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME)) - __seqpReleaseVoice((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME); - } - - seqp->state = AL_STOPPING; - evt.type = AL_SEQP_STOP_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); - } - break; - - case (AL_SEQP_PRIORITY_EVT): - chan = seqp->nextEvent.msg.sppriority.chan; - seqp->chanState[chan].priority = seqp->nextEvent.msg.sppriority.priority; - break; - - case (AL_SEQP_SEQ_EVT): -#if BUILD_VERSION < VERSION_J -#line 294 -#endif - assert(seqp->state != AL_PLAYING); /* Must be done playing to change sequences. */ - - seqp->target = seqp->nextEvent.msg.spseq.seq; - __setUsptFromTempo (seqp, 500000.0); - if (seqp->bank) - __initFromBank((ALSeqPlayer *)seqp, seqp->bank); - break; - - case (AL_SEQP_BANK_EVT): -#if BUILD_VERSION < VERSION_J -#line 303 -#endif - assert(seqp->state == AL_STOPPED); /* Must be fully stopped to change banks. */ - - seqp->bank = seqp->nextEvent.msg.spbank.bank; - __initFromBank((ALSeqPlayer *)seqp, seqp->bank); - break; - - /* sct 11/6/95 - these events should now be handled by __CSPHandleNextSeqEvent */ - case (AL_SEQ_END_EVT): - case (AL_TEMPO_EVT): - case (AL_SEQ_MIDI_EVT): -#if BUILD_VERSION < VERSION_J -#line 313 -#endif - assert(FALSE); - - break; - } - seqp->nextDelta = alEvtqNextEvent(&seqp->evtq, &seqp->nextEvent); - - } while (seqp->nextDelta == 0); - - /* - * assume that next callback won't be more than half an - * hour away - */ - seqp->curTime += seqp->nextDelta; /* sct 11/7/95 */ - return seqp->nextDelta; -} - -/* - Calculates the delta time in ticks until the next sequence - event and posts a sequence reference event with the time in usecs. - Loops are handled automatically by the compact sequence. - - Does nothing if the sequence player is not playing or if there - is no target sequence. - - sct 11/7/95 -*/ -void __CSPPostNextSeqEvent(ALCSPlayer *seqp) -{ - ALEvent evt; - s32 deltaTicks; - - if (seqp->state != AL_PLAYING || seqp->target == NULL) - return; - - /* Get the next event time in ticks. */ - /* If false is returned, then there is no next delta (ie. end of sequence reached). */ - if (!__alCSeqNextDelta(seqp->target, &deltaTicks)) - return; - - evt.type = AL_SEQ_REF_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt); -} - - -/* - Call this routine to handle the next event in the sequence. - Assumes that the next sequence event is scheduled to be processed - immediately since it does not check the event's tick time. - - sct 11/7/95 -*/ -static void -__CSPHandleNextSeqEvent(ALCSPlayer *seqp) -{ - ALEvent evt; - - /* sct 1/5/96 - Do nothing if we don't have a target sequence. */ - if (seqp->target == NULL) - return; - - alCSeqNextEvent(seqp->target, &evt); - - switch (evt.type) - { - case AL_SEQ_MIDI_EVT: - __CSPHandleMIDIMsg(seqp, &evt); - __CSPPostNextSeqEvent(seqp); - break; - - case AL_TEMPO_EVT: - __CSPHandleMetaMsg(seqp, &evt); - __CSPPostNextSeqEvent(seqp); - break; - - case AL_SEQ_END_EVT: - seqp->state = AL_STOPPING; - evt.type = AL_SEQP_STOP_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); - break; - - case AL_TRACK_END: - case AL_CSP_LOOPSTART: - case AL_CSP_LOOPEND: - __CSPPostNextSeqEvent(seqp); - break; - - default: -#if BUILD_VERSION < VERSION_J -#line 399 -#endif - assert(FALSE); /* Sequence event type not supported. */ -#if BUILD_VERSION >= VERSION_J - break; -#endif - } -} - -static void __CSPHandleMIDIMsg(ALCSPlayer *seqp, ALEvent *event) -{ - ALVoice *voice; - ALVoiceState *vs; - s32 status; - u8 chan; - u8 key; - u8 vel; - u8 byte1; - u8 byte2; - ALMIDIEvent *midi = &event->msg.midi; - s16 vol; - ALEvent evt; - ALMicroTime deltaTime; - ALVoiceState *vstate; - ALPan pan; - ALFxRef fxref; - - - status = midi->status & AL_MIDI_StatusMask; - chan = midi->status & AL_MIDI_ChannelMask; - byte1 = key = midi->byte1; - byte2 = vel = midi->byte2; - - switch (status) - { - case (AL_MIDI_NoteOn): - - if (vel != 0) /* a real note on */ - { - ALVoiceConfig config; - ALSound *sound; - s16 cents; - f32 pitch,oscValue; - u8 fxmix; - void *oscState; - ALInstrument *inst; - - /* If we're not playing, don't process note ons. */ - if (seqp->state != AL_PLAYING) - break; - - sound = __lookupSoundQuick((ALSeqPlayer*)seqp, key, vel, chan); - ALFlagFailIf(!sound, seqp->debugFlags & NO_SOUND_ERR_MASK, - ERR_ALSEQP_NO_SOUND); - - config.priority = seqp->chanState[chan].priority; - config.fxBus = 0; - config.unityPitch = 0; - - vstate = __mapVoice((ALSeqPlayer*)seqp, key, vel, chan); - ALFlagFailIf(!vstate, seqp->debugFlags & NO_VOICE_ERR_MASK, - ERR_ALSEQP_NO_VOICE ); - - voice = &vstate->voice; - - alSynAllocVoice(seqp->drvr, voice, &config); - - /* - * set up the voice state structure - */ - vstate->sound = sound; - vstate->envPhase = AL_PHASE_ATTACK; - if (seqp->chanState[chan].sustain > AL_SUSTAIN) - vstate->phase = AL_PHASE_SUSTAIN; - else - vstate->phase = AL_PHASE_NOTEON; - - cents = (key - sound->keyMap->keyBase) * 100 - + sound->keyMap->detune; - - vstate->pitch = alCents2Ratio(cents); - vstate->envGain = sound->envelope->attackVolume; - vstate->envEndTime = seqp->curTime + - sound->envelope->attackTime; - - /* - * setup tremelo and vibrato if active - */ - vstate->flags = 0; - inst = seqp->chanState[chan].instrument; - - oscValue = (f32)AL_VOL_FULL; /* set this as a default */ - if(inst->tremType) - { - if(seqp->initOsc) - { - deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->tremType, - inst->tremRate,inst->tremDepth,inst->tremDelay); - - if(deltaTime) /* a deltaTime of zero means don't run osc */ - { - evt.type = AL_TREM_OSC_EVT; - evt.msg.osc.vs = vstate; - evt.msg.osc.oscState = oscState; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - vstate->flags |= 0x01; /* set tremelo flag bit */ - } - } - } - vstate->tremelo = (u8)oscValue; /* will default if not changed by initOsc */ - - oscValue = 1.0f; /* set this as a default */ - if(inst->vibType) - { - if(seqp->initOsc) - { - deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->vibType, - inst->vibRate,inst->vibDepth,inst->vibDelay); - - if(deltaTime) /* a deltaTime of zero means don't run osc. */ - { - evt.type = AL_VIB_OSC_EVT; - evt.msg.osc.vs = vstate; - evt.msg.osc.oscState = oscState; - evt.msg.osc.chan = chan; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - vstate->flags |= 0x02; /* set the vibrato flag bit */ - } - } - } - vstate->vibrato = oscValue; /* will default if not changed by initOsc */ - - /* - * calculate the note on parameters - */ - pitch = vstate->pitch * seqp->chanState[chan].pitchBend * - vstate->vibrato; - fxmix = seqp->chanState[chan].fxmix; - pan = __vsPan(vstate, (ALSeqPlayer*)seqp); - vol = __vsVol(vstate, (ALSeqPlayer*)seqp); - deltaTime = sound->envelope->attackTime; - - alSynStartVoiceParams(seqp->drvr, voice, sound->wavetable, - pitch, vol, pan, fxmix, deltaTime); - /* - * set up callbacks for envelope - */ - evt.type = AL_SEQP_ENV_EVT; - evt.msg.vol.voice = voice; - evt.msg.vol.vol = sound->envelope->decayVolume; - evt.msg.vol.delta = sound->envelope->decayTime; - - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - - if(midi->duration) - { - /* - * set up note off evt. if no duration don't do this - */ - evt.type = AL_CSP_NOTEOFF_EVT; - evt.msg.midi.status = chan | AL_MIDI_NoteOff; - evt.msg.midi.byte1 = key; - evt.msg.midi.byte2 = 0; /* not needed ? */ - deltaTime = seqp->uspt * midi->duration; - - /* max time would be about one hour ten minutes */ - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - } - - break; - } - - /* - * NOTE: intentional fall-through for note on with zero - * velocity (Should never happen with compact midi sequence, - * but could happen with real time midi.) - */ - - case (AL_MIDI_NoteOff): - vstate = __lookupVoice((ALSeqPlayer*)seqp, key, chan); - ALFlagFailIf(!vstate, seqp->debugFlags & NOTE_OFF_ERR_MASK, - ERR_ALSEQP_OFF_VOICE ); - - if (vstate->phase == AL_PHASE_SUSTAIN) - vstate->phase = AL_PHASE_SUSTREL; - else - { - vstate->phase = AL_PHASE_RELEASE; - __seqpReleaseVoice((ALSeqPlayer*)seqp, &vstate->voice, - vstate->sound->envelope->releaseTime); - } - - break; - - case (AL_MIDI_PolyKeyPressure): - /* - * Aftertouch per key (hardwired to volume). Note that - * aftertouch affects only notes that are already - * sounding. - */ - vstate = __lookupVoice((ALSeqPlayer*)seqp, key, chan); - ALFailIf(!vstate, ERR_ALSEQP_POLY_VOICE ); - - vstate->velocity = byte2; - alSynSetVol(seqp->drvr, &vstate->voice, - __vsVol(vstate, (ALSeqPlayer*)seqp), - __vsDelta(vstate,seqp->curTime)); - break; - - case (AL_MIDI_ChannelPressure): - /* - * Aftertouch per channel (hardwired to volume). Note that - * aftertouch affects only notes that are already - * sounding. - */ - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if (vs->channel == chan) { - vs->velocity = byte1; - alSynSetVol(seqp->drvr, &vs->voice, - __vsVol(vs, (ALSeqPlayer*)seqp), - __vsDelta(vs,seqp->curTime)); - } - } - break; - - case (AL_MIDI_ControlChange): - switch (byte1) - { - case (AL_MIDI_PAN_CTRL): - seqp->chanState[chan].pan = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel == chan) - { - pan = __vsPan(vs, (ALSeqPlayer*)seqp); - alSynSetPan(seqp->drvr, &vs->voice, pan); - } - } - break; - case (AL_MIDI_VOLUME_CTRL): - seqp->chanState[chan].vol = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE)) - { - vol = __vsVol(vs, (ALSeqPlayer*)seqp); - alSynSetVol(seqp->drvr, &vs->voice, vol, - __vsDelta(vs,seqp->curTime)); - } - } - break; - case (AL_MIDI_PRIORITY_CTRL): - /* leave current voices where they are */ - seqp->chanState[chan].priority = byte2; - break; - case (AL_MIDI_SUSTAIN_CTRL): - seqp->chanState[chan].sustain = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if ((vs->channel == chan) && (vs->phase != AL_PHASE_RELEASE)) - { - if ( byte2 > AL_SUSTAIN ) - { - /* - * sustain pedal down - */ - if (vs->phase == AL_PHASE_NOTEON) - vs->phase = AL_PHASE_SUSTAIN; - } - else - { - /* - * sustain pedal up - */ - if (vs->phase == AL_PHASE_SUSTAIN) - vs->phase = AL_PHASE_NOTEON; - - else if(vs->phase == AL_PHASE_SUSTREL) - { - vs->phase = AL_PHASE_RELEASE; - __seqpReleaseVoice((ALSeqPlayer*)seqp, - &vs->voice, - vs->sound->envelope->releaseTime); - } - } - } - } - break; - case (AL_MIDI_FX1_CTRL): - seqp->chanState[chan].fxmix = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel == chan) - alSynSetFXMix(seqp->drvr, &vs->voice, byte2); - } - break; -/* case (AL_MIDI_FX_CTRL_0): - case (AL_MIDI_FX_CTRL_1): - case (AL_MIDI_FX_CTRL_2): - case (AL_MIDI_FX_CTRL_3): - case (AL_MIDI_FX_CTRL_4): - case (AL_MIDI_FX_CTRL_5): - case (AL_MIDI_FX_CTRL_6): - case (AL_MIDI_FX_CTRL_7): - fxref = alSynGetFXRef(seqp->drvr, 0, 0); - if (fxref) - alSynSetFXParam(seqp->drvr, fxref, (s16)byte1, (void *)byte2); - break; - case (AL_MIDI_FX3_CTRL): */ - default: - break; - } - break; - case (AL_MIDI_ProgramChange): - /* sct 1/16/96 - We must have a valid bank in order to process the program change. */ -#if BUILD_VERSION < VERSION_J -#line 710 -#endif - assert(seqp->bank != NULL); - - if (key < seqp->bank->instCount) - { - ALInstrument *inst = seqp->bank->instArray[key]; - __setInstChanState((ALSeqPlayer*)seqp, inst, chan); /* sct 11/6/95 */ - } - else - { -#ifdef _DEBUG - __osError(ERR_ALSEQPINVALIDPROG, 2, key, seqp->bank->instCount); -#endif - } - break; - case (AL_MIDI_PitchBendChange): - { - s32 bendVal; - f32 bendRatio; - s32 cents; - - /* get 14-bit unsigned midi value */ - bendVal = ( (byte2 << 7) + byte1) - 8192; - - /* calculate pitch bend in cents */ - cents = (seqp->chanState[chan].bendRange * bendVal)/8192; - - /* calculate the corresponding ratio */ - bendRatio = alCents2Ratio(cents); - seqp->chanState[chan].pitchBend = bendRatio; - - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - if (vs->channel == chan) - alSynSetPitch(seqp->drvr, &vs->voice, - vs->pitch * bendRatio * vs->vibrato); - - } - break; - - default: -#ifdef _DEBUG - __osError(ERR_ALSEQPUNKNOWNMIDI, 1, status); -#endif - break; - } - -} - -static void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event) -{ - ALTempoEvent *tevt = &event->msg.tempo; - ALEvent evt; - s32 tempo; - s32 oldUspt; - u32 ticks; - ALMicroTime tempDelta,curDelta = 0; - ALEventListItem *thisNode,*nextNode,*firstTemp = 0; - - - if (event->msg.tempo.status == AL_MIDI_Meta) - { - if (event->msg.tempo.type == AL_MIDI_META_TEMPO) - { - oldUspt = seqp->uspt; - tempo = (tevt->byte1 << 16) | (tevt->byte2 << 8) | (tevt->byte3 << 0); - __setUsptFromTempo (seqp, (f32)tempo); /* sct 1/8/96 */ - - thisNode = (ALEventListItem*)seqp->evtq.allocList.next; - while(thisNode) - { - curDelta += thisNode->delta; - nextNode = (ALEventListItem*)thisNode->node.next; - if(thisNode->evt.type == AL_CSP_NOTEOFF_EVT) - { - alUnlink((ALLink*)thisNode); - - if(firstTemp) - alLink((ALLink*)thisNode,(ALLink*)firstTemp); - else - { - thisNode->node.next = 0; - thisNode->node.prev = 0; - firstTemp = thisNode; - } - tempDelta = curDelta; /* record the current delta */ - if(nextNode) /* don't do this if no nextNode */ - { - curDelta -= thisNode->delta; /* subtract out this delta */ - nextNode->delta += thisNode->delta; /* add it to next event */ - } - thisNode->delta = tempDelta; /* set this event delta from current */ - } - thisNode = nextNode; - } - - thisNode = firstTemp; - while(thisNode) - { - nextNode = (ALEventListItem*)thisNode->node.next; - ticks = thisNode->delta/oldUspt; - thisNode->delta = ticks * seqp->uspt; - __CSPRepostEvent(&seqp->evtq,thisNode); - thisNode = nextNode; - } - } - } -} - -static void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item) -{ - OSIntMask mask; - ALLink *node; - ALEventListItem *nextItem; - - mask = osSetIntMask(OS_IM_NONE); - - for (node = &evtq->allocList; node != 0; node = node->next) - { - if (!node->next) /* end of the list */ - { - alLink((ALLink *)item, node); - break; - } - else - { - nextItem = (ALEventListItem *)node->next; - if (item->delta < nextItem->delta) - { - nextItem->delta -= item->delta; - alLink((ALLink *)item, node); - break; - } - item->delta -= nextItem->delta; - } - } - osSetIntMask(mask); -} - - -/* - This routine safely calculates the sequence player's - uspt value based on the given tempo. It does this safely - by making sure that the player has a target sequence and - therefore a qnpt value which is needed for the calculation. - - Compact sequence player needs its own version of this routine - since the ALCSeq's qnpt field is at a different offset. -*/ -static void __setUsptFromTempo (ALCSPlayer *seqp, f32 tempo) -{ - if (seqp->target) - seqp->uspt = (s32)((f32)tempo * seqp->target->qnpt); - else - seqp->uspt = 488; /* This is the initial value set by alSeqpNew. */ -} - diff --git a/lib/ultralib/src/audio/cspplay.c b/lib/ultralib/src/audio/cspplay.c deleted file mode 100644 index e34914c..0000000 --- a/lib/ultralib/src/audio/cspplay.c +++ /dev/null @@ -1,34 +0,0 @@ -/*==================================================================== - * cspplay.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include "cseqp.h" - -void alCSPPlay(ALCSPlayer *seqp) -{ - ALEvent evt; - - evt.type = AL_SEQP_PLAY_EVT; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsendmidi.c b/lib/ultralib/src/audio/cspsendmidi.c deleted file mode 100644 index 3d03c9b..0000000 --- a/lib/ultralib/src/audio/cspsendmidi.c +++ /dev/null @@ -1,40 +0,0 @@ -/*==================================================================== - * cspsendmidi.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSendMidi(ALCSPlayer *seqp, s32 ticks, u8 status, u8 byte1, - u8 byte2) -{ - ALEvent evt; - ALMicroTime deltaTime; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = status; - evt.msg.midi.byte1 = byte1; - evt.msg.midi.byte2 = byte2; - evt.msg.midi.duration = 0; - - deltaTime = ticks*seqp->uspt; - - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); -} - diff --git a/lib/ultralib/src/audio/cspsetbank.c b/lib/ultralib/src/audio/cspsetbank.c deleted file mode 100644 index 63292b4..0000000 --- a/lib/ultralib/src/audio/cspsetbank.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * cspsetbank.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetBank(ALCSPlayer *seqp, ALBank *b) -{ - ALEvent evt; - - evt.type = AL_SEQP_BANK_EVT; - evt.msg.spbank.bank = b; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsetchlvol.c b/lib/ultralib/src/audio/cspsetchlvol.c deleted file mode 100644 index 28e62bb..0000000 --- a/lib/ultralib/src/audio/cspsetchlvol.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * cspsetchlvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol) -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ControlChange | chan; - evt.msg.midi.byte1 = AL_MIDI_VOLUME_CTRL; - evt.msg.midi.byte2 = vol; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsetfxmix.c b/lib/ultralib/src/audio/cspsetfxmix.c deleted file mode 100644 index f099297..0000000 --- a/lib/ultralib/src/audio/cspsetfxmix.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * cspsetfxmix.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetChlFXMix(ALCSPlayer *seqp, u8 chan, u8 fxmix) -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ControlChange | chan; - evt.msg.midi.byte1 = AL_MIDI_FX1_CTRL; - evt.msg.midi.byte2 = fxmix; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsetpan.c b/lib/ultralib/src/audio/cspsetpan.c deleted file mode 100644 index c0dab00..0000000 --- a/lib/ultralib/src/audio/cspsetpan.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * cspsetpan.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan) -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ControlChange | chan; - evt.msg.midi.byte1 = AL_MIDI_PAN_CTRL; - evt.msg.midi.byte2 = pan; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsetpriority.c b/lib/ultralib/src/audio/cspsetpriority.c deleted file mode 100644 index b449b82..0000000 --- a/lib/ultralib/src/audio/cspsetpriority.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * cspsetpriority.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetChlPriority(ALCSPlayer *seqp, u8 chan, u8 priority) -{ - ALEvent evt; - - evt.type = AL_SEQP_PRIORITY_EVT; - evt.msg.sppriority.chan = chan; - evt.msg.sppriority.priority = priority; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} diff --git a/lib/ultralib/src/audio/cspsetprogram.c b/lib/ultralib/src/audio/cspsetprogram.c deleted file mode 100644 index 2b19e63..0000000 --- a/lib/ultralib/src/audio/cspsetprogram.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * cspsetprogram.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetChlProgram(ALCSPlayer *seqp, u8 chan, u8 prog) -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ProgramChange | chan; - evt.msg.midi.byte1 = prog; - evt.msg.midi.byte2 = 0; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsetseq.c b/lib/ultralib/src/audio/cspsetseq.c deleted file mode 100644 index 4b6718e..0000000 --- a/lib/ultralib/src/audio/cspsetseq.c +++ /dev/null @@ -1,34 +0,0 @@ -/*==================================================================== - * cspsetseq.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq) -{ - ALEvent evt; - - evt.type = AL_SEQP_SEQ_EVT; - evt.msg.spseq.seq = seq; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsettempo.c b/lib/ultralib/src/audio/cspsettempo.c deleted file mode 100644 index b085b45..0000000 --- a/lib/ultralib/src/audio/cspsettempo.c +++ /dev/null @@ -1,36 +0,0 @@ -/*==================================================================== - * cspsettempo.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo) -{ - ALEvent evt; - - evt.type = AL_SEQP_META_EVT; - evt.msg.tempo.status = AL_MIDI_Meta; - evt.msg.tempo.type = AL_MIDI_META_TEMPO; - evt.msg.tempo.byte1 = (tempo & 0xff0000)>>16; - evt.msg.tempo.byte2 = (tempo & 0xff00)>>8; - evt.msg.tempo.byte3 = tempo & 0xff; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspsetvol.c b/lib/ultralib/src/audio/cspsetvol.c deleted file mode 100644 index 6782f33..0000000 --- a/lib/ultralib/src/audio/cspsetvol.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * cspsetvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPSetVol(ALCSPlayer *seqp, s16 vol) -{ - ALEvent evt; - - evt.type = AL_SEQP_VOL_EVT; - evt.msg.spvol.vol = vol; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/cspstop.c b/lib/ultralib/src/audio/cspstop.c deleted file mode 100644 index 9929820..0000000 --- a/lib/ultralib/src/audio/cspstop.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * cspstop.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alCSPStop(ALCSPlayer *seqp) -{ - ALEvent evt; - - evt.type = AL_SEQP_STOPPING_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/drvrnew.c b/lib/ultralib/src/audio/drvrnew.c deleted file mode 100644 index 7ca2e10..0000000 --- a/lib/ultralib/src/audio/drvrnew.c +++ /dev/null @@ -1,303 +0,0 @@ -/*==================================================================== - * drvrNew.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -#include -#include "synthInternals.h" -#include -#include -#include "initfx.h" -// TODO: this comes from a header -#ident "$Revision: 1.49 $" -/* - * WARNING: THE FOLLOWING CONSTANT MUST BE KEPT IN SYNC - * WITH SCALING IN MICROCODE!!! - */ -#define SCALE 16384 - -/* - * the following arrays contain default parameters for - * a few hopefully useful effects. - */ -#define ms *(((s32)((f32)44.1))&~0x7) - - -static s32 SMALLROOM_PARAMS[26] = { - /* sections length */ - 3, 100 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 54 ms, 9830, -9830, 0, 0, 0, 0, - 19 ms, 38 ms, 3276, -3276, 0x3fff, 0, 0, 0, - 0, 60 ms, 5000, 0, 0, 0, 0, 0x5000 -}; - -static s32 BIGROOM_PARAMS[34] = { - /* sections length */ - 4, 100 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 66 ms, 9830, -9830, 0, 0, 0, 0, - 22 ms, 54 ms, 3276, -3276, 0x3fff, 0, 0, 0, - 66 ms, 91 ms, 3276, -3276, 0x3fff, 0, 0, 0, - 0, 94 ms, 8000, 0, 0, 0, 0, 0x5000 -}; - -static s32 ECHO_PARAMS[10] = { - /* sections length */ - 1, 200 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 179 ms, 12000, 0, 0x7fff, 0, 0, 0 -}; - -static s32 CHORUS_PARAMS[10] = { - /* sections length */ - 1, 20 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 5 ms, 0x4000, 0, 0x7fff, 7600, 700, 0 -}; - -static s32 FLANGE_PARAMS[10] = { - /* sections length */ - 1, 20 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 5 ms, 0, 0x5fff, 0x7fff, 380, 500, 0 -}; - -static s32 NULL_PARAMS[10] = { - 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - - -void _init_lpfilter(ALLowPass *lp) -{ - s32 i, temp; - s16 fc; - f64 ffc, fcoef; - - temp = lp->fc * SCALE; - fc = temp >> 15; - lp->fgain = SCALE - fc; - - lp->first = 1; - for (i=0; i<8; i++) - lp->fcvec.fccoef[i] = 0; - - lp->fcvec.fccoef[i++] = fc; - fcoef = ffc = (f64)fc/SCALE; - - for (; i<16; i++){ - fcoef *= ffc; - lp->fcvec.fccoef[i] = (s16)(fcoef * SCALE); - } -} - - -void alFxNew(ALFx *r, ALSynConfig *c, ALHeap *hp) -{ - u16 i, j, k; - s32 *param = 0; - ALFilter *f = (ALFilter *) r; - ALDelay *d; - - alFilterNew(f, 0, alFxParam, AL_FX); - f->handler = alFxPull; - r->paramHdl = (ALSetFXParam)alFxParamHdl; - - switch (c->fxType) { - case AL_FX_SMALLROOM: param = SMALLROOM_PARAMS; break; - case AL_FX_BIGROOM: param = BIGROOM_PARAMS; break; - case AL_FX_ECHO: param = ECHO_PARAMS; break; - case AL_FX_CHORUS: param = CHORUS_PARAMS; break; - case AL_FX_FLANGE: param = FLANGE_PARAMS; break; - case AL_FX_CUSTOM: param = c->params; break; - default: param = NULL_PARAMS; break; - } - - - j = 0; - - r->section_count = param[j++]; - r->length = param[j++]; - - r->delay = alHeapAlloc(hp, r->section_count, sizeof(ALDelay)); - r->base = alHeapAlloc(hp, r->length, sizeof(s16)); - r->input = r->base; - - for ( k=0; k < r->length; k++) - r->base[k] = 0; - - for ( i=0; isection_count; i++ ){ - d = &r->delay[i]; - d->input = param[j++]; - d->output = param[j++]; - d->fbcoef = param[j++]; - d->ffcoef = param[j++]; - d->gain = param[j++]; - - if (param[j]) { -#define RANGE 2.0 -/* d->rsinc = ((f32) param[j++])/0xffffff; */ - d->rsinc = ((((f32)param[j++])/1000) * RANGE)/c->outputRate; - - /* - * the following constant is derived from: - * - * ratio = 2^(cents/1200) - * - * and therefore for hundredths of a cent - * x - * ln(ratio) = --------------- - * (120,000)/ln(2) - * where - * 120,000/ln(2) = 173123.40... - */ -#define CONVERT 173123.404906676 -#define LENGTH (d->output - d->input) - d->rsgain = (((f32) param[j++])/CONVERT) * LENGTH; - d->rsval = 1.0; - d->rsdelta = 0.0; - d->rs = alHeapAlloc(hp, 1, sizeof(ALResampler)); - d->rs->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); - d->rs->delta = 0.0; - d->rs->first = 1; - } else { - d->rs = 0; - j++; - j++; - } - - if (param[j]) { - d->lp = alHeapAlloc(hp, 1, sizeof(ALLowPass)); - d->lp->fstate = alHeapAlloc(hp, 1, sizeof(POLEF_STATE)); - d->lp->fc = param[j++]; - _init_lpfilter(d->lp); - } else { - d->lp = 0; - j++; - } - } -} - -void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp) -{ - alFilterNew((ALFilter *) e, alEnvmixerPull, alEnvmixerParam, AL_ENVMIX); - - e->state = alHeapAlloc(hp, 1, sizeof(ENVMIX_STATE)); - - e->first = 1; - e->motion = AL_STOPPED; - e->volume = 1; - e->ltgt = 1; - e->rtgt = 1; - e->cvolL = 1; - e->cvolR = 1; - e->dryamt = 0; - e->wetamt = 0; - e->lratm = 1; - e->lratl = 0; - e->lratm = 1; - e->lratl = 0; - e->delta = 0; - e->segEnd = 0; - e->pan = 0; - e->ctrlList = 0; - e->ctrlTail = 0; - e->sources = 0; -} - -void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp) -{ - s32 - i; - - /* - * init filter superclass - */ - - alFilterNew((ALFilter *) f, alAdpcmPull, alLoadParam, AL_ADPCM); - - f->state = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); - f->lstate = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); - - f->dma = dmaNew(&f->dmaState); - - /* - * init the adpcm state - */ - f->lastsam = 0; - f->first = 1; - f->memin = 0; -} - -void alResampleNew(ALResampler *r, ALHeap *hp) -{ - alFilterNew((ALFilter *) r, alResamplePull, alResampleParam, AL_RESAMPLE); - - /* - * Init resampler state - */ - r->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); - r->delta = 0.0; - r->first = 1; - r->motion = AL_STOPPED; - r->ratio = 1.0; - r->upitch = 0; - r->ctrlList = 0; - r->ctrlTail = 0; - - /* state in the ucode is initialized by the A_INIT flag */ -} - -void alAuxBusNew(ALAuxBus *m, void *sources, s32 maxSources) -{ - alFilterNew((ALFilter *) m, alAuxBusPull, alAuxBusParam, AL_AUXBUS); - m->sourceCount = 0; - m->maxSources = maxSources; - m->sources = (ALFilter **)sources; -} - -void alMainBusNew(ALMainBus *m, void *sources, s32 maxSources) -{ - alFilterNew((ALFilter *) m, alMainBusPull, alMainBusParam, AL_MAINBUS); - m->sourceCount = 0; - m->maxSources = maxSources; - m->sources = (ALFilter **)sources; -} - -void alSaveNew(ALSave *f) -{ - /* - * init filter superclass - */ - - alFilterNew((ALFilter *) f, alSavePull, alSaveParam, AL_SAVE); - - /* - * init the save state, which is a virtual dram address - */ - - f->dramout = 0; - f->first = 1; - -} - diff --git a/lib/ultralib/src/audio/env.c b/lib/ultralib/src/audio/env.c deleted file mode 100644 index fda20f4..0000000 --- a/lib/ultralib/src/audio/env.c +++ /dev/null @@ -1,591 +0,0 @@ -/*==================================================================== - * envmixer.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -#include -#include "synthInternals.h" -#include -#include -#include -#include -// TODO: these come from headers -#ident "$Revision: 1.49 $" -#ident "$Revision: 1.17 $" -#ifdef AUD_PROFILE -extern u32 cnt_index, env_num, env_cnt, env_max, env_min, lastCnt[]; -extern u32 rate_num, rate_cnt, rate_max, rate_min; -extern u32 vol_num, vol_cnt, vol_max, vol_min; -#endif -#define EQPOWER_LENGTH 128 -static s16 eqpower[ EQPOWER_LENGTH ] = { - 32767, 32764, 32757, 32744, 32727, 32704, - 32677, 32644, 32607, 32564, 32517, 32464, - 32407, 32344, 32277, 32205, 32127, 32045, - 31958, 31866, 31770, 31668, 31561, 31450, - 31334, 31213, 31087, 30957, 30822, 30682, - 30537, 30388, 30234, 30075, 29912, 29744, - 29572, 29395, 29214, 29028, 28838, 28643, - 28444, 28241, 28033, 27821, 27605, 27385, - 27160, 26931, 26698, 26461, 26220, 25975, - 25726, 25473, 25216, 24956, 24691, 24423, - 24151, 23875, 23596, 23313, 23026, 22736, - 22442, 22145, 21845, 21541, 21234, 20924, - 20610, 20294, 19974, 19651, 19325, 18997, - 18665, 18331, 17993, 17653, 17310, 16965, - 16617, 16266, 15913, 15558, 15200, 14840, - 14477, 14113, 13746, 13377, 13006, 12633, - 12258, 11881, 11503, 11122, 10740, 10357, - 9971, 9584, 9196, 8806, 8415, 8023, - 7630, 7235, 6839, 6442, 6044, 5646, - 5246, 4845, 4444, 4042, 3640, 3237, - 2833, 2429, 2025, 1620, 1216, 810, - 405, 0 -}; - -extern f64 __pow(f64, f64); - -/* - * prototypes for private enveloper functions - */ -static Acmd *_pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, - s32 sampleOffset, Acmd *p) ; -static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel); - -static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel); - -/*********************************************************************** - * Enveloper filter public interfaces - ***********************************************************************/ -Acmd *alEnvmixerPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, - Acmd *p) -{ - Acmd *ptr = p; - ALEnvMixer *e = (ALEnvMixer *)filter; - s16 inp; - s32 lastOffset; - s32 thisOffset = sampleOffset; - s32 samples; - s16 loutp = 0; - s32 fVol; - ALParam *thisParam; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - /* - * Force the input to be the resampler output - */ - inp = AL_RESAMPLER_OUT; - - while (e->ctrlList != 0) { - lastOffset = thisOffset; - thisOffset = e->ctrlList->delta; - samples = thisOffset - lastOffset; - if (samples > outCount) - break; -#if BUILD_VERSION < VERSION_J -#line 103 -#endif - assert(samples >= 0); - assert(samples <= AL_MAX_RSP_SAMPLES); - - - switch (e->ctrlList->type) { - case (AL_FILTER_START_VOICE_ALT): - { - ALStartParamAlt *param = (ALStartParamAlt *)e->ctrlList; - ALFilter *f = (ALFilter *) e; - s32 tmp; - - if (param->unity) { - (*e->filter.setParam)(&e->filter, - AL_FILTER_SET_UNITY_PITCH, 0); - } - - (*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE, - param->wave); - (*e->filter.setParam)(&e->filter, AL_FILTER_START, 0); - - e->first = 1; - - e->delta = 0; - e->segEnd = param->samples; - - tmp = ((s32)param->volume * (s32)param->volume) >> 15; - e->volume = (s16) tmp; - e->pan = param->pan; - e->dryamt = eqpower[param->fxMix]; - e->wetamt = eqpower[EQPOWER_LENGTH - param->fxMix - 1]; - - if (param->samples) { - e->cvolL = 1; - e->cvolR = 1; - } else { - /* - * Attack time is zero. Simply set the - * volume. We don't want an attack segment. - */ - e->cvolL = (e->volume * eqpower[e->pan]) >> 15; - e->cvolR = (e->volume * - eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; - } - - if (f->source) { - union { - f32 f; - s32 i; - } data; - data.f = param->pitch; - (*f->source->setParam)(f->source, AL_FILTER_SET_PITCH, - (void *)data.i); - } - - } - - break; - - case (AL_FILTER_SET_FXAMT): - case (AL_FILTER_SET_PAN): - case (AL_FILTER_SET_VOLUME): - ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); - - if (e->delta >= e->segEnd){ - /* - * We should have reached our target, calculate - * target in case e->segEnd was 0 - */ - e->ltgt = (e->volume * eqpower[e->pan]) >> 15; - e->rtgt = (e->volume * - eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; - e->delta = e->segEnd; /* To prevent overflow */ - e->cvolL = e->ltgt; - e->cvolR = e->rtgt; - } else { - /* - * Estimate the current volume - */ - e->cvolL = _getVol(e->cvolL, e->delta, e->lratm, e->lratl); - e->cvolR = _getVol(e->cvolR, e->delta, e->rratm, e->rratl); - } - - /* - * We can't have volume of zero, because the envelope - * would never go anywhere from there - */ - if( e->cvolL == 0 ) e->cvolL = 1; - if( e->cvolR == 0 ) e->cvolR = 1; - - if (e->ctrlList->type == AL_FILTER_SET_PAN) - - /* - * This should result in a change to the current - * segment rate and target - */ - e->pan = (s16) e->ctrlList->data.i; - - if (e->ctrlList->type == AL_FILTER_SET_VOLUME){ - - /* - * Switching to a new segment - */ - e->delta = 0; - - /* - * Map volume non-linearly to give something close to - * loudness - */ - fVol = (e->ctrlList->data.i); - fVol = (fVol*fVol)>>15; - e->volume = (s16) fVol; - - e->segEnd = e->ctrlList->moredata.i; - - } - - if (e->ctrlList->type == AL_FILTER_SET_FXAMT){ - e->dryamt = eqpower[e->ctrlList->data.i]; - e->wetamt = eqpower[EQPOWER_LENGTH - e->ctrlList->data.i - 1]; - } - - /* - * Force a volume update - */ - e->first = 1; - break; - - case (AL_FILTER_START_VOICE): - { - ALStartParam *p = (ALStartParam *)e->ctrlList; - - /* - * Changing to PLAYING (since the previous state was - * persumable STOPPED, we'll just bump the output - * pointer rather than pull a subframe of zeros). - */ - if (p->unity) { - (*e->filter.setParam)(&e->filter, - AL_FILTER_SET_UNITY_PITCH, 0); - } - - (*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE, - p->wave); - (*e->filter.setParam)(&e->filter, AL_FILTER_START, 0); - } - break; - - case (AL_FILTER_STOP_VOICE): - { - /* - * Changing to STOPPED and reset the filter - */ - ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); - (*e->filter.setParam)(&e->filter, AL_FILTER_RESET, 0); - } - break; - - case (AL_FILTER_FREE_VOICE): - { - ALSynth *drvr = &alGlobals->drvr; - ALFreeParam *param = (ALFreeParam *)e->ctrlList; - param->pvoice->offset = 0; - _freePVoice(drvr, (PVoice *)param->pvoice); - } - break; - - default: - /* - * Pull the reuired number of samples and then pass the message - * on down the chain - */ - ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); - (*e->filter.setParam)(&e->filter, e->ctrlList->type, - (void *) e->ctrlList->data.i); - break; - } - loutp += (samples<<1); - outCount -= samples; - - /* - * put the param record back on the free list - */ - thisParam = e->ctrlList; - e->ctrlList = e->ctrlList->next; - if (e->ctrlList == 0) - e->ctrlTail = 0; - - __freeParam(thisParam); - - } - - ptr = _pullSubFrame(e, &inp, &loutp, outCount, sampleOffset, ptr); - - /* - * Prevent overflow in e->delta - */ - if (e->delta > e->segEnd) - e->delta = e->segEnd; - -#ifdef AUD_PROFILE - PROFILE_AUD(env_num, env_cnt, env_max, env_min); -#endif - return ptr; -} - -s32 alEnvmixerParam(void *filter, s32 paramID, void *param) -{ - ALFilter *f = (ALFilter *) filter; - ALEnvMixer *e = (ALEnvMixer *) filter; - - switch (paramID) { - - case (AL_FILTER_ADD_UPDATE): - if (e->ctrlTail) { - e->ctrlTail->next = (ALParam *)param; - } else { - e->ctrlList = (ALParam *)param; - } - e->ctrlTail = (ALParam *)param; - - break; - - case (AL_FILTER_RESET): - e->first = 1; - e->motion = AL_STOPPED; - e->volume = 1; - if (f->source) - (*f->source->setParam)(f->source, AL_FILTER_RESET, param); - break; - - case (AL_FILTER_START): - e->motion = AL_PLAYING; - if (f->source) - (*f->source->setParam)(f->source, AL_FILTER_START, param); - break; - - case (AL_FILTER_SET_SOURCE): - f->source = (ALFilter *) param; - break; - - default: - if (f->source) - (*f->source->setParam)(f->source, paramID, param); - } - return 0; -} -#if BUILD_VERSION < VERSION_J -#line 350 -#endif -static Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, - s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; - ALEnvMixer *e = (ALEnvMixer *)filter; - ALFilter *source= e->filter.source; - - /* filter must be playing and request non-zero output samples to pull. */ - if (e->motion != AL_PLAYING || !outCount) - return ptr; - - /* - * ask all filters upstream from us to build their command - * lists. - */ - - assert(source); - - - ptr = (*source->handler)(source, inp, outCount, sampleOffset, p); - - /* - * construct our portion of the command list - */ - aSetBuffer(ptr++, A_MAIN, *inp, AL_MAIN_L_OUT + *outp, outCount<<1); - aSetBuffer(ptr++, A_AUX, AL_MAIN_R_OUT + *outp, AL_AUX_L_OUT + *outp, - AL_AUX_R_OUT + *outp); - - if (e->first){ - e->first = 0; - - /* - * Calculate derived parameters - */ - e->ltgt = (e->volume * eqpower[e->pan]) >> 15; - e->lratm = _getRate((f64)e->cvolL, (f64)e->ltgt, - e->segEnd, &(e->lratl)); - e->rtgt = (e->volume * - eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; - e->rratm = _getRate((f64)e->cvolR, (f64)e->rtgt, e->segEnd, - &(e->rratl)); - - aSetVolume(ptr++, A_LEFT | A_VOL, e->cvolL, 0, 0); - aSetVolume(ptr++, A_RIGHT | A_VOL, e->cvolR, 0, 0); - aSetVolume(ptr++, A_LEFT | A_RATE, e->ltgt, e->lratm, e->lratl); - aSetVolume(ptr++, A_RIGHT | A_RATE, e->rtgt, e->rratm, e->rratl); - aSetVolume(ptr++, A_AUX, e->dryamt, 0, e->wetamt); - aEnvMixer (ptr++, A_INIT | A_AUX, osVirtualToPhysical(e->state)); - } - else - aEnvMixer(ptr++, A_CONTINUE | A_AUX, osVirtualToPhysical(e->state)); - - /* - * bump the input buffer pointer - */ - - *inp += (outCount<<1); - e->delta += outCount; - - return ptr; -} - -#define EXP_MASK 0x7f800000 -#define MANT_MASK 0x807fffff - -f64 -_frexpf(f64 value, s32 *eptr) -{ - f64 absvalue; - - *eptr = 0; - if (value == 0.0) /* nothing to do for zero */ - return (value); - absvalue = (value > 0.0) ? value : -value; - for ( ; absvalue >= 1.0; absvalue *= 0.5) - ++*eptr; - for ( ; absvalue < 0.5; absvalue += absvalue) - --*eptr; - return (value > 0.0 ? absvalue : -absvalue); -} - -f64 -_ldexpf(f64 in, s32 ex) -{ - s32 exp; - - if ( ex ) { - exp = 1 << ex; - in *= (f64)exp; - } - - return ( in ); -} - -/* - _getRate() -- This function determines how to go from the - current volume level (vol) to the target - volume level (tgt) in some number of steps - (count). Two values are returned that are - used as multipliers to incrementally scale - the volume. Some tricky math is used and - is explained below. - RWW 28jun95 -*/ - -static -s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) -{ - s16 s; - - f64 invn = 1.0/count, eps, a, fs, mant; - s32 i_invn, ex, indx; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - if (count == 0){ - if (tgt >= vol){ - *ratel = 0xffff; - return 0x7fff; - } - else{ - *ratel = 0; - return 0; - } - } - - if (tgt < 1.0) - tgt = 1.0; - if (vol <= 0) vol = 1; /* zero and neg values not allowed */ - -#define NBITS (3) -#define NPOS (1<>= 1; - } - } - - a *= (a *= (a *= a)); - s = (s16) a; - *ratel = (s16)(0xffff * (a - (f32) s)); - -#ifdef AUD_PROFILE - PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min); -#endif - return (s16)a; - -} - -static -f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel) -{ - f32 r, a; - s32 i; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - /* - * Rate values are actually rate^8 - */ - samples >>=3; - if (samples == 0){ - return ivol; - } - r = ((f32) (ratem<<16) + (f32) ratel)/65536; - - a = 1.0; - for (i=0; i<32; i++){ - if( samples & 1 ) - a *= r; - samples >>= 1; - if (samples == 0) - break; - r *= r; - } - ivol *= a; -#ifdef AUD_PROFILE - PROFILE_AUD(vol_num, vol_cnt, vol_max, vol_min); -#endif - return ivol; -} - - - - - - - diff --git a/lib/ultralib/src/audio/event.c b/lib/ultralib/src/audio/event.c deleted file mode 100644 index 3112c99..0000000 --- a/lib/ultralib/src/audio/event.c +++ /dev/null @@ -1,272 +0,0 @@ -/*==================================================================== - * event.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include -#include - - -void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, s32 itemCount) -{ - s32 i; - - evtq->eventCount = 0; - evtq->allocList.next = 0; - evtq->allocList.prev = 0; - evtq->freeList.next = 0; - evtq->freeList.prev = 0; - - for (i = 0; i < itemCount; i++) { - alLink((ALLink *)&items[i], &evtq->freeList); - } -} - -ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt) -{ - ALEventListItem *item; - ALMicroTime delta; - OSIntMask mask; - - mask = osSetIntMask(OS_IM_NONE); - - item = (ALEventListItem *)evtq->allocList.next; - - if (item) - { - alUnlink((ALLink *)item); - alCopy(&item->evt, evt, sizeof(*evt)); - alLink((ALLink *)item, &evtq->freeList); - delta = item->delta; - } - else - { - /* sct 11/28/95 - If we get here, most like we overflowed the event queue */ - /* with non-self-perpetuating events. Eg. if we filled the evtq with volume */ - /* events, then when the seqp is told to play it will handle all the events */ - /* at once completely emptying out the queue. At this point this problem */ - /* must be treated as an out of resource error and the evtq should be increased. */ - evt->type = -1; - delta = 0; - } - - osSetIntMask(mask); - - return delta; -} - -void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, ALMicroTime delta) -{ - ALEventListItem *item; - ALEventListItem *nextItem; - ALLink *node; - s32 postAtEnd=0; - OSIntMask mask; - - mask = osSetIntMask(OS_IM_NONE); - - item = (ALEventListItem *)evtq->freeList.next; - if (!item) { - osSetIntMask(mask); -#ifdef _DEBUG - __osError(ERR_ALEVENTNOFREE, 0); -#endif - return; - } - - alUnlink((ALLink *)item); - alCopy(evt, &item->evt, sizeof(*evt)); - - if (delta == AL_EVTQ_END) - postAtEnd = -1; - - for (node = &evtq->allocList; node != 0; node = node->next) { - if (!node->next) { /* end of the list */ - if (postAtEnd) - item->delta = 0; - else - item->delta = delta; - alLink((ALLink *)item, node); - break; - } else { - nextItem = (ALEventListItem *)node->next; - - if (delta < nextItem->delta) { - item->delta = delta; - nextItem->delta -= delta; - - alLink((ALLink *)item, node); - break; - } - - delta -= nextItem->delta; - - } - } - - osSetIntMask(mask); - -} - -void alEvtqFlush(ALEventQueue *evtq) -{ - ALLink *thisNode; - ALLink *nextNode; - OSIntMask mask; - - mask = osSetIntMask(OS_IM_NONE); - - thisNode = evtq->allocList.next; - while( thisNode != 0 ) { - nextNode = thisNode->next; - alUnlink(thisNode); - alLink(thisNode, &evtq->freeList); - thisNode = nextNode; - } - - osSetIntMask(mask); -} - - -/* - This routine flushes events according their type. -*/ -void alEvtqFlushType(ALEventQueue *evtq, s16 type) -{ - ALLink *thisNode; - ALLink *nextNode; - ALEventListItem *thisItem, *nextItem; - OSIntMask mask; - - mask = osSetIntMask(OS_IM_NONE); - - thisNode = evtq->allocList.next; - while( thisNode != 0 ) - { - nextNode = thisNode->next; - thisItem = (ALEventListItem *)thisNode; - nextItem = (ALEventListItem *)nextNode; - if (thisItem->evt.type == type) - { - if (nextItem) - nextItem->delta += thisItem->delta; - alUnlink(thisNode); - alLink(thisNode, &evtq->freeList); - } - thisNode = nextNode; - } - - osSetIntMask(mask); -} - - -#ifdef _DEBUG_INTERNAL -void alEvtqPrintEvtQueue(ALEventQueue *evtq) -{ - s32 count1 = 0; - s32 count2 = 0; - ALLink *node; - ALEventListItem *item; - - /* count free events */ - for (node = evtq->freeList.next; node != 0; node= node->next) { - count1++; - } - - PRINTF("----- Allocated Events -----\n"); - for (node = evtq->allocList.next; node != 0; node= node->next) { - item = (ALEventListItem *)node; - - PRINTF("\tdelta: %d\ttype %d\n", item->delta, item->evt.type); - count2++; - } - PRINTF("\n"); - - PRINTF("free events\t %d\n", count1); - PRINTF("alloc events\t %d\n", count2); - PRINTF("total events\t %d\n", count1 + count2); -} - -char *MidiStatus2Str (char status, char *str); - -void -alEvtqPrintAllocEvts(ALEventQueue *evtq) -{ - ALLink *node; - ALEventListItem *item; - ALMicroTime itemTime = 0; - char str[32]; - - PRINTF("----- Allocated Events -----\n"); - for (node = evtq->allocList.next; node != 0; node= node->next) - { - item = (ALEventListItem *)node; - itemTime += item->delta; - - PRINTF("\tdelta: %d\tabs: %d\t", item->delta, itemTime); - - switch (item->evt.type) - { - case AL_NOTE_END_EVT: - PRINTF("NOTE_END\tvox: %x\n", item->evt.msg.note.voice); - break; - - case AL_SEQP_MIDI_EVT: - PRINTF("SEQP_MIDI\t%s\n", MidiStatus2Str(item->evt.msg.midi.status & AL_MIDI_StatusMask, str)); - break; - - case AL_SEQP_PRIORITY_EVT: - PRINTF("SEQP_PRIORITY\n"); - break; - - default: - PRINTF("type: %d\n", item->evt.type); - break; - } - - } - PRINTF("\n"); - -} - -char * -MidiStatus2Str (char status, char *str) -{ - switch (status) - { - case AL_MIDI_NoteOn: - sprintf(str, "note on"); - break; - - case AL_MIDI_NoteOff: - sprintf(str, "note off"); - break; - - default: - sprintf(str, "status:%d", status); - break; - } - - return str; -} - -#endif /* _DEBUG_INTERNAL */ - - - diff --git a/lib/ultralib/src/audio/filter.c b/lib/ultralib/src/audio/filter.c deleted file mode 100644 index d88460b..0000000 --- a/lib/ultralib/src/audio/filter.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * filter.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include "synthInternals.h" - -void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type) -{ - f->source = 0; - f->handler = h; - f->setParam = s; - f->inp = 0; - f->outp = 0; - f->type = type; -} diff --git a/lib/ultralib/src/audio/heapalloc.c b/lib/ultralib/src/audio/heapalloc.c deleted file mode 100644 index 8a37808..0000000 --- a/lib/ultralib/src/audio/heapalloc.c +++ /dev/null @@ -1,65 +0,0 @@ -/*==================================================================== - * heapalloc.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include -#include - -void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size) -{ - s32 bytes; - u8 *ptr = 0; - - bytes = (num*size + AL_CACHE_ALIGN) & ~AL_CACHE_ALIGN; - -#ifdef _DEBUG - hp->count++; - bytes += sizeof(HeapInfo); -#endif - - if ((hp->cur + bytes) <= (hp->base + hp->len)) { - - ptr = hp->cur; - hp->cur += bytes; - -#ifdef _DEBUG - ((HeapInfo *)ptr)->magic = AL_HEAP_MAGIC; - ((HeapInfo *)ptr)->size = bytes; - ((HeapInfo *)ptr)->count = hp->count; - if (file) { - ((HeapInfo *)ptr)->file = file; - ((HeapInfo *)ptr)->line = line; - } else { - ((HeapInfo *)ptr)->file = (u8 *) "unknown"; - ((HeapInfo *)ptr)->line = 0; - } - - ptr += sizeof(HeapInfo); -#endif - - } else { -#ifdef _DEBUG - __osError(ERR_ALHEAPNOFREE, 1, size); -#endif - } - - return ptr; -} diff --git a/lib/ultralib/src/audio/heapcheck.c b/lib/ultralib/src/audio/heapcheck.c deleted file mode 100644 index baae643..0000000 --- a/lib/ultralib/src/audio/heapcheck.c +++ /dev/null @@ -1,71 +0,0 @@ -/*==================================================================== - * heapcheck.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include -#include - -#ifdef AUD_PROFILE -#include -extern u32 cnt_index, heap_num, heap_cnt, heap_max, heap_min, lastCnt[]; -#endif - -s32 alHeapCheck(ALHeap *hp) -{ - s32 rv = 0; - HeapInfo *hi; - HeapInfo *last = 0; - u8 *ptr; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - -#ifdef _DEBUG - for (ptr = hp->base; ptr < hp->cur; ptr += hi->size){ - - hi = (HeapInfo *)ptr; - - if ( hi->magic != AL_HEAP_MAGIC) { - if (last) { - __osError(ERR_ALHEAPCORRUPT, 0); - } else { - __osError(ERR_ALHEAPFIRSTBLOCK, 0); - } - - rv = 1; -#ifdef AUD_PROFILE - PROFILE_AUD(heap_num, heap_cnt, heap_max, heap_min); -#endif - return rv; - } - - last = hi; - - } -#endif -#ifdef AUD_PROFILE - PROFILE_AUD(heap_num, heap_cnt, heap_max, heap_min); -#endif - return rv; -} - - diff --git a/lib/ultralib/src/audio/heapinit.c b/lib/ultralib/src/audio/heapinit.c deleted file mode 100644 index 9053375..0000000 --- a/lib/ultralib/src/audio/heapinit.c +++ /dev/null @@ -1,37 +0,0 @@ -/*==================================================================== - * heapinit.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include - -void alHeapInit(ALHeap *hp, u8 *base, s32 len) -{ - s32 extraAlign = (AL_CACHE_ALIGN+1) - ((s32) base & AL_CACHE_ALIGN); - - if (extraAlign != AL_CACHE_ALIGN+1) - hp->base = base + extraAlign; - else - hp->base = base; - - hp->len = len; - hp->cur = hp->base; - hp->count = 0; -} - diff --git a/lib/ultralib/src/audio/initfx.h b/lib/ultralib/src/audio/initfx.h deleted file mode 100644 index 704e1f4..0000000 --- a/lib/ultralib/src/audio/initfx.h +++ /dev/null @@ -1,59 +0,0 @@ -/*==================================================================== - * initfx.h - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#ifndef __initfx__ -#define __initfx__ - -#define MAX_L0 AL_FX_BUFFER_SIZE/4 -#define MAX_L1 AL_FX_BUFFER_SIZE/4 -#define MAX_L2 AL_FX_BUFFER_SIZE/2 - -#define L0_INC MAX_L0/128 -#define L1_INC MAX_L1/128 -#define L2_INC MAX_L2/128 - -#define SMALLROOM_SECT_CNT 3 -#define SMALLROOM_SIZE AL_FX_BUFFER_SIZE -#define SMALLROOM_L0 880 /* 22 ms */ -#define SMALLROOM_C0 9830 -#define SMALLROOM_L1 1400 /* 35 ms */ -#define SMALLROOM_C1 3276 -#define SMALLROOM_L2 2640 /* 66 ms */ -#define SMALLROOM_C2 10000 -#define SMALLROOM_FILT_CNT 1 -#define SMALLROOM_FC0 0x4000 /* .25 */ - -#define BIGROOM_SECT_CNT 3 -#define BIGROOM_SIZE AL_FX_BUFFER_SIZE -#define BIGROOM_L0 1408 /* 32 ms */ -#define BIGROOM_C0 9830 -#define BIGROOM_L1 1984 /* 45 ms */ -#define BIGROOM_C1 9830 -#define BIGROOM_L2 3792 /* 86 ms */ -#define BIGROOM_C2 12000 -#define BIGROOM_FILT_CNT 1 -#define BIGROOM_FC0 0x4000 /* .25 */ - -#define ECHO_SIZE AL_FX_BUFFER_SIZE -#define ECHO_SECT_CNT 1 -#define ECHO_L0 7936 /* 180 ms */ -#define ECHO_C0 0x6000 - -#endif diff --git a/lib/ultralib/src/audio/load.c b/lib/ultralib/src/audio/load.c deleted file mode 100644 index af07075..0000000 --- a/lib/ultralib/src/audio/load.c +++ /dev/null @@ -1,471 +0,0 @@ -/*==================================================================== - * load.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include "synthInternals.h" -#include -#include - -#ifndef MIN -# define MIN(a,b) (((a)<(b))?(a):(b)) -#endif - -#ifdef AUD_PROFILE -extern u32 cnt_index, adpcm_num, adpcm_cnt, adpcm_max, adpcm_min, lastCnt[]; -#endif - -#define ADPCMFBYTES 9 -#define LFSAMPLES 4 - -static -Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags); - -Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; - s16 inp; - s32 tsam; - s32 nframes; - s32 nbytes; - s32 overFlow; - s32 startZero; - s32 nOver; - s32 nSam; - s32 op; - s32 nLeft; - s32 bEnd; - s32 decoded = 0; - s32 looped = 0; - - ALLoadFilter *f = (ALLoadFilter *)filter; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - if (outCount == 0) - return ptr; - - inp = AL_DECODER_IN; - aLoadADPCM(ptr++, f->bookSize, - K0_TO_PHYS(f->table->waveInfo.adpcmWave.book->book)); - - looped = (outCount + f->sample > f->loop.end) && (f->loop.count != 0); - if (looped) - nSam = f->loop.end - f->sample; - else - nSam = outCount; - - if (f->lastsam) - nLeft = ADPCMFSIZE - f->lastsam; - else - nLeft = 0; - tsam = nSam - nLeft; - if (tsam<0) tsam = 0; - - nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; - nbytes = nframes*ADPCMFBYTES; - - if (looped){ - - ptr = _decodeChunk(ptr, f, tsam, nbytes, *outp, inp, f->first); - - /* - * Fix up output pointer, which will be used as the input pointer - * by the following module. - */ - if (f->lastsam) - *outp += (f->lastsam<<1); - else - *outp += (ADPCMFSIZE<<1); - - /* - * Now fix up state info to reflect the loop start point - */ - f->lastsam = f->loop.start &0xf; - f->memin = (s32) f->table->base + ADPCMFBYTES * - ((s32) (f->loop.start>>LFSAMPLES) + 1); - f->sample = f->loop.start; - - bEnd = *outp; - while (outCount > nSam){ - - outCount -= nSam; - - /* - * Put next one after the end of the last lot - on the - * frame boundary (32 byte) after the end. - */ - op = (bEnd + ((nframes+1)<<(LFSAMPLES+1))) & ~0x1f; - - /* - * The actual end of data - */ - bEnd += (nSam<<1); - - /* - * -1 is loop forever - the loop count is not exact now - * for small loops! - */ - if ((f->loop.count != -1) && (f->loop.count != 0)) - f->loop.count--; - - /* - * What's left to compute. - */ - nSam = MIN(outCount, f->loop.end - f->loop.start); - tsam = nSam - ADPCMFSIZE + f->lastsam; - if (tsam<0) tsam = 0; - nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; - nbytes = nframes*ADPCMFBYTES; - ptr = _decodeChunk(ptr, f, tsam, nbytes, op, inp, f->first | A_LOOP); - /* - * Merge the two sections in DMEM. - */ - aDMEMMove(ptr++, op+(f->lastsam<<1), bEnd, nSam<<1); - - } - - f->lastsam = (outCount + f->lastsam) & 0xf; - f->sample += outCount; - f->memin += ADPCMFBYTES*nframes; -#ifdef AUD_PROFILE - PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); -#endif - return ptr; - } - - /* - * The unlooped case, which is executed most of the time - */ - - nSam = nframes<memin + nbytes - ((s32) f->table->base + f->table->len); - if (overFlow < 0) - overFlow = 0; - nOver = (overFlow/ADPCMFBYTES)< nSam + nLeft) - nOver = nSam + nLeft; - - nbytes -= overFlow; - - if ((nOver - (nOver & 0xf))< outCount){ - decoded = 1; - ptr = _decodeChunk(ptr, f, nSam - nOver, nbytes, *outp, inp, f->first); - - if (f->lastsam) - *outp += (f->lastsam<<1); - else - *outp += (ADPCMFSIZE<<1); - - f->lastsam = (outCount + f->lastsam) & 0xf; - f->sample += outCount; - f->memin += ADPCMFBYTES*nframes; - } else { - f->lastsam = 0; - f->memin += ADPCMFBYTES*nframes; - } - - /* - * Put zeros in if necessary - */ - if (nOver){ - f->lastsam = 0; - if (decoded) - startZero = (nLeft + nSam - nOver)<<1; - else - startZero = 0; - aClearBuffer(ptr++, startZero + *outp, nOver<<1); - } -#ifdef AUD_PROFILE - PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); -#endif - - return ptr; -} - -Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; - s32 nbytes; - s32 dramLoc; - s32 dramAlign; - s32 dmemAlign; - s32 overFlow; - s32 startZero; - s32 nSam; - s32 op; - - ALLoadFilter *f = (ALLoadFilter *)filter; - ALFilter *a = (ALFilter *) filter; - - if (outCount == 0) - return ptr; - - if ((outCount + f->sample > f->loop.end) && (f->loop.count != 0)){ - - nSam = f->loop.end - f->sample; - nbytes = nSam<<1; - if (nSam > 0){ - dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); - - /* - * Make sure enough is loaded into DMEM to take care - * of 8 byte alignment - */ - dramAlign = dramLoc & 0x7; - nbytes += dramAlign; - aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7)); - aLoadBuffer(ptr++, dramLoc - dramAlign); - } else - dramAlign = 0; - - /* - * Fix up output pointer to allow for dram alignment - */ - *outp += dramAlign; - - f->memin = (s32) f->table->base + (f->loop.start<<1); - f->sample = f->loop.start; - op = *outp; - - while (outCount > nSam){ - - op += (nSam<<1); - outCount -= nSam; - /* - * -1 is loop forever - */ - if ((f->loop.count != -1) && (f->loop.count != 0)) - f->loop.count--; - - /* - * What to compute. - */ - nSam = MIN(outCount, f->loop.end - f->loop.start); - nbytes = nSam<<1; - - /* - * Do the next section, same as last. - */ - dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); - - /* - * Make sure enough is loaded into DMEM to take care - * of 8 byte alignment - */ - dramAlign = dramLoc & 0x7; - nbytes += dramAlign; - if (op & 0x7) - dmemAlign = 8 - (op & 0x7); - else - dmemAlign = 0; - - aSetBuffer(ptr++, 0, op + dmemAlign, 0, nbytes + 8 - (nbytes & 0x7)); - aLoadBuffer(ptr++, dramLoc - dramAlign); - - /* - * Merge the two sections in DMEM. - */ - if (dramAlign || dmemAlign) - aDMEMMove(ptr++, op+dramAlign+dmemAlign, op, nSam<<1); - - } - - f->sample += outCount; - f->memin += (outCount<<1); - - return ptr; - } - - /* - * The unlooped case, which is executed most of the time - * - * overFlow is the number of bytes past the end - * of the bitstream I try to generate - */ - - nbytes = outCount<<1; - overFlow = f->memin + nbytes - ((s32) f->table->base + f->table->len); - if (overFlow < 0) - overFlow = 0; - if (overFlow > nbytes) - overFlow = nbytes; - - if (overFlow < nbytes){ - if (outCount > 0){ - nbytes -= overFlow; - dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); - - /* - * Make sure enough is loaded into DMEM to take care - * of 8 byte alignment - */ - dramAlign = dramLoc & 0x7; - nbytes += dramAlign; - aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7)); - aLoadBuffer(ptr++, dramLoc - dramAlign); - } else - dramAlign = 0; - *outp += dramAlign; - - f->sample += outCount; - f->memin += outCount<<1; - } else { - f->memin += outCount<<1; - } - - /* - * Put zeros in if necessary - */ - if (overFlow){ - startZero = (outCount<<1) - overFlow; - if (startZero < 0) - startZero = 0; - aClearBuffer(ptr++, startZero + *outp, overFlow); - } - return ptr; -} - - -s32 -alLoadParam(void *filter, s32 paramID, void *param) -{ - ALLoadFilter *a = (ALLoadFilter *) filter; - ALFilter *f = (ALFilter *) filter; - - switch (paramID) { - case (AL_FILTER_SET_WAVETABLE): - a->table = (ALWaveTable *) param; - a->memin = (s32) a->table->base; - a->sample = 0; - switch (a->table->type){ - case (AL_ADPCM_WAVE): - - /* - * Set up the correct handler - */ - f->handler = alAdpcmPull; - - /* - * Make sure the table length is an integer number of - * frames - */ - a->table->len = ADPCMFBYTES * - ((s32) (a->table->len/ADPCMFBYTES)); - - a->bookSize = 2*a->table->waveInfo.adpcmWave.book->order* - a->table->waveInfo.adpcmWave.book->npredictors*ADPCMVSIZE; - if (a->table->waveInfo.adpcmWave.loop) { - a->loop.start = a->table->waveInfo.adpcmWave.loop->start; - a->loop.end = a->table->waveInfo.adpcmWave.loop->end; - a->loop.count = a->table->waveInfo.adpcmWave.loop->count; - alCopy(a->table->waveInfo.adpcmWave.loop->state, - a->lstate, sizeof(ADPCM_STATE)); - } else { - a->loop.start = a->loop.end = a->loop.count = 0; - } - break; - - case (AL_RAW16_WAVE): - f->handler = alRaw16Pull; - if (a->table->waveInfo.rawWave.loop) { - a->loop.start = a->table->waveInfo.rawWave.loop->start; - a->loop.end = a->table->waveInfo.rawWave.loop->end; - a->loop.count = a->table->waveInfo.rawWave.loop->count; - } else { - a->loop.start = a->loop.end = a->loop.count = 0; - } - break; - - default: - break; - - } - break; - - case (AL_FILTER_RESET): - a->lastsam = 0; - a->first = 1; - a->sample = 0; - - /* sct 2/14/96 - Check table since it is initialized to null and */ - /* Get loop info according to table type. */ - if (a->table) - { - a->memin = (s32) a->table->base; - if (a->table->type == AL_ADPCM_WAVE) - { - if (a->table->waveInfo.adpcmWave.loop) - a->loop.count = a->table->waveInfo.adpcmWave.loop->count; - } - else if (a->table->type == AL_RAW16_WAVE) - { - if (a->table->waveInfo.rawWave.loop) - a->loop.count = a->table->waveInfo.rawWave.loop->count; - } - } - - break; - - default: - break; - } -} - -Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags) - -{ - - s32 - dramAlign, - dramLoc; - - if (nbytes > 0){ - dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); - /* - * Make sure enough is loaded into DMEM to take care - * of 8 byte alignment - */ - dramAlign = dramLoc & 0x7; - nbytes += dramAlign; - aSetBuffer(ptr++, 0, inp, 0, nbytes + 8 - (nbytes & 0x7)); - aLoadBuffer(ptr++, dramLoc - dramAlign); - } else - dramAlign = 0; - - if (flags & A_LOOP){ - aSetLoop(ptr++, K0_TO_PHYS(f->lstate)); - } - - aSetBuffer(ptr++, 0, inp + dramAlign, outp, tsam<<1); - aADPCMdec(ptr++, flags, K0_TO_PHYS(f->state)); - f->first = 0; - - return ptr; -} - - - diff --git a/lib/ultralib/src/audio/mainbus.c b/lib/ultralib/src/audio/mainbus.c deleted file mode 100644 index d5c8eca..0000000 --- a/lib/ultralib/src/audio/mainbus.c +++ /dev/null @@ -1,67 +0,0 @@ -/*==================================================================== - * mainbus.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include "synthInternals.h" - -Acmd *alMainBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; - ALMainBus *m = (ALMainBus *)filter; - ALFilter **sources = m->sources; - s32 i; - - /* - * clear the output buffers here - */ - aClearBuffer(ptr++, AL_MAIN_L_OUT, outCount<<1); - aClearBuffer(ptr++, AL_MAIN_R_OUT, outCount<<1); - - for (i = 0; i < m->sourceCount; i++) { - ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset, - ptr); - aSetBuffer(ptr++, 0, 0, 0, outCount<<1); - aMix(ptr++, 0, 0x7fff, AL_AUX_L_OUT, AL_MAIN_L_OUT); - aMix(ptr++, 0, 0x7fff, AL_AUX_R_OUT, AL_MAIN_R_OUT); - } - - return ptr; -} - -s32 alMainBusParam(void *filter, s32 paramID, void *param) -{ - ALMainBus *m = (ALMainBus *) filter; - ALFilter **sources = m->sources; - - switch (paramID) { - - case (AL_FILTER_ADD_SOURCE): - sources[m->sourceCount++] = (ALFilter *) param; - break; - - default: - /* ??? */ - break; - } - - return 0; - -} - diff --git a/lib/ultralib/src/audio/parse_abi.c b/lib/ultralib/src/audio/parse_abi.c deleted file mode 100644 index f1fd37d..0000000 --- a/lib/ultralib/src/audio/parse_abi.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include - -#ifndef _FINALROM -void alParseAbiCL(Acmd *cmdList, u32 nbytes) -{ - guDLPrintCB cntlBlk; - - cntlBlk.dataSize = nbytes; - cntlBlk.flags = 0; - cntlBlk.dlType = GU_PARSE_ABI_TYPE; - cntlBlk.paddr = osVirtualToPhysical(cmdList); - - osWriteHost(&cntlBlk,sizeof(cntlBlk)); - osWriteHost(cmdList,nbytes); - -} - -#endif - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/ultralib/src/audio/resample.c b/lib/ultralib/src/audio/resample.c deleted file mode 100644 index 2baf26f..0000000 --- a/lib/ultralib/src/audio/resample.c +++ /dev/null @@ -1,150 +0,0 @@ -/*==================================================================== - * resample.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include "synthInternals.h" -#include -#include - -// TODO: this comes from a header -#ident "$Revision: 1.49 $" - -#ifdef AUD_PROFILE -extern u32 cnt_index, resampler_num, resampler_cnt, resampler_max, resampler_min, lastCnt[]; -#endif - -/*********************************************************************** - * Resampler filter public interfaces - ***********************************************************************/ -Acmd *alResamplePull(void *filter, s16 *outp, s32 outCnt, s32 sampleOffset, Acmd *p) -{ - ALResampler *f = (ALResampler *)filter; - Acmd *ptr = p; - s16 inp; - s32 inCount; - ALFilter *source = f->filter.source; - s32 incr; - f32 finCount; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - inp = AL_DECODER_OUT; - - if (!outCnt) - return ptr; - - /* - * check if resampler is required - */ - if (f->upitch) { - - ptr = (*source->handler)(source, &inp, outCnt, sampleOffset, p); - aDMEMMove(ptr++, inp, *outp, outCnt<<1); - - } else { - - /* - * clip to maximum allowable pitch - * FIXME: should we check for some minimum as well? - */ - if (f->ratio > MAX_RATIO) f->ratio = MAX_RATIO; - - /* - * quantize the pitch - */ - f->ratio = (s32)(f->ratio * UNITY_PITCH); - f->ratio = f->ratio / UNITY_PITCH; - - /* - * determine how many samples to generate - */ - finCount = f->delta + (f->ratio * (f32) outCnt); - inCount = (s32) finCount; - f->delta = finCount - (f32)inCount; - - /* - * ask all filters upstream from us to build their command - * lists. - */ - ptr = (*source->handler)(source, &inp, inCount, sampleOffset, p); - - /* - * construct our portion of the command list - */ - incr = (s32)(f->ratio * UNITY_PITCH); - aSetBuffer(ptr++, 0, inp, *outp, outCnt<<1); - aResample(ptr++, f->first, incr, osVirtualToPhysical(f->state)); - f->first = 0; - } - -#ifdef AUD_PROFILE - PROFILE_AUD(resampler_num, resampler_cnt, resampler_max, resampler_min); -#endif - return ptr; -} - -s32 alResampleParam(void *filter, s32 paramID, void *param) -{ - ALFilter *f = (ALFilter *) filter; - ALResampler *r = (ALResampler *) filter; - union { - f32 f; - s32 i; - } data; - - switch (paramID) { - - case (AL_FILTER_SET_SOURCE): - f->source = (ALFilter *) param; - break; - - case (AL_FILTER_RESET): - r->delta = 0.0; - r->first = 1; - r->motion = AL_STOPPED; - r->upitch = 0; - if (f->source) - (*f->source->setParam)(f->source, AL_FILTER_RESET, 0); - break; - - case (AL_FILTER_START): - r->motion = AL_PLAYING; - if (f->source) - (*f->source->setParam)(f->source, AL_FILTER_START, 0); - break; - - case (AL_FILTER_SET_PITCH): - data.i = (s32) param; - r->ratio = data.f; - break; - - case (AL_FILTER_SET_UNITY_PITCH): - r->upitch = 1; - break; - - default: - if (f->source) - (*f->source->setParam)(f->source, paramID, param); - break; - } - return 0; -} diff --git a/lib/ultralib/src/audio/reverb.c b/lib/ultralib/src/audio/reverb.c deleted file mode 100644 index f5158c3..0000000 --- a/lib/ultralib/src/audio/reverb.c +++ /dev/null @@ -1,452 +0,0 @@ -/*==================================================================== - * reverb.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -#include -#include -#include "synthInternals.h" -#include -#include -#include -#include -#include "initfx.h" -// TODO: these come from headers -#ident "$Revision: 1.49 $" -#ident "$Revision: 1.17 $" -#define RANGE 2.0 -extern ALGlobals *alGlobals; - -#ifdef AUD_PROFILE -extern u32 cnt_index, reverb_num, reverb_cnt, reverb_max, reverb_min, lastCnt[]; -extern u32 load_num, load_cnt, load_max, load_min, save_num, save_cnt, save_max, save_min; -#endif - -/* - * macros - */ -#define SWAP(in, out) \ -{ \ - s16 t = out; \ - out = in; \ - in = t; \ -} - - -Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p); -Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p); -Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p); -Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p); -f32 _doModFunc(ALDelay *d, s32 count); - -static s32 L_INC[] = { L0_INC, L1_INC, L2_INC }; - -/*********************************************************************** - * Reverb filter public interfaces - ***********************************************************************/ -Acmd *alFxPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, - Acmd *p) -{ - Acmd *ptr = p; - ALFx *r = (ALFx *)filter; - ALFilter *source = r->filter.source; - s16 i, buff1, buff2, input, output; - s16 *in_ptr, *out_ptr, gain, *prev_out_ptr = 0; - ALDelay *d, *pd; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif -#if BUILD_VERSION < VERSION_J -#line 74 -#endif - assert(source); - - /* - * pull channels going into this effect first - */ - ptr = (*source->handler)(source, outp, outCount, sampleOffset, p); - - input = AL_AUX_L_OUT; - output = AL_AUX_R_OUT; - buff1 = AL_TEMP_0; - buff2 = AL_TEMP_1; - - aSetBuffer(ptr++, 0, 0, 0, outCount<<1); /* set the buffer size */ - aMix(ptr++, 0, 0xda83, AL_AUX_L_OUT, input); /* .707L = L - .293L */ - aMix(ptr++, 0, 0x5a82, AL_AUX_R_OUT, input); /* mix the AuxL and AuxR into the AuxL */ - /* and write the mixed value to the delay line at r->input */ - ptr = _saveBuffer(r, r->input, input, outCount, ptr); - - aClearBuffer(ptr++, output, outCount<<1); /* clear the AL_AUX_R_OUT */ - - for (i = 0; i < r->section_count; i++) { - d = &r->delay[i]; /* get the ALDelay structure */ - in_ptr = &r->input[-d->input]; - out_ptr = &r->input[-d->output]; - - if (in_ptr == prev_out_ptr) { - SWAP(buff1, buff2); - } else { /* load data at in_ptr into buff1 */ - ptr = _loadBuffer(r, in_ptr, buff1, outCount, ptr); - } - ptr = _loadOutputBuffer(r, d, buff2, outCount, ptr); - - if (d->ffcoef) { - aMix(ptr++, 0, (u16)d->ffcoef, buff1, buff2); - if (!d->rs && !d->lp) { - ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr); - } - } - - if (d->fbcoef) { - aMix(ptr++, 0, (u16)d->fbcoef, buff2, buff1); - ptr = _saveBuffer(r, in_ptr, buff1, outCount, ptr); - } - - if (d->lp) - ptr = _filterBuffer(d->lp, buff2, outCount, ptr); - - if (!d->rs) - ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr); - - if (d->gain) - aMix(ptr++, 0, (u16)d->gain, buff2, output); - - prev_out_ptr = &r->input[d->output]; - } - - /* - * bump the master delay line input pointer - * modulo the length - */ - r->input += outCount; - if (r->input > &r->base[r->length]) - r->input -= r->length; - - /* - * output already in AL_AUX_R_OUT - * just copy to AL_AUX_L_OUT - */ - aDMEMMove(ptr++, output, AL_AUX_L_OUT, outCount<<1); - -#ifdef AUD_PROFILE - PROFILE_AUD(reverb_num, reverb_cnt, reverb_max, reverb_min); -#endif - return ptr; -} - -s32 alFxParam(void *filter, s32 paramID, void *param) -{ - if(paramID == AL_FILTER_SET_SOURCE) - { - ALFilter *f = (ALFilter *) filter; - f->source = (ALFilter*) param; - } - return 0; -} - -/* - * This routine gets called by alSynSetFXParam. No checking takes place to - * verify the validity of the paramID or the param value. input and output - * values must be 8 byte aligned, so round down any param passed. - */ -s32 alFxParamHdl(void *filter, s32 paramID, void *param) -{ - ALFx *f = (ALFx *) filter; - s32 p = (paramID - 2) % 8; - s32 s = (paramID - 2) / 8; - s32 val = *(s32*)param; - -#define INPUT_PARAM 0 -#define OUTPUT_PARAM 1 -#define FBCOEF_PARAM 2 -#define FFCOEF_PARAM 3 -#define GAIN_PARAM 4 -#define CHORUSRATE_PARAM 5 -#define CHORUSDEPTH_PARAM 6 -#define LPFILT_PARAM 7 - - switch(p) - { - case INPUT_PARAM: - f->delay[s].input = (u32)val & 0xFFFFFFF8; - break; - case OUTPUT_PARAM: - f->delay[s].output = (u32)val & 0xFFFFFFF8; - break; - case FFCOEF_PARAM: - f->delay[s].ffcoef = (s16)val; - break; - case FBCOEF_PARAM: - f->delay[s].fbcoef = (s16)val; - break; - case GAIN_PARAM: - f->delay[s].gain = (s16)val; - break; - case CHORUSRATE_PARAM: - /* f->delay[s].rsinc = ((f32)val)/0xffffff; */ - f->delay[s].rsinc = ((((f32)val)/1000) * RANGE)/alGlobals->drvr.outputRate; - break; - -/* - * the following constant is derived from: - * - * ratio = 2^(cents/1200) - * - * and therefore for hundredths of a cent - * x - * ln(ratio) = --------------- - * (120,000)/ln(2) - * where - * 120,000/ln(2) = 173123.40... - */ -#define CONVERT 173123.404906676 -#define LENGTH (f->delay[s].output - f->delay[s].input) - - case CHORUSDEPTH_PARAM: - /*f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; */ - f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; - break; - case LPFILT_PARAM: - if(f->delay[s].lp) - { - f->delay[s].lp->fc = (s16)val; - _init_lpfilter(f->delay[s].lp); - } - break; - } - return 0; -} - -Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p) -{ - Acmd *ptr = p; - s32 ratio, count, rbuff = AL_TEMP_2; - s16 *out_ptr; - f32 fincount, fratio, delta; - s32 ramalign = 0, length; - static f32 val=0.0, lastval=-10.0; - static f32 blob=0; -/* - * The following section implements the chorus resampling. Modulate where you pull - * the samples from, since you need varying amounts of samples. - */ - if (d->rs) { - length = d->output - d->input; - delta = _doModFunc(d, incount); /* get the number of samples to modulate by */ - /* - * find ratio of delta to delay length and quantize - * to same resolution as resampler - */ - delta /= length; /* convert delta from number of samples to a pitch ratio */ - delta = (s32)(delta * UNITY_PITCH); /* quantize to value microcode will use */ - delta = delta / UNITY_PITCH; - fratio = 1.0 - delta; /* pitch ratio needs to be centered around 1, not zero */ - - /* d->rs->delta is the difference between the fractional and integer value - * of the samples needed. fratio * incount + rs->delta gives the number of samples - * needed for this frame. - */ - fincount = d->rs->delta + (fratio * (f32)incount); - count = (s32) fincount; /* quantize to s32 */ - d->rs->delta = fincount - (f32)count; /* calculate the round off and store */ - - /* - * d->rsdelta is amount the out_ptr has deviated from its starting position. - * You calc the out_ptr by taking d->output - d->rsdelta, and then using the - * negative of that as an index into the delay buffer. loadBuffer that uses this - * value then bumps it up if it is below the delay buffer. - */ - out_ptr = &r->input[-(d->output - d->rsdelta)]; - ramalign = ((s32)out_ptr & 0x7) >> 1; /* calculate the number of samples needed - to align the buffer*/ -#ifdef _DEBUG -#if 0 - if(length > 0) { - if (length - d->rsdelta > (s32)r->length) { - __osError(ERR_ALMODDELAYOVERFLOW, 1, length - d->rsdelta - r->length); - } - } - else if(length < 0) { - if ((-length) - d->rsdelta > (s32)r->length) { - __osError(ERR_ALMODDELAYOVERFLOW, 1, (-length) - d->rsdelta - r->length); - } - } -#endif -#endif - /* load the rbuff with samples, note that there will be ramalign worth of - * samples at the begining which you don't care about. */ - ptr = _loadBuffer(r, out_ptr - ramalign, rbuff, count + ramalign, ptr); - - /* convert fratio to 16 bit fraction for microcode use */ - ratio = (s32)(fratio * UNITY_PITCH); - /* set the buffers, and do the resample */ - aSetBuffer(ptr++, 0, rbuff + (ramalign<<1), buff, incount<<1); - aResample(ptr++, d->rs->first, ratio, osVirtualToPhysical(d->rs->state)); - - d->rs->first = 0; /* turn off first time flag */ - d->rsdelta += count - incount; /* add the number of samples to d->rsdelta */ - } else { - out_ptr = &r->input[-d->output]; - ptr = _loadBuffer(r, out_ptr, buff, incount, ptr); - } - - return ptr; -} -/* - * This routine is for loading data from the delay line buff. If the - * address of curr_ptr < r->base, it will force it to be within r->base - * space, If the load goes past the end of r->base it will wrap around. - * Cause count bytes of data at curr_ptr (within the delay line) to be - * loaded into buff. (Buff is a dmem buffer) - */ -Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p) -{ - Acmd *ptr = p; - s32 after_end, before_end; - s16 *updated_ptr, *delay_end; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - delay_end = &r->base[r->length]; - -#ifdef _DEBUG - if(curr_ptr > delay_end) - __osError(ERR_ALMODDELAYOVERFLOW, 1, delay_end - curr_ptr); -#endif - - if (curr_ptr < r->base) - curr_ptr += r->length; - updated_ptr = curr_ptr + count; - - if (updated_ptr > delay_end) { - after_end = updated_ptr - delay_end; - before_end = delay_end - curr_ptr; - - aSetBuffer(ptr++, 0, buff, 0, before_end<<1); - aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); - aSetBuffer(ptr++, 0, buff+(before_end<<1), 0, after_end<<1); - aLoadBuffer(ptr++, osVirtualToPhysical(r->base)); - } else { - aSetBuffer(ptr++, 0, buff, 0, count<<1); - aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); - } - - aSetBuffer(ptr++, 0, 0, 0, count<<1); - -#ifdef AUD_PROFILE - PROFILE_AUD(load_num, load_cnt, load_max, load_min); -#endif - return ptr; - -} - -/* - * This routine is for writing data to the delay line buff. If the - * address of curr_ptr < r->base, it will force it to be within r->base - * space. If the write goes past the end of r->base, it will wrap around - * Cause count bytes of data at buff to be written to delay line, curr_ptr. - */ -Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p) -{ - Acmd *ptr = p; - s32 after_end, before_end; - s16 *updated_ptr, *delay_end; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - delay_end = &r->base[r->length]; - if (curr_ptr < r->base) /* probably just security */ - curr_ptr += r->length; /* shouldn't occur */ - updated_ptr = curr_ptr + count; - - if (updated_ptr > delay_end) { /* if the data wraps past end of r->base */ - after_end = updated_ptr - delay_end; - before_end = delay_end - curr_ptr; - - aSetBuffer(ptr++, 0, 0, buff, before_end<<1); - aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); - aSetBuffer(ptr++, 0, 0, buff+(before_end<<1), after_end<<1); - aSaveBuffer(ptr++, osVirtualToPhysical(r->base)); - aSetBuffer(ptr++, 0, 0, 0, count<<1); - } else { - aSetBuffer(ptr++, 0, 0, buff, count<<1); - aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); - } - -#ifdef AUD_PROFILE - PROFILE_AUD(save_num, save_cnt, save_max, save_min); -#endif - return ptr; - -} - -Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p) -{ - Acmd *ptr = p; - - aSetBuffer(ptr++, 0, buff, buff, count<<1); - aLoadADPCM(ptr++, 32, osVirtualToPhysical(lp->fcvec.fccoef)); - aPoleFilter(ptr++, lp->first, lp->fgain, osVirtualToPhysical(lp->fstate)); - lp->first = 0; - - return ptr; -} - - - -/* - * Generate a triangle wave from -1 to 1, and find the current position - * in the wave. (Rate of the wave is controlled by d->rsinc, which is chorus - * rate) Multiply the current triangle wave value by d->rsgain, (chorus depth) - * which is expressed in number of samples back from output pointer the chorus - * should go at it's full chorus. In otherwords, this function returns a number - * of samples the output pointer should modulate backwards. - */ -f32 _doModFunc(ALDelay *d, s32 count) -{ - f32 val; - - /* - * generate bipolar sawtooth - * from -RANGE to +RANGE - */ - d->rsval += d->rsinc * count; - d->rsval = (d->rsval > RANGE) ? d->rsval-(RANGE*2) : d->rsval; - - /* - * convert to monopolar triangle - * from 0 to RANGE - */ - val = d->rsval; - val = (val < 0) ? -val : val; - - /* - * convert to bipolar triangle - * from -1 to 1 - */ - val -= RANGE/2; - - return(d->rsgain * val); -} - - - diff --git a/lib/ultralib/src/audio/save.c b/lib/ultralib/src/audio/save.c deleted file mode 100644 index 59bd09b..0000000 --- a/lib/ultralib/src/audio/save.c +++ /dev/null @@ -1,70 +0,0 @@ -/*==================================================================== - * save.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -#include -#include "synthInternals.h" -#include -#include -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -Acmd *alSavePull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, - Acmd *p) -{ - Acmd *ptr = p; - ALSave *f = (ALSave *)filter; - ALFilter *source = f->filter.source; -#if BUILD_VERSION < VERSION_J -#line 33 -#endif - assert(f->filter.source); - - - ptr = (*source->handler)(source, outp, outCount, sampleOffset, ptr); - - aSetBuffer (ptr++, 0, 0, 0, outCount<<1); - aInterleave(ptr++, AL_MAIN_L_OUT, AL_MAIN_R_OUT); - aSetBuffer (ptr++, 0, 0, 0, outCount<<2); - aSaveBuffer(ptr++, f->dramout); - return ptr; -} - -s32 alSaveParam(void *filter, s32 paramID, void *param) -{ - ALSave *a = (ALSave *) filter; - ALFilter *f = (ALFilter *) filter; - s32 pp = (s32) param; - - switch (paramID) { - case (AL_FILTER_SET_SOURCE): - f->source = (ALFilter *) param; - break; - - case (AL_FILTER_SET_DRAM): - a->dramout = pp; - break; - - default: - break; - } - return 0; - -} - - - diff --git a/lib/ultralib/src/audio/seq.c b/lib/ultralib/src/audio/seq.c deleted file mode 100644 index 5da5b11..0000000 --- a/lib/ultralib/src/audio/seq.c +++ /dev/null @@ -1,343 +0,0 @@ -/*==================================================================== - * seq.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include -#include -#include "seq.h" - - -#define IFF_FILE_HDR 0x4d546864 /* 'MThd' */ -#define IFF_TRACK_HDR 0x4d54726b /* 'MTrk' */ - -static s32 readVarLen(ALSeq *s); -static u8 read8(ALSeq *s); -static s16 read16(ALSeq *s); -static s32 read32(ALSeq *s); - - -void alSeqNew(ALSeq *seq, u8 *ptr, s32 len) -{ - /* - * load the seqence pointed to by ptr - */ - seq->base = ptr; - seq->len = len; - seq->lastStatus = 0; - seq->lastTicks = 0; - seq->curPtr = ptr; - - if (read32(seq) != IFF_FILE_HDR) { -#ifdef _DEBUG - __osError(ERR_ALSEQNOTMIDI, 1, ptr); -#endif - return; - } - - read32(seq); /* skip the length field */ - - if (read16(seq) != 0) { -#ifdef _DEBUG - __osError(ERR_ALSEQNOTMIDI0, 1, ptr); -#endif - return; - } - - if (read16(seq) != 1) { -#ifdef _DEBUG - __osError(ERR_ALSEQNUMTRACKS, 1, ptr); -#endif - return; - } - - seq->division = read16(seq); - if (seq->division & 0x8000) { -#ifdef _DEBUG - __osError(ERR_ALSEQTIME, 1, ptr); -#endif - return; - } - - seq->qnpt = 1.0/(f32)seq->division; - - if (read32(seq) != IFF_TRACK_HDR) { -#ifdef _DEBUG - __osError(ERR_ALSEQTRACKHDR, 1, ptr); -#endif - return; - } - - read32(seq); /* skip the length field */ - - seq->trackStart = seq->curPtr; -} - - -void alSeqNextEvent(ALSeq *seq, ALEvent *event) -{ - u8 status; - s16 delta; - s32 len; - s32 deltaTicks; - s32 i; - -#ifdef _DEBUG - /* sct 1/17/96 - Warn if curPtr is beyond the end of sequence. */ - if (seq->curPtr >= seq->base + seq->len) - __osError(ERR_ALSEQOVERRUN, 0); -#endif - - deltaTicks = readVarLen(seq); /* read the delta time */ - seq->lastTicks += deltaTicks; - status = read8(seq); - -#if _DEBUG - /* - * System exclusives are not supported, so just skip them and read - * the next event - */ - if ((status == 0xf0) || (status == 0xf7)) { - __osError(ERR_ALSEQSYSEX, 0); - len = readVarLen(seq); - for (i = 0; i < len; i++) { - read8(seq); - } - alSeqNextEvent(seq,event); - return; - } -#endif - - if (status == AL_MIDI_Meta) { - u8 type = read8(seq); - - if (type == AL_MIDI_META_TEMPO) { - event->type = AL_TEMPO_EVT; - event->msg.tempo.ticks = deltaTicks; - event->msg.tempo.status = status; - event->msg.tempo.type = type; - event->msg.tempo.len = read8(seq); - event->msg.tempo.byte1 = read8(seq); - event->msg.tempo.byte2 = read8(seq); - event->msg.tempo.byte3 = read8(seq); - } else if (type == AL_MIDI_META_EOT) { - event->type = AL_SEQ_END_EVT; - event->msg.end.ticks = deltaTicks; - event->msg.end.status = status; - event->msg.end.type = type; - event->msg.end.len = read8(seq); - } else { -#ifdef _DEBUG - __osError(ERR_ALSEQMETA, 1, type); - len = readVarLen(seq); - for (i = 0; i < len; i++) { - read8(seq); - } - alSeqNextEvent(seq,event); - return; -#endif - } - - seq->lastStatus = 0; - - } else { - event->type = AL_SEQ_MIDI_EVT; - event->msg.midi.ticks = deltaTicks; - if (status & 0x80) { - event->msg.midi.status = status; - event->msg.midi.byte1 = read8(seq); - seq->lastStatus = status; - } else { - /* running status */ - event->msg.midi.status = seq->lastStatus; - event->msg.midi.byte1 = status; - } - - if (((event->msg.midi.status & 0xf0) != AL_MIDI_ProgramChange) && - ((event->msg.midi.status & 0xf0) != AL_MIDI_ChannelPressure)) { - event->msg.midi.byte2 = read8(seq); - } else { - event->msg.midi.byte2 = 0; - } - } -} - - -/* - Returns the delta time in ticks for the next event in the sequence. - Assumes that the sequence data pointer is pointing to the delta time. - - If the curPtr is at or beyond the end of the sequence, then return FALSE - to indicate no next event. - - sct 11/6/95 -*/ -char __alSeqNextDelta (ALSeq *seq, s32 *pDeltaTicks) -{ - u8 * savedPtr; - - /* sct 1/16/96 - Put in safety check here to make sure we don't read past sequence data. */ - if (seq->curPtr >= seq->base + seq->len) - return FALSE; - - savedPtr = seq->curPtr; - *pDeltaTicks = readVarLen(seq); /* read the delta time */ - seq->curPtr = savedPtr; - - return TRUE; -} - - -f32 alSeqTicksToSec(ALSeq *seq, s32 ticks, u32 tempo) -{ - return ((f32) (((f32)(ticks) * (f32)(tempo)) / - ((f32)(seq->division) * 1000000.0))); -} - -u32 alSeqSecToTicks(ALSeq *seq, f32 sec, u32 tempo) -{ - return (u32)(((sec * 1000000.0) * seq->division) / tempo); -} - -void alSeqNewMarker(ALSeq *seq, ALSeqMarker *m, u32 ticks) -{ - ALEvent evt; - u8 *savePtr, *lastPtr; - s32 saveTicks, lastTicks; - s16 saveStatus, lastStatus; - - /* does not check that ticks is within bounds */ - - if (ticks == 0) { /* common case */ - m->curPtr = seq->trackStart; - m->lastStatus = 0; - m->lastTicks = 0; - m->curTicks = 0; - return; - } else { - savePtr = seq->curPtr; - saveStatus = seq->lastStatus; - saveTicks = seq->lastTicks; - - seq->curPtr = seq->trackStart; - seq->lastStatus = 0; - seq->lastTicks = 0; - - do { - lastPtr = seq->curPtr; - lastStatus = seq->lastStatus; - lastTicks = seq->lastTicks; - - alSeqNextEvent(seq, &evt); - - if (evt.type == AL_SEQ_END_EVT) - { - lastPtr = seq->curPtr; - lastStatus = seq->lastStatus; - lastTicks = seq->lastTicks; - break; - } - - } while (seq->lastTicks < ticks); - - m->curPtr = lastPtr; - m->lastStatus = lastStatus; - m->lastTicks = lastTicks; - m->curTicks = seq->lastTicks; /* Used by test loop condition. */ - - seq->curPtr = savePtr; - seq->lastStatus = saveStatus; - seq->lastTicks = saveTicks; - - } -} - -s32 alSeqGetTicks(ALSeq *seq) -{ - return seq->lastTicks; -} - -void alSeqSetLoc(ALSeq *seq, ALSeqMarker *m) -{ - seq->curPtr = m->curPtr; - seq->lastStatus = m->lastStatus; - seq->lastTicks = m->lastTicks; -} - -void alSeqGetLoc(ALSeq *seq, ALSeqMarker *m) -{ - m->curPtr = seq->curPtr; - m->lastStatus = seq->lastStatus; - m->lastTicks = seq->lastTicks; -} - -/* non-aligned byte reading routines */ -static u8 read8(ALSeq *seq) -{ - return *seq->curPtr++; -} - -static s16 read16(ALSeq *seq) -{ - s16 tmp; - - tmp = *seq->curPtr++ << 8; - tmp |= *seq->curPtr++; - - return tmp; -} - -static s32 read32(ALSeq *seq) -{ - s32 tmp; - - tmp = *seq->curPtr++ << 24; - tmp |= *seq->curPtr++ << 16; - tmp |= *seq->curPtr++ << 8; - tmp |= *seq->curPtr++; - - return tmp; -} - -static s32 readVarLen(ALSeq *seq) -{ - s32 value; - s32 c; - - c = *seq->curPtr++; - value = c; - if ( c & 0x80 ) { - value &= 0x7f; - do { - c = *seq->curPtr++; - value = (value << 7) + (c & 0x7f); - } while (c & 0x80); - } - return (value); -} - - - - - - - - - - diff --git a/lib/ultralib/src/audio/seq.h b/lib/ultralib/src/audio/seq.h deleted file mode 100644 index 479b339..0000000 --- a/lib/ultralib/src/audio/seq.h +++ /dev/null @@ -1,9 +0,0 @@ - - -#ifndef __seq__ -#define __seq__ - -char __alSeqNextDelta (ALSeq *seq, s32 *pDeltaTicks); - - -#endif /* __seq__ */ diff --git a/lib/ultralib/src/audio/seqp.h b/lib/ultralib/src/audio/seqp.h deleted file mode 100644 index c9ab02b..0000000 --- a/lib/ultralib/src/audio/seqp.h +++ /dev/null @@ -1,37 +0,0 @@ - - -#define KILL_TIME 50000 /* 50 ms */ - -#ifndef MIN -#define MIN(a,b) (((a)<(b))?(a):(b)) -#endif - -#ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - -ALVoiceState *__mapVoice(ALSeqPlayer *, u8, u8, u8); -void __unmapVoice(ALSeqPlayer *seqp, ALVoice *voice); -char __voiceNeedsNoteKill(ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime killTime); /* sct 1/5/96 */ - -ALVoiceState *__lookupVoice(ALSeqPlayer *, u8, u8); -ALSound *__lookupSound(ALSeqPlayer *, u8, u8, u8); -ALSound *__lookupSoundQuick(ALSeqPlayer *, u8, u8, u8); - -s16 __vsVol(ALVoiceState *voice, ALSeqPlayer *seqp); -ALMicroTime __vsDelta(ALVoiceState *voice, ALMicroTime t); -ALPan __vsPan(ALVoiceState *voice, ALSeqPlayer *seqp); - -void __initFromBank(ALSeqPlayer *seqp, ALBank *b); -void __initChanState(ALSeqPlayer *seqp); -void __resetPerfChanState(ALSeqPlayer *seqp, s32 chan); -void __setInstChanState(ALSeqPlayer *seqp, ALInstrument *inst, s32 chan); - -void __seqpPrintVoices(ALSeqPlayer *); -void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, - ALMicroTime deltaTime); - -void __seqpStopOsc(ALSeqPlayer *seqp, ALVoiceState *vs); - -void __postNextSeqEvent(ALSeqPlayer *seqp); /* sct 11/7/95 */ - diff --git a/lib/ultralib/src/audio/seqpdelete.c b/lib/ultralib/src/audio/seqpdelete.c deleted file mode 100644 index 142f190..0000000 --- a/lib/ultralib/src/audio/seqpdelete.c +++ /dev/null @@ -1,39 +0,0 @@ -/*==================================================================== - * seqpdelete.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -#include -#include -#include -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void alSeqpDelete(ALSeqPlayer *seqp) -{ - /* sct 1/4/96 - If the sequence player isn't stopped, then you may end - up with stuck notes. Application should check state before calling - this routine to be sure. */ -#if BUILD_VERSION < VERSION_J -#line 31 -#endif - assert(seqp->state == AL_STOPPED); - - - alSynRemovePlayer(seqp->drvr, &seqp->node); -} - diff --git a/lib/ultralib/src/audio/seqpgetchlvol.c b/lib/ultralib/src/audio/seqpgetchlvol.c deleted file mode 100644 index e205651..0000000 --- a/lib/ultralib/src/audio/seqpgetchlvol.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * seqpgetchlvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -u8 alSeqpGetChlVol(ALSeqPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].vol; -} - diff --git a/lib/ultralib/src/audio/seqpgetfxmix.c b/lib/ultralib/src/audio/seqpgetfxmix.c deleted file mode 100644 index 5d7ee3f..0000000 --- a/lib/ultralib/src/audio/seqpgetfxmix.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * seqpgetfxmix.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].fxmix; -} - diff --git a/lib/ultralib/src/audio/seqpgetpan.c b/lib/ultralib/src/audio/seqpgetpan.c deleted file mode 100644 index 23f1067..0000000 --- a/lib/ultralib/src/audio/seqpgetpan.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * seqpgetpan.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -ALPan alSeqpGetChlPan(ALSeqPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].pan; -} - diff --git a/lib/ultralib/src/audio/seqpgetpriority.c b/lib/ultralib/src/audio/seqpgetpriority.c deleted file mode 100644 index e6f77a4..0000000 --- a/lib/ultralib/src/audio/seqpgetpriority.c +++ /dev/null @@ -1,26 +0,0 @@ -/*==================================================================== - * seqpgetpriority.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -u8 alSeqpGetChlPriority(ALSeqPlayer *seqp, u8 chan) -{ - return seqp->chanState[chan].priority; -} diff --git a/lib/ultralib/src/audio/seqpgetprogram.c b/lib/ultralib/src/audio/seqpgetprogram.c deleted file mode 100644 index d421cde..0000000 --- a/lib/ultralib/src/audio/seqpgetprogram.c +++ /dev/null @@ -1,42 +0,0 @@ -/*==================================================================== - * seqpgetprogram.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s32 alSeqpGetChlProgram(ALSeqPlayer *seqp, u8 chan) - -{ - s32 i; - ALBank *b = seqp->bank; - ALInstrument *inst; - ALChanState s; - - s = seqp->chanState[chan]; - for (i=0; iinstCount; i++){ - inst = b->instArray[i]; - if (inst == s.instrument) - return i; - } - return(-1); - -} - diff --git a/lib/ultralib/src/audio/seqpgetseq.c b/lib/ultralib/src/audio/seqpgetseq.c deleted file mode 100644 index d35ea19..0000000 --- a/lib/ultralib/src/audio/seqpgetseq.c +++ /dev/null @@ -1,29 +0,0 @@ -/*==================================================================== - * seqpgetseq.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -ALSeq *alSeqpGetSeq(ALSeqPlayer *seqp) -{ - return seqp->target; -} - diff --git a/lib/ultralib/src/audio/seqpgetstate.c b/lib/ultralib/src/audio/seqpgetstate.c deleted file mode 100644 index 8d36b49..0000000 --- a/lib/ultralib/src/audio/seqpgetstate.c +++ /dev/null @@ -1,29 +0,0 @@ -/*==================================================================== - * seqpgetstate.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s32 alSeqpGetState(ALSeqPlayer *seqp) -{ - return seqp->state; -} - diff --git a/lib/ultralib/src/audio/seqpgettempo.c b/lib/ultralib/src/audio/seqpgettempo.c deleted file mode 100644 index 41cd4b4..0000000 --- a/lib/ultralib/src/audio/seqpgettempo.c +++ /dev/null @@ -1,31 +0,0 @@ -/*==================================================================== - * seqpgettempo.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s32 alSeqpGetTempo(ALSeqPlayer *seqp) -{ - /* sct 1/8/96 - If no target sequence has been set, just return zero (instead of crashing). */ - if (seqp->target == NULL) - return 0; - - return seqp->uspt/seqp->target->qnpt; -} - diff --git a/lib/ultralib/src/audio/seqpgetvol.c b/lib/ultralib/src/audio/seqpgetvol.c deleted file mode 100644 index 43a3bb8..0000000 --- a/lib/ultralib/src/audio/seqpgetvol.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * seqpgetvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -s16 alSeqpGetVol(ALSeqPlayer *seqp) -{ - return seqp->vol; -} - diff --git a/lib/ultralib/src/audio/seqplayer.c b/lib/ultralib/src/audio/seqplayer.c deleted file mode 100644 index 9d77a6f..0000000 --- a/lib/ultralib/src/audio/seqplayer.c +++ /dev/null @@ -1,1228 +0,0 @@ -/*==================================================================== - * seqplayer.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -/* - * Notes: - * - * Controller Numbers: - * 1 Modulation - * 7 Volume - * 10 Pan - * 11 Expression - * 64 Sustain - * 121 Reset All Controllers - * 123 All Notes Off - * - * Registered Parameters - * 0 Pitch Bend Sensitivity - * 1 Fine Tuning - * 2 Coarse Tuning - */ - -#include -#include -#include -#include -#include "seqp.h" -#include "seq.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - - -static ALMicroTime __seqpVoiceHandler(void *node); -static void __handleMIDIMsg(ALSeqPlayer *seqp, ALEvent *event); -static void __handleMetaMsg(ALSeqPlayer *seqp, ALEvent *event); -static void __handleNextSeqEvent(ALSeqPlayer *seqp); -static void __setUsptFromTempo(ALSeqPlayer *seqp, f32 tempo); /* sct 1/8/96 */ - -/* - * Sequence Player public functions - */ -void alSeqpNew(ALSeqPlayer *seqp, ALSeqpConfig *c) -{ - s32 i; - ALEventListItem *items; - ALVoiceState *vs; - ALVoiceState *voices; - ALHeap *hp = c->heap; - - /* - * initialize member variables - */ - seqp->bank = 0; - seqp->target = NULL; - seqp->drvr = &alGlobals->drvr; - seqp->chanMask = 0xff; - seqp->uspt = 488; - seqp->nextDelta = 0; - seqp->state = AL_STOPPED; - seqp->vol = 0x7FFF; /* full volume */ - seqp->debugFlags = c->debugFlags; - seqp->frameTime = AL_USEC_PER_FRAME; /* should get this from driver */ - seqp->curTime = 0; - seqp->initOsc = c->initOsc; - seqp->updateOsc = c->updateOsc; - seqp->stopOsc = c->stopOsc; - seqp->loopStart = 0; - seqp->loopEnd = 0; - seqp->loopCount = 0; /* -1 = loop forever, 0 = no loop */ - - seqp->nextEvent.type = AL_SEQP_API_EVT; /* start the voice handler "spinning" */ - - /* - * init the channel state - */ - seqp->maxChannels = c->maxChannels; - seqp->chanState = alHeapAlloc(hp, c->maxChannels, sizeof(ALChanState) ); - __initChanState(seqp); /* sct 11/6/95 */ - - /* - * init the voice state array - */ - voices = alHeapAlloc(hp, c->maxVoices, sizeof(ALVoiceState)); - seqp->vFreeList = 0; - for (i = 0; i < c->maxVoices; i++) { - vs = &voices[i]; - vs->next = seqp->vFreeList; - seqp->vFreeList = vs; - } - - seqp->vAllocHead = 0; - seqp->vAllocTail = 0; - - /* - * init the event queue - */ - items = alHeapAlloc(hp, c->maxEvents, sizeof(ALEventListItem)); - alEvtqNew(&seqp->evtq, items, c->maxEvents); - - /* - * add ourselves to the driver - */ - seqp->node.next = NULL; - seqp->node.handler = __seqpVoiceHandler; - seqp->node.clientData = seqp; - alSynAddPlayer(&alGlobals->drvr, &seqp->node); -} - -/************************************************************* - * private routines or driver callback routines - *************************************************************/ -ALMicroTime __seqpVoiceHandler(void *node) -{ - ALSeqPlayer *seqp = (ALSeqPlayer *) node; - ALEvent evt; - ALVoice *voice; - ALMicroTime delta; - ALVoiceState *vs; - void *oscState; - f32 oscValue; - u8 chan; - - do { - - switch (seqp->nextEvent.type) { - - case (AL_SEQ_REF_EVT): - __handleNextSeqEvent(seqp); - break; - - case (AL_SEQP_API_EVT): - evt.type = AL_SEQP_API_EVT; - alEvtqPostEvent(&seqp->evtq, (ALEvent *)&evt, seqp->frameTime); - break; - - case (AL_NOTE_END_EVT): - voice = seqp->nextEvent.msg.note.voice; - alSynStopVoice(seqp->drvr, voice); - alSynFreeVoice(seqp->drvr, voice); - vs = (ALVoiceState *)voice->clientPrivate; - if(vs->flags) - __seqpStopOsc((ALSeqPlayer*)seqp,vs); - __unmapVoice(seqp, voice); - break; - - case (AL_SEQP_ENV_EVT): - voice = seqp->nextEvent.msg.vol.voice; - vs = (ALVoiceState *)voice->clientPrivate; - - if (vs->envPhase == AL_PHASE_ATTACK) - vs->envPhase = AL_PHASE_DECAY; - - delta = seqp->nextEvent.msg.vol.delta; - vs->envGain = seqp->nextEvent.msg.vol.vol; - vs->envEndTime = seqp->curTime + delta; - alSynSetVol(seqp->drvr, voice, __vsVol(vs, seqp), delta); - break; - - case (AL_TREM_OSC_EVT): - vs = seqp->nextEvent.msg.osc.vs; - oscState = seqp->nextEvent.msg.osc.oscState; - delta = (*seqp->updateOsc)(oscState,&oscValue); - vs->tremelo = (u8)oscValue; - alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs,seqp), - __vsDelta(vs,seqp->curTime)); - evt.type = AL_TREM_OSC_EVT; - evt.msg.osc.vs = vs; - evt.msg.osc.oscState = oscState; - alEvtqPostEvent(&seqp->evtq, &evt, delta); - break; - - case (AL_VIB_OSC_EVT): - vs = seqp->nextEvent.msg.osc.vs; - oscState = seqp->nextEvent.msg.osc.oscState; - chan = seqp->nextEvent.msg.osc.chan; - delta = (*seqp->updateOsc)(oscState,&oscValue); - vs->vibrato = oscValue; - alSynSetPitch(seqp->drvr, &vs->voice, vs->pitch * vs->vibrato - * seqp->chanState[chan].pitchBend); - evt.type = AL_VIB_OSC_EVT; - evt.msg.osc.vs = vs; - evt.msg.osc.oscState = oscState; - evt.msg.osc.chan = chan; - alEvtqPostEvent(&seqp->evtq, &evt, delta); - break; - - case (AL_SEQP_MIDI_EVT): - __handleMIDIMsg(seqp, &seqp->nextEvent); - break; - - case (AL_SEQP_META_EVT): - __handleMetaMsg(seqp, &seqp->nextEvent); - break; - - case (AL_SEQP_PLAY_EVT): - if (seqp->state != AL_PLAYING) - { - seqp->state = AL_PLAYING; - __postNextSeqEvent(seqp); /* seqp must be AL_PLAYING before we call this routine. */ - } - break; - - case (AL_SEQP_STOP_EVT): - if ( seqp->state == AL_STOPPING ) - { - for (vs = seqp->vAllocHead; vs != 0; vs = seqp->vAllocHead) - { - alSynStopVoice(seqp->drvr, &vs->voice); - alSynFreeVoice(seqp->drvr, &vs->voice); - if(vs->flags) - __seqpStopOsc((ALSeqPlayer*)seqp,vs); - __unmapVoice((ALSeqPlayer*)seqp, &vs->voice); - } - - seqp->curTime = 0; - seqp->state = AL_STOPPED; - - /* alEvtqFlush(&seqp->evtq); - Don't flush event - queue anymore. */ - /* sct 1/3/96 - Don't overwrite nextEvent with - AL_SEQP_API_EVT or set nextDelta to - AL_USEC_PER_FRAME since we're not stopping event - processing. */ - /* sct 1/3/96 - Don't return here since we keep - processing events as usual. */ - } - break; - - case (AL_SEQP_STOPPING_EVT): - if (seqp->state == AL_PLAYING) - { - /* - * sct 12/29/95 - Remove events associated with the - * stopping sequence. Note that flushing - * AL_SEQP_MIDI_EVTs may flush events that were - * posted after the call to alSeqpStop, so the - * application must queue these events either when - * the player is fully stopped, or when it is - * playing. - */ - alEvtqFlushType(&seqp->evtq, AL_SEQ_REF_EVT); - alEvtqFlushType(&seqp->evtq, AL_SEQP_MIDI_EVT); - - /* - * sct 1/3/96 - Check to see which voices need to be - * killed and release them. Unkilled voices should - * have note end events occurring prior to - * KILL_TIME. - */ - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (__voiceNeedsNoteKill (seqp, &vs->voice, KILL_TIME)) - __seqpReleaseVoice(seqp, &vs->voice, KILL_TIME); - } - - seqp->state = AL_STOPPING; - evt.type = AL_SEQP_STOP_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); - } - break; - - case (AL_SEQP_VOL_EVT): - seqp->vol = seqp->nextEvent.msg.spvol.vol; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs, seqp), - __vsDelta(vs, seqp->curTime)); - } - break; - - case (AL_SEQP_LOOP_EVT): - seqp->loopStart = seqp->nextEvent.msg.loop.start; - seqp->loopEnd = seqp->nextEvent.msg.loop.end; - seqp->loopCount = seqp->nextEvent.msg.loop.count; - break; - - case (AL_SEQP_PRIORITY_EVT): - chan = seqp->nextEvent.msg.sppriority.chan; - seqp->chanState[chan].priority = seqp->nextEvent.msg.sppriority.priority; - break; - case (AL_SEQP_SEQ_EVT): -#if BUILD_VERSION < VERSION_J // Adjust line numbers to match asserts -#line 295 -#endif - assert(seqp->state != AL_PLAYING); /* Must be done playing to change sequences. */ - - - seqp->target = seqp->nextEvent.msg.spseq.seq; - __setUsptFromTempo (seqp, 500000.0); - if (seqp->bank) - __initFromBank(seqp, seqp->bank); - break; - case (AL_SEQP_BANK_EVT): -#if BUILD_VERSION < VERSION_J -#line 304 -#endif - assert(seqp->state == AL_STOPPED); /* Must be fully stopped to change banks. */ - - seqp->bank = seqp->nextEvent.msg.spbank.bank; - __initFromBank(seqp, seqp->bank); - break; - - /* sct 11/6/95 - these events should now be handled by __handleNextSeqEvent */ - case (AL_SEQ_END_EVT): - case (AL_TEMPO_EVT): - case (AL_SEQ_MIDI_EVT): -#if BUILD_VERSION < VERSION_J -#line 314 -#endif - assert(FALSE); - - - break; - } - - seqp->nextDelta = alEvtqNextEvent (&seqp->evtq, &seqp->nextEvent); - - } while (seqp->nextDelta == 0); - - /* - * assume that next callback won't be more than half an hour away - */ - seqp->curTime += seqp->nextDelta; /* Update the player's current time. */ - return seqp->nextDelta; -} - - -/* - Calculates the delta time in ticks until the next sequence - event taking into account loop points, and posts a - sequence reference event with the time in usecs. - - Does nothing if the sequence player is not playing or there - is no target sequence. - - sct 11/7/95 -*/ -void __postNextSeqEvent(ALSeqPlayer *seqp) -{ - ALEvent evt; - s32 deltaTicks; - ALSeq *seq = seqp->target; - - /* sct 1/5/96 - Do nothing if we're not playing or don't have a target sequence. */ - if ((seqp->state != AL_PLAYING) || (seq == NULL)) - return; - - /* Get the next event time in ticks. */ - /* If false is returned, then there is no next delta (ie. end of sequence reached). */ - if (!__alSeqNextDelta(seq, &deltaTicks)) - return; - - /* Handle loops. */ - if (seqp->loopCount) - { - /* Assume that the loop end falls on a MIDI event. Delta time - will be correct even if we loop */ - if (alSeqGetTicks(seq) + deltaTicks >= seqp->loopEnd->curTicks) - { - alSeqSetLoc(seq, seqp->loopStart); - - if (seqp->loopCount != -1) - seqp->loopCount--; - } - } - - evt.type = AL_SEQ_REF_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt); -} - -/* - Call this routine to handle the next event in the sequence. - Assumes that the next sequence event is scheduled to be processed - immediately since it does not check the event's tick time. - - sct 11/7/95 -*/ -static void -__handleNextSeqEvent(ALSeqPlayer *seqp) -{ - ALEvent evt; - - /* sct 1/5/96 - Do nothing if we don't have a target sequence. */ - if (seqp->target == NULL) - return; - - alSeqNextEvent(seqp->target, &evt); - - switch (evt.type) - { - case AL_SEQ_MIDI_EVT: - __handleMIDIMsg(seqp, &evt); - __postNextSeqEvent(seqp); - break; - - case AL_TEMPO_EVT: - __handleMetaMsg(seqp, &evt); - __postNextSeqEvent(seqp); - break; - - case AL_SEQ_END_EVT: - seqp->state = AL_STOPPING; - evt.type = AL_SEQP_STOP_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); - break; - - default: -#if BUILD_VERSION < VERSION_J -#line 411 -#endif - assert(FALSE); /* Sequence event type not supported. */ -#if BUILD_VERSION >= VERSION_J - break; -#endif - } -} - -void __handleMIDIMsg(ALSeqPlayer *seqp, ALEvent *event) -{ - ALVoice *voice; - ALVoiceState *vs; - s32 status; - u8 chan; - u8 key; - u8 vel; - u8 byte1; - u8 byte2; - ALMIDIEvent *midi = &event->msg.midi; - s16 vol; - ALEvent evt; - ALMicroTime deltaTime; - ALVoiceState *vstate; - ALPan pan; - ALFxRef fxref; -#if BUILD_VERSION < VERSION_J -#line 434 -#endif - /* sct 12/15/95 - Fixed assert to also allow seqp midi event types. */ - assert(event->type == AL_SEQ_MIDI_EVT || event->type == AL_SEQP_MIDI_EVT); - - - status = midi->status & AL_MIDI_StatusMask; - chan = midi->status & AL_MIDI_ChannelMask; - byte1 = key = midi->byte1; - byte2 = vel = midi->byte2; - - switch (status) { - - case (AL_MIDI_NoteOn): - - if (vel != 0) { /* a real note on */ - ALVoiceConfig config; - ALSound *sound; - s16 cents; - f32 pitch,oscValue; - u8 fxmix; - void *oscState; - ALInstrument *inst; - - /* If we're not playing, don't process note ons. */ - if (seqp->state != AL_PLAYING) - break; - - sound = __lookupSoundQuick(seqp, key, vel, chan); - ALFlagFailIf(!sound, seqp->debugFlags & NO_SOUND_ERR_MASK, - ERR_ALSEQP_NO_SOUND); - - config.priority = seqp->chanState[chan].priority; - config.fxBus = 0; - config.unityPitch = 0; - - vstate = __mapVoice(seqp, key, vel, chan); - ALFlagFailIf(!vstate, seqp->debugFlags & NO_VOICE_ERR_MASK, - ERR_ALSEQP_NO_VOICE ); - - voice = &vstate->voice; - - alSynAllocVoice(seqp->drvr, voice, &config); - - /* - * set up the voice state structure - */ - vstate->sound = sound; - vstate->envPhase = AL_PHASE_ATTACK; - if (seqp->chanState[chan].sustain > AL_SUSTAIN) - vstate->phase = AL_PHASE_SUSTAIN; - else - vstate->phase = AL_PHASE_NOTEON; - - cents = (key - sound->keyMap->keyBase) * 100 - + sound->keyMap->detune; - - vstate->pitch = alCents2Ratio(cents); - vstate->envGain = sound->envelope->attackVolume; - vstate->envEndTime = seqp->curTime + - sound->envelope->attackTime; - - /* - * setup tremelo and vibrato if active - */ - vstate->flags = 0; - inst = seqp->chanState[chan].instrument; - - oscValue = (f32)AL_VOL_FULL; /* set this as a default */ - - if(inst->tremType) - { - if(seqp->initOsc) - { - deltaTime = (*seqp->initOsc)(&oscState,&oscValue, - inst->tremType, - inst->tremRate, - inst->tremDepth, - inst->tremDelay); - - if(deltaTime) /* if deltaTime = zero, don't run osc */ - { - evt.type = AL_TREM_OSC_EVT; - evt.msg.osc.vs = vstate; - evt.msg.osc.oscState = oscState; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - vstate->flags |= 0x01; /* set tremelo flag bit */ - } - } - } - /* will default if not changed by initOsc */ - vstate->tremelo = (u8)oscValue; - - oscValue = 1.0f; /* set this as a default */ - if(inst->vibType) - { - if(seqp->initOsc) - { - deltaTime = (*seqp->initOsc)(&oscState,&oscValue, - inst->vibType, - inst->vibRate, - inst->vibDepth, - inst->vibDelay); - - if(deltaTime) /* if deltaTime = zero,don't run osc. */ - { - evt.type = AL_VIB_OSC_EVT; - evt.msg.osc.vs = vstate; - evt.msg.osc.oscState = oscState; - evt.msg.osc.chan = chan; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - vstate->flags |= 0x02; /* set the vibrato flag bit */ - } - } - } - /* will default if not changed by initOsc */ - vstate->vibrato = oscValue; - - /* - * calculate the note on parameters - */ - pitch = vstate->pitch * seqp->chanState[chan].pitchBend * - vstate->vibrato; - fxmix = seqp->chanState[chan].fxmix; - pan = __vsPan(vstate, seqp); - vol = __vsVol(vstate, seqp); - deltaTime = sound->envelope->attackTime; - - alSynStartVoiceParams(seqp->drvr, voice, sound->wavetable, - pitch, vol, pan, fxmix, deltaTime); - /* - * set up callbacks for envelope - */ - evt.type = AL_SEQP_ENV_EVT; - evt.msg.vol.voice = voice; - evt.msg.vol.vol = sound->envelope->decayVolume; - evt.msg.vol.delta = sound->envelope->decayTime; - deltaTime = sound->envelope->attackTime; - - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - - break; - } - - /* - * NOTE: intentional fall-through for note on with zero - * velocity - */ - - case (AL_MIDI_NoteOff): - vstate = __lookupVoice(seqp, key, chan); - ALFlagFailIf(!vstate, (seqp->debugFlags & NOTE_OFF_ERR_MASK), - ERR_ALSEQP_OFF_VOICE ); - - if (vstate->phase == AL_PHASE_SUSTAIN) - vstate->phase = AL_PHASE_SUSTREL; - else { - vstate->phase = AL_PHASE_RELEASE; - __seqpReleaseVoice(seqp, &vstate->voice, - vstate->sound->envelope->releaseTime); - } - - break; - - case (AL_MIDI_PolyKeyPressure): - /* - * Aftertouch per key (hardwired to volume). Note that - * aftertouch affects only notes that are already - * sounding. - */ - vstate = __lookupVoice(seqp, key, chan); - ALFailIf(!vstate, ERR_ALSEQP_POLY_VOICE ); - - vstate->velocity = byte2; - alSynSetVol(seqp->drvr, &vstate->voice, __vsVol(vstate, seqp), - __vsDelta(vstate, seqp->curTime)); - break; - - case (AL_MIDI_ChannelPressure): - /* - * Aftertouch per channel (hardwired to volume). Note that - * aftertouch affects only notes that are already - * sounding. - */ - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if (vs->channel == chan) { - vs->velocity = byte1; - alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs, seqp), - __vsDelta(vs, seqp->curTime)); - } - } - break; - - case (AL_MIDI_ControlChange): - - switch (byte1) { - - case (AL_MIDI_PAN_CTRL): - seqp->chanState[chan].pan = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if (vs->channel == chan) { - pan = __vsPan(vs, seqp); - alSynSetPan(seqp->drvr, &vs->voice, pan); - } - } - break; - - case (AL_MIDI_VOLUME_CTRL): - seqp->chanState[chan].vol = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if ((vs->channel == chan) && - (vs->envPhase != AL_PHASE_RELEASE)) - { - vol = __vsVol(vs, seqp); - alSynSetVol(seqp->drvr, &vs->voice, vol, - __vsDelta(vs, seqp->curTime)); - } - } - break; - case (AL_MIDI_PRIORITY_CTRL): - /* leave current voices where they are */ - seqp->chanState[chan].priority = byte2; - break; - case (AL_MIDI_SUSTAIN_CTRL): - seqp->chanState[chan].sustain = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if ((vs->channel == chan) && - (vs->phase != AL_PHASE_RELEASE)) { - if ( byte2 > AL_SUSTAIN ) { - /* - * sustain pedal down - */ - if (vs->phase == AL_PHASE_NOTEON) - vs->phase = AL_PHASE_SUSTAIN; - } else { - /* - * sustain pedal up - */ - if (vs->phase == AL_PHASE_SUSTAIN) - vs->phase = AL_PHASE_NOTEON; - else if(vs->phase == AL_PHASE_SUSTREL) { - vs->phase = AL_PHASE_RELEASE; - __seqpReleaseVoice(seqp, &vs->voice, - vs->sound->envelope->releaseTime); - } - } - } - } - break; - - case (AL_MIDI_FX1_CTRL): - seqp->chanState[chan].fxmix = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if (vs->channel == chan) { - alSynSetFXMix(seqp->drvr, &vs->voice, byte2); - } - } - break; - - case (AL_MIDI_FX_CTRL_0): - case (AL_MIDI_FX_CTRL_1): - case (AL_MIDI_FX_CTRL_2): - case (AL_MIDI_FX_CTRL_3): - case (AL_MIDI_FX_CTRL_4): - case (AL_MIDI_FX_CTRL_5): - case (AL_MIDI_FX_CTRL_6): - case (AL_MIDI_FX_CTRL_7): -#if 0 /* fx control not implemented */ - fxref = alSynGetFXRef(seqp->drvr, 0, 0); - if (fxref) - alSynSetFXParam(seqp->drvr, fxref, (s16)byte1, (void *)byte2); - break; -#endif - case (AL_MIDI_FX3_CTRL): - default: - break; - } - break; - - case (AL_MIDI_ProgramChange): - /* sct 1/16/96 - We must have a valid bank in order to process the program change. */ -#if BUILD_VERSION < VERSION_J -#line 713 -#endif - assert(seqp->bank != NULL); - - - if (key < seqp->bank->instCount) { - ALInstrument *inst = seqp->bank->instArray[key]; - __setInstChanState(seqp, inst, chan); /* sct 11/6/95 */ - } -#ifdef _DEBUG - else - __osError(ERR_ALSEQPINVALIDPROG, 2, key, seqp->bank->instCount); -#endif - break; - - case (AL_MIDI_PitchBendChange): - { - s32 bendVal; - f32 bendRatio; - s32 cents; - - /* - * get 14-bit unsigned midi value - */ - bendVal = ( (byte2 << 7) + byte1) - 8192; - - /* - * calculate pitch bend in cents - */ - cents = (seqp->chanState[chan].bendRange * bendVal)/8192; - - /* - * calculate the corresponding ratio - */ - bendRatio = alCents2Ratio(cents); - seqp->chanState[chan].pitchBend = bendRatio; - - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if (vs->channel == chan) { - alSynSetPitch(seqp->drvr, &vs->voice, - vs->pitch * bendRatio * vs->vibrato); - } - } - } - break; - - default: -#ifdef _DEBUG - __osError(ERR_ALSEQPUNKNOWNMIDI, 1, status); -#endif - break; - } -} - -void __handleMetaMsg(ALSeqPlayer *seqp, ALEvent *event) -{ - ALTempoEvent *tevt = &event->msg.tempo; - ALEvent evt; - s32 tempo; - - if (event->msg.tempo.status == AL_MIDI_Meta) - { - if (event->msg.tempo.type == AL_MIDI_META_TEMPO) - { - tempo = - (tevt->byte1 << 16) | - (tevt->byte2 << 8) | - (tevt->byte3 << 0); - __setUsptFromTempo (seqp, (f32)tempo); /* sct 1/8/96 */ - } - } -} - -ALVoiceState *__mapVoice(ALSeqPlayer *seqp, u8 key, u8 vel, u8 channel) -{ - ALVoiceState *vs = seqp->vFreeList; - - if (vs) { - - seqp->vFreeList = vs->next; - - vs->next = 0; - - if (!seqp->vAllocHead) - seqp->vAllocHead = vs; - else - seqp->vAllocTail->next = vs; - - seqp->vAllocTail = vs; - - vs->channel = channel; - vs->key = key; - vs->velocity = vel; - vs->voice.clientPrivate = vs; - } - - return vs; -} - -void __unmapVoice(ALSeqPlayer *seqp, ALVoice *voice) -{ - ALVoiceState *prev = 0; - ALVoiceState *vs; - - /* - * we could use doubly linked lists here and save some code and - * execution time, but time spent here in negligible, so it won't - * make much difference. - */ - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if (&vs->voice == voice) { - - if (prev) - prev->next = vs->next; - else - seqp->vAllocHead = vs->next; - - if (vs == seqp->vAllocTail) { - seqp->vAllocTail = prev; - } - - vs->next = seqp->vFreeList; - seqp->vFreeList = vs; - return; - - } - prev = vs; - } -#ifdef _DEBUG - __osError(ERR_ALSEQPUNMAP, 1, voice); -#endif -} - -ALVoiceState *__lookupVoice(ALSeqPlayer *seqp, u8 key, u8 channel) -{ - ALVoiceState *vs; - - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { - if ((vs->key == key) && (vs->channel == channel) && - (vs->phase != AL_PHASE_RELEASE) && (vs->phase != AL_PHASE_SUSTREL)) - return vs; - } - - return 0; -} -#if 0 -ALSound *__lookupSound(ALSeqPlayer *seqp, u8 key, u8 vel, u8 chan) -{ - s32 i; - ALInstrument *inst = seqp->chanState[chan].instrument; - ALSound *snd = 0; - - for (i = 0; i < inst->soundCount; i++) { - ALSound *sound = inst->soundArray[i]; - ALKeyMap *keymap = sound->keyMap; - - if ((key >= keymap->keyMin) && (key <= keymap->keyMax) && - (vel >= keymap->velocityMin) && (vel <= keymap->velocityMax)) { - snd = sound; - break; - } - } - return snd; -} -#endif - -ALSound *__lookupSoundQuick(ALSeqPlayer *seqp, u8 key, u8 vel, u8 chan) -{ - ALInstrument *inst = seqp->chanState[chan].instrument; - s32 l = 1; - s32 r = inst->soundCount; - s32 i; - ALKeyMap *keymap; -#if BUILD_VERSION < VERSION_J -#line 885 -#endif - assert(inst != NULL); /* sct 10/31/95 - If inst is NULL, then the seqp probably wasn't setup correctly. */ - - - while (r >= l) { - i = (l+r)/2; - - keymap = inst->soundArray[i-1]->keyMap; - - if ((key >= keymap->keyMin) && (key <= keymap->keyMax) && - (vel >= keymap->velocityMin) && (vel <= keymap->velocityMax)) { - return inst->soundArray[i-1]; - } else if ((key < keymap->keyMin) || - ((vel < keymap->velocityMin) && (key <= keymap->keyMax))) { - r = i - 1; - } else { - l = i + 1; - } - } - - return 0; -} - - -/* - * __vsVol calculates the target volume for the voice based on the - * note on velocity, envelope, sampleVolume and controller. - */ -s16 __vsVol(ALVoiceState *vs, ALSeqPlayer *seqp) -{ - - u32 t1,t2; - - t1 = (vs->tremelo*vs->velocity*vs->envGain) >> 6; - t2 = (vs->sound->sampleVolume*seqp->vol* - seqp->chanState[vs->channel].vol) >> 14; - - t1 *= t2; - t1 >>= 15; - - return( (s16)t1 ); - -} - -ALMicroTime __vsDelta(ALVoiceState *vs, ALMicroTime t) -{ - /* - * If we are interrupting a previously set envelope segment, we - * need to recalculate the segment end time given the current - * time. Note: this routine assumes that the voice is currently - * playing. - */ - - s32 delta = vs->envEndTime - t; - - if (delta >= 0) { - return delta; - } else { - return AL_GAIN_CHANGE_TIME; - } -} - - -ALPan __vsPan(ALVoiceState *vs, ALSeqPlayer *seqp) -{ - s32 tmp; - - tmp = seqp->chanState[vs->channel].pan - AL_PAN_CENTER + - vs->sound->samplePan; - tmp = MAX(tmp, AL_PAN_LEFT); - tmp = MIN(tmp, AL_PAN_RIGHT); - - return (ALPan) tmp; -} - -#ifdef IMPLEMENTED - -s32 seqpGetVoices(SEQP *seqp); -s32 seqpSetVoices(SEQP *seqp, s32 numvoices); - -u16 seqpGetChannelMask(SEQP *seqp); -s32 seqpSetChannelMask(SEQP *seqp, u16 bitmask); - -#endif - -void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, - ALMicroTime deltaTime) -{ - ALEvent evt; - ALVoiceState *vs = (ALVoiceState *)voice->clientPrivate; - - /* - * if in attack phase, remove all pending volume - * events for this voice from the queue - */ - - if (vs->envPhase == AL_PHASE_ATTACK) { - ALLink *thisNode; - ALLink *nextNode; - ALEventListItem *thisItem, *nextItem; - - thisNode = seqp->evtq.allocList.next; - while( thisNode != 0 ) { - nextNode = thisNode->next; - thisItem = (ALEventListItem *)thisNode; - nextItem = (ALEventListItem *)nextNode; - if (thisItem->evt.type == AL_SEQP_ENV_EVT) { - if(thisItem->evt.msg.vol.voice == voice) { - if( nextItem ) - nextItem->delta += thisItem->delta; - alUnlink(thisNode); - alLink(thisNode, &seqp->evtq.freeList); - } - } - thisNode = nextNode; - } - } - - vs->velocity = 0; - vs->envPhase = AL_PHASE_RELEASE; - vs->envGain = 0; - vs->envEndTime = seqp->curTime + deltaTime; - - alSynSetPriority(seqp->drvr, voice, 0); /* make candidate for stealing */ - alSynSetVol(seqp->drvr, voice, 0, deltaTime); - evt.type = AL_NOTE_END_EVT; - evt.msg.note.voice = voice; - - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); -} - - - -/* - This special purpose routine is called only when processing - a stopping event in order to properly kill all active voices. - - The routine searches through the seqp's event queue for an - AL_NOTE_END_EVT for the given voice. If the event's execution - time is greater than kill time, it removes the event from the - event queue and returns true that it needs to kill the voice. - Otherwise, if the event's time is less than the kill time, it - returns false that the voice needs to be killed. - - sct 1/3/96 -*/ - -#define VOICENEEDSNOTEKILL_DEBUG _DEBUG_INTERNAL&&0 /* For debugging voiceNeedsNoteKill routine. */ - -char __voiceNeedsNoteKill (ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime killTime) -{ - ALLink *thisNode; - ALLink *nextNode; - ALEventListItem *thisItem; - ALMicroTime itemTime = 0; - char needsNoteKill = TRUE; - -#if VOICENEEDSNOTEKILL_DEBUG - alEvtqPrintAllocEvts (&seqp->evtq); -#endif - - thisNode = seqp->evtq.allocList.next; - while (thisNode != 0) - { - nextNode = thisNode->next; - thisItem = (ALEventListItem *)thisNode; - itemTime += thisItem->delta; - - if (thisItem->evt.type == AL_NOTE_END_EVT) - { - if (thisItem->evt.msg.note.voice == voice) - { - if (itemTime > killTime) - { - if ((ALEventListItem *)nextNode) - ((ALEventListItem *)nextNode)->delta += thisItem->delta; - alUnlink(thisNode); - alLink(thisNode, &seqp->evtq.freeList); - } - else - needsNoteKill = FALSE; - break; - } - } - thisNode = nextNode; - } - -#if VOICENEEDSNOTEKILL_DEBUG - if (thisNode) - osSyncPrintf("vox 0x%0x: end time %d kill time %d\n\n", voice, itemTime, killTime); - else - osSyncPrintf("vox 0x%0x: not found\n\n", voice); - - alEvtqPrintAllocEvts (&seqp->evtq); -#endif - - return needsNoteKill; -} - - - - -void __initFromBank(ALSeqPlayer *seqp, ALBank *b) -{ - /* - * init the chanState with the default instrument - */ - s32 i; - ALInstrument *inst = 0; - - /* set to the first available instrument. */ - for(i = 0; !inst ; i++) - inst = b->instArray[i]; - - /* sct 11/6/95 - Setup the channel state for the given instrument. */ - /* There is some wasted effort here since both calls the same state vars */ - /* but it's safer. */ - for (i = 0; i < seqp->maxChannels; i++) { - __resetPerfChanState(seqp, i); - __setInstChanState(seqp, inst, i); - } - - if (b->percussion) { - __resetPerfChanState(seqp, i); - __setInstChanState(seqp, b->percussion, 9); - } -} - - -/* - sct 11/6/95 - Call this whenever a new instrument gets assigned to a channel - such as when changing banks or in response to a MIDI program change event. - Currently also gets called when changing sequences. -*/ -void __setInstChanState(ALSeqPlayer *seqp, ALInstrument *inst, s32 chan) -{ - seqp->chanState[chan].instrument = inst; - seqp->chanState[chan].pan = inst->pan; - seqp->chanState[chan].vol = inst->volume; - seqp->chanState[chan].priority = inst->priority; - seqp->chanState[chan].bendRange = inst->bendRange; -} - - -/* - sct 11/6/95 -- Call this whenever a new sequence is to be played or when - initializing a sequence player. -*/ -void __resetPerfChanState(ALSeqPlayer *seqp, s32 chan) -{ - seqp->chanState[chan].fxId = AL_FX_NONE; - seqp->chanState[chan].fxmix = AL_DEFAULT_FXMIX; - seqp->chanState[chan].pan = AL_PAN_CENTER; - seqp->chanState[chan].vol = AL_VOL_FULL; - seqp->chanState[chan].priority = AL_DEFAULT_PRIORITY; - seqp->chanState[chan].sustain = 0; - seqp->chanState[chan].bendRange = 200; - seqp->chanState[chan].pitchBend = 1.0f; -} - - -/* - sct 11/6/95 - Called only when creating a new sequence player. -*/ -void __initChanState(ALSeqPlayer *seqp) -{ - int i; - - for (i = 0; i < seqp->maxChannels; i++) - { - seqp->chanState[i].instrument = 0; - __resetPerfChanState (seqp, i); - } -} - - -void __seqpStopOsc(ALSeqPlayer *seqp, ALVoiceState *vs) -{ - ALEventListItem *thisNode,*nextNode; - s16 evtType; - - thisNode = (ALEventListItem*)seqp->evtq.allocList.next; - while(thisNode) - { - nextNode = (ALEventListItem*)thisNode->node.next; - evtType = thisNode->evt.type; - if(evtType == AL_TREM_OSC_EVT || evtType == AL_VIB_OSC_EVT) - { - if(thisNode->evt.msg.osc.vs == vs) - { - (*seqp->stopOsc)(thisNode->evt.msg.osc.oscState); - alUnlink((ALLink*)thisNode); - if(nextNode) - nextNode->delta += thisNode->delta; - alLink((ALLink*)thisNode, &seqp->evtq.freeList); - if(evtType == AL_TREM_OSC_EVT) - vs->flags = vs->flags & 0xFE; - else /* must be a AL_VIB_OSC_EVT */ - vs->flags = vs->flags & 0xFD; - if(!vs->flags) - return; /* there should be no more events */ - } - } - - thisNode = nextNode; - } -} - - - -/* - This routine safely calculates the sequence player's - uspt value based on the given tempo. It does this safely - by making sure that the player has a target sequence and - therefore a qnpt value which is needed for the calculation. -*/ -static void __setUsptFromTempo (ALSeqPlayer *seqp, f32 tempo) -{ - if (seqp->target) - seqp->uspt = (s32)((f32)tempo * seqp->target->qnpt); - else - seqp->uspt = 488; /* This is the initial value set by alSeqpNew. */ -} diff --git a/lib/ultralib/src/audio/seqploop.c b/lib/ultralib/src/audio/seqploop.c deleted file mode 100644 index 9bbaf5f..0000000 --- a/lib/ultralib/src/audio/seqploop.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * seqploop.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpLoop(ALSeqPlayer *seqp, ALSeqMarker *start, ALSeqMarker *end, - s32 count) -{ - ALEvent evt; - - evt.type = AL_SEQP_LOOP_EVT; - evt.msg.loop.start = start; - evt.msg.loop.end = end; - evt.msg.loop.count = count; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpplay.c b/lib/ultralib/src/audio/seqpplay.c deleted file mode 100644 index 8e65504..0000000 --- a/lib/ultralib/src/audio/seqpplay.c +++ /dev/null @@ -1,48 +0,0 @@ -/*==================================================================== - * seqpplay.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include "seqp.h" - -void alSeqpPlay(ALSeqPlayer *seqp) -{ - ALEvent evt; - - evt.type = AL_SEQP_PLAY_EVT; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - - - - - - - - - - - - - - - diff --git a/lib/ultralib/src/audio/seqpsendmidi.c b/lib/ultralib/src/audio/seqpsendmidi.c deleted file mode 100644 index 56a9510..0000000 --- a/lib/ultralib/src/audio/seqpsendmidi.c +++ /dev/null @@ -1,40 +0,0 @@ -/*==================================================================== - * seqpsendmidi.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSendMidi(ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, - u8 byte2) -{ - ALEvent evt; - ALMicroTime deltaTime; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = status; - evt.msg.midi.byte1 = byte1; - evt.msg.midi.byte2 = byte2; - evt.msg.midi.duration = 0; - - deltaTime = ticks*seqp->uspt; - - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); -} - diff --git a/lib/ultralib/src/audio/seqpsetbank.c b/lib/ultralib/src/audio/seqpsetbank.c deleted file mode 100644 index 1c00e8b..0000000 --- a/lib/ultralib/src/audio/seqpsetbank.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * seqpsetbank.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetBank(ALSeqPlayer *seqp, ALBank *b) -{ - ALEvent evt; - - evt.type = AL_SEQP_BANK_EVT; - evt.msg.spbank.bank = b; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpsetchlvol.c b/lib/ultralib/src/audio/seqpsetchlvol.c deleted file mode 100644 index 9b48803..0000000 --- a/lib/ultralib/src/audio/seqpsetchlvol.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * seqpsetchlvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetChlVol(ALSeqPlayer *seqp, u8 chan, u8 vol) -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ControlChange | chan; - evt.msg.midi.byte1 = AL_MIDI_VOLUME_CTRL; - evt.msg.midi.byte2 = vol; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpsetfxmix.c b/lib/ultralib/src/audio/seqpsetfxmix.c deleted file mode 100644 index 9397963..0000000 --- a/lib/ultralib/src/audio/seqpsetfxmix.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * seqpsetfxmix.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetChlFXMix(ALSeqPlayer *seqp, u8 chan, u8 fxmix) -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ControlChange | chan; - evt.msg.midi.byte1 = AL_MIDI_FX1_CTRL; - evt.msg.midi.byte2 = fxmix; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpsetpan.c b/lib/ultralib/src/audio/seqpsetpan.c deleted file mode 100644 index 85d07d9..0000000 --- a/lib/ultralib/src/audio/seqpsetpan.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * seqpsetpan.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetChlPan(ALSeqPlayer *seqp, u8 chan, ALPan pan) -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ControlChange | chan; - evt.msg.midi.byte1 = AL_MIDI_PAN_CTRL; - evt.msg.midi.byte2 = pan; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpsetpriority.c b/lib/ultralib/src/audio/seqpsetpriority.c deleted file mode 100644 index 0910726..0000000 --- a/lib/ultralib/src/audio/seqpsetpriority.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * seqpsetpriority.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetChlPriority(ALSeqPlayer *seqp, u8 chan, u8 priority) -{ - ALEvent evt; - - evt.type = AL_SEQP_PRIORITY_EVT; - evt.msg.sppriority.chan = chan; - evt.msg.sppriority.priority = priority; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} diff --git a/lib/ultralib/src/audio/seqpsetprogram.c b/lib/ultralib/src/audio/seqpsetprogram.c deleted file mode 100644 index dfd6d94..0000000 --- a/lib/ultralib/src/audio/seqpsetprogram.c +++ /dev/null @@ -1,36 +0,0 @@ -/*==================================================================== - * seqpsetprogram.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetChlProgram(ALSeqPlayer *seqp, u8 chan, u8 prog) - -{ - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ProgramChange | chan; - evt.msg.midi.byte1 = prog; - evt.msg.midi.byte2 = 0; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpsetseq.c b/lib/ultralib/src/audio/seqpsetseq.c deleted file mode 100644 index 3fe8175..0000000 --- a/lib/ultralib/src/audio/seqpsetseq.c +++ /dev/null @@ -1,34 +0,0 @@ -/*==================================================================== - * seqpsetseq.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetSeq(ALSeqPlayer *seqp, ALSeq *seq) -{ - ALEvent evt; - - evt.type = AL_SEQP_SEQ_EVT; - evt.msg.spseq.seq = seq; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpsettempo.c b/lib/ultralib/src/audio/seqpsettempo.c deleted file mode 100644 index 592320a..0000000 --- a/lib/ultralib/src/audio/seqpsettempo.c +++ /dev/null @@ -1,36 +0,0 @@ -/*==================================================================== - * seqpsettempo.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetTempo(ALSeqPlayer *seqp, s32 tempo) -{ - ALEvent evt; - - evt.type = AL_SEQP_META_EVT; - evt.msg.tempo.status = AL_MIDI_Meta; - evt.msg.tempo.type = AL_MIDI_META_TEMPO; - evt.msg.tempo.byte1 = (tempo & 0xff0000)>>16; - evt.msg.tempo.byte2 = (tempo & 0xff00)>>8; - evt.msg.tempo.byte3 = tempo & 0xff; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpsetvol.c b/lib/ultralib/src/audio/seqpsetvol.c deleted file mode 100644 index b698a40..0000000 --- a/lib/ultralib/src/audio/seqpsetvol.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * seqpsetvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpSetVol(ALSeqPlayer *seqp, s16 vol) -{ - ALEvent evt; - - evt.type = AL_SEQP_VOL_EVT; - evt.msg.spvol.vol = vol; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} - diff --git a/lib/ultralib/src/audio/seqpstop.c b/lib/ultralib/src/audio/seqpstop.c deleted file mode 100644 index abec781..0000000 --- a/lib/ultralib/src/audio/seqpstop.c +++ /dev/null @@ -1,33 +0,0 @@ -/*==================================================================== - * seqpstop.c - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSeqpStop(ALSeqPlayer *seqp) -{ - ALEvent evt; - - evt.type = AL_SEQP_STOPPING_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, 0); - -} - diff --git a/lib/ultralib/src/audio/sl.c b/lib/ultralib/src/audio/sl.c deleted file mode 100644 index d184972..0000000 --- a/lib/ultralib/src/audio/sl.c +++ /dev/null @@ -1,65 +0,0 @@ -/*==================================================================== - * sl.c - * - * Synopsis: - * Sound library global routines - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -ALGlobals *alGlobals=0; - -void alInit(ALGlobals *g, ALSynConfig *c) -{ - if (!alGlobals) { /* already initialized? */ - alGlobals = g; - alSynNew(&alGlobals->drvr, c); - } -} - -void alClose(ALGlobals *glob) -{ - if (alGlobals) { - alSynDelete(&glob->drvr); - alGlobals = 0; - } -} - -/* might want to make these macros */ -void alLink(ALLink *ln, ALLink *to) -{ - ln->next = to->next; - ln->prev = to; - if (to->next) - to->next->prev = ln; - to->next = ln; -} - -void alUnlink(ALLink *ln) -{ - if (ln->next) - ln->next->prev = ln->prev; - if (ln->prev) - ln->prev->next = ln->next; -} - - - - - diff --git a/lib/ultralib/src/audio/sndp.h b/lib/ultralib/src/audio/sndp.h deleted file mode 100644 index 17d7015..0000000 --- a/lib/ultralib/src/audio/sndp.h +++ /dev/null @@ -1,102 +0,0 @@ -/*==================================================================== - * sndp.h - * - * Synopsis: - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - - -#ifndef __SNDP__ -#define __SNDP__ - -#include - -#ifndef MIN -#define MIN(a,b) (((a)<(b))?(a):(b)) -#endif - -#ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - -#define MIN_RATIO 0.0001 - -typedef enum { - AL_SNDP_PLAY_EVT, - AL_SNDP_STOP_EVT, - AL_SNDP_PAN_EVT, - AL_SNDP_VOL_EVT, - AL_SNDP_PITCH_EVT, - AL_SNDP_API_EVT, - AL_SNDP_DECAY_EVT, - AL_SNDP_END_EVT, - AL_SNDP_FX_EVT -} ALSndpMsgType; - -typedef struct { - ALVoice voice; - ALSound *sound; /* sound referenced here */ - s16 priority; - f32 pitch; /* current playback pitch */ - s32 state; /* play state for this sound */ - s16 vol; /* volume - combined with volume from bank */ - ALPan pan; /* pan - 0 = left, 127 = right */ - u8 fxMix; /* wet/dry mix - 0 = dry, 127 = wet */ -} ALSoundState; - -typedef union { - - ALEvent msg; - - struct { - s16 type; - ALSoundState *state; - } common; - - struct { - s16 type; - ALSoundState *state; - s16 vol; - } vol; - - struct { - s16 type; - ALSoundState *state; - f32 pitch; - } pitch; - - struct { - s16 type; - ALSoundState *state; - ALPan pan; - } pan; - - struct { - s16 type; - ALSoundState *state; - u8 mix; - } fx; - -} ALSndpEvent; - -static ALMicroTime _sndpVoiceHandler(void *node); -static void _handleEvent(ALSndPlayer *sndp, ALSndpEvent *event); -static void _removeEvents(ALEventQueue *evtq, ALSoundState *state); -static s32 _DivS32ByF32 (s32 i, f32 f); - -#endif diff --git a/lib/ultralib/src/audio/sndpallocate.c b/lib/ultralib/src/audio/sndpallocate.c deleted file mode 100644 index 0629ac7..0000000 --- a/lib/ultralib/src/audio/sndpallocate.c +++ /dev/null @@ -1,43 +0,0 @@ -/*==================================================================== - * sndpallocate.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" - -ALSndId alSndpAllocate(ALSndPlayer *sndp, ALSound *sound) -{ - ALSndId i; - ALSoundState *sState = sndp->sndState; - - for (i = 0; i < sndp->maxSounds; i++) { - if (!sState[i].sound) { - sState[i].sound = sound; - sState[i].priority = AL_DEFAULT_PRIORITY; - sState[i].state = AL_STOPPED; - sState[i].pitch = 1.0; - sState[i].pan = AL_PAN_CENTER; - sState[i].fxMix = AL_DEFAULT_FXMIX; - sState[i].vol = 32767*sound->sampleVolume/AL_VOL_FULL; - return i; - } - } - - return -1; -} - diff --git a/lib/ultralib/src/audio/sndpdeallocate.c b/lib/ultralib/src/audio/sndpdeallocate.c deleted file mode 100644 index 7c18b56..0000000 --- a/lib/ultralib/src/audio/sndpdeallocate.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * sndpdeallocate.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpDeallocate(ALSndPlayer *sndp, ALSndId id) -{ - ALSoundState *sState = sndp->sndState; - - ALFailIf((sState + id)->state != AL_STOPPED, ERR_ALSNDPDEALLOCATE); - - sState[id].sound = 0; - if (sndp->target == id) /* if we are deleting the target sound */ - sndp->target = -1; -} - diff --git a/lib/ultralib/src/audio/sndpdelete.c b/lib/ultralib/src/audio/sndpdelete.c deleted file mode 100644 index 5cfb4f7..0000000 --- a/lib/ultralib/src/audio/sndpdelete.c +++ /dev/null @@ -1,44 +0,0 @@ -/*==================================================================== - * sndpdelete.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpDelete(ALSndPlayer *sndp) -{ - /* - * Remove client from synthesizer. Note application is responsible - * for making sure all sounds have been stopped beforehand. - */ -#ifdef _DEBUG - { - int i, notStopped = 0; - ALSoundState *sState = sndp->sndState; - - for (i=0; imaxSounds; i++) - if ((sState + i)->state != AL_STOPPED) - notStopped = 1; - ALFailIf(notStopped, ERR_ALSNDPDELETE); - } -#endif - alSynRemovePlayer(&alGlobals->drvr, &sndp->node); -} - diff --git a/lib/ultralib/src/audio/sndpgetsound.c b/lib/ultralib/src/audio/sndpgetsound.c deleted file mode 100644 index 9088982..0000000 --- a/lib/ultralib/src/audio/sndpgetsound.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * sndpgetsound.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" - -ALSndId alSndpGetSound(ALSndPlayer *sndp) -{ - return (ALSndId) sndp->target; -} - diff --git a/lib/ultralib/src/audio/sndpgetstate.c b/lib/ultralib/src/audio/sndpgetstate.c deleted file mode 100644 index 882b4a3..0000000 --- a/lib/ultralib/src/audio/sndpgetstate.c +++ /dev/null @@ -1,29 +0,0 @@ -/*==================================================================== - * sndpgetstate.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" - -s32 alSndpGetState(ALSndPlayer *sndp) -{ - ALSoundState *sState = sndp->sndState; - - return (sState + sndp->target)->state; -} - diff --git a/lib/ultralib/src/audio/sndplayer.c b/lib/ultralib/src/audio/sndplayer.c deleted file mode 100644 index f2d7b56..0000000 --- a/lib/ultralib/src/audio/sndplayer.c +++ /dev/null @@ -1,297 +0,0 @@ -/*==================================================================== - * Sndplayer.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include -#include - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void alSndpNew(ALSndPlayer *sndp, ALSndpConfig *c) -{ - u8 *ptr; - ALEvent evt; - ALSoundState *sState; - u32 i; - - /* - * Init member variables - */ - sndp->maxSounds = c->maxSounds; - sndp->target = -1; - sndp->frameTime = AL_USEC_PER_FRAME; /* time between API events */ - sState = (ALSoundState*)alHeapAlloc(c->heap, 1, - c->maxSounds * sizeof(ALSoundState)); - sndp->sndState = sState; - - for(i = 0; i < c->maxSounds; i++) - sState[i].sound = 0; - - /* - * init the event queue - */ - ptr = alHeapAlloc(c->heap, 1, c->maxEvents * sizeof(ALEventListItem)); - alEvtqNew(&sndp->evtq, (ALEventListItem *)ptr, c->maxEvents); - - /* - * add ourselves to the driver - */ - sndp->drvr = &alGlobals->drvr; - sndp->node.next = NULL; - sndp->node.handler = _sndpVoiceHandler; - sndp->node.clientData = sndp; - alSynAddPlayer(sndp->drvr, &sndp->node); - - /* - * Start responding to API events - */ - evt.type = AL_SNDP_API_EVT; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, sndp->frameTime); - sndp->nextDelta = alEvtqNextEvent(&sndp->evtq, &sndp->nextEvent); - -} - -/************************************************************* - * Sound Player private routines - *************************************************************/ -ALMicroTime _sndpVoiceHandler(void *node) -{ - ALSndPlayer *sndp = (ALSndPlayer *) node; - ALSndpEvent evt; - - do { - switch (sndp->nextEvent.type) { - case (AL_SNDP_API_EVT): - evt.common.type = AL_SNDP_API_EVT; -#if BUILD_VERSION >= VERSION_K - evt.common.state = (ALSoundState*)-1; -#endif - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, sndp->frameTime); - break; - - default: - _handleEvent(sndp, (ALSndpEvent *)&sndp->nextEvent); - break; - } - sndp->nextDelta = alEvtqNextEvent(&sndp->evtq, &sndp->nextEvent); - - } while (sndp->nextDelta == 0); - sndp->curTime += sndp->nextDelta; - return sndp->nextDelta; -} - -void _handleEvent(ALSndPlayer *sndp, ALSndpEvent *event) -{ - ALVoiceConfig vc; - ALSound *snd; - ALVoice *voice; - ALPan pan; - f32 pitch; - ALSndpEvent evt; - ALMicroTime delta; - - s16 vol; - s16 tmp; - s32 vtmp; - ALSoundState *state; - - state = event->common.state; - snd = state->sound; - - - switch (event->msg.type) { - case (AL_SNDP_PLAY_EVT): - if (state->state != AL_STOPPED || !snd) - return; - - vc.fxBus = 0; /* effect buss 0 */ - vc.priority = state->priority; - vc.unityPitch = 0; - - voice = &state->voice; - alSynAllocVoice(sndp->drvr, voice, &vc); - - vol = (s16) ((s32) snd->envelope->attackVolume*state->vol/AL_VOL_FULL); - tmp = state->pan - AL_PAN_CENTER + snd->samplePan; - tmp = MAX(tmp, AL_PAN_LEFT); - pan = (ALPan) MIN(tmp, AL_PAN_RIGHT); - pitch = state->pitch; - delta = snd->envelope->attackTime; - - alSynStartVoice(sndp->drvr, voice, snd->wavetable); - state->state = AL_PLAYING; - - alSynSetPan(sndp->drvr, voice, pan); - alSynSetVol(sndp->drvr, voice, vol, delta); - alSynSetPitch(sndp->drvr, voice, pitch); - alSynSetFXMix(sndp->drvr, voice, state->fxMix); - - evt.common.type = AL_SNDP_DECAY_EVT; - evt.common.state = state; - delta = (ALMicroTime) _DivS32ByF32 (snd->envelope->attackTime, state->pitch); - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); - break; - - case (AL_SNDP_STOP_EVT): - if (state->state != AL_PLAYING || !snd) - return; - - delta = (ALMicroTime) _DivS32ByF32 (snd->envelope->releaseTime, state->pitch); - alSynSetVol(sndp->drvr, &state->voice, 0, delta); - - if (delta) { - evt.common.type = AL_SNDP_END_EVT; - evt.common.state = state; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); - state->state = AL_STOPPING; - } else { - /* note: this code is repeated in AL_SNDP_END_EVT */ - alSynStopVoice(sndp->drvr, &state->voice); - alSynFreeVoice(sndp->drvr, &state->voice); - _removeEvents(&sndp->evtq, state); - state->state = AL_STOPPED; - } - break; - - case (AL_SNDP_PAN_EVT): - state->pan = event->pan.pan; - if (state->state == AL_PLAYING && snd){ - tmp = state->pan - AL_PAN_CENTER + snd->samplePan; - tmp = MAX(tmp, AL_PAN_LEFT); - pan = (ALPan) MIN(tmp, AL_PAN_RIGHT); - alSynSetPan(sndp->drvr, &state->voice, pan); - } - break; - - case (AL_SNDP_PITCH_EVT): - /* Limit the pitch to a practical value even though we only need */ - /* to limit it to a non-zero number to avoid divide by zero. */ - if ((state->pitch = event->pitch.pitch) < MIN_RATIO) - state->pitch = MIN_RATIO; - - if (state->state == AL_PLAYING){ - alSynSetPitch(sndp->drvr, &state->voice, state->pitch); - } - break; - - case (AL_SNDP_FX_EVT): - state->fxMix = event->fx.mix; - if (state->state == AL_PLAYING) - alSynSetFXMix(sndp->drvr, &state->voice, state->fxMix); - break; - - case (AL_SNDP_VOL_EVT): - state->vol = event->vol.vol; - if (state->state == AL_PLAYING && snd){ - vtmp = snd->envelope->decayVolume * state->vol/AL_VOL_FULL; - alSynSetVol(sndp->drvr, &state->voice, (s16) vtmp, 1000); - } - break; - - case (AL_SNDP_DECAY_EVT): - /* - * The voice has theoretically reached its attack velocity, - * set up callback for release envelope - except for a looped sound - */ - if (snd->envelope->decayTime != -1){ - vtmp = snd->envelope->decayVolume * state->vol/AL_VOL_FULL; - delta = (ALMicroTime) _DivS32ByF32 (snd->envelope->decayTime, state->pitch); - alSynSetVol(sndp->drvr, &state->voice, (s16) vtmp, delta); - evt.common.type = AL_SNDP_STOP_EVT; - evt.common.state = state; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); - } - break; - - case (AL_SNDP_END_EVT): - /* note: this code is repeated in AL_SNDP_STOP_EVT */ - alSynStopVoice(sndp->drvr, &state->voice); - alSynFreeVoice(sndp->drvr, &state->voice); - _removeEvents(&sndp->evtq, state); - state->state = AL_STOPPED; - break; - - default: - break; - } -} -static void _removeEvents(ALEventQueue *evtq, ALSoundState *state) -{ - ALLink *thisNode; - ALLink *nextNode; - ALEventListItem *thisItem; - ALEventListItem *nextItem; - ALSndpEvent *thisEvent; - OSIntMask mask; - - mask = osSetIntMask(OS_IM_NONE); - - thisNode = evtq->allocList.next; - while( thisNode != 0 ) { - nextNode = thisNode->next; - thisItem = (ALEventListItem *)thisNode; - nextItem = (ALEventListItem *)nextNode; - thisEvent = (ALSndpEvent *) &thisItem->evt; - if (thisEvent->common.state == state){ - if( nextItem ) - nextItem->delta += thisItem->delta; - alUnlink(thisNode); - alLink(thisNode, &evtq->freeList); - } - thisNode = nextNode; - } - - osSetIntMask(mask); -} -/* - This routine safely divides a signed 32-bit integer - by a floating point value. It avoids overflow by using - a double to store the result and then before truncating - to an integer it compares the result to the limit and - limits it on overflow. Underflow is handled automatically - by the CPU which limits the value to zero. - - Presently this routine is used to divide a time in usecs - by a pitch ratio. Since the time could be a very large number, - very small pitch ratios can cause the reult to overflow, - causing a floating point exception. -*/ -#if BUILD_VERSION == VERSION_J // Adjust line numbers to match assert -#line 277 -#elif BUILD_VERSION < VERSION_J -#line 278 -#endif -static s32 _DivS32ByF32 (s32 i, f32 f) -{ - #define INT_MAX 2147483647 /* Should be in a limits.h file. */ - f64 rd; - int ri; - - assert(f!=0); /* Caller must make sure we do not divide by zero! */ - - rd = i/f; /* Store result as a double to avoid overflow. */ - - if (rd > INT_MAX) /* Limit the value if necessary. */ - ri = INT_MAX; - else - ri = rd; - - return ri; -} diff --git a/lib/ultralib/src/audio/sndpplay.c b/lib/ultralib/src/audio/sndpplay.c deleted file mode 100644 index ff5d123..0000000 --- a/lib/ultralib/src/audio/sndpplay.c +++ /dev/null @@ -1,36 +0,0 @@ -/*==================================================================== - * sndpplay.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpPlay(ALSndPlayer *sndp) -{ - ALSndpEvent evt; - ALSoundState *sState = sndp->sndState; - - ALFailIf((sState + sndp->target)->state != AL_STOPPED, ERR_ALSNDPPLAY); - - evt.common.type = AL_SNDP_PLAY_EVT; - evt.common.state = &sState[sndp->target]; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); -} - diff --git a/lib/ultralib/src/audio/sndpplayat.c b/lib/ultralib/src/audio/sndpplayat.c deleted file mode 100644 index b37f796..0000000 --- a/lib/ultralib/src/audio/sndpplayat.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * sndpplayat.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" - -void alSndpPlayAt(ALSndPlayer *sndp, ALMicroTime delta) -{ - ALSndpEvent evt; - ALSoundState *sState = sndp->sndState; - - evt.common.type = AL_SNDP_PLAY_EVT; - evt.common.state = &sState[sndp->target]; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); -} - diff --git a/lib/ultralib/src/audio/sndpsetfxmix.c b/lib/ultralib/src/audio/sndpsetfxmix.c deleted file mode 100644 index 147c956..0000000 --- a/lib/ultralib/src/audio/sndpsetfxmix.c +++ /dev/null @@ -1,42 +0,0 @@ -/*==================================================================== - * sndpsetfxmix.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpSetFXMix(ALSndPlayer *sndp, u8 mix) -{ - ALSndpEvent evt; - ALSoundState *sState = sndp->sndState; - -#ifdef _DEBUG - if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ - __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); - return; - } -#endif - - evt.fx.type = AL_SNDP_FX_EVT; - evt.fx.state = &sState[sndp->target]; - evt.fx.mix = mix; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); -} - diff --git a/lib/ultralib/src/audio/sndpsetpan.c b/lib/ultralib/src/audio/sndpsetpan.c deleted file mode 100644 index 5f98648..0000000 --- a/lib/ultralib/src/audio/sndpsetpan.c +++ /dev/null @@ -1,42 +0,0 @@ -/*==================================================================== - * sndpsetpan.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpSetPan(ALSndPlayer *sndp, ALPan pan) -{ - ALSndpEvent evt; - ALSoundState *sState = sndp->sndState; - -#ifdef _DEBUG - if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ - __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); - return; - } -#endif - - evt.pan.type = AL_SNDP_PAN_EVT; - evt.pan.pan = pan; - evt.pan.state = &sState[sndp->target]; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); -} - diff --git a/lib/ultralib/src/audio/sndpsetpitch.c b/lib/ultralib/src/audio/sndpsetpitch.c deleted file mode 100644 index 0ee174c..0000000 --- a/lib/ultralib/src/audio/sndpsetpitch.c +++ /dev/null @@ -1,48 +0,0 @@ -/*==================================================================== - * sndpsetpitch.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpSetPitch(ALSndPlayer *sndp, f32 pitch) -{ - ALSndpEvent evt; - ALSoundState *sState = sndp->sndState; - - /* - * If this is set during playback there will be - * a the envelope lengths won't be accurate - but you can still - * do it. - */ - -#ifdef _DEBUG - if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ - __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); - return; - } -#endif - - evt.pitch.type = AL_SNDP_PITCH_EVT; - evt.pitch.state = &sState[sndp->target]; - evt.pitch.pitch = pitch; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); -} - diff --git a/lib/ultralib/src/audio/sndpsetpriority.c b/lib/ultralib/src/audio/sndpsetpriority.c deleted file mode 100644 index 0d0fbc0..0000000 --- a/lib/ultralib/src/audio/sndpsetpriority.c +++ /dev/null @@ -1,38 +0,0 @@ -/*==================================================================== - * sndpsetsound.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpSetPriority(ALSndPlayer *sndp, ALSndId id, u8 priority) -{ - ALSoundState *sState = sndp->sndState; - -#ifdef _DEBUG - if ((id >= sndp->maxSounds) || (id < 0)){ - __osError(ERR_ALSNDPSETPRIORITY, 2, id, sndp->maxSounds-1); - return; - } -#endif - - sState[id].priority = priority; -} - diff --git a/lib/ultralib/src/audio/sndpsetsound.c b/lib/ultralib/src/audio/sndpsetsound.c deleted file mode 100644 index 3d341ec..0000000 --- a/lib/ultralib/src/audio/sndpsetsound.c +++ /dev/null @@ -1,36 +0,0 @@ -/*==================================================================== - * sndpsetsound.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpSetSound(ALSndPlayer *sndp, ALSndId id) -{ -#ifdef _DEBUG - if ((id >= sndp->maxSounds) || (id < 0)){ - __osError(ERR_ALSNDPSETSOUND, 2, id, sndp->maxSounds-1); - return; - } -#endif - - sndp->target = id; -} - diff --git a/lib/ultralib/src/audio/sndpsetvol.c b/lib/ultralib/src/audio/sndpsetvol.c deleted file mode 100644 index ad79f5f..0000000 --- a/lib/ultralib/src/audio/sndpsetvol.c +++ /dev/null @@ -1,42 +0,0 @@ -/*==================================================================== - * sndpsetvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" -#include -#include - -void alSndpSetVol(ALSndPlayer *sndp, s16 vol) -{ - ALSndpEvent evt; - ALSoundState *sState = sndp->sndState; - -#ifdef _DEBUG - if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ - __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); - return; - } -#endif - - evt.vol.type = AL_SNDP_VOL_EVT; - evt.vol.state = &sState[sndp->target]; - evt.vol.vol = vol; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); -} - diff --git a/lib/ultralib/src/audio/sndpstop.c b/lib/ultralib/src/audio/sndpstop.c deleted file mode 100644 index 69aead6..0000000 --- a/lib/ultralib/src/audio/sndpstop.c +++ /dev/null @@ -1,35 +0,0 @@ -/*==================================================================== - * sndpstop.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "sndp.h" - -void alSndpStop(ALSndPlayer *sndp) -{ - ALSndpEvent evt; - ALSoundState *sState = sndp->sndState; - - /* - * Go immediately into the release phase - */ - evt.common.type = AL_SNDP_STOP_EVT; - evt.common.state = &sState[sndp->target]; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); -} - diff --git a/lib/ultralib/src/audio/synaddplayer.c b/lib/ultralib/src/audio/synaddplayer.c deleted file mode 100644 index 77efb29..0000000 --- a/lib/ultralib/src/audio/synaddplayer.c +++ /dev/null @@ -1,34 +0,0 @@ -/*==================================================================== - * synaddplayer.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include - -void alSynAddPlayer(ALSynth *drvr, ALPlayer *client) -{ - OSIntMask mask = osSetIntMask(OS_IM_NONE); - - client->samplesLeft = drvr->curSamples; - client->next = drvr->head; - drvr->head = client; - - osSetIntMask(mask); -} - diff --git a/lib/ultralib/src/audio/synallocfx.c b/lib/ultralib/src/audio/synallocfx.c deleted file mode 100644 index e0e7f26..0000000 --- a/lib/ultralib/src/audio/synallocfx.c +++ /dev/null @@ -1,32 +0,0 @@ -/*==================================================================== - * synallocfx.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" - -ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp) -{ - alFxNew(&s->auxBus[bus].fx[0], c, hp); - alFxParam(&s->auxBus[bus].fx[0], AL_FILTER_SET_SOURCE, - &s->auxBus[bus]); - alMainBusParam(s->mainBus, AL_FILTER_ADD_SOURCE,&s->auxBus[bus].fx[0]); - - return (ALFxRef)(&s->auxBus[bus].fx[0]); -} - diff --git a/lib/ultralib/src/audio/synallocvoice.c b/lib/ultralib/src/audio/synallocvoice.c deleted file mode 100644 index 73d608d..0000000 --- a/lib/ultralib/src/audio/synallocvoice.c +++ /dev/null @@ -1,132 +0,0 @@ -/*==================================================================== - * synallocvoice.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include -#include "synthInternals.h" - -s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority); - -s32 alSynAllocVoice(ALSynth *drvr, ALVoice *voice, ALVoiceConfig *vc) -{ - PVoice *pvoice = 0; - ALFilter *f; - ALParam *update; - s32 stolen; - -#ifdef _DEBUG - /* need two updates if voice is stolen */ - if (drvr->paramList == 0) { - __osError(ERR_ALSYN_NO_UPDATE, 0); - return 0; - } else if (drvr->paramList->next == 0) { - __osError(ERR_ALSYN_NO_UPDATE, 0); - return 0; - } -#endif - - voice->priority = vc->priority; - voice->unityPitch = vc->unityPitch; - voice->table = 0; - voice->fxBus = vc->fxBus; - voice->state = AL_STOPPED; - voice->pvoice = 0; - - stolen = _allocatePVoice(drvr, &pvoice, vc->priority); - - if (pvoice) { /* if we were able to allocate a voice */ - - f = pvoice->channelKnob; - - if (stolen) { - - pvoice->offset = 512; - pvoice->vvoice->pvoice = 0; /* zero stolen voice */ - - /* - * ramp down stolen voice - */ - update = __allocParam(); - update->delta = drvr->paramSamples; - update->type = AL_FILTER_SET_VOLUME; - update->data.i = 0; - update->moredata.i = pvoice->offset - 64; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - - /* - * stop stolen voice - */ - update = __allocParam(); - if (update) { - update->delta = drvr->paramSamples + pvoice->offset; - update->type = AL_FILTER_STOP_VOICE; - update->next = 0; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } else { -#ifdef _DEBUG - __osError(ERR_ALSYN_NO_UPDATE, 0); -#endif - } - - } else { - pvoice->offset = 0; - } - - pvoice->vvoice = voice; /* assign new voice */ - voice->pvoice = pvoice; - - } - - return (pvoice != 0); -} - -s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority) -{ - ALLink *dl; - PVoice *pv; - s32 stolen = 0; - - if ((dl = drvr->pLameList.next) != 0) { /* check the lame list first */ - *pvoice = (PVoice *) dl; - alUnlink(dl); - alLink(dl, &drvr->pAllocList); - } else if ((dl = drvr->pFreeList.next) != 0) { /* from the free list */ - *pvoice = (PVoice *) dl; - alUnlink(dl); - alLink(dl, &drvr->pAllocList); - } else { /* steal one */ - for (dl = drvr->pAllocList.next; dl != 0; dl = dl->next) { - pv = (PVoice *)dl; - - /* - * if it is lower priority and not already stolen, keep it - * as a candidate for stealing - */ - if ((pv->vvoice->priority <= priority) && (pv->offset == 0)) { - *pvoice = pv; - priority = pv->vvoice->priority; - stolen = 1; - } - } - } - - return stolen; -} - diff --git a/lib/ultralib/src/audio/syndelete.c b/lib/ultralib/src/audio/syndelete.c deleted file mode 100644 index 900fe76..0000000 --- a/lib/ultralib/src/audio/syndelete.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * syndelete.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" - -void alSynDelete(ALSynth *drvr) -{ - drvr->head = 0; -} - diff --git a/lib/ultralib/src/audio/synfreefx.c b/lib/ultralib/src/audio/synfreefx.c deleted file mode 100644 index be436ea..0000000 --- a/lib/ultralib/src/audio/synfreefx.c +++ /dev/null @@ -1,26 +0,0 @@ -/*==================================================================== - * synfreefx.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" - -void alSynFreeFX(ALSynth *s, ALFxRef *fx) -{ -} - diff --git a/lib/ultralib/src/audio/synfreevoice.c b/lib/ultralib/src/audio/synfreevoice.c deleted file mode 100644 index eaa71ac..0000000 --- a/lib/ultralib/src/audio/synfreevoice.c +++ /dev/null @@ -1,54 +0,0 @@ -/*==================================================================== - * synfreevoice.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include -#include -#include "synthInternals.h" - -#include - -void alSynFreeVoice(ALSynth *drvr, ALVoice *voice) -{ - ALFilter *f; - ALFreeParam *update; - - if (voice->pvoice) { - - if (voice->pvoice->offset) { /* if voice was stolen */ - update = (ALFreeParam *)__allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - - /* - * set voice data - */ - update->delta = drvr->paramSamples + voice->pvoice->offset; - update->type = AL_FILTER_FREE_VOICE; - update->pvoice = voice->pvoice; - - f = voice->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } else { - _freePVoice(drvr, voice->pvoice); - } - - voice->pvoice = 0; - - } -} diff --git a/lib/ultralib/src/audio/syngetfxref.c b/lib/ultralib/src/audio/syngetfxref.c deleted file mode 100644 index b0fa577..0000000 --- a/lib/ultralib/src/audio/syngetfxref.c +++ /dev/null @@ -1,33 +0,0 @@ -/*==================================================================== - * syngetfxref.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" - -ALFxRef alSynGetFXRef(ALSynth *s, s16 bus, s16 index) -{ - ALMainBus *m = (ALMainBus *) s->mainBus; - ALFilter **sources = m->sources; - - if (sources[0]->type == AL_FX) - return (ALFxRef)(&s->auxBus[bus].fx[index]); - else - return 0; -} - diff --git a/lib/ultralib/src/audio/syngetpriority.c b/lib/ultralib/src/audio/syngetpriority.c deleted file mode 100644 index 68de365..0000000 --- a/lib/ultralib/src/audio/syngetpriority.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * syngetpriority.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" - -s16 alSynGetPriority(ALSynth *s, ALVoice *voice) -{ - return voice->priority; -} - diff --git a/lib/ultralib/src/audio/synremoveplayer.c b/lib/ultralib/src/audio/synremoveplayer.c deleted file mode 100644 index 0248a7e..0000000 --- a/lib/ultralib/src/audio/synremoveplayer.c +++ /dev/null @@ -1,49 +0,0 @@ -/*==================================================================== - * synremoveplayer.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include - -void alSynRemovePlayer(ALSynth *drvr, ALPlayer *client) -{ - ALPlayer *thing; - ALPlayer *prev = 0; - - if (drvr->head != 0) - { - OSIntMask mask = osSetIntMask(OS_IM_NONE); - - for (thing = drvr->head; thing != 0; thing = thing->next) { - if (thing == client) { - if(prev) - prev->next = thing->next; - else - drvr->head = thing->next; - - client->next = 0; - break; - } - prev = thing; - } - - osSetIntMask(mask); - } -} - diff --git a/lib/ultralib/src/audio/synsetfxmix.c b/lib/ultralib/src/audio/synsetfxmix.c deleted file mode 100644 index c787103..0000000 --- a/lib/ultralib/src/audio/synsetfxmix.c +++ /dev/null @@ -1,60 +0,0 @@ -/*==================================================================== - * synsetfxmix.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include - -void alSynSetFXMix(ALSynth *synth, ALVoice *v, u8 fxmix) -{ - ALParam *update; - ALFilter *f; - - if (v->pvoice) { - /* - * get new update struct from the free list - */ - update = __allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - - /* - * set offset and fxmix data - */ - update->delta = synth->paramSamples + v->pvoice->offset; - update->type = AL_FILTER_SET_FXAMT; -#if BUILD_VERSION >= VERSION_J - if (fxmix > 127) { - fxmix = 127; - } - update->data.i = fxmix; -#else - if (fxmix < 0) { // Not possible - update->data.i = -fxmix; - } else { - update->data.i = fxmix; - } -#endif - update->next = 0; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } -} - diff --git a/lib/ultralib/src/audio/synsetfxparam.c b/lib/ultralib/src/audio/synsetfxparam.c deleted file mode 100644 index b3991f6..0000000 --- a/lib/ultralib/src/audio/synsetfxparam.c +++ /dev/null @@ -1,29 +0,0 @@ -/*==================================================================== - * synsetfxparam.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" - -void alSynSetFXParam(ALSynth *synth, ALFxRef fx, s16 paramID, void *param) -{ - ALFx *f = (ALFx *)fx; - - (*f->paramHdl)(f, (s32)paramID, param); -} - diff --git a/lib/ultralib/src/audio/synsetpan.c b/lib/ultralib/src/audio/synsetpan.c deleted file mode 100644 index 0d68538..0000000 --- a/lib/ultralib/src/audio/synsetpan.c +++ /dev/null @@ -1,50 +0,0 @@ -/*==================================================================== - * synsetpan.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include - -void alSynSetPan(ALSynth *synth, ALVoice *v, u8 pan) -{ - ALParam *update; - ALFilter *f; - - if (v->pvoice) { - - /* - * get new update struct from the free list - */ - update = __allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - - /* - * set offset and pan data - */ - update->delta = synth->paramSamples + v->pvoice->offset; - update->type = AL_FILTER_SET_PAN; - update->data.i = pan; - update->next = 0; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } -} - diff --git a/lib/ultralib/src/audio/synsetpitch.c b/lib/ultralib/src/audio/synsetpitch.c deleted file mode 100644 index 0bfb7ba..0000000 --- a/lib/ultralib/src/audio/synsetpitch.c +++ /dev/null @@ -1,50 +0,0 @@ -/*==================================================================== - * synsetpitch.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include - -void alSynSetPitch(ALSynth *synth, ALVoice *v, f32 pitch) -{ - ALParam *update; - ALFilter *f; - - if (v->pvoice) { - /* - * get new update struct from the free list - */ - - update = __allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - - /* - * set offset and pitch data - */ - update->delta = synth->paramSamples + v->pvoice->offset; - update->type = AL_FILTER_SET_PITCH; - update->data.f = pitch; - update->next = 0; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } -} - diff --git a/lib/ultralib/src/audio/synsetpriority.c b/lib/ultralib/src/audio/synsetpriority.c deleted file mode 100644 index c680bcc..0000000 --- a/lib/ultralib/src/audio/synsetpriority.c +++ /dev/null @@ -1,27 +0,0 @@ -/*==================================================================== - * synsetpriority.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include - -void alSynSetPriority(ALSynth *s, ALVoice *voice, s16 priority) -{ - voice->priority = priority; -} - diff --git a/lib/ultralib/src/audio/synsetvol.c b/lib/ultralib/src/audio/synsetvol.c deleted file mode 100644 index 181c96f..0000000 --- a/lib/ultralib/src/audio/synsetvol.c +++ /dev/null @@ -1,50 +0,0 @@ -/*==================================================================== - * synsetvol.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include - -void alSynSetVol(ALSynth *synth, ALVoice *v, s16 volume, ALMicroTime t) -{ - ALParam *update; - ALFilter *f; - - if (v->pvoice) { - /* - * get new update struct from the free list - */ - update = __allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - - /* - * set offset and volume data - */ - update->delta = synth->paramSamples + v->pvoice->offset; - update->type = AL_FILTER_SET_VOLUME; - update->data.i = volume; - update->moredata.i = _timeToSamples(synth, t); - update->next = 0; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } -} - diff --git a/lib/ultralib/src/audio/synstartvoice.c b/lib/ultralib/src/audio/synstartvoice.c deleted file mode 100644 index 9ad1d89..0000000 --- a/lib/ultralib/src/audio/synstartvoice.c +++ /dev/null @@ -1,48 +0,0 @@ -/*==================================================================== - * synstartvoice.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include - -void alSynStartVoice(ALSynth *synth, ALVoice *v, ALWaveTable *table) -{ - ALStartParam *update; - ALFilter *f; - - if (v->pvoice) { - - update = (ALStartParam *)__allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - - /* - * send the start message to the motion control filter - */ - update->delta = synth->paramSamples + v->pvoice->offset; - update->type = AL_FILTER_START_VOICE; - update->wave = table; - update->next = 0; - update->unity = v->unityPitch; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } -} - diff --git a/lib/ultralib/src/audio/synstartvoiceparam.c b/lib/ultralib/src/audio/synstartvoiceparam.c deleted file mode 100644 index 8d1a54b..0000000 --- a/lib/ultralib/src/audio/synstartvoiceparam.c +++ /dev/null @@ -1,75 +0,0 @@ -/*==================================================================== - * synquickstartvoice - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include -#include - -#if BUILD_VERSION < VERSION_J -#ident "$Revision: 1.17 $" -#endif - -void alSynStartVoiceParams(ALSynth *s, ALVoice *v, ALWaveTable *w, - f32 pitch, s16 vol, ALPan pan, u8 fxmix, - ALMicroTime t) -{ - ALStartParamAlt *update; - ALFilter *f; - - if (v->pvoice) { - /* - * get new update struct from the free list - */ - update = (ALStartParamAlt *)__allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - -#if BUILD_VERSION >= VERSION_J - if (fxmix > 127) { - fxmix = 127; - } -#else - if (fxmix < 0) { // Not possible - fxmix = -fxmix; - } -#endif - - /* - * set offset and fxmix data - */ - update->delta = s->paramSamples + v->pvoice->offset; - update->next = 0; - update->type = AL_FILTER_START_VOICE_ALT; - - update->unity = v->unityPitch; - update->pan = pan; - update->volume = vol; - update->fxMix = fxmix; - update->pitch = pitch; - update->samples = _timeToSamples(s, t); - update->wave = w; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } - -} - - diff --git a/lib/ultralib/src/audio/synstopvoice.c b/lib/ultralib/src/audio/synstopvoice.c deleted file mode 100644 index 69c09d8..0000000 --- a/lib/ultralib/src/audio/synstopvoice.c +++ /dev/null @@ -1,44 +0,0 @@ -/*==================================================================== - * synstopvoice.c - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#include "synthInternals.h" -#include -#include - - -void alSynStopVoice(ALSynth *synth, ALVoice *v) -{ - ALParam *update; - ALFilter *f; - - if (v->pvoice) { - - update = __allocParam(); - ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - - update->delta = synth->paramSamples + v->pvoice->offset; - update->type = AL_FILTER_STOP_VOICE; - update->next = 0; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } -} - diff --git a/lib/ultralib/src/audio/synthInternals.h b/lib/ultralib/src/audio/synthInternals.h deleted file mode 100644 index c6c476c..0000000 --- a/lib/ultralib/src/audio/synthInternals.h +++ /dev/null @@ -1,344 +0,0 @@ -/*==================================================================== - * audioInternals.h - * - * Synopsis: - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -#ifndef __audioInternals__ -#define __audioInternals__ - -#include -#include - -/* - * filter message ids - */ -enum { - AL_FILTER_FREE_VOICE, - AL_FILTER_SET_SOURCE, - AL_FILTER_ADD_SOURCE, - AL_FILTER_ADD_UPDATE, - AL_FILTER_RESET, - AL_FILTER_SET_WAVETABLE, -/* AL_FILTER_SET_DMA_PROC,*/ -/* AL_FILTER_SKIP_LOOP,*/ - AL_FILTER_SET_DRAM, - AL_FILTER_SET_PITCH, - AL_FILTER_SET_UNITY_PITCH, - AL_FILTER_START, -/* AL_FILTER_SET_DECAY,*/ -/* AL_FILTER_SET_FC,*/ - AL_FILTER_SET_STATE, - AL_FILTER_SET_VOLUME, - AL_FILTER_SET_PAN, - AL_FILTER_START_VOICE_ALT, - AL_FILTER_START_VOICE, - AL_FILTER_STOP_VOICE, - AL_FILTER_SET_FXAMT -}; - -#define AL_MAX_RSP_SAMPLES 160 - -/* - * buffer locations based on AL_MAX_RSP_SAMPLES - */ -#define AL_DECODER_IN 0 -#define AL_RESAMPLER_OUT 0 -#define AL_TEMP_0 0 -#define AL_DECODER_OUT 320 -#define AL_TEMP_1 320 -#define AL_TEMP_2 640 -#define AL_MAIN_L_OUT 1088 -#define AL_MAIN_R_OUT 1408 -#define AL_AUX_L_OUT 1728 -#define AL_AUX_R_OUT 2048 - -/* - * filter types - */ -enum { - AL_ADPCM, - AL_RESAMPLE, - AL_BUFFER, - AL_SAVE, - AL_ENVMIX, - AL_FX, - AL_AUXBUS, - AL_MAINBUS -}; - -typedef struct ALParam_s { - struct ALParam_s *next; - s32 delta; - s16 type; - union { - f32 f; - s32 i; - } data; - union { - f32 f; - s32 i; - } moredata; - union { - f32 f; - s32 i; - } stillmoredata; - union { - f32 f; - s32 i; - } yetstillmoredata; -} ALParam; - -typedef struct { - struct ALParam_s *next; - s32 delta; - s16 type; - s16 unity; /* disable resampler */ - f32 pitch; - s16 volume; - ALPan pan; - u8 fxMix; - s32 samples; - struct ALWaveTable_s *wave; -} ALStartParamAlt; - -typedef struct { - struct ALParam_s *next; - s32 delta; - s16 type; - s16 unity; /* disable resampler */ - struct ALWaveTable_s *wave; -} ALStartParam; - -typedef struct { - struct ALParam_s *next; - s32 delta; - s16 type; - struct PVoice_s *pvoice; -} ALFreeParam; - -typedef Acmd *(*ALCmdHandler)(void *, s16 *, s32, s32, Acmd *); -typedef s32 (*ALSetParam)(void *, s32, void *); - -typedef struct ALFilter_s { - struct ALFilter_s *source; - ALCmdHandler handler; - ALSetParam setParam; - s16 inp; - s16 outp; - s32 type; -} ALFilter; - -void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type); - -#define AL_MAX_ADPCM_STATES 3 /* Depends on number of subframes - * per frame and loop length - */ -typedef struct { - ALFilter filter; - ADPCM_STATE *state; - ADPCM_STATE *lstate; - ALRawLoop loop; - struct ALWaveTable_s *table; - s32 bookSize; - ALDMAproc dma; - void *dmaState; - s32 sample; - s32 lastsam; - s32 first; - s32 memin; -} ALLoadFilter; - -void alLoadNew(ALLoadFilter *f, ALDMANew dma, ALHeap *hp); -Acmd *alAdpcmPull(void *f, s16 *outp, s32 byteCount, s32 sampleOffset, Acmd *p); -Acmd *alRaw16Pull(void *f, s16 *outp, s32 byteCount, s32 sampleOffset, Acmd *p); -s32 alLoadParam(void *filter, s32 paramID, void *param); - -typedef struct ALResampler_s { - ALFilter filter; - RESAMPLE_STATE *state; - f32 ratio; - s32 upitch; - f32 delta; - s32 first; - ALParam *ctrlList; - ALParam *ctrlTail; - s32 motion; -} ALResampler; - -typedef struct { - s16 fc; - s16 fgain; - union { - s16 fccoef[16]; - s64 force_aligned; - } fcvec; - POLEF_STATE *fstate; - s32 first; -} ALLowPass; - -typedef struct { - u32 input; - u32 output; - s16 ffcoef; - s16 fbcoef; - s16 gain; - f32 rsinc; - f32 rsval; - s32 rsdelta; - f32 rsgain; - ALLowPass *lp; - ALResampler *rs; -} ALDelay; - -typedef s32 (*ALSetFXParam)(void *, s32, void *); -typedef struct { - struct ALFilter_s filter; - s16 *base; - s16 *input; - u32 length; - ALDelay *delay; - u8 section_count; - ALSetFXParam paramHdl; -} ALFx; - -void alFxNew(ALFx *r, ALSynConfig *c, ALHeap *hp); -Acmd *alFxPull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); -s32 alFxParam(void *filter, s32 paramID, void *param); -s32 alFxParamHdl(void *filter, s32 paramID, void *param); - -#define AL_MAX_MAIN_BUS_SOURCES 1 -typedef struct ALMainBus_s { - ALFilter filter; - s32 sourceCount; - s32 maxSources; - ALFilter **sources; -} ALMainBus; - -void alMainBusNew(ALMainBus *m, void *ptr, s32 len); -Acmd *alMainBusPull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); -s32 alMainBusParam(void *filter, s32 paramID, void *param); - -#define AL_MAX_AUX_BUS_SOURCES 8 -#define AL_MAX_AUX_BUS_FX 1 -typedef struct ALAuxBus_s { - ALFilter filter; - s32 sourceCount; - s32 maxSources; - ALFilter **sources; - ALFx fx[AL_MAX_AUX_BUS_FX]; -} ALAuxBus; - -void alAuxBusNew(ALAuxBus *m, void *ptr, s32 len); -Acmd *alAuxBusPull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); -s32 alAuxBusParam(void *filter, s32 paramID, void *param); - -void alResampleNew(ALResampler *r, ALHeap *hp); -Acmd *alResamplePull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); -s32 alResampleParam(void *f, s32 paramID, void *param); - -typedef struct ALSave_s { - ALFilter filter; - s32 dramout; - s32 first; -} ALSave; - -void alSaveNew(ALSave *r); -Acmd *alSavePull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); -s32 alSaveParam(void *f, s32 paramID, void *param); - -typedef struct ALEnvMixer_s { - ALFilter filter; - ENVMIX_STATE *state; - s16 pan; - s16 volume; - s16 cvolL; - s16 cvolR; - s16 dryamt; - s16 wetamt; - u16 lratl; - s16 lratm; - s16 ltgt; - u16 rratl; - s16 rratm; - s16 rtgt; - s32 delta; - s32 segEnd; - s32 first; - ALParam *ctrlList; - ALParam *ctrlTail; - ALFilter **sources; - s32 motion; -} ALEnvMixer; - -void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp); -Acmd *alEnvmixerPull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); -s32 alEnvmixerParam(void *filter, s32 paramID, void *param); - - -/* - * heap stuff - */ -typedef struct { - s32 magic; /* check structure integrety */ - s32 size; /* size of this allocated block */ - u8 *file; /* file that this alloc was called from */ - s32 line; /* line that it was called from */ - s32 count; /* heap call number */ - s32 pad0; - s32 pad1; - s32 pad2; /* Make it 32 bytes */ -} HeapInfo; - -#define AL_CACHE_ALIGN 15 - -/* - * synth stuff - */ - -typedef struct PVoice_s { - ALLink node; - struct ALVoice_s *vvoice; - ALFilter *channelKnob; - ALLoadFilter decoder; - ALResampler resampler; - ALEnvMixer envmixer; - s32 offset; -} PVoice; - -/* - * prototypes for private driver functions - */ -ALParam *__allocParam(void); -void __freeParam(ALParam *param); -void _freePVoice(ALSynth *drvr, PVoice *pvoice); -void _collectPVoices(ALSynth *drvr); - -s32 _timeToSamples(ALSynth *ALSynth, s32 micros); -ALMicroTime _samplesToTime(ALSynth *synth, s32 samples); - -// This was renamed to have a leading underscore in 2.0J -#if BUILD_VERSION < VERSION_J -#define _init_lpfilter init_lpfilter -#endif - -void _init_lpfilter(ALLowPass *lp); - -#endif - diff --git a/lib/ultralib/src/audio/synthesizer.c b/lib/ultralib/src/audio/synthesizer.c deleted file mode 100644 index 9123874..0000000 --- a/lib/ultralib/src/audio/synthesizer.c +++ /dev/null @@ -1,323 +0,0 @@ -/*==================================================================== - * synthesizer.c - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -#include "synthInternals.h" -#include -#include -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -#ifdef AUD_PROFILE -#include -extern u32 cnt_index, drvr_num, drvr_cnt, drvr_max, drvr_min, lastCnt[]; -extern u32 client_num, client_cnt, client_max, client_min; -#endif - -#ifndef MIN -# define MIN(a,b) (((a)<(b))?(a):(b)) -#endif - -static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client); -static s32 _timeToSamplesNoRound(ALSynth *ALSynth, s32 micros); - -/*********************************************************************** - * Synthesis driver public interfaces - ***********************************************************************/ -void alSynNew(ALSynth *drvr, ALSynConfig *c) -{ - s32 i; - ALVoice *vv; - PVoice *pv; - ALVoice *vvoices; - PVoice *pvoices; - ALHeap *hp = c->heap; - ALSave *save; - ALFilter *sources; - ALParam *params; - ALParam *paramPtr; - - drvr->head = NULL; - drvr->numPVoices = c->maxPVoices; - drvr->curSamples = 0; - drvr->paramSamples = 0; - drvr->outputRate = c->outputRate; - drvr->maxOutSamples = AL_MAX_RSP_SAMPLES; - drvr->dma = (ALDMANew) c->dmaproc; - - save = alHeapAlloc(hp, 1, sizeof(ALSave)); - alSaveNew(save); - drvr->outputFilter = (ALFilter *)save; - - /* - * allocate and initialize the auxilliary effects bus. at present - * we only support 1 effects bus. - */ - drvr->auxBus = alHeapAlloc(hp, 1, sizeof(ALAuxBus)); - drvr->maxAuxBusses = 1; - sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); - alAuxBusNew(drvr->auxBus, sources, c->maxPVoices); - - /* - * allocate and initialize the main bus. - */ - drvr->mainBus = alHeapAlloc(hp, 1, sizeof(ALMainBus)); - sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); - alMainBusNew(drvr->mainBus, sources, c->maxPVoices); - - if (c->fxType != AL_FX_NONE){ - /* - * Allocate an effect and set parameters - */ - alSynAllocFX(drvr, 0, c, hp); - } else - /* - * Connect the aux bus to the main bus - */ - alMainBusParam(drvr->mainBus, AL_FILTER_ADD_SOURCE, &drvr->auxBus[0]); - - /* - * Build the physical voice lists - */ - drvr->pFreeList.next = 0; - drvr->pFreeList.prev = 0; - drvr->pLameList.next = 0; - drvr->pLameList.prev = 0; - drvr->pAllocList.next = 0; - drvr->pAllocList.prev = 0; - - pvoices = alHeapAlloc(hp, c->maxPVoices, sizeof(PVoice)); - for (i = 0; i < c->maxPVoices; i++) { - pv = &pvoices[i]; - alLink((ALLink *)pv, &drvr->pFreeList); - pv->vvoice = 0; - - alLoadNew(&pv->decoder, drvr->dma, hp); - alLoadParam(&pv->decoder, AL_FILTER_SET_SOURCE, 0); - - alResampleNew(&pv->resampler, hp); - alResampleParam(&pv->resampler, AL_FILTER_SET_SOURCE, &pv->decoder); - - alEnvmixerNew(&pv->envmixer, hp); - alEnvmixerParam(&pv->envmixer, AL_FILTER_SET_SOURCE, &pv->resampler); - - alAuxBusParam(drvr->auxBus, AL_FILTER_ADD_SOURCE, &pv->envmixer); - - pv->channelKnob = (ALFilter *)&pv->envmixer; - } - - alSaveParam(save, AL_FILTER_SET_SOURCE, drvr->mainBus); - - /* - * build the parameter update list - */ - params = alHeapAlloc(hp, c->maxUpdates, sizeof(ALParam)); - drvr->paramList = 0; - for (i = 0; i < c->maxUpdates; i++) { - paramPtr= ¶ms[i]; - paramPtr->next = drvr->paramList; - drvr->paramList = paramPtr; - } - - drvr->heap = hp; -} - -/* - * slAudioFrame() is called every video frame, and is based on the video - * frame interrupt. It is assumed to be an accurate time source for the - * clients. - */ -Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) -{ - ALPlayer *client; - ALFilter *output; - ALSynth *drvr = &alGlobals->drvr; - s16 tmp = 0; /* Starting buffer in DMEM */ - Acmd *cmdlEnd = cmdList; - Acmd *cmdPtr; - s32 nOut; - s16 *lOutBuf = outBuf; - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - if (drvr->head == 0) { - *cmdLen = 0; - return cmdList; /* nothing to do */ - } - - /* - * run down list of clients and execute callback if needed this - * subframe. Here we do all the work for the frame at the - * start. Time offsets that occur before the next frame are - * executed "early". - */ - -#ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); -#endif - - /* - * paramSamples = time of next parameter change. - * curSamples = current sample time. - * so paramSamples - curSamples is the time until the next parameter change. - * if the next parameter change occurs within this frame time (outLen), - * then call back the client that contains the parameter change. - * Note, paramSamples must be rounded down to 16 sample boundary for use - * during the client handler. - */ - - for (drvr->paramSamples = __nextSampleTime(drvr, &client); - drvr->paramSamples - drvr->curSamples < outLen; - drvr->paramSamples = __nextSampleTime(drvr, &client)) - { - drvr->paramSamples &= ~0xf; - client->samplesLeft += _timeToSamplesNoRound(drvr, (*client->handler)(client)); - } - - /* for safety's sake, always store paramSamples aligned to 16 sample boundary. - * this way, if an voice handler routine gets called outside the ALVoiceHandler - * routine (alSynAllocVoice) it will get timestamped with an aligned value and - * will be processed immediately next audio frame. - */ - drvr->paramSamples &= ~0xf; - - -#ifdef AUD_PROFILE - PROFILE_AUD(client_num, client_cnt, client_max, client_min); -#endif - - /* - * Now build the command list in small chunks - */ - while (outLen > 0){ - nOut = MIN(drvr->maxOutSamples, outLen); - - /* - * construct the command list for each physical voice by calling - * the head of the filter chain. - */ - cmdPtr = cmdlEnd; - aSegment(cmdPtr++, 0, 0); - output = drvr->outputFilter; - (*output->setParam)(output, AL_FILTER_SET_DRAM, lOutBuf); - cmdlEnd = (*output->handler)(output, &tmp, nOut, drvr->curSamples, - cmdPtr); - - outLen -= nOut; - lOutBuf += nOut<<1; /* For Stereo */ - drvr->curSamples += nOut; - - } - *cmdLen = (s32) (cmdlEnd - cmdList); - - _collectPVoices(drvr); /* collect free physical voices */ - -#ifdef AUD_PROFILE - PROFILE_AUD(drvr_num, drvr_cnt, drvr_max, drvr_min); -#endif - return cmdlEnd; -} - -/*********************************************************************** - * Synthesis driver private interfaces - ***********************************************************************/ - -ALParam *__allocParam() -{ - ALParam *update = 0; - ALSynth *drvr = &alGlobals->drvr; - - if (drvr->paramList) { - update = drvr->paramList; - drvr->paramList = drvr->paramList->next; - update->next = 0; - } - return update; -} - -void __freeParam(ALParam *param) -{ - ALSynth *drvr = &alGlobals->drvr; - param->next = drvr->paramList; - drvr->paramList = param; -} - -void _collectPVoices(ALSynth *drvr) -{ - ALLink *dl; - PVoice *pv; - - while ((dl = drvr->pLameList.next) != 0) { - pv = (PVoice *)dl; - - /* ### remove from mixer */ - - alUnlink(dl); - alLink(dl, &drvr->pFreeList); - } -} - -void _freePVoice(ALSynth *drvr, PVoice *pvoice) -{ - /* - * move the voice from the allocated list to the lame list - */ - alUnlink((ALLink *)pvoice); - alLink((ALLink *)pvoice, &drvr->pLameList); -} - -/* - Add 0.5 to adjust the average affect of - the truncation error produced by casting - a float to an int. -*/ -s32 _timeToSamplesNoRound(ALSynth *synth, s32 micros) -{ - f32 tmp = ((f32)micros) * synth->outputRate / 1000000.0 + 0.5; - - return (s32)tmp; -} - -s32 _timeToSamples(ALSynth *synth, s32 micros) -{ - return _timeToSamplesNoRound(synth, micros) & ~0xf; -} - -static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client) -{ - ALMicroTime delta = 0x7fffffff; /* max delta for s32 */ - ALPlayer *cl; -#if BUILD_VERSION < VERSION_J // Adjust line numbers to match assert -#line 306 -#endif - assert(drvr->head); - - *client = 0; - - for (cl = drvr->head; cl != 0; cl = cl->next) { - if ((cl->samplesLeft - drvr->curSamples) < delta) { - *client = cl; - delta = cl->samplesLeft - drvr->curSamples; - } - } - - return (*client)->samplesLeft; -} - - - diff --git a/lib/ultralib/src/debug/assert.c b/lib/ultralib/src/debug/assert.c deleted file mode 100644 index ab7e313..0000000 --- a/lib/ultralib/src/debug/assert.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "os.h" -#include "../os/osint.h" -#include "osint_debug.h" - -void __assertBreak(void); - -void __assert(const char* exp, const char* filename, int line) { -#ifndef _FINALROM - osSyncPrintf("\nASSERTION FAULT: %s, %d: \"%s\"\n", filename, line, exp); - __assertBreak; // Doesn't actually do anything, but is needed for matching -#endif -} diff --git a/lib/ultralib/src/debug/assertbreak.s b/lib/ultralib/src/debug/assertbreak.s deleted file mode 100644 index 69de71d..0000000 --- a/lib/ultralib/src/debug/assertbreak.s +++ /dev/null @@ -1,14 +0,0 @@ -#include "PR/os_version.h" - -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J -#include "sys/asm.h" -#include "sys/regdef.h" - -.set noreorder - -LEAF(__assertBreak) - break 0 - j ra -END(__assertBreak) - -#endif diff --git a/lib/ultralib/src/debug/atomic.c b/lib/ultralib/src/debug/atomic.c deleted file mode 100644 index a0bd8fe..0000000 --- a/lib/ultralib/src/debug/atomic.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "PR/os_internal.h" - -int __osAtomicDec(unsigned int* p) { - u32 mask; - int result; - - mask = __osDisableInt(); - if (*p) { - (*p)--; - result = 1; - } else { - result = 0; - } - __osRestoreInt(mask); - return result; -} diff --git a/lib/ultralib/src/debug/kdebugserver.c b/lib/ultralib/src/debug/kdebugserver.c deleted file mode 100644 index 948a460..0000000 --- a/lib/ultralib/src/debug/kdebugserver.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PR/rdb.h" - -// not included in final rom, but __osThreadSave is here for some reason -OSThread __osThreadSave; - -extern OSThread *__osRunningThread; -extern u32 __osRdb_IP6_Empty; - -#ifndef _FINALROM - -static u8 buffer[12]; -static u32 numChars = 0; - -static u32 string_to_u32(u8* s) { - u32 k; - - k = ((s[0] & 0xFF) << 0x18); - k |= ((s[1] & 0xFF) << 0x10); - k |= ((s[2] & 0xFF) << 0x8); - k |= (s[3] & 0xFF); - - return k; -} - -static void send_packet(u8* s, u32 n) { - rdbPacket packet; - u32 i; - - packet.type = 0xC; - packet.length = n; - - for (i = 0; i < n; i++) { - packet.buf[i] = s[i]; - } - *(vu32*)RDB_BASE_REG = *(u32*)&packet; -} - -static void clear_IP6(void) { - while (!(__osGetCause() & CAUSE_IP6)) { - ; - } - *(vu32*)RDB_READ_INTR_REG = 0; - - while (__osGetCause() & CAUSE_IP6) { - ; - } -} - -static void send(u8* s, u32 n) { - u32 ct; - u32 i = 0; - u32 getLastIP6; - - if (!__osRdb_IP6_Empty) { - clear_IP6(); - getLastIP6 = FALSE; - } else { - getLastIP6 = TRUE; - } - while (n != 0) { - ct = (n < 3) ? n : 3; - send_packet(s + i, ct); - n -= ct; - i += ct; - if (n != 0) { - clear_IP6(); - } - } - if (getLastIP6) { - clear_IP6(); - } -} - -void kdebugserver(rdbPacket packet) { - u32 i; - u32 length; - u8* addr; - - for (i = 0; i < 3; i++) { - buffer[numChars++] = packet.buf[i]; - } - - if (buffer[0] == 2) { - send((char*)&__osRunningThread->context, sizeof(__OSThreadContext)); - numChars = 0; - } else if (numChars >= 9 && buffer[0] == 1) { - addr = string_to_u32(&buffer[1]); - length = string_to_u32(&buffer[5]); - send(addr, length); - numChars = 0; - } -} - -#endif diff --git a/lib/ultralib/src/debug/osint_debug.h b/lib/ultralib/src/debug/osint_debug.h deleted file mode 100644 index 6d644f2..0000000 --- a/lib/ultralib/src/debug/osint_debug.h +++ /dev/null @@ -1,11 +0,0 @@ -#include "PR/os_internal.h" - -extern s32 __osThprofFlag; -extern void (*__osThprofFunc)(OSThread*); -extern u32 __osThprofLastTimer; -extern u32 __osThprofCount; -extern __OSThreadprofile_s thprof[]; -extern u64 __osThprofHeap[]; -extern void* __osThprofStack; - -void osThreadProfileCallback(OSThread*); diff --git a/lib/ultralib/src/debug/profile.c b/lib/ultralib/src/debug/profile.c deleted file mode 100644 index 47b19d8..0000000 --- a/lib/ultralib/src/debug/profile.c +++ /dev/null @@ -1,176 +0,0 @@ -#include "PR/rdb.h" -#include "PR/ultratypes.h" -#include "PR/os.h" -#include "PR/ultraerror.h" -#include "PR/ultralog.h" -#include "PR/sptask.h" -#include "../os/osint.h" -#include "macros.h" -#include "osint_debug.h" - -#ifndef _FINALROM - -OSTimer __osProfTimer; -OSMesg __osProfTimerMsg; - -OSMesgQueue __osProfFlushMQ ALIGNED(8); -OSMesg __osProfFlushMesg; - -OSMesgQueue __osProfAckMQ ALIGNED(8); -OSMesg __osProfAckMesg; - -u32 __osProfTimerPeriod; - -u32 __osProfNumSections; - -static u32 __osProfileActive = FALSE; -static u32 __osProfileIOActive = FALSE; - -unsigned char __osProfileIOStack[2400] ALIGNED(16); - -static OSThread __osProfileIOThread; - -void osProfSendWord(u32 word); - -void __osProfileIO(void* arg) { - s32 totalBytes; - u32 bytesThisBlock; - u32 ct; - u8* sendPtr; - OSProf* t; - - while (TRUE) { - osRecvMesg(&__osProfFlushMQ, NULL, OS_MESG_BLOCK); - osProfSendWord(__osProfNumSections); - osProfSendWord(__osProfTimerPeriod); - osProfSendWord(__osProfileOverflowBin); - - for (t = __osProfileList; t < __osProfileListEnd; t++) { - osProfSendWord(t->text_start); - osProfSendWord(t->histo_size); - osRecvMesg(&__osProfAckMQ, NULL, OS_MESG_BLOCK); - - totalBytes = t->histo_size * 2; - sendPtr = t->histo_base; - while (totalBytes > 0) { - bytesThisBlock = (totalBytes < 0x800U) ? totalBytes : 0x800U; - - ct = 0; - while (ct < bytesThisBlock) { - ct += __osRdbSend(sendPtr + ct, bytesThisBlock - ct, RDB_TYPE_GtoH_PROF_DATA); - } - - sendPtr += bytesThisBlock; - totalBytes -= bytesThisBlock; - osRecvMesg(&__osProfAckMQ, NULL, OS_MESG_BLOCK); - } - } - } -} - -void osProfSendWord(u32 word) { - u32 ct = 0; - u8* sendPtr = &word; - - while (ct < sizeof(word)) { - ct += __osRdbSend(sendPtr + ct, sizeof(word) - ct, RDB_TYPE_GtoH_PROF_DATA); - } -} - -void osProfileFlush(void) { - osSendMesg(&__osProfFlushMQ, NULL, OS_MESG_BLOCK); -} - -void osProfileInit(OSProf* profp, u32 profcnt) { - u32 i; - OSProf* t; - -#if !defined(NDEBUG) && BUILD_VERSION >= VERSION_K - if (__osProfileActive) { - __osError(ERR_OSPROFILEINIT_STR, 0); - return; - } - - if (profcnt == 0) { - __osError(ERR_OSPROFILEINIT_CNT, 1, profcnt); - return; - } -#endif - - for (t = profp; t < profp + profcnt; t++) { -#ifndef NDEBUG - if ((u32)t->histo_base & 1) { - __osError(ERR_OSPROFILEINIT_ALN, 1, t->histo_base); - return; - } - - if (t->text_start >= t->text_end) { - __osError(ERR_OSPROFILEINIT_ORD, 2, t->text_start, t->text_end); - return; - } - - if (((u32)(t->text_end - t->text_start) / 4) > t->histo_size) { - __osError(ERR_OSPROFILEINIT_SIZ, 1, t->histo_size); - return; - } -#endif - - for (i = 0; i < t->histo_size; i++) { - t->histo_base[i] = 0; - } - } - - __osProfileActive = FALSE; - __osProfileOverflowBin = 0; - __osProfileList = profp; - __osProfileListEnd = profp + profcnt; - __osProfNumSections = profcnt; - if (!__osProfileIOActive) { - osCreateMesgQueue(&__osProfFlushMQ, &__osProfFlushMesg, 1); - osSetEventMesg(OS_EVENT_RDB_FLUSH_PROF, &__osProfFlushMQ, 0); - osCreateMesgQueue(&__osProfAckMQ, &__osProfAckMesg, 1); - osSetEventMesg(OS_EVENT_RDB_ACK_PROF, &__osProfAckMQ, 0); - osCreateThread(&__osProfileIOThread, 0, __osProfileIO, NULL, &__osProfileIOStack[2400], 0x81); - osStartThread(&__osProfileIOThread); - __osProfileIOActive = TRUE; - } -} - -void osProfileStart(u32 microseconds) { -#ifndef NDEBUG - if (microseconds < 50) { - __osError(ERR_OSPROFILESTART_TIME, 1, microseconds); - return; - } - - if (__osProfileActive) { - __osError(ERR_OSPROFILESTART_FLAG, 0); - return; - } -#endif - - osCreateMesgQueue(&__osProfTimerQ, &__osProfTimerMsg, 1); - osSetTimer(&__osProfTimer, 0, OS_USEC_TO_CYCLES(microseconds), &__osProfTimerQ, NULL); - __osProfTimerPeriod = microseconds; - __osProfileActive = TRUE; -} - -void osProfileStop(void) { -#ifndef NDEBUG - if (!__osProfileActive) { - __osError(ERR_OSPROFILESTOP_FLAG, 0); - return; - } -#endif - - if (osStopTimer(&__osProfTimer) < 0) { -#ifndef NDEBUG - __osError(ERR_OSPROFILESTOP_TIMER, 0); - return; -#endif - } - - __osProfileActive = FALSE; -} - -#endif diff --git a/lib/ultralib/src/debug/threadprofile.c b/lib/ultralib/src/debug/threadprofile.c deleted file mode 100644 index e383773..0000000 --- a/lib/ultralib/src/debug/threadprofile.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "osint_debug.h" - -#include "macros.h" - -s32 __osThprofFlag = 0; -void (*__osThprofFunc)(OSThread*) = NULL; - -u32 __osThprofLastTimer; -u32 __osThprofCount; -__OSThreadprofile_s thprof[THPROF_IDMAX] ALIGNED(0x10); -u64 __osThprofHeap[THPROF_STACKSIZE] ALIGNED(0x10); -void* __osThprofStack; - -void osThreadProfileCallback(OSThread* osthread) { - register u32 now_time = osGetCount(); - __OSThreadprofile_s* thprof = osthread->thprof; - - thprof->time += now_time - __osThprofLastTimer; - thprof->count++; - __osThprofCount++; - __osThprofLastTimer = now_time; -} diff --git a/lib/ultralib/src/debug/threadprofileclear.c b/lib/ultralib/src/debug/threadprofileclear.c deleted file mode 100644 index 42788f8..0000000 --- a/lib/ultralib/src/debug/threadprofileclear.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "osint_debug.h" - -void osThreadProfileClear(OSId id) { - register OSIntMask saveMask = __osDisableInt(); - - thprof[id].flag = 0; - thprof[id].count = 0; - thprof[id].time = 0; - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/debug/threadprofileinit.c b/lib/ultralib/src/debug/threadprofileinit.c deleted file mode 100644 index 7fef229..0000000 --- a/lib/ultralib/src/debug/threadprofileinit.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "osint_debug.h" - -void osThreadProfileInit(void) { - register u32 saveMask = __osDisableInt(); - OSId i; - - __osThprofFunc = NULL; - __osThprofFlag = 1; - __osThprofCount = 0; - __osThprofStack = &__osThprofHeap[(THPROF_STACKSIZE - 8) / sizeof(*__osThprofHeap)]; - __osRestoreInt(saveMask); - - for (i = 0; i < THPROF_IDMAX; i++) { - osThreadProfileClear(i); - } -} diff --git a/lib/ultralib/src/debug/threadprofilereadcount.c b/lib/ultralib/src/debug/threadprofilereadcount.c deleted file mode 100644 index 3237987..0000000 --- a/lib/ultralib/src/debug/threadprofilereadcount.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "osint_debug.h" - -u32 osThreadProfileReadCount(OSId id) { -#ifndef NDEBUG - if (!__osThprofFlag) { - __osError(139, 0); - return 0; - } -#endif - - if (id >= THPROF_IDMAX) { -#ifndef NDEBUG - __osError(143, 1, id); -#endif - return 0; - } - return thprof[id].count; -} - -u32 osThreadProfileReadCountTh(OSThread* thread) { - OSId id; - -#ifndef NDEBUG - if (!__osThprofFlag) { - __osError(141, 0); - return 0; - } -#endif - - id = osGetThreadId(thread); - - if (id >= THPROF_IDMAX) { -#ifndef NDEBUG - __osError(145, 1, id); -#endif - return 0; - } - return thprof[id].count; -} diff --git a/lib/ultralib/src/debug/threadprofilereadtime.c b/lib/ultralib/src/debug/threadprofilereadtime.c deleted file mode 100644 index 9930cac..0000000 --- a/lib/ultralib/src/debug/threadprofilereadtime.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "osint_debug.h" - -OSTime osThreadProfileReadTime(OSId id) { - OSTime adjust = 0; - u32 now_time = osGetCount(); - -#ifndef NDEBUG - if (!__osThprofFlag) { - __osError(140, 0); - return 0; - } -#endif - if (id >= THPROF_IDMAX) { -#ifndef NDEBUG - __osError(144, 1, id); -#endif - return 0; - } - - if (id == osGetThreadId(NULL) && __osThprofFunc != NULL) { - adjust = now_time - __osThprofLastTimer; - } - return thprof[id].time + adjust; -} - -OSTime osThreadProfileReadTimeTh(OSThread* thread) { - OSId id; - OSTime adjust = 0; - u32 now_time = osGetCount(); - -#ifndef NDEBUG - if (!__osThprofFlag) { - __osError(142, 0); - return 0; - } -#endif - - id = osGetThreadId(thread); - - if (id >= THPROF_IDMAX) { -#ifndef NDEBUG - __osError(146, 1, id); -#endif - return 0; - } - - if (id == osGetThreadId(NULL) && __osThprofFunc != NULL) { - adjust = now_time - __osThprofLastTimer; - } - return thprof[id].time + adjust; -} diff --git a/lib/ultralib/src/debug/threadprofilestart.c b/lib/ultralib/src/debug/threadprofilestart.c deleted file mode 100644 index 3ef8fa7..0000000 --- a/lib/ultralib/src/debug/threadprofilestart.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "osint_debug.h" - -void osThreadProfileStart(void) { - register u32 saveMask; - -#ifndef NDEBUG - if (!__osThprofFlag) { - __osError(136, 0); - return; - } - if (__osThprofFunc != NULL) { - __osError(137, 0); - return; - } -#endif - - saveMask = __osDisableInt(); - - __osThprofLastTimer = osGetCount(); - __osThprofFunc = osThreadProfileCallback; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/debug/threadprofilestop.c b/lib/ultralib/src/debug/threadprofilestop.c deleted file mode 100644 index 4803620..0000000 --- a/lib/ultralib/src/debug/threadprofilestop.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "osint_debug.h" - -void osThreadProfileStop(void) { - register u32 saveMask; - int i; - OSId id; - u32 now_time = osGetCount(); - - saveMask = __osDisableInt(); - -#ifndef NDEBUG - if (__osThprofFlag == 0) { -#if BUILD_VERSION >= VERSION_L - __osRestoreInt(saveMask); - __osError(138, 0); -#else - __osError(138, 0); - __osRestoreInt(saveMask); -#endif - return; - } -#endif - - if (__osThprofFunc != NULL) { - id = osGetThreadId(0); - - if (id < THPROF_IDMAX) { - thprof[id].time += now_time - __osThprofLastTimer; - } else { -#ifndef NDEBUG -#if BUILD_VERSION >= VERSION_L - __osRestoreInt(saveMask); -#endif - __osError(147, 1, id); -#if BUILD_VERSION >= VERSION_L - saveMask = __osDisableInt(); -#endif -#endif - } - } - __osThprofFunc = NULL; - - for (i = 0; i < THPROF_IDMAX; i++) { - thprof[i].flag = 0; - } - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/error/commonerror.c b/lib/ultralib/src/error/commonerror.c deleted file mode 100644 index 5a6f1c9..0000000 --- a/lib/ultralib/src/error/commonerror.c +++ /dev/null @@ -1,193 +0,0 @@ -#include "PR/os.h" -#include "PR/os_internal.h" -#include "PR/sptask.h" -#include "PR/ultraerror.h" -#include "PR/ultralog.h" -#include "macros.h" -#include "stdarg.h" - -#ifndef _FINALROM - -void __osSyncVPrintf(const char* fmt, va_list args); - -static u32 errorLogData[19] ALIGNED(8); -static OSLog errorLog = { - OS_ERROR_MAGIC, // magic - sizeof(errorLogData), // len - errorLogData, // base - 0, //startCount - 0, //writeOffset -}; - -static void __commonErrorHandler(s16 code, s16 numArgs, ...); -OSErrorHandler __osCommonHandler = __commonErrorHandler; - -char NULSTR[] = { '\0' }; - -const char* __os_error_message[] = { - NULSTR, - "osCreateThread: stack pointer not aligned to 8 bytes (0x%x)", - "osCreateThread: priority not in range [0-255] (%d)", - "osStartThread: thread has bad state (running/runnable/other)", - "osSetThreadPri: priority not in range [0-255] (%d)", - "osCreateMesgQueue: message count not > 0 (%d)", - "osSendMesg: flag not OS_MESG_NOBLOCK or OS_MESG_BLOCK (%d)", - "osJamMesg: flag not OS_MESG_NOBLOCK or OS_MESG_BLOCK (%d)", - "osRecvMesg: flag not OS_MESG_NOBLOCK or OS_MESG_BLOCK (%d)", - "osSetEventMesg: unknown event type (%d)", - "osMapTLB: index not in range [0-30] (%d)", - "osMapTLB: asid argument not -1 or in range [0-255] (%d)", - "osUnmapTLB: index not in range [0-30] (%d)", - "osSetTLBASID: asid not in range [0-255] (%d)", - "osAiSetFrequency: freq not in range [%d-%d] (%d)", - "osAiSetNextBuffer: address not aligned to 8 bytes (0x%x)", - "osAiSetNextBuffer: size not aligned to 8 bytes (0x%x)", - "osDpSetNextBuffer: address not aligned to 8 bytes (0x%x)", - "osDpSetNextBuffer: size not aligned to 8 bytes (0x%x)", - "osPiRawReadIo: address not aligned to 4 bytes (0x%x)", - "osPiRawWriteIo: address not aligned to 4 bytes (0x%x)", - "osPiRawStartDma: direction not OS_READ or OS_WRITE (%d)", - "osPiRawStartDma: device address not aligned to 2 bytes (0x%x)", - "osPiRawStartDma: DRAM address not aligned to 8 bytes (0x%x)", - "osPiRawStartDma: size not aligned to 2 bytes (%d)", - "osPiRawStartDma: size not in range [0,16777216] (%d)", - "osPiReadIo: address not aligned to 4 bytes (0x%x)", - "osPiWriteIo: address not aligned to 4 bytes (0x%x)", - "osPiStartDma: PI Manager not yet begun by osCreatePiManager", - "osPiStartDma: priority not OS_MESG_PRI_[NORMAL|HIGH] (%d)", - "osPiStartDma: direction not OS_READ or OS_WRITE (%d)", - "osPiStartDma: device address not aligned to 2 bytes (0x%x)", - "osPiStartDma: DRAM address not aligned to 8 bytes (0x%x)", - "osPiStartDma: size not aligned to 2 bytes (%d)", - "osPiStartDma: size not in range [0,16777216] (%d)", - "osCreatePiManager: priority not in range [0-255] (%d)", - "osViGetCurrentMode: VI Manager not yet begun", - "osViGetCurrentFramebuffer: VI Manager not yet begun", - "osViGetNextFramebuffer: VI Manager not yet begun", - "osViSetXScale: value not in range [0.25,1.0] (%f)", - "osViSetXScale: VI Manager not yet begun by osCreateViManager", - "osViSetYScale: value not in range [0.05,1.0] (%f)", - "osViSetYScale: VI Manager not yet begun by osCreateViManager", - "osViSetSpecialFeatures: not a known feature value (%d)", - "osViSetSpecialFeatures: VI Manager not yet begun", - "osViSetMode: VI Manager not yet begun by osCreateViManager", - "osViSetEvent: VI Manager not yet begun by osCreateViManager", - "osViSwapBuffer: frame buffer not aligned to 64 bytes (0x%x)", - "osViSwapBuffer: VI Manager not yet begun", - "osCreateViManager: priority not in range [0-255] (%d)", - "osCreateRegion: not a known alignment (%d)", - "osCreateRegion: length (%d) too small for buffer size (%d)", - "osMalloc: invalid or corrupt region (0x%x)", - "osFree: invalid or corrupt region (0x%x)", - "osFree: invalid address (0x%x) or\n corrupt region (0x%x)", - "osGetRegionBufCount: invalid or corrupt region (0x%x)", - "osGetRegionBufSize: invalid or corrupt region (0x%x)", - "osSpTaskLoad: dram_stack not aligned to 16 bytes (0x%x)", - "osSpTaskLoad: output_buff not aligned to 16 bytes (0x%x)", - "osSpTaskLoad: output_buff_size not aligned to 16 bytes (0x%x)", - "osSpTaskLoad: yield_data_ptr not aligned to 16 bytes (0x%x)", - "osProfileInit: profile counter is running, call osProfileStop before init", - "osProfileInit: profcnt is %d", - "osProfileInit: histo_base pointer must be 32-bit aligned (%x)", - "osProfileInit: text_start (%x) >= text_end (%x)", - "osProfileInit: histo_size is an illegal size (%d)", - "osProfileStart: microseconds is < PROF_MIN_INTERVAL (%d)", - "osProfileStart: profiling has already been started", - "osProfileStop: profiling has already been stopped", - "osProfileStop: no profile timer to stop", - "osReadHost: address not aligned to 8 bytes (0x%x)", - "osReadHost: size either 0 or not aligned to 4 bytes (0x%x)", - "osWriteHost: address not aligned to 8 bytes (0x%x)", - "osWriteHost: size either 0 or not aligned to 4 bytes (0x%x)", - "osGetTime: VI manager not yet begun by osCreateViManager", - "osSetTime: VI manager not yet begun by osCreateViManager", - "osSetTimer: VI manager not yet begun by osCreateViManager", - "osStopTimer: VI manager not yet begun by osCreateViManager", - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - NULSTR, - "_handleMIDIMsg: no sound mapped", - "_handleMIDIMsg: no free voices", - "_handleMIDIMsg: couldn't map voice", - "_handleMIDIMsg: note off - couldn't find voice", - "_handleMIDIMsg: poly pressure - couldn't find voice", - "_handleEvent: no free voices", - "Synthesizer: no free updates", - "alSndPDeallocate: attempt to deallocate a sound which is playing", - "alSndpDelete: attempt to delete player with playing sounds", - "alSndpPlay: attempt to play a sound which is playing", - "alSndpSetSound: sound id (%d) out of range (0 - %d)", - "alSndpSetPriority: sound id (%d) out of range (0 - %d)", - "alSndpSet Parameter: target (%d) out of range (0 - %d)", - "alBnkfNew: bank file out of date", - "alSeqNew: 0x%x is not a midi file", - "alSeqNew: 0x%x is not a type 0 midi file", - "alSeqNew: 0x%x has more than 1 track", - "alSeqNew: SMPTE delta times not supported", - "alSeqNew: Error parsing file 0x%x (no track header)", - "alSeqNextEvent: Unsupported system exclusive", - "alSeqNextEvent: Unsupported midi meta event 0x%x", - "_handleMIDIMsg: Invalid program change to %d, max instruments %d", - "_handleMIDIMsg: Unknown midi message 0x%x", - "_unmapVoice: Couldn't unmap voice 0x%x", - "alEvtqPostEvent: Out of free events", - "alHeapAlloc: Can't allocate %d bytes", - "alHeapCheck: Heap corrupt", - "alHeapCheck: Heap corrupt - first block is bad", - "alCSeqGetTrackEvent: Running status of zero on track %d", - "alCSeqGetTrackEvent: Note on velocity of zero on track %d", - "alCSPVoiceHandler: Stopping sequence but voice not free chan %d, key %d", - "alSeqNextEvent: Read past end of sequence", - "osAiSetNextBuffer: DMA buffer location may cause audio clicks (0x%x)", - "_loadOutputBuffer: Modulated delay greater than total delay by %d samples", - "osViExtendVStart: VI Manager not yet begun by osCreateViManager", - "osViExtendVStart: value not in range [0-48] %d", - "osThreadProfileStart: thread profiler is not initialized", - "osThreadProfileStart: profiling has already been started", - "osThreadProfileStop: thread profiler is not initialized", - "osThreadProfileReadCount: thread profiler is not initialized", - "osThreadProfileReadCountTh: thread profiler is not initialized", - "osThreadProfileReadTime: thread profiler is not initialized", - "osThreadProfileReadTimeTh: thread profiler is not initialized", - "osThreadProfileReadCount: thread ID is too large(%d)", - "osThreadProfileReadTime: thread ID is too large(%d)", - "osThreadProfileReadCountTh: thread ID is too large(%d)", - "osThreadProfileReadTimeTh: thread ID is too large(%d)", - "osThreadProfileStop: current thread ID is too large(%d)", - NULSTR, -}; - -void __commonErrorHandler(s16 code, s16 numArgs, ...) { - va_list argPtr; - const char* fmt; - - fmt = __os_error_message[code]; - va_start(argPtr, numArgs); - - osSyncPrintf("0x%08X (%04d):", osGetCount(), code); - __osSyncVPrintf(fmt, argPtr); - osSyncPrintf("\n"); - - va_end(argPtr); -} - -#endif diff --git a/lib/ultralib/src/error/error.c b/lib/ultralib/src/error/error.c deleted file mode 100644 index 3f9ae2d..0000000 --- a/lib/ultralib/src/error/error.c +++ /dev/null @@ -1,30 +0,0 @@ -// This file was removed in 2.0J -#include "stdarg.h" -#include "PR/os_internal.h" -#include "PR/ultralog.h" -#include "PR/ultraerror.h" -#include "macros.h" - -void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr); -static void __osDefaultHandler(s16 code, s16 numArgs, ...); - -static u32 errorLogData[19] ALIGNED(8); -static OSLog errorLog ALIGNED(8) = { - OS_ERROR_MAGIC, // magic - sizeof(errorLogData), // len - errorLogData, // base - 0, //startCount - 0, //writeOffset -}; - -OSErrorHandler __osErrorHandler = __osDefaultHandler; - -static void __osDefaultHandler(s16 code, s16 numArgs, ...) { - va_list argPtr; - va_start(argPtr, numArgs); - - __osLogWrite(&errorLog, code, numArgs, argPtr); - osFlushLog(&errorLog); - - va_end(argPtr); -} diff --git a/lib/ultralib/src/error/errorasm.s b/lib/ultralib/src/error/errorasm.s deleted file mode 100644 index 10f3561..0000000 --- a/lib/ultralib/src/error/errorasm.s +++ /dev/null @@ -1,33 +0,0 @@ -#include "PR/os_version.h" - -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J -#include "sys/asm.h" -#include "sys/regdef.h" -#include "PR/os_version.h" - -LEAF(__osError) -#if BUILD_VERSION < VERSION_J - lw t0,__osErrorHandler - beqz t0,1f - jr t0 -#elif BUILD_VERSION < VERSION_K - lw t0,__kmc_pt_mode - bnez t0,_kmc_mode - - lw t0,__osErrorHandler - beqz t0,1f - jr t0 -_kmc_mode: - lw t0,__kmcErrorHandler - beqz t0,1f - jr t0 -#else - lw t0,__osCommonHandler - beqz t0,1f - jr t0 -#endif -1: - j ra -END(__osError) - -#endif diff --git a/lib/ultralib/src/flash/flashallerase.c b/lib/ultralib/src/flash/flashallerase.c deleted file mode 100644 index 0e982a5..0000000 --- a/lib/ultralib/src/flash/flashallerase.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - - -s32 osFlashAllErase(void) { - u32 status; - OSTimer mytimer; - OSMesgQueue timerMesgQueue; - OSMesg dummy; - - // start chip erase operation - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_CHIP_ERASE); - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); - - // wait for completion by polling erase-busy flag - osCreateMesgQueue(&timerMesgQueue, &dummy, 1); - do { - osSetTimer(&mytimer, OS_USEC_TO_CYCLES(15000), 0, &timerMesgQueue, &dummy); - osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - } while ((status & FLASH_STATUS_ERASE_BUSY) == FLASH_STATUS_ERASE_BUSY); - - // check erase operation status, clear status - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - osFlashClearStatus(); - - // check for success - if (((status & 0xFF) == 8) || ((status & 0xFF) == 0x48) || ((status & 8) == 8)) { - return FLASH_STATUS_ERASE_OK; - } else { - return FLASH_STATUS_ERASE_ERROR; - } -} diff --git a/lib/ultralib/src/flash/flashallerasethrough.c b/lib/ultralib/src/flash/flashallerasethrough.c deleted file mode 100644 index 1c3c1dd..0000000 --- a/lib/ultralib/src/flash/flashallerasethrough.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -void osFlashAllEraseThrough(void) { - // start chip erase operation, no waiting for completion - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_CHIP_ERASE); - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); -} diff --git a/lib/ultralib/src/flash/flashchange.c b/lib/ultralib/src/flash/flashchange.c deleted file mode 100644 index d92ff7b..0000000 --- a/lib/ultralib/src/flash/flashchange.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -void osFlashChange(u32 flash_num) { - __osFlashHandler.baseAddress = PHYS_TO_K1((FLASH_START_ADDR + flash_num * FLASH_SIZE)); - __osFlashHandler.type = DEVICE_TYPE_FLASH + flash_num; - return; -} diff --git a/lib/ultralib/src/flash/flashcheckeraseend.c b/lib/ultralib/src/flash/flashcheckeraseend.c deleted file mode 100644 index c87876b..0000000 --- a/lib/ultralib/src/flash/flashcheckeraseend.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -s32 osFlashCheckEraseEnd(void) { - u8 status; - - osFlashReadStatus(&status); - - if ((status & FLASH_STATUS_ERASE_BUSY) == FLASH_STATUS_ERASE_BUSY) { - return FLASH_STATUS_ERASE_BUSY; - } else { - // not busy, read and clear status - osFlashReadStatus(&status); - } - osFlashClearStatus(); - - // check for success - if (((status & 0xFF) == 8) || ((status & 0xFF) == 0x48) || ((status & 8) == 8)) { - return FLASH_STATUS_ERASE_OK; - } else { - return FLASH_STATUS_ERASE_ERROR; - } -} diff --git a/lib/ultralib/src/flash/flashclearstatus.c b/lib/ultralib/src/flash/flashclearstatus.c deleted file mode 100644 index 86165d6..0000000 --- a/lib/ultralib/src/flash/flashclearstatus.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -void osFlashClearStatus(void) { - // select status mode - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_STATUS); - // clear status - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress, 0); - return; -} diff --git a/lib/ultralib/src/flash/flashgetaddr.c b/lib/ultralib/src/flash/flashgetaddr.c deleted file mode 100644 index a530947..0000000 --- a/lib/ultralib/src/flash/flashgetaddr.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -u32 __osFlashGetAddr(u32 page_num) { - u32 devAddr; - - if (__osFlashVersion == OLD_FLASH) { - // Account for hardware bug in old flash where the address bits are shifted 1-off where they should be - devAddr = page_num * (FLASH_BLOCK_SIZE >> 1); - } else { - devAddr = page_num * FLASH_BLOCK_SIZE; - } - - return devAddr; -} diff --git a/lib/ultralib/src/flash/flashinit.c b/lib/ultralib/src/flash/flashinit.c deleted file mode 100644 index 33c7dc3..0000000 --- a/lib/ultralib/src/flash/flashinit.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" -#include "macros.h" - -u32 __osFlashID[4] ALIGNED(8); -OSIoMesg __osFlashMsg ALIGNED(8); -OSMesgQueue __osFlashMessageQ ALIGNED(8); -OSPiHandle __osFlashHandler ALIGNED(8); -OSMesg __osFlashMsgBuf[1]; -s32 __osFlashVersion; - -OSPiHandle* osFlashInit(void) { - u32 flash_type; - u32 flash_maker; - - osCreateMesgQueue(&__osFlashMessageQ, __osFlashMsgBuf, ARRLEN(__osFlashMsgBuf)); - - if (__osFlashHandler.baseAddress == PHYS_TO_K1(FLASH_START_ADDR)) { - return &__osFlashHandler; - } - - __osFlashHandler.type = DEVICE_TYPE_FLASH; - __osFlashHandler.baseAddress = PHYS_TO_K1(FLASH_START_ADDR); - __osFlashHandler.latency = FLASH_LATENCY; - __osFlashHandler.pulse = FLASH_PULSE; - __osFlashHandler.pageSize = FLASH_PAGE_SIZE; - __osFlashHandler.relDuration = FLASH_REL_DURATION; - __osFlashHandler.domain = PI_DOMAIN2; - __osFlashHandler.speed = 0; - - bzero(&__osFlashHandler.transferInfo, sizeof(__OSTranxInfo)); - - osEPiLinkHandle(&__osFlashHandler); - osFlashReadId(&flash_type, &flash_maker); - - if (flash_maker == FLASH_VERSION_MX_C || flash_maker == FLASH_VERSION_MX_A || - flash_maker == FLASH_VERSION_MX_PROTO_A) { - __osFlashVersion = OLD_FLASH; - } else { - __osFlashVersion = NEW_FLASH; - } - - return &__osFlashHandler; -} diff --git a/lib/ultralib/src/flash/flashreadarray.c b/lib/ultralib/src/flash/flashreadarray.c deleted file mode 100644 index 543f236..0000000 --- a/lib/ultralib/src/flash/flashreadarray.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - - -s32 osFlashReadArray(OSIoMesg* mb, s32 priority, u32 page_num, void* dramAddr, u32 n_pages, OSMesgQueue* mq) { - u32 ret; - u32 tmp; - u32 end_page; - u32 one_dma_pages; - - // select read array mode - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_READ_ARRAY); - // dummy read? - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &tmp); - - // DMA requested pages - mb->hdr.pri = priority; - mb->hdr.retQueue = mq; - mb->dramAddr = dramAddr; - - end_page = page_num + n_pages - 1; - - if ((end_page & 0xF00) != (page_num & 0xF00)) { - one_dma_pages = 256 - (page_num & 0xFF); - n_pages -= one_dma_pages; - mb->size = one_dma_pages * FLASH_BLOCK_SIZE; - mb->devAddr = __osFlashGetAddr(page_num); - osEPiStartDma(&__osFlashHandler, mb, OS_READ); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - page_num = (page_num + 256) & 0xF00; - mb->dramAddr = (u32)mb->dramAddr + mb->size; - } - - while (n_pages > 256) { - one_dma_pages = 256; - n_pages -= 256; - mb->size = one_dma_pages * FLASH_BLOCK_SIZE; - mb->devAddr = __osFlashGetAddr(page_num); - osEPiStartDma(&__osFlashHandler, mb, OS_READ); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - page_num += 256; - mb->dramAddr = (u32)mb->dramAddr + mb->size; - } - - mb->size = n_pages * FLASH_BLOCK_SIZE; - mb->devAddr = __osFlashGetAddr(page_num); - - ret = osEPiStartDma(&__osFlashHandler, mb, OS_READ); - - return ret; -} diff --git a/lib/ultralib/src/flash/flashreadid.c b/lib/ultralib/src/flash/flashreadid.c deleted file mode 100644 index 3112d74..0000000 --- a/lib/ultralib/src/flash/flashreadid.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -void osFlashReadId(u32* flash_type, u32* flash_maker) { - u8 tmp; - - // why read status ? - osFlashReadStatus(&tmp); - - // select silicon id read mode - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_ID); - - // read silicon id using DMA - __osFlashMsg.hdr.pri = OS_MESG_PRI_NORMAL; - __osFlashMsg.hdr.retQueue = &__osFlashMessageQ; - __osFlashMsg.dramAddr = __osFlashID; - __osFlashMsg.devAddr = 0; - __osFlashMsg.size = 2 * sizeof(u32); - - osInvalDCache(__osFlashID, sizeof(__osFlashID)); - osEPiStartDma(&__osFlashHandler, &__osFlashMsg, OS_READ); - osRecvMesg(&__osFlashMessageQ, NULL, OS_MESG_BLOCK); - - *flash_type = __osFlashID[0]; - *flash_maker = __osFlashID[1]; - return; -} diff --git a/lib/ultralib/src/flash/flashreadstatus.c b/lib/ultralib/src/flash/flashreadstatus.c deleted file mode 100644 index 6ff5560..0000000 --- a/lib/ultralib/src/flash/flashreadstatus.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -void osFlashReadStatus(u8* flash_status) { - u32 status; - - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_STATUS); - // read status - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - - // why twice ? - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_STATUS); - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - - *flash_status = status & 0xFF; - return; -} diff --git a/lib/ultralib/src/flash/flashreinit.c b/lib/ultralib/src/flash/flashreinit.c deleted file mode 100644 index b2ab93d..0000000 --- a/lib/ultralib/src/flash/flashreinit.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -OSPiHandle* osFlashReInit(u8 latency, u8 pulse, u8 page_size, u8 rel_duration, u32 start) { - __osFlashHandler.baseAddress = PHYS_TO_K1(start); - __osFlashHandler.type++; - __osFlashHandler.latency = latency; - __osFlashHandler.pulse = pulse; - __osFlashHandler.pageSize = page_size; - __osFlashHandler.relDuration = rel_duration; - __osFlashHandler.domain = PI_DOMAIN2; - - return &__osFlashHandler; -} diff --git a/lib/ultralib/src/flash/flashsectorerase.c b/lib/ultralib/src/flash/flashsectorerase.c deleted file mode 100644 index 14a0583..0000000 --- a/lib/ultralib/src/flash/flashsectorerase.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -s32 osFlashSectorErase(u32 page_num) { - u32 status; - OSTimer mytimer; - OSMesgQueue timerMesgQueue; - OSMesg dummy; - - // start sector erase operation - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_SECTOR_ERASE | page_num); - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); - - // wait for completion by polling erase-busy flag - osCreateMesgQueue(&timerMesgQueue, &dummy, 1); - - do { - osSetTimer(&mytimer, OS_USEC_TO_CYCLES(12500), 0, &timerMesgQueue, &dummy); - osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - } while ((status & FLASH_STATUS_ERASE_BUSY) == FLASH_STATUS_ERASE_BUSY); - - // check erase operation status, clear status - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - osFlashClearStatus(); - - if (((status & 0xFF) == 8) || ((status & 0xFF) == 0x48) || ((status & 8) == 8)) { - return FLASH_STATUS_ERASE_OK; - } else { - return FLASH_STATUS_ERASE_ERROR; - } -} diff --git a/lib/ultralib/src/flash/flashsectorerasethrough.c b/lib/ultralib/src/flash/flashsectorerasethrough.c deleted file mode 100644 index 474ee96..0000000 --- a/lib/ultralib/src/flash/flashsectorerasethrough.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -void osFlashSectorEraseThrough(u32 page_num) { - // start sector erase operation - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_SECTOR_ERASE | page_num); - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); -} diff --git a/lib/ultralib/src/flash/flashwritearray.c b/lib/ultralib/src/flash/flashwritearray.c deleted file mode 100644 index d5f56a0..0000000 --- a/lib/ultralib/src/flash/flashwritearray.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -s32 osFlashWriteArray(u32 page_num) { - u32 status; - OSTimer mytimer; - OSMesgQueue timerMesgQueue; - OSMesg dummy; - - if ((u32)__osFlashVersion == NEW_FLASH) { - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_PAGE_PROGRAM); - } - - // start program page operation - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_PROGRAM_PAGE | page_num); - - // wait for completion by polling write-busy flag - osCreateMesgQueue(&timerMesgQueue, &dummy, 1); - do { - osSetTimer(&mytimer, OS_USEC_TO_CYCLES(200), 0, &timerMesgQueue, &dummy); - osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - } while ((status & FLASH_STATUS_WRITE_BUSY) == FLASH_STATUS_WRITE_BUSY); - - // check program operation status, clear status - osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); - osFlashClearStatus(); - - if (((status & 0xFF) == 4) || ((status & 0xFF) == 0x44) || ((status & 4) == 4)) { - return FLASH_STATUS_WRITE_OK; - } else { - return FLASH_STATUS_WRITE_ERROR; - } -} diff --git a/lib/ultralib/src/flash/flashwritebuffer.c b/lib/ultralib/src/flash/flashwritebuffer.c deleted file mode 100644 index ad3f790..0000000 --- a/lib/ultralib/src/flash/flashwritebuffer.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "ultra64.h" -#include "PR/os_internal_flash.h" - -s32 osFlashWriteBuffer(OSIoMesg* mb, s32 priority, void* dramAddr, OSMesgQueue* mq) { - s32 ret; - - // select page program mode - osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_PAGE_PROGRAM); - - // DMA 128-byte page - mb->hdr.pri = priority; - mb->hdr.retQueue = mq; - mb->dramAddr = dramAddr; - mb->devAddr = 0; - mb->size = FLASH_BLOCK_SIZE; - - ret = osEPiStartDma(&__osFlashHandler, mb, OS_WRITE); - - return ret; -} diff --git a/lib/ultralib/src/gio/giointerrupt.c b/lib/ultralib/src/gio/giointerrupt.c deleted file mode 100644 index 3abc04f..0000000 --- a/lib/ultralib/src/gio/giointerrupt.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "PR/os_internal.h" -#include "../io/piint.h" - -void __osGIOInterrupt(s32 value) { - __osPiGetAccess(); - __osGIORawInterrupt(value); - __osPiRelAccess(); -} diff --git a/lib/ultralib/src/gio/giorawinterrupt.c b/lib/ultralib/src/gio/giorawinterrupt.c deleted file mode 100644 index 2fdc909..0000000 --- a/lib/ultralib/src/gio/giorawinterrupt.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "../io/piint.h" - -void __osGIORawInterrupt(s32 value) { - register u32 stat; - - WAIT_ON_IOBUSY(stat); - - IO_WRITE(GIO_GIO_INTR_REG, value); - - WAIT_ON_IOBUSY(stat); -} diff --git a/lib/ultralib/src/gt/Makefile b/lib/ultralib/src/gt/Makefile deleted file mode 100644 index b0868fd..0000000 --- a/lib/ultralib/src/gt/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -#!smake -# -# Makefile for the gt subdirectory -# - -include $(ROOT)/usr/include/make/PRdefs - - -# LCOPTS = -mips2 -non_shared -fullwarn -G 0 - -LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include - -CFILES = dumpturbo.c gt.c - -OBJECTS = $(CFILES:.c=.o) - -default: $(OBJECTS) - -include $(COMMONRULES) diff --git a/lib/ultralib/src/gt/dumpturbo.c b/lib/ultralib/src/gt/dumpturbo.c deleted file mode 100644 index 02c0e63..0000000 --- a/lib/ultralib/src/gt/dumpturbo.c +++ /dev/null @@ -1,260 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - *************************************************************************/ - -/* - * Interpret & dump a turbo display list for RSPSIM debugging - * - */ - -#include -#include -#include "macros.h" - -#if BUILD_VERSION < VERSION_J -#ident "$Revision: 1.4 $" -#endif - -#undef PRINTF -#define PRINTF rmonPrintf - - -#define TX_MAX 100 -static u32 textures[TX_MAX] ALIGNED(8); -static u32 numtextures; - -#define UNSEG_ADDR(sa) ((u32 *) (((globp)? \ - (((int)(sa) & 0x00ffffff) + \ - globp->sp.segBases[(int)(sa)>>24]) \ - : (int)(sa)) | 0x80000000)) -#define PHYS(a) ((int) ((int)(a) & 0x7fffffff)) -#define UNPHYS(a) ((u32 *) ((int)(a) | 0x80000000)) - -#define DOPRINT(a,r) \ -rmonPrintf("UNSEG: %x ->(seg%x = %06x)-> %08x\n",(int)(a),(int)(a)>>24,((globp)?(globp->sp.segBases[(int)(a)>>24]):0), (int)(r)) - - - -#define UCODE_SIZE_MAX (4096*1) -void -gtDumpTurbo(OSTask *tp,u8 flags) -{ - int i; - gtGfx *gtlistp; - gtGlobState *globp=0; - gtState *statep; - u32 dat,*datp,*addr; - - - PRINTF("\nGBI_DUMP_START:\n"); - PRINTF("$ %08x\n",PHYS(tp)); - - for (i=(int)tp; i<(int)tp+sizeof(OSTask); i+=4) { - PRINTF("<%08x\n",(int) *((u32 *) i)); - } - -#if 1 - PRINTF("? %08x\n",PHYS(tp->t.ucode_boot)); - for (i=(int)tp->t.ucode_boot; - i<(int)tp->t.ucode_boot+tp->t.ucode_boot_size; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - PRINTF("? %08x\n",PHYS(tp->t.ucode)); - for (i=(int)tp->t.ucode; i<(int)tp->t.ucode+UCODE_SIZE_MAX; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - PRINTF("? %08x\n",PHYS(tp->t.ucode_data)); - for (i=(int)tp->t.ucode_data; - i<(int)tp->t.ucode_data+tp->t.ucode_data_size; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - -#endif - - - - gtlistp = (gtGfx *) tp->t.data_ptr; - PRINTF("@ %08x\n",PHYS(gtlistp)); - -/* - * Dump turbo display list - */ - while (gtlistp->obj.statep) { - PRINTF(">%08x\n",(int) gtlistp->obj.gstatep); - PRINTF("-%08x\n",(int) gtlistp->obj.statep); - PRINTF("-%08x\n",(int) gtlistp->obj.vtxp); - PRINTF("-%08x\n",(int) gtlistp->obj.trip); - gtlistp++; - } - PRINTF(">%08x\n",(int) gtlistp->obj.gstatep); - PRINTF("-%08x\n",(int) gtlistp->obj.statep); - PRINTF("-%08x\n",(int) gtlistp->obj.vtxp); - PRINTF("-%08x\n",(int) gtlistp->obj.trip); - -/* - * Dump infor pointed to by DL - */ - gtlistp = (gtGfx *) tp->t.data_ptr; - while (gtlistp->obj.statep) { -/*rmonPrintf("=============== DUMP A DL ENTRY (%x)\n",(int)gtlistp);*/ - -/* - * Dump global state - */ - if (gtlistp->obj.gstatep) { - addr = UNSEG_ADDR(gtlistp->obj.gstatep); - globp = (gtGlobState *) addr; -/*rmonPrintf("======= DUMP GlobalState (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = addr; - (u8 *) datp < (u8 *) addr + sizeof(gtGlobState); - datp++) { - PRINTF("+%08x\n",*datp); - } - if (globp->sp.rdpCmds) { - addr = UNSEG_ADDR(globp->sp.rdpCmds); -/*rmonPrintf("GlobalState RDP cmds (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = addr; - *datp || *(datp+1); - datp+=2) { - PRINTF("+%08x\n",*datp); - PRINTF("+%08x\n",*(datp+1)); - } - PRINTF("+%08x\n",*datp); - PRINTF("+%08x\n",*(datp+1)); - } - } - -/* - * Dump state - */ - addr = UNSEG_ADDR(gtlistp->obj.statep); - statep = (gtState *) addr; -/*rmonPrintf("======= DUMP State (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = addr; - (u8 *) datp < (u8 *) addr + sizeof(gtState); - datp++) { - PRINTF("+%08x\n",*datp); - } - if (statep->sp.rdpCmds) { - addr = UNSEG_ADDR(statep->sp.rdpCmds); -/*rmonPrintf("DUMP State RDP cmds (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = addr; - *datp || *(datp+1); - datp+=2) { - PRINTF("+%08x\n",*datp); - PRINTF("+%08x\n",*(datp+1)); - } - PRINTF("+%08x\n",*datp); - PRINTF("+%08x\n",*(datp+1)); - } - -/* - * Dump vertices - */ - if (gtlistp->obj.vtxp) { - addr = UNSEG_ADDR(gtlistp->obj.vtxp); -/*rmonPrintf("======= DUMP VTX (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = (u32 *) addr; - (u8 *) datp < (u8 *) addr + - (statep->sp.vtxCount * sizeof(Vtx)); - datp++) { - PRINTF("+%08x\n",*datp); - } - } - -/* - * Dump triangles - */ - if (gtlistp->obj.trip) { - addr = UNSEG_ADDR(gtlistp->obj.trip); -/*rmonPrintf("======= DUMP TRI (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = (u32 *) addr; - (u8 *) datp < (u8 *) addr + - (statep->sp.triCount * sizeof(gtTriN)); - datp++) { - PRINTF("+%08x\n",*datp); - } - } - - - - gtlistp++; - } - - -/* - * Dump Last global state - */ - if (gtlistp->obj.gstatep) { - addr = UNSEG_ADDR(gtlistp->obj.gstatep); - globp = (gtGlobState *) addr; -/*rmonPrintf("======= DUMP GlobalState (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = addr; - (u8 *) datp < (u8 *) addr + sizeof(gtGlobState); - datp++) { - PRINTF("+%08x\n",*datp); - } - if (globp->sp.rdpCmds) { - addr = UNSEG_ADDR(globp->sp.rdpCmds); -/*rmonPrintf("GlobalState RDP cmds (%x)\n",(int)addr);*/ - PRINTF("& %08x\n",PHYS(addr)); - for (datp = addr; - *datp || *(datp+1); - datp+=2) { - PRINTF("+%08x\n",*datp); - PRINTF("+%08x\n",*(datp+1)); - } - PRINTF("+%08x\n",*datp); - PRINTF("+%08x\n",*(datp+1)); - } - } - - PRINTF("^\nGBI_DUMP_END:\n"); - - - if (flags & GT_DUMPTURBO_HANGAFTER) { - for (i=0; i<1000;i++) - rmonPrintf("=======================================\n"); - while(1); - } - - -/* - * Dumps stuff - * each line is either an address for data to follow or data itself - * 1st char on line indicates what it is: - * - * $ task header address - * @ display list address - * & dma data address - * % texture address - * ? code/code data address - * - * < task header data - * > 1st half of display list command - * - 2nd half of display list command - * + dma data - * * texture data - * | code/code data - * - */ - -} diff --git a/lib/ultralib/src/gt/gt.c b/lib/ultralib/src/gt/gt.c deleted file mode 100644 index bf99e85..0000000 --- a/lib/ultralib/src/gt/gt.c +++ /dev/null @@ -1,155 +0,0 @@ - -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: gt.c - * Creator: hsa@sgi.com - * Create Date: Fri Oct 13 14:23:48 PDT 1995 - * - */ - - -#include "gtint.h" - - -/* - * Set the cached RDP othermode word in the gt state structure. - */ -void -gtStateSetOthermode(Gfx *om, gtStateOthermode_t mode, int data) -{ - int shift, length; - u32 mask; - - if (mode == GT_CLEAR) { /* special case */ - om->words.w0 = (G_RDPSETOTHERMODE << 24); - om->words.w1 = 0x0; - } - - if (mode <= GT_RENDERMODE) { - /* these are OTHERMODE_L */ - switch (mode) { - - case GT_ALPHACOMPARE: - shift = G_MDSFT_ALPHACOMPARE; - length = 2; - break; - - case GT_ZSRCSEL: - shift = G_MDSFT_ZSRCSEL; - length = 1; - break; - - case GT_RENDERMODE: - shift = G_MDSFT_RENDERMODE; - length = 29; - break; - - default: - break; - } - - mask = (0x01 << length); - mask = mask - 1; - mask = (mask << shift); - mask = mask ^ 0xffffffff; - om->words.w1 &= mask; - om->words.w1 |= data; - - } else { - /* these are OTHERMODE_H */ - switch (mode) { - case GT_ALPHADITHER: - shift = G_MDSFT_ALPHADITHER; - length = 2; - break; - - case GT_RGBDITHER: - shift = G_MDSFT_RGBDITHER; - length = 2; - break; - - case GT_COMBKEY: - shift = G_MDSFT_COMBKEY; - length = 1; - break; - - case GT_TEXTCONV: - shift = G_MDSFT_TEXTCONV; - length = 3; - break; - - case GT_TEXTFILT: - shift = G_MDSFT_TEXTFILT; - length = 2; - break; - - case GT_TEXTLUT: - shift = G_MDSFT_TEXTLUT; - length = 2; - break; - - case GT_TEXTLOD: - shift = G_MDSFT_TEXTLOD; - length = 1; - break; - - case GT_TEXTDETAIL: - shift = G_MDSFT_TEXTDETAIL; - length = 2; - break; - - case GT_TEXTPERSP: - shift = G_MDSFT_TEXTPERSP; - length = 1; - break; - - case GT_CYCLETYPE: - shift = G_MDSFT_CYCLETYPE; - length = 2; - break; - - case GT_PIPELINE: - shift = G_MDSFT_PIPELINE; - length = 1; - break; - - default: - break; - } - - mask = (0x01 << length); - mask = mask - 1; - mask = (mask << shift); - mask = mask ^ 0xffffffff; - om->words.w0 &= mask; - om->words.w0 |= data; - } - - /* force cached othermode word to have proper command id: */ - om->words.w0 &= 0x00ffffff; - om->words.w0 |= (G_RDPSETOTHERMODE << 24); -} - diff --git a/lib/ultralib/src/gt/gtint.h b/lib/ultralib/src/gt/gtint.h deleted file mode 100644 index 31ddd7c..0000000 --- a/lib/ultralib/src/gt/gtint.h +++ /dev/null @@ -1,36 +0,0 @@ - -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: gtint.h - * Creator: hsa@sgi.com - * Create Date: Fri Oct 13 14:24:36 PDT 1995 - * - */ - -#include "mbi.h" -#include "gu.h" -#include "gt.h" - diff --git a/lib/ultralib/src/gu/Makefile b/lib/ultralib/src/gu/Makefile deleted file mode 100644 index ad6e2fa..0000000 --- a/lib/ultralib/src/gu/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -#!smake -# -# Makefile for the gu subdirectory -# - -include $(ROOT)/usr/include/make/PRdefs - - -# LCOPTS = -mips2 -non_shared -fullwarn -G 0 -LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include -LCOPTS = -G 0 -g -O - -CFILES = \ - align.c \ - cosf.c \ - coss.c \ - frustum.c \ - guloadtile_bug.c \ - loadtextureblockmipmap.c\ - lookat.c \ - lookathil.c \ - lookatref.c \ - lookatstereo.c \ - mtxcatf.c \ - mtxcatl.c \ - mtxutil.c \ - normalize.c \ - ortho.c \ - perspective.c \ - position.c \ - poslight.c \ - poslighthil.c \ - random.c \ - rotate.c \ - rotaterpy.c \ - scale.c \ - sinf.c \ - sins.c \ - translate.c \ - us2dex.c \ - us2dex_emu.c \ - us2dex2_emu.c \ - usprite.c - -ASFILES = \ - libm_vals.s \ - sqrtf.s -OBJECTS = $(CFILES:.c=.o) - -default: $(OBJECTS) - -include $(COMMONRULES) diff --git a/lib/ultralib/src/gu/align.c b/lib/ultralib/src/gu/align.c deleted file mode 100644 index 9be7b4a..0000000 --- a/lib/ultralib/src/gu/align.c +++ /dev/null @@ -1,75 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* - * S = sin (a) - * C = cos (a) - * H = sqrt (X*X + Z*Z) - * - * [ v ] [ C S ] [ 1 ] [ -Z/H X/H ] - * [ -S C ] [ H Y ] [ 1 ] - * [ 1 ] [ -Y H ] [ -X/H -Z/H ] - * [ 1 ] [ 1 ] [ 1 ] - * - */ - -void guAlignF(float mf[4][4], float a, float x, float y, float z) -{ - static float dtor = 3.1415926 / 180.0; - float s, c, h, hinv; - - guNormalize(&x, &y, &z); - - a *= dtor; - s = sinf (a); - c = cosf (a); - h = sqrtf (x*x + z*z); - - guMtxIdentF(mf); - - if (h != 0) { - hinv = 1 / h; - - mf[0][0] = (-z*c - s*y*x) * hinv; - mf[1][0] = (z*s - c*y*x) * hinv; - mf[2][0] = -x; - mf[3][0] = 0; - - mf[0][1] = s*h; - mf[1][1] = c*h; - mf[2][1] = -y; - mf[3][1] = 0; - - mf[0][2] = (c*x - s*y*z) * hinv; - mf[1][2] = (-s*x - c*y*z) * hinv; - mf[2][2] = -z; - mf[3][2] = 0; - - mf[0][3] = 0; - mf[1][3] = 0; - mf[2][3] = 0; - mf[3][3] = 1; - } else { - /* XXX: should do this right */ - } -} - -void guAlign(Mtx *m, float a, float x, float y, float z) -{ - Matrix mf; - - guAlignF(mf, a, x, y, z); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/cosf.c b/lib/ultralib/src/gu/cosf.c deleted file mode 100644 index 5a66c1b..0000000 --- a/lib/ultralib/src/gu/cosf.c +++ /dev/null @@ -1,137 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* ==================================================================== - * ==================================================================== - * - * Module: fcos.c - * $Revision: 1.3 $ - * $Date: 1998/10/09 06:10:53 $ - * $Author: has $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/cosf.c,v $ - * - * Revision history: - * 09-Jun-93 - Original Version - * - * Description: source code for fcos function - * - * ==================================================================== - * ==================================================================== - */ - -#pragma weak fcos = __cosf -#pragma weak cosf = __cosf -#define fcos __cosf - -/* coefficients for polynomial approximation of cos on +/- pi/2 */ - -static const du P[] = -{ -{0x3ff00000, 0x00000000}, -{0xbfc55554, 0xbc83656d}, -{0x3f8110ed, 0x3804c2a0}, -{0xbf29f6ff, 0xeea56814}, -{0x3ec5dbdf, 0x0e314bfe}, -}; - -static const du rpi = -{0x3fd45f30, 0x6dc9c883}; - -static const du pihi = -{0x400921fb, 0x50000000}; - -static const du pilo = -{0x3e6110b4, 0x611a6263}; - -static const fu zero = {0x00000000}; - - -/* ==================================================================== - * - * FunctionName fcos - * - * Description computes cosine of arg - * - * ==================================================================== - */ - -float -fcos( float x ) -{ -float absx; -double dx, xsq, poly; -double dn; -int n; -double result; -int ix, xpt; - - - ix = *(int *)&x; - xpt = (ix >> 22); - xpt &= 0x1ff; - - /* xpt is exponent(x) + 1 bit of mantissa */ - - - if ( xpt < 0x136 ) - { - /* |x| < 2^28 */ - - /* use the standard algorithm from Cody and Waite, doing - the computations in double precision - */ - - absx = ABS(x); - - dx = absx; - - dn = dx*rpi.d + 0.5; - n = ROUND(dn); - dn = n; - - dn -= 0.5; - - dx = dx - dn*pihi.d; - dx = dx - dn*pilo.d; /* dx = x - (n - 0.5)*pi */ - - xsq = dx*dx; - - poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; - - result = dx + (dx*xsq)*poly; - - /* negate result if n is odd */ - - if ( (n & 1) == 0 ) - return ( (float)result ); - - return ( -(float)result ); - } - - if ( x != x ) - { - /* x is a NaN; return a quiet NaN */ - -#ifdef _IP_NAN_SETS_ERRNO - - *__errnoaddr = EDOM; -#endif - - return ( __libm_qnan_f ); - } - - /* just give up and return 0.0 */ - - return ( zero.f ); -} diff --git a/lib/ultralib/src/gu/coss.c b/lib/ultralib/src/gu/coss.c deleted file mode 100644 index 0d95530..0000000 --- a/lib/ultralib/src/gu/coss.c +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* ==================================================================== - * ==================================================================== - * - * Module: coss.c - * $Revision: 1.3 $ - * $Date: 1998/10/09 06:11:01 $ - * $Author: has $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/coss.c,v $ - * - * ==================================================================== - * ==================================================================== - */ - -/* coefficients for polynomial approximation of sin on +/- pi/2 */ - -/* ==================================================================== - * - * FunctionName coss - * - * Description computes cosine of arg - * - * ==================================================================== - */ - -signed short -coss( unsigned short x ) -{ - /* 0 <= x < 0x10000 ==> 0 <= x < 2PI */ - - return sins ((unsigned short) (x + 0x4000)); -} diff --git a/lib/ultralib/src/gu/dump_gbi.c b/lib/ultralib/src/gu/dump_gbi.c deleted file mode 100644 index a5e5e12..0000000 --- a/lib/ultralib/src/gu/dump_gbi.c +++ /dev/null @@ -1,274 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - *************************************************************************/ - -/* - * Interpret Task with GBI display list and dump it for debugging. - */ - - -/************************************************** - * - * guDumpGbiDL no longer supported - * applications should use guParseGbiDL with the - * GU_PARSEGBI_DUMPONLY flag set. - * - **************************************************/ - - -#if 0 - - -#include "ultra64.h" -#include "bstring.h" - -#undef PRINTF -#define PRINTF osSyncPrintf - -#define DL_STACKSIZE 11 -static u32 *Gp[DL_STACKSIZE]; - -#define TX_MAX 100 -static u32 textures[TX_MAX]; -static u32 numtextures; - -static u32 segment_base[16]; -static u32 dotextures = TRUE; -static int dl_depth = 0; - - -/* - * dump a DMA-type display list command. - */ -static void -dump_dma(u32 *bufp) -{ - u32 addr, - *data; - u8 seg_id; - u16 len; - char op, - b0; - - op = ((*bufp & 0xff000000) >> 24); - - /* - * DMA op addressing is all the same: - */ - seg_id = (u8) ((bufp[1] & 0x0f000000) >> 24); - addr = segment_base[seg_id] + (bufp[1] & 0x00ffffff); - - - addr = (u32) osPhysicalToVirtual(addr); - - len = (u16) (bufp[0] & 0x0000ffff); - - PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); - if (op == (char) G_DL) { - b0 = (char) ((bufp[0] & 0x00ff0000) >> 16); - ++dl_depth; - if (dl_depth > (DL_STACKSIZE - 1)) { - PRINTF("***** Error, max levels of display lists exceeded\n"); - return; - } - Gp[dl_depth] = (u32 *) addr; - PRINTF("@ %08x\n",(int)Gp[dl_depth]&0x7fffffff); - } else { - PRINTF("& %08x\n", (int)addr&0x7fffffff); - data = (u32 *) addr; - while(len>0) { - PRINTF("+%08x\n", *data); - data++; - len -= 4; - } - PRINTF("@ %08x\n",(int)(Gp[dl_depth] + (sizeof(Gfx) >> 2))&0x7fffffff); - } -} - -/* - * dump a IMM-type display list command. - */ -static void -dump_imm(u32 *bufp) -{ - char op, - b0; - - op = ((*bufp & 0xff000000) >> 24); - - PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); - if (op == (char) G_ENDDL) { - dl_depth--; - if (dl_depth >= 0) { - PRINTF("@ %08x\n",(int)(Gp[dl_depth] + (sizeof(Gfx) >> 2))&0x7fffffff); - } - } - if (op == (char) G_MOVEWORD) { - if (((bufp[0] ) & 0xff) == G_MW_SEGMENT) { - b0 = (char) ((bufp[0] & 0xff00)>>10); - segment_base[b0] = bufp[1] & 0x00ffffff; - } - } -} - -/* - * dump a RDP-type display list command. - */ -static void -dump_rdp(u32 *bufp) -{ - u8 seg_id; - u32 addr; - int i0, - i1; - char op; - - op = ((*bufp & 0xff000000) >> 24); - - PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); - if (op == (char) G_SETTIMG && dotextures) { - if (numtextures>=TX_MAX) { - PRINTF("GBI DUMP ERROR: too many textures (max=%d)\n",TX_MAX); - return; - } - seg_id = (u8) ((bufp[1] & 0x0f000000) >> 24); - addr = segment_base[seg_id] + (bufp[1] & 0x00ffffff); - addr = (u32) osPhysicalToVirtual(addr); - i1=1; - for (i0=0;i0= 0) && (dl_depth < (DL_STACKSIZE - 1))) { - - op = (u8) ((*Gp[dl_depth] & 0xff000000) >> 24); - bcopy((char *) Gp[dl_depth], (char *) &(readBuf[0]), sizeof(Gfx)); - - switch (op & 0xc0) { - - case (u8) 0x00: - dump_dma(readBuf); - break; - - case (u8) 0x80: - dump_imm(readBuf); - break; - - case (u8) 0xc0: - dump_rdp(readBuf); - break; - - default: - PRINTF("ERROR : display list is lost, op = %02x\n", op); - break; - - } - - if (op != (u8) G_DL) { - Gp[dl_depth] += (sizeof(Gfx) >> 2); - } - } - if (dotextures) { - u32 i,j; - for (i=0; it.ucode_boot & 0x7fffffff); - for (i=(int)tp->t.ucode_boot; i<(int)tp->t.ucode_boot+tp->t.ucode_boot_size; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - PRINTF("? %08x\n",(int) tp->t.ucode& 0x7fffffff); - for (i=(int)tp->t.ucode; i<(int)tp->t.ucode+UCODE_SIZE_MAX; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - PRINTF("? %08x\n",(int) tp->t.ucode_data & 0x7fffffff); - for (i=(int)tp->t.ucode_data; i<(int)tp->t.ucode_data+tp->t.ucode_data_size; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - - guDumpGbi((u32 *) tp->t.data_ptr); - - - PRINTF("^\nGBI_DUMP_END:\n"); - - if (flags & GU_PARSEGBI_HANGAFTER) { - int i; - for (i=0; i<1000;i++) - PRINTF("=============================================================\n"); - while(1); - } - - -/* - * Dumps stuff - * each line is either an address for data to follow or data itself - * 1st char on line indicates what it is: - * - * $ task header address - * @ display list address - * & dma data address - * % texture address - * ? code/code data address - * - * < task header data - * > 1st half of display list command - * - 2nd half of display list command - * + dma data - * * texture data - * | code/code data - * - */ - -} - -#endif diff --git a/lib/ultralib/src/gu/frustum.c b/lib/ultralib/src/gu/frustum.c deleted file mode 100644 index 4af9c5d..0000000 --- a/lib/ultralib/src/gu/frustum.c +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guFrustumF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale) -{ - int i, j; - - guMtxIdentF(mf); - - mf[0][0] = 2*n/(r-l); - mf[1][1] = 2*n/(t-b); - mf[2][0] = (r+l)/(r-l); - mf[2][1] = (t+b)/(t-b); - mf[2][2] = -(f+n)/(f-n); - mf[2][3] = -1; - mf[3][2] = -2*f*n/(f-n); - mf[3][3] = 0; - - for (i=0; i<4; i++) - for (j=0; j<4; j++) - mf[i][j] *= scale; -} - -void guFrustum(Mtx *m, float l, float r, float b, float t, float n, float f, float scale) -{ - Matrix mf; - - guFrustumF(mf, l, r, b, t, n, f, scale); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/guint.h b/lib/ultralib/src/gu/guint.h deleted file mode 100644 index c3206dd..0000000 --- a/lib/ultralib/src/gu/guint.h +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "mbi.h" -#include "gu.h" - -typedef union -{ - struct - { - unsigned int hi; - unsigned int lo; - } word; - - double d; -} du; - -typedef union -{ - unsigned int i; - float f; -} fu; - -#ifndef __GL_GL_H__ - -typedef float Matrix[4][4]; - -#endif - -#define ROUND(d) (int)(((d) >= 0.0) ? ((d) + 0.5) : ((d) - 0.5)) -#define ABS(d) ((d) > 0) ? (d) : -(d) - -extern float __libm_qnan_f; diff --git a/lib/ultralib/src/gu/guloadtile_bug.c b/lib/ultralib/src/gu/guloadtile_bug.c deleted file mode 100644 index e16e250..0000000 --- a/lib/ultralib/src/gu/guloadtile_bug.c +++ /dev/null @@ -1,235 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "ultra64.h" - -/* - * Inidicates how many words will be added to display list - * by guDPLoadTextureTile function. - */ -int -guGetDPLoadTextureTileSz(int ult, int lrt) -{ - return (((lrt - ult + 1) / 2) * 4 + 3); -} - -/* - * Workaround for load_tile bug on tapeout one hardware. Uses - * load blocks for each line. ~25% more dma traffic + memory for - * extra commands. - */ -void -guDPLoadTextureTile(Gfx * temp, void *timg, - int texl_fmt, int texl_size, - int img_width, int img_height, - int uls, int ult, int lrs, int lrt, - int palette, - int cms, int cmt, - int masks, int maskt, - int shifts, int shiftt) -{ - int line; - int tile_width, - tile_height; /* - - * in texels - */ - int dxt; - int sizeb; - int lineb; - int line_size; /* - - * in 64-bit words - */ - int texel_num_pad; /* - - * in texels, pad to 64-bit word size - */ - int count; - int tmem; - int tile; - int s, - t; - - tile_width = lrs - uls + 1; - tile_height = lrt - ult + 1; - - switch (texl_size) { - case G_IM_SIZ_8b: - sizeb = G_IM_SIZ_8b_BYTES; - lineb = G_IM_SIZ_8b_LINE_BYTES; - break; - case G_IM_SIZ_16b: - sizeb = G_IM_SIZ_16b_BYTES; - lineb = G_IM_SIZ_16b_LINE_BYTES; - break; - case G_IM_SIZ_32b: - sizeb = G_IM_SIZ_32b_BYTES; - lineb = G_IM_SIZ_32b_LINE_BYTES; - break; - } - - dxt = CALC_DXT(tile_width, sizeb); - line_size = ((tile_width * lineb) + 7) >> 3; - /* - * pad line to word boundary - */ - texel_num_pad = ((((tile_width * sizeb) + 7) >> 3) * 8) / sizeb; - - gDPSetTextureImage(temp++, texl_fmt, texl_size, img_width, timg); - - for (line = 0; line < tile_height; line += 2) { - t = (ult + line) & ~1; /* - * load from even line - */ - tmem = line * line_size; - - /* - * set for both loads, avoid sync by alternating tiles - */ - tile = (line % 4) ? 1 : 0; - - gDPSetTile(temp++, texl_fmt, texl_size, 0, tmem, G_TX_LOADTILE - tile, 0, - cmt, maskt, shiftt, - cms, masks, shifts); - - /* - * do odd line first - */ - s = uls + img_width - texel_num_pad; - count = (texel_num_pad * 2) - 1; - - gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); - - /* - * do even line - */ - s = uls; - count = tile_width - 1; - - gDPLoadSync(temp++); - gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); - - } - - /* - * set final tile - */ - gDPSetTile(temp++, texl_fmt, texl_size, line_size, 0, G_TX_RENDERTILE, 0, - cmt, maskt, shiftt, - cms, masks, shifts); - - gDPSetTileSize(temp++, G_TX_RENDERTILE, - (uls) << G_TEXTURE_IMAGE_FRAC, - (ult) << G_TEXTURE_IMAGE_FRAC, - (lrs) << G_TEXTURE_IMAGE_FRAC, - (lrt) << G_TEXTURE_IMAGE_FRAC); -} - -/* - * 4-BIT VERSION - */ - -/* - * Inidicates how many words will be added to display list - * by guDPLoadTextureTile function. - */ -int -guGetDPLoadTextureTile_4bSz(int ult, int lrt) -{ - return (((lrt - ult + 1) / 2) * 4 + 3); -} - -/* - * Workaround for load_tile bug on version 1.0 hardware. Uses - * load blocks for each line. ~25% more dma traffic + memory for - * extra commands. - */ -void -guDPLoadTextureTile_4b(Gfx * temp, void *timg, - int texl_fmt, - int img_width, int img_height, - int uls, int ult, int lrs, int lrt, - int palette, - int cms, int cmt, - int masks, int maskt, - int shifts, int shiftt) -{ - int line; - int tile_width, - tile_height; - int dxt; - int sizeb; - int lineb; - int line_size; - int count; - int tmem; - int tile; - int s, - t; - - tile_width = (lrs - uls + 1) >> 1; - tile_height = lrt - ult + 1; - sizeb = G_IM_SIZ_8b_BYTES; - lineb = G_IM_SIZ_8b_LINE_BYTES; - line_size = ((tile_width * lineb) + 7) >> 3; - dxt = CALC_DXT_4b(tile_width); - - gDPSetTextureImage(temp++, texl_fmt, G_IM_SIZ_8b, ((img_width) >> 1), timg); - - for (line = 0; line < tile_height; line += 2) { - t = (ult + line) & ~1; /* - * load from even line - */ - tmem = line * line_size; - - /* - * set for both loads, avoid sync by alternating tiles - */ - tile = (line % 4) ? 1 : 0; - - gDPSetTile(temp++, texl_fmt, G_IM_SIZ_8b, 0, tmem, G_TX_LOADTILE - tile, 0, - cmt, maskt, shiftt, - cms, masks, shifts); - - /* - * do odd line first - */ - s = uls + img_width - line_size * 8; - count = (line_size * 8 * 2) - 1; - - gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); - - /* - * do even line - */ - s = uls; - count = tile_width - 1; - - gDPLoadSync(temp++); - gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); - - } - - /* - * set final tile - */ - gDPSetTile(temp++, texl_fmt, G_IM_SIZ_4b, line_size, 0, G_TX_RENDERTILE, 0, - cmt, maskt, shiftt, - cms, masks, shifts); - - gDPSetTileSize(temp++, G_TX_RENDERTILE, - (uls) << G_TEXTURE_IMAGE_FRAC, - (ult) << G_TEXTURE_IMAGE_FRAC, - (lrs) << G_TEXTURE_IMAGE_FRAC, - (lrt) << G_TEXTURE_IMAGE_FRAC); -} diff --git a/lib/ultralib/src/gu/libm_vals.s b/lib/ultralib/src/gu/libm_vals.s deleted file mode 100644 index b88ad98..0000000 --- a/lib/ultralib/src/gu/libm_vals.s +++ /dev/null @@ -1,5 +0,0 @@ - .rdata - .align 4 - .globl __libm_qnan_f -__libm_qnan_f: - .word 0x7F810000 diff --git a/lib/ultralib/src/gu/loadtextureblockmipmap.c b/lib/ultralib/src/gu/loadtextureblockmipmap.c deleted file mode 100644 index 30ffc65..0000000 --- a/lib/ultralib/src/gu/loadtextureblockmipmap.c +++ /dev/null @@ -1,717 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/**************************************************************************** - * NOTE: To view this file correctly, set tabstop=3 -*****************************************************************************/ -#include "guint.h" -#include -#include "ultra64.h" -#include "macros.h" - -// TODO: this comes from a header -#ident "$Revision: 1.49 $" - -#define TRAM_SIZE 4096 /* in bytes */ -#define TRAM_WSIZE 8 /* TRAM word size in bytes */ -#define TRAM_LSIZE 8 /* TRAM load word size in bytes */ -#define MM_MAX_LEVEL 7 /* number of mipmap levels 0 to MM_MAX_LEVEL */ -#define MM_MIN_SIZE 1 /* smallest mipmap tile */ - -struct texelSizeParams -{ - unsigned char gran; - unsigned char shift; - unsigned char tsize; - unsigned char shiftr; -}; - -/* texture ram tile */ -struct Tile -{ - int w; /* width of tile in texels, padded to tram line sz */ - int s, t; /* size of tile in texels */ - int addr; /* address in tram of tile */ -}; - -/* tram mipmaps */ -static struct Tile mipmap[MM_MAX_LEVEL+1] ALIGNED(8); -static struct texelSizeParams sizeParams[4] = - { 16, 3, 1, 0, - 8, 2, 2, 1, - 4, 1, 4, 2, - 2, 0, 8, 3 - }; - - -static int max_mipmap; -static unsigned char *tram; -static int txlsize; -static int errNo = 0; -static int NA = 0; /* Not applicable */ -static unsigned int length; /* total texels in mipmap */ -static int level; /* total levels in mipmap */ - -static void get3x3(struct Tile *tile, int *s, int *t, int *texel, int shift, int size); -static void stuffDisplayList(Gfx **glistp, Image *im, char *tbuf, unsigned char startTile, - unsigned char pal, unsigned char cms, unsigned char cmt, - unsigned char masks, unsigned char maskt, unsigned char shifts, - unsigned char shiftt); -static void kernel(int i, int r1, int g1, int b1, int a1, float *r2, float *g2, - float *b2, float *a2); - -#define unpack_ia16(c,i,a) \ - i = (c & 0xff00) >> 8, a = (c & 0xff) -#define pack_ia16(i,a) \ - (i << 8) | a - -#define unpack_ia8(c,i,a) \ - i = ((c & 0xf0) >> 4), a = (c & 0xf) -#define pack_ia8(i,a) \ - (a & 0xf) | ((i & 0xf) << 4) - -#define unpack_ia4(c,i,a) \ - i = ((c & 0xe) >> 1), a = (c & 0x1) -#define pack_ia4(i,a) \ - ((i & 0x7) << 1) | ((a & 0x1)) - -#define unpack_i4(c,i) \ - i = (c & 0xf) -#define pack_i4(i) \ - (i) - -#define unpack_i8(c,i) \ - i = (c & 0xff) -#define pack_i8(i) \ - (i) - -#define unpack_ci8(c,ci) unpack_i8(c,ci) -#define pack_ci8(ci) pack_i8(ci) - -#define unpack_ci4(c,ci) unpack_i4(c,ci) -#define pack_ci4(ci) pack_i4(ci) - -#define unpack_rgba(c,r,g,b,a) \ - (r = (c & 0xf800) >> 11), g = ((c & 0x07c0) >> 6), b = ((c & 0x003e) >> 1), \ - a = (c & 0x1) - -#define pack_rgba( r, g, b, a) ((r&0x1f) << 11) | (g&0x1f) << 6 | \ - ((b&0x1f) << 1) | (a) - -/************************************************************************* - * Generates all levels of a power-of-two mipmap from an input array. * - * Also stuffs display list with entries for loading and rendering the * - * texture. Filtering Color-Index maps makes sense only if the lookup * - * is a linear ramp. Billboards and trees cutout using alpha will change * - * shape as the level changes due to change in map resolution. Texel * - * formats with only one bit of alpha will not be filtered very well. * - ************************************************************************* - * ErrNo value error description * - *-----------------------------------------------------------------------* - * 1 Mipmap too big to load into tmem. Not Fatal, * - * will load as many levels as there is space for. * - * * - * 2 Texel format not supported, Fatal error * - ************************************************************************/ - -int guLoadTextureBlockMipMap(Gfx **glistp, unsigned char *tbuf, Image *im, - unsigned char startTile, unsigned char pal, unsigned char cms, unsigned char cmt, - unsigned char masks, unsigned char maskt, unsigned char shifts, unsigned char shiftt, - unsigned char cfs, unsigned char cft) -{ - - unsigned char *iaddr, *taddr; - int im_bytes, tr_bytes; - int h, b; - int flip; - char startUnAligned; - char endUnAligned; - - txlsize = sizeParams[im->siz].tsize; /* texel size in nibbles */ - /* to next line size */ - - /* - * Do top level map, swizzle bytes on odd t's * - */ - /* base char address of tile to be loaded */ - iaddr = ((im->t * im->lsize)+((im->s * txlsize) >> 1) + im->base); - - /*check tile line starting and ending alignments along 4bit bndries */ - startUnAligned = ((im->s & 0x1) && (im->siz == G_IM_SIZ_4b)); - endUnAligned = (((im->s + im->w) & 0x1) && (im->siz == G_IM_SIZ_4b)); - - im_bytes = ((im->w * txlsize + 1) >> 1); /* siz of 1 tile line in bytes */ - tr_bytes = im_bytes / TRAM_LSIZE; /* no of tram lines per tile line */ - tr_bytes = tr_bytes * TRAM_LSIZE; /* tile line size in bytes */ - if (im_bytes > tr_bytes) tr_bytes += TRAM_LSIZE; - - taddr = &tbuf[im->addr]; /* why ? make this zero?*/ - - if (startUnAligned) - { - for (h=0; hh; h++) - { - flip = (h & 1) << 2; /*shift does not depend on txlsize*/ - for (b=0; b> 4); - } - /* add last aligned nibble */ - if (!endUnAligned) *(taddr+((b-1)^flip)) &= (0xf0); - /* pickup trailing bytes */ - for (b=im_bytes; blsize; - taddr += tr_bytes; - } - } - else /* if start aligned */ - { - for (h=0; hh; h++) - { - flip = (h & 1) << 2; /*shift does not depend on txlsize*/ - for (b=0; blsize; - taddr += tr_bytes; - } - } - - tram = tbuf; - - /* save tile attributes in top mipmap */ - mipmap[0].s = im->w; /* tile width */ - mipmap[0].t = im->h; /* tile height */ - /* guaranteed no remainder ? */ - mipmap[0].w = ((tr_bytes / txlsize) << 1); /* tile line width in texels*/ - mipmap[0].addr = im->addr; - max_mipmap = MM_MAX_LEVEL; - length = mipmap[0].w*mipmap[0].t; /* total texels in level 0 */ -/** - rmonPrintf("level0 w,t,l = %d %d %d\n",mipmap[0].w, mipmap[0].t,length); -***/ - -/****************************************************************************** - Generate other levels of mipmap using a box filter -******************************************************************************/ - -{/* generate mip map for this tile */ - unsigned char *taddr, *saddr; - int shift = (int) sizeParams[im->siz].shift; - int s, t, si, ti, sii, tii; - int s4[9]; - int t4[9]; - int tex4[9]; - int r0, g0, b0, a0, r1, g1, b1, a1; - float r2 ,g2, b2, a2; - float dummy; - int i0, ci0, ia0, i1, ci1, ia1; - float i2, ci2, ia2; - int texel; - int i,trip; - unsigned int tempaddr; - int ntexels = ((TRAM_LSIZE/txlsize) << 1); /* texels per line */ - - level = 0; /* need to check for memory overflow */ - while ((mipmap[level].s > 1) || (mipmap[level].t > 1)) - { - level++; - /* - * set new mipmap level address in bytes - */ - mipmap[level].addr = mipmap[level-1].addr + - (mipmap[level-1].w * txlsize * mipmap[level-1].t >> 1); - - /* - * grab location in tram pointing to the current level address - */ - taddr = &(tram[ mipmap[level].addr ]); - - /* - * downfilter by 2X, bump odd size - * compute parameters for new mipmap level - */ - mipmap[level].s = (mipmap[0].s) >> level; - mipmap[level].t = (mipmap[0].t) >> level; - - if (mipmap[level].s == 0) mipmap[level].s = 1; - if (mipmap[level].t == 0) mipmap[level].t = 1; - - /* - * width must be a multiple of 8 bytes (padding for tram line size) - */ - mipmap[level].w = - ((mipmap[level].s + (ntexels -1)) >> (shift +1) << (shift +1)); - - /* - * compute total no of texels to be loaded - */ - length += mipmap[level].w*mipmap[level].t; -/** - rmonPrintf("level, w,t,l = %d %d %d %d\n", level, mipmap[level].w, mipmap[level].t,length); -**/ - if ((length*txlsize >> 1) >= TRAM_SIZE) - { - errNo = 1; - length -= mipmap[level].w*mipmap[level].t; - break; - } - - /* - * for each scanline - */ - for (t=0; t= mipmap[level-1].t) ti = t; - if (tii < 0) tii = t; - } else { - if (ti >= mipmap[level-1].t) ti = 0; - if (tii < 0) tii = mipmap[level-1].t - 1; - } - - tempaddr = 0; - - for (s=0; s= mipmap[level-1].s) si = s; - if (sii < 0) sii = s; - } else { - if (si >= mipmap[level-1].s) si = 0; - if (sii < 0) sii = mipmap[level-1].s - 1; - } - -/*** - if (level == 6) - rmonPrintf("sts = %d %d %d %d %d %d\n", - s, si, sii, t, ti, tii); -***/ - - /* - * grab the nine neighbours to apply kernel function - */ - s4[0] = s; t4[0] = tii; - s4[1] = si; t4[1] = tii; - s4[2] = si; t4[2] = t; - s4[3] = si; t4[3] = ti; - s4[4] = s; t4[4] = ti; - s4[5] = sii; t4[5] = ti; - s4[6] = sii; t4[6] = t; - s4[7] = sii; t4[7] = tii; - s4[8] = s; t4[8] = t; - - get3x3( &mipmap[level-1], s4, t4, tex4, shift, im->siz); - - saddr = taddr + ((tempaddr >> 1)^trip); - r1 = g1 = b1 = a1 = ci1 = i1 = 0; - r2 = g2 = b2 = a2 = ci2 = i2 = 0; - - /* - * Extract R,G and B components of the 9 texels and - * apply the filter kernel - */ - switch (im->fmt) - { - case (G_IM_FMT_RGBA): - if (im->siz == G_IM_SIZ_16b) - { - for (i=0; i< 9; i++) - { - unpack_rgba(tex4[i], r0, g0, b0, a0); - kernel(i, r0, g0, b0, a0, &r2, &g2, &b2, &a2); -/*** - if (level == 6) - rmonPrintf("r0, g0, b0, a0 = %d %d %d %d\n", - r0, g0, b0, a0); -**/ - } - r1 = (int)(r2/16.0 + 0.5); - g1 = (int)(g2/16.0 + 0.5); - b1 = (int)(b2/16.0 + 0.5); - a1 = (int)(a2/16.0 + 0.5); - } - else - { - /* - * RGBA32 is not supported - */ - errNo = 2; - return errNo; - } - break; - - case (G_IM_FMT_YUV): - errNo = 2; - return errNo; - break; - - case (G_IM_FMT_CI): - if (im->siz == G_IM_SIZ_4b) - { - for (i=0; i<9; i++) - { - unpack_ci4(tex4[i],ci0); - kernel(i, ci0, 0, 0, 0, &ci2, &dummy, &dummy, - &dummy); - } - ci1 = (int)(ci2/16.0 + 0.5); - } - else - if (im->siz == G_IM_SIZ_8b) - { - for (i=0; i<9; i++) - { - unpack_ci8(tex4[i],ci0); - kernel(i, ci0, 0, 0, 0, &ci2, &dummy, - &dummy, &dummy); - } - ci1 = (int)(ci2/16.0 + 0.5); - } - else - { - errNo=2; - return errNo; - } - break; - - case (G_IM_FMT_IA): - if (im->siz == G_IM_SIZ_4b) - { - for (i=0; i<9; i++) - { - unpack_ia4(tex4[i],i0,a0); - kernel(i, i0, a0, 0, 0, &i2, &a2, &dummy, - &dummy); - } - i1 = (int)(i2/16.0 +0.5); - a1 = (int)(a2/16.0 +0.5); - } - else if (im->siz == G_IM_SIZ_8b) - { - for (i=0; i<9; i++) - { - unpack_ia8(tex4[i],i0,a0); - kernel(i, i0, a0, 0, 0, &i2, &a2, &dummy, - &dummy); - } - i1 = (int)(i2/16.0 +0.5); - a1 = (int)(a2/16.0 +0.5); - } - else - if (im->siz == G_IM_SIZ_16b) - { - for (i=0; i<9; i++) - { - unpack_ia16(tex4[i],i0,a0); - kernel(i, i0, a0, 0, 0, &i2, &a2, &dummy, - &dummy); - } - i1 = (int)(i2/16.0 +0.5); - a1 = (int)(a2/16.0 +0.5); - } - else - { - errNo = 2; - return errNo; - } - break; - - case (G_IM_FMT_I): - if (im->siz == G_IM_SIZ_4b) - { - for (i=0; i<9; i++) - { - unpack_i4(tex4[i],i0); - kernel(i, i0, 0, 0, 0, &i2, &dummy, &dummy, - &dummy); - } - i1 = (int)(i2/16.0 + 0.5); - } - else - if (im->siz == G_IM_SIZ_8b) - { - for (i=0; i<9; i++) - { - unpack_i8(tex4[i],i0); - kernel(i, i0, 0, 0, 0, &i2, &dummy, &dummy, - &dummy); - } - i1 = (int)(i2/16.0 +0.5); - } - else - { - errNo = 2; - return errNo; - } - - default: - break; - } - - /* - * Pack fields into destination texel - */ - switch (im->fmt) - { - - case (G_IM_FMT_RGBA): - texel = pack_rgba(r1,g1,b1,a1); - *(short *)((int)saddr^flip) = texel; - break; - - case (G_IM_FMT_YUV): - break; - - case (G_IM_FMT_CI): - - if (im->siz == G_IM_SIZ_4b) - { - texel = pack_ci4(ci1); - *(char *)((int)saddr^flip) |= (s & 0x2)? - (texel): (texel << 4); - } - else - if (im->siz == G_IM_SIZ_8b) - { - texel = pack_ci8(ci1); - *(char *)((int)saddr^flip) = texel; - } - break; - - case (G_IM_FMT_IA): - if (im->siz == G_IM_SIZ_4b) - { - texel = pack_ia4(i1,a1); - *(char *)((int)saddr^flip) |= (s & 0x2)? - (texel): (texel << 4); - } - else - if (im->siz == G_IM_SIZ_8b) - { - texel = pack_ia8(i1,a1); - *(char *)((int)saddr^flip) = texel; - } - else - if (im->siz == G_IM_SIZ_16b) - { - texel = pack_ia16(i1,a1); - *(short *)((int)saddr^flip) = texel; - } - break; - - case (G_IM_FMT_I): - if (im->siz == G_IM_SIZ_4b) - { - texel = pack_i4(i1); - *(char *)((int)saddr^flip) |= (s & 0x2)? - (texel): (texel << 4); - } - else - if (im->siz == G_IM_SIZ_8b) - { - texel = pack_i8(i1); - *(char *)((int)saddr^flip) = texel; - } - break; - } - - tempaddr += txlsize; - - } /* end s */ - - taddr += ((mipmap[level].w * txlsize) >> 1); - - } /* end t */ - - if (mipmap[level].s <= MM_MIN_SIZE && - mipmap[level].t <= MM_MIN_SIZE) - { - max_mipmap = level; - break; - } - } /* end level */ - -}/* end generate mipmap */ -/* - * Add entries for texture loading and rendering in DL - */ -stuffDisplayList(glistp, im, tbuf, startTile, pal, cms, cmt, masks, maskt, shifts, shiftt); - -return errNo; -} /* end guLoadTextureBlockMipMap */ - -/****************************************************************************** - * - * Apply Kernel : - * 1 2 1 - * 2 4 1 - * 1 2 1 - ******************************************************************************/ -static void kernel(int i, int r0, int g0, int b0, int a0, float *r2, float *g2, float *b2, float *a2) -{ - if (i == 8) - { - *r2 += r0*4; *g2 += g0*4; *b2 += b0*4; *a2 += a0*4; - } else - if (i%2 == 0) - { - *r2 += r0*2; - *g2 += g0*2; - *b2 += b0*2; - *a2 += a0*2; - } else - { - *r2 += r0; - *g2 += g0; - *b2 += b0; - *a2 += a0; - } -} - -/******************************************************************** - Add entries for loading and rendering textures into the display list -*********************************************************************/ -static void stuffDisplayList(Gfx **glistp, Image *im, char *tbuf, unsigned char startTile, - unsigned char pal, unsigned char cms, unsigned char cmt, - unsigned char masks, unsigned char maskt, unsigned char shifts, - unsigned char shiftt) -{ - int tile; - int Smask, Tmask; - int Sshift, Tshift; - - /* - * set LOADTILE for loading texture - * 4-bit textures are loaded in 8-bit chunks - */ - if (im->siz == G_IM_SIZ_4b) { - gDPSetTextureImage((*glistp)++, im->fmt, G_IM_SIZ_8b, 1, - osVirtualToPhysical((unsigned short *)tbuf)); - gDPSetTile((*glistp)++, im->fmt, G_IM_SIZ_8b, NA, 0, G_TX_LOADTILE, NA, - NA, NA, NA, NA, NA, NA); - /* Wait until all primitives are done */ - gDPLoadSync((*glistp)++); - gDPLoadBlock((*glistp)++, G_TX_LOADTILE, 0, 0, length/2, 0x0); - } else { - gDPSetTextureImage((*glistp)++, im->fmt, im->siz, 1, - osVirtualToPhysical((unsigned short *)tbuf)); - gDPSetTile((*glistp)++, im->fmt, im->siz, NA, 0, G_TX_LOADTILE, NA, - NA, NA, NA, NA, NA, NA); - /* Wait until all primitives are done */ - gDPLoadSync((*glistp)++); - gDPLoadBlock((*glistp)++, G_TX_LOADTILE, 0, 0, length, 0x0); - } - - for (tile = 0; tile <= level; tile ++) - { - Tmask = maskt-tile; - if (Tmask < 0){ - Tmask = 0; - } else { - Tshift = tile; - } - - Smask = masks-tile; - if (Smask < 0){ - Smask = 0; - } else { - Sshift = tile; - } - -/*** - rmonPrintf("tile, Tmask, Tshift, Smask, Sshift %d %d %d %d %d\n", - tile, Tmask, Tshift, Smask, Sshift); - rmonPrintf("%d\n",startTile); -***/ - - - gDPSetTile((*glistp)++,im->fmt, im->siz, (mipmap[tile].w*txlsize >> 4), - (mipmap[tile].addr >> 3), tile+startTile, pal, cmt, Tmask, Tshift, cms, - Smask, Sshift); - - gDPSetTileSize((*glistp)++,tile+startTile, (0 <> (shift-1)) ^ ((tt & 0x1) << 1)) << 1; - row = (((tt * tile->w + ss) * txlsize) >> 1) / TRAM_LSIZE; - addr = tile->addr + row * TRAM_WSIZE + bank; - - overlap = (i == 0) ? bank : overlap ^ bank; - - switch (size) - { - case G_IM_SIZ_4b: - texel[i] = (tram[addr + ((ss & 0x2) >> 1)] - & (0xf0 >> ((ss & 0x1) << 2))); - if (!(ss & 0x1)) texel[i] = texel[i] >> 4; - break; - - case G_IM_SIZ_8b: - texel[i] = tram[addr + (ss & 0x1)]; - break; - - case G_IM_SIZ_16b: - texel[i] = (tram[addr] << 8) | tram[addr+1]; - break; - - case G_IM_SIZ_32b: - errNo = 2; /* Format not supported */ - break; - - default: - break; - } - - } -} diff --git a/lib/ultralib/src/gu/lookat.c b/lib/ultralib/src/gu/lookat.c deleted file mode 100644 index 1fadc17..0000000 --- a/lib/ultralib/src/gu/lookat.c +++ /dev/null @@ -1,83 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp) -{ - float len, xLook, yLook, zLook, xRight, yRight, zRight; - - guMtxIdentF(mf); - - xLook = xAt - xEye; - yLook = yAt - yEye; - zLook = zAt - zEye; - - /* Negate because positive Z is behind us: */ - len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); - xLook *= len; - yLook *= len; - zLook *= len; - - /* Right = Up x Look */ - - xRight = yUp * zLook - zUp * yLook; - yRight = zUp * xLook - xUp * zLook; - zRight = xUp * yLook - yUp * xLook; - len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); - xRight *= len; - yRight *= len; - zRight *= len; - - /* Up = Look x Right */ - - xUp = yLook * zRight - zLook * yRight; - yUp = zLook * xRight - xLook * zRight; - zUp = xLook * yRight - yLook * xRight; - len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); - xUp *= len; - yUp *= len; - zUp *= len; - - mf[0][0] = xRight; - mf[1][0] = yRight; - mf[2][0] = zRight; - mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); - - mf[0][1] = xUp; - mf[1][1] = yUp; - mf[2][1] = zUp; - mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); - - mf[0][2] = xLook; - mf[1][2] = yLook; - mf[2][2] = zLook; - mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); - - mf[0][3] = 0; - mf[1][3] = 0; - mf[2][3] = 0; - mf[3][3] = 1; -} - -void guLookAt (Mtx *m, float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp) -{ - Matrix mf; - - guLookAtF(mf, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/lookathil.c b/lib/ultralib/src/gu/lookathil.c deleted file mode 100644 index a848688..0000000 --- a/lib/ultralib/src/gu/lookathil.c +++ /dev/null @@ -1,185 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - - -void guLookAtHiliteF(float mf[4][4], LookAt *l, Hilite *h, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, - float xl1, float yl1, float zl1, /* light 1 direction */ - float xl2, float yl2, float zl2, /* light 2 direction */ - int twidth, int theight) /* highlight txtr size*/ -{ - float len, xLook, yLook, zLook, xRight, yRight, zRight; - float xHilite, yHilite, zHilite; - - guMtxIdentF(mf); - - xLook = xAt - xEye; - yLook = yAt - yEye; - zLook = zAt - zEye; - - /* Negate because positive Z is behind us: */ - len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); - xLook *= len; - yLook *= len; - zLook *= len; - - /* Right = Up x Look */ - - xRight = yUp * zLook - zUp * yLook; - yRight = zUp * xLook - xUp * zLook; - zRight = xUp * yLook - yUp * xLook; - len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); - xRight *= len; - yRight *= len; - zRight *= len; - - /* Up = Look x Right */ - - xUp = yLook * zRight - zLook * yRight; - yUp = zLook * xRight - xLook * zRight; - zUp = xLook * yRight - yLook * xRight; - len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); - xUp *= len; - yUp *= len; - zUp *= len; - - /* hilite vectors */ - - len = 1.0 / sqrtf (xl1*xl1 + yl1*yl1 + zl1*zl1); - xl1 *= len; - yl1 *= len; - zl1 *= len; - -#define THRESH2 0.1 - xHilite = xl1 + xLook; - yHilite = yl1 + yLook; - zHilite = zl1 + zLook; - - len = sqrtf (xHilite*xHilite + yHilite*yHilite + zHilite*zHilite); - - if (len>THRESH2) - { - len = 1.0 / len; - xHilite *= len; - yHilite *= len; - zHilite *= len; - - h->h.x1 = - twidth*4 + (xHilite*xRight + - yHilite*yRight + - zHilite*zRight)*twidth*2; - - h->h.y1 = - theight*4 + (xHilite*xUp + - yHilite*yUp + - zHilite*zUp)*theight*2; - } - else - { - h->h.x1 = twidth*2; - h->h.y1 = theight*2; - } - - len = 1.0 / sqrtf (xl2*xl2 + yl2*yl2 + zl2*zl2); - xl2 *= len; - yl2 *= len; - zl2 *= len; - - xHilite = xl2 + xLook; - yHilite = yl2 + yLook; - zHilite = zl2 + zLook; - len = sqrtf (xHilite*xHilite + yHilite*yHilite + zHilite*zHilite); - if (len>THRESH2) - { - len = 1.0 / len; - xHilite *= len; - yHilite *= len; - zHilite *= len; - - h->h.x2 = twidth*4 + - (xHilite*xRight + yHilite*yRight + zHilite*zRight)*twidth*2; - - h->h.y2 = theight*4 + - (xHilite*xUp + yHilite*yUp + zHilite*zUp)*theight*2; - } - else - { - h->h.x2 = twidth*2; - h->h.y2 = theight*2; - } - - /* reflectance vectors = Up and Right */ - - l->l[0].l.dir[0] = FTOFRAC8(xRight); - l->l[0].l.dir[1] = FTOFRAC8(yRight); - l->l[0].l.dir[2] = FTOFRAC8(zRight); - l->l[1].l.dir[0] = FTOFRAC8(xUp); - l->l[1].l.dir[1] = FTOFRAC8(yUp); - l->l[1].l.dir[2] = FTOFRAC8(zUp); - l->l[0].l.col[0] = 0x00; - l->l[0].l.col[1] = 0x00; - l->l[0].l.col[2] = 0x00; - l->l[0].l.pad1 = 0x00; - l->l[0].l.colc[0] = 0x00; - l->l[0].l.colc[1] = 0x00; - l->l[0].l.colc[2] = 0x00; - l->l[0].l.pad2 = 0x00; - l->l[1].l.col[0] = 0x00; - l->l[1].l.col[1] = 0x80; - l->l[1].l.col[2] = 0x00; - l->l[1].l.pad1 = 0x00; - l->l[1].l.colc[0] = 0x00; - l->l[1].l.colc[1] = 0x80; - l->l[1].l.colc[2] = 0x00; - l->l[1].l.pad2 = 0x00; - - mf[0][0] = xRight; - mf[1][0] = yRight; - mf[2][0] = zRight; - mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); - - mf[0][1] = xUp; - mf[1][1] = yUp; - mf[2][1] = zUp; - mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); - - mf[0][2] = xLook; - mf[1][2] = yLook; - mf[2][2] = zLook; - mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); - - mf[0][3] = 0; - mf[1][3] = 0; - mf[2][3] = 0; - mf[3][3] = 1; -} - -void guLookAtHilite (Mtx *m, LookAt *l, Hilite *h, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, - float xl1, float yl1, float zl1, /* light 1 direction */ - float xl2, float yl2, float zl2, /* light 2 direction */ - int twidth, int theight) /* highlight txtr size*/ -{ - Matrix mf; - - guLookAtHiliteF(mf, l, h, xEye, yEye, zEye, xAt, yAt, zAt, - xUp, yUp, zUp, xl1, yl1, zl1, xl2, yl2, zl2, - twidth, theight); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/lookatref.c b/lib/ultralib/src/gu/lookatref.c deleted file mode 100644 index 3cd3b65..0000000 --- a/lib/ultralib/src/gu/lookatref.c +++ /dev/null @@ -1,111 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - - -void guLookAtReflectF(float mf[4][4], LookAt *l, - float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp) -{ - float len, xLook, yLook, zLook, xRight, yRight, zRight; - - guMtxIdentF(mf); - - xLook = xAt - xEye; - yLook = yAt - yEye; - zLook = zAt - zEye; - - /* Negate because positive Z is behind us: */ - len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); - xLook *= len; - yLook *= len; - zLook *= len; - - /* Right = Up x Look */ - - xRight = yUp * zLook - zUp * yLook; - yRight = zUp * xLook - xUp * zLook; - zRight = xUp * yLook - yUp * xLook; - len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); - xRight *= len; - yRight *= len; - zRight *= len; - - /* Up = Look x Right */ - - xUp = yLook * zRight - zLook * yRight; - yUp = zLook * xRight - xLook * zRight; - zUp = xLook * yRight - yLook * xRight; - len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); - xUp *= len; - yUp *= len; - zUp *= len; - - /* reflectance vectors = Up and Right */ - - l->l[0].l.dir[0] = FTOFRAC8(xRight); - l->l[0].l.dir[1] = FTOFRAC8(yRight); - l->l[0].l.dir[2] = FTOFRAC8(zRight); - l->l[1].l.dir[0] = FTOFRAC8(xUp); - l->l[1].l.dir[1] = FTOFRAC8(yUp); - l->l[1].l.dir[2] = FTOFRAC8(zUp); - l->l[0].l.col[0] = 0x00; - l->l[0].l.col[1] = 0x00; - l->l[0].l.col[2] = 0x00; - l->l[0].l.pad1 = 0x00; - l->l[0].l.colc[0] = 0x00; - l->l[0].l.colc[1] = 0x00; - l->l[0].l.colc[2] = 0x00; - l->l[0].l.pad2 = 0x00; - l->l[1].l.col[0] = 0x00; - l->l[1].l.col[1] = 0x80; - l->l[1].l.col[2] = 0x00; - l->l[1].l.pad1 = 0x00; - l->l[1].l.colc[0] = 0x00; - l->l[1].l.colc[1] = 0x80; - l->l[1].l.colc[2] = 0x00; - l->l[1].l.pad2 = 0x00; - - mf[0][0] = xRight; - mf[1][0] = yRight; - mf[2][0] = zRight; - mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); - - mf[0][1] = xUp; - mf[1][1] = yUp; - mf[2][1] = zUp; - mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); - - mf[0][2] = xLook; - mf[1][2] = yLook; - mf[2][2] = zLook; - mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); - - mf[0][3] = 0; - mf[1][3] = 0; - mf[2][3] = 0; - mf[3][3] = 1; -} - -void guLookAtReflect (Mtx *m, LookAt *l, float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp) -{ - float mf[4][4]; - - guLookAtReflectF(mf, l, xEye, yEye, zEye, xAt, yAt, zAt, - xUp, yUp, zUp); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/lookatstereo.c b/lib/ultralib/src/gu/lookatstereo.c deleted file mode 100644 index b60ca08..0000000 --- a/lib/ultralib/src/gu/lookatstereo.c +++ /dev/null @@ -1,111 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guLookAtStereoF(float mf[4][4], float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, float eyedist) -{ - float len, xLook, yLook, zLook, xRight, yRight, zRight; - - guMtxIdentF(mf); - - xLook = xAt - xEye; - yLook = yAt - yEye; - zLook = zAt - zEye; - - /* Negate because positive Z is behind us: */ - len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); - xLook *= len; - yLook *= len; - zLook *= len; - - /* Right = Up x Look */ - - xRight = yUp * zLook - zUp * yLook; - yRight = zUp * xLook - xUp * zLook; - zRight = xUp * yLook - yUp * xLook; - len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); - xRight *= len; - yRight *= len; - zRight *= len; - - /* Move eye for stereo */ - xEye += eyedist*xRight; - yEye += eyedist*yRight; - zEye += eyedist*zRight; - - /* recalculate using new eye */ - xLook = xAt - xEye; - yLook = yAt - yEye; - zLook = zAt - zEye; - - /* Negate because positive Z is behind us: */ - len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); - xLook *= len; - yLook *= len; - zLook *= len; - - /* Right = Up x Look */ - - xRight = yUp * zLook - zUp * yLook; - yRight = zUp * xLook - xUp * zLook; - zRight = xUp * yLook - yUp * xLook; - len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); - xRight *= len; - yRight *= len; - zRight *= len; - - - /* Up = Look x Right */ - - xUp = yLook * zRight - zLook * yRight; - yUp = zLook * xRight - xLook * zRight; - zUp = xLook * yRight - yLook * xRight; - len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); - xUp *= len; - yUp *= len; - zUp *= len; - - mf[0][0] = xRight; - mf[1][0] = yRight; - mf[2][0] = zRight; - mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); - - mf[0][1] = xUp; - mf[1][1] = yUp; - mf[2][1] = zUp; - mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); - - mf[0][2] = xLook; - mf[1][2] = yLook; - mf[2][2] = zLook; - mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); - - mf[0][3] = 0; - mf[1][3] = 0; - mf[2][3] = 0; - mf[3][3] = 1; -} - -void guLookAtStereo (Mtx *m, float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp, float eyedist) -{ - Matrix mf; - - guLookAtStereoF(mf, xEye, yEye, zEye, xAt, yAt, zAt, - xUp, yUp, zUp, eyedist); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/mtxcatf.c b/lib/ultralib/src/gu/mtxcatf.c deleted file mode 100644 index 6572e0f..0000000 --- a/lib/ultralib/src/gu/mtxcatf.c +++ /dev/null @@ -1,63 +0,0 @@ - -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: mtxcatf.c - * Creator: hsa@sgi.com - * Create Date: Thu Nov 2 13:03:02 PST 1995 - * - */ - -#include "guint.h" - -void guMtxCatF(float mf[4][4], float nf[4][4], float res[4][4]) -{ - int i, j, k; - float temp[4][4]; - - for (i=0; i<4; i++) { - for (j=0; j<4; j++) { - temp[i][j] = 0.0; - for (k=0; k<4; k++) { - temp[i][j] += mf[i][k] * nf[k][j]; - } - } - } - - /* make sure we handle case where result is an input */ - for (i=0; i<4; i++) { - for (j=0; j<4; j++) { - res[i][j] = temp[i][j]; - } - } -} - -void guMtxXFMF(float mf[4][4], float x, float y, float z, float *ox, float *oy, float *oz) -{ - *ox = mf[0][0]*x + mf[1][0]*y + mf[2][0]*z + mf[3][0]; - *oy = mf[0][1]*x + mf[1][1]*y + mf[2][1]*z + mf[3][1]; - *oz = mf[0][2]*x + mf[1][2]*y + mf[2][2]*z + mf[3][2]; -} - diff --git a/lib/ultralib/src/gu/mtxcatl.c b/lib/ultralib/src/gu/mtxcatl.c deleted file mode 100644 index 3f165bb..0000000 --- a/lib/ultralib/src/gu/mtxcatl.c +++ /dev/null @@ -1,57 +0,0 @@ - -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: mtxcatl.c - * Creator: hsa@sgi.com - * Create Date: Thu Nov 2 13:03:02 PST 1995 - * - */ - -#include "guint.h" -#include "os_version.h" - -void guMtxCatL(Mtx *m, Mtx *n, Mtx *res) -{ - float mf[4][4], nf[4][4], resf[4][4]; - - guMtxL2F(mf, m); - guMtxL2F(nf, n); - - guMtxCatF(mf, nf, resf); - - guMtxF2L(resf, res); -} - -#if BUILD_VERSION < VERSION_K -void guMtxXFML(Mtx *m, float x, float y, float z, float *ox, float *oy, float *oz) -{ - float mf[4][4]; - - guMtxL2F(mf, m); - - guMtxXFMF(mf, x, y, z, ox, oy, oz); -} -#endif diff --git a/lib/ultralib/src/gu/mtxutil.c b/lib/ultralib/src/gu/mtxutil.c deleted file mode 100644 index 2510558..0000000 --- a/lib/ultralib/src/gu/mtxutil.c +++ /dev/null @@ -1,73 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guMtxF2L(float mf[4][4], Mtx *m) -{ - int i, j; - int e1,e2; - int *ai,*af; - - - ai=(int *) &m->m[0][0]; - af=(int *) &m->m[2][0]; - - for (i=0; i<4; i++) - for (j=0; j<2; j++) { - e1=FTOFIX32(mf[i][j*2]); - e2=FTOFIX32(mf[i][j*2+1]); - *(ai++) = ( e1 & 0xffff0000 ) | ((e2 >> 16)&0xffff); - *(af++) = ((e1 << 16) & 0xffff0000) | (e2 & 0xffff); - } -} - -void guMtxL2F(float mf[4][4], Mtx *m) -{ - int i, j; - unsigned int e1,e2; - unsigned int *ai,*af; - int q1,q2; - - ai=(unsigned int *) &m->m[0][0]; - af=(unsigned int *) &m->m[2][0]; - - for (i=0; i<4; i++) - for (j=0; j<2; j++) { - e1 = (*ai & 0xffff0000) | ((*af >> 16) & 0xffff); - e2 = ((*(ai++) << 16) & 0xffff0000) | (*(af++) & 0xffff); - q1 = *((int *)&e1); - q2 = *((int *)&e2); - - mf[i][j*2] = FIX32TOF(q1); - mf[i][j*2+1] = FIX32TOF(q2); - } -} - -void guMtxIdentF(float mf[4][4]) -{ - int i, j; - - for (i=0; i<4; i++) - for (j=0; j<4; j++) - if (i == j) mf[i][j] = 1.0; - else mf[i][j] = 0.0; -} - -void guMtxIdent(Mtx *m) -{ - float mf[4][4]; - - guMtxIdentF(mf); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/normalize.c b/lib/ultralib/src/gu/normalize.c deleted file mode 100644 index 6884b29..0000000 --- a/lib/ultralib/src/gu/normalize.c +++ /dev/null @@ -1,23 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guNormalize(float *x, float *y, float *z) -{ - float m; - - m = 1/sqrtf((*x)*(*x) + (*y)*(*y) + (*z)*(*z)); - *x *= m; - *y *= m; - *z *= m; -} diff --git a/lib/ultralib/src/gu/ortho.c b/lib/ultralib/src/gu/ortho.c deleted file mode 100644 index 9e52cb3..0000000 --- a/lib/ultralib/src/gu/ortho.c +++ /dev/null @@ -1,41 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guOrthoF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale) -{ - int i, j; - - guMtxIdentF(mf); - - mf[0][0] = 2/(r-l); - mf[1][1] = 2/(t-b); - mf[2][2] = -2/(f-n); - mf[3][0] = -(r+l)/(r-l); - mf[3][1] = -(t+b)/(t-b); - mf[3][2] = -(f+n)/(f-n); - mf[3][3] = 1; - - for (i=0; i<4; i++) - for (j=0; j<4; j++) - mf[i][j] *= scale; -} - -void guOrtho(Mtx *m, float l, float r, float b, float t, float n, float f, float scale) -{ - Matrix mf; - - guOrthoF(mf, l, r, b, t, n, f, scale); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/parse_gbi.c b/lib/ultralib/src/gu/parse_gbi.c deleted file mode 100644 index d736d4a..0000000 --- a/lib/ultralib/src/gu/parse_gbi.c +++ /dev/null @@ -1,139 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - *************************************************************************/ -#include -#include -#include - -#ifndef _FINALROM - -/* - * guParseGbiDL works in conjunction with the dlprint tool. dlprint must be - * running on the host Indy. guParseGbiDL, sends a bunch of blocks of data, - * with a minimum of one display list, but typically, the principle display - * list with a bunch of branched or nested display lists, as well as all the - * vertex and matrix data that will be used. After all the blocks of data - * are sent, a GU_PARSE_READY command is sent, and dlprint parses out the - * data printing it to stdout. - * - * In order to know what data to send, guParseGbiDL must step through the - * display list, find all the gSPDisplayList and gSPBranchList calls, go - * to those lists, and also find and send info for all the matrix and vertex - * calls. - */ -void guParseGbiDL(u64 *gbi_dl, u32 nbytes, u8 flags) -{ - guDLPrintCB cntlBlk; - Gfx* dlStk[11]; - s32 dlcount = 0; - Gfx *curGfx,*dlPtr,*vaddr; - s8 op; - u32 *word0; - u32 *word1; - u32 segments[16]; - u32 param, seg; - u32 paddr,len; - - - cntlBlk.dataSize = nbytes; - cntlBlk.flags = flags; - cntlBlk.dlType = GU_PARSE_GBI_TYPE; - cntlBlk.paddr = osVirtualToPhysical(gbi_dl); - - osWriteHost(&cntlBlk,sizeof(cntlBlk)); - osWriteHost(gbi_dl,nbytes); - - dlStk[0] = (Gfx*)gbi_dl; - while((dlcount >= 0) && (dlcount <= 10)) - { - curGfx = dlStk[dlcount]; /* get the current graphics display list */ - op = *((s8*)curGfx); /* get the first byte */ - dlStk[dlcount]++; /* increment to next gfx command */ - switch(op) - { - case G_MOVEWORD: - word0 = (u32*)curGfx; /* get ptr to first word */ - if(((*word0) & 0x000000ff) == G_MW_SEGMENT) - { - u32 seg; - seg = (((*word0) & 0x00ffff00) >> 8) >> 2; - word1 = word0 + 1; - segments[seg] = *word1; - } - break; - case G_ENDDL: - dlcount--; - break; - case G_DL: - word0 = (u32*)curGfx; /* get ptr to first word */ - param = ((*word0) & 0x00ff0000) >> 16; /* get param */ - word1 = word0 + 1; /* get pointer to second word */ -#if BUILD_VERSION >= VERSION_J - seg = ((*word1) & 0x0f000000) >> 24; /* get the segment */ -#else - seg = ((*word1) & 0xff000000) >> 24; /* get the segment */ -#endif - paddr = segments[seg] + ((*word1) & 0x00ffffff); - vaddr = (Gfx*)osPhysicalToVirtual(paddr); - len = 1; - dlPtr = vaddr; - while((*(s8*)dlPtr) != G_ENDDL) - { - len++; - dlPtr++; - } - len *= sizeof(Gfx); - - cntlBlk.dataSize = len; - cntlBlk.dlType = GU_PARSE_GBI_TYPE; - cntlBlk.paddr = paddr; - - osWriteHost(&cntlBlk,sizeof(cntlBlk)); - osWriteHost((u8*)vaddr,len); - if(param == G_DL_PUSH) - { - if(dlcount < 10) - dlcount++; - else - osSyncPrintf("Display lists nested too deep!!!\n"); - } - dlStk[dlcount] = (Gfx*)vaddr; - break; - case G_VTX: - case G_MOVEMEM: - case G_MTX: - word0 = (u32*)curGfx; /* get ptr to first word */ - word1 = word0 + 1; /* get pointer to second word */ -#if BUILD_VERSION >= VERSION_J - seg = ((*word1) & 0x0f000000) >> 24; /* get the segment */ -#else - seg = ((*word1) & 0xff000000) >> 24; /* get the segment */ -#endif - paddr = segments[seg] + ((*word1) & 0x00ffffff); - vaddr = (Gfx*)osPhysicalToVirtual(paddr); - len = (*word0) & 0x0000ffff; - cntlBlk.dataSize = len; /* always send 32 bytes, the most used */ - cntlBlk.dlType = GU_PARSE_MEM_BLOCK; - cntlBlk.paddr = paddr; - osWriteHost(&cntlBlk,sizeof(cntlBlk)); - osWriteHost((u8*)vaddr,len); - break; - - } - } - - cntlBlk.dlType = GU_PARSE_READY; - osWriteHost(&cntlBlk,sizeof(cntlBlk)); -} - -#endif - diff --git a/lib/ultralib/src/gu/parse_rdp.c b/lib/ultralib/src/gu/parse_rdp.c deleted file mode 100644 index c17c978..0000000 --- a/lib/ultralib/src/gu/parse_rdp.c +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - *************************************************************************/ -#include -#include -#include - -/* guParseRdpDL works in conjunction with dlprint which must be running on - * the host Indy. guParseRdpDL simple uses the hostio routines to send the - * display list to the Indy, and dlprint does all the parsing. - */ - -#ifndef _FINALROM -void guParseRdpDL(u64 *rdp_dl, u64 nbytes, u8 flags) -{ - guDLPrintCB cntlBlk; - - cntlBlk.dataSize = nbytes; - cntlBlk.flags = flags; - cntlBlk.dlType = GU_PARSE_RDP_TYPE; - cntlBlk.paddr = osVirtualToPhysical(rdp_dl); - - osWriteHost(&cntlBlk,sizeof(cntlBlk)); - osWriteHost(rdp_dl,nbytes); - -} - -#endif diff --git a/lib/ultralib/src/gu/parse_string.c b/lib/ultralib/src/gu/parse_string.c deleted file mode 100644 index 71a58a8..0000000 --- a/lib/ultralib/src/gu/parse_string.c +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - *************************************************************************/ -#include -#include -#include - -/* guParseString works in conjunction with dlprint which must be running on - * the host Indy. guParseString simply uses the hostio routines to send the - * string to the Indy, and dlprint does all the parsing. - */ - -#ifndef _FINALROM -void guParseString(char *StringPointer, u64 nbytes) -{ - guDLPrintCB cntlBlk; - - cntlBlk.dataSize = nbytes /* /8 + ((nbytes%8) != 0) */; - cntlBlk.dlType = GU_PARSE_STRING_TYPE; - cntlBlk.paddr = osVirtualToPhysical((u64 *) StringPointer); - - osWriteHost(&cntlBlk,sizeof(cntlBlk)); - osWriteHost((u64 *) StringPointer,nbytes); - -} - -#endif diff --git a/lib/ultralib/src/gu/perspective.c b/lib/ultralib/src/gu/perspective.c deleted file mode 100644 index be571d4..0000000 --- a/lib/ultralib/src/gu/perspective.c +++ /dev/null @@ -1,58 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" -#include - -void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) -{ - float cot; - int i, j; - - guMtxIdentF(mf); - - fovy *= 3.1415926 / 180.0; - cot = cosf (fovy/2) / sinf (fovy/2); - - mf[0][0] = cot / aspect; - mf[1][1] = cot; - mf[2][2] = (near + far) / (near - far); - mf[2][3] = -1; - mf[3][2] = (2 * near * far) / (near - far); - mf[3][3] = 0; - - for (i=0; i<4; i++) - for (j=0; j<4; j++) - mf[i][j] *= scale; - - if (perspNorm != (u16 *) NULL) { - if (near+far<=2.0) { - *perspNorm = (u16) 0xFFFF; - } else { - *perspNorm = (u16) ((2.0*65536.0)/(near+far)); - if (*perspNorm<=0) - *perspNorm = (u16) 0x0001; - } - } -} - -void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) -{ - Matrix mf; - - guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); - - guMtxF2L(mf, m); -} - - diff --git a/lib/ultralib/src/gu/position.c b/lib/ultralib/src/gu/position.c deleted file mode 100644 index 52cdd96..0000000 --- a/lib/ultralib/src/gu/position.c +++ /dev/null @@ -1,73 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* - * Return position matrix given roll, pitch, and yaw in degrees - * plus scale and position. - * - * r = roll (degrees) - * p = pitch (degrees) - * h = yaw (degrees) - * s = scale - * x,y,z = position (world coordinates) - * - */ - -void guPositionF(float mf[4][4], float r, float p, float h, float s, - float x, float y, float z) -{ - static float dtor = 3.1415926 / 180.0; - float sinr, sinp, sinh; - float cosr, cosp, cosh; - - r *= dtor; - p *= dtor; - h *= dtor; - sinr = sinf(r); - cosr = cosf(r); - sinp = sinf(p); - cosp = cosf(p); - sinh = sinf(h); - cosh = cosf(h); - - mf[0][0] = (cosp*cosh) * s; - mf[0][1] = (cosp*sinh) * s; - mf[0][2] = (-sinp) * s; - mf[0][3] = 0.0; - - mf[1][0] = (sinr*sinp*cosh - cosr*sinh) * s; - mf[1][1] = (sinr*sinp*sinh + cosr*cosh) * s; - mf[1][2] = (sinr*cosp) * s; - mf[1][3] = 0.0; - - mf[2][0] = (cosr*sinp*cosh + sinr*sinh) * s; - mf[2][1] = (cosr*sinp*sinh - sinr*cosh) * s; - mf[2][2] = (cosr*cosp) * s; - mf[2][3] = 0.0; - - mf[3][0] = x; - mf[3][1] = y; - mf[3][2] = z; - mf[3][3] = 1.0; -} - -void guPosition(Mtx *m, float r, float p, float h, float s, - float x, float y, float z) -{ - float mf[4][4]; - - guPositionF(mf, r, p, h, s, x, y, z); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/poslight.c b/lib/ultralib/src/gu/poslight.c deleted file mode 100644 index 389a04d..0000000 --- a/lib/ultralib/src/gu/poslight.c +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - - -/* - * define a positional light. - * this function must be called anytime the light or object moves. - * - * pl = (input) positional light description. - * l = (output) directiona light description for gSPLight or gSPSetLightsN. - * *Ob = position of (center of) object to be lit. - * - */ -#define THRESH1 0.01 -#define THRESH2 0.1 -void guPosLight(PositionalLight *pl, Light *l, - float xOb, float yOb, float zOb) -{ - float x,y,z,d,a; - - - x = pl->pos[0]-xOb; - y = pl->pos[1]-yOb; - z = pl->pos[2]-zOb; - d = sqrtf(x*x + y*y + z*z); - - a = d*pl->a1 + pl->a2; - if (al.dir[0] = 0; - l->l.dir[1] = 0; - l->l.dir[2] = -120; - - l->l.col[0] = 0; - l->l.col[1] = 0; - l->l.col[2] = 0; - l->l.colc[0] = 0; - l->l.colc[1] = 0; - l->l.colc[2] = 0; - } else { - d = 1/d; - l->l.dir[0] = 120.0*x*d; - l->l.dir[1] = 120.0*y*d; - l->l.dir[2] = 120.0*z*d; - - l->l.col[0] = pl->col[0]*a; - l->l.col[1] = pl->col[1]*a; - l->l.col[2] = pl->col[2]*a; - l->l.colc[0] = pl->col[0]*a; - l->l.colc[1] = pl->col[1]*a; - l->l.colc[2] = pl->col[2]*a; - } - -} diff --git a/lib/ultralib/src/gu/poslighthil.c b/lib/ultralib/src/gu/poslighthil.c deleted file mode 100644 index 259fe8c..0000000 --- a/lib/ultralib/src/gu/poslighthil.c +++ /dev/null @@ -1,168 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - - -/* - * define 2 positional lights with highlights. - * this function must be called anytime the viewpoint, light or object moves. - * - * pl1 = (input) positional light#1 description. - * pl2 = (input) positional light#2 description. - * l1 = (output) directional light desc. #1 for gSPLight or gSPSetLightsN. - * l2 = (output) directional light desc. #2 for gSPLight or gSPSetLightsN. - * *Eye = position of eye (viewpoint). (usually same as in LookAt command.) - * *Ob = position of (center of) object to be lit. - * *Ob = up vector (usually same as in LookAt command). - * twidth = width of texture map used for highlight. - * theight = height of texture map used for highlight. - * - */ -#define THRESH2 0.01 -#define THRESH3 0.1 -void guPosLightHilite(PositionalLight *pl1, PositionalLight *pl2, - Light *l1, Light *l2, - LookAt *l, Hilite *h, - float xEye, float yEye, float zEye, - float xOb, float yOb, float zOb, - float xUp, float yUp, float zUp, - int twidth, int theight) /* hilite txtr size*/ -{ - float x,y,z,d,a; - Mtx m; - - -/* - * light 1, diffuse - */ - x = pl1->pos[0]-xOb; - y = pl1->pos[1]-yOb; - z = pl1->pos[2]-zOb; - d = sqrtf(x*x + y*y + z*z); - - a=d*pl1->a1 + pl1->a2; - if (al.dir[0] = 0; - l1->l.dir[1] = 0; - l1->l.dir[2] = -120; - - l1->l.col[0] = 0; - l1->l.col[1] = 0; - l1->l.col[2] = 0; - l1->l.colc[0] = 0; - l1->l.colc[1] = 0; - l1->l.colc[2] = 0; - } else { - d = 1/d; - l1->l.dir[0] = 120.0*x*d; - l1->l.dir[1] = 120.0*y*d; - l1->l.dir[2] = 120.0*z*d; - - l1->l.col[0] = pl1->col[0]*a; - l1->l.col[1] = pl1->col[1]*a; - l1->l.col[2] = pl1->col[2]*a; - l1->l.colc[0] = pl1->col[0]*a; - l1->l.colc[1] = pl1->col[1]*a; - l1->l.colc[2] = pl1->col[2]*a; - } - - -/* - * light 2, diffuse - */ - x = pl2->pos[0]-xOb; - y = pl2->pos[1]-yOb; - z = pl2->pos[2]-zOb; - d = sqrtf(x*x + y*y + z*z); - - a = d*pl2->a1 + pl2->a2; - if (al.dir[0] = 0; - l2->l.dir[1] = 0; - l2->l.dir[2] = -120; - - l2->l.col[0] = 0; - l2->l.col[1] = 0; - l2->l.col[2] = 0; - l2->l.colc[0] = 0; - l2->l.colc[1] = 0; - l2->l.colc[2] = 0; - } else { - d = 1/d; - l2->l.dir[0] = 120.0*x*d; - l2->l.dir[1] = 120.0*y*d; - l2->l.dir[2] = 120.0*z*d; - - l2->l.col[0] = pl2->col[0]*a; - l2->l.col[1] = pl2->col[1]*a; - l2->l.col[2] = pl2->col[2]*a; - l2->l.colc[0] = pl2->col[0]*a; - l2->l.colc[1] = pl2->col[1]*a; - l2->l.colc[2] = pl2->col[2]*a; - } - - -/* - * Hilight factors - */ - x = xOb-xEye; - y = yOb-yEye; - z = zOb-zEye; - if (sqrtf(x*x + y*y + z*z)h.x1 = twidth*2; - h->h.y1 = twidth*2; - h->h.x2 = twidth*2; - h->h.y2 = twidth*2; - l->l[0].l.dir[0] = 0; - l->l[0].l.dir[1] = 0; - l->l[0].l.dir[2] = 0; - l->l[1].l.dir[0] = 0; - l->l[1].l.dir[1] = 0; - l->l[1].l.dir[2] = 0; - l->l[0].l.col[0] = 0x00; - l->l[0].l.col[1] = 0x00; - l->l[0].l.col[2] = 0x00; - l->l[0].l.pad1 = 0x00; - l->l[0].l.colc[0] = 0x00; - l->l[0].l.colc[1] = 0x00; - l->l[0].l.colc[2] = 0x00; - l->l[0].l.pad2 = 0x00; - l->l[1].l.col[0] = 0x00; - l->l[1].l.col[1] = 0x80; - l->l[1].l.col[2] = 0x00; - l->l[1].l.pad1 = 0x00; - l->l[1].l.colc[0] = 0x00; - l->l[1].l.colc[1] = 0x80; - l->l[1].l.colc[2] = 0x00; - l->l[1].l.pad2 = 0x00; - } else { - guLookAtHilite(&m, l, h, - xEye, yEye, zEye, - xOb, yOb, zOb, - xUp, yUp, zUp, - l1->l.dir[0], l1->l.dir[1], l1->l.dir[2], - l2->l.dir[0], l2->l.dir[1], l2->l.dir[2], - twidth, theight); - } -} - diff --git a/lib/ultralib/src/gu/random.c b/lib/ultralib/src/gu/random.c deleted file mode 100644 index 32cfde3..0000000 --- a/lib/ultralib/src/gu/random.c +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* - * Return a pseudorandom 32 bit number - * try the RAND macro too - * - */ -int guRandom(void) -{ - static unsigned int xseed = 174823885; - unsigned int x; - - x = (xseed<<2) + 2; - - x *= (x+1); - x = x >> 2; - - xseed = x; - - return( x ); -} diff --git a/lib/ultralib/src/gu/readme.txt b/lib/ultralib/src/gu/readme.txt deleted file mode 100644 index 114174e..0000000 --- a/lib/ultralib/src/gu/readme.txt +++ /dev/null @@ -1,17 +0,0 @@ -Among the gu Functions, the following were replaced with the newly -created high speed versions. With the current version OS they are -not being used. - -guMtxIdent -guMtxIdentF -guScale -guScaleF -guNormalize -guTranslate -guTranslateF -guMtxF2L -guRotateF -guMtxL2F -guMtxCatF - -The newly created functions are installed in the mgu directory. diff --git a/lib/ultralib/src/gu/rotate.c b/lib/ultralib/src/gu/rotate.c deleted file mode 100644 index c843d9f..0000000 --- a/lib/ultralib/src/gu/rotate.c +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" -#include "os_version.h" - -void guRotateF(float mf[4][4], float a, float x, float y, float z) -{ - static float dtor = 3.1415926 / 180.0; - float sine; - float cosine; - float ab, bc, ca, t; -#if BUILD_VERSION >= VERSION_K - float xxsine; - float yxsine; - float zxsine; -#endif - - guNormalize(&x, &y, &z); - a *= dtor; - sine = sinf(a); - cosine = cosf(a); - t = (1-cosine); - ab = x*y*t; - bc = y*z*t; - ca = z*x*t; - - guMtxIdentF(mf); - -#if BUILD_VERSION >= VERSION_K - xxsine = x * sine; - yxsine = y * sine; - zxsine = z * sine; -#else - #define xxsine (x * sine) - #define yxsine (y * sine) - #define zxsine (z * sine) -#endif - - t = x*x; - mf[0][0] = t+cosine*(1-t); - mf[2][1] = bc-xxsine; - mf[1][2] = bc+xxsine; - - t = y*y; - mf[1][1] = t+cosine*(1-t); - mf[2][0] = ca+yxsine; - mf[0][2] = ca-yxsine; - - t = z*z; - mf[2][2] = t+cosine*(1-t); - mf[1][0] = ab-zxsine; - mf[0][1] = ab+zxsine; -} - -void guRotate(Mtx *m, float a, float x, float y, float z) -{ - Matrix mf; - - guRotateF(mf, a, x, y, z); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/rotaterpy.c b/lib/ultralib/src/gu/rotaterpy.c deleted file mode 100644 index c239d21..0000000 --- a/lib/ultralib/src/gu/rotaterpy.c +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* - * Return rotation matrix given roll, pitch, and yaw in degrees - * - */ - -void guRotateRPYF(float mf[4][4], float r, float p, float h) -{ - static float dtor = 3.1415926 / 180.0; - float sinr, sinp, sinh; - float cosr, cosp, cosh; - - r *= dtor; - p *= dtor; - h *= dtor; - sinr = sinf(r); - cosr = cosf(r); - sinp = sinf(p); - cosp = cosf(p); - sinh = sinf(h); - cosh = cosf(h); - - guMtxIdentF(mf); - - mf[0][0] = cosp*cosh; - mf[0][1] = cosp*sinh; - mf[0][2] = -sinp; - - mf[1][0] = sinr*sinp*cosh - cosr*sinh; - mf[1][1] = sinr*sinp*sinh + cosr*cosh; - mf[1][2] = sinr*cosp; - - mf[2][0] = cosr*sinp*cosh + sinr*sinh; - mf[2][1] = cosr*sinp*sinh - sinr*cosh; - mf[2][2] = cosr*cosp; -} - -void guRotateRPY(Mtx *m, float r, float p, float h) -{ - Matrix mf; - - guRotateRPYF(mf, r, p, h); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/scale.c b/lib/ultralib/src/gu/scale.c deleted file mode 100644 index 1523cd0..0000000 --- a/lib/ultralib/src/gu/scale.c +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guScaleF(float mf[4][4], float x, float y, float z) -{ - guMtxIdentF(mf); - - mf[0][0] = x; - mf[1][1] = y; - mf[2][2] = z; - mf[3][3] = 1; -} - -void guScale(Mtx *m, float x, float y, float z) -{ - Matrix mf; - - guScaleF(mf, x, y, z); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/sinf.c b/lib/ultralib/src/gu/sinf.c deleted file mode 100644 index f4bb1ad..0000000 --- a/lib/ultralib/src/gu/sinf.c +++ /dev/null @@ -1,157 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* ==================================================================== - * ==================================================================== - * - * Module: fsin.c - * $Revision: 1.3 $ - * $Date: 1998/10/09 06:14:51 $ - * $Author: has $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/sinf.c,v $ - * - * Revision history: - * 09-Jun-93 - Original Version - * - * Description: source code for fsin function - * - * ==================================================================== - * ==================================================================== - */ - -#pragma weak fsin = __sinf -#pragma weak sinf = __sinf -#define fsin __sinf - -/* coefficients for polynomial approximation of sin on +/- pi/2 */ - -static const du P[] = -{ -{0x3ff00000, 0x00000000}, -{0xbfc55554, 0xbc83656d}, -{0x3f8110ed, 0x3804c2a0}, -{0xbf29f6ff, 0xeea56814}, -{0x3ec5dbdf, 0x0e314bfe}, -}; - -static const du rpi = -{0x3fd45f30, 0x6dc9c883}; - -static const du pihi = -{0x400921fb, 0x50000000}; - -static const du pilo = -{0x3e6110b4, 0x611a6263}; - -static const fu zero = {0x00000000}; - - -/* ==================================================================== - * - * FunctionName fsin - * - * Description computes sine of arg - * - * ==================================================================== - */ - -float -fsin( float x ) -{ -double dx, xsq, poly; -double dn; -int n; -double result; -int ix, xpt; - - - ix = *(int *)&x; - xpt = (ix >> 22); - xpt &= 0x1ff; - - /* xpt is exponent(x) + 1 bit of mantissa */ - - if ( xpt < 0xff ) - { - /* |x| < 1.5 */ - - dx = x; - - if ( xpt >= 0xe6 ) - { - /* |x| >= 2^(-12) */ - - /* compute sin(x) with a standard polynomial approximation */ - - xsq = dx*dx; - - poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; - - result = dx + (dx*xsq)*poly; - - return ( (float)result ); - } - - return ( x ); - } - - if ( xpt < 0x136 ) - { - /* |x| < 2^28 */ - - dx = x; - - /* reduce argument to +/- pi/2 */ - - dn = dx*rpi.d; - - n = ROUND(dn); - dn = n; - - dx = dx - dn*pihi.d; - dx = dx - dn*pilo.d; /* dx = x - n*pi */ - - /* compute sin(dx) as before, negating result if n is odd - */ - - xsq = dx*dx; - - poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; - - result = dx + (dx*xsq)*poly; - - - if ( (n & 1) == 0 ) - return ( (float)result ); - - return ( -(float)result ); - } - - if ( x != x ) - { - /* x is a NaN; return a quiet NaN */ - -#ifdef _IP_NAN_SETS_ERRNO - - *__errnoaddr = EDOM; -#endif - - return ( __libm_qnan_f ); - } - - /* just give up and return 0.0 */ - - return ( zero.f ); -} - diff --git a/lib/ultralib/src/gu/sins.c b/lib/ultralib/src/gu/sins.c deleted file mode 100644 index b24851f..0000000 --- a/lib/ultralib/src/gu/sins.c +++ /dev/null @@ -1,61 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -/* ==================================================================== - * ==================================================================== - * - * Module: sins.c - * $Revision: 1.3 $ - * $Date: 1998/10/09 06:15:00 $ - * $Author: has $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/sins.c,v $ - * - * ==================================================================== - * ==================================================================== - */ - -/* coefficients for polynomial approximation of sin on +/- pi/2 */ - -/* ==================================================================== - * - * FunctionName sins - * - * Description computes sine of arg - * - * ==================================================================== - */ - -#include "sintable.h" - -signed short -sins( unsigned short x ) -{ - /* 0 <= x < 0x10000 ==> 0 <= x < 2PI */ - - signed short val; - - x >>= 4; /* Now range 0 <= x < 0x1000 */ - - if (x & 0x400) { - val = sintable[0x3ff - (x & 0x3ff)]; - } else { - val = sintable[x & 0x3ff]; - } - - if (x & 0x800) { - return -val; - } else { - return val; - } -} diff --git a/lib/ultralib/src/gu/sintable.h b/lib/ultralib/src/gu/sintable.h deleted file mode 100644 index b5e1a45..0000000 --- a/lib/ultralib/src/gu/sintable.h +++ /dev/null @@ -1,1031 +0,0 @@ - -/* - * Do not edit this file -- it was generated by "maketable". - */ - -static signed short sintable[0x400] = { - 0x0000, - 0x0032, - 0x0064, - 0x0096, - 0x00c9, - 0x00fb, - 0x012d, - 0x0160, - 0x0192, - 0x01c4, - 0x01f7, - 0x0229, - 0x025b, - 0x028e, - 0x02c0, - 0x02f2, - 0x0324, - 0x0357, - 0x0389, - 0x03bb, - 0x03ee, - 0x0420, - 0x0452, - 0x0484, - 0x04b7, - 0x04e9, - 0x051b, - 0x054e, - 0x0580, - 0x05b2, - 0x05e4, - 0x0617, - 0x0649, - 0x067b, - 0x06ad, - 0x06e0, - 0x0712, - 0x0744, - 0x0776, - 0x07a9, - 0x07db, - 0x080d, - 0x083f, - 0x0871, - 0x08a4, - 0x08d6, - 0x0908, - 0x093a, - 0x096c, - 0x099f, - 0x09d1, - 0x0a03, - 0x0a35, - 0x0a67, - 0x0a99, - 0x0acb, - 0x0afe, - 0x0b30, - 0x0b62, - 0x0b94, - 0x0bc6, - 0x0bf8, - 0x0c2a, - 0x0c5c, - 0x0c8e, - 0x0cc0, - 0x0cf2, - 0x0d25, - 0x0d57, - 0x0d89, - 0x0dbb, - 0x0ded, - 0x0e1f, - 0x0e51, - 0x0e83, - 0x0eb5, - 0x0ee7, - 0x0f19, - 0x0f4b, - 0x0f7c, - 0x0fae, - 0x0fe0, - 0x1012, - 0x1044, - 0x1076, - 0x10a8, - 0x10da, - 0x110c, - 0x113e, - 0x116f, - 0x11a1, - 0x11d3, - 0x1205, - 0x1237, - 0x1269, - 0x129a, - 0x12cc, - 0x12fe, - 0x1330, - 0x1361, - 0x1393, - 0x13c5, - 0x13f6, - 0x1428, - 0x145a, - 0x148c, - 0x14bd, - 0x14ef, - 0x1520, - 0x1552, - 0x1584, - 0x15b5, - 0x15e7, - 0x1618, - 0x164a, - 0x167b, - 0x16ad, - 0x16df, - 0x1710, - 0x1741, - 0x1773, - 0x17a4, - 0x17d6, - 0x1807, - 0x1839, - 0x186a, - 0x189b, - 0x18cd, - 0x18fe, - 0x1930, - 0x1961, - 0x1992, - 0x19c3, - 0x19f5, - 0x1a26, - 0x1a57, - 0x1a88, - 0x1aba, - 0x1aeb, - 0x1b1c, - 0x1b4d, - 0x1b7e, - 0x1baf, - 0x1be1, - 0x1c12, - 0x1c43, - 0x1c74, - 0x1ca5, - 0x1cd6, - 0x1d07, - 0x1d38, - 0x1d69, - 0x1d9a, - 0x1dcb, - 0x1dfc, - 0x1e2d, - 0x1e5d, - 0x1e8e, - 0x1ebf, - 0x1ef0, - 0x1f21, - 0x1f52, - 0x1f82, - 0x1fb3, - 0x1fe4, - 0x2015, - 0x2045, - 0x2076, - 0x20a7, - 0x20d7, - 0x2108, - 0x2139, - 0x2169, - 0x219a, - 0x21ca, - 0x21fb, - 0x222b, - 0x225c, - 0x228c, - 0x22bd, - 0x22ed, - 0x231d, - 0x234e, - 0x237e, - 0x23ae, - 0x23df, - 0x240f, - 0x243f, - 0x2470, - 0x24a0, - 0x24d0, - 0x2500, - 0x2530, - 0x2560, - 0x2591, - 0x25c1, - 0x25f1, - 0x2621, - 0x2651, - 0x2681, - 0x26b1, - 0x26e1, - 0x2711, - 0x2740, - 0x2770, - 0x27a0, - 0x27d0, - 0x2800, - 0x2830, - 0x285f, - 0x288f, - 0x28bf, - 0x28ee, - 0x291e, - 0x294e, - 0x297d, - 0x29ad, - 0x29dd, - 0x2a0c, - 0x2a3c, - 0x2a6b, - 0x2a9b, - 0x2aca, - 0x2af9, - 0x2b29, - 0x2b58, - 0x2b87, - 0x2bb7, - 0x2be6, - 0x2c15, - 0x2c44, - 0x2c74, - 0x2ca3, - 0x2cd2, - 0x2d01, - 0x2d30, - 0x2d5f, - 0x2d8e, - 0x2dbd, - 0x2dec, - 0x2e1b, - 0x2e4a, - 0x2e79, - 0x2ea8, - 0x2ed7, - 0x2f06, - 0x2f34, - 0x2f63, - 0x2f92, - 0x2fc0, - 0x2fef, - 0x301e, - 0x304c, - 0x307b, - 0x30a9, - 0x30d8, - 0x3107, - 0x3135, - 0x3163, - 0x3192, - 0x31c0, - 0x31ef, - 0x321d, - 0x324b, - 0x3279, - 0x32a8, - 0x32d6, - 0x3304, - 0x3332, - 0x3360, - 0x338e, - 0x33bc, - 0x33ea, - 0x3418, - 0x3446, - 0x3474, - 0x34a2, - 0x34d0, - 0x34fe, - 0x352b, - 0x3559, - 0x3587, - 0x35b5, - 0x35e2, - 0x3610, - 0x363d, - 0x366b, - 0x3698, - 0x36c6, - 0x36f3, - 0x3721, - 0x374e, - 0x377c, - 0x37a9, - 0x37d6, - 0x3803, - 0x3831, - 0x385e, - 0x388b, - 0x38b8, - 0x38e5, - 0x3912, - 0x393f, - 0x396c, - 0x3999, - 0x39c6, - 0x39f3, - 0x3a20, - 0x3a4d, - 0x3a79, - 0x3aa6, - 0x3ad3, - 0x3b00, - 0x3b2c, - 0x3b59, - 0x3b85, - 0x3bb2, - 0x3bde, - 0x3c0b, - 0x3c37, - 0x3c64, - 0x3c90, - 0x3cbc, - 0x3ce9, - 0x3d15, - 0x3d41, - 0x3d6d, - 0x3d99, - 0x3dc5, - 0x3df1, - 0x3e1d, - 0x3e49, - 0x3e75, - 0x3ea1, - 0x3ecd, - 0x3ef9, - 0x3f25, - 0x3f50, - 0x3f7c, - 0x3fa8, - 0x3fd3, - 0x3fff, - 0x402b, - 0x4056, - 0x4082, - 0x40ad, - 0x40d8, - 0x4104, - 0x412f, - 0x415a, - 0x4186, - 0x41b1, - 0x41dc, - 0x4207, - 0x4232, - 0x425d, - 0x4288, - 0x42b3, - 0x42de, - 0x4309, - 0x4334, - 0x435f, - 0x4389, - 0x43b4, - 0x43df, - 0x4409, - 0x4434, - 0x445f, - 0x4489, - 0x44b4, - 0x44de, - 0x4508, - 0x4533, - 0x455d, - 0x4587, - 0x45b1, - 0x45dc, - 0x4606, - 0x4630, - 0x465a, - 0x4684, - 0x46ae, - 0x46d8, - 0x4702, - 0x472c, - 0x4755, - 0x477f, - 0x47a9, - 0x47d2, - 0x47fc, - 0x4826, - 0x484f, - 0x4879, - 0x48a2, - 0x48cc, - 0x48f5, - 0x491e, - 0x4948, - 0x4971, - 0x499a, - 0x49c3, - 0x49ec, - 0x4a15, - 0x4a3e, - 0x4a67, - 0x4a90, - 0x4ab9, - 0x4ae2, - 0x4b0b, - 0x4b33, - 0x4b5c, - 0x4b85, - 0x4bad, - 0x4bd6, - 0x4bfe, - 0x4c27, - 0x4c4f, - 0x4c78, - 0x4ca0, - 0x4cc8, - 0x4cf0, - 0x4d19, - 0x4d41, - 0x4d69, - 0x4d91, - 0x4db9, - 0x4de1, - 0x4e09, - 0x4e31, - 0x4e58, - 0x4e80, - 0x4ea8, - 0x4ed0, - 0x4ef7, - 0x4f1f, - 0x4f46, - 0x4f6e, - 0x4f95, - 0x4fbd, - 0x4fe4, - 0x500b, - 0x5032, - 0x505a, - 0x5081, - 0x50a8, - 0x50cf, - 0x50f6, - 0x511d, - 0x5144, - 0x516b, - 0x5191, - 0x51b8, - 0x51df, - 0x5205, - 0x522c, - 0x5253, - 0x5279, - 0x52a0, - 0x52c6, - 0x52ec, - 0x5313, - 0x5339, - 0x535f, - 0x5385, - 0x53ab, - 0x53d1, - 0x53f7, - 0x541d, - 0x5443, - 0x5469, - 0x548f, - 0x54b5, - 0x54da, - 0x5500, - 0x5525, - 0x554b, - 0x5571, - 0x5596, - 0x55bb, - 0x55e1, - 0x5606, - 0x562b, - 0x5650, - 0x5675, - 0x569b, - 0x56c0, - 0x56e5, - 0x5709, - 0x572e, - 0x5753, - 0x5778, - 0x579d, - 0x57c1, - 0x57e6, - 0x580a, - 0x582f, - 0x5853, - 0x5878, - 0x589c, - 0x58c0, - 0x58e5, - 0x5909, - 0x592d, - 0x5951, - 0x5975, - 0x5999, - 0x59bd, - 0x59e1, - 0x5a04, - 0x5a28, - 0x5a4c, - 0x5a6f, - 0x5a93, - 0x5ab7, - 0x5ada, - 0x5afd, - 0x5b21, - 0x5b44, - 0x5b67, - 0x5b8b, - 0x5bae, - 0x5bd1, - 0x5bf4, - 0x5c17, - 0x5c3a, - 0x5c5d, - 0x5c7f, - 0x5ca2, - 0x5cc5, - 0x5ce7, - 0x5d0a, - 0x5d2d, - 0x5d4f, - 0x5d71, - 0x5d94, - 0x5db6, - 0x5dd8, - 0x5dfa, - 0x5e1d, - 0x5e3f, - 0x5e61, - 0x5e83, - 0x5ea5, - 0x5ec6, - 0x5ee8, - 0x5f0a, - 0x5f2c, - 0x5f4d, - 0x5f6f, - 0x5f90, - 0x5fb2, - 0x5fd3, - 0x5ff4, - 0x6016, - 0x6037, - 0x6058, - 0x6079, - 0x609a, - 0x60bb, - 0x60dc, - 0x60fd, - 0x611e, - 0x613e, - 0x615f, - 0x6180, - 0x61a0, - 0x61c1, - 0x61e1, - 0x6202, - 0x6222, - 0x6242, - 0x6263, - 0x6283, - 0x62a3, - 0x62c3, - 0x62e3, - 0x6303, - 0x6323, - 0x6342, - 0x6362, - 0x6382, - 0x63a1, - 0x63c1, - 0x63e0, - 0x6400, - 0x641f, - 0x643f, - 0x645e, - 0x647d, - 0x649c, - 0x64bb, - 0x64da, - 0x64f9, - 0x6518, - 0x6537, - 0x6556, - 0x6574, - 0x6593, - 0x65b2, - 0x65d0, - 0x65ef, - 0x660d, - 0x662b, - 0x664a, - 0x6668, - 0x6686, - 0x66a4, - 0x66c2, - 0x66e0, - 0x66fe, - 0x671c, - 0x673a, - 0x6757, - 0x6775, - 0x6792, - 0x67b0, - 0x67cd, - 0x67eb, - 0x6808, - 0x6825, - 0x6843, - 0x6860, - 0x687d, - 0x689a, - 0x68b7, - 0x68d4, - 0x68f1, - 0x690d, - 0x692a, - 0x6947, - 0x6963, - 0x6980, - 0x699c, - 0x69b9, - 0x69d5, - 0x69f1, - 0x6a0e, - 0x6a2a, - 0x6a46, - 0x6a62, - 0x6a7e, - 0x6a9a, - 0x6ab5, - 0x6ad1, - 0x6aed, - 0x6b08, - 0x6b24, - 0x6b40, - 0x6b5b, - 0x6b76, - 0x6b92, - 0x6bad, - 0x6bc8, - 0x6be3, - 0x6bfe, - 0x6c19, - 0x6c34, - 0x6c4f, - 0x6c6a, - 0x6c84, - 0x6c9f, - 0x6cba, - 0x6cd4, - 0x6cef, - 0x6d09, - 0x6d23, - 0x6d3e, - 0x6d58, - 0x6d72, - 0x6d8c, - 0x6da6, - 0x6dc0, - 0x6dda, - 0x6df3, - 0x6e0d, - 0x6e27, - 0x6e40, - 0x6e5a, - 0x6e73, - 0x6e8d, - 0x6ea6, - 0x6ebf, - 0x6ed9, - 0x6ef2, - 0x6f0b, - 0x6f24, - 0x6f3d, - 0x6f55, - 0x6f6e, - 0x6f87, - 0x6fa0, - 0x6fb8, - 0x6fd1, - 0x6fe9, - 0x7002, - 0x701a, - 0x7032, - 0x704a, - 0x7062, - 0x707a, - 0x7092, - 0x70aa, - 0x70c2, - 0x70da, - 0x70f2, - 0x7109, - 0x7121, - 0x7138, - 0x7150, - 0x7167, - 0x717e, - 0x7196, - 0x71ad, - 0x71c4, - 0x71db, - 0x71f2, - 0x7209, - 0x7220, - 0x7236, - 0x724d, - 0x7264, - 0x727a, - 0x7291, - 0x72a7, - 0x72bd, - 0x72d4, - 0x72ea, - 0x7300, - 0x7316, - 0x732c, - 0x7342, - 0x7358, - 0x736e, - 0x7383, - 0x7399, - 0x73ae, - 0x73c4, - 0x73d9, - 0x73ef, - 0x7404, - 0x7419, - 0x742e, - 0x7443, - 0x7458, - 0x746d, - 0x7482, - 0x7497, - 0x74ac, - 0x74c0, - 0x74d5, - 0x74ea, - 0x74fe, - 0x7512, - 0x7527, - 0x753b, - 0x754f, - 0x7563, - 0x7577, - 0x758b, - 0x759f, - 0x75b3, - 0x75c7, - 0x75da, - 0x75ee, - 0x7601, - 0x7615, - 0x7628, - 0x763b, - 0x764f, - 0x7662, - 0x7675, - 0x7688, - 0x769b, - 0x76ae, - 0x76c1, - 0x76d3, - 0x76e6, - 0x76f9, - 0x770b, - 0x771e, - 0x7730, - 0x7742, - 0x7754, - 0x7767, - 0x7779, - 0x778b, - 0x779d, - 0x77af, - 0x77c0, - 0x77d2, - 0x77e4, - 0x77f5, - 0x7807, - 0x7818, - 0x782a, - 0x783b, - 0x784c, - 0x785d, - 0x786e, - 0x787f, - 0x7890, - 0x78a1, - 0x78b2, - 0x78c3, - 0x78d3, - 0x78e4, - 0x78f4, - 0x7905, - 0x7915, - 0x7925, - 0x7936, - 0x7946, - 0x7956, - 0x7966, - 0x7976, - 0x7985, - 0x7995, - 0x79a5, - 0x79b5, - 0x79c4, - 0x79d4, - 0x79e3, - 0x79f2, - 0x7a02, - 0x7a11, - 0x7a20, - 0x7a2f, - 0x7a3e, - 0x7a4d, - 0x7a5b, - 0x7a6a, - 0x7a79, - 0x7a87, - 0x7a96, - 0x7aa4, - 0x7ab3, - 0x7ac1, - 0x7acf, - 0x7add, - 0x7aeb, - 0x7af9, - 0x7b07, - 0x7b15, - 0x7b23, - 0x7b31, - 0x7b3e, - 0x7b4c, - 0x7b59, - 0x7b67, - 0x7b74, - 0x7b81, - 0x7b8e, - 0x7b9b, - 0x7ba8, - 0x7bb5, - 0x7bc2, - 0x7bcf, - 0x7bdc, - 0x7be8, - 0x7bf5, - 0x7c02, - 0x7c0e, - 0x7c1a, - 0x7c27, - 0x7c33, - 0x7c3f, - 0x7c4b, - 0x7c57, - 0x7c63, - 0x7c6f, - 0x7c7a, - 0x7c86, - 0x7c92, - 0x7c9d, - 0x7ca9, - 0x7cb4, - 0x7cbf, - 0x7ccb, - 0x7cd6, - 0x7ce1, - 0x7cec, - 0x7cf7, - 0x7d02, - 0x7d0c, - 0x7d17, - 0x7d22, - 0x7d2c, - 0x7d37, - 0x7d41, - 0x7d4b, - 0x7d56, - 0x7d60, - 0x7d6a, - 0x7d74, - 0x7d7e, - 0x7d88, - 0x7d91, - 0x7d9b, - 0x7da5, - 0x7dae, - 0x7db8, - 0x7dc1, - 0x7dcb, - 0x7dd4, - 0x7ddd, - 0x7de6, - 0x7def, - 0x7df8, - 0x7e01, - 0x7e0a, - 0x7e13, - 0x7e1b, - 0x7e24, - 0x7e2c, - 0x7e35, - 0x7e3d, - 0x7e45, - 0x7e4d, - 0x7e56, - 0x7e5e, - 0x7e66, - 0x7e6d, - 0x7e75, - 0x7e7d, - 0x7e85, - 0x7e8c, - 0x7e94, - 0x7e9b, - 0x7ea3, - 0x7eaa, - 0x7eb1, - 0x7eb8, - 0x7ebf, - 0x7ec6, - 0x7ecd, - 0x7ed4, - 0x7edb, - 0x7ee1, - 0x7ee8, - 0x7eee, - 0x7ef5, - 0x7efb, - 0x7f01, - 0x7f08, - 0x7f0e, - 0x7f14, - 0x7f1a, - 0x7f20, - 0x7f25, - 0x7f2b, - 0x7f31, - 0x7f36, - 0x7f3c, - 0x7f41, - 0x7f47, - 0x7f4c, - 0x7f51, - 0x7f56, - 0x7f5b, - 0x7f60, - 0x7f65, - 0x7f6a, - 0x7f6f, - 0x7f74, - 0x7f78, - 0x7f7d, - 0x7f81, - 0x7f85, - 0x7f8a, - 0x7f8e, - 0x7f92, - 0x7f96, - 0x7f9a, - 0x7f9e, - 0x7fa2, - 0x7fa6, - 0x7fa9, - 0x7fad, - 0x7fb0, - 0x7fb4, - 0x7fb7, - 0x7fba, - 0x7fbe, - 0x7fc1, - 0x7fc4, - 0x7fc7, - 0x7fca, - 0x7fcc, - 0x7fcf, - 0x7fd2, - 0x7fd4, - 0x7fd7, - 0x7fd9, - 0x7fdc, - 0x7fde, - 0x7fe0, - 0x7fe2, - 0x7fe4, - 0x7fe6, - 0x7fe8, - 0x7fea, - 0x7fec, - 0x7fed, - 0x7fef, - 0x7ff1, - 0x7ff2, - 0x7ff3, - 0x7ff5, - 0x7ff6, - 0x7ff7, - 0x7ff8, - 0x7ff9, - 0x7ffa, - 0x7ffb, - 0x7ffb, - 0x7ffc, - 0x7ffd, - 0x7ffd, - 0x7ffe, - 0x7ffe, - 0x7ffe, - 0x7ffe, - 0x7ffe, - 0x7fff, -}; diff --git a/lib/ultralib/src/gu/sqrtf.s b/lib/ultralib/src/gu/sqrtf.s deleted file mode 100644 index 475a827..0000000 --- a/lib/ultralib/src/gu/sqrtf.s +++ /dev/null @@ -1,25 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/* - * Due to compiler bug, it won't insert a sqrt.s opcode in the stream so we - * make a function and call it for now. When compiler fixed, also remove the - * seperate Makefile rules - */ - -#include "sys/asm.h" -#include "sys/regdef.h" - -LEAF(sqrtf) - sqrt.s fv0, fa0 - j ra -END(sqrtf) diff --git a/lib/ultralib/src/gu/translate.c b/lib/ultralib/src/gu/translate.c deleted file mode 100644 index f086f39..0000000 --- a/lib/ultralib/src/gu/translate.c +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guTranslateF(float mf[4][4], float x, float y, float z) -{ - guMtxIdentF(mf); - - mf[3][0] = x; - mf[3][1] = y; - mf[3][2] = z; -} - -void guTranslate(Mtx *m, float x, float y, float z) -{ - Matrix mf; - - guTranslateF(mf, x, y, z); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/gu/us2dex.c b/lib/ultralib/src/gu/us2dex.c deleted file mode 100644 index 92f42bb..0000000 --- a/lib/ultralib/src/gu/us2dex.c +++ /dev/null @@ -1,73 +0,0 @@ -/*--------------------------------------------------------------------- - $Id: us2dex.c,v 1.4 1998/10/09 06:15:30 has Exp $ - - File : us2dex.c - - Coded by Yoshitaka Yasumoto. Mar 19, 1997. - Copyright by Nintendo, Co., Ltd. 1997. - ---------------------------------------------------------------------*/ -#include -#include - -/* - * Routines that support processing of S2DEX microcode - */ - -/* - * guS2DInitBG - * Set BG screen draw parameters - * - * If called at time of initialization, then it only needs to be - * called again when changes made to imageFmt, imageSiz, imageLoad, * imageW, frameW. However, if imageLoad == G_BGLT_LOADBLOCK and * only frameW is changed, another call is unnecessary. - */ -void guS2DInitBg(uObjBg *bg) -{ - u16 tmemUse; - u16 shift; -#if BUILD_VERSION >= VERSION_J - u32 tsize; -#endif - - /* - * Get the useable volume for TMEM - * If imageFmt is CI then TLUT will use half. - */ - tmemUse = (bg->b.imageFmt == G_IM_FMT_CI) ? 256 : 512; - - /* - * Get shift volume for conversion to TMEM word. - */ - shift = 6 - bg->b.imageSiz; - - /* - * Set other parameters for Load Mode. - */ - if (bg->b.imageLoad == G_BGLT_LOADBLOCK){ - bg->b.tmemW = bg->b.imageW >> shift; - bg->b.tmemH = (tmemUse / bg->b.tmemW) << 2; - bg->b.tmemSizeW = bg->b.tmemW << 1; - bg->b.tmemSize = bg->b.tmemH * bg->b.tmemSizeW; - bg->b.tmemLoadSH = (bg->b.tmemSize>>1) - 1; - bg->b.tmemLoadTH = GS_CALC_DXT(bg->b.tmemW); - } else { -#if BUILD_VERSION >= VERSION_J - bg->b.tmemW = (bg->b.frameW >> shift) + 3; - bg->b.tmemH = (tmemUse / bg->b.tmemW) << 2; - bg->b.tmemSizeW = (bg->b.imageW >> shift) * 2; - tsize = bg->b.tmemH * bg->b.tmemSizeW; - bg->b.tmemSize = tsize >> 16; - bg->b.tmemLoadSH = tsize & 0xffff; - bg->b.tmemLoadTH = bg->b.tmemH - 1; -#else - bg->b.tmemW = (bg->b.frameW >> shift) + 1; - bg->b.tmemH = (tmemUse / bg->b.tmemW) << 2; - bg->b.tmemSizeW = (bg->b.imageW >> shift) * 2; - bg->b.tmemSize = bg->b.tmemH * bg->b.tmemSizeW; - bg->b.tmemLoadSH = (bg->b.tmemW<<4) - 1; - bg->b.tmemLoadTH = bg->b.tmemH - 1; -#endif - } - return; -} - -/*======== End of us2dex.c ========*/ diff --git a/lib/ultralib/src/gu/us2dex2_emu.c b/lib/ultralib/src/gu/us2dex2_emu.c deleted file mode 100644 index cc32179..0000000 --- a/lib/ultralib/src/gu/us2dex2_emu.c +++ /dev/null @@ -1,12 +0,0 @@ -/*---------------------------------------------------------------------* - Copyright (C) 1998, Nintendo. - - File us2dex2_emu.c - Coded by Yoshitaka Yasumoto. Apr 10, 1998. - - $Id: us2dex2_emu.c,v 1.3 1998/10/09 06:15:40 has Exp $ - *---------------------------------------------------------------------*/ -#define F3DEX_GBI_2 -#include "us2dex_emu.c" - -/*======== End of us2dex2_emu.c ========*/ diff --git a/lib/ultralib/src/gu/us2dex_emu.c b/lib/ultralib/src/gu/us2dex_emu.c deleted file mode 100644 index c0a9e30..0000000 --- a/lib/ultralib/src/gu/us2dex_emu.c +++ /dev/null @@ -1,521 +0,0 @@ -/*---------------------------------------------------------------------* - Copyright (C) 1998, Nintendo. - - File us2dex_emu.c - Coded by Yoshitaka Yasumoto. Apr 9, 1998. - - $Id: us2dex_emu.c,v 1.9 1999/07/08 05:02:04 yurugi Exp $ - *---------------------------------------------------------------------*/ -#define F3DEX_GBI -#include -#include - -#define RSP_DEBUG - -static u16 scissorX0 = 0; /* (s13.2) */ -static u16 scissorY0 = 0; /* (s13.2) */ -static u16 scissorX1 = 320<<2; /* (s13.2) */ -static u16 scissorY1 = 240<<2; /* (s13.2) */ -static u8 flagBilerp = 0; - -static u32 rdpSetTimg_w0, rdpSetTile_w0; -static u16 tmemSliceWmax; -static u16 imageSrcWsize; -static s16 flagSplit; -static u16 imagePtrX0; -static u32 imageTop; -static s16 tmemSrcLines; - -/* Addition 99/05/31(Y) */ -#if BUILD_VERSION >= VERSION_K -static s8 bgflg; -#endif - -/*----------------------------------------------------------------------------* - * Set scissoring parameters - * *---------------------------------------------------------------------------*/ -void guS2DEmuSetScissor(u32 ulx, u32 uly, u32 lrx, u32 lry, u8 flag) -{ - scissorX0 = (u16)ulx << 2; - scissorY0 = (u16)uly << 2; - scissorX1 = (u16)lrx << 2; - scissorY1 = (u16)lry << 2; - flagBilerp = (flag) ? 1 : 0; -} - -/*---------------------------------------------------------------------------* - * Create texture load RDP commands - *---------------------------------------------------------------------------*/ -static void tmemLoad_B(Gfx **pkt, u32 imagePtr, s16 loadLines, s16 tmemSH) -{ - /* - * Load 16-bit texture of tmemSH word width starting from imagePtr - * into the loadLines amount of lines of tmem. - */ - - /* [SetTImg] CMD=0x3d FMT=RGBA(0) SIZ=16b(2) */ - (*pkt)->words.w0 = rdpSetTimg_w0; - (*pkt)->words.w1 = imagePtr; - (*pkt) ++; - - /* [LoadSync] Wait for completion of preceding primitive draw */ - (*pkt)->words.w0 = (G_RDPLOADSYNC<<24); - (*pkt) ++; - - /* [LoadTile] CMD=0x34 TILE=7 SH=TMEMW*16-1 TMEMH*4-1 */ - (*pkt)->words.w0 = (G_LOADTILE<<24)|0x000000; -/* addition 99/5/31(Y) */ -#if BUILD_VERSION >= VERSION_K - if(bgflg==3) (*pkt)->words.w1 = 0x07000000 | (tmemSH-1)<<16; - else (*pkt)->words.w1 = 0x07000000 | (tmemSH-1)<<16 | (loadLines<<2)-1; -#else - (*pkt)->words.w1 = 0x07000000 | (tmemSH-1)<<16 | (loadLines<<2)-1; -#endif - (*pkt) ++; -} - -static void tmemLoad_A(Gfx **pkt, u32 imagePtr, - s16 loadLines, s16 tmemAdrs, s16 tmemSH) -{ - /* - * Load 16-bit texture of tmemSH word width starting from imagePtr into - * the loadLines amount of lines of the tmemAdrs of tmem. - */ - - /* [TileSync] Wait for completion of Tile access of preceding command */ - (*pkt)->words.w0 = 0xe8000000; - (*pkt) ++; - - /* [SetTile] */ - (*pkt)->words.w0 = rdpSetTile_w0|tmemAdrs; - (*pkt)->words.w1 = 0x07000000; - (*pkt) ++; - - tmemLoad_B(pkt, imagePtr, loadLines, tmemSH); -} - -static void tmemLoad(Gfx **pkt, u32 *imagePtr, - s16 *imageRemain, s16 drawLines, s16 flagBilerp) -{ - s16 loadLines = drawLines + flagBilerp; - s16 iLoadable = (*imageRemain) - flagSplit; - - if (iLoadable >= loadLines){ /* If load can be done all at once */ - tmemLoad_B(pkt, *imagePtr, loadLines, tmemSliceWmax); - (*imagePtr) += imageSrcWsize * drawLines; - (*imageRemain) -= drawLines; - - } else { /* If load is to be partitioned */ - s16 SubSliceL2, SubSliceD2, SubSliceY2; - u32 imageTopSeg = imageTop & 0xff000000; - - SubSliceY2 = *imageRemain; - SubSliceL2 = loadLines - SubSliceY2; - SubSliceD2 = drawLines - SubSliceY2; - - if (SubSliceL2 > 0){ - u32 imagePtr2; - - imagePtr2 = imageTop + imagePtrX0; - if (SubSliceY2 & 1){ - imagePtr2 -= imageSrcWsize; - imagePtr2 = imageTopSeg | (imagePtr2 & 0x00ffffff); /*Segment counterm */ - SubSliceY2 --; - SubSliceL2 ++; - } - tmemLoad_A(pkt, imagePtr2, - SubSliceL2, SubSliceY2 * tmemSliceWmax, tmemSliceWmax); - } - if (flagSplit){ - u32 imagePtr1A, imagePtr1B; - s16 SubSliceY1, SubSliceL1; - s16 tmemSH_A, tmemSH_B; - - imagePtr1A = (*imagePtr) + iLoadable * imageSrcWsize; - imagePtr1B = imageTop; - SubSliceY1 = iLoadable; - if (SubSliceL1 = iLoadable & 1){ - imagePtr1A -= imageSrcWsize; - imagePtr1B -= imageSrcWsize; - imagePtr1B = imageTopSeg | (imagePtr1B & 0x00ffffff); /*Segment countermeasure */ - SubSliceY1 --; - } - SubSliceL1 ++; - tmemSH_A = (imageSrcWsize - imagePtrX0) >> 3; - tmemSH_B = tmemSliceWmax - tmemSH_A; - tmemLoad_A(pkt, imagePtr1B, - SubSliceL1, SubSliceY1 * tmemSliceWmax + tmemSH_A, tmemSH_B); - tmemLoad_A(pkt, imagePtr1A, - SubSliceL1, SubSliceY1 * tmemSliceWmax, tmemSH_A); - } - if (iLoadable > 0){ - - tmemLoad_A(pkt, *imagePtr, iLoadable, 0, tmemSliceWmax); - - } else { - - /* [SetTile] */ - (*pkt)->words.w0 = rdpSetTile_w0; - (*pkt)->words.w1 = 0x07000000; - (*pkt) ++; - } - - (*imageRemain) -= drawLines; - if ((*imageRemain) > 0){ - (*imagePtr) += imageSrcWsize * drawLines; - } else { - (*imageRemain) = tmemSrcLines - SubSliceD2; - (*imagePtr) = imageTop + SubSliceD2 * imageSrcWsize + imagePtrX0; - } - - } -} - -/*---------------------------------------------------------------------------* - * Scalable BG serface draw process - *---------------------------------------------------------------------------*/ -void guS2DEmuBgRect1Cyc(Gfx **pkt, uObjBg *bg) -{ - s16 frameX0, frameX1, framePtrY0, frameRemain; - s16 imageX0, imageY0, imageSliceW, imageW; - s32 imageYorig; - s16 scaleW, scaleH; - - s16 imageSrcW, imageSrcH; - s16 tmemSliceLines, imageSliceLines; - s32 frameSliceLines, frameSliceCount; - u16 imageS, imageT; - u32 imagePtr; - - s16 imageISliceL0, imageIY0; - s32 frameLSliceL0; - - scaleW = bg->s.scaleW; - scaleH = bg->s.scaleH; - -/* addition 99/05/31(Y) */ -#if BUILD_VERSION >= VERSION_K - bgflg=bg->s.imageSiz; - if(scaleW==0) scaleW=1; - if(scaleH==0) scaleH=1; -#endif - - -{ - /*-------------------------------------------------* - Scissoring process - *-------------------------------------------------*/ - /* - / frameX0, frameX1, framePtrY0, frameRemain - / imageX0, imageY0, tmemSliceW - / imageSrcW, imageSrcH - */ - s16 pixX0, pixY0, pixX1, pixY1; /* (s13.2) */ - s16 frameY0, frameW, frameH; - s32 frameWmax, frameHmax; - - /* Determine maximum frame size from image and enlargement ratio */ - frameWmax = ((((s32)bg->s.imageW << 10) / scaleW)-1) & ~3; - frameHmax = ((((s32)bg->s.imageH << 10) / scaleH)-1) & ~3; - - /* Clamp the frame size */ - frameW = bg->s.frameW; - frameH = bg->s.frameH; - frameX0 = bg->s.frameX; - frameY0 = bg->s.frameY; - if ((frameWmax = bg->s.frameW - frameWmax) < 0) frameWmax = 0; - if ((frameHmax = bg->s.frameH - frameHmax) < 0) frameHmax = 0; - frameW -= frameWmax; - frameH -= frameHmax; - if (bg->s.imageFlip & G_BG_FLAG_FLIPS){ - frameX0 += frameWmax; - } - - /* Caluculate amount of projection from screen */ - pixX0 = scissorX0 - frameX0; /* (s13.2) */ - pixY0 = scissorY0 - frameY0; /* (s13.2) */ - pixX1 = frameW - scissorX1 + frameX0; /* (s13.2) */ - pixY1 = frameH - scissorY1 + frameY0; /* (s13.2) */ - - /* Clamp if no projection */ - if (pixX0 < 0) pixX0 = 0; - if (pixY0 < 0) pixY0 = 0; - if (pixX1 < 0) pixX1 = 0; - if (pixY1 < 0) pixY1 = 0; - - /* Cut the part that is projecting */ - frameW = frameW - (pixX0 + pixX1); /* (s13.2) */ - frameH = frameH - (pixY0 + pixY1); /* (s13.2) */ - frameX0 = frameX0 + pixX0; /* (s13.2) */ - frameY0 = frameY0 + pixY0; /* (s13.2) */ - - /* Terminate if no draw range remains */ - if (frameW <= 0 || frameH <= 0) return; - - /* Caluculate frame */ - frameX1 = frameX0 + frameW; /* (s13.2) */ - framePtrY0 = frameY0 >> 2; /* (s15.0) */ - frameRemain = frameH >> 2; /* (s15.0) */ - - /* Join image columns */ - imageSrcW = bg->s.imageW << 3; /* (u11.5) */ - imageSrcH = bg->s.imageH << 3; /* (u11.5) */ - - /* Get image range (u14.2)*(u6.10)=(u20.12)->(u11.5) */ - imageSliceW = (imageW = frameW * scaleW >> 7) + flagBilerp * 32; - if (bg->s.imageFlip & G_BG_FLAG_FLIPS){ - imageX0 = bg->s.imageX + (pixX1 * scaleW >> 7); /* (s10.5) */ - } else { - imageX0 = bg->s.imageX + (pixX0 * scaleW >> 7); /* (s10.5) */ - } - imageY0 = bg->s.imageY + (pixY0 * scaleH >> 7); /* (s10.5) */ - imageYorig = bg->s.imageYorig; - - /* Loop one step down when left end of image area is greater than right end of image source */ - while (imageX0 >= imageSrcW){ - imageX0 -= imageSrcW; - imageY0 += 32; - imageYorig += 32; /* Add 1 to carrier */ - } - - /* Loop when top end of image area is greater than bottom end of image source */ - while (imageY0 >= imageSrcH){ - imageY0 -= imageSrcH; - imageYorig -= imageSrcH; - } -} - -{ - /*-------------------------------------------------* - Check process connecting top and bottom of image - *-------------------------------------------------*/ - /* - // flagSplit - // tmemSrcLines - // imageSrcLines - */ - /* Top/bottom connection process necessary when image range straddles right -end */ - flagSplit = (imageX0 + imageSliceW >= imageSrcW); - - /* Number of image lines that can be loaded at once */ - tmemSrcLines = imageSrcH >> 5; -} - -{ - /*-------------------------------------------------* - Get load data for TMEM - *-------------------------------------------------*/ - /* - //Calculate number of lines that can be loaded into TMEM. - // If the slice width changes due to scissoring and the linked - // load line number is changed, then the frame division line will - // change and the result will be the generation of unnatural wrinkles. - // To prevent this, the division region is set such that scissoring - // does not occur. - // - */ - s16 tmemSize, tmemMask, tmemShift; - s32 imageNumSlice; - s32 imageSliceWmax; - s32 imageLYoffset, frameLYoffset; - s32 imageLHidden, frameLHidden; - s32 frameLYslice; - - static s16 TMEMSIZE[] = { 512, 512, 256, 512, 512 }; - static s16 TMEMMASK[] = { 0x1ff, 0xff, 0x7f, 0x3f }; - static s16 TMEMSHIFT[] = { 0x200, 0x100, 0x80, 0x40 }; - tmemSize = TMEMSIZE[bg->s.imageFmt]; /* (s15.0) */ - tmemMask = TMEMMASK[bg->s.imageSiz]; /* (s10.5) */ - tmemShift = TMEMSHIFT[bg->s.imageSiz]; /* (s10.5)->(s15.0) */ - - /* Calculate tmem width to accommodate the slice image width */ - /* o Extra is needed at Bilerp time. - // o Clamp slice image width based on image source width. - // o Cut image width end number at TMEM Word boundary. - // o tmem width + 1 when start position not in agreement with Word boundary */ -/* addition 99/05/31(Y) */ -#if BUILD_VERSION >= VERSION_K - if(bgflg==3){ - tmemSize=480; - imageSliceWmax = 0x2800; - } - else{ - imageSliceWmax = (((s32)bg->s.frameW * (s32)scaleW)>>7) + (flagBilerp<<5); - if (imageSliceWmax > imageSrcW) imageSliceWmax = imageSrcW; - } -#else - imageSliceWmax = (((s32)bg->s.frameW * (s32)scaleW)>>7) + (flagBilerp<<5); - if (imageSliceWmax > imageSrcW) imageSliceWmax = imageSrcW; -#endif - - tmemSliceWmax = (imageSliceWmax + tmemMask) / tmemShift + 1; - - /* Get TMEM/image/frame line number that can be loaded at once */ - tmemSliceLines = tmemSize / tmemSliceWmax; /* (s15.0) */ - imageSliceLines = tmemSliceLines - flagBilerp; /* (s15.0) */ - frameSliceLines = (imageSliceLines << 20) / scaleH; /* (s21.10) */ - - /* Line up image Y coordinate offset value with frame image */ - imageLYoffset = ((s32)imageY0 - imageYorig) << 5; - if (imageLYoffset < 0) imageLYoffset -= (scaleH - 1); - frameLYoffset = imageLYoffset / scaleH; - frameLYoffset <<= 10; - - /* Get slice number corresponding to image Y */ - if (frameLYoffset >= 0){ - imageNumSlice = frameLYoffset / frameSliceLines; - } else { - imageNumSlice = (frameLYoffset - frameSliceLines + 1) / frameSliceLines; - } - - /* Calculate extent to which first draw slice is hidden at top of frame */ - frameLYslice = (frameLSliceL0 = frameSliceLines * imageNumSlice) & ~1023; - frameLHidden = frameLYoffset - frameLYslice; - imageLHidden = (frameLHidden >> 10) * scaleH; - - /* Calculate fram size of first draw slice */ - frameLSliceL0 = (frameLSliceL0 & 1023) + frameSliceLines - frameLHidden; - - /* Calculate image parameters for draw in midst of slice */ - imageT = (imageLHidden >> 5) & 31; - imageLHidden >>= 10; - imageISliceL0 = imageSliceLines - imageLHidden; - imageIY0 = - imageSliceLines * imageNumSlice + (imageYorig & ~31) / 32 + imageLHidden; - if (imageIY0 < 0) imageIY0 += (bg->s.imageH >> 2); - if (imageIY0 >= (bg->s.imageH >> 2)) imageIY0 -= (bg->s.imageH >> 2); - imageTop = (u32)bg->s.imagePtr; /* (u32.0) */ - imageSrcWsize = (imageSrcW / tmemShift) << 3; /* (u16.0) */ - imagePtrX0 = (imageX0 / tmemShift) << 3; /* (u16.0) */ - imagePtr = imageTop + imageSrcWsize * imageIY0 + imagePtrX0; - - /* S invert process */ - imageS = imageX0 & tmemMask; /* (u10.5) */ - if (bg->s.imageFlip & G_BG_FLAG_FLIPS){ - imageS = - (imageS + imageW); - } -} - -{ - /*-------------------------------------------------* - Creating RDP command constant values - *-------------------------------------------------*/ - /* u32 rdpSetTimg_w0; - u32 rdpSetTile_w0; */ -/* Addition 99/05/31(Y) */ -#if BUILD_VERSION >= VERSION_K - if(bgflg==3){ - rdpSetTimg_w0 = (G_SETTIMG<<24)+0x180000+(imageSrcWsize>>1)-1; - rdpSetTile_w0 = (G_SETTILE<<24)+0x180000+(tmemSliceWmax<<9); - } - else{ - rdpSetTimg_w0 = (G_SETTIMG<<24)+0x100000+(imageSrcWsize>>1)-1; - rdpSetTile_w0 = (G_SETTILE<<24)+0x100000+(tmemSliceWmax<<9); - } -#else - rdpSetTimg_w0 = (G_SETTIMG<<24)+0x100000+(imageSrcWsize>>1)-1; - rdpSetTile_w0 = (G_SETTILE<<24)+0x100000+(tmemSliceWmax<<9); -#endif - /* [SetTile:7] */ - (*pkt)->words.w0 = rdpSetTile_w0; - (*pkt)->words.w1 = 0x07000000; - (*pkt)++; - /* [SetTile:0] */ - (*pkt)->words.w0 = rdpSetTile_w0; - ((u8 *)&((*pkt)->words.w0))[1] = (bg->s.imageFmt<<5)|(bg->s.imageSiz<<3); - (*pkt)->words.w1 = 0x0007c1f0 | (bg->s.imagePal<<20); - (*pkt)++; - /* [SetTileSize:7] */ - (*pkt)->words.w0 = (G_SETTILESIZE<<24)|0x000000; - (*pkt)->words.w1 = 0x00000000; - (*pkt)++; -} - -{ - s16 imageRemain; - s16 imageSliceH, frameSliceH; - - imageRemain = tmemSrcLines - imageIY0; - imageSliceH = imageISliceL0; - frameSliceCount = frameLSliceL0; - - while(1){ - - /* Calculate draw line number and determine whether to perform a draw */ - frameSliceH = frameSliceCount >> 10; - if (frameSliceH <= 0){ - /* If no draw to be performed */ - imageRemain -= imageSliceH; - if (imageRemain > 0){ - imagePtr += imageSrcWsize * imageSliceH; - } else { - imagePtr = imageTop - (imageRemain * imageSrcWsize) + imagePtrX0; - imageRemain += tmemSrcLines; - } - - } else { - /* If draw to be performed */ - s16 framePtrY1; - - frameSliceCount &= 1023; - if ((frameRemain -= frameSliceH) < 0){ - /* Determine final slice */ - frameSliceH += frameRemain; - imageSliceH += ((frameRemain * scaleH) >> 10) + 1; - if (imageSliceH > imageSliceLines) imageSliceH = imageSliceLines; - } - tmemLoad(pkt, &imagePtr, &imageRemain, imageSliceH, flagBilerp); - - /* Get draw frame range */ - framePtrY1 = framePtrY0 + frameSliceH; /* (s15.0) */ - - /* [PipeSync] Wait for end of preceding LOADTILE command */ - (*pkt)->words.w0 = (G_RDPPIPESYNC<<24); - (*pkt) ++; - - /* Rectangle draw */ - /* Here an RSP command is created. With ucode an RDP command is created */ -#if 1 - { - /* [TextureRectangle] */ - (*pkt)->words.w0 = (G_TEXRECT<<24)|(frameX1<<12)|(framePtrY1<<2); - (*pkt)->words.w1 = (frameX0<<12)|(framePtrY0<<2); - (*pkt) ++; -#else - /* Code for checking slice division line */ - if (frameSliceH > 1){ - (*pkt)->words.w0 = (G_TEXRECT<<24)|(frameX1<<12)|(framePtrY1<<2)-4; - (*pkt)->words.w1 = (frameX0<<12)|(framePtrY0<<2); - (*pkt) ++; -#endif - -#if 0 /* At RDP command creation time */ - (*pkt)->words.w0 = (imageS<<16) | imageT; - (*pkt)->words.w1 = (scaleW<<16) | scaleH; -#else /* At RSP command creation time */ - (*pkt)->words.w0 = (G_RDPHALF_1<<24); - (*pkt)->words.w1 = (imageS<<16) | imageT; - (*pkt) ++; - (*pkt)->words.w0 = (G_RDPHALF_2<<24); - (*pkt)->words.w1 = (scaleW<<16) | scaleH; -#endif - (*pkt) ++; - } - - /* Update region */ - framePtrY0 = framePtrY1; - - /* End if no more undrawn line numbers for frame */ - if (frameRemain <= 0){ - return; - } - } - frameSliceCount += frameSliceLines; - imageSliceH = imageSliceLines; - imageT = 0; - } -} -} - -/*======== End of us2dex_emu.c ========*/ diff --git a/lib/ultralib/src/gu/usprite.c b/lib/ultralib/src/gu/usprite.c deleted file mode 100644 index a10ed34..0000000 --- a/lib/ultralib/src/gu/usprite.c +++ /dev/null @@ -1,39 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1996, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "gbi.h" - -void guSprite2DInit(uSprite *SpritePointer, - void *SourceImagePointer, - void *TlutPointer, - short Stride, - short SubImageWidth, - short SubImageHeight, - char SourceImageType, - char SourceImageBitSize, - short SourceImageOffsetS, - short SourceImageOffsetT) -{ - SpritePointer->s.SourceImagePointer = SourceImagePointer; - SpritePointer->s.TlutPointer = TlutPointer; - SpritePointer->s.Stride = Stride; - SpritePointer->s.SubImageWidth = SubImageWidth; - SpritePointer->s.SubImageHeight = SubImageHeight; - SpritePointer->s.SourceImageType = SourceImageType; - SpritePointer->s.SourceImageBitSize = SourceImageBitSize; - SpritePointer->s.SourceImageOffsetS = SourceImageOffsetS; - SpritePointer->s.SourceImageOffsetT = SourceImageOffsetT; -} - - - diff --git a/lib/ultralib/src/host/host_ptn64.c b/lib/ultralib/src/host/host_ptn64.c deleted file mode 100644 index 54e5e9e..0000000 --- a/lib/ultralib/src/host/host_ptn64.c +++ /dev/null @@ -1,209 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/os_version.h" -#include "PR/rcp.h" -#include "memory.h" - -#include "macros.h" - -#if BUILD_VERSION >= VERSION_J || !defined(_FINALROM) - -static volatile unsigned int* ptwtmode = (unsigned*)0xbff08014; -static volatile unsigned int* ptstat = (unsigned*)0xbff08004; -static volatile unsigned int* ptport = (unsigned*)0xbff08000; -static volatile unsigned int* n64piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); - -static OSMesgQueue waitPtQueue ALIGNED(8); -static OSMesg waitPtQueueBuf; -static u32 isWaitPtQueueCreated = FALSE; - -void __osPiRelAccess(void); -void __osPiGetAccess(void); - -static void createWaitPtQueue(void) { - osCreateMesgQueue(&waitPtQueue, &waitPtQueueBuf, 1); - isWaitPtQueueCreated = TRUE; -} - -static u32 getPT_wait(void) { - OSTimer waitTimer; - u32 status UNUSED; - - for (;;) { - while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - ; - } - - if (*ptstat & 2) { - return *ptport; - } - __osPiRelAccess(); - - osRecvMesg(&waitPtQueue, NULL, OS_MESG_NOBLOCK); - osSetTimer(&waitTimer, OS_USEC_TO_CYCLES(1000), 0, &waitPtQueue, NULL); - osRecvMesg(&waitPtQueue, NULL, OS_MESG_BLOCK); - - __osPiGetAccess(); - } -} - -static void putPT(u32 c) { - while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - ; - } - while (!(*ptstat & 4)) { - ; - } - *ptport = c; -} - -static u32 getPT(void) { - while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - ; - } - while (!(*ptstat & 2)) { - ; - } - return *ptport; -} - -void osReadHost_pt(void* dramAddr, u32 nbytes) { - u8* tPtr; - u32 buf[256]; - u32* bp; - u32 data; - u32 ct; - u32 ct1; - u32 ct1_bak; - u32 shift; - u32 cmd; - u32 size; - - if (nbytes == 0) { - return; - } - - if (!isWaitPtQueueCreated) { - createWaitPtQueue(); - } - - __osPiGetAccess(); - - putPT(0x82U); - - cmd = getPT_wait(); - - size = getPT(); - - if (cmd != 2) { - nbytes = -1U; - } - - putPT(nbytes); - - if (size != nbytes) { - goto osReadHost_ret; - } - - tPtr = dramAddr; - ct = nbytes / 4; - - while (ct != 0) { - if (ct > 0x100) { - ct1_bak = ct1 = 0x100; - ct -= 0x100; - } else { - ct1_bak = ct1 = ct; - ct = 0; - } - bp = (u32*)&buf; - - while (ct1 != 0) { - *(bp++) = getPT(); - ct1--; - } - - memcpy(tPtr, &buf, ct1_bak * 4); - tPtr += ct1_bak * 4; - } - - nbytes &= 3; - - if (nbytes != 0) { - data = getPT(); - shift = 0x18; - - do { - *(tPtr++) = (data >> shift); - nbytes--; - shift -= 8; - } while (nbytes != 0); - } - -osReadHost_ret: - __osPiRelAccess(); - return; -} - -void osWriteHost_pt(void* dramAddr, u32 nbytes) { - u8* tPtr; - u32 buf[256]; - u32* bp; - u32 ct; - u32 ct1; - u32 ct1_bak; - u32 cmd; - u32 size; - - if (nbytes == 0) { - return; - } - - if (!isWaitPtQueueCreated) { - createWaitPtQueue(); - } - - __osPiGetAccess(); - putPT(0x82); - - cmd = getPT_wait(); - - size = getPT(); - - if (cmd != 3) { - nbytes = -1; - } - - putPT(nbytes); - - if (size != nbytes) { - goto osWriteHost_ret; - } - - tPtr = dramAddr; - ct = (nbytes + 3) >> 2; - - while (ct != 0) { - if (ct > 0x100) { - ct1_bak = ct1 = 0x100; - ct -= 0x100; - } else { - ct1_bak = ct1 = ct; - ct = 0; - } - - memcpy(bp = buf, tPtr, ct1_bak * 4); - - while (ct1 != 0) { - putPT(*(bp++)); - ct1--; - } - - tPtr += ct1_bak * 4; - } - -osWriteHost_ret: - __osPiRelAccess(); - return; -} - -#endif diff --git a/lib/ultralib/src/host/readhost.c b/lib/ultralib/src/host/readhost.c deleted file mode 100644 index ed6402d..0000000 --- a/lib/ultralib/src/host/readhost.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "PR/rdb.h" - -#include "macros.h" - -static int readHostInitialized = FALSE; -static OSMesgQueue readHostMesgQueue ALIGNED(8); -static OSMesg readHostMesgBuf[1]; - -u32 __osRdb_Read_Data_Buf; -u32 __osRdb_Read_Data_Ct; - -void osReadHost(void* dramAddr, u32 nbytes) { - char tstr[4]; - u32 sent = 0; - - if (!readHostInitialized) { - osCreateMesgQueue(&readHostMesgQueue, readHostMesgBuf, ARRLEN(readHostMesgBuf)); - osSetEventMesg(OS_EVENT_RDB_READ_DONE, &readHostMesgQueue, NULL); - readHostInitialized = TRUE; - } - - __osRdb_Read_Data_Buf = dramAddr; - __osRdb_Read_Data_Ct = nbytes; - - while (sent == 0) { - sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_READY_FOR_DATA); - } - - osRecvMesg(&readHostMesgQueue, NULL, OS_MESG_BLOCK); - return; -} - -#endif diff --git a/lib/ultralib/src/host/writehost.c b/lib/ultralib/src/host/writehost.c deleted file mode 100644 index c7477e6..0000000 --- a/lib/ultralib/src/host/writehost.c +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "PR/rdb.h" -#include "PR/ultraerror.h" - -#include "macros.h" - -static int writeHostInitialized = FALSE; -static OSMesgQueue writeHostMesgQueue ALIGNED(8); -static OSMesg writeHostMesgBuf[1]; - -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - -void osWriteHost(void* dramAddr, u32 nbytes) { - u8* tPtr = dramAddr; - u32 sent; - u8 dCount[3]; - u32 count; - -#ifndef NDEBUG - if (nbytes == 0) { - __osError(ERR_OSWRITEHOST_SIZE, 1, nbytes); - return; - } -#endif - - if (writeHostInitialized == FALSE) { - osCreateMesgQueue(&writeHostMesgQueue, writeHostMesgBuf, ARRLEN(writeHostMesgBuf)); - osSetEventMesg(OS_EVENT_RDB_DATA_DONE, &writeHostMesgQueue, NULL); - writeHostInitialized = TRUE; - } - - while (nbytes != 0) { - count = MIN(nbytes, 0x8000); - - dCount[0] = (count & 0xFF0000) >> 0x10; - dCount[1] = (count & 0xFF00) >> 8; - dCount[2] = count & 0xFF; - - sent = 0; - while (sent < ARRLEN(dCount)) { - sent += __osRdbSend(dCount + sent, ARRLEN(dCount) - sent, RDB_TYPE_GtoH_DATA_CT); - } - - sent = 0; - while (sent < count) { - sent += __osRdbSend(tPtr + sent, count - sent, RDB_TYPE_GtoH_DATA); - } - - nbytes -= count; - tPtr += count; - osRecvMesg(&writeHostMesgQueue, NULL, OS_MESG_BLOCK); - } -} - -#endif diff --git a/lib/ultralib/src/io/ai.c b/lib/ultralib/src/io/ai.c deleted file mode 100644 index 4ece0f1..0000000 --- a/lib/ultralib/src/io/ai.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osAiDeviceBusy(void) { - register s32 status = IO_READ(AI_STATUS_REG); - - if (status & AI_STATUS_FIFO_FULL) { - return TRUE; - } else { - return FALSE; - } -} diff --git a/lib/ultralib/src/io/aigetlen.c b/lib/ultralib/src/io/aigetlen.c deleted file mode 100644 index 6b83682..0000000 --- a/lib/ultralib/src/io/aigetlen.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -u32 osAiGetLength(void) { - return IO_READ(AI_LEN_REG); -} diff --git a/lib/ultralib/src/io/aigetstat.c b/lib/ultralib/src/io/aigetstat.c deleted file mode 100644 index c7a3cf7..0000000 --- a/lib/ultralib/src/io/aigetstat.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -u32 osAiGetStatus() { - return IO_READ(AI_STATUS_REG); -} diff --git a/lib/ultralib/src/io/aisetfreq.c b/lib/ultralib/src/io/aisetfreq.c deleted file mode 100644 index e41d6fa..0000000 --- a/lib/ultralib/src/io/aisetfreq.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "PR/rcp.h" -#include "PR/ultraerror.h" -#include "../os/osint.h" -// TODO: not sure if this should be here -extern s32 osViClock; - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 osAiSetFrequency(u32 frequency) { - register unsigned int dacRate; - register unsigned char bitRate; - register float f; - -#ifdef _DEBUG - if (osViClock == VI_PAL_CLOCK) { - if (frequency < AI_PAL_MIN_FREQ || frequency > AI_PAL_MAX_FREQ) { - __osError(ERR_OSAISETFREQUENCY, 3, AI_PAL_MIN_FREQ, AI_PAL_MAX_FREQ, frequency); - return -1; - } - } else if (osViClock == VI_MPAL_CLOCK) { - if (frequency < AI_MPAL_MIN_FREQ || frequency > AI_MPAL_MAX_FREQ) { - __osError(ERR_OSAISETFREQUENCY, 3, AI_MPAL_MIN_FREQ, AI_MPAL_MAX_FREQ, frequency); - return -1; - } - } else { - if (frequency < AI_NTSC_MIN_FREQ || frequency > AI_NTSC_MAX_FREQ) { - __osError(ERR_OSAISETFREQUENCY, 3, AI_NTSC_MIN_FREQ, AI_NTSC_MAX_FREQ, frequency); - return -1; - } - } -#endif - - f = osViClock / (float)frequency + .5f; - dacRate = f; - - if (dacRate < AI_MIN_DAC_RATE) { - return -1; - } - - bitRate = dacRate / 66; - - if (bitRate > AI_MAX_BIT_RATE) { - bitRate = AI_MAX_BIT_RATE; - } - - IO_WRITE(AI_DACRATE_REG, dacRate - 1); - IO_WRITE(AI_BITRATE_REG, bitRate - 1); -#if BUILD_VERSION < VERSION_J - IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); -#endif - return osViClock / (s32)dacRate; -} diff --git a/lib/ultralib/src/io/aisetnextbuf.c b/lib/ultralib/src/io/aisetnextbuf.c deleted file mode 100644 index 041b61d..0000000 --- a/lib/ultralib/src/io/aisetnextbuf.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/rcp.h" -#include "../os/osint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 osAiSetNextBuffer(void* bufPtr, u32 size) { - static u8 hdwrBugFlag = FALSE; - char* bptr; - -#if BUILD_VERSION >= VERSION_J - if (__osAiDeviceBusy()) { - return -1; - } -#endif - -#ifdef _DEBUG - if ((u32)bufPtr & (8 - 1)) { - __osError(ERR_OSAISETNEXTBUFFER_ADDR, 1, bufPtr); - return -1; - } - - if ((u32)size & (8 - 1)) { - __osError(ERR_OSAISETNEXTBUFFER_SIZE, 1, size); - return -1; - } -#endif - - bptr = bufPtr; - - if (hdwrBugFlag) { - bptr = (u8*)bufPtr - 0x2000; - } - - if ((((u32)bufPtr + size) & 0x1fff) == 0) { - hdwrBugFlag = TRUE; - } else { - hdwrBugFlag = FALSE; - } - -#if BUILD_VERSION < VERSION_J - if (__osAiDeviceBusy()) { - return -1; - } -#endif - - IO_WRITE(AI_DRAM_ADDR_REG, osVirtualToPhysical(bptr)); - IO_WRITE(AI_LEN_REG, size); - return 0; -} diff --git a/lib/ultralib/src/io/cartrominit.c b/lib/ultralib/src/io/cartrominit.c deleted file mode 100644 index 87aa8bb..0000000 --- a/lib/ultralib/src/io/cartrominit.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "macros.h" -#include "PR/os_version.h" -#include "PR/os_internal.h" -#include "PR/R4300.h" -#include "PR/rcp.h" -#include "piint.h" - -#if BUILD_VERSION >= VERSION_J -OSPiHandle __CartRomHandle ALIGNED(8); -OSPiHandle* osCartRomInit(void) { - u32 value = 0; - u32 saveMask; - static int first = 1; - register u32 stat; - u32 latency; - u32 pulse; - u32 pageSize; - u32 relDuration; - - __osPiGetAccess(); - - if (!first) { - __osPiRelAccess(); - return &__CartRomHandle; - } - - first = 0; - __CartRomHandle.type = DEVICE_TYPE_CART; - __CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); - __CartRomHandle.domain = PI_DOMAIN1; - __CartRomHandle.speed = 0; - - bzero(&__CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); - - WAIT_ON_IOBUSY(stat); - - latency = IO_READ(PI_BSD_DOM1_LAT_REG); - pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); - relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); - pulse = IO_READ(PI_BSD_DOM1_PWD_REG); - - IO_WRITE(PI_BSD_DOM1_LAT_REG, 0xFF); - IO_WRITE(PI_BSD_DOM1_PGS_REG, 0); - IO_WRITE(PI_BSD_DOM1_RLS_REG, 3); - IO_WRITE(PI_BSD_DOM1_PWD_REG, 0xFF); - - value = IO_READ(__CartRomHandle.baseAddress); - __CartRomHandle.latency = value & 0xFF; - __CartRomHandle.pageSize = (value >> 0x10) & 0xF; - __CartRomHandle.relDuration = (value >> 0x14) & 0xF; - __CartRomHandle.pulse = (value >> 8) & 0xFF; - - IO_WRITE(PI_BSD_DOM1_LAT_REG, latency); - IO_WRITE(PI_BSD_DOM1_PGS_REG, pageSize); - IO_WRITE(PI_BSD_DOM1_RLS_REG, relDuration); - IO_WRITE(PI_BSD_DOM1_PWD_REG, pulse); - - saveMask = __osDisableInt(); - __CartRomHandle.next = __osPiTable; - __osPiTable = &__CartRomHandle; - __osRestoreInt(saveMask); - __osPiRelAccess(); - - return &__CartRomHandle; -} -#else - -OSPiHandle CartRomHandle ALIGNED(8); -OSPiHandle* osCartRomInit(void) { - u32 domain = 0; - u32 saveMask; - - if (CartRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR2)) - return &CartRomHandle; - - CartRomHandle.type = DEVICE_TYPE_CART; - CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); - osPiRawReadIo(NULL, &domain); - CartRomHandle.latency = domain & 0xff; - CartRomHandle.pulse = (domain >> 8) & 0xff; - CartRomHandle.pageSize = (domain >> 0x10) & 0xf; - CartRomHandle.relDuration = (domain >> 0x14) & 0xf; - CartRomHandle.domain = PI_DOMAIN1; - CartRomHandle.speed = 0; - - bzero(&CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); - - saveMask = __osDisableInt(); - CartRomHandle.next = __osPiTable; - __osPiTable = &CartRomHandle; - __osRestoreInt(saveMask); - - return &CartRomHandle; -} -#endif diff --git a/lib/ultralib/src/io/contchannelreset.c b/lib/ultralib/src/io/contchannelreset.c deleted file mode 100644 index f6ed8a2..0000000 --- a/lib/ultralib/src/io/contchannelreset.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -s32 __osContChannelReset(OSMesgQueue* mq, int channel) { - s32 i; - s32 ret; - u8* ptr = (u8*)&__osPfsPifRam; - - __osSiGetAccess(); - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - for (i = 0; i < channel; i++) { - *ptr++ = CONT_CMD_REQUEST_STATUS; - } - - *ptr++ = CONT_CMD_CHANNEL_RESET; - *ptr = CONT_CMD_END; - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - __osSiRelAccess(); - return ret; -} diff --git a/lib/ultralib/src/io/conteeplongread.c b/lib/ultralib/src/io/conteeplongread.c deleted file mode 100644 index d8d59f6..0000000 --- a/lib/ultralib/src/io/conteeplongread.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osEepromLongRead(OSMesgQueue* mq, u8 address, u8* buffer, int length) { - s32 ret = 0; - - while (length > 0) { - ERRCK(osEepromRead(mq, address, buffer)); - length -= EEPROM_BLOCK_SIZE; - address++; - buffer += EEPROM_BLOCK_SIZE; - } - - return ret; -} diff --git a/lib/ultralib/src/io/conteeplongwrite.c b/lib/ultralib/src/io/conteeplongwrite.c deleted file mode 100644 index c5668e1..0000000 --- a/lib/ultralib/src/io/conteeplongwrite.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osEepromLongWrite(OSMesgQueue* mq, u8 address, u8* buffer, int length) { - s32 ret = 0; - - while (length > 0) { - ERRCK(osEepromWrite(mq, address, buffer)); - length -= EEPROM_BLOCK_SIZE; - address++; - buffer += EEPROM_BLOCK_SIZE; - osSetTimer(&__osEepromTimer, OS_USEC_TO_CYCLES(12000), 0, &__osEepromTimerQ, &__osEepromTimerMsg); - osRecvMesg(&__osEepromTimerQ, NULL, OS_MESG_BLOCK); - } - - return ret; -} diff --git a/lib/ultralib/src/io/conteepprobe.c b/lib/ultralib/src/io/conteepprobe.c deleted file mode 100644 index b19dc49..0000000 --- a/lib/ultralib/src/io/conteepprobe.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "controller.h" -#include "siint.h" - -s32 osEepromProbe(OSMesgQueue* mq) { - s32 ret = 0; - u16 type; - OSContStatus sdata; - - __osSiGetAccess(); - ret = __osEepStatus(mq, &sdata); - type = sdata.type & (CONT_EEPROM | CONT_EEP16K); - - if (ret != 0) { - ret = 0; - } else { - switch (type) { - case CONT_EEPROM: - ret = EEPROM_TYPE_4K; - break; - case CONT_EEPROM | CONT_EEP16K: - ret = EEPROM_TYPE_16K; - break; - default: - ret = 0; - break; - } - } - -#if BUILD_VERSION >= VERSION_L - __osEepromRead16K = 0; -#endif - __osSiRelAccess(); - return ret; -} diff --git a/lib/ultralib/src/io/conteepread.c b/lib/ultralib/src/io/conteepread.c deleted file mode 100644 index 2d334fa..0000000 --- a/lib/ultralib/src/io/conteepread.c +++ /dev/null @@ -1,139 +0,0 @@ -#include "macros.h" -#include "PR/rcp.h" -#include "controller.h" -#include "siint.h" - -OSPifRam __osEepPifRam ALIGNED(16); -#if BUILD_VERSION >= VERSION_L -s32 __osEepromRead16K; -#endif -static void __osPackEepReadData(u8 address); - -s32 osEepromRead(OSMesgQueue* mq, u8 address, u8* buffer) { - s32 ret = 0; - int i = 0; - u16 type; - u8* ptr; - OSContStatus sdata; - __OSContEepromFormat eepromformat; - - ptr = (u8*)&__osEepPifRam.ramarray; - __osSiGetAccess(); - ret = __osEepStatus(mq, &sdata); - type = sdata.type & (CONT_EEPROM | CONT_EEP16K); - -#if BUILD_VERSION >= VERSION_J - if (ret == 0) { - switch (type) { - case CONT_EEPROM: - if (address >= EEPROM_MAXBLOCKS) { - ret = CONT_RANGE_ERROR; - } - break; - case CONT_EEPROM | CONT_EEP16K: - if (address >= EEP16K_MAXBLOCKS) { - // not technically possible - ret = CONT_RANGE_ERROR; - } -#if BUILD_VERSION >= VERSION_L - else { - __osEepromRead16K = 1; - } -#endif - break; - default: - ret = CONT_NO_RESPONSE_ERROR; - } - } - - if (ret != 0) { - __osSiRelAccess(); - return ret; - } -#else - if (ret != 0) - { - __osSiRelAccess(); - return CONT_NO_RESPONSE_ERROR; - } else { - switch (type) { - case CONT_EEPROM: - if (address > EEPROM_MAXBLOCKS) { - __osSiRelAccess(); - return CONT_RANGE_ERROR; - } - break; - case CONT_EEPROM | CONT_EEP16K: - if (address > EEP16K_MAXBLOCKS) { - // not technically possible - __osSiRelAccess(); - return CONT_RANGE_ERROR; - } - break; - default: - __osSiRelAccess(); - return CONT_NO_RESPONSE_ERROR; - } - } -#endif - - while (sdata.status & CONT_EEPROM_BUSY) { - __osEepStatus(mq, &sdata); - } - - __osPackEepReadData(address); - ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); // send command to pif - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); // recv response - __osContLastCmd = CONT_CMD_READ_EEPROM; - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - for (i = 0; i < MAXCONTROLLERS; i++) { - // skip the first 4 bytes - ptr++; - } - - eepromformat = *(__OSContEepromFormat*)ptr; - ret = CHNL_ERR(eepromformat); - - if (ret == 0) { - for (i = 0; i < ARRLEN(eepromformat.data); i++) { - *buffer++ = eepromformat.data[i]; - } - } - __osSiRelAccess(); - return ret; -} - -static void __osPackEepReadData(u8 address) { - u8* ptr = (u8*)&__osEepPifRam.ramarray; - __OSContEepromFormat eepromformat; - int i; - -#if BUILD_VERSION < VERSION_J - for (i = 0; i < ARRLEN(__osEepPifRam.ramarray); i++) { - __osEepPifRam.ramarray[i] = CONT_CMD_NOP; - } -#endif - - __osEepPifRam.pifstatus = CONT_CMD_EXE; - - eepromformat.txsize = CONT_CMD_READ_EEPROM_TX; - eepromformat.rxsize = CONT_CMD_READ_EEPROM_RX; - eepromformat.cmd = CONT_CMD_READ_EEPROM; - eepromformat.address = address; - -#if BUILD_VERSION < VERSION_J - for (i = 0; i < ARRLEN(eepromformat.data); i++) { - eepromformat.data[i] = 0; - } -#endif - - for (i = 0; i < MAXCONTROLLERS; i++) { - *ptr++ = 0; - } - - *(__OSContEepromFormat*)(ptr) = eepromformat; - ptr += sizeof(__OSContEepromFormat); - ptr[0] = CONT_CMD_END; -} diff --git a/lib/ultralib/src/io/conteepwrite.c b/lib/ultralib/src/io/conteepwrite.c deleted file mode 100644 index 7352430..0000000 --- a/lib/ultralib/src/io/conteepwrite.c +++ /dev/null @@ -1,203 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "controller.h" -#include "siint.h" - -static void __osPackEepWriteData(u8 address, u8* buffer); -s32 osEepromWrite(OSMesgQueue* mq, u8 address, u8* buffer) { - s32 ret = 0; -#if BUILD_VERSION < VERSION_J - int i; -#endif - u16 type; - u8* ptr = (u8*)&__osEepPifRam.ramarray; - __OSContEepromFormat eepromformat; - OSContStatus sdata; -#if BUILD_VERSION >= VERSION_L - u8 temp[8]; -#endif - - __osSiGetAccess(); - ret = __osEepStatus(mq, &sdata); -#if BUILD_VERSION < VERSION_J - ret = __osEepStatus(mq, &sdata); // Duplicate that was removed in 2.0J -#endif - - type = sdata.type & (CONT_EEPROM | CONT_EEP16K); - -#if BUILD_VERSION >= VERSION_J - if (ret == 0) { - switch (type) { - case CONT_EEPROM: - if (address >= EEPROM_MAXBLOCKS) { - ret = CONT_RANGE_ERROR; - } - break; - case CONT_EEPROM | CONT_EEP16K: - if (address >= EEP16K_MAXBLOCKS) { - // not technically possible - ret = CONT_RANGE_ERROR; - } -#if BUILD_VERSION >= VERSION_L - else if (__osEepromRead16K) { - __osEepromRead16K = 0; - __osSiRelAccess(); - osEepromRead(mq, (address ^ 1), temp); - __osSiGetAccess(); - } -#endif - break; - default: - ret = CONT_NO_RESPONSE_ERROR; - } - } - - if (ret != 0) { - __osSiRelAccess(); - return ret; - } -#else - if (ret != 0) { - __osSiRelAccess(); - return CONT_NO_RESPONSE_ERROR; - } else { - switch (type) { - case CONT_EEPROM: - if (address > EEPROM_MAXBLOCKS) { - __osSiRelAccess(); - return -1; - } - - break; - case CONT_EEPROM | CONT_EEP16K: - if (address > EEP16K_MAXBLOCKS) { - // not technically possible - __osSiRelAccess(); - return -1; - } - break; - default: - __osSiRelAccess(); - return CONT_NO_RESPONSE_ERROR; - } - } -#endif - - while (sdata.status & CONT_EEPROM_BUSY) { - __osEepStatus(mq, &sdata); - } - - __osPackEepWriteData(address, buffer); - ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); // send command to pif - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); // recv response - __osContLastCmd = CONT_CMD_WRITE_EEPROM; - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - // skip the first 4 bytes -#if BUILD_VERSION >= VERSION_J - ptr += 4; -#else - for (i = 0; i < 4; i++) { - ptr++; - } -#endif - - eepromformat = *(__OSContEepromFormat*)ptr; - - ret = CHNL_ERR(eepromformat); - - __osSiRelAccess(); - return ret; -} - -static void __osPackEepWriteData(u8 address, u8* buffer) { - u8* ptr = (u8*)&__osEepPifRam.ramarray; - __OSContEepromFormat eepromformat; - int i; - -#if BUILD_VERSION < VERSION_J - for (i = 0; i < ARRLEN(__osEepPifRam.ramarray); i++) { - __osEepPifRam.ramarray[i] = CONT_CMD_NOP; - } -#endif - __osEepPifRam.pifstatus = CONT_CMD_EXE; - - eepromformat.txsize = CONT_CMD_WRITE_EEPROM_TX; - eepromformat.rxsize = CONT_CMD_WRITE_EEPROM_RX; - eepromformat.cmd = CONT_CMD_WRITE_EEPROM; - eepromformat.address = address; - - for (i = 0; i < ARRLEN(eepromformat.data); i++) { - eepromformat.data[i] = *buffer++; - } - - for (i = 0; i < MAXCONTROLLERS; i++) { - *ptr++ = 0; - } - - *(__OSContEepromFormat*)(ptr) = eepromformat; - ptr += sizeof(__OSContEepromFormat); - ptr[0] = CONT_CMD_END; -} - -s32 __osEepStatus(OSMesgQueue* mq, OSContStatus* data) { - s32 ret = 0; - int i; - u8* ptr = (u8*)__osEepPifRam.ramarray; - __OSContRequesFormat requestformat; - - for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { - __osEepPifRam.ramarray[i] = 0; - } - - __osEepPifRam.pifstatus = CONT_CMD_EXE; - ptr = (u8*)__osEepPifRam.ramarray; - - for (i = 0; i < MAXCONTROLLERS; i++) { - *ptr++ = CONT_CMD_REQUEST_STATUS; - } - - requestformat.dummy = CONT_CMD_NOP; - requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; - requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; - requestformat.cmd = CONT_CMD_REQUEST_STATUS; - requestformat.typeh = CONT_CMD_NOP; - requestformat.typel = CONT_CMD_NOP; - requestformat.status = CONT_CMD_NOP; - requestformat.dummy1 = CONT_CMD_NOP; - *(__OSContRequesFormat*)ptr = requestformat; - ptr += sizeof(__OSContRequesFormat); - *ptr = CONT_CMD_END; - - ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); -#if BUILD_VERSION >= VERSION_J - __osContLastCmd = CONT_CMD_END; -#else - __osContLastCmd = CONT_CMD_REQUEST_STATUS; -#endif - ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - if (ret != 0) { - return ret; - } - - ptr = (u8*)&__osEepPifRam; - - for (i = 0; i < MAXCONTROLLERS; i++) { - *ptr++ = 0; - } - - requestformat = *(__OSContRequesFormat*)ptr; - data->errno = CHNL_ERR(requestformat); - data->type = (requestformat.typel << 8) | requestformat.typeh; - data->status = requestformat.status; - - if (data->errno != 0) { - return data->errno; - } - - return 0; -} diff --git a/lib/ultralib/src/io/contpfs.c b/lib/ultralib/src/io/contpfs.c deleted file mode 100644 index 2632193..0000000 --- a/lib/ultralib/src/io/contpfs.c +++ /dev/null @@ -1,393 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "PR/os_version.h" -#include "controller.h" -#include "PR/rmon.h" - -#if BUILD_VERSION >= VERSION_J -__OSInode __osPfsInodeCache ALIGNED(8); -s32 __osPfsInodeCacheChannel = -1; -u8 __osPfsInodeCacheBank = 250; -#endif - -u16 __osSumcalc(u8* ptr, int length) { - int i; - u32 sum = 0; - u8* tmp = ptr; - - for (i = 0; i < length; i++) { - sum += *tmp++; -#if BUILD_VERSION < VERSION_J - sum = sum & 0xFFFF; -#endif - } - -#if BUILD_VERSION >= VERSION_J - return sum & 0xFFFF; -#else - return sum; -#endif -} - -s32 __osIdCheckSum(u16* ptr, u16* csum, u16* icsum) { - u16 data = 0; - u32 j; - - *csum = *icsum = 0; - - for (j = 0; j < ((sizeof(__OSPackId) - sizeof(u32)) / sizeof(u8)); j += 2) { - data = *(u16*)((u32)ptr + j); - *csum += data; - *icsum += ~data; - } - - return 0; -} - -s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) { - s32 ret = 0; - u8 temp[BLOCKSIZE]; - u8 comp[BLOCKSIZE]; - u8 mask = 0; - int i; - int j; - u16 index[4]; - -#if BUILD_VERSION >= VERSION_J - j = 0; -#else - SET_ACTIVEBANK_TO_ZERO; -#endif - - newid->repaired = -1; - newid->random = osGetCount(); - newid->serial_mid = badid->serial_mid; - newid->serial_low = badid->serial_low; - -#if BUILD_VERSION >= VERSION_J - SET_ACTIVEBANK_TO_ZERO; -#else - j = 0; -#endif - do { - ERRCK(SELECT_BANK(pfs, j)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, temp)); - - temp[0] = j | 0x80; - - for (i = 1; i < BLOCKSIZE; i++) { - temp[i] = ~temp[i]; - } - - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, 0, temp, FALSE)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, comp)); - - for (i = 0; i < BLOCKSIZE; i++) { - if (comp[i] != temp[i]) { - break; - } - } - - if (i != BLOCKSIZE) { - break; - } - - if (j > 0) { - ERRCK(SELECT_BANK(pfs, 0)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)temp)); - - if (temp[0] != 0x80) { - break; - } - } - - j++; - } while (j < PFS_MAX_BANKS); - -#if BUILD_VERSION >= VERSION_J - SET_ACTIVEBANK_TO_ZERO; -#else - ERRCK(SELECT_BANK(pfs, 0)); -#endif - - mask = (j > 0) ? 1 : 0; - - newid->deviceid = (badid->deviceid & (u16)~1) | mask; - newid->banks = j; - newid->version = badid->version; - __osIdCheckSum((u16*)newid, &newid->checksum, &newid->inverted_checksum); - index[0] = PFS_ID_0AREA; - index[1] = PFS_ID_1AREA; - index[2] = PFS_ID_2AREA; - index[3] = PFS_ID_3AREA; - - for (i = 0; i < ARRLEN(index); i++) { - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[i], (u8*)newid, TRUE)); - } - - ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); - - for (i = 0; i < BLOCKSIZE; i++) { - if (temp[i] != ((u8*)newid)[i]) { -#if BUILD_VERSION >= VERSION_J - return PFS_ERR_DEVICE; -#else - return PFS_ERR_ID_FATAL; -#endif - } - } - return 0; -} - -s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp) { - u16 index[4]; - s32 ret = 0; - u16 sum; - u16 isum; - int i; - int j; - - SET_ACTIVEBANK_TO_ZERO; - index[0] = PFS_ID_0AREA; - index[1] = PFS_ID_1AREA; - index[2] = PFS_ID_2AREA; - index[3] = PFS_ID_3AREA; - for (i = 1; i < ARRLEN(index); i++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, index[i], (u8*)temp)); - __osIdCheckSum((u16*)temp, &sum, &isum); - if (temp->checksum == sum && temp->inverted_checksum == isum) { - break; - } - } - - if (i == ARRLEN(index)) { - return PFS_ERR_ID_FATAL; - } - - for (j = 0; j < ARRLEN(index); j++) { - if (j != i) { - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[j], (u8*)temp, TRUE)); - } - } - - return 0; -} - -s32 __osGetId(OSPfs* pfs) { -#if BUILD_VERSION < VERSION_J - int k; -#endif - u16 sum; - u16 isum; - u8 temp[BLOCKSIZE]; - __OSPackId newid; - s32 ret; - __OSPackId* id; - - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); - __osIdCheckSum((u16*)temp, &sum, &isum); - id = (__OSPackId*)temp; - - if (id->checksum != sum || id->inverted_checksum != isum) { - ret = __osCheckPackId(pfs, id); - - if (ret == PFS_ERR_ID_FATAL) { - ERRCK(__osRepairPackId(pfs, id, &newid)); - id = &newid; - } else if (ret != 0) { - return ret; - } - } - - if ((id->deviceid & 1) == 0) { - ERRCK(__osRepairPackId(pfs, id, &newid)); - id = &newid; - - if ((id->deviceid & 1) == 0) { - return PFS_ERR_DEVICE; - } - } - -#if BUILD_VERSION >= VERSION_J - bcopy(id, pfs->id, BLOCKSIZE); -#else - for (k = 0; k < ARRLEN(pfs->id); k++) { - pfs->id[k] = ((u8 *)id)[k]; - } -#endif - pfs->version = id->version; - pfs->banks = id->banks; - pfs->inode_start_page = 1 + DEF_DIR_PAGES + (2 * pfs->banks); - pfs->dir_size = 16; - pfs->inode_table = PFS_ONE_PAGE; - pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; - pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label)); - return 0; -} - -s32 __osCheckId(OSPfs* pfs) { -#if BUILD_VERSION < VERSION_J - int k; -#endif - u8 temp[BLOCKSIZE]; - s32 ret; - -#if BUILD_VERSION >= VERSION_J - if (pfs->activebank != 0) { - ret = __osPfsSelectBank(pfs, 0); - - if (ret == PFS_ERR_NEW_PACK) { - ret = __osPfsSelectBank(pfs, 0); - } - - if (ret != 0) { - return ret; - } - } -#else - SET_ACTIVEBANK_TO_ZERO; -#endif - - ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp); - - if (ret != 0) { - if (ret != PFS_ERR_NEW_PACK) { - return ret; - } - ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); - } - -#if BUILD_VERSION >= VERSION_J - if (bcmp(pfs->id, temp, BLOCKSIZE) != 0) { - return PFS_ERR_NEW_PACK; - } -#else - for (k = 0; k < ARRLEN(temp); k++) { - if (pfs->id[k] != temp[k]) - return PFS_ERR_NEW_PACK; - } -#endif - - return 0; -} - -s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) { - u8 sum; - int j; - s32 ret; - int offset; - u8* addr; - -#if BUILD_VERSION >= VERSION_J - if (flag == PFS_READ && bank == __osPfsInodeCacheBank && (pfs->channel == __osPfsInodeCacheChannel)) { - bcopy(&__osPfsInodeCache, inode, sizeof(__OSInode)); - return 0; - } -#endif - - SET_ACTIVEBANK_TO_ZERO; - - offset = (bank > 0) ? 1 : pfs->inode_start_page; - - if (flag == PFS_WRITE) { - inode->inode_page[0].inode_t.page = - __osSumcalc((u8*)&inode->inode_page[offset], (PFS_INODE_SIZE_PER_PAGE - offset) * 2); - } - - for (j = 0; j < PFS_ONE_PAGE; j++) { - addr = ((u8*)inode->inode_page + j * BLOCKSIZE); - - if (flag == PFS_WRITE) { - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); - } else { - ret = __osContRamRead(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr); - } - - if (ret != 0) { - return ret; - } - } - - if (flag == PFS_READ) { - sum = __osSumcalc((u8*)&inode->inode_page[offset], (PFS_INODE_SIZE_PER_PAGE - offset) * 2); - if (sum != inode->inode_page[0].inode_t.page) { - for (j = 0; j < PFS_ONE_PAGE; j++) { - addr = ((u8*)inode->inode_page + j * BLOCKSIZE); - ret = __osContRamRead(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr); - } - -#if BUILD_VERSION >= VERSION_J - sum = __osSumcalc((u8*)&inode->inode_page[offset], (PFS_INODE_SIZE_PER_PAGE - offset) * 2); -#endif - - if (sum != inode->inode_page[0].inode_t.page) { - return PFS_ERR_INCONSISTENT; - } - - for (j = 0; j < PFS_ONE_PAGE; j++) { - addr = ((u8*)inode->inode_page + j * BLOCKSIZE); - ret = - __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); - } - } -#if BUILD_VERSION < VERSION_J - else - { - for (j = 0; j < PFS_ONE_PAGE; j++) - { - addr = ((u8 *)inode->inode_page + j * 32); - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); - } - } -#endif - } - -#if BUILD_VERSION >= VERSION_J - __osPfsInodeCacheBank = bank; - bcopy(inode, &__osPfsInodeCache, sizeof(__OSInode)); - __osPfsInodeCacheChannel = pfs->channel; -#endif - - return 0; -} - -// This was moved into it's own file in 2.0J -#if BUILD_VERSION < VERSION_J -s32 __osPfsSelectBank(OSPfs* pfs) { - u8 temp[BLOCKSIZE]; - int i; - s32 ret = 0; - - for (i = 0; i < BLOCKSIZE; i++) { - temp[i] = pfs->activebank; - } - - ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_DETECT, temp, FALSE); - return ret; -} -#endif - -#ifdef _DEBUG -s32 __osDumpId(OSPfs* pfs) { - u8 id[BLOCKSIZE]; - __OSPackId* temp; - s32 ret; - - ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, id)); - - temp = (__OSPackId*)id; - rmonPrintf("repaired %x\n", temp->repaired); - rmonPrintf("random %x\n", temp->random); - rmonPrintf("serial_mid %llu\n", temp->serial_mid); - rmonPrintf("serial_low %llu\n", temp->serial_low); - rmonPrintf("deviceid %x\n", temp->deviceid); - rmonPrintf("banks %x\n", temp->banks); - rmonPrintf("version %x\n", temp->version); - rmonPrintf("checksum %x\n", temp->checksum); - rmonPrintf("inverted_checksum %x\n", temp->inverted_checksum); - return 0; -} -#endif diff --git a/lib/ultralib/src/io/contquery.c b/lib/ultralib/src/io/contquery.c deleted file mode 100644 index df038ce..0000000 --- a/lib/ultralib/src/io/contquery.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -s32 osContStartQuery(OSMesgQueue* mq) { - s32 ret = 0; - - __osSiGetAccess(); - - if (__osContLastCmd != CONT_CMD_REQUEST_STATUS) { - __osPackRequestData(CONT_CMD_REQUEST_STATUS); - ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - } - - ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); - __osContLastCmd = CONT_CMD_REQUEST_STATUS; - __osSiRelAccess(); - return ret; -} - -void osContGetQuery(OSContStatus* data) { - u8 pattern; - __osContGetInitData(&pattern, data); -} diff --git a/lib/ultralib/src/io/contramread.c b/lib/ultralib/src/io/contramread.c deleted file mode 100644 index 9c399ee..0000000 --- a/lib/ultralib/src/io/contramread.c +++ /dev/null @@ -1,163 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "controller.h" -#include "siint.h" - -#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) - -#if BUILD_VERSION >= VERSION_J -s32 __osPfsLastChannel = -1; - -s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { - s32 ret = 0; - s32 i; - u8* ptr; - s32 retry = 2; - - __osSiGetAccess(); - - do { - ptr = (u8*)&__osPfsPifRam; - - if (__osContLastCmd != CONT_CMD_READ_PAK || (u32)__osPfsLastChannel != channel) { - __osContLastCmd = CONT_CMD_READ_PAK; - __osPfsLastChannel = channel; - - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - READFORMAT(ptr)->dummy = CONT_CMD_NOP; - READFORMAT(ptr)->txsize = CONT_CMD_READ_PAK_TX; - READFORMAT(ptr)->rxsize = CONT_CMD_READ_PAK_RX; - READFORMAT(ptr)->cmd = CONT_CMD_READ_PAK; - READFORMAT(ptr)->datacrc = 0xFF; - - ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; - } else { - ptr += channel; - } - -#if BUILD_VERSION >= VERSION_J - READFORMAT(ptr)->addrh = address >> 3; - READFORMAT(ptr)->addrl = (u8)((address << 5) | __osContAddressCrc(address)); -#else - READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); -#endif - - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = CHNL_ERR(*READFORMAT(ptr)); - - if (!ret) { - if (__osContDataCrc(READFORMAT(ptr)->data) != READFORMAT(ptr)->datacrc) { - ret = __osPfsGetStatus(mq, channel); - - if (ret) { - break; - } else { - ret = PFS_ERR_CONTRFAIL; - } - } else { - bcopy(READFORMAT(ptr)->data, buffer, BLOCKSIZE); - } - } else { - ret = PFS_ERR_NOPACK; - } - } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); - __osSiRelAccess(); - return ret; -} -#else - -static void __osPackRamReadData(int channel, u16 address); - -s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { - s32 ret = 0; - int i; - u8* ptr = (u8*)&__osPfsPifRam; - __OSContRamReadFormat ramreadformat; - int retry = 2; - - __osSiGetAccess(); - __osContLastCmd = CONT_CMD_READ_PAK; - __osPackRamReadData(channel, address); - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - do { - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ptr = (u8*)&__osPfsPifRam; - - if (channel != 0) { - for (i = 0; i < channel; i++) { - ptr++; - } - } - - ramreadformat = *READFORMAT(ptr); - - ret = CHNL_ERR(ramreadformat); - if (ret == 0) { - u8 c = __osContDataCrc((u8*)&ramreadformat.data); - if (c != ramreadformat.datacrc) { - ret = __osPfsGetStatus(mq, channel); - - if (ret != 0) { - __osSiRelAccess(); - return ret; - } - - ret = PFS_ERR_CONTRFAIL; - } else { - for (i = 0; i < ARRLEN(ramreadformat.data); i++) { - *buffer++ = ramreadformat.data[i]; - } - } - } else { - ret = PFS_ERR_NOPACK; - } - } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); - - __osSiRelAccess(); - - return ret; -} - -static void __osPackRamReadData(int channel, u16 address) { - u8 *ptr; - __OSContRamReadFormat ramreadformat; - int i; - - ptr = (u8 *)__osPfsPifRam.ramarray; - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - ramreadformat.dummy = CONT_CMD_NOP; - ramreadformat.txsize = CONT_CMD_READ_PAK_TX; - ramreadformat.rxsize = CONT_CMD_READ_PAK_RX; - ramreadformat.cmd = CONT_CMD_READ_PAK; - ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); - ramreadformat.datacrc = CONT_CMD_NOP; - - for (i = 0; i < ARRLEN(ramreadformat.data); i++) { - ramreadformat.data[i] = CONT_CMD_NOP; - } - - if (channel != 0) { - for (i = 0; i < channel; i++) { - *ptr++ = CONT_CMD_REQUEST_STATUS; - } - } - - *(__OSContRamReadFormat *)ptr = ramreadformat; - ptr += sizeof(__OSContRamReadFormat); - ptr[0] = CONT_CMD_END; -} - -#endif - diff --git a/lib/ultralib/src/io/contramwrite.c b/lib/ultralib/src/io/contramwrite.c deleted file mode 100644 index a213049..0000000 --- a/lib/ultralib/src/io/contramwrite.c +++ /dev/null @@ -1,165 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "controller.h" -#include "siint.h" - -extern s32 __osPfsLastChannel; - -#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) - -#if BUILD_VERSION >= VERSION_J -s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { - s32 ret = 0; - s32 i; - u8* ptr; - s32 retry = 2; - u8 crc; - - if ((force != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { - return 0; - } - - __osSiGetAccess(); - - do { - ptr = (u8*)__osPfsPifRam.ramarray; - - if (__osContLastCmd != CONT_CMD_WRITE_PAK || (u32)__osPfsLastChannel != channel) { - __osContLastCmd = CONT_CMD_WRITE_PAK; - __osPfsLastChannel = channel; - - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - READFORMAT(ptr)->dummy = CONT_CMD_NOP; - READFORMAT(ptr)->txsize = CONT_CMD_WRITE_PAK_TX; - READFORMAT(ptr)->rxsize = CONT_CMD_WRITE_PAK_RX; - READFORMAT(ptr)->cmd = CONT_CMD_WRITE_PAK; - READFORMAT(ptr)->datacrc = 0xFF; - - ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; - } else { - ptr += channel; - } - -#if BUILD_VERSION >= VERSION_J - READFORMAT(ptr)->addrh = address >> 3; - READFORMAT(ptr)->addrl = ((address << 5) | __osContAddressCrc(address)); -#else - READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); -#endif - - bcopy(buffer, READFORMAT(ptr)->data, BLOCKSIZE); - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - crc = __osContDataCrc(buffer); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = CHNL_ERR(*READFORMAT(ptr)); - - if (!ret) { - if (crc != READFORMAT(ptr)->datacrc) { - if ((ret = __osPfsGetStatus(mq, channel))) { - break; - } else { - ret = PFS_ERR_CONTRFAIL; - } - } - } else { - ret = PFS_ERR_NOPACK; - } - } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); - - __osSiRelAccess(); - - return ret; -} -#else - -static void __osPackRamWriteData(int channel, u16 address, u8 *buffer); - -s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { - s32 ret = 0; - s32 i; - u8* ptr = (u8*)&__osPfsPifRam; - __OSContRamReadFormat ramreadformat; - s32 retry = 2; - u8 crc; - - if ((force != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { - return 0; - } - - __osSiGetAccess(); - __osContLastCmd = CONT_CMD_WRITE_PAK; - __osPackRamWriteData(channel, address, buffer); - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - do { - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ptr = (u8*)&__osPfsPifRam; - - if (channel != 0) { - for (i = 0; i < channel; i++) { - ptr++; - } - } - - ramreadformat = *READFORMAT(ptr); - - ret = CHNL_ERR(ramreadformat); - if (ret == 0) { - if (__osContDataCrc(buffer) != ramreadformat.datacrc) { - ret = __osPfsGetStatus(mq, channel); - - if (ret != 0) { - __osSiRelAccess(); - return ret; - } - - ret = PFS_ERR_CONTRFAIL; - } - } else { - ret = PFS_ERR_NOPACK; - } - } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); - - __osSiRelAccess(); - - return ret; -} - -static void __osPackRamWriteData(int channel, u16 address, u8 *buffer) { - u8 *ptr; - __OSContRamReadFormat ramreadformat; - int i; - - ptr = (u8 *)__osPfsPifRam.ramarray; - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - ramreadformat.dummy = CONT_CMD_NOP; - ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; - ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; - ramreadformat.cmd = CONT_CMD_WRITE_PAK; - ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); - ramreadformat.datacrc = CONT_CMD_NOP; - - for (i = 0; i < ARRLEN(ramreadformat.data); i++) { - ramreadformat.data[i] = *buffer++; - } - - if (channel != 0) { - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - } - - *(__OSContRamReadFormat *)ptr = ramreadformat; - ptr += sizeof(__OSContRamReadFormat); - ptr[0] = CONT_CMD_END; -} - -#endif diff --git a/lib/ultralib/src/io/contreaddata.c b/lib/ultralib/src/io/contreaddata.c deleted file mode 100644 index da0cac3..0000000 --- a/lib/ultralib/src/io/contreaddata.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -static void __osPackReadData(void); - -s32 osContStartReadData(OSMesgQueue* mq) { - s32 ret = 0; - - __osSiGetAccess(); - - if (__osContLastCmd != CONT_CMD_READ_BUTTON) { - __osPackReadData(); - ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - } - - ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); - __osContLastCmd = CONT_CMD_READ_BUTTON; - __osSiRelAccess(); - - return ret; -} - -void osContGetReadData(OSContPad* data) { - u8* ptr = (u8*)__osContPifRam.ramarray; - __OSContReadFormat readformat; - int i; - - for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++) { - readformat = *(__OSContReadFormat*)ptr; - data->errno = CHNL_ERR(readformat); - - if (data->errno != 0) { - continue; - } - - data->button = readformat.button; - data->stick_x = readformat.stick_x; - data->stick_y = readformat.stick_y; - } -} - -static void __osPackReadData(void) { - u8* ptr = (u8*)__osContPifRam.ramarray; - __OSContReadFormat readformat; - int i; - - for (i = 0; i < ARRLEN(__osContPifRam.ramarray); i++) { - __osContPifRam.ramarray[i] = 0; - } - - __osContPifRam.pifstatus = CONT_CMD_EXE; - readformat.dummy = CONT_CMD_NOP; - readformat.txsize = CONT_CMD_READ_BUTTON_TX; - readformat.rxsize = CONT_CMD_READ_BUTTON_RX; - readformat.cmd = CONT_CMD_READ_BUTTON; - readformat.button = 0xFFFF; - readformat.stick_x = -1; - readformat.stick_y = -1; - - for (i = 0; i < __osMaxControllers; i++) { - *(__OSContReadFormat*)ptr = readformat; - ptr += sizeof(__OSContReadFormat); - } - - *ptr = CONT_CMD_END; -} diff --git a/lib/ultralib/src/io/contreset.c b/lib/ultralib/src/io/contreset.c deleted file mode 100644 index 140088a..0000000 --- a/lib/ultralib/src/io/contreset.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -void __osPackResetData(void); - -s32 osContReset(OSMesgQueue* mq, OSContStatus* data) { - u8 pattern; - s32 ret; - - __osSiGetAccess(); - - if (__osContLastCmd != CONT_CMD_RESET) { - __osPackResetData(); - - ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - __osPackRequestData(CONT_CMD_RESET); - - ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - __osContLastCmd = CONT_CMD_RESET; - } - - ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - __osContGetInitData(&pattern, data); - __osSiRelAccess(); - - return ret; -} - -void __osPackResetData(void) { - u8* ptr; - int i; - - __osContPifRam.pifstatus = CONT_CMD_EXE; - ptr = (u8*)__osContPifRam.ramarray; - - for (i = 0; i < MAXCONTROLLERS; i++) { - *ptr++ = CONT_CMD_CHANNEL_RESET; - } - - *ptr = CONT_CMD_END; -} diff --git a/lib/ultralib/src/io/controller.c b/lib/ultralib/src/io/controller.c deleted file mode 100644 index 728c207..0000000 --- a/lib/ultralib/src/io/controller.c +++ /dev/null @@ -1,101 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -OSPifRam __osContPifRam ALIGNED(16); -u8 __osContLastCmd; -u8 __osMaxControllers; - -OSTimer __osEepromTimer; -OSMesgQueue __osEepromTimerQ ALIGNED(8); -OSMesg __osEepromTimerMsg; - -s32 __osContinitialized = 0; - -s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { - OSMesg dummy; - s32 ret = 0; - OSTime t; - OSTimer mytimer; - OSMesgQueue timerMesgQueue; - - if (__osContinitialized != 0) { - return 0; - } - - __osContinitialized = 1; - - t = osGetTime(); - if (t < OS_USEC_TO_CYCLES(500000)) { - osCreateMesgQueue(&timerMesgQueue, &dummy, 1); - osSetTimer(&mytimer, OS_USEC_TO_CYCLES(500000) - t, 0, &timerMesgQueue, &dummy); - osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); - } - - __osMaxControllers = 4; - - __osPackRequestData(CONT_CMD_REQUEST_STATUS); - - ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); - osRecvMesg(mq, &dummy, OS_MESG_BLOCK); - - ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); - osRecvMesg(mq, &dummy, OS_MESG_BLOCK); - - __osContGetInitData(bitpattern, data); - __osContLastCmd = CONT_CMD_REQUEST_STATUS; - __osSiCreateAccessQueue(); - osCreateMesgQueue(&__osEepromTimerQ, &__osEepromTimerMsg, 1); - - return ret; -} - -void __osContGetInitData(u8* pattern, OSContStatus* data) { - u8* ptr; - __OSContRequesFormat requestHeader; - int i; - u8 bits = 0; - - ptr = (u8*)__osContPifRam.ramarray; - for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestHeader), data++) { - requestHeader = *(__OSContRequesFormat*)ptr; - data->errno = CHNL_ERR(requestHeader); - - if (data->errno != 0) { - continue; - } - - data->type = requestHeader.typel << 8 | requestHeader.typeh; - data->status = requestHeader.status; - bits |= 1 << i; - } - *pattern = bits; -} - -void __osPackRequestData(u8 cmd) { - u8* ptr; - __OSContRequesFormat requestHeader; - s32 i; - - for (i = 0; i < ARRLEN(__osContPifRam.ramarray); i++) { - __osContPifRam.ramarray[i] = 0; - } - - __osContPifRam.pifstatus = CONT_CMD_EXE; - ptr = (u8*)__osContPifRam.ramarray; - requestHeader.dummy = CONT_CMD_NOP; - requestHeader.txsize = CONT_CMD_RESET_TX; - requestHeader.rxsize = CONT_CMD_RESET_RX; - requestHeader.cmd = cmd; - requestHeader.typeh = CONT_CMD_NOP; - requestHeader.typel = CONT_CMD_NOP; - requestHeader.status = CONT_CMD_NOP; - requestHeader.dummy1 = CONT_CMD_NOP; - - for (i = 0; i < __osMaxControllers; i++) { - *(__OSContRequesFormat*)ptr = requestHeader; - ptr += sizeof(requestHeader); - } - *ptr = CONT_CMD_END; -} diff --git a/lib/ultralib/src/io/controller.h b/lib/ultralib/src/io/controller.h deleted file mode 100644 index 97889e0..0000000 --- a/lib/ultralib/src/io/controller.h +++ /dev/null @@ -1,290 +0,0 @@ -#ifndef _CONTROLLER_H -#define _CONTROLLER_H - -#include "PR/os_internal.h" -#include "PR/os_version.h" -#include "PR/rcp.h" - -//should go somewhere else but -#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) -#define CHNL_ERR(format) (((format).rxsize & CHNL_ERR_MASK) >> 4) - -typedef struct -{ - /* 0x0 */ u32 ramarray[15]; - /* 0x3C */ u32 pifstatus; -} OSPifRam; - -typedef struct -{ - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; - /* 0x4 */ u16 button; - /* 0x6 */ s8 stick_x; - /* 0x7 */ s8 stick_y; -} __OSContReadFormat; - -typedef struct -{ - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; - /* 0x4 */ u8 typeh; - /* 0x5 */ u8 typel; - /* 0x6 */ u8 status; - /* 0x7 */ u8 dummy1; -} __OSContRequesFormat; - -typedef struct -{ - /* 0x0 */ u8 txsize; - /* 0x1 */ u8 rxsize; - /* 0x2 */ u8 cmd; - /* 0x3 */ u8 typeh; - /* 0x4 */ u8 typel; - /* 0x5 */ u8 status; -} __OSContRequesFormatShort; - -typedef struct -{ - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; -#if BUILD_VERSION >= VERSION_J - /* 0x4 */ u8 addrh; - /* 0x5 */ u8 addrl; -#else - /* 0x4 */ u16 address; -#endif - /* 0x6 */ u8 data[BLOCKSIZE]; - /* 0x26 */ u8 datacrc; -} __OSContRamReadFormat; - -typedef union { - /* 0x0 */ struct - { - /* 0x0 */ u8 bank; - /* 0x1 */ u8 page; - } inode_t; - /* 0x0 */ u16 ipage; -} __OSInodeUnit; - -typedef struct -{ - /* 0x0 */ u32 game_code; - /* 0x4 */ u16 company_code; - /* 0x6 */ __OSInodeUnit start_page; - /* 0x8 */ u8 status; - /* 0x9 */ s8 reserved; - /* 0xA */ u16 data_sum; - /* 0xC */ u8 ext_name[PFS_FILE_EXT_LEN]; - /* 0x10 */ u8 game_name[PFS_FILE_NAME_LEN]; -} __OSDir; - -typedef struct -{ - /* 0x0 */ __OSInodeUnit inode_page[128]; -} __OSInode; - -typedef struct -{ - /* 0x0 */ u32 repaired; - /* 0x4 */ u32 random; - /* 0x8 */ u64 serial_mid; - /* 0x10 */ u64 serial_low; - /* 0x18 */ u16 deviceid; - /* 0x1A */ u8 banks; - /* 0x1B */ u8 version; - /* 0x1C */ u16 checksum; - /* 0x1E */ u16 inverted_checksum; -} __OSPackId; - -typedef struct -{ - /* 0x0 */ u8 txsize; - /* 0x1 */ u8 rxsize; - /* 0x2 */ u8 cmd; - /* 0x3 */ u8 address; - /* 0x4 */ u8 data[EEPROM_BLOCK_SIZE]; -} __OSContEepromFormat; - -// Joybus commands -//from: http://en64.shoutwiki.com/wiki/SI_Registers_Detailed#CONT_CMD_Usage -#define CONT_CMD_REQUEST_STATUS 0 -#define CONT_CMD_READ_BUTTON 1 -#define CONT_CMD_READ_PAK 2 -#define CONT_CMD_WRITE_PAK 3 -#define CONT_CMD_READ_EEPROM 4 -#define CONT_CMD_WRITE_EEPROM 5 -#define CONT_CMD_READ36_VOICE 9 -#define CONT_CMD_WRITE20_VOICE 10 -#define CONT_CMD_READ2_VOICE 11 -#define CONT_CMD_WRITE4_VOICE 12 -#define CONT_CMD_SWRITE_VOICE 13 -#define CONT_CMD_CHANNEL_RESET 0xFD -#define CONT_CMD_RESET 0xFF - -// Bytes transmitted for each joybus command -#define CONT_CMD_REQUEST_STATUS_TX 1 -#define CONT_CMD_READ_BUTTON_TX 1 -#define CONT_CMD_READ_PAK_TX 3 -#define CONT_CMD_WRITE_PAK_TX 35 -#define CONT_CMD_READ_EEPROM_TX 2 -#define CONT_CMD_WRITE_EEPROM_TX 10 -#define CONT_CMD_READ36_VOICE_TX 3 -#define CONT_CMD_WRITE20_VOICE_TX 23 -#define CONT_CMD_READ2_VOICE_TX 3 -#define CONT_CMD_WRITE4_VOICE_TX 7 -#define CONT_CMD_SWRITE_VOICE_TX 3 -#define CONT_CMD_RESET_TX 1 - -// Bytes received for each joybus command -#define CONT_CMD_REQUEST_STATUS_RX 3 -#define CONT_CMD_READ_BUTTON_RX 4 -#define CONT_CMD_READ_PAK_RX 33 -#define CONT_CMD_WRITE_PAK_RX 1 -#define CONT_CMD_READ_EEPROM_RX 8 -#define CONT_CMD_WRITE_EEPROM_RX 1 -#define CONT_CMD_READ36_VOICE_RX 37 -#define CONT_CMD_WRITE20_VOICE_RX 1 -#define CONT_CMD_READ2_VOICE_RX 3 -#define CONT_CMD_WRITE4_VOICE_RX 1 -#define CONT_CMD_SWRITE_VOICE_RX 1 -#define CONT_CMD_RESET_RX 3 - -#define CONT_CMD_NOP 0xff -#define CONT_CMD_END 0xfe //indicates end of a command -#define CONT_CMD_EXE 1 //set pif ram status byte to this to do a command - -#define DIR_STATUS_EMPTY 0 -#define DIR_STATUS_UNKNOWN 1 -#define DIR_STATUS_OCCUPIED 2 - -// Controller accessory addresses -// https://github.com/joeldipops/TransferBoy/blob/master/docs/TransferPakReference.md - -// Accesory detection -#define CONT_ADDR_DETECT 0x8000 -// Rumble -#define CONT_ADDR_RUMBLE 0xC000 -// Controller Pak -// Transfer Pak -#define CONT_ADDR_GB_POWER 0x8000 // Same as the detection address, but semantically different -#define CONT_ADDR_GB_BANK 0xA000 -#define CONT_ADDR_GB_STATUS 0xB000 - -// Addresses sent to controller accessories are in blocks, not bytes -#define CONT_BLOCKS(x) ((x) / BLOCKSIZE) - -// Block addresses of the above -#define CONT_BLOCK_DETECT CONT_BLOCKS(CONT_ADDR_DETECT) -#define CONT_BLOCK_RUMBLE CONT_BLOCKS(CONT_ADDR_RUMBLE) -#define CONT_BLOCK_GB_POWER CONT_BLOCKS(CONT_ADDR_GB_POWER) -#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK) -#define CONT_BLOCK_GB_STATUS CONT_BLOCKS(CONT_ADDR_GB_STATUS) - - -// Transfer pak - -#define GB_POWER_ON 0x84 -#define GB_POWER_OFF 0xFE - - -typedef struct -{ - /* 0x0 */ __OSInode inode; - /* 0x100 */ u8 bank; - /* 0x101 */ u8 map[PFS_INODE_DIST_MAP]; -} __OSInodeCache; - -extern s32 __osEepStatus(OSMesgQueue *, OSContStatus *); -u16 __osSumcalc(u8 *ptr, int length); -s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum); -s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid); -s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp); -s32 __osGetId(OSPfs *pfs); -s32 __osCheckId(OSPfs *pfs); -s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank); -#if BUILD_VERSION >= VERSION_J -s32 __osPfsSelectBank(OSPfs *pfs, u8 bank); -#else -s32 __osPfsSelectBank(OSPfs *pfs); -#endif -s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page); -#if BUILD_VERSION >= VERSION_J -s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u8 bank, __OSInodeUnit *last_page); -#else -s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag); -#endif -s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank); -s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer); -s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force); -void __osContGetInitData(u8 *pattern, OSContStatus *data); -void __osPackRequestData(u8 cmd); -void __osPfsRequestData(u8 cmd); -void __osPfsGetInitData(u8* pattern, OSContStatus* data); -u8 __osContAddressCrc(u16 addr); -u8 __osContDataCrc(u8 *data); -s32 __osPfsGetStatus(OSMesgQueue *queue, int channel); - -extern u8 __osContLastCmd; -extern OSTimer __osEepromTimer; -extern OSMesg __osEepromTimerMsg; -extern OSMesgQueue __osEepromTimerQ; -extern OSPifRam __osEepPifRam; -extern OSPifRam __osContPifRam; -extern OSPifRam __osPfsPifRam; -extern u8 __osMaxControllers; - -//some version of this almost certainly existed since there's plenty of times where it's used right before a return 0 -#define ERRCK(fn) \ - ret = fn; \ - if (ret != 0) \ - return ret - -#if BUILD_VERSION >= VERSION_J - -#define SELECT_BANK(pfs, bank) \ - __osPfsSelectBank((pfs), (bank)) - -#define SET_ACTIVEBANK_TO_ZERO \ - if (pfs->activebank != 0) \ - { \ - ERRCK(__osPfsSelectBank(pfs, 0)); \ - } (void)0 - -#else - -#define SELECT_BANK(pfs, bank) \ - (pfs->activebank = (bank), \ - __osPfsSelectBank((pfs))) \ - -#define SET_ACTIVEBANK_TO_ZERO \ - if (pfs->activebank != 0) \ - { \ - pfs->activebank = 0; \ - ERRCK(__osPfsSelectBank(pfs)); \ - } (void)0 - -#endif - -#define PFS_CHECK_ID \ - if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \ - return PFS_ERR_NEW_PACK - -#define PFS_CHECK_STATUS \ - if ((pfs->status & PFS_INITIALIZED) == 0) \ - return PFS_ERR_INVALID - -#define PFS_GET_STATUS \ - __osSiGetAccess(); \ - ret = __osPfsGetStatus(queue, channel); \ - __osSiRelAccess(); \ - if (ret != 0) \ - return ret - -#endif diff --git a/lib/ultralib/src/io/controller_gbpak.h b/lib/ultralib/src/io/controller_gbpak.h deleted file mode 100644 index db98bd4..0000000 --- a/lib/ultralib/src/io/controller_gbpak.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _CONTROLLER_GBPAK_H -#define _CONTROLLER_GBPAK_H - -extern OSTimer __osGbpakTimer; -extern OSMesg __osGbpakTimerMsg; -extern OSMesgQueue __osGbpakTimerQ; - -#endif diff --git a/lib/ultralib/src/io/controller_voice.h b/lib/ultralib/src/io/controller_voice.h deleted file mode 100644 index 1b9dee6..0000000 --- a/lib/ultralib/src/io/controller_voice.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef CONTROLLER_VOICE_H -#define CONTROLLER_VOICE_H - -#include "PR/ultratypes.h" - -typedef struct { - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; - /* 0x4 */ u8 addrh; - /* 0x5 */ u8 addrl; - /* 0x6 */ u8 data[2]; - /* 0x8 */ u8 datacrc; -} __OSVoiceRead2Format; - -typedef struct { - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; - /* 0x4 */ u8 addrh; - /* 0x5 */ u8 addrl; - /* 0x6 */ u8 data[36]; - /* 0x2A */ u8 datacrc; -} __OSVoiceRead36Format; - -typedef struct { - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; - /* 0x4 */ u8 addrh; - /* 0x5 */ u8 addrl; - /* 0x6 */ u8 data[4]; - /* 0xA */ u8 datacrc; -} __OSVoiceWrite4Format; - -typedef struct { - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; - /* 0x4 */ u8 addrh; - /* 0x5 */ u8 addrl; - /* 0x6 */ u8 data[20]; - /* 0x1A */ u8 datacrc; -} __OSVoiceWrite20Format; - -typedef struct { - /* 0x0 */ u8 txsize; - /* 0x1 */ u8 rxsize; - /* 0x2 */ u8 cmd; - /* 0x3 */ u8 data; - /* 0x4 */ u8 scrc; - /* 0x5 */ u8 datacrc; -} __OSVoiceSWriteFormat; - -#endif // CONTROLLER_VOICE_H diff --git a/lib/ultralib/src/io/contsetch.c b/lib/ultralib/src/io/contsetch.c deleted file mode 100644 index 0cababd..0000000 --- a/lib/ultralib/src/io/contsetch.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -s32 osContSetCh(u8 ch) { - s32 ret = 0; - - __osSiGetAccess(); - - if (ch > MAXCONTROLLERS) { - __osMaxControllers = MAXCONTROLLERS; - } else { - __osMaxControllers = ch; - } - - __osContLastCmd = CONT_CMD_END; - __osSiRelAccess(); - return ret; -} diff --git a/lib/ultralib/src/io/crc.c b/lib/ultralib/src/io/crc.c deleted file mode 100644 index 3293b2d..0000000 --- a/lib/ultralib/src/io/crc.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "PR/os_internal.h" - -#if BUILD_VERSION >= VERSION_J - -u8 __osContAddressCrc(u16 addr) { - u32 temp = 0; - u32 i = 0x400; - - do { - temp <<= 1; - - if ((u32)addr & i) { - if (temp & 0x20) { - temp ^= 0x14; - } else { - ++temp; - } - } else if (temp & 0x20) { - temp ^= 0x15; - } - - i >>= 1; - } while (i != 0); - - i = 5; - - do { - temp <<= 1; - if (temp & 0x20) { - temp ^= 0x15; - } - } while (--i != 0); - - return temp & 0x1F; -} - -u8 __osContDataCrc(u8* data) { - u32 temp = 0; - u32 i; - u32 j; - - for (i = 0x20; i; --i) { - for (j = 0x80; j; j >>= 1) { - temp <<= 1; - - if ((*data & j) != 0) { - if ((temp & 0x100) != 0) { - temp ^= 0x84; - } else { - ++temp; - } - } else if (temp & 0x100) { - temp ^= 0x85; - } - } - - data++; - } - do { - temp <<= 1; - - if (temp & 0x100) { - temp ^= 0x85; - } - } while (++i < 8U); - - return temp; -} - -#else - -u8 __osContAddressCrc(u16 addr) { - u8 temp = 0; - u8 temp2; - int i; - - for (i = 0; i < 16; i++) { - temp2 = (temp & 0x10) ? 0x15 : 0; - - temp <<= 1; - temp |= (u8)((addr & 0x400) ? 1 : 0); - addr <<= 1; - temp ^= temp2; - } - - return temp & 0x1f; -} - -u8 __osContDataCrc(u8 *data) { - u8 temp = 0; - u8 temp2; - int i; - int j; - - for (i = 0; i <= 32; i++) { - for (j = 7; j > -1; j--) { - temp2 = (temp & 0x80) ? 0x85 : 0; - - temp <<= 1; - - if (i == 32) { - temp &= -1; - } else { - temp |= ((*data & (1 << j)) ? 1 : 0); - } - - temp ^= temp2; - } - data++; - } - return temp; -} - -#endif diff --git a/lib/ultralib/src/io/devmgr.c b/lib/ultralib/src/io/devmgr.c deleted file mode 100644 index 616dee5..0000000 --- a/lib/ultralib/src/io/devmgr.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "piint.h" - -void __osDevMgrMain(void* args) { - OSIoMesg* mb; - OSMesg em; - OSMesg dummy; - s32 ret; - OSDevMgr* dm; - s32 messageSend = 0; - - dm = (OSDevMgr*)args; - mb = NULL; - ret = 0; - - while (TRUE) { - osRecvMesg(dm->cmdQueue, (OSMesg)&mb, OS_MESG_BLOCK); - - if (mb->piHandle != NULL && mb->piHandle->type == DEVICE_TYPE_64DD && - (mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0 || - mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_1)) { - __OSBlockInfo* blockInfo; - __OSTranxInfo* info; - info = &mb->piHandle->transferInfo; - blockInfo = &info->block[info->blockNum]; - info->sectorNum = -1; - - if (info->transferMode != LEO_SECTOR_MODE) { - blockInfo->dramAddr = (void*)((u32)blockInfo->dramAddr - blockInfo->sectorSize); - } - - if (info->transferMode == LEO_TRACK_MODE && mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0) { - messageSend = 1; - } else { - messageSend = 0; - } - - osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); - __osResetGlobalIntMask(OS_IM_PI); - __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, (info->bmCtlShadow | 0x80000000)); - - readblock1: - osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); - info = &mb->piHandle->transferInfo; - blockInfo = &info->block[info->blockNum]; - - if (blockInfo->errStatus == LEO_ERROR_29) { - u32 stat; - __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); - __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow); - __osEPiRawReadIo(mb->piHandle, LEO_STATUS, &stat); - - if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { - __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); - } - - blockInfo->errStatus = LEO_ERROR_4; - IO_WRITE(PI_STATUS_REG, PI_CLR_INTR); - __osSetGlobalIntMask(OS_IM_PI | SR_IBIT4); - } - - osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); - - if (messageSend == 1 && mb->piHandle->transferInfo.block[0].errStatus == LEO_ERROR_GOOD) { - messageSend = 0; - goto readblock1; - } - - osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); - if (mb->piHandle->transferInfo.blockNum == 1) { - osYieldThread(); - } - } else { - switch (mb->hdr.type) { - case OS_MESG_TYPE_DMAREAD: - osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); - ret = dm->dma(OS_READ, mb->devAddr, mb->dramAddr, mb->size); - break; - case OS_MESG_TYPE_DMAWRITE: - osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); - ret = dm->dma(OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); - break; - case OS_MESG_TYPE_EDMAREAD: - osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); - ret = dm->edma(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr, mb->size); - break; - case OS_MESG_TYPE_EDMAWRITE: - osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); - ret = dm->edma(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); - break; - case OS_MESG_TYPE_LOOPBACK: - osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); - ret = -1; - break; - default: - ret = -1; - break; - } - - if (ret == 0) { - osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); - osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); - osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); - } - } - } -} diff --git a/lib/ultralib/src/io/dp.c b/lib/ultralib/src/io/dp.c deleted file mode 100644 index e636217..0000000 --- a/lib/ultralib/src/io/dp.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -int __osDpDeviceBusy(void) { - register u32 stat = IO_READ(DPC_STATUS_REG); - - if (stat & DPC_STATUS_DMA_BUSY) { - return TRUE; - } else { - return FALSE; - } -} diff --git a/lib/ultralib/src/io/dpctr.c b/lib/ultralib/src/io/dpctr.c deleted file mode 100644 index a53b030..0000000 --- a/lib/ultralib/src/io/dpctr.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -void osDpGetCounters(u32* array) { - *array++ = IO_READ(DPC_CLOCK_REG); - *array++ = IO_READ(DPC_BUFBUSY_REG); - *array++ = IO_READ(DPC_PIPEBUSY_REG); - *array++ = IO_READ(DPC_TMEM_REG); -} diff --git a/lib/ultralib/src/io/dpgetstat.c b/lib/ultralib/src/io/dpgetstat.c deleted file mode 100644 index af3ccee..0000000 --- a/lib/ultralib/src/io/dpgetstat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -u32 osDpGetStatus() { - return IO_READ(DPC_STATUS_REG); -} diff --git a/lib/ultralib/src/io/dpsetnextbuf.c b/lib/ultralib/src/io/dpsetnextbuf.c deleted file mode 100644 index 6314472..0000000 --- a/lib/ultralib/src/io/dpsetnextbuf.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/rcp.h" -#include "../os/osint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 osDpSetNextBuffer(void* bufPtr, u64 size) { - register u32 stat; - -#ifdef _DEBUG - if ((u32)bufPtr & 0x7) { - __osError(ERR_OSDPSETNEXTBUFFER_ADDR, 1, bufPtr); - return -1; - } - if (size & 0x7) { - __osError(ERR_OSDPSETNEXTBUFFER_SIZE, 1, size); - return -1; - } -#endif - - if (__osDpDeviceBusy()) { - return -1; - } - - IO_WRITE(DPC_STATUS_REG, DPC_CLR_XBUS_DMEM_DMA); - - while (TRUE) { - stat = IO_READ(DPC_STATUS_REG); - if ((stat & DPC_STATUS_XBUS_DMEM_DMA) == 0) { - break; - } - } - - IO_WRITE(DPC_START_REG, osVirtualToPhysical(bufPtr)); - IO_WRITE(DPC_END_REG, osVirtualToPhysical(bufPtr) + size); - return 0; -} diff --git a/lib/ultralib/src/io/dpsetstat.c b/lib/ultralib/src/io/dpsetstat.c deleted file mode 100644 index 5b53867..0000000 --- a/lib/ultralib/src/io/dpsetstat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osDpSetStatus(u32 data) { - IO_WRITE(DPC_STATUS_REG, data); -} diff --git a/lib/ultralib/src/io/driverominit.c b/lib/ultralib/src/io/driverominit.c deleted file mode 100644 index d73d349..0000000 --- a/lib/ultralib/src/io/driverominit.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "macros.h" - -OSPiHandle DriveRomHandle ALIGNED(8); - -OSPiHandle *osDriveRomInit() { - u32 saveMask; - - if (DriveRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR1)) { - return &DriveRomHandle; - } - - DriveRomHandle.type = DEVICE_TYPE_BULK; - DriveRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR1); - DriveRomHandle.latency = 64; - DriveRomHandle.pulse = 7; - DriveRomHandle.pageSize = 7; - DriveRomHandle.relDuration = 2; - DriveRomHandle.domain = PI_DOMAIN1; - DriveRomHandle.speed = 0; - - bzero(&DriveRomHandle.transferInfo, sizeof(__OSTranxInfo)); - - saveMask = __osDisableInt(); - DriveRomHandle.next = __osPiTable; - __osPiTable = &DriveRomHandle; - __osRestoreInt(saveMask); - - return &DriveRomHandle; -} diff --git a/lib/ultralib/src/io/epidma.c b/lib/ultralib/src/io/epidma.c deleted file mode 100644 index 06a9f69..0000000 --- a/lib/ultralib/src/io/epidma.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { - register s32 ret; - - if (!__osPiDevMgr.active) { -#ifdef _DEBUG - __osError(ERR_OSPISTARTDMA_PIMGR, 0); -#endif - return -1; - } - -#ifdef _DEBUG - if ((mb->hdr.pri != OS_MESG_PRI_NORMAL) && (mb->hdr.pri != OS_MESG_PRI_HIGH)) { - __osError(ERR_OSPISTARTDMA_PRI, 1, mb->hdr.pri); - return -1; - } - - if ((direction != OS_READ) && (direction != OS_WRITE)) { - __osError(ERR_OSPISTARTDMA_DIR, 1, direction); - return -1; - } - - if (mb->devAddr & 0x1) { - __osError(ERR_OSPISTARTDMA_DEVADDR, 1, mb->devAddr); - return -1; - } - - if ((u32)mb->dramAddr & 0x7) { - __osError(ERR_OSPISTARTDMA_ADDR, 1, mb->dramAddr); - return -1; - } - - if (mb->size & 0x1) { - __osError(ERR_OSPISTARTDMA_SIZE, 1, mb->size); - return -1; - } - - if ((mb->size == 0) || (mb->size > (16 * 1024 * 1024))) { - __osError(ERR_OSPISTARTDMA_RANGE, 1, mb->size); - return -1; - } -#endif - - mb->piHandle = pihandle; - - if (direction == OS_READ) { - mb->hdr.type = OS_MESG_TYPE_EDMAREAD; - } else { - mb->hdr.type = OS_MESG_TYPE_EDMAWRITE; - } - - if (mb->hdr.pri == OS_MESG_PRI_HIGH) { - ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); - } else { - ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); - } - - return ret; -} diff --git a/lib/ultralib/src/io/epigettype.c b/lib/ultralib/src/io/epigettype.c deleted file mode 100644 index c94012c..0000000 --- a/lib/ultralib/src/io/epigettype.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "piint.h" - -s32 osEPiGetDeviceType(OSPiHandle* pihandle, OSPiInfo* info) { - info->type = pihandle->type; - info->address = pihandle->baseAddress; - return 0; -} diff --git a/lib/ultralib/src/io/epilinkhandle.c b/lib/ultralib/src/io/epilinkhandle.c deleted file mode 100644 index 5f51854..0000000 --- a/lib/ultralib/src/io/epilinkhandle.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "piint.h" - -s32 osEPiLinkHandle(OSPiHandle* EPiHandle) { - u32 saveMask = __osDisableInt(); - - EPiHandle->next = __osPiTable; - __osPiTable = EPiHandle; - - __osRestoreInt(saveMask); - return 0; -} diff --git a/lib/ultralib/src/io/epirawdma.c b/lib/ultralib/src/io/epirawdma.c deleted file mode 100644 index 69a404d..0000000 --- a/lib/ultralib/src/io/epirawdma.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osEPiRawStartDma(OSPiHandle* pihandle, s32 direction, u32 devAddr, void* dramAddr, u32 size) { - u32 stat; - u32 domain; - -#ifdef _DEBUG - if ((direction != OS_READ) && (direction != OS_WRITE)) { - __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); - return -1; - } - - if (devAddr & 0x1) { - __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); - return -1; - } - - if ((u32)dramAddr & 0x7) { - __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); - return -1; - } - - if (size & 0x1) { - __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); - return -1; - } - - if ((size == 0) || (size > (16 * 1024 * 1024))) { - __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); - return -1; - } -#endif - - EPI_SYNC(pihandle, stat, domain); - IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); - IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(pihandle->baseAddress | devAddr)); - - switch (direction) { - case OS_READ: - IO_WRITE(PI_WR_LEN_REG, size - 1); - break; - case OS_WRITE: - IO_WRITE(PI_RD_LEN_REG, size - 1); - break; - default: - return -1; - } - return 0; -} diff --git a/lib/ultralib/src/io/epirawread.c b/lib/ultralib/src/io/epirawread.c deleted file mode 100644 index 500a2ce..0000000 --- a/lib/ultralib/src/io/epirawread.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 28 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osEPiRawReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data) { - register u32 stat; - register u32 domain; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIRAWREADIO, 1, devAddr); - return -1; - } -#endif - assert(data != NULL); - - EPI_SYNC(pihandle, stat, domain); - *data = IO_READ(pihandle->baseAddress | devAddr); - - return 0; -} diff --git a/lib/ultralib/src/io/epirawwrite.c b/lib/ultralib/src/io/epirawwrite.c deleted file mode 100644 index 79fba31..0000000 --- a/lib/ultralib/src/io/epirawwrite.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osEPiRawWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data) { - register u32 stat; - register u32 domain; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIRAWWRITEIO, 1, devAddr); - return -1; - } -#endif - - EPI_SYNC(pihandle, stat, domain); - IO_WRITE(pihandle->baseAddress | devAddr, data); - - return 0; -} diff --git a/lib/ultralib/src/io/epiread.c b/lib/ultralib/src/io/epiread.c deleted file mode 100644 index 08cd0be..0000000 --- a/lib/ultralib/src/io/epiread.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -s32 osEPiReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data) { - register s32 ret; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIREADIO, 1, devAddr); - return -1; - } -#endif - - __osPiGetAccess(); - ret = __osEPiRawReadIo(pihandle, devAddr, data); - __osPiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/io/epiwrite.c b/lib/ultralib/src/io/epiwrite.c deleted file mode 100644 index 42a239e..0000000 --- a/lib/ultralib/src/io/epiwrite.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -s32 osEPiWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data) { - register s32 ret; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIWRITEIO, 1, devAddr); - return -1; - } -#endif - - __osPiGetAccess(); - ret = __osEPiRawWriteIo(pihandle, devAddr, data); - __osPiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/io/gbpakcheckconnector.c b/lib/ultralib/src/io/gbpakcheckconnector.c deleted file mode 100644 index 8eb3298..0000000 --- a/lib/ultralib/src/io/gbpakcheckconnector.c +++ /dev/null @@ -1,131 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "controller.h" - -s32 osGbpakCheckConnector(OSPfs* pfs, u8* status) { - s32 ret; - s32 bufn = 1; - s32 oldbufn = 0; - u16 address = 0; - u16 oldaddr = 0; - u16 daddr = 0; - u16 num; - u8 buf[3][4][BLOCKSIZE]; - u8 buf_status[3][4]; - - ret = osGbpakGetStatus(pfs, status); - - if (ret == PFS_ERR_NEW_GBCART) { - ret = osGbpakGetStatus(pfs, status); - } - - if (ret == PFS_ERR_NEW_GBCART) { - return PFS_ERR_CONTRFAIL; - } else if (ret == 0) { - if (!(*status & OS_GBPAK_POWER)) { - ERRCK(osGbpakPower(pfs, OS_GBPAK_POWER_ON)); - } - - bzero(buf_status, sizeof(buf_status)); - - for (address = 0x80; address <= 0x4000; address <<= 1) { - num = 0; - daddr = 0; - - do { - ERRCK(osGbpakReadWrite(pfs, OS_READ, address + daddr, buf[bufn][num], BLOCKSIZE)); - buf_status[bufn][num] = 1; - - if (buf_status[oldbufn][num] == 0) { - ret = osGbpakReadWrite(pfs, OS_READ, oldaddr + daddr, buf[oldbufn][num], BLOCKSIZE); - - if (ret != 0) { - return ret; - } else { - buf_status[oldbufn][num] = 1; - } - } - - if (bcmp(buf[bufn][num], buf[oldbufn][num], BLOCKSIZE) != 0) { - num = 0; - break; - } - - daddr += BLOCKSIZE; - } while (num++ < ARRLEN(buf[0]) - 1); - - if (num != 0) { - return PFS_ERR_CONTRFAIL; - } - - if (oldbufn != 0) { - num = 0; - daddr = 0; - - do { - if (buf_status[bufn][num] == 0) { - ERRCK(osGbpakReadWrite(pfs, OS_READ, address + daddr, buf[bufn][num], BLOCKSIZE)); - buf_status[bufn][num] = 1; - } - - if (buf_status[0][num] == 0) { - ret = osGbpakReadWrite(pfs, OS_READ, daddr, buf[0][num], BLOCKSIZE); - if (ret != 0) { - return ret; - } else { - buf_status[0][num] = 1; - } - } - - if (bcmp(buf[bufn][num], buf[0][num], BLOCKSIZE)) { - num = 0; - break; - } - - daddr += BLOCKSIZE; - } while (num++ < ARRLEN(buf_status[0]) - 1); - } - - if (num != 0) { - return PFS_ERR_CONTRFAIL; - } - - if (oldbufn != 0) { - bzero(buf_status[oldbufn], ARRLEN(buf_status[oldbufn])); - } - - oldaddr = address; - oldbufn = bufn; - bufn ^= 3; - } - - if ((pfs->dir_size >= 2) || (pfs->version == 2)) { - num = 0; - daddr = 0; - - do { - ERRCK(osGbpakReadWrite(pfs, OS_READ, daddr + 0xA000, buf[bufn][num], BLOCKSIZE)); - ERRCK(osGbpakReadWrite(pfs, OS_READ, daddr + 0x2000, buf[oldbufn][num], BLOCKSIZE)); - - if (bcmp(buf[bufn][num], buf[oldbufn][num], BLOCKSIZE)) { - num = 0; - break; - } - - daddr += BLOCKSIZE; - } while (num++ < ARRLEN(buf[0]) - 1); - - if (num != 0) { - return PFS_ERR_CONTRFAIL; - } - } - - ret = osGbpakGetStatus(pfs, status); - - if (ret == PFS_ERR_NEW_GBCART) { - ret = PFS_ERR_CONTRFAIL; - } - } - - return ret; -} diff --git a/lib/ultralib/src/io/gbpakgetbank.c b/lib/ultralib/src/io/gbpakgetbank.c deleted file mode 100644 index a2e5f38..0000000 --- a/lib/ultralib/src/io/gbpakgetbank.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 __osGbpakGetBank(OSPfs* pfs, u8* bank) { - s32 ret; - u32 temp[BLOCKSIZE / sizeof(u32)]; - - ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, (u8*)temp); - - if (ret == PFS_ERR_NEW_PACK) { - ret = osGbpakInit(pfs->queue, pfs, pfs->channel); - - if (ret == 0) { - ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, (u8*)temp); - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - } - } - - if (ret == 0) { - *bank = ((u8*)temp)[0]; - pfs->banks = *bank; - } - - return ret; -} diff --git a/lib/ultralib/src/io/gbpakgetstatus.c b/lib/ultralib/src/io/gbpakgetstatus.c deleted file mode 100644 index d17d15c..0000000 --- a/lib/ultralib/src/io/gbpakgetstatus.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osGbpakGetStatus(OSPfs* pfs, u8* status) { - s32 ret; - s32 i; - u32 temp[BLOCKSIZE / sizeof(u32)]; - - ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_POWER, (u8*)temp); - - if ((ret == PFS_ERR_NEW_PACK) || (((u8*)temp)[BLOCKSIZE - 1] != GB_POWER_ON)) { - ERRCK(osGbpakInit(pfs->queue, pfs, pfs->channel)); - } - - ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_STATUS, (u8*)temp); - - if (ret == 0) { - ERRCK(__osPfsGetStatus(pfs->queue, pfs->channel)); - - *status = ((u8*)temp)[0]; - - for (i = 1; i < BLOCKSIZE; i++) { - *status |= ((u8*)temp)[i]; - } - - *status &= (OS_GBPAK_GBCART_PULL | OS_GBPAK_RSTB_DETECTION); - *status |= ((u8*)temp)[BLOCKSIZE - 1]; - - if (!(*status & OS_GBPAK_GBCART_ON)) { - ret = PFS_ERR_NO_GBCART; - } else if (*status & OS_GBPAK_GBCART_PULL) { - ret = PFS_ERR_NEW_GBCART; - } - } else if (ret == 2) { - ret = PFS_ERR_CONTRFAIL; - } - - return ret; -} diff --git a/lib/ultralib/src/io/gbpakinit.c b/lib/ultralib/src/io/gbpakinit.c deleted file mode 100644 index 102d962..0000000 --- a/lib/ultralib/src/io/gbpakinit.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "controller.h" -#include "controller_gbpak.h" - -OSTimer __osGbpakTimer; -OSMesgQueue __osGbpakTimerQ ALIGNED(8); -OSMesg __osGbpakTimerMsg; - -s32 osGbpakInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { - int i; - s32 ret; - u8 temp[BLOCKSIZE]; - - pfs->status = 0; - - // Turn off the transfer pak - for (i = 0; i < BLOCKSIZE; temp[i++] = GB_POWER_OFF) { - ; - } - - ret = __osContRamWrite(mq, channel, CONT_BLOCK_GB_POWER, temp, FALSE); - if (ret == PFS_ERR_NEW_PACK) { - ret = __osContRamWrite(mq, channel, CONT_BLOCK_GB_POWER, temp, FALSE); - } - - if (ret != 0) { - return ret; - } - - ret = __osContRamRead(mq, channel, CONT_BLOCK_GB_POWER, temp); - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } else { - // Check if the power is still off as set earlier - if (temp[BLOCKSIZE - 1] == GB_POWER_OFF) { - return PFS_ERR_DEVICE; - } - } - - // Turn on the transfer pak - for (i = 0; i < BLOCKSIZE; temp[i++] = GB_POWER_ON) { - ; - } - - ret = __osContRamWrite(mq, channel, CONT_BLOCK_GB_POWER, temp, FALSE); - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } - - ret = __osContRamRead(mq, channel, CONT_BLOCK_GB_POWER, temp); - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } else { - // Check if the power is still on as set earlier - if (temp[BLOCKSIZE - 1] != GB_POWER_ON) { - return PFS_ERR_DEVICE; - } - } - - ERRCK(__osPfsGetStatus(mq, channel)); - - osCreateMesgQueue(&__osGbpakTimerQ, &__osGbpakTimerMsg, 1); - osSetTimer(&__osGbpakTimer, OS_USEC_TO_CYCLES(192000), 0, &__osGbpakTimerQ, &__osGbpakTimerMsg); - osRecvMesg(&__osGbpakTimerQ, NULL, OS_MESG_BLOCK); - pfs->queue = mq; - pfs->status = PFS_GBPAK_INITIALIZED; - pfs->channel = channel; - pfs->activebank = 0x84; - pfs->banks = 0xFF; - pfs->version = 0xFF; - pfs->dir_size = 0xFF; - - return 0; -} diff --git a/lib/ultralib/src/io/gbpakpower.c b/lib/ultralib/src/io/gbpakpower.c deleted file mode 100644 index 3d4a8f4..0000000 --- a/lib/ultralib/src/io/gbpakpower.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "controller_gbpak.h" - -s32 osGbpakPower(OSPfs* pfs, s32 flag) { - s32 i; - s32 ret; - u8 temp[BLOCKSIZE]; - - for (i = 0; i < BLOCKSIZE; temp[i++] = (u8)flag) { - ; - } - - ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_STATUS, temp, 0); - - if (ret == PFS_ERR_NEW_PACK) { - ret = osGbpakInit(pfs->queue, pfs, pfs->channel); - - if (ret == 0) { - ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_STATUS, temp, 0); - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - } - } - - if (flag != OS_GBPAK_POWER_OFF) { - osSetTimer(&__osGbpakTimer, OS_USEC_TO_CYCLES(120000), 0, &__osGbpakTimerQ, &__osGbpakTimerMsg); - osRecvMesg(&__osGbpakTimerQ, NULL, OS_MESG_BLOCK); - } - - return ret; -} diff --git a/lib/ultralib/src/io/gbpakreadid.c b/lib/ultralib/src/io/gbpakreadid.c deleted file mode 100644 index 3e2fa19..0000000 --- a/lib/ultralib/src/io/gbpakreadid.c +++ /dev/null @@ -1,97 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "controller.h" -#include "os_version.h" - -s32 osGbpakReadId(OSPfs* pfs, OSGbpakId* id, u8* status) { - s32 i; - s32 ret; - u8 isum; - u8 buf[96]; -#if BUILD_VERSION >= VERSION_K - u8 temp[32]; -#endif - static u8 nintendo[] = { 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83, - 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E, - 0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDD, 0xD9, 0x99, 0xBB, 0xBB, 0x67, 0x63, - 0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E }; - static u8 mmc_type[] = { 0x00, 0x01, 0x01, 0x01, 0xFF, 0x02, 0x02, 0xFF, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03 }; - - ret = osGbpakGetStatus(pfs, status); - - if (ret == PFS_ERR_NEW_GBCART) { - ret = osGbpakGetStatus(pfs, status); - } - - if (ret == PFS_ERR_NEW_GBCART) { - return PFS_ERR_CONTRFAIL; - } else if (ret == 0) { - if (!(*status & OS_GBPAK_POWER)) { - ERRCK(osGbpakPower(pfs, OS_GBPAK_POWER_ON)); - } - - ERRCK(osGbpakReadWrite(pfs, OS_READ, 0x100U, buf, ARRLEN(buf))); - - ret = osGbpakGetStatus(pfs, status); - - if (ret == PFS_ERR_NEW_GBCART) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } - - if (!(*status & OS_GBPAK_RSTB_STATUS)) { - return PFS_ERR_CONTRFAIL; - } - -#if BUILD_VERSION >= VERSION_K - if (bcmp(nintendo, buf + 4, ARRLEN(nintendo))) { - for (i = 0; i < ARRLEN(temp); temp[i++] = 0) { - ; - } - - ERRCK(osGbpakReadWrite(pfs, OS_WRITE, 0x6000U, temp, ARRLEN(temp))); - ret = osGbpakReadWrite(pfs, OS_READ, 0x100U, buf, ARRLEN(buf)); - ERRCK(osGbpakReadWrite(pfs, OS_READ, 0x100U, buf, ARRLEN(buf))); - - ret = osGbpakGetStatus(pfs, status); - - if (ret == PFS_ERR_NEW_GBCART) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } - - if (bcmp(nintendo, buf + 4, ARRLEN(nintendo))) { - return 4; - } - } -#else - if (bcmp(nintendo, buf + 4, ARRLEN(nintendo))) { - return 4; - } -#endif - for (i = 0x34, isum = 0; i < 0x4E; i++) { - isum += buf[i]; - } - - if ((isum + 0x19) & 0xFF) { - return 4; - } - - bcopy(buf, id, 0x50); - - if (id->cart_type < 0x14) { - pfs->version = (int)mmc_type[id->cart_type]; - } - - pfs->dir_size = (int)id->ram_size; - } - - return ret; -} diff --git a/lib/ultralib/src/io/gbpakreadwrite.c b/lib/ultralib/src/io/gbpakreadwrite.c deleted file mode 100644 index a6d4b02..0000000 --- a/lib/ultralib/src/io/gbpakreadwrite.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "os_version.h" - -s32 __osGbpakSetBank(OSPfs* pfs, u8 bank); - -s32 osGbpakReadWrite(OSPfs* pfs, u16 flag, u16 address, u8* buffer, u16 size) { - s32 i; - s32 ret; - u8 bank; - - bank = (u8)(address >> 0xE); - - if (bank != pfs->banks) { - ret = __osGbpakSetBank(pfs, bank); - - if (ret != 0) { - return ret; - } - } - -#if BUILD_VERSION >= VERSION_K - if (size == 0) { - return 0; - } -#endif - - size = (u16)(size >> 5); - address = (u16)((address | 0xC000) >> 5); - - if (flag == 1) { - for (i = 0; i < (s32)size; i++, buffer += BLOCKSIZE) { - ret = __osContRamWrite(pfs->queue, pfs->channel, address, buffer, 0); - - if (ret != 0) { - break; - } - - if ((++address >= 0x800) && (i < (s32)(size - 1))) { - ret = __osGbpakSetBank(pfs, ++bank); - - if (ret != 0) { - break; - } - - address = 0x600U; - } - } - } else { - for (i = 0; i < (s32)size; i++, buffer += BLOCKSIZE) { - ret = __osContRamRead(pfs->queue, pfs->channel, address, buffer); - - if (ret != 0) { - break; - } - - if (++address >= 0x800 && (i < (s32)(size - 1))) { - ret = __osGbpakSetBank(pfs, ++bank); - - if (ret != 0) { - break; - } - - address = 0x600U; - } - } - } - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - return ret; -} diff --git a/lib/ultralib/src/io/gbpaksetbank.c b/lib/ultralib/src/io/gbpaksetbank.c deleted file mode 100644 index 7a08646..0000000 --- a/lib/ultralib/src/io/gbpaksetbank.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 __osGbpakSetBank(OSPfs* pfs, u8 bank) { - int i; - s32 ret; - u8 temp[BLOCKSIZE]; - - if (bank > 2) { - return PFS_ERR_INVALID; - } - - for (i = 0; i < BLOCKSIZE; temp[i++] = bank) { - ; - } - - ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, temp, FALSE); - - if (ret == PFS_ERR_NEW_PACK) { - ret = osGbpakInit(pfs->queue, pfs, pfs->channel); - - if (ret == 0) { - ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, temp, FALSE); - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - } - } - - if (ret == 0) { - pfs->banks = bank; - } - - return ret; -} diff --git a/lib/ultralib/src/io/leodiskinit.c b/lib/ultralib/src/io/leodiskinit.c deleted file mode 100644 index e9f140b..0000000 --- a/lib/ultralib/src/io/leodiskinit.c +++ /dev/null @@ -1,36 +0,0 @@ -// This file was removed in 2.0J -#include "PR/os_internal.h" -#include "PR/os_libc.h" -#include "PR/rcp.h" -#include "macros.h" - -OSPiHandle LeoDiskHandle ALIGNED(8); -OSPiHandle *__osDiskHandle; - -OSPiHandle *osLeoDiskInit() { - u32 saveMask; - - LeoDiskHandle.type = DEVICE_TYPE_64DD; - LeoDiskHandle.baseAddress = PHYS_TO_K1(PI_DOM2_ADDR1); - LeoDiskHandle.latency = 3; - LeoDiskHandle.pulse = 6; - LeoDiskHandle.pageSize = 6; - LeoDiskHandle.relDuration = 2; - LeoDiskHandle.domain = PI_DOMAIN2; - - IO_WRITE(PI_BSD_DOM2_LAT_REG, LeoDiskHandle.latency); - IO_WRITE(PI_BSD_DOM2_PWD_REG, LeoDiskHandle.pulse); - IO_WRITE(PI_BSD_DOM2_PGS_REG, LeoDiskHandle.pageSize); - IO_WRITE(PI_BSD_DOM2_RLS_REG, LeoDiskHandle.relDuration); - LeoDiskHandle.speed = 0; - - bzero(&LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo)); - - saveMask = __osDisableInt(); - LeoDiskHandle.next = __osPiTable; - __osPiTable = &LeoDiskHandle; - __osDiskHandle = &LeoDiskHandle; - __osRestoreInt(saveMask); - - return &LeoDiskHandle; -} diff --git a/lib/ultralib/src/io/leointerrupt.c b/lib/ultralib/src/io/leointerrupt.c deleted file mode 100644 index 0f7adae..0000000 --- a/lib/ultralib/src/io/leointerrupt.c +++ /dev/null @@ -1,194 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "../os/osint.h" -#include "piint.h" -#include "macros.h" - -extern OSPiHandle *__osDiskHandle; - -u8 leoDiskStack[OS_PIM_STACKSIZE] ALIGNED(16); - -static void __osLeoAbnormalResume(void); -static void __osLeoResume(void); - -s32 __osLeoInterrupt() { - u32 stat = 0; - volatile u32 pi_stat; - u32 bm_stat; - __OSTranxInfo *info = &__osDiskHandle->transferInfo; - __OSBlockInfo *blockInfo = &info->block[info->blockNum]; - - pi_stat = IO_READ(PI_STATUS_REG); - if (pi_stat & PI_STATUS_DMA_BUSY) { - __OSGlobalIntMask = __OSGlobalIntMask & ~SR_IBIT4; //cart interrupt - blockInfo->errStatus = LEO_ERROR_29; - __osLeoResume(); - return 1; - } - - WAIT_ON_IOBUSY(pi_stat); - stat = IO_READ(LEO_STATUS); - if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); - blockInfo->errStatus = LEO_ERROR_GOOD; - return 0; - } - - if (info->cmdType == LEO_CMD_TYPE_2) { - return 1; - } - - if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR) { - WAIT_ON_IOBUSY(pi_stat); - stat = IO_READ(LEO_STATUS); - blockInfo->errStatus = LEO_ERROR_22; - __osLeoResume(); - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - return 1; - } - - if (info->cmdType == LEO_CMD_TYPE_1) { - if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { - if (info->sectorNum + 1 != info->transferMode * 85) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - blockInfo->errStatus = LEO_ERROR_GOOD; - __osLeoResume(); - return 1; - } else { - blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr + blockInfo->sectorSize); - info->sectorNum++; - osEPiRawStartDma(__osDiskHandle, OS_WRITE, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); - return 1; - } - } else if (info->cmdType == LEO_CMD_TYPE_0) { - if (info->transferMode == LEO_SECTOR_MODE) { - if (info->sectorNum > (s32)blockInfo->C1ErrNum + 17) { - blockInfo->errStatus = LEO_ERROR_GOOD; - __osLeoAbnormalResume(); - return 1; - } - - if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { - blockInfo->errStatus = LEO_ERROR_23; - __osLeoAbnormalResume(); - return 1; - } - } else { - blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr + blockInfo->sectorSize); - } - - bm_stat = IO_READ(LEO_BM_STATUS); - if ((bm_stat & LEO_BM_STATUS_C1SINGLE && bm_stat & LEO_BM_STATUS_C1DOUBLE) || bm_stat & LEO_BM_STATUS_MICRO) { - if (blockInfo->C1ErrNum > 3) { - if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52) { - blockInfo->errStatus = LEO_ERROR_23; - __osLeoAbnormalResume(); - return 1; - } - } else { - int errNum = blockInfo->C1ErrNum; - blockInfo->C1ErrSector[errNum] = info->sectorNum + 1; - } - - blockInfo->C1ErrNum++; - } - - if (stat & LEO_STATUS_C2_TRANSFER) { - if (info->sectorNum + 1 != 88) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - } - - if (info->transferMode == LEO_TRACK_MODE && info->blockNum == 0) { - info->blockNum = 1; - info->sectorNum = -1; - info->block[1].dramAddr = (void *)((u32)info->block[1].dramAddr - info->block[1].sectorSize); - - blockInfo->errStatus = LEO_ERROR_22; - } else { - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - info->cmdType = LEO_CMD_TYPE_2; - blockInfo->errStatus = LEO_ERROR_GOOD; - } - - osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4); - return 1; - } - - if (info->sectorNum == -1 && info->transferMode == LEO_TRACK_MODE && info->blockNum == 1) { - __OSBlockInfo *bptr = &info->block[0]; - if (bptr->C1ErrNum == 0) { - if (((u32 *)bptr->C2Addr)[0] | ((u32 *)bptr->C2Addr)[1] | ((u32 *)bptr->C2Addr)[2] | ((u32 *)bptr->C2Addr)[3]) { - bptr->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - } - - bptr->errStatus = 0; - __osLeoResume(); - } - info->sectorNum++; - if (stat & LEO_STATUS_DATA_REQUEST) { - if (info->sectorNum > 0x54) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - - osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); - blockInfo->errStatus = LEO_ERROR_GOOD; - return 1; - } else if (info->sectorNum <= 0x54) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - - return 1; - } else { - blockInfo->errStatus = LEO_ERROR_4; - __osLeoAbnormalResume(); - return 1; - } -} - -static void __osLeoAbnormalResume(void) { - __OSTranxInfo *info = &__osDiskHandle->transferInfo; - u32 pi_stat; - - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow); - __osLeoResume(); - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; -} - -static void __osLeoResume(void) { - __OSEventState *es = &__osEventStateTab[OS_EVENT_PI]; - OSMesgQueue *mq = es->messageQueue; - s32 last; - - if (mq == NULL || MQ_IS_FULL(mq)) { - return; - } - - last = (mq->first + mq->validCount) % mq->msgCount; - mq->msg[last] = es->message; - mq->validCount++; - - if (mq->mtqueue->next != NULL) { - __osEnqueueThread(&__osRunQueue, __osPopThread(&mq->mtqueue)); - } -} diff --git a/lib/ultralib/src/io/motor.c b/lib/ultralib/src/io/motor.c deleted file mode 100644 index 8028d69..0000000 --- a/lib/ultralib/src/io/motor.c +++ /dev/null @@ -1,332 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "PR/os_version.h" -#include "controller.h" -#include "siint.h" - -#if BUILD_VERSION >= VERSION_J -static OSPifRam __MotorDataBuf[MAXCONTROLLERS] ALIGNED(8); - -#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) - -s32 __osMotorAccess(OSPfs* pfs, s32 flag) { - int i; - s32 ret; - u8* ptr = (u8*)&__MotorDataBuf[pfs->channel]; - - if (!(pfs->status & PFS_MOTOR_INITIALIZED)) { - return 5; - } - - __osSiGetAccess(); - __MotorDataBuf[pfs->channel].pifstatus = CONT_CMD_EXE; - ptr += pfs->channel; - - for (i = 0; i < BLOCKSIZE; i++) { - READFORMAT(ptr)->data[i] = flag; - } - - __osContLastCmd = CONT_CMD_END; - __osSiRawStartDma(OS_WRITE, &__MotorDataBuf[pfs->channel]); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__MotorDataBuf[pfs->channel]); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - - ret = READFORMAT(ptr)->rxsize & CHNL_ERR_MASK; - if (!ret) { - if (!flag) { - if (READFORMAT(ptr)->datacrc != 0) { - ret = PFS_ERR_CONTRFAIL; - } - } else { - if (READFORMAT(ptr)->datacrc != 0xEB) { - ret = PFS_ERR_CONTRFAIL; - } - } - } - - __osSiRelAccess(); - - return ret; -} - -static void __osMakeMotorData(int channel, OSPifRam* mdata) { - u8* ptr = (u8*)mdata->ramarray; - __OSContRamReadFormat ramreadformat; - int i; - - ramreadformat.dummy = CONT_CMD_NOP; - ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; - ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; - ramreadformat.cmd = CONT_CMD_WRITE_PAK; - ramreadformat.addrh = CONT_BLOCK_RUMBLE >> 3; - ramreadformat.addrl = (u8)(__osContAddressCrc(CONT_BLOCK_RUMBLE) | (CONT_BLOCK_RUMBLE << 5)); - - if (channel != 0) { - for (i = 0; i < channel; i++) { - *ptr++ = CONT_CMD_REQUEST_STATUS; - } - } - - *READFORMAT(ptr) = ramreadformat; - ptr += sizeof(__OSContRamReadFormat); - ptr[0] = CONT_CMD_END; -} - -s32 osMotorInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { - s32 ret; - u8 temp[32]; - - pfs->queue = mq; - pfs->channel = channel; - pfs->activebank = 0xFF; - pfs->status = 0; - - ret = SELECT_BANK(pfs, 0xFE); - - if (ret == PFS_ERR_NEW_PACK) { - ret = SELECT_BANK(pfs, 0x80); - } - - if (ret != 0) { - return ret; - } - - ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } else if (temp[31] == 254) { - return PFS_ERR_DEVICE; - } - - ret = SELECT_BANK(pfs, 0x80); - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } - - ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } else if (temp[31] != 0x80) { - return PFS_ERR_DEVICE; - } - - if (!(pfs->status & PFS_MOTOR_INITIALIZED)) { - __osMakeMotorData(channel, &__MotorDataBuf[channel]); - } - - pfs->status = PFS_MOTOR_INITIALIZED; - return 0; -} - -#else - -OSPifRam _MotorStopData[MAXCONTROLLERS] ALIGNED(8); -OSPifRam _MotorStartData[MAXCONTROLLERS] ALIGNED(8); -u8 _motorstopbuf[32] ALIGNED(8); -u8 _motorstartbuf[32] ALIGNED(8); -u32 __osMotorinitialized[MAXCONTROLLERS] = {0, 0, 0, 0}; - -s32 osMotorStop(OSPfs *pfs) { - int i; - s32 ret; - u8 *ptr; - __OSContRamReadFormat ramreadformat; - - ptr = (u8 *)&__osPfsPifRam; - - if (!__osMotorinitialized[pfs->channel]) { - return PFS_ERR_INVALID; - } - - __osSiGetAccess(); - - __osContLastCmd = CONT_CMD_WRITE_PAK; - __osSiRawStartDma(OS_WRITE, &_MotorStopData[pfs->channel]); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - ptr = (u8 *)&__osPfsPifRam; - - if (pfs->channel != 0) { - for (i = 0; i < pfs->channel; i++) { - ptr++; - } - } - - ramreadformat = *(__OSContRamReadFormat *)ptr; - ret = CHNL_ERR(ramreadformat); - - if (ret == 0 && __osContDataCrc((u8*)&_motorstopbuf) != ramreadformat.datacrc) { - ret = PFS_ERR_CONTRFAIL; - } - - __osSiRelAccess(); - return ret; -} - -s32 osMotorStart(OSPfs *pfs) { - - int i; - s32 ret; - u8 *ptr; - __OSContRamReadFormat ramreadformat; - - ptr = (u8 *)&__osPfsPifRam; - - if (!__osMotorinitialized[pfs->channel]) { - return PFS_ERR_INVALID; - } - - __osSiGetAccess(); - - __osContLastCmd = CONT_CMD_WRITE_PAK; - __osSiRawStartDma(OS_WRITE, &_MotorStartData[pfs->channel]); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - ptr = (u8 *)&__osPfsPifRam; - - if (pfs->channel != 0) { - for (i = 0; i < pfs->channel; i++) { - ptr++; - } - } - - ramreadformat = *(__OSContRamReadFormat *)ptr; - ret = CHNL_ERR(ramreadformat); - - if (ret == 0 && __osContDataCrc((u8*)&_motorstartbuf) != ramreadformat.datacrc) { - ret = PFS_ERR_CONTRFAIL; - } - - __osSiRelAccess(); - return ret; -} - -static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata) -{ - u8 *ptr = (u8 *)mdata->ramarray; - __OSContRamReadFormat ramreadformat; - int i; - - for (i = 0; i < ARRLEN(mdata->ramarray); i++) { - mdata->ramarray[i] = 0; - } - - mdata->pifstatus = CONT_CMD_EXE; - ramreadformat.dummy = CONT_CMD_NOP; - ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; - ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; - ramreadformat.cmd = CONT_CMD_WRITE_PAK; - - ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); - ramreadformat.datacrc = CONT_CMD_NOP; - - for (i = 0; i < ARRLEN(ramreadformat.data); i++) { - ramreadformat.data[i] = *buffer++; - } - - if (channel != 0) { - for (i = 0; i < channel; i++) { - *ptr++ = 0; - } - } - - *(__OSContRamReadFormat *)ptr = ramreadformat; - ptr += sizeof(__OSContRamReadFormat); - ptr[0] = CONT_CMD_END; -} - -s32 osMotorInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { - int i; - s32 ret; - u8 temp[32]; - - pfs->queue = mq; - pfs->channel = channel; - pfs->status = 0; - pfs->activebank = 128; - - for (i = 0; i < ARRLEN(temp); i++) { - temp[i] = 254; - } - - ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); - - if (ret == PFS_ERR_NEW_PACK) { - ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); - } - - if (ret != 0) { - return ret; - } - - ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); - - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } - - if (temp[31] == 254) { - return PFS_ERR_DEVICE; - } - - for (i = 0; i < ARRLEN(temp); i++) { - temp[i] = 128; - } - - ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); - - if (ret == PFS_ERR_NEW_PACK) { - ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); - } - - if (ret != 0) { - return ret; - } - - ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); - if (ret == PFS_ERR_NEW_PACK) { - ret = PFS_ERR_CONTRFAIL; - } - - if (ret != 0) { - return ret; - } - - if (temp[31] != 0x80) { - return PFS_ERR_DEVICE; - } - - if (!__osMotorinitialized[channel]) { - for (i = 0; i < ARRLEN(_motorstartbuf); i++) { - _motorstartbuf[i] = 1; - _motorstopbuf[i] = 0; - } - _MakeMotorData(channel, CONT_BLOCK_RUMBLE, _motorstartbuf, &_MotorStartData[channel]); - _MakeMotorData(channel, CONT_BLOCK_RUMBLE, _motorstopbuf, &_MotorStopData[channel]); - __osMotorinitialized[channel] = 1; - } - - return 0; -} - -#endif diff --git a/lib/ultralib/src/io/pfsallocatefile.c b/lib/ultralib/src/io/pfsallocatefile.c deleted file mode 100644 index da7d793..0000000 --- a/lib/ultralib/src/io/pfsallocatefile.c +++ /dev/null @@ -1,371 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "PR/rmon.h" - -#define ROUND_UP_DIVIDE(numerator, denominator) (((numerator) + (denominator)-1) / (denominator)) - -#if BUILD_VERSION >= VERSION_J - -s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, - s32* file_no) { - int start_page; - int decleared; - int last_page; - int old_last_page = 0; - s32 ret = 0; - int file_size_in_pages; - __OSInode inode; - __OSInode backup_inode; - __OSDir dir; - u8 bank; - u8 old_bank = 0; - int firsttime = 0; - s32 bytes; - __OSInodeUnit fpage; - - if (company_code == 0 || game_code == 0) { - return PFS_ERR_INVALID; - } - - file_size_in_pages = ROUND_UP_DIVIDE(file_size_in_bytes, BLOCKSIZE * PFS_ONE_PAGE); - - if (((ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no)) != 0) && - ret != PFS_ERR_INVALID) { - return ret; - } - - if (*file_no != -1) { - return PFS_ERR_EXIST; - } - - ret = osPfsFreeBlocks(pfs, &bytes); - - if (file_size_in_bytes > bytes) { - return PFS_DATA_FULL; - } - - if (file_size_in_pages == 0) { - return PFS_ERR_INVALID; - } - - if (((ret = osPfsFindFile(pfs, 0, 0, NULL, NULL, file_no)) != 0) && ret != PFS_ERR_INVALID) { - return ret; - } - - if (*file_no == -1) { - return PFS_DIR_FULL; - } - - for (bank = 0; bank < pfs->banks; bank++) { - ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); - ERRCK(__osPfsDeclearPage(pfs, &inode, file_size_in_pages, &start_page, bank, &decleared, &last_page)); - - if (start_page != -1) { - if (firsttime == 0) { - fpage.inode_t.page = start_page; - fpage.inode_t.bank = bank; - } else { - backup_inode.inode_page[old_last_page].inode_t.bank = bank; - backup_inode.inode_page[old_last_page].inode_t.page = start_page; - ERRCK(__osPfsRWInode(pfs, &backup_inode, PFS_WRITE, old_bank)); - } - - if (file_size_in_pages > decleared) { - bcopy(&inode, &backup_inode, sizeof(__OSInode)); - old_last_page = last_page; - old_bank = bank; - file_size_in_pages -= decleared; - firsttime++; - } else { - file_size_in_pages = 0; - ERRCK(__osPfsRWInode(pfs, &inode, PFS_WRITE, bank)); - break; - } - } - } - - if (file_size_in_pages > 0 || start_page == -1) { - return PFS_ERR_INCONSISTENT; - } - - dir.start_page = fpage; - dir.company_code = company_code; - dir.game_code = game_code; - dir.data_sum = 0; - - bcopy(game_name, dir.game_name, PFS_FILE_NAME_LEN); - bcopy(ext_name, dir.ext_name, PFS_FILE_EXT_LEN); - - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *file_no, (u8*)&dir, FALSE); - return ret; -} - -s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, int file_size_in_pages, int* first_page, u8 bank, int* decleared, - int* last_page) { - int j; - int spage; - int old_page; - s32 ret = 0; - int offset = bank > 0 ? 1 : pfs->inode_start_page; - - for (j = offset; j < ARRLEN(inode->inode_page); j++) { - if (inode->inode_page[j].ipage == 3) { - break; - } - } - - if (j == ARRLEN(inode->inode_page)) { - *first_page = -1; - return ret; - } - - spage = j; - *decleared = 1; - old_page = j; - j++; - - while (file_size_in_pages > *decleared && j < ARRLEN(inode->inode_page)) { - if (inode->inode_page[j].ipage == 3) { - inode->inode_page[old_page].inode_t.bank = bank; - inode->inode_page[old_page].inode_t.page = j; - old_page = j; - (*decleared)++; - } - j++; - } - - *first_page = spage; - - if (j == ARRLEN(inode->inode_page) && file_size_in_pages > *decleared) { - *last_page = old_page; - } else { - inode->inode_page[old_page].ipage = 1; - *last_page = 0; - } - - return ret; -} - -#else - -static s32 __osClearPage(OSPfs *pfs, int page_num, u8 *data, u8 bank); - -s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, - s32* file_no) { - int start_page; - int decleared; - int last_page; - int old_last_page = 0; - int j; - s32 ret = 0; - int file_size_in_pages; - __OSInode inode; - __OSInode backup_inode; - __OSDir dir; - u8 bank; - u8 old_bank = 0; - int firsttime = 0; - s32 bytes; - __OSInodeUnit fpage; - - if (company_code == 0 || game_code == 0) { - return PFS_ERR_INVALID; - } - - file_size_in_pages = ROUND_UP_DIVIDE(file_size_in_bytes, BLOCKSIZE * PFS_ONE_PAGE); - - if ((pfs->status & PFS_INITIALIZED) == FALSE) { - return PFS_ERR_INVALID; - } - - PFS_CHECK_ID; - - if (((ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no)) != 0) && - ret != PFS_ERR_INVALID) { - return ret; - } - - if (*file_no != -1) { - return PFS_ERR_EXIST; - } - - ret = osPfsFreeBlocks(pfs, &bytes); - - if (file_size_in_bytes > bytes) { - return PFS_DATA_FULL; - } - - if (file_size_in_pages != 0) { - - if (((ret = osPfsFindFile(pfs, 0, 0, NULL, NULL, file_no)) != 0) && ret != PFS_ERR_INVALID) { - return ret; - } - - if (*file_no == -1) { - return PFS_DIR_FULL; - } - - for (bank = 0; bank < pfs->banks; bank++) { - ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); - ERRCK(__osPfsDeclearPage(pfs, &inode, file_size_in_pages, &start_page, bank, &decleared, &last_page)); - - if (start_page != -1) { - if (firsttime == 0) { - fpage.inode_t.page = start_page; - fpage.inode_t.bank = bank; - } else { - backup_inode.inode_page[old_last_page].inode_t.bank = bank; - backup_inode.inode_page[old_last_page].inode_t.page = start_page; - ERRCK(__osPfsRWInode(pfs, &backup_inode, PFS_WRITE, old_bank)); - } - - for (j = 0; j < ARRLEN(inode.inode_page); j++) { - backup_inode.inode_page[j].ipage = inode.inode_page[j].ipage; - } - old_last_page = last_page; - old_bank = bank; - firsttime++; - if (file_size_in_pages > decleared) { - file_size_in_pages = file_size_in_pages - decleared; - } else { - file_size_in_pages = 0; - break; - } - } - } - - if (file_size_in_pages > 0 || start_page == -1) { - return PFS_ERR_INCONSISTENT; - } - - backup_inode.inode_page[old_last_page].inode_t.bank = bank; - backup_inode.inode_page[old_last_page].inode_t.page = start_page; - ERRCK(__osPfsRWInode(pfs, &backup_inode, OS_WRITE, old_bank)); - - dir.start_page = fpage; - dir.company_code = company_code; - dir.game_code = game_code; - dir.data_sum = 0; - - for (j = 0; j < ARRLEN(dir.game_name); j++) - dir.game_name[j] = *game_name++; - for (j = 0; j < ARRLEN(dir.ext_name); j++) - dir.ext_name[j] = *ext_name++; - - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *file_no, (u8*)&dir, FALSE)); - return ret; - } else { - return PFS_ERR_INVALID; - } -} - -s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, int file_size_in_pages, int* first_page, u8 bank, int* decleared, - int* last_page) { - int j; - int spage; - int old_page; - u8 tmp_data[BLOCKSIZE]; - int i; - s32 ret = 0; - int offset = bank > 0 ? 1 : pfs->inode_start_page; - - for (j = offset; j < ARRLEN(inode->inode_page); j++) { - if (inode->inode_page[j].ipage == 3) { - break; - } - } - - if (j == ARRLEN(inode->inode_page)) { - *first_page = -1; - return ret; - } - - for (i = 0; i < ARRLEN(tmp_data); i++) { - tmp_data[i] = 0; - } - - spage = j; - *decleared = 1; - old_page = j; - j++; - - while (file_size_in_pages > *decleared && j < ARRLEN(inode->inode_page)) { - if (inode->inode_page[j].ipage == 3) { - inode->inode_page[old_page].inode_t.bank = bank; - inode->inode_page[old_page].inode_t.page = j; - ERRCK(__osClearPage(pfs, old_page, (u8*)tmp_data, bank)); - old_page = j; - (*decleared)++; - } - j++; - } - - *first_page = spage; - - if (j == ARRLEN(inode->inode_page) && file_size_in_pages > *decleared) { - *last_page = old_page; - return ret; - } else { - inode->inode_page[old_page].ipage = 1; - ret = __osClearPage(pfs, old_page, (u8*)tmp_data, bank); - *last_page = 0; - return ret; - } -} - -static s32 __osClearPage(OSPfs *pfs, int page_no, u8 *data, u8 bank) -{ - int i; - s32 ret; - ret = 0; - pfs->activebank = bank; - ERRCK(__osPfsSelectBank(pfs)); - for (i = 0; i < PFS_ONE_PAGE; i++) { - ret = __osContRamWrite(pfs->queue, pfs->channel, page_no * PFS_ONE_PAGE + i, data, FALSE); - if (ret != 0) { - break; - } - } - pfs->activebank = 0; - ret = __osPfsSelectBank(pfs); - return ret; -} - -#endif - -#ifdef _DEBUG -s32 __osDumpInode(OSPfs* pfs) { - int j; - __OSInode inode; - s32 ret = 0; - __OSDir dir; - u8 bank; -#if BUILD_VERSION >= VERSION_J - u8 startbank = PFS_ID_BANK_256K; -#endif - - rmonPrintf("INODE:\n"); - -#if BUILD_VERSION >= VERSION_J - for (bank = startbank; bank < pfs->banks; bank++) { -#else - for (bank = 0; bank < pfs->banks; bank++) { -#endif - rmonPrintf("\nBank %d:\n", bank); - ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank); - for (j = 0; j < PFS_INODE_SIZE_PER_PAGE; j++) { - rmonPrintf("%x ", inode.inode_page[j].ipage); - } - } - - rmonPrintf("dir_size %d %d\n", pfs->dir_size, pfs->inode_start_page); - - for (j = 0; j < pfs->dir_size; j++) { - __osContRamRead(pfs->queue, pfs->channel, (u16)(pfs->dir_table + (int)j), (u8*)&dir); - rmonPrintf("file %d game_code %d page %x c_code %d sum %d\n", j, dir.game_code, dir.start_page.ipage, - dir.company_code, dir.data_sum); - } - rmonPrintf("End of Dump\n"); - return ret; -} -#endif diff --git a/lib/ultralib/src/io/pfschecker.c b/lib/ultralib/src/io/pfschecker.c deleted file mode 100644 index 980e68e..0000000 --- a/lib/ultralib/src/io/pfschecker.c +++ /dev/null @@ -1,258 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache); -s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache); - -#define CHECK_IPAGE(p) \ - (((p).ipage >= pfs->inode_start_page) && ((p).inode_t.bank < pfs->banks) && ((p).inode_t.page >= 0x01) && \ - ((p).inode_t.page < 0x80)) - -s32 osPfsChecker(OSPfs* pfs) { - int j; - s32 ret; - __OSInodeUnit next_page; - __OSInode checked_inode; - __OSInode tmp_inode; - __OSDir tmp_dir; - __OSInodeUnit file_next_node[16]; - __OSInodeCache cache; - int fixed = 0; - u8 bank; -#if BUILD_VERSION >= VERSION_J - u8 oldbank = 254; -#endif - s32 cc; - s32 cl; - int offset; - - ret = __osCheckId(pfs); - - if (ret == PFS_ERR_NEW_PACK) { - ret = __osGetId(pfs); - } - - if (ret != 0) { - return ret; - } - - ERRCK(corrupted_init(pfs, &cache)); - - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); - -#if BUILD_VERSION >= VERSION_J - if (tmp_dir.company_code != 0 || tmp_dir.game_code != 0) { - if (tmp_dir.company_code == 0 || tmp_dir.game_code == 0) { - cc = -1; - } else { - next_page = tmp_dir.start_page; - cl = cc = 0; - bank = 255; - - while (CHECK_IPAGE(next_page)) { - if (bank != next_page.inode_t.bank) { - bank = next_page.inode_t.bank; - - if (oldbank != bank) { - ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); - oldbank = bank; - } - - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { - return ret; - } - } - - if ((cc = corrupted(pfs, next_page, &cache) - cl) != 0) { - break; - } - - cl = 1; - next_page = tmp_inode.inode_page[next_page.inode_t.page]; - } - } - - if (cc != 0 || next_page.ipage != PFS_EOF) { - bzero(&tmp_dir, sizeof(__OSDir)); - - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); - fixed++; - } - } -#else - if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0) { - next_page = tmp_dir.start_page; - cl = cc = 0; - bank = 255; - - while (CHECK_IPAGE(next_page)) { - if (bank != next_page.inode_t.bank) { - bank = next_page.inode_t.bank; - ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { - return ret; - } - } - - if ((cc = corrupted(pfs, next_page, &cache) - cl) != 0) { - break; - } - - cl = 1; - next_page = tmp_inode.inode_page[next_page.inode_t.page]; - } - - if (cc != 0 || next_page.ipage != PFS_EOF) { - tmp_dir.company_code = 0; - tmp_dir.game_code = 0; - tmp_dir.start_page.ipage = 0; - tmp_dir.status = DIR_STATUS_EMPTY; - tmp_dir.data_sum = 0; - - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); - fixed++; - } - } else { - if (tmp_dir.company_code != 0 || tmp_dir.game_code != 0) { - tmp_dir.company_code = 0; - tmp_dir.game_code = 0; - tmp_dir.start_page.ipage = 0; - tmp_dir.status = DIR_STATUS_EMPTY; - tmp_dir.data_sum = 0; - - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); - fixed++; - } - } -#endif - } - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); - - if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0 && - tmp_dir.start_page.ipage >= (u16)pfs->inode_start_page) { - file_next_node[j].ipage = tmp_dir.start_page.ipage; - } else { - file_next_node[j].ipage = 0; - } - } - - for (bank = 0; bank < pfs->banks; bank++) { - ret = __osPfsRWInode(pfs, &tmp_inode, 0, bank); - - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { - return ret; - } - - offset = (bank > 0) ? 1 : pfs->inode_start_page; - - for (j = 0; j < offset; j++) { - checked_inode.inode_page[j].ipage = tmp_inode.inode_page[j].ipage; - } - - for (; j < 128; j++) { - checked_inode.inode_page[j].ipage = PFS_PAGE_NOT_USED; - } - - for (j = 0; j < pfs->dir_size; j++) { - while (file_next_node[j].inode_t.bank == bank && file_next_node[j].ipage >= (u16)pfs->inode_start_page) { - u8 pp = file_next_node[j].inode_t.page; - file_next_node[j] = checked_inode.inode_page[pp] = tmp_inode.inode_page[pp]; - } - } - ERRCK(__osPfsRWInode(pfs, &checked_inode, OS_WRITE, bank)); - } - - if (fixed) { - pfs->status |= PFS_CORRUPTED; - } else { - pfs->status &= ~PFS_CORRUPTED; - } - - return 0; -} - -s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache) { - int i; - int n; - int offset; - u8 bank; - __OSInodeUnit tpage; - __OSInode tmp_inode; - s32 ret; - - for (i = 0; i < PFS_INODE_DIST_MAP; i++) { - cache->map[i] = 0; - } - - cache->bank = -1; - for (bank = 0; bank < pfs->banks; bank++) { - offset = bank > 0 ? 1 : pfs->inode_start_page; - - ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); - - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { - return ret; - } - - for (i = offset; i < ARRLEN(tmp_inode.inode_page); i++) { - tpage = tmp_inode.inode_page[i]; - - if (tpage.ipage >= pfs->inode_start_page && tpage.inode_t.bank != bank) { -#if BUILD_VERSION >= VERSION_J - n = ((tpage.inode_t.page & 0x7F) / PFS_SECTOR_SIZE) + - ((tpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE); -#else - n = ((tpage.inode_t.page) / PFS_SECTOR_SIZE) + - ((tpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE); -#endif - cache->map[n] |= 1 << (bank % PFS_BANK_LAPPED_BY); - } - } - } - return 0; -} - -s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache) { - int j; - int n; - int hit; - u8 bank; - int offset; - s32 ret; - - hit = 0; - ret = 0; - n = (fpage.inode_t.page / PFS_SECTOR_SIZE) + (fpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE; - - for (bank = 0; bank < pfs->banks; bank++) { - offset = bank > 0 ? 1 : pfs->inode_start_page; - - if (bank == fpage.inode_t.bank || cache->map[n] & (1 << (bank % PFS_BANK_LAPPED_BY))) { - if (bank != cache->bank) { - ret = __osPfsRWInode(pfs, &cache->inode, 0, bank); - - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { - return ret; - } - - cache->bank = bank; - } - - for (j = offset; hit < 2 && (j < ARRLEN(cache->inode.inode_page)); j++) { - if (cache->inode.inode_page[j].ipage == fpage.ipage) { - hit++; - } - } - - if (hit >= 2) { - return PFS_ERR_NEW_PACK; - } - } - } - return hit; -} diff --git a/lib/ultralib/src/io/pfsdeletefile.c b/lib/ultralib/src/io/pfsdeletefile.c deleted file mode 100644 index 065bf26..0000000 --- a/lib/ultralib/src/io/pfsdeletefile.c +++ /dev/null @@ -1,180 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osPfsDeleteFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name) { - s32 file_no; -#if BUILD_VERSION < VERSION_J - int k; -#endif - s32 ret; - __OSInode inode; - __OSDir dir; -#if BUILD_VERSION < VERSION_J - u16 sum = 0; -#endif - __OSInodeUnit last_page; - u8 startpage; - u8 bank; - - if (company_code == 0 || game_code == 0) { - return PFS_ERR_INVALID; - } - -#if BUILD_VERSION >= VERSION_J - ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no)); - SET_ACTIVEBANK_TO_ZERO; -#else - PFS_CHECK_STATUS; - PFS_CHECK_ID; - SET_ACTIVEBANK_TO_ZERO; - ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no)); - - if (file_no == -1) { - return PFS_ERR_INVALID; - } -#endif - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); - - startpage = dir.start_page.inode_t.page; - - for (bank = dir.start_page.inode_t.bank; bank < pfs->banks;) { - ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); -#if BUILD_VERSION >= VERSION_J - ERRCK(__osPfsReleasePages(pfs, &inode, startpage, bank, &last_page)); -#else - ERRCK(__osPfsReleasePages(pfs, &inode, startpage, &sum, bank, &last_page, TRUE)); -#endif - ERRCK(__osPfsRWInode(pfs, &inode, OS_WRITE, bank)); - - if (last_page.ipage == PFS_EOF) { - break; - } - - bank = last_page.inode_t.bank; - startpage = last_page.inode_t.page; - } - - if (bank >= pfs->banks) { - return PFS_ERR_INCONSISTENT; - } - -#if BUILD_VERSION >= VERSION_J - bzero(&dir, sizeof(__OSDir)); -#else - dir.game_code = 0; - dir.company_code = 0; - dir.start_page.ipage = 0; - dir.data_sum = 0; - for (k = 0; k < ARRLEN(dir.game_name); k++) - { - dir.game_name[k] = 0; - } - for (k = 0; k < ARRLEN(dir.ext_name); k++) - { - dir.ext_name[k] = 0; - } - dir.status = DIR_STATUS_EMPTY; -#endif - - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir, FALSE); - - return ret; -} - -#if BUILD_VERSION >= VERSION_J - -s32 __osPfsReleasePages(OSPfs* pfs, __OSInode* inode, u8 start_page, u8 bank, __OSInodeUnit* last_page) { - __OSInodeUnit next_page; - __OSInodeUnit old_page; - s32 ret = 0; - - next_page.ipage = (bank << 8) + start_page; - - do { - old_page = next_page; - next_page = inode->inode_page[next_page.inode_t.page]; - inode->inode_page[old_page.inode_t.page].ipage = PFS_PAGE_NOT_USED; - } while (next_page.ipage >= pfs->inode_start_page && next_page.inode_t.bank == bank); - - *last_page = next_page; - - return ret; -} - -#else - -s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag) -{ - __OSInodeUnit next_page; - __OSInodeUnit old_page; - s32 ret; - int offset; - ret = 0; - next_page = inode->inode_page[start_page]; - - if (next_page.ipage != 1) { - offset = (next_page.inode_t.bank > 0) ? 1 : pfs->inode_start_page; - } else { - offset = (bank > 0) ? 1 : pfs->inode_start_page; - } - - if (next_page.inode_t.page < offset && next_page.ipage != 1) { - return PFS_ERR_INCONSISTENT; - } - - *last_page = next_page; - - if (flag == TRUE) { - inode->inode_page[start_page].ipage = 3; - } - - ERRCK(__osBlockSum(pfs, start_page, sum, bank)); - - if (next_page.ipage == 1) { - return 0; - } - - while (next_page.ipage >= pfs->inode_start_page) { - old_page = next_page; - next_page = inode->inode_page[next_page.inode_t.page]; - inode->inode_page[old_page.inode_t.page].ipage = 3; - - ERRCK(__osBlockSum(pfs, old_page.inode_t.page, sum, bank)); - - if (next_page.inode_t.bank != bank) { - break; - } - } - - if (next_page.ipage >= pfs->inode_start_page && next_page.inode_t.bank == bank) { - inode->inode_page[next_page.inode_t.page].ipage = 3; - } - - *last_page = next_page; - return 0; -} -s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank) -{ - int i; - s32 ret; - u8 data[32]; - ret = 0; - pfs->activebank = bank; - ERRCK(__osPfsSelectBank(pfs)); - for (i = 0; i < PFS_ONE_PAGE; i++) - { - ret = __osContRamRead(pfs->queue, pfs->channel, page_no * PFS_ONE_PAGE + i, data); - if (ret != 0) - { - pfs->activebank = 0; - __osPfsSelectBank(pfs); - return ret; - } - *sum = *sum + __osSumcalc(data, sizeof(data)); - } - pfs->activebank = 0; - ret = __osPfsSelectBank(pfs); - return ret; -} - -#endif diff --git a/lib/ultralib/src/io/pfsfilestate.c b/lib/ultralib/src/io/pfsfilestate.c deleted file mode 100644 index 1878907..0000000 --- a/lib/ultralib/src/io/pfsfilestate.c +++ /dev/null @@ -1,112 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osPfsFileState(OSPfs* pfs, s32 file_no, OSPfsState* state) { - s32 ret; - int pages; - __OSInode inode; - __OSDir dir; - __OSInodeUnit next_page; -#if BUILD_VERSION < VERSION_J - int j; -#endif - u8 bank; -#if BUILD_VERSION < VERSION_J - u8 start_page; -#endif - - if (file_no >= pfs->dir_size || file_no < 0) { - return PFS_ERR_INVALID; - } - - PFS_CHECK_STATUS; -#if BUILD_VERSION >= VERSION_J - ERRCK(__osCheckId(pfs)); -#else - PFS_CHECK_ID; -#endif - SET_ACTIVEBANK_TO_ZERO; - - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); - - if (dir.company_code == 0 || dir.game_code == 0) { - return PFS_ERR_INVALID; - } - -#if BUILD_VERSION >= VERSION_J - pages = 0; - next_page = dir.start_page; - bank = 0xFF; - - while (TRUE) { - if (next_page.ipage < pfs->inode_start_page) { - break; - } else if (next_page.inode_t.bank != bank) { - bank = next_page.inode_t.bank; - ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); - } - - pages++; - next_page = inode.inode_page[next_page.inode_t.page]; - } - - if (next_page.ipage != PFS_EOF) { - return PFS_ERR_INCONSISTENT; - } - - state->file_size = pages * (PFS_ONE_PAGE * BLOCKSIZE); - state->company_code = dir.company_code; - state->game_code = dir.game_code; - bcopy(&dir.game_name, state->game_name, PFS_FILE_NAME_LEN); - bcopy(&dir.ext_name, state->ext_name, PFS_FILE_EXT_LEN); - - ret = __osPfsGetStatus(pfs->queue, pfs->channel); - return ret; -#else - if (dir.start_page.ipage < pfs->inode_start_page) { - return PFS_ERR_INCONSISTENT; - } - - pages = 0; - start_page = dir.start_page.inode_t.page; - bank = dir.start_page.inode_t.bank; - - while (bank < pfs->banks) { - ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); - next_page = inode.inode_page[start_page]; - pages++; - - while (next_page.ipage >= pfs->inode_start_page) { - pages++; - next_page = inode.inode_page[next_page.inode_t.page]; - if (next_page.inode_t.bank != bank) { - bank = next_page.inode_t.bank; - start_page = next_page.inode_t.page; - break; - } - } - - if (next_page.ipage == PFS_EOF) { - break; - } - } - - if (next_page.ipage != PFS_EOF) { - return PFS_ERR_INCONSISTENT; - } - - state->file_size = pages * (PFS_ONE_PAGE * BLOCKSIZE); - state->company_code = dir.company_code; - state->game_code = dir.game_code; - - for (j = 0; j < ARRLEN(state->game_name); j++) { - state->game_name[j] = dir.game_name[j]; - } - - for (j = 0; j < ARRLEN(state->ext_name); j++) { - state->ext_name[j] = dir.ext_name[j]; - } - - return 0; -#endif -} diff --git a/lib/ultralib/src/io/pfsfreeblocks.c b/lib/ultralib/src/io/pfsfreeblocks.c deleted file mode 100644 index 28f0011..0000000 --- a/lib/ultralib/src/io/pfsfreeblocks.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osPfsFreeBlocks(OSPfs* pfs, s32* bytes_not_used) { - int j; - int pages = 0; - __OSInode inode; - s32 ret = 0; - u8 bank; - int offset; - - PFS_CHECK_STATUS; -#if BUILD_VERSION >= VERSION_J - ERRCK(__osCheckId(pfs)); -#else - PFS_CHECK_ID; -#endif - for (bank = 0; bank < pfs->banks; bank++) { - ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); - offset = ((bank > 0) ? 1 : pfs->inode_start_page); - - for (j = offset; j < ARRLEN(inode.inode_page); j++) { - if (inode.inode_page[j].ipage == PFS_PAGE_NOT_USED) { - pages++; - } - } - } - - *bytes_not_used = pages * PFS_ONE_PAGE * BLOCKSIZE; - return 0; -} diff --git a/lib/ultralib/src/io/pfsgetlabel.c b/lib/ultralib/src/io/pfsgetlabel.c deleted file mode 100644 index 0e4de49..0000000 --- a/lib/ultralib/src/io/pfsgetlabel.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osPfsGetLabel(OSPfs* pfs, u8* label, int* len) { - int i; - - if (label == NULL) { - return PFS_ERR_INVALID; - } - - if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) { - return PFS_ERR_NEW_PACK; - } - - for (i = 0; i < ARRLEN(pfs->label); i++) { - if (*(u8*)(u32)(i + pfs->label) == 0) { - break; - } - - *label++ = *(u8*)(u32)(i + pfs->label); - } - - *len = i; - return 0; -} diff --git a/lib/ultralib/src/io/pfsgetstatus.c b/lib/ultralib/src/io/pfsgetstatus.c deleted file mode 100644 index 955412b..0000000 --- a/lib/ultralib/src/io/pfsgetstatus.c +++ /dev/null @@ -1,100 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -#if BUILD_VERSION >= VERSION_J -void __osPfsRequestOneChannel(int channel, u8 cmd); -#else -void __osPfsRequestOneChannel(int channel); -#endif -void __osPfsGetOneChannelData(int channel, OSContStatus* data); - -s32 __osPfsGetStatus(OSMesgQueue* queue, int channel) { - s32 ret = 0; - OSMesg dummy; - OSContStatus data; - -#if BUILD_VERSION >= VERSION_J - __osPfsInodeCacheBank = 250; - - __osPfsRequestOneChannel(channel, CONT_CMD_REQUEST_STATUS); -#else - __osPfsRequestOneChannel(channel); -#endif - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(queue, &dummy, OS_MESG_BLOCK); - - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(queue, &dummy, OS_MESG_BLOCK); - - __osPfsGetOneChannelData(channel, &data); - - if (((data.status & CONT_CARD_ON) != 0) && ((data.status & CONT_CARD_PULL) != 0)) { - return PFS_ERR_NEW_PACK; - } else if ((data.errno != 0) || ((data.status & CONT_CARD_ON) == 0)) { - return PFS_ERR_NOPACK; - } else if ((data.status & CONT_ADDR_CRC_ER) != 0) { - return PFS_ERR_CONTRFAIL; - } - - return ret; -} - -#if BUILD_VERSION >= VERSION_J -void __osPfsRequestOneChannel(int channel, u8 cmd) { -#else -void __osPfsRequestOneChannel(int channel) { -#endif - u8* ptr; - __OSContRequesFormatShort requestformat; - int i; - -#if BUILD_VERSION >= VERSION_J - __osContLastCmd = CONT_CMD_END; -#else - __osContLastCmd = CONT_CMD_REQUEST_STATUS; -#endif - __osPfsPifRam.pifstatus = CONT_CMD_READ_BUTTON; - - ptr = (u8*)&__osPfsPifRam; - - requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; - requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; -#if BUILD_VERSION >= VERSION_J - requestformat.cmd = cmd; -#else - requestformat.cmd = CONT_CMD_REQUEST_STATUS; -#endif - requestformat.typeh = CONT_CMD_NOP; - requestformat.typel = CONT_CMD_NOP; - requestformat.status = CONT_CMD_NOP; - - for (i = 0; i < channel; i++) { - *ptr++ = CONT_CMD_REQUEST_STATUS; - } - - *(__OSContRequesFormatShort*)ptr = requestformat; - ptr += sizeof(__OSContRequesFormatShort); - *ptr = CONT_CMD_END; -} - -void __osPfsGetOneChannelData(int channel, OSContStatus* data) { - u8* ptr = (u8*)&__osPfsPifRam; - __OSContRequesFormatShort requestformat; - int i; - - for (i = 0; i < channel; i++) { - ptr++; - } - - requestformat = *(__OSContRequesFormatShort*)ptr; - data->errno = CHNL_ERR(requestformat); - - if (data->errno != 0) { - return; - } - - data->type = (requestformat.typel << 8) | (requestformat.typeh); - data->status = requestformat.status; -} diff --git a/lib/ultralib/src/io/pfsinit.c b/lib/ultralib/src/io/pfsinit.c deleted file mode 100644 index 5633c78..0000000 --- a/lib/ultralib/src/io/pfsinit.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -s32 osPfsInit(OSMesgQueue* queue, OSPfs* pfs, int channel) { - s32 ret = 0; - - __osSiGetAccess(); - ret = __osPfsGetStatus(queue, channel); - __osSiRelAccess(); - - if (ret != 0) { - return ret; - } - - pfs->queue = queue; - pfs->channel = channel; - pfs->status = 0; - pfs->activebank = -1; - ERRCK(__osGetId(pfs)); - - ret = osPfsChecker(pfs); - pfs->status |= PFS_INITIALIZED; - return ret; -} diff --git a/lib/ultralib/src/io/pfsinitpak.c b/lib/ultralib/src/io/pfsinitpak.c deleted file mode 100644 index d3fde1f..0000000 --- a/lib/ultralib/src/io/pfsinitpak.c +++ /dev/null @@ -1,129 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -#if BUILD_VERSION >= VERSION_J -static s32 __osPfsCheckRamArea(OSPfs* pfs); -#endif - -s32 osPfsInitPak(OSMesgQueue* queue, OSPfs* pfs, int channel) { -#if BUILD_VERSION < VERSION_J - int k; -#endif - s32 ret = 0; - u16 sum; - u16 isum; - u8 temp[BLOCKSIZE]; - __OSPackId* id; - __OSPackId newid; - - __osSiGetAccess(); - - ret = __osPfsGetStatus(queue, channel); - - __osSiRelAccess(); - - if (ret != 0) { - return ret; - } - - pfs->queue = queue; - pfs->channel = channel; - pfs->status = 0; - -#if BUILD_VERSION >= VERSION_J - ERRCK(__osPfsCheckRamArea(pfs)); -#endif - ERRCK(SELECT_BANK(pfs, 0)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)); - - __osIdCheckSum((u16*)temp, &sum, &isum); - id = (__OSPackId*)temp; - - if ((id->checksum != sum) || (id->inverted_checksum != isum)) { - ret = __osCheckPackId(pfs, id); - - if (ret != 0) { -#if BUILD_VERSION >= VERSION_J - pfs->status |= PFS_ID_BROKEN; -#endif - return ret; - } - -#if BUILD_VERSION < VERSION_J - // Duplicated check - else if (ret != 0) { - return ret; - } -#endif - } - - if (!(id->deviceid & 1)) { - ret = __osRepairPackId(pfs, id, &newid); - - if (ret != 0) { -#if BUILD_VERSION >= VERSION_J - if (ret == PFS_ERR_ID_FATAL) { - pfs->status |= PFS_ID_BROKEN; - } -#endif - return ret; - } - - id = &newid; - - if (!(id->deviceid & 1)) { - return PFS_ERR_DEVICE; - } - } - -#if BUILD_VERSION >= VERSION_J - bcopy(id, pfs->id, BLOCKSIZE); -#else - for (k = 0; k < ARRLEN(pfs->id); k++) { - pfs->id[k] = ((u8 *)id)[k]; - } -#endif - - pfs->version = id->version; - pfs->banks = id->banks; - pfs->inode_start_page = 1 + DEF_DIR_PAGES + (2 * pfs->banks); - pfs->dir_size = DEF_DIR_PAGES * PFS_ONE_PAGE; - pfs->inode_table = 1 * PFS_ONE_PAGE; - pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; - pfs->dir_table = pfs->minode_table + (pfs->banks * PFS_ONE_PAGE); - - ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label)); - - ret = osPfsChecker(pfs); - pfs->status |= PFS_INITIALIZED; - - return ret; -} - -#if BUILD_VERSION >= VERSION_J -static s32 __osPfsCheckRamArea(OSPfs* pfs) { - s32 i; - s32 ret = 0; - u8 temp1[BLOCKSIZE]; - u8 temp2[BLOCKSIZE]; - u8 save[BLOCKSIZE]; - - ERRCK(SELECT_BANK(pfs, PFS_ID_BANK_256K)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, save)); - - for (i = 0; i < BLOCKSIZE; i++) { - temp1[i] = i; - } - - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, 0, temp1, FALSE)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, temp2)); - - if (bcmp(temp1, temp2, BLOCKSIZE) != 0) { - return PFS_ERR_DEVICE; - } - - ret = __osContRamWrite(pfs->queue, pfs->channel, 0, save, FALSE); - return ret; -} -#endif diff --git a/lib/ultralib/src/io/pfsisplug.c b/lib/ultralib/src/io/pfsisplug.c deleted file mode 100644 index 9607907..0000000 --- a/lib/ultralib/src/io/pfsisplug.c +++ /dev/null @@ -1,97 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -OSPifRam __osPfsPifRam ALIGNED(16); - -s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { - s32 ret = 0; - OSMesg msg; - u8 bitpattern; - OSContStatus contData[MAXCONTROLLERS]; - s32 channel; - u8 bits = 0; - s32 crcErrorCount = 3; - - __osSiGetAccess(); - - do { - __osPfsRequestData(CONT_CMD_REQUEST_STATUS); - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, &msg, OS_MESG_BLOCK); - - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, &msg, OS_MESG_BLOCK); - - __osPfsGetInitData(&bitpattern, &contData[0]); - - for (channel = 0; channel < __osMaxControllers; channel++) { - if ((contData[channel].status & CONT_ADDR_CRC_ER) == 0) { - crcErrorCount--; - break; - } - } - - if (channel == __osMaxControllers) { - crcErrorCount = 0; - } - } while (crcErrorCount > 0); - - for (channel = 0; channel < __osMaxControllers; channel++) { - if ((contData[channel].errno == 0) && ((contData[channel].status & CONT_CARD_ON) != 0)) { - bits |= (1 << channel); - } - } - __osSiRelAccess(); - *pattern = bits; - return ret; -} - -void __osPfsRequestData(u8 cmd) { - u8* ptr = (u8*)&__osPfsPifRam; - __OSContRequesFormat requestformat; - int i; - - __osContLastCmd = cmd; - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - requestformat.dummy = CONT_CMD_NOP; - requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; - requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; - requestformat.cmd = cmd; - requestformat.typeh = CONT_CMD_NOP; - requestformat.typel = CONT_CMD_NOP; - requestformat.status = CONT_CMD_NOP; - requestformat.dummy1 = CONT_CMD_NOP; - - for (i = 0; i < __osMaxControllers; i++) { - *((__OSContRequesFormat*)ptr) = requestformat; - ptr += sizeof(__OSContRequesFormat); - } - - *ptr = CONT_CMD_END; -} - -void __osPfsGetInitData(u8* pattern, OSContStatus* data) { - u8* ptr; - __OSContRequesFormat requestformat; - int i; - u8 bits = 0; - - ptr = (u8*)&__osPfsPifRam; - - for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestformat), data++) { - requestformat = *((__OSContRequesFormat*)ptr); - data->errno = CHNL_ERR(requestformat); - - if (data->errno != 0) { - continue; - } - - data->type = ((requestformat.typel << 8) | requestformat.typeh); - data->status = requestformat.status; - bits |= (1 << i); - } - *pattern = bits; -} diff --git a/lib/ultralib/src/io/pfsnumfiles.c b/lib/ultralib/src/io/pfsnumfiles.c deleted file mode 100644 index c9d3b87..0000000 --- a/lib/ultralib/src/io/pfsnumfiles.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osPfsNumFiles(OSPfs* pfs, s32* max_files, s32* files_used) { - int j; - s32 ret; - __OSDir dir; - int files = 0; - - PFS_CHECK_STATUS; -#if BUILD_VERSION >= VERSION_J - ERRCK(__osCheckId(pfs)); -#else - PFS_CHECK_ID; -#endif - SET_ACTIVEBANK_TO_ZERO; - - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); - - if (dir.company_code != 0 && dir.game_code != 0) { - files++; - } - } - *files_used = files; - *max_files = pfs->dir_size; - -#if BUILD_VERSION >= VERSION_J - ret = __osPfsGetStatus(pfs->queue, pfs->channel); - return ret; -#else - return 0; -#endif -} diff --git a/lib/ultralib/src/io/pfsreadwritefile.c b/lib/ultralib/src/io/pfsreadwritefile.c deleted file mode 100644 index 4650dc0..0000000 --- a/lib/ultralib/src/io/pfsreadwritefile.c +++ /dev/null @@ -1,124 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -static s32 __osPfsGetNextPage(OSPfs* pfs, u8* bank, __OSInode* inode, __OSInodeUnit* page) { - s32 ret; - - if (page->inode_t.bank != *bank) { - *bank = page->inode_t.bank; - ERRCK(__osPfsRWInode(pfs, inode, 0, *bank)); - } - - *page = inode->inode_page[page->inode_t.page]; - - if (page->ipage < pfs->inode_start_page || page->inode_t.bank >= pfs->banks || page->inode_t.page <= 0 || - page->inode_t.page >= ARRLEN(inode->inode_page)) { - - if (page->ipage == 1) { - return PFS_ERR_INVALID; - } - - return PFS_ERR_INCONSISTENT; - } - return 0; -} -s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8* data_buffer) { - s32 ret; - __OSDir dir; - __OSInode inode; - __OSInodeUnit cur_page; - int cur_block; - int siz_block; - u8* buffer; - u8 bank; - u16 blockno; - - if ((file_no >= (s32)pfs->dir_size) || (file_no < 0)) { - return PFS_ERR_INVALID; - } - - if ((size_in_bytes <= 0) || ((size_in_bytes % BLOCKSIZE) != 0)) { - return PFS_ERR_INVALID; - } - - if ((offset < 0) || ((offset % BLOCKSIZE) != 0)) { - return PFS_ERR_INVALID; - } - - PFS_CHECK_STATUS; - PFS_CHECK_ID; - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); - - if (dir.company_code == 0 || dir.game_code == 0) { - return PFS_ERR_INVALID; - } - - if (dir.start_page.ipage < pfs->inode_start_page || dir.start_page.inode_t.bank >= pfs->banks || - dir.start_page.inode_t.page <= 0 || dir.start_page.inode_t.page >= ARRLEN(inode.inode_page)) { - if ((dir.start_page.ipage == 1)) { - return PFS_ERR_INVALID; - } - - return PFS_ERR_INCONSISTENT; - } - - if (flag == PFS_READ && (dir.status & DIR_STATUS_OCCUPIED) == 0) { - return PFS_ERR_BAD_DATA; - } - - bank = -1; - cur_block = offset / BLOCKSIZE; - cur_page = dir.start_page; - - while (cur_block >= PFS_ONE_PAGE) { - ERRCK(__osPfsGetNextPage(pfs, &bank, &inode, &cur_page)); - cur_block -= PFS_ONE_PAGE; - } - - siz_block = size_in_bytes / BLOCKSIZE; - buffer = data_buffer; - - while (siz_block > 0) { - if (cur_block == PFS_ONE_PAGE) { - ERRCK(__osPfsGetNextPage(pfs, &bank, &inode, &cur_page)); - cur_block = 0; - } - - if (pfs->activebank != cur_page.inode_t.bank) { - ERRCK(SELECT_BANK(pfs, cur_page.inode_t.bank)); - } - - blockno = cur_page.inode_t.page * PFS_ONE_PAGE + cur_block; - - if (flag == OS_READ) { - ret = __osContRamRead(pfs->queue, pfs->channel, blockno, buffer); - } else { - ret = __osContRamWrite(pfs->queue, pfs->channel, blockno, buffer, FALSE); - } - - if (ret != 0) { - return ret; - } - buffer += BLOCKSIZE; - cur_block++; - siz_block--; - } - - if (flag == PFS_WRITE && (dir.status & DIR_STATUS_OCCUPIED) == 0) { - dir.status |= DIR_STATUS_OCCUPIED; -#if BUILD_VERSION >= VERSION_J - SET_ACTIVEBANK_TO_ZERO; -#else - ERRCK(SELECT_BANK(pfs, 0)); -#endif - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir, FALSE)); - } - -#if BUILD_VERSION >= VERSION_J - ret = __osPfsGetStatus(pfs->queue, pfs->channel); - return ret; -#else - return 0; -#endif -} diff --git a/lib/ultralib/src/io/pfsreformat.c b/lib/ultralib/src/io/pfsreformat.c deleted file mode 100644 index 7cd6391..0000000 --- a/lib/ultralib/src/io/pfsreformat.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" -#include "siint.h" - -s32 osPfsReFormat(OSPfs* pfs, OSMesgQueue* queue, int channel) { - int j; - int i; - __OSInode inode; - u8 tmp_data[32]; - u8* ptr; - s32 ret; - __osSiGetAccess(); - ret = __osPfsGetStatus(queue, channel); - - if (ret != 0) { - __osSiRelAccess(); - return ret; - } - - pfs->status ^= PFS_INITIALIZED; - pfs->queue = queue; - pfs->channel = channel; - __osSiRelAccess(); - ERRCK(__osGetId(pfs)); - - SET_ACTIVEBANK_TO_ZERO; - - for (j = 0; j < ARRLEN(tmp_data); j++) { - tmp_data[j] = 0; - } - - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamWrite(queue, channel, pfs->dir_table + j, tmp_data, FALSE)); - } - - for (j = 0; j < pfs->inode_start_page; j++) { - inode.inode_page[j].ipage = 0; - } - - for (j = pfs->inode_start_page; j < ARRLEN(inode.inode_page); j++) { - inode.inode_page[j].ipage = 3; - } - - inode.inode_page[0].ipage = __osSumcalc((u8*)(inode.inode_page + pfs->inode_start_page), - (ARRLEN(inode.inode_page) - pfs->inode_start_page) * sizeof(__OSInodeUnit)); - ptr = (u8*)&inode; - - for (j = 0; j < PFS_ONE_PAGE; j++) { - ERRCK(__osContRamWrite(queue, channel, pfs->inode_table + j, ptr + j * BLOCKSIZE, FALSE)); - ERRCK(__osContRamWrite(queue, channel, pfs->minode_table + j, ptr + j * BLOCKSIZE, FALSE)); - } - - for (i = 1; i < pfs->banks; i++) { - for (j = 1; j < ARRLEN(inode.inode_page); j++) { - inode.inode_page[j].ipage = 3; - } - - inode.inode_page[0].ipage = - __osSumcalc((u8*)(inode.inode_page + 1), (ARRLEN(inode.inode_page) - 1) * sizeof(__OSInodeUnit)); - ptr = (u8*)&inode; - - for (j = 0; j < PFS_ONE_PAGE; j++) { - ERRCK( - __osContRamWrite(queue, channel, pfs->inode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); - ERRCK( - __osContRamWrite(queue, channel, pfs->minode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); - } - } - - return 0; -} diff --git a/lib/ultralib/src/io/pfsrepairid.c b/lib/ultralib/src/io/pfsrepairid.c deleted file mode 100644 index 3fec2a9..0000000 --- a/lib/ultralib/src/io/pfsrepairid.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -#if BUILD_VERSION >= VERSION_J - -s32 osPfsRepairId(OSPfs* pfs) { - s32 ret = 0; - - if ((pfs->status & (PFS_INITIALIZED | PFS_ID_BROKEN))) { - ret = __osGetId(pfs); - - if (ret == 0) { - pfs->status &= ~(PFS_ID_BROKEN); - } - } else { - ret = PFS_ERR_INVALID; - } - - return ret; -} - -#else - -s32 osPfsRepairId(OSPfs *pfs) { - int k; - u16 sum; - u16 isum; - u8 temp[32]; - __OSPackId newid; - s32 ret; - __OSPackId *id; - - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)&temp)); - __osIdCheckSum((u16*)&temp, &sum, &isum); - id = (__OSPackId*)&temp; - - if (id->checksum != sum || id->inverted_checksum != isum) { - ret = __osCheckPackId(pfs, id); - - if (ret == 10) { - ERRCK(__osRepairPackId(pfs, id, &newid)); - id = &newid; - } else if (ret != 0) { - return ret; - } - } - - if ((id->deviceid & 1) == 0) { - ERRCK(__osRepairPackId(pfs, id, &newid)); - id = &newid; - - if ((id->deviceid & 1) == 0) { - return PFS_ERR_DEVICE; - } - } - - for (k = 0; k < ARRLEN(pfs->id); k++) { - pfs->id[k] = ((u8*)id)[k]; - } - - pfs->version = id->version; - pfs->banks = id->banks; - pfs->inode_start_page = pfs->banks * 2 + 3; - pfs->dir_size = 16; - pfs->inode_table = 8; - pfs->minode_table = (pfs->banks + 1) * PFS_ONE_PAGE; - pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 7, pfs->label)); - return 0; -} - -#endif diff --git a/lib/ultralib/src/io/pfssearchfile.c b/lib/ultralib/src/io/pfssearchfile.c deleted file mode 100644 index 351cd72..0000000 --- a/lib/ultralib/src/io/pfssearchfile.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osPfsFindFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, s32* file_no) { - s32 j; - int i; - __OSDir dir; - s32 ret = 0; - int fail; - -#if BUILD_VERSION >= VERSION_J - if (!(pfs->status & PFS_INITIALIZED)) { - return PFS_ERR_INVALID; - } - ERRCK(__osCheckId(pfs)); -#else - PFS_CHECK_ID; -#endif - - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); -#if BUILD_VERSION >= VERSION_J - ERRCK(__osPfsGetStatus(pfs->queue, pfs->channel)); -#endif - - if ((dir.company_code == company_code) && dir.game_code == game_code) { - fail = FALSE; - - if (game_name != NULL) { - for (i = 0; i < ARRLEN(dir.game_name); i++) { - if (dir.game_name[i] != game_name[i]) { - fail = TRUE; - break; - } - } - } - - if (ext_name != NULL && !fail) { - for (i = 0; i < ARRLEN(dir.ext_name); i++) { - if (dir.ext_name[i] != ext_name[i]) { - fail = TRUE; - break; - } - } - } - - if (!fail) { - *file_no = j; - return ret; - } - } - } - - *file_no = -1; - return PFS_ERR_INVALID; -} diff --git a/lib/ultralib/src/io/pfsselectbank.c b/lib/ultralib/src/io/pfsselectbank.c deleted file mode 100644 index 7e33b2d..0000000 --- a/lib/ultralib/src/io/pfsselectbank.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -#if BUILD_VERSION >= VERSION_J -s32 __osPfsSelectBank(OSPfs* pfs, u8 bank) { - u8 temp[BLOCKSIZE]; - int i; - s32 ret = 0; - - for (i = 0; i < BLOCKSIZE; i++) { - temp[i] = bank; - } - - ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_DETECT, temp, FALSE); - - if (ret == 0) { - pfs->activebank = bank; - } - - return ret; -} -#endif diff --git a/lib/ultralib/src/io/pfssetlabel.c b/lib/ultralib/src/io/pfssetlabel.c deleted file mode 100644 index 967b37f..0000000 --- a/lib/ultralib/src/io/pfssetlabel.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "PR/os_internal.h" -#include "controller.h" - -s32 osPfsSetLabel(OSPfs* pfs, u8* label) { - int i; - s32 ret; - -#if BUILD_VERSION >= VERSION_J - if (!(pfs->status & PFS_INITIALIZED)) { - return PFS_ERR_INVALID; - } - - ERRCK(__osCheckId(pfs)); -#else - PFS_CHECK_ID; -#endif - - if (label != NULL) { - for (i = 0; i < ARRLEN(pfs->label); i++) { - if (*label == 0) { - break; - } - - *(pfs->label + i) = *label++; - } - } - -#if BUILD_VERSION >= VERSION_J - if (pfs->activebank != 0) { - ret = SELECT_BANK(pfs, 0); - if (ret == 0) { - ret = (__osContRamWrite(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label, FALSE)); - } - } - return ret; -#else - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label, FALSE)); - return 0; -#endif -} diff --git a/lib/ultralib/src/io/pi.c b/lib/ultralib/src/io/pi.c deleted file mode 100644 index 3e67ddb..0000000 --- a/lib/ultralib/src/io/pi.c +++ /dev/null @@ -1,15 +0,0 @@ - -#include "PR/os_internal.h" -#include "piint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -int __osPiDeviceBusy() { - register u32 stat = IO_READ(PI_STATUS_REG); - if (stat & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - return TRUE; - } else { - return FALSE; - } -} diff --git a/lib/ultralib/src/io/piacs.c b/lib/ultralib/src/io/piacs.c deleted file mode 100644 index c95147f..0000000 --- a/lib/ultralib/src/io/piacs.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" - -#define PI_Q_BUF_LEN 1 -u32 __osPiAccessQueueEnabled = 0; -static OSMesg piAccessBuf[PI_Q_BUF_LEN]; -OSMesgQueue __osPiAccessQueue ALIGNED(8); - -void __osPiCreateAccessQueue(void) { - __osPiAccessQueueEnabled = 1; - osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, PI_Q_BUF_LEN); - osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); -} - -void __osPiGetAccess(void) { - OSMesg dummyMesg; - if (!__osPiAccessQueueEnabled) { - __osPiCreateAccessQueue(); - } - osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK); -} - -void __osPiRelAccess(void) { - osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); -} diff --git a/lib/ultralib/src/io/pidma.c b/lib/ultralib/src/io/pidma.c deleted file mode 100644 index 0584e12..0000000 --- a/lib/ultralib/src/io/pidma.c +++ /dev/null @@ -1,66 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "piint.h" - -s32 osPiStartDma(OSIoMesg* mb, s32 priority, s32 direction, u32 devAddr, void* dramAddr, u32 size, OSMesgQueue* mq) { - register s32 ret; - if (!__osPiDevMgr.active) { -#ifdef _DEBUG - __osError(ERR_OSPISTARTDMA_PIMGR, 0); -#endif - return -1; - } - -#ifdef _DEBUG - if ((priority != OS_MESG_PRI_NORMAL) && (priority != OS_MESG_PRI_HIGH)) { - __osError(ERR_OSPISTARTDMA_PRI, 1, priority); - return -1; - } - - if ((direction != OS_READ) && (direction != OS_WRITE)) { - __osError(ERR_OSPISTARTDMA_DIR, 1, direction); - return -1; - } - - if (devAddr & 0x1) { - __osError(ERR_OSPISTARTDMA_DEVADDR, 1, devAddr); - return -1; - } - - if ((u32)dramAddr & 0x7) { - __osError(ERR_OSPISTARTDMA_ADDR, 1, dramAddr); - return -1; - } - - if (size & 0x1) { - __osError(ERR_OSPISTARTDMA_SIZE, 1, size); - return -1; - } - - if ((size == 0) || (size > (16 * 1024 * 1024))) { - __osError(ERR_OSPISTARTDMA_RANGE, 1, size); - return -1; - } -#endif - - if (direction == OS_READ) { - mb->hdr.type = OS_MESG_TYPE_DMAREAD; - } else { - mb->hdr.type = OS_MESG_TYPE_DMAWRITE; - } - - mb->hdr.pri = priority; - mb->hdr.retQueue = mq; - mb->dramAddr = dramAddr; - mb->devAddr = devAddr; - mb->size = size; - mb->piHandle = NULL; - - if (priority == OS_MESG_PRI_HIGH) { - ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); - } else { - ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); - } - - return ret; -} diff --git a/lib/ultralib/src/io/pigetcmdq.c b/lib/ultralib/src/io/pigetcmdq.c deleted file mode 100644 index 4724301..0000000 --- a/lib/ultralib/src/io/pigetcmdq.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/os_internal.h" -#include "piint.h" - -OSMesgQueue* osPiGetCmdQueue(void) { - if (!__osPiDevMgr.active) { - return NULL; - } else { - return __osPiDevMgr.cmdQueue; - } -} diff --git a/lib/ultralib/src/io/pigetstat.c b/lib/ultralib/src/io/pigetstat.c deleted file mode 100644 index 43e9a27..0000000 --- a/lib/ultralib/src/io/pigetstat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "piint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -u32 osPiGetStatus() { - return IO_READ(PI_STATUS_REG); -} diff --git a/lib/ultralib/src/io/pigettype.c b/lib/ultralib/src/io/pigettype.c deleted file mode 100644 index f918306..0000000 --- a/lib/ultralib/src/io/pigettype.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "PR/os_internal.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 osPiGetDeviceType() { - return osRomType; -} diff --git a/lib/ultralib/src/io/piint.h b/lib/ultralib/src/io/piint.h deleted file mode 100644 index 50a0858..0000000 --- a/lib/ultralib/src/io/piint.h +++ /dev/null @@ -1,197 +0,0 @@ -#ifndef _PIINT_H_ -#define _PIINT_H_ - -#include "PR/os_internal.h" -#include "PR/rcp.h" - -//https://github.com/LuigiBlood/64dd/wiki/Memory-Map - -#define LEO_BASE_REG 0x05000000 - -#define LEO_CMD (LEO_BASE_REG + 0x508) -#define LEO_STATUS (LEO_BASE_REG + 0x508) - -#define LEO_BM_CTL (LEO_BASE_REG + 0x510) -#define LEO_BM_STATUS (LEO_BASE_REG + 0x510) - -#define LEO_SEQ_CTL (LEO_BASE_REG + 0x518) -#define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518) - -#define LEO_C2_BUFF (LEO_BASE_REG + 0x000) //C2 Sector Buffer -#define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400) //Data Sector Buffer -#define LEO_DATA (LEO_BASE_REG + 0x500) //Data -#define LEO_MISC_REG (LEO_BASE_REG + 0x504) //Misc Register -#define LEO_CUR_TK (LEO_BASE_REG + 0x50C) //Current Track -#define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514) //Sector Error Status -#define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C) //Current Sector -#define LEO_HARD_RESET (LEO_BASE_REG + 0x520) //Hard Reset -#define LEO_C1_S0 (LEO_BASE_REG + 0x524) //C1 -#define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) //Sector Size (in bytes) -#define LEO_C1_S2 (LEO_BASE_REG + 0x52C) //C1 -#define LEO_SEC_BYTE (LEO_BASE_REG + 0x530) //Sectors per Block, Full Size -#define LEO_C1_S4 (LEO_BASE_REG + 0x534) //C1 -#define LEO_C1_S6 (LEO_BASE_REG + 0x538) //C1 -#define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C) //Current Address? -#define LEO_ID_REG (LEO_BASE_REG + 0x540) //ID -#define LEO_TEST_REG (LEO_BASE_REG + 0x544) //Test Read -#define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) //Test Write -#define LEO_RAM_ADDR (LEO_BASE_REG + 0x580) //Microsequencer RAM - -#define LEO_STATUS_PRESENCE_MASK 0xFFFF - -#define LEO_STATUS_DATA_REQUEST 0x40000000 -#define LEO_STATUS_C2_TRANSFER 0x10000000 -#define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000 -#define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000 -#define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000 -#define LEO_STATUS_DISK_PRESENT 0x01000000 -#define LEO_STATUS_BUSY_STATE 0x00800000 -#define LEO_STATUS_RESET_STATE 0x00400000 -#define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000 -#define LEO_STATUS_HEAD_RETRACTED 0x00080000 -#define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000 -#define LEO_STATUS_MECHANIC_ERROR 0x00020000 -#define LEO_STATUS_DISK_CHANGE 0x00010000 - -#define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) -#define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) -#define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED) -#define LEO_STATUS_MODE_ACTIVE 0 - -#define LEO_CUR_TK_INDEX_LOCK 0x60000000 - -#define LEO_BM_STATUS_RUNNING 0x80000000 //Running -#define LEO_BM_STATUS_ERROR 0x04000000 //Error -#define LEO_BM_STATUS_MICRO 0x02000000 //Micro Status? -#define LEO_BM_STATUS_BLOCK 0x01000000 //Block Transfer -#define LEO_BM_STATUS_C1CORRECTION 0x00800000 //C1 Correction -#define LEO_BM_STATUS_C1DOUBLE 0x00400000 //C1 Double -#define LEO_BM_STATUS_C1SINGLE 0x00200000 //C1 Single -#define LEO_BM_STATUS_C1ERROR 0x00010000 //C1 Error - -#define LEO_BM_CTL_START 0x80000000 //Start Buffer Manager -#define LEO_BM_CTL_MODE 0x40000000 //Buffer Manager Mode -#define LEO_BM_CTL_IMASK 0x20000000 //BM Interrupt Mask -#define LEO_BM_CTL_RESET 0x10000000 //Buffer Manager Reset -#define LEO_BM_CTL_DISABLE_OR 0x08000000 //Disable OR Check? -#define LEO_BM_CTL_DISABLE_C1 0x04000000 //Disable C1 Correction -#define LEO_BM_CTL_BLOCK 0x02000000 //Block Transfer -#define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 //Mechanic Interrupt Reset - -#define LEO_BM_CTL_CONTROL_MASK 0xFF000000 -#define LEO_BM_CTL_SECTOR_MASK 0x00FF0000 -#define LEO_BM_CTL_SECTOR_SHIFT 16 - -#define LEO_CMD_TYPE_0 0 //TODO: name -#define LEO_CMD_TYPE_1 1 //TODO: name -#define LEO_CMD_TYPE_2 2 //TODO: name - -#define LEO_ERROR_GOOD 0 -#define LEO_ERROR_4 4 //maybe busy? -#define LEO_ERROR_22 22 // -#define LEO_ERROR_23 23 //unrecovered read error? -#define LEO_ERROR_24 24 //no reference position found? -#define LEO_ERROR_29 29 // - -extern OSDevMgr __osPiDevMgr; -extern OSPiHandle *__osCurrentHandle[]; -extern OSPiHandle CartRomHandle; -extern OSPiHandle LeoDiskHandle; -extern OSMesgQueue __osPiAccessQueue; -extern u32 __osPiAccessQueueEnabled; - -// These symbols were all renamed in 2.0J. -#if BUILD_VERSION < VERSION_J -#define __osEPiRawStartDma osEPiRawStartDma -#define __osEPiRawReadIo osEPiRawReadIo -#define __osEPiRawWriteIo osEPiRawWriteIo -#define __osPiRawStartDma osPiRawStartDma -#define __osPiRawWriteIo osPiRawWriteIo -#define __osPiRawReadIo osPiRawReadIo -#endif - -int __osPiDeviceBusy(void); -void __osDevMgrMain(void *); -void __osPiCreateAccessQueue(void); -void __osPiRelAccess(void); -void __osPiGetAccess(void); -s32 __osPiRawStartDma(s32, u32 , void *, u32 ); -s32 __osPiRawWriteIo(u32, u32); -s32 __osPiRawReadIo(u32, u32 *); -s32 __osEPiRawWriteIo(OSPiHandle *, u32 , u32); -s32 __osEPiRawReadIo(OSPiHandle *, u32 , u32 *); -s32 __osEPiRawStartDma(OSPiHandle *, s32 , u32 , void *, u32 ); -OSMesgQueue *osPiGetCmdQueue(void); - -#define WAIT_ON_IOBUSY(stat) \ - { \ - stat = IO_READ(PI_STATUS_REG); \ - while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \ - stat = IO_READ(PI_STATUS_REG); \ - } (void)0 - -#define UPDATE_REG(pihandle, reg, var) \ - if (cHandle->var != pihandle->var) \ - IO_WRITE(reg, pihandle->var) - -#if BUILD_VERSION >= VERSION_J - -#define EPI_SYNC(pihandle, stat, domain) \ - \ - WAIT_ON_IOBUSY(stat); \ - \ - domain = pihandle->domain; \ - if (__osCurrentHandle[domain]->type != pihandle->type) \ - { \ - OSPiHandle *cHandle = __osCurrentHandle[domain]; \ - if (domain == PI_DOMAIN1) \ - { \ - UPDATE_REG(pihandle, PI_BSD_DOM1_LAT_REG, latency); \ - UPDATE_REG(pihandle, PI_BSD_DOM1_PGS_REG, pageSize); \ - UPDATE_REG(pihandle, PI_BSD_DOM1_RLS_REG, relDuration); \ - UPDATE_REG(pihandle, PI_BSD_DOM1_PWD_REG, pulse); \ - } \ - else \ - { \ - UPDATE_REG(pihandle, PI_BSD_DOM2_LAT_REG, latency); \ - UPDATE_REG(pihandle, PI_BSD_DOM2_PGS_REG, pageSize); \ - UPDATE_REG(pihandle, PI_BSD_DOM2_RLS_REG, relDuration); \ - UPDATE_REG(pihandle, PI_BSD_DOM2_PWD_REG, pulse); \ - } \ - cHandle->type = pihandle->type; \ - cHandle->latency = pihandle->latency; \ - cHandle->pageSize = pihandle->pageSize; \ - cHandle->relDuration = pihandle->relDuration; \ - cHandle->pulse = pihandle->pulse; \ - }(void)0 - -#else - -#define EPI_SYNC(pihandle, stat, domain) \ - \ - WAIT_ON_IOBUSY(stat); \ - \ - domain = pihandle->domain; \ - if (__osCurrentHandle[domain] != pihandle) \ - { \ - OSPiHandle *cHandle = __osCurrentHandle[domain]; \ - if (domain == PI_DOMAIN1) \ - { \ - UPDATE_REG(pihandle, PI_BSD_DOM1_LAT_REG, latency); \ - UPDATE_REG(pihandle, PI_BSD_DOM1_PGS_REG, pageSize); \ - UPDATE_REG(pihandle, PI_BSD_DOM1_RLS_REG, relDuration); \ - UPDATE_REG(pihandle, PI_BSD_DOM1_PWD_REG, pulse); \ - } \ - else \ - { \ - UPDATE_REG(pihandle, PI_BSD_DOM2_LAT_REG, latency); \ - UPDATE_REG(pihandle, PI_BSD_DOM2_PGS_REG, pageSize); \ - UPDATE_REG(pihandle, PI_BSD_DOM2_RLS_REG, relDuration); \ - UPDATE_REG(pihandle, PI_BSD_DOM2_PWD_REG, pulse); \ - } \ - __osCurrentHandle[domain] = pihandle; \ - }(void)0 - -#endif - -#endif diff --git a/lib/ultralib/src/io/pimgr.c b/lib/ultralib/src/io/pimgr.c deleted file mode 100644 index d98c6ad..0000000 --- a/lib/ultralib/src/io/pimgr.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "piint.h" -#include "PR/rdb.h" - -static OSThread piThread ALIGNED(8); -static char piThreadStack[OS_PIM_STACKSIZE] ALIGNED(16); - -#ifndef _FINALROM -static OSThread ramromThread ALIGNED(8); -static char ramromThreadStack[1024] ALIGNED(16); -static OSMesgQueue getRamromQ ALIGNED(8); -static OSMesg getRamromBuf[1]; -static OSMesgQueue freeRamromQ ALIGNED(8); -static OSMesg freeRamromBuf[1]; -static void ramromMain(void*); -#endif - -static OSMesgQueue piEventQueue ALIGNED(8); -static OSMesg piEventBuf[1]; - -OSDevMgr __osPiDevMgr = { 0 }; -OSPiHandle* __osPiTable = NULL; -#if BUILD_VERSION >= VERSION_J -OSPiHandle __Dom1SpeedParam ALIGNED(8); -OSPiHandle __Dom2SpeedParam ALIGNED(8); -OSPiHandle* __osCurrentHandle[2] ALIGNED(8) = { &__Dom1SpeedParam, &__Dom2SpeedParam }; -#else -extern OSPiHandle CartRomHandle; -extern OSPiHandle LeoDiskHandle; -OSPiHandle* __osCurrentHandle[2] ALIGNED(8) = { &CartRomHandle, &LeoDiskHandle }; -#endif - -void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { - u32 savedMask; - OSPri oldPri; - OSPri myPri; - -#ifdef _DEBUG - if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { - __osError(ERR_OSCREATEPIMANAGER, 1, pri); - return; - } -#endif - - if (__osPiDevMgr.active) { - return; - } - osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt); - osCreateMesgQueue(&piEventQueue, (OSMesg*)piEventBuf, 1); - - if (!__osPiAccessQueueEnabled) { - __osPiCreateAccessQueue(); - } - - osSetEventMesg(OS_EVENT_PI, &piEventQueue, (OSMesg)0x22222222); - oldPri = -1; - myPri = osGetThreadPri(NULL); - - if (myPri < pri) { - oldPri = myPri; - osSetThreadPri(NULL, pri); - } - - savedMask = __osDisableInt(); - __osPiDevMgr.active = 1; - __osPiDevMgr.thread = &piThread; - __osPiDevMgr.cmdQueue = cmdQ; - __osPiDevMgr.evtQueue = &piEventQueue; - __osPiDevMgr.acsQueue = &__osPiAccessQueue; - __osPiDevMgr.dma = __osPiRawStartDma; - __osPiDevMgr.edma = __osEPiRawStartDma; - osCreateThread(&piThread, 0, __osDevMgrMain, &__osPiDevMgr, &piThreadStack[OS_PIM_STACKSIZE], pri); - osStartThread(&piThread); - -#ifndef _FINALROM - osCreateThread(&ramromThread, 0, ramromMain, NULL, ramromThreadStack + 1024, (OSPri)pri - 1); - osStartThread(&ramromThread); -#endif - __osRestoreInt(savedMask); - - if (oldPri != -1) { - osSetThreadPri(NULL, oldPri); - } -} - -#ifndef _FINALROM -static void ramromMain(void* arg) { - u32 sent; - u8 tmp[3]; - - osCreateMesgQueue(&getRamromQ, getRamromBuf, 1); - osCreateMesgQueue(&freeRamromQ, freeRamromBuf, 1); - osSetEventMesg(OS_EVENT_RDB_REQ_RAMROM, &getRamromQ, NULL); - osSetEventMesg(OS_EVENT_RDB_FREE_RAMROM, &freeRamromQ, NULL); - - while (TRUE) { - osRecvMesg(&getRamromQ, NULL, OS_MESG_BLOCK); - - __osPiGetAccess(); - - sent = 0; - - while (sent < 1) { - sent += __osRdbSend(tmp, 1, RDB_TYPE_GtoH_RAMROM); - } - - osRecvMesg(&freeRamromQ, NULL, OS_MESG_BLOCK); - - __osPiRelAccess(); - } -} -#endif diff --git a/lib/ultralib/src/io/pirawdma.c b/lib/ultralib/src/io/pirawdma.c deleted file mode 100644 index d5ea8c3..0000000 --- a/lib/ultralib/src/io/pirawdma.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osPiRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { - register u32 stat; - -#ifdef _DEBUG - if ((direction != OS_READ) && (direction != OS_WRITE)) { - __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); - return -1; - } - - if (devAddr & 0x1) { - __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); - return -1; - } - - if ((u32)dramAddr & 0x7) { - __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); - return -1; - } - - if (size & 0x1) { - __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); - return -1; - } - - if ((size == 0) || (size > (16 * 1024 * 1024))) { - __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); - return -1; - } -#endif - - WAIT_ON_IOBUSY(stat); - - IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); - IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS((u32)osRomBase | devAddr)); - - switch (direction) { - case OS_READ: - IO_WRITE(PI_WR_LEN_REG, size - 1); - break; - case OS_WRITE: - IO_WRITE(PI_RD_LEN_REG, size - 1); - break; - default: - return -1; - } - return 0; -} diff --git a/lib/ultralib/src/io/pirawread.c b/lib/ultralib/src/io/pirawread.c deleted file mode 100644 index 95d7082..0000000 --- a/lib/ultralib/src/io/pirawread.c +++ /dev/null @@ -1,66 +0,0 @@ -#include "piint.h" -#include "assert.h" -#include "PR/ultraerror.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 46 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osPiRawReadIo(u32 devAddr, u32* data) { - register u32 stat; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIRAWREADIO, 1, devAddr); - return -1; - } -#endif - - assert(data != NULL); - - WAIT_ON_IOBUSY(stat); - *data = IO_READ((u32)osRomBase | devAddr); - - return 0; -} diff --git a/lib/ultralib/src/io/pirawwrite.c b/lib/ultralib/src/io/pirawwrite.c deleted file mode 100644 index 92eba84..0000000 --- a/lib/ultralib/src/io/pirawwrite.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osPiRawWriteIo(u32 devAddr, u32 data) { - register u32 stat; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIRAWWRITEIO, 1, devAddr); - return -1; - } -#endif - - WAIT_ON_IOBUSY(stat); - IO_WRITE((u32)osRomBase | devAddr, data); - - return 0; -} diff --git a/lib/ultralib/src/io/piread.c b/lib/ultralib/src/io/piread.c deleted file mode 100644 index 42bcf3e..0000000 --- a/lib/ultralib/src/io/piread.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -s32 osPiReadIo(u32 devAddr, u32* data) { - register s32 ret; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIREADIO, 1, devAddr); - return -1; - } -#endif - - __osPiGetAccess(); - ret = __osPiRawReadIo(devAddr, data); - __osPiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/io/piwrite.c b/lib/ultralib/src/io/piwrite.c deleted file mode 100644 index 75c00d1..0000000 --- a/lib/ultralib/src/io/piwrite.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "piint.h" -#include "PR/ultraerror.h" - -s32 osPiWriteIo(u32 devAddr, u32 data) { - register s32 ret; - -#ifdef _DEBUG - if (devAddr & 0x3) { - __osError(ERR_OSPIWRITEIO, 1, devAddr); - return -1; - } -#endif - - __osPiGetAccess(); - ret = __osPiRawWriteIo(devAddr, data); - __osPiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/io/si.c b/lib/ultralib/src/io/si.c deleted file mode 100644 index 0188927..0000000 --- a/lib/ultralib/src/io/si.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "PR/os_internal.h" -#include "siint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -int __osSiDeviceBusy() { - register u32 stat = IO_READ(SI_STATUS_REG); - - if (stat & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { - return TRUE; - } else { - return FALSE; - } -} diff --git a/lib/ultralib/src/io/siacs.c b/lib/ultralib/src/io/siacs.c deleted file mode 100644 index 8ef5b3f..0000000 --- a/lib/ultralib/src/io/siacs.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" - -#define SI_Q_BUF_LEN 1 -static OSMesg siAccessBuf[SI_Q_BUF_LEN] ALIGNED(8); -OSMesgQueue __osSiAccessQueue ALIGNED(8); -u32 __osSiAccessQueueEnabled = 0; - -void __osSiCreateAccessQueue(void) { - __osSiAccessQueueEnabled = 1; - osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, SI_Q_BUF_LEN); - osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); -} - -void __osSiGetAccess(void) { - OSMesg dummyMesg; - if (!__osSiAccessQueueEnabled) { - __osSiCreateAccessQueue(); - } - osRecvMesg(&__osSiAccessQueue, &dummyMesg, OS_MESG_BLOCK); -} - -void __osSiRelAccess(void) { - osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); -} diff --git a/lib/ultralib/src/io/sigetstat.c b/lib/ultralib/src/io/sigetstat.c deleted file mode 100644 index 0225445..0000000 --- a/lib/ultralib/src/io/sigetstat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "siint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -u32 __osSiGetStatus() { - return IO_READ(SI_STATUS_REG); -} diff --git a/lib/ultralib/src/io/siint.h b/lib/ultralib/src/io/siint.h deleted file mode 100644 index 636a87f..0000000 --- a/lib/ultralib/src/io/siint.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _SIINT_H -#define _SIINT_H - -#include "PR/os_internal.h" -#include "PR/rcp.h" - -extern s32 __osEepromRead16K; -extern u8 __osPfsInodeCacheBank; - -void __osSiGetAccess(void); -void __osSiRelAccess(void); -int __osSiDeviceBusy(void); -void __osSiCreateAccessQueue(void); - -#endif diff --git a/lib/ultralib/src/io/sirawdma.c b/lib/ultralib/src/io/sirawdma.c deleted file mode 100644 index 5fb5f8a..0000000 --- a/lib/ultralib/src/io/sirawdma.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "PR/os_internal.h" -#include "assert.h" -#include "siint.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 49 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osSiRawStartDma(s32 direction, void* dramAddr) { - assert(((u32)dramAddr & 0x3) == 0); - -#if BUILD_VERSION >= VERSION_J - if (IO_READ(SI_STATUS_REG) & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { - return -1; - } -#else - if (__osSiDeviceBusy()) { - return -1; - } -#endif - - if (direction == OS_WRITE) { - osWritebackDCache(dramAddr, 64); - } - - IO_WRITE(SI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); - - if (direction == OS_READ) { - IO_WRITE(SI_PIF_ADDR_RD64B_REG, PIF_RAM_START); - } else { - IO_WRITE(SI_PIF_ADDR_WR64B_REG, PIF_RAM_START); - } - - if (direction == OS_READ) { - osInvalDCache(dramAddr, 64); - } - - return 0; -} diff --git a/lib/ultralib/src/io/sirawread.c b/lib/ultralib/src/io/sirawread.c deleted file mode 100644 index 4ce8330..0000000 --- a/lib/ultralib/src/io/sirawread.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "PR/os_internal.h" -#include "assert.h" -#include "siint.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 45 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osSiRawReadIo(u32 devAddr, u32* data) { - assert((devAddr & 0x3) == 0); - assert(data != NULL); - - if (__osSiDeviceBusy()) { - return -1; - } - - *data = IO_READ(devAddr); - return 0; -} diff --git a/lib/ultralib/src/io/sirawwrite.c b/lib/ultralib/src/io/sirawwrite.c deleted file mode 100644 index 795d38a..0000000 --- a/lib/ultralib/src/io/sirawwrite.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "PR/os_internal.h" -#include "siint.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 46 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osSiRawWriteIo(u32 devAddr, u32 data) { - assert((devAddr & 0x3) == 0); - - if (__osSiDeviceBusy()) { - return -1; - } - - IO_WRITE(devAddr, data); - return 0; -} diff --git a/lib/ultralib/src/io/sp.c b/lib/ultralib/src/io/sp.c deleted file mode 100644 index 3ad9076..0000000 --- a/lib/ultralib/src/io/sp.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PR/sptask.h" -#include "../os/osint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -int __osSpDeviceBusy() { - register u32 stat = IO_READ(SP_STATUS_REG); - - if (stat & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) { - return TRUE; - } else { - return FALSE; - } -} diff --git a/lib/ultralib/src/io/spgetstat.c b/lib/ultralib/src/io/spgetstat.c deleted file mode 100644 index 0cdfda6..0000000 --- a/lib/ultralib/src/io/spgetstat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -u32 __osSpGetStatus() { - return IO_READ(SP_STATUS_REG); -} diff --git a/lib/ultralib/src/io/sprawdma.c b/lib/ultralib/src/io/sprawdma.c deleted file mode 100644 index 6d95a49..0000000 --- a/lib/ultralib/src/io/sprawdma.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "../os/osint.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 52 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { - assert(((u32)devAddr & 0x7) == 0); - assert(((u32)dramAddr & 0x7) == 0); - assert(((u32)size & 0x7) == 0); - - if (__osSpDeviceBusy()) { - return -1; - } - - IO_WRITE(SP_MEM_ADDR_REG, devAddr); - IO_WRITE(SP_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); - - if (direction == OS_READ) { - IO_WRITE(SP_WR_LEN_REG, size - 1); - } else { - IO_WRITE(SP_RD_LEN_REG, size - 1); - } - - return 0; -} diff --git a/lib/ultralib/src/io/sprawread.c b/lib/ultralib/src/io/sprawread.c deleted file mode 100644 index 5910a9e..0000000 --- a/lib/ultralib/src/io/sprawread.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "../os/osint.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 45 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osSpRawReadIo(u32 devAddr, u32* data) { - assert((devAddr & 0x3) == 0); - assert(data != NULL); - - if (__osSpDeviceBusy()) { - return -1; - } - - *data = IO_READ(devAddr); - return 0; -} diff --git a/lib/ultralib/src/io/sprawwrite.c b/lib/ultralib/src/io/sprawwrite.c deleted file mode 100644 index 9ce3ebf..0000000 --- a/lib/ultralib/src/io/sprawwrite.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "../os/osint.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Adjust line numbers to match assert -#if BUILD_VERSION < VERSION_J -#line 45 -#endif - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osSpRawWriteIo(u32 devAddr, u32 data) { - assert((devAddr & 0x3) == 0); - - if (__osSpDeviceBusy()) { - return -1; - } - - IO_WRITE(devAddr, data); - return 0; -} diff --git a/lib/ultralib/src/io/spsetpc.c b/lib/ultralib/src/io/spsetpc.c deleted file mode 100644 index dce0b5d..0000000 --- a/lib/ultralib/src/io/spsetpc.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 __osSpSetPc(u32 pc) { - register u32 status = IO_READ(SP_STATUS_REG); - - if (!(status & SP_STATUS_HALT)) { - return -1; - } - IO_WRITE(SP_PC_REG, pc); - - return 0; -} diff --git a/lib/ultralib/src/io/spsetstat.c b/lib/ultralib/src/io/spsetstat.c deleted file mode 100644 index 2ab47e0..0000000 --- a/lib/ultralib/src/io/spsetstat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void __osSpSetStatus(u32 data) { - IO_WRITE(SP_STATUS_REG, data); -} diff --git a/lib/ultralib/src/io/sptask.c b/lib/ultralib/src/io/sptask.c deleted file mode 100644 index 8fbfeb2..0000000 --- a/lib/ultralib/src/io/sptask.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/sptask.h" -#include "PR/rcp.h" -#include "../os/osint.h" - -#if BUILD_VERSION < VERSION_J -#ident "$Revision: 1.4 $" -#endif - -#define _osVirtualToPhysical(ptr) \ - if (ptr != NULL) { \ - ptr = (void*)osVirtualToPhysical(ptr); \ - } - -static OSTask tmp_task; - -static OSTask* _VirtualToPhysicalTask(OSTask* intp) { - OSTask* tp; - tp = &tmp_task; - bcopy(intp, tp, sizeof(OSTask)); - - _osVirtualToPhysical(tp->t.ucode); - _osVirtualToPhysical(tp->t.ucode_data); - _osVirtualToPhysical(tp->t.dram_stack); - _osVirtualToPhysical(tp->t.output_buff); - _osVirtualToPhysical(tp->t.output_buff_size); - _osVirtualToPhysical(tp->t.data_ptr); - _osVirtualToPhysical(tp->t.yield_data_ptr); - return tp; -} - -void osSpTaskLoad(OSTask* intp) { - OSTask* tp; - -#ifdef _DEBUG - if ((intp->t.dram_stack != 0x0) && ((u32)intp->t.dram_stack & 0xf)) { - __osError(ERR_OSSPTASKLOAD_DRAM, 1, intp->t.dram_stack); - return; - } - if ((intp->t.output_buff != 0x0) && ((u32)intp->t.output_buff & 0xf)) { - __osError(ERR_OSSPTASKLOAD_OUT, 1, intp->t.output_buff); - return; - } - if ((intp->t.output_buff_size != 0x0) && ((u32)intp->t.output_buff_size & 0xf)) { - __osError(ERR_OSSPTASKLOAD_OUTSIZE, 1, intp->t.output_buff_size); - return; - } - if ((intp->t.yield_data_ptr != 0x0) && ((u32)intp->t.yield_data_ptr & 0xf)) { - __osError(ERR_OSSPTASKLOAD_YIELD, 1, intp->t.yield_data_ptr); - return; - } -#endif - - tp = _VirtualToPhysicalTask(intp); - - if (tp->t.flags & OS_TASK_YIELDED) { - tp->t.ucode_data = tp->t.yield_data_ptr; - tp->t.ucode_data_size = tp->t.yield_data_size; - intp->t.flags &= ~OS_TASK_YIELDED; - if (tp->t.flags & OS_TASK_LOADABLE) { - tp->t.ucode = (u64*)IO_READ((u32)intp->t.yield_data_ptr + OS_YIELD_DATA_SIZE - 4); - } - } - - osWritebackDCache(tp, sizeof(OSTask)); - __osSpSetStatus(SP_CLR_YIELD | SP_CLR_YIELDED | SP_CLR_TASKDONE | SP_SET_INTR_BREAK); - - while (__osSpSetPc(SP_IMEM_START) == -1) {} - - while (__osSpRawStartDma(1, (SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) {} - - while (__osSpDeviceBusy()) {} - - while (__osSpRawStartDma(1, SP_IMEM_START, tp->t.ucode_boot, tp->t.ucode_boot_size) == -1) {} -} - -void osSpTaskStartGo(OSTask* tp) { - while (__osSpDeviceBusy()) {} - - __osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT); -} diff --git a/lib/ultralib/src/io/sptaskyield.c b/lib/ultralib/src/io/sptaskyield.c deleted file mode 100644 index 78bacae..0000000 --- a/lib/ultralib/src/io/sptaskyield.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -void osSpTaskYield(void) { - __osSpSetStatus(SP_SET_YIELD); -} diff --git a/lib/ultralib/src/io/sptaskyielded.c b/lib/ultralib/src/io/sptaskyielded.c deleted file mode 100644 index 3ecab55..0000000 --- a/lib/ultralib/src/io/sptaskyielded.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/sptask.h" -#include "PR/rcp.h" - -OSYieldResult osSpTaskYielded(OSTask* tp) { - u32 status; - OSYieldResult result; - - status = __osSpGetStatus(); - result = (status & SP_STATUS_YIELDED) ? OS_TASK_YIELDED : 0; - - if (status & SP_STATUS_YIELD) { - tp->t.flags |= result; - tp->t.flags &= ~(OS_TASK_DP_WAIT); - } - - return result; -} diff --git a/lib/ultralib/src/io/vi.c b/lib/ultralib/src/io/vi.c deleted file mode 100644 index 246f01f..0000000 --- a/lib/ultralib/src/io/vi.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "PR/R4300.h" -#include "PR/rcp.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -static __OSViContext vi[2] ALIGNED(8) = { 0 }; -__OSViContext* __osViCurr = &vi[0]; -__OSViContext* __osViNext = &vi[1]; - -void __osViInit(void) { - bzero(vi, sizeof(vi)); - __osViCurr = &vi[0]; - __osViNext = &vi[1]; - __osViNext->retraceCount = 1; - __osViCurr->retraceCount = 1; - __osViNext->framep = (void*)K0BASE; - __osViCurr->framep = (void*)K0BASE; - - if (osTvType == OS_TV_TYPE_PAL) { - __osViNext->modep = &osViModePalLan1; - } else if (osTvType == OS_TV_TYPE_MPAL) { - __osViNext->modep = &osViModeMpalLan1; - } else { - __osViNext->modep = &osViModeNtscLan1; - } - - __osViNext->state = VI_STATE_BLACK; - __osViNext->control = __osViNext->modep->comRegs.ctrl; - - while (IO_READ(VI_CURRENT_REG) > 10) { // wait for vsync? - } - - IO_WRITE(VI_CONTROL_REG, 0); // pixel size blank (no data, no sync) - __osViSwapContext(); -} diff --git a/lib/ultralib/src/io/viblack.c b/lib/ultralib/src/io/viblack.c deleted file mode 100644 index 30dd85c..0000000 --- a/lib/ultralib/src/io/viblack.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/os_internal.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViBlack(u8 active) { - register u32 saveMask = __osDisableInt(); - - if (active) { - __osViNext->state |= VI_STATE_BLACK; - } else { - __osViNext->state &= ~VI_STATE_BLACK; - } - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/viextendvstart.c b/lib/ultralib/src/io/viextendvstart.c deleted file mode 100644 index 7ee06d3..0000000 --- a/lib/ultralib/src/io/viextendvstart.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "viint.h" - -void osViExtendVStart(u32 value) { -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(134, 0); - return; - } - - if (value > 48) { - __osError(135, 1, value); - return; - } -#endif - __additional_scanline = value; - return; -} diff --git a/lib/ultralib/src/io/vifade.c b/lib/ultralib/src/io/vifade.c deleted file mode 100644 index 6766871..0000000 --- a/lib/ultralib/src/io/vifade.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "PR/os_internal.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViFade(u8 active, u16 factor) { - register u32 saveMask = __osDisableInt(); - - if (active) { - __osViNext->y.offset = factor & VI_2_10_FPART_MASK; - __osViNext->state |= VI_STATE_FADE; - } else { - __osViNext->state &= ~VI_STATE_FADE; - } - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/vigetcurrcontext.c b/lib/ultralib/src/io/vigetcurrcontext.c deleted file mode 100644 index 7b1df9b..0000000 --- a/lib/ultralib/src/io/vigetcurrcontext.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -__OSViContext* __osViGetCurrentContext(void) { - return __osViCurr; -} diff --git a/lib/ultralib/src/io/vigetcurrframebuf.c b/lib/ultralib/src/io/vigetcurrframebuf.c deleted file mode 100644 index de36712..0000000 --- a/lib/ultralib/src/io/vigetcurrframebuf.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "viint.h" - -void* osViGetCurrentFramebuffer(void) { - register u32 saveMask; - void* framep; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVIGETCURRENTFRAMEBUFFER, 0); - return NULL; - } -#endif - - saveMask = __osDisableInt(); - framep = __osViCurr->framep; - __osRestoreInt(saveMask); - return framep; -} diff --git a/lib/ultralib/src/io/vigetfield.c b/lib/ultralib/src/io/vigetfield.c deleted file mode 100644 index 9dcb7fc..0000000 --- a/lib/ultralib/src/io/vigetfield.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -u32 osViGetCurrentField(void) { - return IO_READ(VI_CURRENT_REG) & 1; -} diff --git a/lib/ultralib/src/io/vigetline.c b/lib/ultralib/src/io/vigetline.c deleted file mode 100644 index 5667d61..0000000 --- a/lib/ultralib/src/io/vigetline.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -u32 osViGetCurrentLine(void) { - return IO_READ(VI_CURRENT_REG); -} diff --git a/lib/ultralib/src/io/vigetmode.c b/lib/ultralib/src/io/vigetmode.c deleted file mode 100644 index 2507372..0000000 --- a/lib/ultralib/src/io/vigetmode.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "viint.h" - -u32 osViGetCurrentMode(void) { - register u32 saveMask; - register u32 modeType; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVIGETCURRENTMODE, 0); - return -1; - } -#endif - - saveMask = __osDisableInt(); - modeType = (u32)__osViCurr->modep->type; - - __osRestoreInt(saveMask); - return modeType; -} diff --git a/lib/ultralib/src/io/vigetnextcontext.c b/lib/ultralib/src/io/vigetnextcontext.c deleted file mode 100644 index bb6012a..0000000 --- a/lib/ultralib/src/io/vigetnextcontext.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "viint.h" - -__OSViContext* __osViGetNextContext(void) { - return __osViNext; -} diff --git a/lib/ultralib/src/io/vigetnextframebuf.c b/lib/ultralib/src/io/vigetnextframebuf.c deleted file mode 100644 index 2985358..0000000 --- a/lib/ultralib/src/io/vigetnextframebuf.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "viint.h" - -void* osViGetNextFramebuffer(void) { - register u32 saveMask; - void* framep; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVIGETNEXTFRAMEBUFFER, 0); - return NULL; - } -#endif - - saveMask = __osDisableInt(); - framep = __osViNext->framep; - __osRestoreInt(saveMask); - return framep; -} diff --git a/lib/ultralib/src/io/vigetstat.c b/lib/ultralib/src/io/vigetstat.c deleted file mode 100644 index 8fc6f38..0000000 --- a/lib/ultralib/src/io/vigetstat.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" - -u32 osViGetStatus(void) { - return IO_READ(VI_STATUS_REG); -} diff --git a/lib/ultralib/src/io/viint.h b/lib/ultralib/src/io/viint.h deleted file mode 100644 index ffe0927..0000000 --- a/lib/ultralib/src/io/viint.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef _VIINT_H -#define _VIINT_H -#include "PR/os_internal.h" - -#define OS_TV_TYPE_PAL 0 -#define OS_TV_TYPE_NTSC 1 -#define OS_TV_TYPE_MPAL 2 - -#define VI_STATE_MODE_UPDATED 0x01 -#define VI_STATE_XSCALE_UPDATED 0x02 -#define VI_STATE_YSCALE_UPDATED 0x04 -#define VI_STATE_CTRL_UPDATED 0x08 // related to control regs changing -#define VI_STATE_BUFFER_UPDATED 0x10 // swap buffer -#define VI_STATE_BLACK 0x20 // probably related to a black screen -#define VI_STATE_REPEATLINE 0x40 // repeat line? -#define VI_STATE_FADE 0x80 // fade - -#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ -#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ -#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ - -#define VI_SCALE_MASK 0xfff //see rcp scale_x/scale_y -#define VI_2_10_FPART_MASK 0x3ff -#define VI_SUBPIXEL_SH 0x10 - -#define BURST(hsync_width, color_width, vsync_width, color_start) \ - (((u32)(hsync_width) & 0xFF) | (((u32)(color_width) & 0xFF) << 8) | (((u32)(vsync_width) & 0xF) << 16) | (((u32)(color_start) & 0xFFFF) << 20)) -#define WIDTH(v) (v) -#define VSYNC(v) (v) -#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration) & 0xFFFF)) -#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower) & 0xFFFF)) -#define START(start, end) (((u32)(start) << 16) | ((u32)(end) & 0xFFFF)) - -#define FTOFIX(val, i, f) ((u32)((val) * (f32)(1 << (f))) & ((1 << ((i) + (f))) - 1)) - -#define F210(val) FTOFIX(val, 2, 10) -#define SCALE(scaleup, off) (F210((1.0f / (f32)(scaleup))) | (F210((f32)(off)) << 16)) - -#define VCURRENT(v) v //seemingly unused -#define ORIGIN(v) v -#define VINTR(v) v -#define HSTART START - -typedef struct -{ - /* 0x0 */ f32 factor; - /* 0x4 */ u16 offset; - /* 0x8 */ u32 scale; -} __OSViScale; - -typedef struct -{ - /* 0x0 */ u16 state; - /* 0x2 */ u16 retraceCount; - /* 0x4 */ void *framep; - /* 0x8 */ OSViMode *modep; - /* 0xC */ u32 control; - /* 0x10 */ OSMesgQueue *msgq; - /* 0x14 */ OSMesg msg; - /* 0x18 */ __OSViScale x; - /* 0x24 */ __OSViScale y; -} __OSViContext; // 0x30 bytes - -void __osViSwapContext(void); -extern __OSViContext *__osViCurr; -extern __OSViContext *__osViNext; -extern u32 __additional_scanline; -__OSViContext *__osViGetCurrentContext(void); -void __osViInit(void); -extern OSDevMgr __osViDevMgr; -#endif diff --git a/lib/ultralib/src/io/vimgr.c b/lib/ultralib/src/io/vimgr.c deleted file mode 100644 index 0fe51d5..0000000 --- a/lib/ultralib/src/io/vimgr.c +++ /dev/null @@ -1,126 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/rcp.h" -#include "viint.h" -#include "../os/osint.h" - -OSDevMgr __osViDevMgr = { 0 }; -#if BUILD_VERSION >= VERSION_J -u32 __additional_scanline = 0; -#endif -static OSThread viThread; -static unsigned char viThreadStack[OS_VIM_STACKSIZE] ALIGNED(16); -static OSMesgQueue viEventQueue ALIGNED(8); -static OSMesg viEventBuf[5] ALIGNED(8); -static OSIoMesg viRetraceMsg ALIGNED(8); -static OSIoMesg viCounterMsg ALIGNED(8); - -static void viMgrMain(void* arg); -void osCreateViManager(OSPri pri) { - u32 savedMask; - OSPri oldPri; - OSPri myPri; - -#ifdef _DEBUG - if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { - __osError(ERR_OSCREATEVIMANAGER, 1, pri); - return; - } -#endif - - if (__osViDevMgr.active) { - return; - } - __osTimerServicesInit(); -#if BUILD_VERSION >= VERSION_J - __additional_scanline = 0; -#endif - osCreateMesgQueue(&viEventQueue, viEventBuf, ARRLEN(viEventBuf)); - viRetraceMsg.hdr.type = OS_MESG_TYPE_VRETRACE; - viRetraceMsg.hdr.pri = OS_MESG_PRI_NORMAL; - viRetraceMsg.hdr.retQueue = NULL; - viCounterMsg.hdr.type = OS_MESG_TYPE_COUNTER; - viCounterMsg.hdr.pri = OS_MESG_PRI_NORMAL; - viCounterMsg.hdr.retQueue = NULL; - osSetEventMesg(OS_EVENT_VI, &viEventQueue, &viRetraceMsg); - osSetEventMesg(OS_EVENT_COUNTER, &viEventQueue, &viCounterMsg); - oldPri = -1; - myPri = osGetThreadPri(NULL); - - if (myPri < pri) { - oldPri = myPri; - osSetThreadPri(NULL, pri); - } - - savedMask = __osDisableInt(); - __osViDevMgr.active = TRUE; - __osViDevMgr.thread = &viThread; - __osViDevMgr.cmdQueue = &viEventQueue; - __osViDevMgr.evtQueue = &viEventQueue; - __osViDevMgr.acsQueue = NULL; - __osViDevMgr.dma = NULL; - __osViDevMgr.edma = NULL; - osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &viThreadStack[OS_VIM_STACKSIZE], pri); - __osViInit(); - osStartThread(&viThread); - __osRestoreInt(savedMask); - - if (oldPri != -1) { - osSetThreadPri(NULL, oldPri); - } -} - -static void viMgrMain(void* arg) { - __OSViContext* vc; - OSDevMgr* dm; - OSIoMesg* mb; - static u16 retrace; - s32 first; - u32 count; - - mb = NULL; - first = 0; - vc = __osViGetCurrentContext(); - retrace = vc->retraceCount; - if (retrace == 0) { - retrace = 1; - } - dm = (OSDevMgr*)arg; - - while (TRUE) { - osRecvMesg(dm->evtQueue, (OSMesg)&mb, OS_MESG_BLOCK); - switch (mb->hdr.type) { - case OS_MESG_TYPE_VRETRACE: - __osViSwapContext(); - retrace--; - - if (retrace == 0) { - vc = __osViGetCurrentContext(); - if (vc->msgq != NULL) { - osSendMesg(vc->msgq, vc->msg, OS_MESG_NOBLOCK); - } - retrace = vc->retraceCount; - } - - __osViIntrCount++; - - if (first) { - count = osGetCount(); - __osCurrentTime = count; - first = 0; - } - - count = __osBaseCounter; - __osBaseCounter = osGetCount(); - count = __osBaseCounter - count; - __osCurrentTime = __osCurrentTime + count; - break; - case OS_MESG_TYPE_COUNTER: - __osTimerInterrupt(); - break; - default: - break; - } - } -} diff --git a/lib/ultralib/src/io/virepeatline.c b/lib/ultralib/src/io/virepeatline.c deleted file mode 100644 index 1bc4984..0000000 --- a/lib/ultralib/src/io/virepeatline.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/os_internal.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViRepeatLine(u8 active) { - register u32 saveMask = __osDisableInt(); - - if (active) { - __osViNext->state |= VI_STATE_REPEATLINE; - } else { - __osViNext->state &= ~VI_STATE_REPEATLINE; - } - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/visetevent.c b/lib/ultralib/src/io/visetevent.c deleted file mode 100644 index f741a0e..0000000 --- a/lib/ultralib/src/io/visetevent.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "assert.h" -#include "viint.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount) { - register u32 saveMask; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVISETEVENT, 0); - return; - } - - assert(mq != NULL); -#endif - - saveMask = __osDisableInt(); - - __osViNext->msgq = mq; - __osViNext->msg = m; - __osViNext->retraceCount = retraceCount; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/visetmode.c b/lib/ultralib/src/io/visetmode.c deleted file mode 100644 index 5ab2094..0000000 --- a/lib/ultralib/src/io/visetmode.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "assert.h" -#include "viint.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViSetMode(OSViMode* modep) { - register u32 saveMask; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVISETMODE, 0); - return; - } - - assert(modep != NULL); -#endif - - saveMask = __osDisableInt(); - - __osViNext->modep = modep; - __osViNext->state = VI_STATE_MODE_UPDATED; - __osViNext->control = __osViNext->modep->comRegs.ctrl; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/visetspecial.c b/lib/ultralib/src/io/visetspecial.c deleted file mode 100644 index 0a288e5..0000000 --- a/lib/ultralib/src/io/visetspecial.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/rcp.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -// This value was incorrectly calculated until being fixed in 2.0J -#if BUILD_VERSION >= VERSION_J -#define OS_VI_SPECIAL_MAX \ - (OS_VI_GAMMA_ON | OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_ON | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | \ - OS_VI_DIVOT_OFF | OS_VI_DITHER_FILTER_ON | OS_VI_DITHER_FILTER_OFF) -#else -#define OS_VI_SPECIAL_MAX OS_VI_DITHER_FILTER_OFF -#endif - -void osViSetSpecialFeatures(u32 func) { - register u32 saveMask; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVISETSPECIAL_VIMGR, 0); - return; - } - - if ((func < OS_VI_GAMMA_ON) || (func > OS_VI_SPECIAL_MAX)) { - __osError(ERR_OSVISETSPECIAL_VALUE, 1, func); - return; - } -#endif - - saveMask = __osDisableInt(); - - if ((func & OS_VI_GAMMA_ON) != 0) { - __osViNext->control |= VI_CTRL_GAMMA_ON; - } - - if ((func & OS_VI_GAMMA_OFF) != 0) { - __osViNext->control &= ~VI_CTRL_GAMMA_ON; - } - - if ((func & OS_VI_GAMMA_DITHER_ON) != 0) { - __osViNext->control |= VI_CTRL_GAMMA_DITHER_ON; - } - - if ((func & OS_VI_GAMMA_DITHER_OFF) != 0) { - __osViNext->control &= ~VI_CTRL_GAMMA_DITHER_ON; - } - - if ((func & OS_VI_DIVOT_ON) != 0) { - __osViNext->control |= VI_CTRL_DIVOT_ON; - } - - if ((func & OS_VI_DIVOT_OFF) != 0) { - __osViNext->control &= ~VI_CTRL_DIVOT_ON; - } - - if ((func & OS_VI_DITHER_FILTER_ON) != 0) { - __osViNext->control |= VI_CTRL_DITHER_FILTER_ON; - __osViNext->control &= ~VI_CTRL_ANTIALIAS_MASK; - } - - if ((func & OS_VI_DITHER_FILTER_OFF) != 0) { - __osViNext->control &= ~VI_CTRL_DITHER_FILTER_ON; - __osViNext->control |= __osViNext->modep->comRegs.ctrl & VI_CTRL_ANTIALIAS_MASK; - } - - __osViNext->state |= VI_STATE_CTRL_UPDATED; - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/visetxscale.c b/lib/ultralib/src/io/visetxscale.c deleted file mode 100644 index 6af6535..0000000 --- a/lib/ultralib/src/io/visetxscale.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/ultralog.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViSetXScale(f32 value) { - register u32 nomValue; - register u32 saveMask; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVISETXSCALE_VIMGR, 0); - return; - } - - if ((value < 0.25f) || (value > 1.0f)) { - __osError(ERR_OSVISETXSCALE_VALUE, 1, OS_LOG_FLOAT(value)); - - if (value < 0.25f) { - value = 0.25f; - } else { - value = 1.0f; - } - } -#endif - - saveMask = __osDisableInt(); - - __osViNext->x.factor = value; - __osViNext->state |= VI_STATE_XSCALE_UPDATED; - nomValue = __osViNext->modep->comRegs.xScale & VI_SCALE_MASK; - __osViNext->x.scale = (u32)(__osViNext->x.factor * nomValue) & VI_SCALE_MASK; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/visetyscale.c b/lib/ultralib/src/io/visetyscale.c deleted file mode 100644 index c1c96f4..0000000 --- a/lib/ultralib/src/io/visetyscale.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/ultralog.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViSetYScale(f32 value) { - register u32 saveMask; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVISETYSCALE_VIMGR, 0); - return; - } - - if ((value < 0.05f) || (value > 1.0f)) { - __osError(ERR_OSVISETYSCALE_VALUE, 1, OS_LOG_FLOAT(value)); - - if (value < 0.05f) { - value = 0.05f; - } else { - value = 1.0f; - } - } -#endif - - saveMask = __osDisableInt(); - - __osViNext->y.factor = value; - __osViNext->state |= VI_STATE_YSCALE_UPDATED; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/viswapbuf.c b/lib/ultralib/src/io/viswapbuf.c deleted file mode 100644 index aa077cd..0000000 --- a/lib/ultralib/src/io/viswapbuf.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "assert.h" -#include "viint.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osViSwapBuffer(void* frameBufPtr) { - u32 saveMask; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSVISWAPBUFFER_VIMGR, 0); - return; - } - - assert(frameBufPtr != NULL); - - if ((u32)frameBufPtr & 0x3f) { - __osError(ERR_OSVISWAPBUFFER_ADDR, 1, frameBufPtr); - return; - } -#endif - - saveMask = __osDisableInt(); - - __osViNext->framep = frameBufPtr; - __osViNext->state |= VI_STATE_BUFFER_UPDATED; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/io/viswapcontext.c b/lib/ultralib/src/io/viswapcontext.c deleted file mode 100644 index 2f6d2c6..0000000 --- a/lib/ultralib/src/io/viswapcontext.c +++ /dev/null @@ -1,80 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "viint.h" - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void __osViSwapContext() { - register OSViMode* vm; - register __OSViContext* vc; - u32 origin; - u32 hStart; -#if BUILD_VERSION >= VERSION_J - u32 vStart; -#endif - u32 nomValue; - u32 field; - - field = 0; - vc = __osViNext; - vm = vc->modep; - - field = IO_READ(VI_CURRENT_REG) & 1; // field num - - origin = osVirtualToPhysical(vc->framep) + (vm->fldRegs[field].origin); - if (vc->state & VI_STATE_XSCALE_UPDATED) { - vc->x.scale |= (vm->comRegs.xScale & ~VI_SCALE_MASK); - } else { - vc->x.scale = vm->comRegs.xScale; - } - - if (vc->state & VI_STATE_YSCALE_UPDATED) { - nomValue = vm->fldRegs[field].yScale & VI_SCALE_MASK; - vc->y.scale = vc->y.factor * nomValue; - vc->y.scale |= vm->fldRegs[field].yScale & ~VI_SCALE_MASK; - } else { - vc->y.scale = vm->fldRegs[field].yScale; - } - -#if BUILD_VERSION >= VERSION_J - vStart = (vm->fldRegs[field].vStart - (__additional_scanline << 0x10)) + __additional_scanline; -#endif - hStart = vm->comRegs.hStart; - - if (vc->state & VI_STATE_BLACK) { - hStart = 0; - } - - if (vc->state & VI_STATE_REPEATLINE) { - vc->y.scale = 0; - origin = osVirtualToPhysical(vc->framep); - } - - if (vc->state & VI_STATE_FADE) { - vc->y.scale = (vc->y.offset << VI_SUBPIXEL_SH) & (VI_2_10_FPART_MASK << VI_SUBPIXEL_SH); - origin = osVirtualToPhysical(vc->framep); - } - - IO_WRITE(VI_ORIGIN_REG, origin); - IO_WRITE(VI_WIDTH_REG, vm->comRegs.width); - IO_WRITE(VI_BURST_REG, vm->comRegs.burst); - IO_WRITE(VI_V_SYNC_REG, vm->comRegs.vSync); - IO_WRITE(VI_H_SYNC_REG, vm->comRegs.hSync); - IO_WRITE(VI_LEAP_REG, vm->comRegs.leap); - IO_WRITE(VI_H_START_REG, hStart); -#if BUILD_VERSION >= VERSION_J - IO_WRITE(VI_V_START_REG, vStart); -#else - IO_WRITE(VI_V_START_REG, vm->fldRegs[field].vStart); -#endif - IO_WRITE(VI_V_BURST_REG, vm->fldRegs[field].vBurst); - IO_WRITE(VI_INTR_REG, vm->fldRegs[field].vIntr); - IO_WRITE(VI_X_SCALE_REG, vc->x.scale); - IO_WRITE(VI_Y_SCALE_REG, vc->y.scale); - IO_WRITE(VI_CONTROL_REG, vc->control); - - __osViNext = __osViCurr; - __osViCurr = vc; - *__osViNext = *__osViCurr; -} diff --git a/lib/ultralib/src/io/vitbl.c b/lib/ultralib/src/io/vitbl.c deleted file mode 100644 index 476036e..0000000 --- a/lib/ultralib/src/io/vitbl.c +++ /dev/null @@ -1,1740 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeTable[] = { - { OS_VI_NTSC_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_NTSC_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_PAL_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - //[0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - //[1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_MPAL_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } } }, -#if BUILD_VERSION >= VERSION_J - { OS_VI_FPAL_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } }, - { OS_VI_FPAL_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } } } -#endif -}; diff --git a/lib/ultralib/src/libc/bcmp.s b/lib/ultralib/src/libc/bcmp.s deleted file mode 100644 index 11db46d..0000000 --- a/lib/ultralib/src/libc/bcmp.s +++ /dev/null @@ -1,96 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -#ifdef __sgi -WEAK(bcmp, _bcmp) -#else -#define _bcmp bcmp -#endif -LEAF(_bcmp) - xor v0, a0, a1 - blt a2, 16, bytecmp - - andi v0, v0, 0x3 - negu t8, a0 - bnez v0, unalgncmp - - andi t8, t8, 0x3 - subu a2, a2, t8 - beqz t8, wordcmp - - move v0, v1 - lwl v0, 0(a0) - lwl v1, 0(a1) - addu a0, a0, t8 - addu a1, a1, t8 - bne v0, v1, cmpne - -wordcmp: - and a3, a2, ~3 - subu a2, a2, a3 - beqz a3, bytecmp - - addu a3, a3, a0 -1: - lw v0, 0(a0) - lw v1, 0(a1) - addiu a0, a0, 4 - addiu a1, a1, 4 - bne v0, v1, cmpne - bne a0, a3, 1b - - b bytecmp -unalgncmp: - negu a3, a1 - andi a3, a3, 0x3 - subu a2, a2, a3 - beqz a3, partaligncmp - - addu a3, a3, a0 - -1: - lbu v0, 0(a0) - lbu v1, 0(a1) - addiu a0, a0, 1 - addiu a1, a1, 1 - bne v0, v1, cmpne - bne a0, a3, 1b - -partaligncmp: - and a3, a2, ~3 - subu a2, a2, a3 - beqz a3, bytecmp - - addu a3, a3, a0 - -1: - lwl v0, 0(a0) - lwr v0, 3(a0) - lw v1, 0(a1) - addiu a0, a0, 4 - addiu a1, a1, 4 - bne v0, v1, cmpne - bne a0, a3, 1b - -bytecmp: - addu a3, a2, a0 - blez a2, cmpdone - -1: - lbu v0, 0(a0) - lbu v1, 0(a1) - addiu a0, a0, 1 - addiu a1, a1, 1 - bne v0, v1, cmpne - bne a0, a3, 1b - -cmpdone: - move v0, zero - jr ra -cmpne: - li v0, 1 - jr ra - -.end _bcmp diff --git a/lib/ultralib/src/libc/bcopy.s b/lib/ultralib/src/libc/bcopy.s deleted file mode 100644 index 216c378..0000000 --- a/lib/ultralib/src/libc/bcopy.s +++ /dev/null @@ -1,220 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -#ifdef __sgi -WEAK(bcopy, _bcopy) -#else -#define _bcopy bcopy -#endif -LEAF(_bcopy) - move a3, a1 - beqz a2, ret - beq a0, a1, ret - blt a1, a0, goforwards - - add v0, a0, a2 - bge a1, v0, goforwards - b gobackwards - -goforwards: - - blt a2, 16, forwards_bytecopy - - andi v0, a0, 0x3 - andi v1, a1, 0x3 - beq v0, v1,forwalignable - - -forwards_bytecopy: - beqz a2, ret - addu v1, a0, a2 -99: - lb v0, 0(a0) - addiu a0, a0, 1 - sb v0, 0(a1) - addiu a1, a1, 1 - bne a0, v1, 99b -ret: - move v0, a3 - jr ra - -forwalignable: - beqz v0, forwards - beq v0, 1, forw_copy3 - beq v0, 2, forw_copy2 - - lb v0, 0(a0) - addiu a0, a0, 1 - sb v0, 0(a1) - addiu a1, a1, 1 - addiu a2, a2, -1 - b forwards - -forw_copy2: - lh v0, 0(a0) - addiu a0, a0, 2 - sh v0, 0(a1) - addiu a1, a1, 2 - addiu a2, a2, -2 - b forwards - -forw_copy3: - lb v0, 0(a0) - lh v1, 1(a0) - addiu a0, a0, 3 - sb v0, 0(a1) - sh v1, 1(a1) - addiu a1, a1, 3 - addiu a2, a2, -3 - -forwards: -forwards_32: - blt a2, 32, forwards_16 - lw v0, 0(a0) - lw v1, 4(a0) - lw t0, 8(a0) - lw t1, 12(a0) - lw t2, 16(a0) - lw t3, 20(a0) - lw ta0, 24(a0) - lw ta1, 28(a0) - addiu a0, a0, 32 - sw v0, 0(a1) - sw v1, 4(a1) - sw t0, 8(a1) - sw t1, 12(a1) - sw t2, 16(a1) - sw t3, 20(a1) - sw ta0, 24(a1) - sw ta1, 28(a1) - addiu a1, a1, 32 - addiu a2, a2, -32 - b forwards_32 - -forwards_16: - blt a2, 16, forwards_4 - lw v0, 0(a0) - lw v1, 4(a0) - lw t0, 8(a0) - lw t1, 12(a0) - addiu a0, a0, 16 - sw v0, 0(a1) - sw v1, 4(a1) - sw t0, 8(a1) - sw t1, 12(a1) - addiu a1, a1, 16 - addiu a2, a2, -16 - b forwards_16 - -forwards_4: - blt a2, 4, forwards_bytecopy - - lw v0, 0(a0) - addiu a0, a0, 4 - sw v0, 0(a1) - addiu a1, a1, 4 - addiu a2, a2, -4 - b forwards_4 - -gobackwards: - add a0, a0,a2 - add a1, a1,a2 - blt a2, 16, backwards_bytecopy - - andi v0, a0, 0x3 - andi v1, a1, 0x3 - beq v0, v1,backalignable - -backwards_bytecopy: - beqz a2, ret - addiu a0, a0, -1 - addiu a1, a1, -1 - subu v1, a0,a2 -99: - lb v0, 0(a0) - addiu a0, a0, -1 - sb v0, 0(a1) - addiu a1, a1, -1 - bne a0, v1,99b - - move v0, a3 - jr ra -backalignable: - beqz v0, backwards - beq v0, 3, back_copy3 - beq v0, 2, back_copy2 - lb v0, -1(a0) - addiu a0, a0, -1 - sb v0, -1(a1) - addiu a1, a1, -1 - addiu a2, a2, -1 - b backwards - -back_copy2: - lh v0, -2(a0) - addiu a0, a0, -2 - sh v0, -2(a1) - addiu a1, a1, -2 - addiu a2, a2, -2 - b backwards - -back_copy3: - lb v0, -1(a0) - lh v1, -3(a0) - addiu a0, a0, -3 - sb v0, -1(a1) - sh v1, -3(a1) - addiu a1, a1, -3 - addiu a2, a2, -3 - -backwards: -backwards_32: - blt a2, 32, backwards_16 - lw v0, -4(a0) - lw v1, -8(a0) - lw t0, -12(a0) - lw t1, -16(a0) - lw t2, -20(a0) - lw t3, -24(a0) - lw ta0, -28(a0) - lw ta1, -32(a0) - addiu a0, a0, -32 - sw v0, -4(a1) - sw v1, -8(a1) - sw t0, -12(a1) - sw t1, -16(a1) - sw t2, -20(a1) - sw t3, -24(a1) - sw ta0, -28(a1) - sw ta1, -32(a1) - addiu a1, a1, -32 - addiu a2, a2, -32 - b backwards_32 - -backwards_16: - blt a2, 16, backwards_4 - lw v0, -4(a0) - lw v1, -8(a0) - lw t0, -12(a0) - lw t1, -16(a0) - addiu a0, a0, -16 - sw v0, -4(a1) - sw v1, -8(a1) - sw t0, -12(a1) - sw t1, -16(a1) - addiu a1, a1, -16 - addiu a2, a2, -16 - b backwards_16 - -backwards_4: - blt a2, 4, backwards_bytecopy - lw v0, -4(a0) - addiu a0, a0, -4 - sw v0, -4(a1) - addiu a1, a1, -4 - addiu a2, a2, -4 - b backwards_4 - -.end _bcopy diff --git a/lib/ultralib/src/libc/bzero.s b/lib/ultralib/src/libc/bzero.s deleted file mode 100644 index 894c186..0000000 --- a/lib/ultralib/src/libc/bzero.s +++ /dev/null @@ -1,64 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -#ifdef __sgi -WEAK(bzero, _bzero) -WEAK(blkclr, _blkclr) -#else -#define _bzero bzero -#define _blkclr blkclr -#endif -LEAF(_bzero) -XLEAF(_blkclr) - negu v1, a0 - blt a1, 12, bytezero - - andi v1, v1, 0x3 - subu a1, a1, v1 - - beqz v1, blkzero - swl zero, 0(a0) - addu a0, a0, v1 -blkzero: - and a3, a1, ~31 - subu a1, a1, a3 - beqz a3, wordzero - - addu a3, a3, a0 -1: - sw zero, 0(a0) - sw zero, 4(a0) - sw zero, 8(a0) - sw zero, 12(a0) - addiu a0, a0, 32 - sw zero, -16(a0) - sw zero, -12(a0) - sw zero, -8(a0) - sw zero, -4(a0) - bne a0, a3, 1b - -wordzero: - and a3, a1, ~3 - subu a1, a1, a3 - beqz a3, bytezero - - addu a3, a3, a0 -1: - addiu a0, a0, 4 - sw zero, -4(a0) - bne a0, a3, 1b - -bytezero: - blez a1, zerodone - #nop - addu a1, a1, a0 -1: - addiu a0, a0, 1 - sb zero, -1(a0) - bne a0, a1, 1b -zerodone: - jr ra - -.end _bzero diff --git a/lib/ultralib/src/libc/ldiv.c b/lib/ultralib/src/libc/ldiv.c deleted file mode 100644 index 92388d3..0000000 --- a/lib/ultralib/src/libc/ldiv.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "os_version.h" -#include "stdlib.h" - -// TODO: these come from headers -#ident "$Revision: 1.34 $" -#ident "$Revision: 1.5 $" - -ldiv_t ldiv(long num, long denom) { - ldiv_t ret; - - ret.quot = num / denom; - ret.rem = num - denom * ret.quot; - - if (ret.quot < 0 && ret.rem > 0) { - ret.quot += 1; - ret.rem -= denom; - } - - return ret; -} - -lldiv_t lldiv(long long num, long long denom) { - lldiv_t ret; - - ret.quot = num / denom; - ret.rem = num - denom * ret.quot; - - if (ret.quot < 0 && ret.rem > 0) { - ret.quot += 1; - ret.rem -= denom; - } - - return ret; -} diff --git a/lib/ultralib/src/libc/ll.c b/lib/ultralib/src/libc/ll.c deleted file mode 100644 index 4334b03..0000000 --- a/lib/ultralib/src/libc/ll.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "PR/os.h" - -unsigned long long __ull_rshift(unsigned long long a0, unsigned long long a1) { - return a0 >> a1; -} - -unsigned long long __ull_rem(unsigned long long a0, unsigned long long a1) { - return a0 % a1; -} - -unsigned long long __ull_div(unsigned long long a0, unsigned long long a1) { - return a0 / a1; -} - -unsigned long long __ll_lshift(unsigned long long a0, unsigned long long a1) { - return a0 << a1; -} - -long long __ll_rem(unsigned long long a0, long long a1) { - return a0 % a1; -} - -long long __ll_div(long long a0, long long a1) { - return a0 / a1; -} - -unsigned long long __ll_mul(unsigned long long a0, unsigned long long a1) { - return a0 * a1; -} - -void __ull_divremi(unsigned long long* div, unsigned long long* rem, unsigned long long a2, unsigned short a3) { - *div = a2 / a3; - *rem = a2 % a3; -} - -long long __ll_mod(long long a0, long long a1) { - long long tmp = a0 % a1; - - if ((tmp < 0 && a1 > 0) || (tmp > 0 && a1 < 0)) { - tmp += a1; - } - - return tmp; -} - -long long __ll_rshift(long long a0, long long a1) { - return a0 >> a1; -} diff --git a/lib/ultralib/src/libc/llbit.c b/lib/ultralib/src/libc/llbit.c deleted file mode 100644 index 0680726..0000000 --- a/lib/ultralib/src/libc/llbit.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "PR/os.h" -#include "PR/ultratypes.h" - -s64 __ll_bit_extract(u64* addr, unsigned int start_bit, unsigned int length) { - unsigned int words; - unsigned int lbits; - unsigned int rbits; - u64 mask; - - words = start_bit / 64; - lbits = start_bit & (64 - 1); - rbits = 64 - (lbits + length); - - addr += words; - mask = ((u64)1 << length) - 1; - mask = mask << rbits; - return (s64)((*addr & mask) >> rbits); -} - -u64 __ull_bit_extract(u64* addr, unsigned int start_bit, unsigned int length) { - unsigned int words; - unsigned int lbits; - unsigned int rbits; - u64 mask; - - words = start_bit / 64; - lbits = start_bit & (64 - 1); - rbits = 64 - (lbits + length); - addr += words; - mask = ((u64)1 << length) - 1; - mask = mask << rbits; - return (u64)((*addr & mask) >> rbits); -} - -u64 __ll_bit_insert(u64* addr, unsigned int start_bit, unsigned int length, u64 val) { - unsigned int words; - unsigned int lbits; - unsigned int rbits; - unsigned long long llval; - unsigned long long mask; - - words = start_bit / 64; - lbits = start_bit & 0x3f; - rbits = 64 - (lbits + length); - addr += words; - mask = ((u64)1 << length) - 1; - mask <<= rbits; - llval = (val << (64 - length)) >> lbits; - *addr = (*addr & ~mask) | llval; - llval = llval >> rbits; - return llval; -} diff --git a/lib/ultralib/src/libc/llcvt.c b/lib/ultralib/src/libc/llcvt.c deleted file mode 100644 index 74d244b..0000000 --- a/lib/ultralib/src/libc/llcvt.c +++ /dev/null @@ -1,31 +0,0 @@ -long long __d_to_ll(double d) { - return d; -} - -long long __f_to_ll(float f) { - return f; -} - -unsigned long long __d_to_ull(double d) { - return d; -} - -unsigned long long __f_to_ull(float f) { - return f; -} - -double __ll_to_d(long long s) { - return s; -} - -float __ll_to_f(long long s) { - return s; -} - -double __ull_to_d(unsigned long long u) { - return u; -} - -float __ull_to_f(unsigned long long u) { - return u; -} diff --git a/lib/ultralib/src/libc/sprintf.c b/lib/ultralib/src/libc/sprintf.c deleted file mode 100644 index fd95523..0000000 --- a/lib/ultralib/src/libc/sprintf.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "xstdio.h" -#include "string.h" -#include "os.h" - -// TODO: this comes from a header -#ident "$Revision: 1.23 $" - -static char* proutSprintf(char* dst, const char* src, size_t count); - -int sprintf(char* dst, const char* fmt, ...) { - s32 ans; - va_list ap; - va_start(ap, fmt); - ans = _Printf(proutSprintf, dst, fmt, ap); - if (ans >= 0) { - dst[ans] = 0; - } - return ans; -} -static char* proutSprintf(char* dst, const char* src, size_t count) { - return (char*)memcpy((u8*)dst, (u8*)src, count) + count; -} diff --git a/lib/ultralib/src/libc/string.c b/lib/ultralib/src/libc/string.c deleted file mode 100644 index 0f01d1f..0000000 --- a/lib/ultralib/src/libc/string.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "PR/ultratypes.h" -#include "string.h" - -// TODO: this comes from a header -#ident "$Revision: 1.23 $" - -char* strchr(const char* s, int c) { - const char ch = c; - while (*s != ch) { - if (*s == 0) { - return NULL; - } - s++; - } - return (char*)s; -} - -size_t strlen(const char* s) { - const char* sc = s; - while (*sc != 0) { - sc++; - } - return sc - s; -} - -void* memcpy(void* s1, const void* s2, size_t n) { - char* su1 = (char*)s1; - const char* su2 = (const char*)s2; - while (n > 0) { - *su1 = *su2; - su1++; - su2++; - n--; - } - return (void*)s1; -} diff --git a/lib/ultralib/src/libc/syncprintf.c b/lib/ultralib/src/libc/syncprintf.c deleted file mode 100644 index 572ac73..0000000 --- a/lib/ultralib/src/libc/syncprintf.c +++ /dev/null @@ -1,154 +0,0 @@ -#include "stdarg.h" -#include "PR/os.h" -#include "PR/rdb.h" -#include "xstdio.h" -#include "PR/rcp.h" - -extern void* __printfunc; - -#if BUILD_VERSION <= VERSION_J - -#ifndef _FINALROM -extern u32 __kmc_pt_mode; - -static void* proutSyncPrintf(void* str, const char* buf, size_t n) { - size_t sent = 0; - - while (sent < n) { - sent += __osRdbSend(buf + sent, n - sent, RDB_TYPE_GtoH_PRINT); - } - return 1; -} - -static volatile unsigned int* stat = (unsigned*)0xbff08004; -static volatile unsigned int* wport = (unsigned*)0xbff08000; -static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); - -static void rmonPutchar(char c) { - u32 data; - - while (*piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - } - - while (!(*stat & 4)) { - } - - *wport = c; -} - -static void* kmc_proutSyncPrintf(void* str, const char* buf, int n) { - int i; - char c; - char* p; - char* q; - char xbuf[128]; - static int column = 0; - - p = &xbuf; - - for (i = 0; i < n; i++) { - c = *buf++; - - switch (c) { - case '\n': - *p++ = '\n'; - column = 0; - break; - case '\t': - do { - *p++ = ' '; - } while (++column % 8); - break; - default: - column++; - *p++ = c; - break; - } - - if (c == '\n' || (p - xbuf) > 100) { - rmonPutchar((p - xbuf) - 1); - - q = xbuf; - while (q != p) { - rmonPutchar(*q++); - } - p = xbuf; - } - } - if (p != xbuf) { - rmonPutchar((p - xbuf) - 1); - - q = xbuf; - while (q != p) { - rmonPutchar(*q++); - } - } - return (void*)1; -} -#endif - -void osSyncPrintf(const char* fmt, ...) { - int ans; - va_list ap; - -#ifndef _FINALROM - va_start(ap, fmt); - if (__kmc_pt_mode) { - ans = _Printf(kmc_proutSyncPrintf, NULL, fmt, ap); - } else { - ans = _Printf(proutSyncPrintf, NULL, fmt, ap); - } - va_end(ap); -#endif -} - -void rmonPrintf(const char* fmt, ...) { - int ans; - va_list ap; - -#ifndef _FINALROM - va_start(ap, fmt); - if (__kmc_pt_mode) { - ans = _Printf(kmc_proutSyncPrintf, NULL, fmt, ap); - } - va_end(ap); -#endif -} - -#else - -void __osSyncVPrintf(const char* fmt, va_list args) { - - int ans; -#ifndef _FINALROM - if (__printfunc != NULL) { - ans = _Printf(__printfunc, NULL, fmt, args); - } -#endif -} - -void osSyncPrintf(const char* fmt, ...) { - int ans; - va_list ap; - -#ifndef _FINALROM - va_start(ap, fmt); - __osSyncVPrintf(fmt, ap); - va_end(ap); -#endif -} - -void rmonPrintf(const char* fmt, ...) { - int ans; - va_list ap; - -#ifndef _FINALROM - va_start(ap, fmt); - if (__printfunc != NULL) { - ans = _Printf(__printfunc, NULL, fmt, ap); - } - va_end(ap); -#endif -} - -#endif diff --git a/lib/ultralib/src/libc/xldtob.c b/lib/ultralib/src/libc/xldtob.c deleted file mode 100644 index 1dc1434..0000000 --- a/lib/ultralib/src/libc/xldtob.c +++ /dev/null @@ -1,309 +0,0 @@ -#include "stdlib.h" -#include "string.h" -#include "xstdio.h" - -// TODO: these come from headers -#ident "$Revision: 1.23 $" -#ident "$Revision: 1.34 $" -#ident "$Revision: 1.5 $" - -#define BUFF_LEN 0x20 - -static s16 _Ldunscale(s16* pex, _Pft* px); -static void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp); - -static const double pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L}; - -// float properties -#define _D0 0 -#define _DBIAS 0x3ff -#define _DLONG 1 -#define _DOFF 4 -#define _FBIAS 0x7e -#define _FOFF 7 -#define _FRND 1 -#define _LBIAS 0x3ffe -#define _LOFF 15 -// integer properties -#define _C2 1 -#define _CSIGN 1 -#define _ILONG 0 -#define _MBMAX 8 -#define NAN 2 -#define INF 1 -#define FINITE -1 -#define _DFRAC ((1 << _DOFF) - 1) -#define _DMASK (0x7fff & ~_DFRAC) -#define _DMAX ((1 << (15 - _DOFF)) - 1) -#define _DNAN (0x8000 | _DMAX << _DOFF | 1 << (_DOFF - 1)) -#define _DSIGN 0x8000 -#define _D1 1 // big-endian order -#define _D2 2 -#define _D3 3 - -#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1)) - -void _Ldtob(_Pft* px, char code) { - char buff[BUFF_LEN]; - char *p; - f64 ldval; - s16 err; - s16 nsig; - s16 xexp; - - // char unused[0x4]; - p = buff; - ldval = px->v.ld; - - if (px->prec < 0) { - px->prec = 6; - } else if (px->prec == 0 && (code == 'g' || code == 'G')) { - px->prec = 1; - } - - err = _Ldunscale(&xexp, px); - if (err > 0) { - memcpy(px->s, err == 2 ? "NaN" : "Inf", px->n1 = 3); - return; - } else if (err == 0) { - nsig = 0; - xexp = 0; - } else { - { - int i; - int n; - - if (ldval < 0) { - ldval = -ldval; - } - - // what - if ((xexp = xexp * 30103 / 100000 - 4) < 0) { - n = ALIGN(-xexp, 4), xexp = -n; - - for (i = 0; n > 0; n >>= 1, i++) { - if (n & 1) { - ldval *= pows[i]; - } - } - } else if (xexp > 0) { - f64 factor = 1; - - xexp &= ~3; - - for (n = xexp, i = 0; n > 0; n >>= 1, i++) { - if (n & 1) { - factor *= pows[i]; - } - } - - ldval /= factor; - } - } - { - int gen = px->prec + ((code == 'f') ? 10 + xexp : 6); - - if (gen > 0x13) { - gen = 0x13; - } - - for (*p++ = '0'; gen > 0 && 0 < ldval; p += 8) { - int j; - long lo = ldval; - - if ((gen -= 8) > 0) { - ldval = (ldval - lo) * 1e8; - } - - for (p += 8, j = 8; lo > 0 && --j >= 0;) { - ldiv_t qr; - qr = ldiv(lo, 10); - *--p = qr.rem + '0', lo = qr.quot; - } - - while (--j >= 0) { - *--p = '0'; - } - } - - gen = p - &buff[1]; - - for (p = &buff[1], xexp += 7; *p == '0'; p++) { - --gen, --xexp; - } - - nsig = px->prec + ((code == 'f') ? xexp + 1 : ((code == 'e' || code == 'E') ? 1 : 0)); - - if (gen < nsig) { - nsig = gen; - } - - if (nsig > 0) { - const char drop = nsig < gen && '5' <= p[nsig] ? '9' : '0'; - int n; - - for (n = nsig; p[--n] == drop;) { - --nsig; - } - - if (drop == '9') { - ++p[n]; - } - - if (n < 0) { - --p, ++nsig, ++xexp; - } - } - } - } - - _Genld(px, code, p, nsig, xexp); -} - -s16 _Ldunscale(s16* pex, _Pft* px) { - u16* ps = (u16*)px; - s16 xchar = (ps[_D0] & _DMASK) >> _DOFF; - - - if (xchar == _DMAX) { - *pex = 0; - - return (ps[_D0] & _DFRAC) || ps[_D1] || ps[_D2] || ps[_D3] ? 2 : 1; - } else if (xchar > 0) { - ps[_D0] = (ps[_D0] & ~_DMASK) | 0x3FF0; - *pex = xchar - 0x3FE; - return -1; - } else if (xchar < 0) { - return 2; - } else { - *pex = 0; - return 0; - } -} - -void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp) { - const unsigned char point = '.'; - - if (nsig <= 0) { - nsig = 1, p = "0"; - } - - if (code == 'f' || (code == 'g' || code == 'G') && xexp >= -4 && xexp < px->prec) { - xexp++; - if (code != 'f') { - if (((px->flags & 8) == 0) && nsig < px->prec) { - px->prec = nsig; - } - - if ((px->prec -= xexp) < 0) { - px->prec = 0; - } - } - - if (xexp <= 0) { - px->s[px->n1++] = '0'; - - if (px->prec > 0 || (px->flags & 8)) { - px->s[px->n1++] = point; - } - - if (px->prec < -xexp) { - xexp = -px->prec; - } - - px->nz1 = -xexp; - px->prec += xexp; - - if (px->prec < nsig) { - nsig = px->prec; - } - - memcpy(&px->s[px->n1], p, px->n2 = nsig); - px->nz2 = px->prec - nsig; - } else if (nsig < xexp) { - memcpy(&px->s[px->n1], p, nsig); - px->n1 += nsig; - px->nz1 = xexp - nsig; - if (px->prec > 0 || (px->flags & 8)) { - px->s[px->n1] = point; - px->n2++; - } - - px->nz2 = px->prec; - } else { - memcpy(&px->s[px->n1], p, xexp); - px->n1 += xexp; - nsig -= xexp; - - if (px->prec > 0 || (px->flags & 8)) { - px->s[px->n1++] = point; - } - - if (px->prec < nsig) { - nsig = px->prec; - } - - memcpy(&px->s[px->n1], &p[xexp], nsig); - px->n1 += nsig; - px->nz1 = px->prec - nsig; - } - } else { - if (code == 'g' || code == 'G') { - if (nsig < px->prec) { - px->prec = nsig; - } - - if (--px->prec < 0) { - px->prec = 0; - } - - code = (code == 'g') ? 'e' : 'E'; - } - - px->s[px->n1++] = *p++; - - if (px->prec > 0 || (px->flags & 8)) { - px->s[px->n1++] = point; - } - - if (px->prec > 0) { - if (px->prec < --nsig) { - nsig = px->prec; - } - - memcpy(&px->s[px->n1], p, nsig); - px->n1 += nsig; - px->nz1 = px->prec - nsig; - } - - p = &px->s[px->n1]; - *p++ = code; - - if (xexp >= 0) { - *p++ = '+'; - } else { - *p++ = '-'; - xexp = -xexp; - } - - if (xexp >= 100) { - if (xexp >= 1000) { - *p++ = (xexp / 1000) + '0', xexp %= 1000; - } - *p++ = (xexp / 100) + '0', xexp %= 100; - } - *p++ = (xexp / 10) + '0', xexp %= 10; - - *p++ = xexp + '0'; - px->n2 = (size_t)p - ((size_t)px->s + px->n1); - } - - if ((px->flags & 0x14) == 0x10) { - s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2; - - if (n < px->width) { - px->nz0 = px->width - n; - } - } -} - diff --git a/lib/ultralib/src/libc/xlitob.c b/lib/ultralib/src/libc/xlitob.c deleted file mode 100644 index 2b27b3a..0000000 --- a/lib/ultralib/src/libc/xlitob.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "stdlib.h" -#include "string.h" -#include "xstdio.h" - -// TODO: these come from headers -#ident "$Revision: 1.34 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.23 $" - -#define BUFF_LEN 0x18 - -static char ldigs[] = "0123456789abcdef"; -static char udigs[] = "0123456789ABCDEF"; - -void _Litob(_Pft *args, char type) { - char buff[BUFF_LEN]; - const char *digs; - s32 base; - s32 i; - unsigned long long ullval; - - digs = (type == 'X') ? udigs : ldigs; - - base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16); - i = BUFF_LEN; - ullval = args->v.ll; - - if ((type == 'd' || type == 'i') && args->v.ll < 0) { - ullval = -ullval; - } - - if (ullval != 0 || args->prec != 0) { - buff[--i] = digs[ullval % base]; - } - - args->v.ll = ullval / base; - - while (args->v.ll > 0 && i > 0) { - lldiv_t qr = lldiv(args->v.ll, base); - - args->v.ll = qr.quot; - buff[--i] = digs[qr.rem]; - } - - args->n1 = BUFF_LEN - i; - - memcpy(args->s, buff + i, args->n1); - - if (args->n1 < args->prec) { - args->nz0 = args->prec - args->n1; - } - - if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { - if ((i = args->width - args->n0 - args->nz0 - args->n1) > 0) { - args->nz0 += i; - } - } -} diff --git a/lib/ultralib/src/libc/xprintf.c b/lib/ultralib/src/libc/xprintf.c deleted file mode 100644 index 788f42c..0000000 --- a/lib/ultralib/src/libc/xprintf.c +++ /dev/null @@ -1,257 +0,0 @@ -#include "macros.h" -#include "string.h" -#include "stdarg.h" -#include "xstdio.h" - -// TODO: these come from headers -#ident "$Revision: 1.34 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.23 $" - -#define isdigit(x) ((x >= '0' && x <= '9')) -#define LDSIGN(x) (((unsigned short *)&(x))[0] & 0x8000) - -#define ATOI(dst, src) \ - for (dst = 0; isdigit(*src); ++src) \ - { \ - if (dst < 999) \ - dst = dst * 10 + *src - '0'; \ - } - -#define MAX_PAD ((sizeof(spaces) - 1)) -#define PAD(s, n) \ - if (0 < (n)) \ - { \ - int i, j = (n); \ - for (; 0 < j; j -= i) \ - { \ - i = MAX_PAD < (unsigned int)j ? (int)MAX_PAD : j; \ - PUT(s, i); \ - } \ - } -#define PUT(s, n) \ - if (0 < (n)) \ - { \ - if ((arg = (*prout)(arg, s, n)) != NULL) \ - x.nchar += (n); \ - else \ - return x.nchar; \ - } -static char spaces[] = " "; -static char zeroes[] = "00000000000000000000000000000000"; - -static void _Putfld(_Pft *pf, va_list *pap, char code, char *ac); - -int _Printf(outfun prout, char *arg, const char *fmt, va_list args) { - _Pft x; - - x.nchar = 0; - - while (TRUE) { - const char *s; - char c; - const char *t; - static const char fchar[] = {' ', '+', '-', '#', '0', '\0'}; - static const int fbit[] = {FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0}; - char ac[32]; - s = fmt; - - for (c = *s; c != 0 && c != '%';) { - c = *++s; - } - - PUT(fmt, s - fmt); - - if (c == 0) { - return x.nchar; - } - - fmt = ++s; - - for (x.flags = 0; (t = strchr(fchar, *s)) != NULL; s++) { - x.flags |= fbit[t - fchar]; - } - - if (*s == '*') { - x.width = va_arg(args, int); - - if (x.width < 0) { - x.width = -x.width; - x.flags |= FLAGS_MINUS; - } - s++; - } else - ATOI(x.width, s); - - - if (*s != '.') { - x.prec = -1; - } else if (*++s == '*') { - x.prec = va_arg(args, int); - ++s; - } else - for (x.prec = 0; isdigit(*s); s++) { - if (x.prec < 999) - x.prec = x.prec * 10 + *s - '0'; - } - - - x.qual = strchr("hlL", *s) ? *s++ : '\0'; - - if (x.qual == 'l' && *s == 'l') { - x.qual = 'L'; - ++s; - } - - _Putfld(&x, &args, *s, ac); - x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2; - - { - - if (!(x.flags & FLAGS_MINUS)) { - int i, j; - if (0 < (x.width)) - { - i, j = x.width; - for (; 0 < j; j -= i) - { - i = MAX_PAD < (unsigned int)j ? (int)MAX_PAD : j; - PUT(spaces, i); - } - } - } - - PUT(ac, x.n0); - PAD(zeroes, x.nz0) - - PUT(x.s, x.n1); - PAD(zeroes, x.nz1); - - PUT(x.s + x.n1, x.n2); - PAD(zeroes, x.nz2); - - if (x.flags & FLAGS_MINUS) { - PAD(spaces, x.width); - } - } - fmt = s + 1; - } - return 0; -} - -static void _Putfld(_Pft *x, va_list *args, char type, char *buff) { - x->n0 = x->nz0 = x->n1 = x->nz1 = x->n2 = - x->nz2 = 0; - - switch (type) { - case 'c': - buff[x->n0++] = va_arg(*args, int); - break; - case 'd': - case 'i': - if (x->qual == 'l') { - x->v.ll = va_arg(*args, int); - } else if (x->qual == 'L') { - x->v.ll = va_arg(*args, s64); - } else { - x->v.ll = va_arg(*args, int); - } - - if (x->qual == 'h') { - x->v.ll = (s16)x->v.ll; - } - - if (x->v.ll < 0) { - buff[x->n0++] = '-'; - } else if (x->flags & FLAGS_PLUS) { - buff[x->n0++] = '+'; - } else if (x->flags & FLAGS_SPACE) { - buff[x->n0++] = ' '; - } - - x->s = (char *)&buff[x->n0]; - - _Litob(x, type); - break; - case 'x': - case 'X': - case 'u': - case 'o': - if (x->qual == 'l') { - x->v.ll = va_arg(*args, int); - } else if (x->qual == 'L') { - x->v.ll = va_arg(*args, s64); - } else { - x->v.ll = va_arg(*args, int); - } - - if (x->qual == 'h') { - x->v.ll = (u16)x->v.ll; - } else if (x->qual == 0) { - x->v.ll = (unsigned int)x->v.ll; - } - - if (x->flags & FLAGS_HASH) { - buff[x->n0++] = '0'; - - if (type == 'x' || type == 'X') { - buff[x->n0++] = type; - } - } - - x->s = (char *)&buff[x->n0]; - _Litob(x, type); - break; - case 'e': - case 'f': - case 'g': - case 'E': - case 'G': - //... okay? - x->v.ld = x->qual == 'L' ? va_arg(*args, f64) : va_arg(*args, f64); - - if (LDSIGN(x->v.ld)) - buff[x->n0++] = '-'; - else if (x->flags & FLAGS_PLUS) - buff[x->n0++] = '+'; - else if (x->flags & FLAGS_SPACE) - buff[x->n0++] = ' '; - - x->s = (char *)&buff[x->n0]; - _Ldtob(x, type); - break; - - case 'n': - if (x->qual == 'h') { - *(va_arg(*args, u16 *)) = x->nchar; - } else if (x->qual == 'l') { - *va_arg(*args, unsigned int *) = x->nchar; - } else if (x->qual == 'L') { - *va_arg(*args, u64 *) = x->nchar; - } else { - *va_arg(*args, unsigned int *) = x->nchar; - } - - break; - case 'p': - x->v.ll = (long)va_arg(*args, void *); - x->s = (char *)&buff[x->n0]; - _Litob(x, 'x'); - break; - case 's': - x->s = va_arg(*args, char *); - x->n1 = strlen(x->s); - - if (x->prec >= 0 && x->prec < x->n1) { - x->n1 = x->prec; - } - - break; - case '%': - buff[x->n0++] = '%'; - break; - default: - buff[x->n0++] = type; - break; - } -} diff --git a/lib/ultralib/src/libc/xstdio.h b/lib/ultralib/src/libc/xstdio.h deleted file mode 100644 index bd70de8..0000000 --- a/lib/ultralib/src/libc/xstdio.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _XSTDIO_H -#define _XSTDIO_H -#include "PR/ultratypes.h" -#include "stdlib.h" -#include "stdarg.h" - -typedef struct { - /* 0x0 */ union { - /* 0x0 */ long long ll; - /* 0x0 */ double ld; - } v; - /* 0x8 */ unsigned char* s; - /* 0xC */ int n0; - /* 0x10 */ int nz0; - /* 0x14 */ int n1; - /* 0x18 */ int nz1; - /* 0x1C */ int n2; - /* 0x20 */ int nz2; - /* 0x24 */ int prec; - /* 0x28 */ int width; - /* 0x2C */ size_t nchar; - /* 0x30 */ unsigned int flags; - /* 0x34 */ char qual; -} _Pft; - -#define FLAGS_SPACE 1 -#define FLAGS_PLUS 2 -#define FLAGS_MINUS 4 -#define FLAGS_HASH 8 -#define FLAGS_ZERO 16 -typedef char *outfun(char*,const char*,size_t); - -int _Printf(outfun prout, char *arg, const char *fmt, va_list args); -void _Litob(_Pft *args, char type); -void _Ldtob(_Pft* args, char type); - -#endif diff --git a/lib/ultralib/src/log/delay.s b/lib/ultralib/src/log/delay.s deleted file mode 100644 index 631781a..0000000 --- a/lib/ultralib/src/log/delay.s +++ /dev/null @@ -1,24 +0,0 @@ -#include "PR/os_version.h" - -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J -#include "sys/asm.h" -#include "sys/regdef.h" - -LEAF(osDelay) - sll t0,a0,2 - addu t0,a0 - sll t0,t0,2 - beqz a0,2f - -1: - subu t0,1 - NOP - NOP - bnez t0,1b - -2: - j ra - -END(osDelay) - -#endif diff --git a/lib/ultralib/src/log/log.c b/lib/ultralib/src/log/log.c deleted file mode 100644 index 85129d2..0000000 --- a/lib/ultralib/src/log/log.c +++ /dev/null @@ -1,124 +0,0 @@ -#include "stdarg.h" -#include "PR/rdb.h" -#include "PR/os.h" -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/ultralog.h" -#include "macros.h" - -#ifndef _FINALROM - -static u32 __osLogOKtoWrite = TRUE; -static u32 __osLogInitialized = FALSE; - -static OSMesgQueue __osLogDoneMsgQ ALIGNED(8); -static OSMesg __osLogMsgBuf; - -void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr); - -void osCreateLog(OSLog* log, u32* base, s32 byteLen) { - log->magic = OS_LOG_MAGIC; - log->base = base; - log->len = byteLen; - log->startCount = osGetCount(); - log->writeOffset = 0; -} - -void osLogEvent(OSLog* log, s16 code, s16 numArgs, ...) { - va_list argPtr; - - if (numArgs > 16) { - return; - } - - va_start(argPtr, numArgs); - __osLogWrite(log, code, numArgs, argPtr); - va_end(argPtr); -} - -void osFlushLog(OSLog* log) { - s32 mask; - u32 sent; - u32 count; - u32 subcount; - u8* base; - u8 dCount[3]; - - if (!__osLogInitialized) { - osCreateMesgQueue(&__osLogDoneMsgQ, &__osLogMsgBuf, 1); - osSetEventMesg(OS_EVENT_RDB_LOG_DONE, &__osLogDoneMsgQ, 0); - __osLogInitialized = 1; - } - - mask = __osDisableInt(); - __osLogOKtoWrite = 0; - base = log->base; - count = log->writeOffset * 4; - __osRestoreInt(mask); - - while (count != 0) { - subcount = (count < 0x8000) ? count : 0x8000; - dCount[0] = (subcount & 0xFF0000) >> 0x10; - dCount[1] = (subcount & 0xFF00) >> 8; - dCount[2] = subcount & 0xFF; - - sent = 0; - while (sent < 3) { - sent += __osRdbSend(dCount + sent, 3 - sent, RDB_TYPE_GtoH_LOG_CT); - } - - sent = 0; - while (sent < subcount) { - sent += __osRdbSend(base + sent, subcount - sent, RDB_TYPE_GtoH_LOG); - } - - count -= subcount; - base += subcount; - osRecvMesg(&__osLogDoneMsgQ, NULL, OS_MESG_BLOCK); - } - mask = __osDisableInt(); - log->writeOffset = 0; - __osLogOKtoWrite = 1; - __osRestoreInt(mask); -} - -void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr) { - int i; - u32 saveEnable; - u32 buf[19]; - u32* bufp; - OSLogItem* hdr; - s32* args; - s32* dest; - int numLongs; - - bufp = buf; - hdr = buf; - args = buf + 3; - numLongs = numArgs + 3; - saveEnable = __osDisableInt(); - - hdr->magic = log->magic; - hdr->timeStamp = osGetCount() - log->startCount; - hdr->argCount = numArgs; - hdr->eventID = code; - - for (i = 0; i < numArgs; i++) { - *args++ = va_arg(argPtr, int); - } - - if (__osLogOKtoWrite) { - if ((log->writeOffset + numLongs) < (log->len >> 2)) { - dest = log->base + log->writeOffset; - for (i = 0; i < numLongs; i++) { - *dest++ = *bufp++; - } - log->writeOffset += numLongs; - } else { - __osLogOKtoWrite = FALSE; - } - } - __osRestoreInt(saveEnable); -} - -#endif diff --git a/lib/ultralib/src/log/logfloat.c b/lib/ultralib/src/log/logfloat.c deleted file mode 100644 index 17db739..0000000 --- a/lib/ultralib/src/log/logfloat.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "os_version.h" - -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J - -#include "ultralog.h" - -u32 osLogFloat(f32 f) { - return OS_LOG_FLOAT(f); -} - -#endif diff --git a/lib/ultralib/src/mgu/Makefile b/lib/ultralib/src/mgu/Makefile deleted file mode 100644 index 52c29f6..0000000 --- a/lib/ultralib/src/mgu/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -# -# Makefile for the gu subdirectory -# - -include $(ROOT)/usr/include/make/PRdefs - -LCINCS = -I. -I../gu -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include -LASINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/include -LCOPTS = -G 0 -g -O - -CFILES = mtxcatl.c \ - mtxxfml.c \ - mtxxfmf.c \ - rotate.c - -ASFILES = mtxident.s \ - mtxidentf.s \ - mtxf2l.s \ - mtxl2f.s \ - mtxcatf.s \ - scale.s \ - scalef.s \ - normalize.s \ - translate.s \ - translatef.s - -OBJECTS = $(CFILES:.c=.o) $(ASFILES:.s=.o) - -default: $(OBJECTS) - -include $(COMMONRULES) - -.s.o: - cpp $(F_ROM) -DLANG_JAPANESE -E -DMIPSEB -DLANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64 -I. -I$(LIBDEPTH)\include $*.s $*.ss2 - as -mips3 -G0 -o $*.o $*.ss2 - del $*.ss? diff --git a/lib/ultralib/src/mgu/asm.h b/lib/ultralib/src/mgu/asm.h deleted file mode 100644 index 0c417fa..0000000 --- a/lib/ultralib/src/mgu/asm.h +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO Co,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/07/06 13:21:13 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#ifndef __ASM_H__ -#define __ASM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#define _MIPS_ISA_MIPS1 1 /* R2/3K */ -#define _MIPS_ISA_MIPS2 2 /* R4K/6K */ -#define _MIPS_ISA_MIPS3 3 /* R4K */ -#define _MIPS_ISA_MIPS4 4 /* TFP */ - -#define _MIPS_SIM_ABI32 1 /* MIPS MSIG calling convention */ -#define _MIPS_SIM_NABI32 2 /* MIPS new 32-bit abi */ - /* NABI32 is 64bit calling convention but 32bit type sizes) */ -#define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ - -#define LEAF(x) \ - .globl x; \ - .ent x,0; \ -x:; \ - .frame sp,0,ra - -#define END(proc) \ - .end proc - - -#ifdef __cplusplus -} -#endif - -#endif /* !__ASM_H__ */ diff --git a/lib/ultralib/src/mgu/mtxcatf.s b/lib/ultralib/src/mgu/mtxcatf.s deleted file mode 100644 index 4b96124..0000000 --- a/lib/ultralib/src/mgu/mtxcatf.s +++ /dev/null @@ -1,103 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:37 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#include -#include - -/* - * void guMtxCatF(float mf[4][4], float nf[4][4], float res[4][4]) - * res = mf * nf - */ -#define FRAME_SIZE 64 - .text - .align 5 - .globl guMtxCatF - .ent guMtxCatF, 0 -guMtxCatF: - .set reorder - subu sp, FRAME_SIZE - .frame sp, FRAME_SIZE, ra - - addu v0, a0, 64 - addu v1, a1, 16 - move t2, sp -label_loop_i: - move a3, a1 -label_loop_j: - l.s ft0, 0(a0) /* mf[i][0] * nf[0][j] */ - l.s ft1, 0(a3) - mul.s ft2, ft0, ft1 - l.s ft3, 4(a0) /* + mf[i][1] * nf[1][j] */ - l.s ft4, 16(a3) - mul.s ft5, ft3, ft4 - add.s ft2, ft2, ft5 - l.s ft0, 8(a0) /* + mf[i][2] * nf[2][j] */ - l.s ft1, 32(a3) - mul.s ft5, ft0, ft1 - add.s ft2, ft2, ft5 - l.s ft3, 12(a0) /* + mf[i][3] * nf[3][j] */ - l.s ft4, 48(a3) - mul.s ft5, ft3, ft4 - add.s ft2, ft2, ft5 - - s.s ft2, 0(t2) - addu a3, a3, 4 - addu t2, t2, 4 - bne a3, v1, label_loop_j -/* loop_j_end */ - addu a0, a0, 16 - bne a0, v0, label_loop_i -/* loop_i_end */ - s.s ft2, 60(a2) - lw t0, 0(sp) - lw t1, 4(sp) - lw t2, 8(sp) - lw t3, 12(sp) - lw ta0, 16(sp) - lw ta1, 20(sp) - lw ta2, 24(sp) - lw ta3, 28(sp) - lw t8, 32(sp) - lw t9, 36(sp) - lw v0, 40(sp) - lw v1, 44(sp) - lw a0, 48(sp) - lw a1, 52(sp) - lw a3, 56(sp) - - sw t0, 0(a2) - sw t1, 4(a2) - sw t2, 8(a2) - sw t3, 12(a2) - sw ta0, 16(a2) - sw ta1, 20(a2) - sw ta2, 24(a2) - sw ta3, 28(a2) - sw t8, 32(a2) - sw t9, 36(a2) - sw v0, 40(a2) - sw v1, 44(a2) - sw a0, 48(a2) - sw a1, 52(a2) - sw a3, 56(a2) - - addu sp , FRAME_SIZE - j ra - - .end guMtxCatF - -/* end of file */ diff --git a/lib/ultralib/src/mgu/mtxcatl.c b/lib/ultralib/src/mgu/mtxcatl.c deleted file mode 100644 index 6054972..0000000 --- a/lib/ultralib/src/mgu/mtxcatl.c +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:37 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#include -#include "../gu/guint.h" -#include "gu.h" - -void guMtxCatL(Mtx *m, Mtx *n, Mtx *res) -{ - float mf[4][4], nf[4][4], resf[4][4]; - - guMtxL2F(mf, m); - guMtxL2F(nf, n); - - guMtxCatF(mf, nf, resf); - - guMtxF2L(resf, res); -} - -#if BUILD_VERSION < VERSION_K -void guMtxXFML(Mtx *m, float x, float y, float z, float *ox, float *oy, float *oz) -{ - float mf[4][4]; - - guMtxL2F(mf, m); - - guMtxXFMF(mf, x, y, z, ox, oy, oz); -} -#endif -/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxf2l.s b/lib/ultralib/src/mgu/mtxf2l.s deleted file mode 100644 index 43bbe7e..0000000 --- a/lib/ultralib/src/mgu/mtxf2l.s +++ /dev/null @@ -1,80 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:38 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#include -#include - -/* - * void guMtxF2L(float mf[4][4], Mtx *m) - * - * Input - * float mf[4][4] - * Output - * Mtx *m - */ - -#define HALF_SIZE_MTX 32 -#define MASK_LOW 0x0000FFFF -#define MASK_HIGH 0xFFFF0000 -#define MAGNIFICANT 65536.0 /* = 0x10000 */ - -#define ptr_fl a0 /* argument */ -#define ptr_mtx a1 /* argument */ -#define end_mtx t8 -#define mask_hi t9 -#define magni fv0 - - .text - .align 5 -LEAF( guMtxF2L ) - .set reorder - - li.s magni, MAGNIFICANT - li mask_hi, MASK_HIGH - addu end_mtx, ptr_mtx, HALF_SIZE_MTX -label_loop: - l.s ft0, 0(ptr_fl) /* FTOFIX32( ) */ - mul.s ft1, ft0, magni - trunc.w.s ft2, ft1 - - l.s ft3, 4(ptr_fl) /* FTOFIX32( ) */ - mul.s ft4, ft3, magni - trunc.w.s ft5, ft4 - - mfc1 t0, ft2 /* t0 <- FIXED */ - mfc1 t1, ft5 /* t1 <- FIXED */ - - and t2, t0, mask_hi /* integral part */ - srl t3, t1, 16 - or ta0, t2, t3 - sw ta0, 0(ptr_mtx) - - sll ta1, t0, 16 /* decimal part */ - and ta2, t1, MASK_LOW - or ta3, ta1, ta2 - sw ta3, HALF_SIZE_MTX(ptr_mtx) - - addu ptr_mtx, ptr_mtx, 4 - addu ptr_fl, ptr_fl, 8 - - bne ptr_mtx, end_mtx, label_loop -/* loop-end */ - - j ra - END( guMtxF2L ) - -/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxident.s b/lib/ultralib/src/mgu/mtxident.s deleted file mode 100644 index a9ec491..0000000 --- a/lib/ultralib/src/mgu/mtxident.s +++ /dev/null @@ -1,60 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:38 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ -#include -#include - -/* - * void guMtxIdent( Mtx * matrix ) - * Substitute unit matrix for matrix - * Correspond only when alignment is 4 byte boundary - * Input - * a0 = matrix - * Output - * *matrix unit matrix - */ - -#define SIZE_OF_MTX 64 /* sizeof( Mtx ) */ - .text - .align 5 -LEAF(guMtxIdent) - .set reorder - - addi t0, zero, 1 /* t0 = 0x00000001 */ - sll t1, t0, 16 /* t1 = 0x00010000 */ - - sw t1, 0(a0) /* Substitution of integers */ - sw zero, 4(a0) - sw t0, 8(a0) - sw zero, 12(a0) - sw zero, 16(a0) - sw t1, 20(a0) - sw zero, 24(a0) - sw t0, 28(a0) - - sw zero, 32(a0) /* Substitution of fractions */ - sw zero, 36(a0) - sw zero, 40(a0) - sw zero, 44(a0) - sw zero, 48(a0) - sw zero, 52(a0) - sw zero, 56(a0) - sw zero, 60(a0) - j ra - - END(guMtxIdent) - -/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxidentf.s b/lib/ultralib/src/mgu/mtxidentf.s deleted file mode 100644 index a6aa779..0000000 --- a/lib/ultralib/src/mgu/mtxidentf.s +++ /dev/null @@ -1,60 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:38 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ -#include -#include - -/* - * guMtxIdentF( float matrix[4][4] ) - * substitute unit matrix for floating point matrix - * correspond only when alignment is four byte boundary - * Input - * a0 = matrix - * Output - * *matrix unti matix - */ - .text - .align 5 -LEAF( guMtxIdentF ) - .set reorder - - li t0, 0x3f800000 /* t0 = 1.0 */ - - sw t0, 0(a0) - sw zero, 4(a0) /* line 1 */ - sw zero, 8(a0) - sw zero, 12(a0) - - sw zero, 16(a0) /* line 2 */ - sw t0, 20(a0) - sw zero, 24(a0) - sw zero, 28(a0) - - sw zero, 32(a0) /* line 3 */ - sw zero, 36(a0) - sw t0, 40(a0) - sw zero, 44(a0) - - sw zero, 48(a0) /* line 4 */ - sw zero, 52(a0) - sw zero, 56(a0) - sw t0, 60(a0) - - j ra - - END( guMtxIdentF ) - -/* End of file */ \ No newline at end of file diff --git a/lib/ultralib/src/mgu/mtxl2f.s b/lib/ultralib/src/mgu/mtxl2f.s deleted file mode 100644 index 897acfb..0000000 --- a/lib/ultralib/src/mgu/mtxl2f.s +++ /dev/null @@ -1,80 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:38 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#include -#include - -/* - * void guMtxF2L(float mf[4][4], Mtx *m) - * - * Input - * float mf[4][4] - * Output - * Mtx *m - */ - -#define HALF_SIZE_MTX 32 -#define MASK_LOW 0x0000FFFF -#define MASK_HIGH 0xFFFF0000 -#define MAGNIFICANT 1.5258789062500000e-05 /* ~ 1 / 0x10000 */ - -#define ptr_fl a0 /* argument */ -#define ptr_mtx a1 /* argument */ -#define end_mtx t8 -#define mask_hi t9 -#define magni fv0 - - .text - .align 5 -LEAF( guMtxL2F ) - .set reorder - li.s magni, MAGNIFICANT - li mask_hi, MASK_HIGH - addu end_mtx, ptr_mtx, HALF_SIZE_MTX -label_loop: - lw t0, 0(ptr_mtx) - lw t1, 32(ptr_mtx) - - and t2, t0, mask_hi - srl t3, t1, 16 - or ta0, t2, t3 - - sll ta1, t0, 16 - and ta2, t1, MASK_LOW - or ta3, ta1, ta2 - - mtc1 ta0, ft0 /* FIX32TOF( ) */ - cvt.s.w ft1, ft0 - mul.s ft2, ft1, magni - - mtc1 ta3, ft3 /* FIX32TOF( ) */ - cvt.s.w ft4, ft3 - mul.s ft5, ft4, magni - - s.s ft2, 0(ptr_fl) - s.s ft5, 4(ptr_fl) - - addu ptr_mtx, ptr_mtx, 4 - addu ptr_fl, ptr_fl, 8 - - bne ptr_mtx, end_mtx, label_loop -/* loop-end */ - - j ra - END( guMtxL2F ) - -/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxxfmf.c b/lib/ultralib/src/mgu/mtxxfmf.c deleted file mode 100644 index 58c6772..0000000 --- a/lib/ultralib/src/mgu/mtxxfmf.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: mtxcatf.c - * Creator: hsa@sgi.com - * Create Date: Thu Nov 2 13:03:02 PST 1995 - * - */ - -#include "../gu/guint.h" - -void guMtxXFMF(float mf[4][4], float x, float y, float z, float *ox, float *oy, float *oz) -{ - *ox = mf[0][0]*x + mf[1][0]*y + mf[2][0]*z + mf[3][0]; - *oy = mf[0][1]*x + mf[1][1]*y + mf[2][1]*z + mf[3][1]; - *oz = mf[0][2]*x + mf[1][2]*y + mf[2][2]*z + mf[3][2]; -} - diff --git a/lib/ultralib/src/mgu/mtxxfml.c b/lib/ultralib/src/mgu/mtxxfml.c deleted file mode 100644 index 1dfa871..0000000 --- a/lib/ultralib/src/mgu/mtxxfml.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: mtxcatl.c - * Creator: hsa@sgi.com - * Create Date: Thu Nov 2 13:03:02 PST 1995 - * - */ - -#include "../gu/guint.h" - -void guMtxXFML(Mtx *m, float x, float y, float z, float *ox, float *oy, float *oz) -{ - float mf[4][4]; - - guMtxL2F(mf, m); - - guMtxXFMF(mf, x, y, z, ox, oy, oz); -} diff --git a/lib/ultralib/src/mgu/normalize.s b/lib/ultralib/src/mgu/normalize.s deleted file mode 100644 index 58b9093..0000000 --- a/lib/ultralib/src/mgu/normalize.s +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:39 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ -#include -#include - -/* - * void guNormalize(float *x, float *y, float *z) - */ - .text - .align 5 -LEAF( guNormalize ) - .set noreorder - - l.s ft0, 0(a0) /* ft0 = x */ - l.s ft1, 0(a1) /* ft1 = y */ - l.s ft2, 0(a2) /* ft2 = z */ - - mul.s ft3, ft0, ft0 /* ft3 = x*x */ - lui t0, 0x3f80 /* t0 = 1.0f */ - mul.s ft4, ft1, ft1 /* ft4 = y*y */ - add.s ft5, ft3, ft4 - mul.s ft4, ft2, ft2 /* ft4 = z*z */ - - add.s ft3, ft4, ft5 /* ft3 = x*x + y*y + z*z */ - mtc1 t0, ft5 - sqrt.s ft4, ft3 /* ft4 = sqrt(x*x + y*y + z*z) */ - - div.s ft3, ft5, ft4 /* ft3 = 1/sqrt(x*x + y*y + z*z) */ - - mul.s ft4, ft0, ft3 /* ft4 = x * 1/sqrt(x*x + y*y + z*z) */ - nop - mul.s ft5, ft1, ft3 /* ft5 = y * 1/sqrt(x*x + y*y + z*z) */ - nop - mul.s ft0, ft2, ft3 /* ft0 = z * 1/sqrt(x*x + y*y + z*z) */ - - s.s ft4, 0(a0) /* x = ft4 */ - s.s ft5, 0(a1) /* y = ft5 */ - j ra - s.s ft0, 0(a2) /* z = ft0 */ /* Use delayed slot */ - - END( guNormalize ) -/* end of file */ diff --git a/lib/ultralib/src/mgu/regdef.h b/lib/ultralib/src/mgu/regdef.h deleted file mode 100644 index ac9c109..0000000 --- a/lib/ultralib/src/mgu/regdef.h +++ /dev/null @@ -1,187 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO Co,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/07/06 13:21:13 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ - -#ifndef __REGDEF_H__ -#define __REGDEF_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef mips - -#if (_MIPS_SIM == _MIPS_SIM_ABI32) -#define zero $0 -#define AT $at -#define v0 $2 -#define v1 $3 -#define a0 $4 -#define a1 $5 -#define a2 $6 -#define a3 $7 -#define t0 $8 -#define t1 $9 -#define t2 $10 -#define t3 $11 -#define t4 $12 -#define ta0 $12 -#define t5 $13 -#define ta1 $13 -#define t6 $14 -#define ta2 $14 -#define t7 $15 -#define ta3 $15 -#define s0 $16 -#define s1 $17 -#define s2 $18 -#define s3 $19 -#define s4 $20 -#define s5 $21 -#define s6 $22 -#define s7 $23 -#define t8 $24 -#define t9 $25 -#define jp $25 -#define k0 $26 -#define k1 $27 -#define gp $28 -#define sp $29 -#define fp $30 -#define s8 $30 -#define ra $31 -#endif - -#if (_MIPS_SIM == _MIPS_SIM_ABI64) -#define zero $0 -#define AT $at -#define v0 $2 -#define v1 $3 -#define a0 $4 -#define a1 $5 -#define a2 $6 -#define a3 $7 -#define a4 $8 -#define ta0 $8 -#define a5 $9 -#define ta1 $9 -#define a6 $10 -#define ta2 $10 -#define a7 $11 -#define ta3 $11 -#define t0 $12 -#define t1 $13 -#define t2 $14 -#define t3 $15 -#define s0 $16 -#define s1 $17 -#define s2 $18 -#define s3 $19 -#define s4 $20 -#define s5 $21 -#define s6 $22 -#define s7 $23 -#define t8 $24 -#define t9 $25 -#define jp $25 -#define k0 $26 -#define k1 $27 -#define gp $28 -#define sp $29 -#define fp $30 -#define s8 $30 -#define ra $31 -#endif - -#if (_MIPS_SIM == _MIPS_SIM_ABI32) -#define fv0 $f0 -#define fv0f $f1 -#define fv1 $f2 -#define fv1f $f3 -#define fa0 $f12 -#define fa0f $f13 -#define fa1 $f14 -#define fa1f $f15 -#define ft0 $f4 -#define ft0f $f5 -#define ft1 $f6 -#define ft1f $f7 -#define ft2 $f8 -#define ft2f $f9 -#define ft3 $f10 -#define ft3f $f11 -#define ft4 $f16 -#define ft4f $f17 -#define ft5 $f18 -#define ft5f $f19 -#define fs0 $f20 -#define fs0f $f21 -#define fs1 $f22 -#define fs1f $f23 -#define fs2 $f24 -#define fs2f $f25 -#define fs3 $f26 -#define fs3f $f27 -#define fs4 $f28 -#define fs4f $f29 -#define fs5 $f30 -#define fs5f $f31 -#endif - -#if (_MIPS_SIM == _MIPS_SIM_ABI64) -#define fv0 $f0 -#define fv1 $f2 -#define fa0 $f12 -#define fa1 $f13 -#define fa2 $f14 -#define fa3 $f15 -#define fa4 $f16 -#define fa5 $f17 -#define fa6 $f18 -#define fa7 $f19 -#define ft0 $f4 -#define ft1 $f5 -#define ft2 $f6 -#define ft3 $f7 -#define ft4 $f8 -#define ft5 $f9 -#define ft6 $f10 -#define ft7 $f11 -#define ft8 $f20 -#define ft9 $f21 -#define ft10 $f22 -#define ft11 $f23 -#define ft12 $f1 -#define ft13 $f3 -#define fs0 $f24 -#define fs1 $f25 -#define fs2 $f26 -#define fs3 $f27 -#define fs4 $f28 -#define fs5 $f29 -#define fs6 $f30 -#define fs7 $f31 -#endif - -#define fcr31 $31 - -#endif /* mips */ - -#ifdef __cplusplus -} -#endif - -#endif /* !__REGDEF_H__ */ diff --git a/lib/ultralib/src/mgu/rotate.c b/lib/ultralib/src/mgu/rotate.c deleted file mode 100644 index 1c09bd8..0000000 --- a/lib/ultralib/src/mgu/rotate.c +++ /dev/null @@ -1,73 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "../gu/guint.h" -#include "gu.h" -#include "os_version.h" - -void guRotateF(float mf[4][4], float a, float x, float y, float z) -{ - static float dtor = 3.1415926 / 180.0; - float sine; - float cosine; - float ab, bc, ca, t; -#if BUILD_VERSION >= VERSION_K - float xxsine; - float yxsine; - float zxsine; -#endif - - guNormalize(&x, &y, &z); - a *= dtor; - sine = sinf(a); - cosine = cosf(a); - t = (1-cosine); - ab = x*y*t; - bc = y*z*t; - ca = z*x*t; - - guMtxIdentF(mf); - -#if BUILD_VERSION >= VERSION_K - xxsine = x * sine; - yxsine = y * sine; - zxsine = z * sine; -#else - #define xxsine (x * sine) - #define yxsine (y * sine) - #define zxsine (z * sine) -#endif - - t = x*x; - mf[0][0] = t+cosine*(1-t); - mf[2][1] = bc-xxsine; - mf[1][2] = bc+xxsine; - - t = y*y; - mf[1][1] = t+cosine*(1-t); - mf[2][0] = ca+yxsine; - mf[0][2] = ca-yxsine; - - t = z*z; - mf[2][2] = t+cosine*(1-t); - mf[1][0] = ab-zxsine; - mf[0][1] = ab+zxsine; -} - -void guRotate(Mtx *m, float a, float x, float y, float z) -{ - Matrix mf; - - guRotateF(mf, a, x, y, z); - - guMtxF2L(mf, m); -} diff --git a/lib/ultralib/src/mgu/scale.s b/lib/ultralib/src/mgu/scale.s deleted file mode 100644 index 01bc290..0000000 --- a/lib/ultralib/src/mgu/scale.s +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:40 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ -#include -#include - -/* - * FTOFIX32 (float to fix32) - * a: input - * t: output - * ft0 : (float)0x00010000 - * ft1, ft2, ft3, t0 : work reg - */ -#define FTOFIX32(a, t) \ - mtc1 a, ft1 ; \ - mul.s ft2, ft1, ft0 ; \ - trunc.w.s ft3, ft2, t0 ; \ - mfc1 t, ft3 ; - -/* - void guScale(Mtx *m, float x, float y, float z) - m: a0 - x: a1 - y: a2 - z a3 - */ -#define SIZE_OF_MTX 64 /* sizeof( Mtx ) */ -#define FLOAT_0x10000 6.5536e+04 /* (float)0x00010000) */ - - .text - .align 5 -LEAF( guScale ) - .set reorder - - li.s ft0, FLOAT_0x10000 /* (float)0x00010000 */ - - FTOFIX32(a1, t1) /* t1 = FTOFIX32(x) */ - srl t2, t1, 16 - sll t0, t2, 16 - sw t0, 0(a0) /* t0 = x integral part */ - sll t2, t1, 16 - sw t2, 32(a0) /* t2 = x decimal part */ - - FTOFIX32(a2, t1) /* t1 = FTOFIX32(y) */ - srl t0, t1, 16 - sw t0, 8(a0) /* t0 = y integral part */ - andi t2, t1, 0xffff - sw t2, 40(a0) /* t2 = y decimal part */ - - FTOFIX32(a3, t1) /* t1 = FTOFIX32(z) */ - srl t2, t1, 16 - sll t0, t2, 16 - sw t0, 20(a0) /* t0 = z integral part */ - sll t2, t1, 16 - sw t2, 52(a0) /* t2 = z decimal part */ - - li t0, 1 /* t0 = 1.0 integral part */ - sw t0, 28(a0) - - sw zero, 4(a0) - sw zero, 12(a0) - sw zero, 16(a0) - sw zero, 24(a0) - sw zero, 36(a0) - sw zero, 44(a0) - sw zero, 48(a0) - sw zero, 56(a0) - sw zero, 60(a0) - j ra - - END( guScale ) -/* end of file */ diff --git a/lib/ultralib/src/mgu/scalef.s b/lib/ultralib/src/mgu/scalef.s deleted file mode 100644 index b27d1e3..0000000 --- a/lib/ultralib/src/mgu/scalef.s +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:40 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ -#include -#include - -/* - * void guScaleF(float m[4][4], float x, float y, float z) - * m: a0 - * x: a1 - * y: a2 - * z: a3 - */ - .text - .align 5 -LEAF( guScaleF ) - .set reorder - - sw a1, 0(a0) - sw zero, 4(a0) /* line 1 */ - sw zero, 8(a0) - sw zero, 12(a0) - - sw zero, 16(a0) /* line 2 */ - sw a2, 20(a0) - sw zero, 24(a0) - sw zero, 28(a0) - - sw zero, 32(a0) /* line 3 */ - sw zero, 36(a0) - sw a3, 40(a0) - sw zero, 44(a0) - - li t0, 0x3f800000 /* t0 = 1.0 */ - sw zero, 48(a0) /* line 4 */ - sw zero, 52(a0) - sw zero, 56(a0) - sw t0, 60(a0) - - j ra - - END( guScaleF ) - -/* End of file */ diff --git a/lib/ultralib/src/mgu/translate.s b/lib/ultralib/src/mgu/translate.s deleted file mode 100644 index 472fd8c..0000000 --- a/lib/ultralib/src/mgu/translate.s +++ /dev/null @@ -1,101 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:40 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ -#include -#include - -/* - void guTranslate(Mtx *m, float x, float y, float z) - m: a0 - x: a1 - y: a2 - z a3 - */ - -#define SIZE_OF_MTX 64 /* sizeof( Mtx ) */ -#define FLOAT_0x10000 6.5536e+04 /* (float)0x00010000) */ - - .text - .align 5 -LEAF( guTranslate ) - .set reorder - - li.s ft0, FLOAT_0x10000 /* (float)0x00010000 */ - - mtc1 a1, ft1 - mul.s ft2, ft1, ft0 - trunc.w.s ft3, ft2 - mfc1 t1, ft3 /* t1 = FTOFIX32(x) */ - - mtc1 a2, ft1 - mul.s ft2, ft1, ft0 - trunc.w.s ft3, ft2 - mfc1 t3, ft3 /* t3 = FTOFIX32(y) */ - - /* Save t1 and t3 values until fraction process is finished! */ - - srl t2, t1, 16 /* x integeral part for t0 interger */ - sll t0, t2, 16 - srl t2, t3, 16 /* y integral part for t2 fraction */ - or t0, t0, t2 /* Compose in t0 */ - sw t0, 24(a0) - - sll t0,t1,16 /* x fraction part for t0 interger */ - sll t2,t3,16 - srl t2,t2,16 /* y fraction part for t2 fraction */ - or t0,t0,t2 /* Compose in t0 */ - sw t0,24+32(a0) - - - mtc1 a3, ft1 - mul.s ft2, ft1, ft0 - trunc.w.s ft3, ft2 - mfc1 t1, ft3 /* t1 = FTOFIX32(z) */ - - srl t2,t1,16 - sll t0,t2,16 /* z integral part for t0 integer */ - addiu t0,t0,1 /* enter 0x0001 in t0 fraction */ - sw t0,28(a0) - - sll t2,t1,16 /* z fraction part for t2 integer */ - sw t2,28+32(a0) - - sw zero, 0(a0) - sw zero, 4(a0) - sw zero, 8(a0) - sw zero, 12(a0) - sw zero, 16(a0) - sw zero, 20(a0) - sw zero, 0+32(a0) - sw zero, 4+32(a0) - sw zero, 8+32(a0) - sw zero, 12+32(a0) - sw zero, 16+32(a0) - sw zero, 20+32(a0) - - lui t0,0x0001 - ori t0,0x0000 - sw t0,0(a0) - sw t0,20(a0) - - lui t0,0x0000 - ori t0,0x0001 - sw t0,8(a0) - - j ra - - END( guTranslate ) -/* end of file */ diff --git a/lib/ultralib/src/mgu/translatef.s b/lib/ultralib/src/mgu/translatef.s deleted file mode 100644 index 47d14bd..0000000 --- a/lib/ultralib/src/mgu/translatef.s +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************ - Copyright (C) 1998,1999 NINTENDO CO,Ltd, - Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved -This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. -and it is not to be reproduced, published, disclosed to others, copied, -adapted, distributed, or displayed without the prior authorization of -NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed -this Notice on all copies of the program, including partial copies or -modified versions thereof. -*************************************************************************/ -/************************************************************************ - $Date: 1999/06/16 09:15:41 $ - $Revision: 1.1 $ - $Author: doseki $ -************************************************************************/ -#include -#include - -/* - * void guTranslateF(float m[4][4], float x, float y, float z) - * m: a0 - * x: a1 - * y: a2 - * z: a3 - */ - .text - .align 5 -LEAF( guTranslateF ) - .set reorder - - li t0,0x3f800000 /* t0 = 1.0 */ - - sw t0, 0(a0) - sw zero, 4(a0) /* line 1 */ - sw zero, 8(a0) - sw zero, 12(a0) - - sw zero, 16(a0) /* line 2 */ - sw t0, 20(a0) - sw zero, 24(a0) - sw zero, 28(a0) - - sw zero, 32(a0) /* line 3 */ - sw zero, 36(a0) - sw t0, 40(a0) - sw zero, 44(a0) - - sw a1, 48(a0) /* line 4 */ - sw a2, 52(a0) - sw a3, 56(a0) - sw t0, 60(a0) - - j ra - - END( guTranslateF ) - -/* End of file */ diff --git a/lib/ultralib/src/monutil.s b/lib/ultralib/src/monutil.s deleted file mode 100644 index e5974bd..0000000 --- a/lib/ultralib/src/monutil.s +++ /dev/null @@ -1,188 +0,0 @@ -#ifndef _FINALROM -#include "asm.h" -#include "sgidefs.h" -#include "regdef.h" -#include "sgidefs.h" -#include "PR/R4300.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#define EXC(code) (EXC_##code >> CAUSE_EXCSHIFT) - -.text - -LEAF(__isExpJP); .set noreorder - j __isExp - nop - sw k0, -0x10(sp) - la k0, __isExp - jr k0 - nop -.set reorder -END(__isExpJP) - -LEAF(__isExp); .set noreorder - sw k0, -0x10(sp) - sw k1, -8(sp) - - mfc0 k0, C0_CAUSE - nop - andi k0, k0, CAUSE_EXCMASK - bnez k0, non_stop - - nop - mfc0 k0, C0_CAUSE - nop - andi k0, k0, CAUSE_IP7 - beqz k0, throw_os_exception - nop - j go_monitor - nop -non_stop: - sra k0, k0, CAUSE_EXCSHIFT - li k1, EXC(BREAK) - bne k0, k1, non_bp - nop - j go_monitor - nop - -non_bp: - li k1, EXC(RADE) - bne k0, k1, non_adrs_store_exp - nop - j go_monitor - nop -non_adrs_store_exp: - li k1, EXC(WADE) - bne k0, k1, non_adrs_load_exp - nop - j go_monitor - nop -non_adrs_load_exp: - li k1, EXC(IBE) - bne k0, k1, non_bus_code_exp - nop - j go_monitor - nop -non_bus_code_exp: - li k1, EXC(DBE) - bne k0, k1, non_bus_data_exp - nop - j go_monitor - nop -non_bus_data_exp: - li k1, EXC(MOD) - bne k0, k1, non_tlb_mod - nop - j go_monitor - nop -non_tlb_mod: - li k1, EXC(RMISS) - bne k0, k1, non_tlb_load - nop - j go_monitor - nop -non_tlb_load: - li k1, EXC(WMISS) - bne k0, k1, non_tlb_store - nop - j go_monitor - nop -non_tlb_store: - li k1, EXC(II) - bne k0, k1, non_resv - nop - j go_monitor - nop - -non_resv: - lw k1, -8(sp) - -throw_os_exception: - j ramOldVector - nop - - - - - - - - - -go_monitor: - move k0, sp - addiu sp, sp, -0x200 - sw k0, 0x78(sp) - lw k1, -8(k0) - sw k1, 0x70(sp) - lw k1, -0x10(k0) - sw k1, 0x6c(sp) - nop -w: - lui k0, (0xA4600010 >> 16) - lw k0, (0xA4600010 & 0xFFFF)(k0) /* PI_STATUS_REG */ - nop - andi k0, k0, 3 /* (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY) */ - bnez k0, w - nop - la k0, 0xBFF00050 - jr k0 - nop -.set reorder -END(__isExp) - - -LEAF(MonitorInitBreak); .set noreorder - nop - nop -INIT_BREAK_POSITION: - break 4 - nop - nop - nop - jr ra - nop -.set reorder -END(MonitorInitBreak) - -#endif diff --git a/lib/ultralib/src/os/ackramromread.c b/lib/ultralib/src/os/ackramromread.c deleted file mode 100644 index 3de1f6f..0000000 --- a/lib/ultralib/src/os/ackramromread.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/os_version.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -void osAckRamromRead() { -} diff --git a/lib/ultralib/src/os/ackramromwrite.c b/lib/ultralib/src/os/ackramromwrite.c deleted file mode 100644 index a99e951..0000000 --- a/lib/ultralib/src/os/ackramromwrite.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "PR/os_internal.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -void osAckRamromWrite() { -} diff --git a/lib/ultralib/src/os/afterprenmi.c b/lib/ultralib/src/os/afterprenmi.c deleted file mode 100644 index 03b5b24..0000000 --- a/lib/ultralib/src/os/afterprenmi.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "PR/os_internal.h" - -s32 osAfterPreNMI() { - return __osSpSetPc(0); -} diff --git a/lib/ultralib/src/os/atomic.c b/lib/ultralib/src/os/atomic.c deleted file mode 100644 index a0bd8fe..0000000 --- a/lib/ultralib/src/os/atomic.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "PR/os_internal.h" - -int __osAtomicDec(unsigned int* p) { - u32 mask; - int result; - - mask = __osDisableInt(); - if (*p) { - (*p)--; - result = 1; - } else { - result = 0; - } - __osRestoreInt(mask); - return result; -} diff --git a/lib/ultralib/src/os/createmesgqueue.c b/lib/ultralib/src/os/createmesgqueue.c deleted file mode 100644 index 5c92f04..0000000 --- a/lib/ultralib/src/os/createmesgqueue.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" - -void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 msgCount) { - -#ifdef _DEBUG - if (msgCount <= 0) { - __osError(ERR_OSCREATEMESGQUEUE, 1, msgCount); - return; - } -#endif - - mq->mtqueue = (OSThread*)&__osThreadTail.next; - mq->fullqueue = (OSThread*)&__osThreadTail.next; - mq->validCount = 0; - mq->first = 0; - mq->msgCount = msgCount; - mq->msg = msg; -} diff --git a/lib/ultralib/src/os/createthread.c b/lib/ultralib/src/os/createthread.c deleted file mode 100644 index 7c17834..0000000 --- a/lib/ultralib/src/os/createthread.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/R4300.h" -#include "PR/ultraerror.h" -#include "osint.h" - -extern __OSThreadprofile_s thprof[]; - -void osCreateThread(OSThread* t, OSId id, void (*entry)(void*), void* arg, void* sp, OSPri p) { - register u32 saveMask; - OSIntMask mask; - -#ifdef _DEBUG - if ((u32)sp & 0x7) { - __osError(ERR_OSCREATETHREAD_SP, 1, sp); - return; - } - - if ((p < OS_PRIORITY_IDLE) || (p > OS_PRIORITY_MAX)) { - __osError(ERR_OSCREATETHREAD_PRI, 1, p); - return; - } -#endif - - t->id = id; - t->priority = p; - t->next = NULL; - t->queue = NULL; - t->context.pc = (u32)entry; - t->context.a0 = (s64)(s32)arg; // Double cast gets rid of compiler warning - t->context.sp = (s64)(s32)sp - 16; - t->context.ra = (u64)__osCleanupThread; - mask = OS_IM_ALL; - t->context.sr = (mask & (SR_IMASK | SR_IE)) | SR_EXL; - t->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT; - t->context.fpcsr = (u32)(FPCSR_FS | FPCSR_EV); - t->fp = 0; - t->state = OS_STATE_STOPPED; - t->flags = 0; - -#if BUILD_VERSION >= VERSION_K -#ifndef _FINALROM - if (id < THPROF_IDMAX) { - t->thprof = &thprof[id]; - } else { - t->thprof = &thprof[THPROF_IDMAX - 1]; - } -#endif -#endif - - saveMask = __osDisableInt(); - t->tlnext = __osActiveQueue; - __osActiveQueue = t; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/destroythread.c b/lib/ultralib/src/os/destroythread.c deleted file mode 100644 index c668869..0000000 --- a/lib/ultralib/src/os/destroythread.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -void osDestroyThread(OSThread* t) { - register u32 saveMask; - register OSThread* pred; - register OSThread* succ; - - saveMask = __osDisableInt(); - - if (t == NULL) { - t = __osRunningThread; - } else if (t->state != OS_STATE_STOPPED) { - __osDequeueThread(t->queue, t); - } - - if (__osActiveQueue == t) { - __osActiveQueue = __osActiveQueue->tlnext; - } else { -#if BUILD_VERSION >= VERSION_J || !defined(__GNUC__) - pred = __osActiveQueue; - while (pred->priority != -1) { - succ = pred->tlnext; - if (succ == t) { - pred->tlnext = t->tlnext; - break; - } - pred = succ; - } -#else - pred = __osActiveQueue; - succ = pred->tlnext; - while (succ != NULL) { - if (succ == t) { - pred->tlnext = t->tlnext; - break; - } - pred = succ; - succ = pred->tlnext; - } -#endif - } - - if (t == __osRunningThread) { - __osDispatchThread(); - } - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/exceptasm.h b/lib/ultralib/src/os/exceptasm.h deleted file mode 100644 index 0d7def5..0000000 --- a/lib/ultralib/src/os/exceptasm.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _EXCEPTASM_H -#define _EXCEPTASM_H - -#include "PR/os_version.h" - -#define MESG(type) (type << 3) - -#define MQ_MTQUEUE 0 -#define MQ_FULLQUEUE 4 -#define MQ_VALIDCOUNT 8 -#define MQ_FIRST 12 -#define MQ_MSGCOUNT 16 -#define MQ_MSG 20 - -#define OS_EVENTSTATE_MESSAGE_QUEUE 0 -#define OS_EVENTSTATE_MESSAGE 4 - -/* __osHwInt struct member offsets */ -#define HWINTR_CALLBACK 0x00 -#define HWINTR_SP 0x04 - -/* __osHwInt struct size */ -#if BUILD_VERSION >= VERSION_J -#define HWINTR_SIZE 0x8 -#else -#define HWINTR_SIZE 0x4 -#endif - -#endif diff --git a/lib/ultralib/src/os/exceptasm.s b/lib/ultralib/src/os/exceptasm.s deleted file mode 100644 index b7699a8..0000000 --- a/lib/ultralib/src/os/exceptasm.s +++ /dev/null @@ -1,1069 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" -#include "PR/os.h" -#include "PR/rcp.h" -#include "PR/rdb.h" -#include "exceptasm.h" -#include "threadasm.h" -#include "PR/os_version.h" -#define KMC_CODE_ENTRY 0xBFF00014 -#define KMC_WPORT 0xBFF08000 -#define KMC_STAT 0xBFF08004 - -.rdata - -#define REDISPATCH 0x00 -#define SW1 0x04 -#define SW2 0x08 -#define RCP 0x0c -#define CART 0x10 -#define PRENMI 0x14 -#define IP6_HDLR 0x18 -#define IP7_HDLR 0x1c -#define COUNTER 0x20 - -__osIntOffTable: - .byte REDISPATCH - .byte PRENMI - .byte IP6_HDLR - .byte IP6_HDLR - .byte IP7_HDLR - .byte IP7_HDLR - .byte IP7_HDLR - .byte IP7_HDLR - .byte COUNTER - .byte COUNTER - .byte COUNTER - .byte COUNTER - .byte COUNTER - .byte COUNTER - .byte COUNTER - .byte COUNTER - .byte REDISPATCH - .byte SW1 - .byte SW2 - .byte SW2 - .byte RCP - .byte RCP - .byte RCP - .byte RCP - .byte CART - .byte CART - .byte CART - .byte CART - .byte CART - .byte CART - .byte CART - .byte CART - -__osIntTable: - .word redispatch, sw1, sw2, rcp, cart, prenmi, IP6_Hdlr, IP7_Hdlr, counter - -#ifndef _FINALROM -EXPORT(__osCauseTable_pt) - .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 - .byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 -#endif - -.data - -#if BUILD_VERSION >= VERSION_J -EXPORT(__osHwIntTable) - .word 0, 0 - .word 0, 0 - .word 0, 0 - .word 0, 0 - .word 0, 0 - -EXPORT(__osPiIntTable) - .word 0, 0 -#else -EXPORT(__osHwIntTable) - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 -#endif - -#ifndef _FINALROM -__osRdb_DbgRead_Ct: - .word 0 - -__osRdb_Mesg: - .word 0 - -__os_Kdebug_Pkt: - .word 0 - -#if BUILD_VERSION >= VERSION_K -__osPreviousThread: - .word 0 -#endif -#endif - -.text - -LEAF(__osExceptionPreamble) - la k0, __osException - jr k0 -END(__osExceptionPreamble) - -#ifndef _FINALROM -LEAF(__ptExceptionPreamble) -.set noreorder - sw k0, -0x10(sp) - b pt_next - lui k0, %hi(__ptException) - nop - nop -pt_next: - addiu k0, k0, %lo(__ptException) - jr k0 - nop -.set reorder -END(__ptExceptionPreamble) - -LEAF(__ptException) -.set noreorder - mfc0 k0, C0_CAUSE - andi k0, k0, 0x7c - bnez k0, pt_not_Int - srl k0, k0, 2 - mfc0 k0, C0_CAUSE - nop - andi k0, k0, CAUSE_IP7 - beqz k0, __osException - nop - j pt_break - nop -pt_not_Int: - sw k1, -8(sp) - /* determine if the pt exception handler should deal with this cause */ - la k1, __osCauseTable_pt - add k1, k1, k0 - lbu k0, (k1) - beqz k0, __osException - nop -pt_break: -pi_ok_loop: - lw k0, PHYS_TO_K1(PI_STATUS_REG) - nop - andi k0, k0, (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY) - bnez k0, pi_ok_loop - nop - lw k0, KMC_STAT - nop - andi k0, k0, 8 - bnez k0, pt_prof - li k0, KMC_CODE_ENTRY - lw k1, -8(sp) - jr k0 - addiu sp, sp, -0x60 -pt_prof: - mfc0 k0, C0_EPC - /* the following two ways is a (necessarily) messy way to write "sw k0, KMC_WPORT" without using at */ - lui k1, (KMC_WPORT >> 16 + 1) - sw k0, -(KMC_WPORT & 0xFFFF)(k1) - lw k1, -8(sp) - lw k0, -0x10(sp) - eret - nop -.set reorder -END(__ptException) -#endif - -LEAF(__osException) - la k0, __osThreadSave - /* save AT */ -.set noat - sd $1, THREAD_GP1(k0); -.set at - /* save sr */ -STAY2(mfc0 k1, C0_SR) - sw k1, THREAD_SR(k0) - /* clear interrupts */ - and k1, k1, -4 -STAY2(mtc0 k1, C0_SR) - /* save other regs */ - sd $8, THREAD_GP8(k0) - sd $9, THREAD_GP9(k0) - sd $10, THREAD_GP10(k0) - /* say fp has not been used */ - sw zero, THREAD_FP(k0) - /* this instruction is useless, leftover because of bad placement of an ifdef for the debug version */ -STAY2(mfc0 t0, C0_CAUSE) -#ifndef _FINALROM - lw t2, __kmc_pt_mode - bnez t2, skip_kmc_mode - andi t1, t0, 0x7c - li t2, 0 - bne t1, t2, savecontext - and t1, k1, t0 - andi t2, t1, CAUSE_IP7 - beqz t2, notIP7 - /* clear rdb write interrupt */ - la t1, RDB_WRITE_INTR_REG - sw zero, (t1) -IP7check: -STAY2(mfc0 t0, C0_CAUSE) - andi t0, t0, CAUSE_IP7 - bne zero, t0, IP7check - la t2, RDB_BASE_REG - lw t0, (t2) - srl t1, t0, 0x1a - andi t1, t1, 0x3f - li t2, RDB_TYPE_HtoG_DATA - beq t1, t2, HandData - li t2, RDB_TYPE_HtoG_DEBUG - beq t1, t2, HandDbg - li t2, RDB_TYPE_HtoG_KDEBUG - beq t1, t2, HandKDebug - li t2, RDB_TYPE_HtoG_DEBUG_CT - beq t1, t2, DbgCnt - li t2, RDB_TYPE_HtoG_DATA_DONE - beq t1, t2, DataRead - li t2, RDB_TYPE_HtoG_LOG_DONE - beq t1, t2, LogRead - li t2, RDB_TYPE_HtoG_REQ_RAMROM - beq t1, t2, ReqRamrom - li t2, RDB_TYPE_HtoG_FREE_RAMROM - beq t1, t2, FreeRamrom - li t2, RDB_TYPE_HtoG_PROF_SIGNAL - beq t1, t2, SignalProf - b rdbout -SignalProf: - li t2, 1 - srl t1, t0, 0x10 - andi t1, t1, 0xff - beq t1, t2, AckProf - li t2, 0xa8 - sw t2, __osRdb_Mesg - b savecontext -AckProf: - li t2, 0xb0 - sw t2, __osRdb_Mesg - b savecontext -HandKDebug: - sw t0, __os_Kdebug_Pkt - b savecontext -DbgCnt: - li t2, 0xffffff - and t1, t0, t2 - sw t1, __osRdb_DbgRead_Ct - b rdbout -DataRead: - li t2, 0x88 - sw t2, __osRdb_Mesg - b savecontext -LogRead: - li t2, 0x80 - sw t2, __osRdb_Mesg - b savecontext -ReqRamrom: - li t2, 0x90 - sw t2, __osRdb_Mesg - b savecontext -FreeRamrom: - li t2, 0x98 - sw t2, __osRdb_Mesg - b savecontext -HandData: - srl t1, t0, 0x18 - andi t1, t1, 3 - beq zero, t1, rdbout - lw t2, __osRdb_Read_Data_Ct - subu t2, t2, t1 - sw t2, __osRdb_Read_Data_Ct - sd t3, THREAD_GP11(k0) - lw t3, __osRdb_Read_Data_Buf - srl t2, t0, 0x10 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneData - srl t2, t0, 8 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneData - andi t0, t0, 0xff - sb t0, (t3) - addi t3, t3, 1 -doneData: - sw t3, __osRdb_Read_Data_Buf - ld t3, THREAD_GP11(k0) - lw t2, __osRdb_Read_Data_Ct - bne zero, t2, rdbout - li t2, 0x78 - sw t2, __osRdb_Mesg - b savecontext -HandDbg: - srl t1, t0, 0x18 - andi t1, t1, 3 - beq zero, t1, rdbout - lw t2, __osRdb_DbgRead_Ct - subu t2, t2, t1 - sw t2, __osRdb_DbgRead_Ct - sd t3, THREAD_GP11(k0) - lw t3, __osRdb_DbgRead_Buf - bne zero, t3, 1f - ld t3, THREAD_GP11(k0) - b rdbout -1: - srl t2, t0, 0x10 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneDbg - srl t2, t0, 8 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneDbg - andi t0, t0, 0xff - sb t0, (t3) - addi t3, t3, 1 -doneDbg: - sw t3, __osRdb_DbgRead_Buf - ld t3, THREAD_GP11(k0) - lw t2, __osRdb_DbgRead_Ct - bne zero, t2, rdbout - li t2, 0xa0 - sw t2, __osRdb_Mesg - b savecontext -notIP7: - andi t2, t1, CAUSE_IP6 - beqz t2, savecontext - /* clear rdb read interrupt */ - la t1, RDB_READ_INTR_REG - sw zero, (t1) - lw t2, __osRdb_IP6_Ct - bnez t2, 2f - li t2, 1 - sw t2, __osRdb_IP6_Empty - b rdbout -2: - addi t2, t2, -1 - sw t2, __osRdb_IP6_Ct - lw t0, __osRdb_IP6_Data - lw t1, __osRdb_IP6_CurSend - sll t2, t1, 2 - add t0, t2, t0 - lw t2, (t0) - addi t1, t1, 1 - lw t0, __osRdb_IP6_Size - sub t0, t0, t1 - bgtz t0, 5f - li t1, 0 -5: - sw t1, __osRdb_IP6_CurSend -checkIP6: -STAY2(mfc0 t0, C0_CAUSE) - andi t0, t0, CAUSE_IP6 - bne zero, t0, checkIP6 - la t0, RDB_BASE_REG - sw t2, (t0) -rdbout: - ld t0, THREAD_GP8(k0) - ld t1, THREAD_GP9(k0) - ld t2, THREAD_GP10(k0) -.set noat - ld $1, THREAD_GP1(k0) -.set at - lw k1, THREAD_SR(k0) -STAY2(mtc0 k1, C0_SR) -.set noreorder - nop - nop - nop - nop - eret -.set reorder - -skip_kmc_mode: -#endif - -savecontext: - move t0, k0 - lw k0, __osRunningThread -#if !defined(_FINALROM) && BUILD_VERSION >= VERSION_K - sw k0, __osPreviousThread -#endif - ld t1, THREAD_GP1(t0) - sd t1, THREAD_GP1(k0) - ld t1, THREAD_SR(t0) - sd t1, THREAD_SR(k0) - ld t1, THREAD_GP8(t0) - sd t1, THREAD_GP8(k0) - ld t1, THREAD_GP9(t0) - sd t1, THREAD_GP9(k0) - ld t1, THREAD_GP10(t0) - sd t1, THREAD_GP10(k0) -3: - sd $2, THREAD_GP2(k0) - sd $3, THREAD_GP3(k0) - sd $4, THREAD_GP4(k0) - sd $5, THREAD_GP5(k0) - sd $6, THREAD_GP6(k0) - sd $7, THREAD_GP7(k0) - sd $11, THREAD_GP11(k0) - sd $12, THREAD_GP12(k0) - sd $13, THREAD_GP13(k0) - sd $14, THREAD_GP14(k0) - sd $15, THREAD_GP15(k0) - sd $16, THREAD_GP16(k0) - sd $17, THREAD_GP17(k0) - sd $18, THREAD_GP18(k0) - sd $19, THREAD_GP19(k0) - sd $20, THREAD_GP20(k0) - sd $21, THREAD_GP21(k0) - sd $22, THREAD_GP22(k0) - sd $23, THREAD_GP23(k0) - sd $24, THREAD_GP24(k0) - sd $25, THREAD_GP25(k0) - sd $28, THREAD_GP28(k0) - sd $29, THREAD_GP29(k0) - sd $30, THREAD_GP30(k0) - sd $31, THREAD_GP31(k0) - - mflo t0 - sd t0, THREAD_LO(k0) - mfhi t0 - sd t0, THREAD_HI(k0) - - lw k1, THREAD_SR(k0) - andi t1, k1, SR_IMASK - beqz t1, savercp - -/*if any interrupts are enabled*/ - la t0, __OSGlobalIntMask - lw t0, 0(t0) - xor t2, t0, ~0 /* not except not using not */ - andi t2, t2, SR_IMASK - or ta0, t1, t2 - and t3, k1, ~SR_IMASK - or t3, t3, ta0 - sw t3, THREAD_SR(k0) - andi t0, t0, SR_IMASK - and t1, t1, t0 - and k1, k1, ~SR_IMASK - or k1, k1, t1 -savercp: - - lw t1, PHYS_TO_K1(MI_INTR_MASK_REG) - beqz t1, endrcp - - la t0, __OSGlobalIntMask - lw t0, 0(t0) - - srl t0, t0, 0x10 - xor t0, t0, ~0 - andi t0, t0, 0x3f - lw ta0, THREAD_RCP(k0) - and t0, t0, ta0 - or t1, t1, t0 -endrcp: - sw t1, THREAD_RCP(k0) -STAY2(mfc0 t0, C0_EPC) - sw t0, THREAD_PC(k0) - lw t0, THREAD_FP(k0) - beqz t0, 1f -STAY2(cfc1 t0, fcr31) - NOP - sw t0, THREAD_FPCSR(k0) - sdc1 $f0, THREAD_FP0(k0) - sdc1 $f2, THREAD_FP2(k0) - sdc1 $f4, THREAD_FP4(k0) - sdc1 $f6, THREAD_FP6(k0) - sdc1 $f8, THREAD_FP8(k0) - sdc1 $f10, THREAD_FP10(k0) - sdc1 $f12, THREAD_FP12(k0) - sdc1 $f14, THREAD_FP14(k0) - sdc1 $f16, THREAD_FP16(k0) - sdc1 $f18, THREAD_FP18(k0) - sdc1 $f20, THREAD_FP20(k0) - sdc1 $f22, THREAD_FP22(k0) - sdc1 $f24, THREAD_FP24(k0) - sdc1 $f26, THREAD_FP26(k0) - sdc1 $f28, THREAD_FP28(k0) - sdc1 $f30, THREAD_FP30(k0) -1: -STAY2(mfc0 t0, C0_CAUSE) - sw t0, THREAD_CAUSE(k0) - -.set noreorder - li t1, OS_STATE_RUNNABLE - sh t1, THREAD_STATE(k0) -.set reorder - -#ifndef _FINALROM - lw a0, __os_Kdebug_Pkt - beqz a0, no_kdebug - sw zero, __os_Kdebug_Pkt - jal kdebugserver - b __osDispatchThreadSave -no_kdebug: - lw a0, __osRdb_Mesg - beqz a0, no_rdb_mesg - sw zero, __osRdb_Mesg - jal send_mesg - lw t0, 0x120(k0) -no_rdb_mesg: -#endif - - andi t1, t0, CAUSE_EXCMASK - li t2, EXC_BREAK - beq t1, t2, handle_break - - li t2, EXC_CPU - beq t1, t2, handle_CpU - - li t2, EXC_INT - bne t1, t2, panic -handle_interrupt: - and s0, k1, t0 -next_interrupt: - andi t1, s0, SR_IMASK - srl t2, t1, 0xc - bnez t2, 1f - - srl t2, t1, SR_IMASKSHIFT - addi t2, t2, 16 -1: - - lbu t2, __osIntOffTable(t2) - - lw t2, __osIntTable(t2) - jr t2 - -IP6_Hdlr: - and s0, s0, ~CAUSE_IP6 - b next_interrupt - -IP7_Hdlr: - and s0, s0, ~CAUSE_IP7 - b next_interrupt - -counter: -STAY2(mfc0 t1, C0_COMPARE) -STAY2(mtc0 t1, C0_COMPARE) - li a0, MESG(OS_EVENT_COUNTER) - jal send_mesg - and s0, s0, ~CAUSE_IP8 - b next_interrupt - -cart: -#if BUILD_VERSION >= VERSION_J - and s0, s0, ~CAUSE_IP4 - la t1, __osHwIntTable - add t1, HWINTR_SIZE - lw t2, HWINTR_CALLBACK(t1) - - beqz t2, 1f - - lw sp, HWINTR_SP(t1) - jalr t2 - - beqz v0, 1f - b redispatch - -1: - li a0, MESG(OS_EVENT_CART) - jal send_mesg - b next_interrupt -#else - li a0, MESG(OS_EVENT_CART) - and s0, s0, ~CAUSE_IP4 - la sp, leoDiskStack - addiu sp, 0x1000 - 0x10 # Stack size minus initial frame - li t2, HWINTR_SIZE - lw t2, __osHwIntTable(t2) - - beqz t2, 1f - - jalr t2 - li a0, MESG(OS_EVENT_CART) - - beqz v0, 1f - b redispatch - -1: - jal send_mesg - b next_interrupt -#endif - -rcp: - lw s1, PHYS_TO_K1(MI_INTR_REG) - la t0, __OSGlobalIntMask - lw t0, (t0) - - srl t0, t0, 0x10 - and s1, s1, t0 - andi t1, s1, MI_INTR_SP - beqz t1, vi - - andi s1, s1, 0x3e - lw ta0, PHYS_TO_K1(SP_STATUS_REG) - li t1, (SP_CLR_INTR | SP_CLR_SIG3) - - sw t1, PHYS_TO_K1(SP_STATUS_REG) - andi ta0, ta0, 0x300 - beqz ta0, sp_other_break - - li a0, MESG(OS_EVENT_SP) - jal send_mesg - - beqz s1, NoMoreRcpInts - - b vi - -sp_other_break: - li a0, MESG(OS_EVENT_SP_BREAK) - jal send_mesg - - beqz s1, NoMoreRcpInts - -vi: - andi t1, s1, 0x8 - beqz t1, ai - - andi s1, s1, 0x37 - - sw zero, PHYS_TO_K1(VI_CURRENT_REG) - li a0, MESG(OS_EVENT_VI) - jal send_mesg - beqz s1, NoMoreRcpInts - -ai: - andi t1, s1, 0x4 - beqz t1, si - - andi s1, s1, 0x3b - - li t1, 1 - sw t1, PHYS_TO_K1(AI_STATUS_REG) - - li a0, MESG(OS_EVENT_AI) - jal send_mesg - beqz s1, NoMoreRcpInts - -si: - andi t1, s1, 0x2 - beqz t1, pi - - andi s1, s1, 0x3d - /* any write clears interrupts */ - sw zero, PHYS_TO_K1(SI_STATUS_REG) - li a0, MESG(OS_EVENT_SI) - jal send_mesg - beqz s1, NoMoreRcpInts - -pi: - andi t1, s1, 0x10 - beqz t1, dp - - andi s1, s1, 0x2f - - li t1, PI_STATUS_CLR_INTR - sw t1, PHYS_TO_K1(PI_STATUS_REG) - -#if BUILD_VERSION >= VERSION_J - la t1, __osPiIntTable - lw t2, (t1) - beqz t2, 1f - - lw sp, 4(t1) - move a0, v0 - jalr t2 - - bnez v0, 2f -1: -#endif - li a0, MESG(OS_EVENT_PI) - jal send_mesg -#if BUILD_VERSION >= VERSION_J -2: -#endif - beqz s1, NoMoreRcpInts - -dp: - andi t1, s1, 0x20 - beqz t1, NoMoreRcpInts - - andi s1, s1, 0x1f - - li t1, MI_CLR_DP_INTR - sw t1, PHYS_TO_K1(MI_INIT_MODE_REG) - - li a0, MESG(OS_EVENT_DP) - jal send_mesg - -NoMoreRcpInts: - and s0, s0, ~CAUSE_IP3 - b next_interrupt - -prenmi: - lw k1, THREAD_SR(k0) - - and k1, k1, ~CAUSE_IP5 - sw k1, THREAD_SR(k0) - la t1, __osShutdown - lw t2, 0(t1) - beqz t2, firstnmi - - and s0, s0, ~CAUSE_IP5 - b redispatch - -firstnmi: - li t2, 1 - sw t2, 0(t1) /* __osShutdown */ - li a0, MESG(OS_EVENT_PRENMI) - jal send_mesg - - and s0, s0, ~CAUSE_IP5 - lw t2, __osRunQueue - lw k1, THREAD_SR(t2) - and k1, k1, ~CAUSE_IP5 - sw k1, THREAD_SR(t2) - b redispatch - -sw2: - and t0, t0, ~CAUSE_SW2 -STAY2(mtc0 t0, C0_CAUSE) - - li a0, MESG(OS_EVENT_SW2) - jal send_mesg - - and s0, s0, ~CAUSE_SW2 - b next_interrupt - -sw1: - and t0, t0, ~CAUSE_SW1 -STAY2(mtc0 t0, C0_CAUSE) - - li a0, MESG(OS_EVENT_SW1) - jal send_mesg - - and s0, s0, ~CAUSE_SW1 - b next_interrupt - -handle_break: - li t1, OS_FLAG_CPU_BREAK - sh t1, THREAD_FLAGS(k0) - li a0, MESG(OS_EVENT_CPU_BREAK) - jal send_mesg - b redispatch - -redispatch: - lw t1, THREAD_PRI(k0) - lw t2, __osRunQueue - lw t3, THREAD_PRI(t2) - - bge t1, t3, enqueueRunning - - move a1, k0 - la a0, __osRunQueue - - jal __osEnqueueThread - - j __osDispatchThread - -enqueueRunning: - la t1, __osRunQueue - lw t2, MQ_MTQUEUE(t1) - sw t2, THREAD_NEXT(k0) - sw k0, MQ_MTQUEUE(t1) - j __osDispatchThread -panic: - sw k0, __osFaultedThread - li t1, OS_STATE_STOPPED - sh t1, THREAD_STATE(k0) - li t1, OS_FLAG_FAULT - sh t1, THREAD_FLAGS(k0) - -STAY2(mfc0 t2, C0_BADVADDR) - - sw t2, THREAD_BADVADDR(k0) - - li a0, MESG(OS_EVENT_FAULT) - jal send_mesg - j __osDispatchThread -END(__osException) - -LEAF(send_mesg) - move s2, ra - la t2, __osEventStateTab - addu t2, t2, a0 - lw t1, OS_EVENTSTATE_MESSAGE_QUEUE(t2) - beqz t1, send_done - - lw t3, MQ_VALIDCOUNT(t1) - lw ta0, MQ_MSGCOUNT(t1) - - bge t3, ta0, send_done - - lw ta1, MQ_FIRST(t1) - addu ta1, ta1, t3 - - rem ta1, ta1, ta0 - lw ta0, MQ_MSG(t1) - mul ta1, ta1, 4 - addu ta0, ta0, ta1 - lw ta1, OS_EVENTSTATE_MESSAGE(t2) - sw ta1, 0(ta0) /* msg[ta1] = */ - addiu t2, t3, 1 - sw t2, MQ_VALIDCOUNT(t1) - lw t2, MQ_MTQUEUE(t1) - lw t3, THREAD_NEXT(t2) - beqz t3, send_done - - move a0, t1 - jal __osPopThread - - move t2, v0 - - move a1, t2 - la a0, __osRunQueue - jal __osEnqueueThread -send_done: - jr s2 -END(send_mesg) - -LEAF(handle_CpU) /* coprocessor error */ - and t1, t0, CAUSE_CEMASK - srl t1, t1, CAUSE_CESHIFT - li t2, 1 /* cp1 error */ - bne t1, t2, panic - - /* enable cp1 (fpu) for this thread */ - li t1, 1 - sw t1, THREAD_FP(k0) - lw k1, THREAD_SR(k0) - or k1, k1, SR_CU1 - sw k1, THREAD_SR(k0) - b enqueueRunning -END(handle_CpU) - -LEAF(__osEnqueueAndYield) - lw a1, __osRunningThread -#if !defined(_FINALROM) && BUILD_VERSION >= VERSION_K - sw a1, __osPreviousThread -#endif -STAY2(mfc0 t0, C0_SR) - ori t0, t0, SR_EXL - sw t0, THREAD_SR(a1) - sd s0, THREAD_GP16(a1) - sd s1, THREAD_GP17(a1) - sd s2, THREAD_GP18(a1) - sd s3, THREAD_GP19(a1) - sd s4, THREAD_GP20(a1) - sd s5, THREAD_GP21(a1) - sd s6, THREAD_GP22(a1) - sd s7, THREAD_GP23(a1) - sd gp, THREAD_GP28(a1) - sd sp, THREAD_GP29(a1) - sd s8, THREAD_GP30(a1) - sd ra, THREAD_GP31(a1) - sw ra, THREAD_PC(a1) - lw k1, THREAD_FP(a1) - beqz k1, 1f - cfc1 k1, fcr31 - sw k1, THREAD_FPCSR(a1) - sdc1 $f20, THREAD_FP20(a1) - sdc1 $f22, THREAD_FP22(a1) - sdc1 $f24, THREAD_FP24(a1) - sdc1 $f26, THREAD_FP26(a1) - sdc1 $f28, THREAD_FP28(a1) - sdc1 $f30, THREAD_FP30(a1) -1: - lw k1, THREAD_SR(a1) - andi t1, k1, SR_IMASK - beqz t1, 2f - - la t0, __OSGlobalIntMask - lw t0, 0(t0) - xor t0, t0, ~0 - andi t0, t0, SR_IMASK - or t1, t1, t0 - and k1, k1, ~SR_IMASK - or k1, k1, t1 - sw k1, THREAD_SR(a1) -2: - lw k1, PHYS_TO_K1(MI_INTR_MASK_REG) - beqz k1, 3f - - la k0, __OSGlobalIntMask - lw k0, 0(k0) - - srl k0, k0, 0x10 - xor k0, k0, ~0 - andi k0, k0, 0x3f - lw t0, THREAD_RCP(a1) - and k0, k0, t0 - or k1, k1, k0 -3: - sw k1, THREAD_RCP(a1) - beqz a0, noEnqueue - jal __osEnqueueThread -noEnqueue: - j __osDispatchThread -END(__osEnqueueAndYield) - -/*__osEnqueueThread(OSThread **, OSThread *)*/ -LEAF(__osEnqueueThread) - move t9, a0 - lw t8, 0(a0) - lw ta3, THREAD_PRI(a1) - lw ta2, THREAD_PRI(t8) - blt ta2, ta3, 2f -1: - move t9, t8 - lw t8, THREAD_NEXT(t8) - lw ta2, THREAD_PRI(t8) - bge ta2, ta3, 1b -2: - lw t8, THREAD_NEXT(t9) - sw t8, THREAD_NEXT(a1) - sw a1, THREAD_NEXT(t9) - sw a0, THREAD_QUEUE(a1) - jr ra -END(__osEnqueueThread) - -LEAF(__osPopThread) - lw v0, 0(a0) /* a0 is OSThread** */ - lw t9, THREAD_NEXT(v0) - sw t9, 0(a0) - jr ra -END(__osPopThread) -#if BUILD_VERSION >= VERSION_K -LEAF(__osNop) - jr ra -END(__osNop) -#endif -LEAF(__osDispatchThread) - la a0, __osRunQueue - jal __osPopThread - sw v0, __osRunningThread - li t0, OS_STATE_RUNNING - sh t0, THREAD_STATE(v0) - move k0, v0 - -#if !defined(_FINALROM) && BUILD_VERSION >= VERSION_K - la t0, __osThprofFunc - lw t0, (t0) - beqz t0, __osDispatchThreadSave -1: - lw a0, __osPreviousThread - lw sp, __osThprofStack - jalr t0 -#endif - -/* There's another 1: label somewhere around here in version J and below */ -#if BUILD_VERSION < VERSION_K -1: -#endif - -__osDispatchThreadSave: - lw k1, THREAD_SR(k0) - la t0, __OSGlobalIntMask - lw t0, 0(t0) - andi t0, t0, SR_IMASK - andi t1, k1, SR_IMASK - and t1, t1, t0 - and k1, k1, ~SR_IMASK - or k1, k1, t1 -STAY2(mtc0 k1, C0_SR) -.set noat - ld $1, THREAD_GP1(k0) -.set at - ld $2, THREAD_GP2(k0) - ld $3, THREAD_GP3(k0) - ld $4, THREAD_GP4(k0) - ld $5, THREAD_GP5(k0) - ld $6, THREAD_GP6(k0) - ld $7, THREAD_GP7(k0) - ld $8, THREAD_GP8(k0) - ld $9, THREAD_GP9(k0) - ld $10, THREAD_GP10(k0) - ld $11, THREAD_GP11(k0) - ld $12, THREAD_GP12(k0) - ld $13, THREAD_GP13(k0) - ld $14, THREAD_GP14(k0) - ld $15, THREAD_GP15(k0) - ld $16, THREAD_GP16(k0) - ld $17, THREAD_GP17(k0) - ld $18, THREAD_GP18(k0) - ld $19, THREAD_GP19(k0) - ld $20, THREAD_GP20(k0) - ld $21, THREAD_GP21(k0) - ld $22, THREAD_GP22(k0) - ld $23, THREAD_GP23(k0) - ld $24, THREAD_GP24(k0) - ld $25, THREAD_GP25(k0) - ld $28, THREAD_GP28(k0) - ld $29, THREAD_GP29(k0) - ld $30, THREAD_GP30(k0) - ld $31, THREAD_GP31(k0) - ld k1, THREAD_LO(k0) - mtlo k1 - ld k1, THREAD_HI(k0) - mthi k1 - lw k1, THREAD_PC(k0) -STAY2(mtc0 k1, C0_EPC) - lw k1, THREAD_FP(k0) - beqz k1, 1f - - lw k1, THREAD_FPCSR(k0) -STAY2(ctc1 k1, fcr31) - ldc1 $f0, THREAD_FP0(k0) - ldc1 $f2, THREAD_FP2(k0) - ldc1 $f4, THREAD_FP4(k0) - ldc1 $f6, THREAD_FP6(k0) - ldc1 $f8, THREAD_FP8(k0) - ldc1 $f10, THREAD_FP10(k0) - ldc1 $f12, THREAD_FP12(k0) - ldc1 $f14, THREAD_FP14(k0) - ldc1 $f16, THREAD_FP16(k0) - ldc1 $f18, THREAD_FP18(k0) - ldc1 $f20, THREAD_FP20(k0) - ldc1 $f22, THREAD_FP22(k0) - ldc1 $f24, THREAD_FP24(k0) - ldc1 $f26, THREAD_FP26(k0) - ldc1 $f28, THREAD_FP28(k0) - ldc1 $f30, THREAD_FP30(k0) - -1: -.set noreorder - lw k1, THREAD_RCP(k0) - la k0, __OSGlobalIntMask - lw k0, 0(k0) - srl k0, k0, 0x10 - and k1, k1, k0 - sll k1, k1, 0x1 - la k0, __osRcpImTable - addu k1, k1, k0 - lhu k1, 0(k1) - la k0, PHYS_TO_K1(MI_INTR_MASK_REG) - sw k1, 0(k0) - - nop - nop - nop - nop - eret -.set reorder -END(__osDispatchThread) - -LEAF(__osCleanupThread) - move a0, zero -#if !defined(BBPLAYER) && !defined(__sgi) - nop -#endif - jal osDestroyThread -END(__osCleanupThread) diff --git a/lib/ultralib/src/os/exit.c b/lib/ultralib/src/os/exit.c deleted file mode 100644 index 24a873f..0000000 --- a/lib/ultralib/src/os/exit.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" - -void osExit() { - __osGIOInterrupt(16); - - for (;;) { - ; - } -} diff --git a/lib/ultralib/src/os/getactivequeue.c b/lib/ultralib/src/os/getactivequeue.c deleted file mode 100644 index 1fefc88..0000000 --- a/lib/ultralib/src/os/getactivequeue.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -OSThread* __osGetActiveQueue(void) { - return __osActiveQueue; -} diff --git a/lib/ultralib/src/os/getcause.s b/lib/ultralib/src/os/getcause.s deleted file mode 100644 index 873464f..0000000 --- a/lib/ultralib/src/os/getcause.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osGetCause) - STAY2(mfc0 v0, C0_CAUSE) - jr ra -END(__osGetCause) diff --git a/lib/ultralib/src/os/getcompare.s b/lib/ultralib/src/os/getcompare.s deleted file mode 100644 index 99c1758..0000000 --- a/lib/ultralib/src/os/getcompare.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osGetCompare) - STAY2(mfc0 v0, C0_COMPARE) - jr ra -END(__osGetCompare) diff --git a/lib/ultralib/src/os/getconfig.s b/lib/ultralib/src/os/getconfig.s deleted file mode 100644 index 8165178..0000000 --- a/lib/ultralib/src/os/getconfig.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osGetConfig) - STAY2(mfc0 v0, C0_CONFIG) - jr ra -END(__osGetConfig) diff --git a/lib/ultralib/src/os/getcount.s b/lib/ultralib/src/os/getcount.s deleted file mode 100644 index 28d5a79..0000000 --- a/lib/ultralib/src/os/getcount.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(osGetCount) - STAY2(mfc0 v0, C0_COUNT) - jr ra -END(osGetCount) diff --git a/lib/ultralib/src/os/getcurrfaultthread.c b/lib/ultralib/src/os/getcurrfaultthread.c deleted file mode 100644 index d7668c2..0000000 --- a/lib/ultralib/src/os/getcurrfaultthread.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -OSThread* __osGetCurrFaultedThread() { - return __osFaultedThread; -} diff --git a/lib/ultralib/src/os/getfpccsr.s b/lib/ultralib/src/os/getfpccsr.s deleted file mode 100644 index 56837a5..0000000 --- a/lib/ultralib/src/os/getfpccsr.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osGetFpcCsr) - STAY2(cfc1 v0, fcr31) - jr ra -END(__osGetSR) # @bug: Should be __osGetFpcCsr diff --git a/lib/ultralib/src/os/gethwinterrupt.c b/lib/ultralib/src/os/gethwinterrupt.c deleted file mode 100644 index 46dc366..0000000 --- a/lib/ultralib/src/os/gethwinterrupt.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "PR/os_internal.h" - -struct __osHwInt { - s32 (*handler)(void); -#if BUILD_VERSION >= VERSION_J - void* stackEnd; -#endif -}; - -extern struct __osHwInt __osHwIntTable[]; - -#if BUILD_VERSION >= VERSION_J -void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void), void** stackEnd) { -#else -void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void)) { -#endif - *handler = __osHwIntTable[interrupt].handler; -#if BUILD_VERSION >= VERSION_J - *stackEnd = __osHwIntTable[interrupt].stackEnd; -#endif -} diff --git a/lib/ultralib/src/os/getintmask.s b/lib/ultralib/src/os/getintmask.s deleted file mode 100644 index 573eed1..0000000 --- a/lib/ultralib/src/os/getintmask.s +++ /dev/null @@ -1,33 +0,0 @@ -#include "PR/R4300.h" -#include "PR/rcp.h" -#include "PR/os.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -.set noreorder -LEAF(osGetIntMask) - mfc0 v0, C0_SR - andi v0, v0, OS_IM_CPU - la t0, __OSGlobalIntMask - lw t1, 0(t0) - xor t0, t1, -1 - andi t0, t0, SR_IMASK - or v0, v0, t0 - - lw t1, PHYS_TO_K1(MI_INTR_MASK_REG) - beqz t1, 1f - - la t0, __OSGlobalIntMask # this is intentionally a macro in the branch delay slot - - lw t0, 0(t0) - srl t0, t0, 0x10 - xor t0, t0, -1 - andi t0, t0, 0x3f - or t1, t1, t0 -1: - sll t2, t1, 0x10 - or v0, v0, t2 - jr ra - nop -END(osGetIntMask) diff --git a/lib/ultralib/src/os/getmemsize.c b/lib/ultralib/src/os/getmemsize.c deleted file mode 100644 index 814443d..0000000 --- a/lib/ultralib/src/os/getmemsize.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PR/R4300.h" - -#define STEP 0x100000 -#define SIZE_4MB 0x400000 -#define SIZE_8MB 0x800000 - -#if BUILD_VERSION >= VERSION_J - -u32 osGetMemSize(void) { - vu32* ptr; - u32 size = SIZE_4MB; - u32 data0; - u32 data1; - - while (size < SIZE_8MB) { - ptr = (vu32*)(K1BASE + size); - - data0 = *ptr; - data1 = ptr[STEP / 4 - 1]; - - *ptr ^= ~0; - ptr[STEP / 4 - 1] ^= ~0; - - if ((*ptr != (data0 ^ ~0)) || (ptr[STEP / 4 - 1] != (data1 ^ ~0))) { - return size; - } - - *ptr = data0; - ptr[STEP / 4 - 1] = data1; - - size += STEP; - } - - return size; -} - -#else - -u32 osGetMemSize(void) { - u32* memory; - u32 memsize = SIZE_4MB - STEP; - do { - memsize += STEP; - memory = (u32*)(memsize + K1BASE); - memory[0] = 0x12345678; - memory[STEP / 4 - 1] = 0x87654321; - } while (memory[0] == 0x12345678 && memory[STEP / 4 - 1] == 0x87654321); - return memsize; -} - -#endif diff --git a/lib/ultralib/src/os/getnextfaultthread.c b/lib/ultralib/src/os/getnextfaultthread.c deleted file mode 100644 index 44d723a..0000000 --- a/lib/ultralib/src/os/getnextfaultthread.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -OSThread* __osGetNextFaultedThread(OSThread* lastFault) { - register int saveMask = __osDisableInt(); - register OSThread* fault; - - fault = lastFault == NULL ? __osActiveQueue : lastFault; - - while (fault->priority != -1) { - if ((fault->flags & OS_FLAG_FAULT) != 0 && fault != lastFault) { - break; - } - fault = fault->tlnext; - } - - if (fault->priority == -1) { - fault = NULL; - } - - __osRestoreInt(saveMask); - return fault; -} diff --git a/lib/ultralib/src/os/getsr.s b/lib/ultralib/src/os/getsr.s deleted file mode 100644 index bc9c767..0000000 --- a/lib/ultralib/src/os/getsr.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osGetSR) - STAY2(mfc0 v0, C0_SR) - jr ra -END(__osGetSR) diff --git a/lib/ultralib/src/os/getthreadid.c b/lib/ultralib/src/os/getthreadid.c deleted file mode 100644 index 8bbc9f6..0000000 --- a/lib/ultralib/src/os/getthreadid.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -OSId osGetThreadId(OSThread* thread) { - if (thread == NULL) { - thread = __osRunningThread; - } - - return thread->id; -} diff --git a/lib/ultralib/src/os/getthreadpri.c b/lib/ultralib/src/os/getthreadpri.c deleted file mode 100644 index 149f3f7..0000000 --- a/lib/ultralib/src/os/getthreadpri.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -OSPri osGetThreadPri(OSThread* thread) { - if (thread == NULL) { - thread = __osRunningThread; - } - - return thread->priority; -} diff --git a/lib/ultralib/src/os/gettime.c b/lib/ultralib/src/os/gettime.c deleted file mode 100644 index aab4133..0000000 --- a/lib/ultralib/src/os/gettime.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" -#include "../io/viint.h" - -OSTime osGetTime() { - u32 tmptime; - u32 elapseCount; - OSTime currentCount; - register u32 saveMask; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSGETTIME, 0); - return 0; - } -#endif - - saveMask = __osDisableInt(); - tmptime = osGetCount(); - elapseCount = tmptime - __osBaseCounter; - currentCount = __osCurrentTime; - __osRestoreInt(saveMask); - return currentCount + elapseCount; -} diff --git a/lib/ultralib/src/os/gettlbasid.s b/lib/ultralib/src/os/gettlbasid.s deleted file mode 100644 index a0702ea..0000000 --- a/lib/ultralib/src/os/gettlbasid.s +++ /dev/null @@ -1,11 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.set noreorder -.text -LEAF(__osGetTLBASID) - mfc0 v0, C0_ENTRYHI - jr ra - nop -END(__osGetTLBASID) diff --git a/lib/ultralib/src/os/gettlbhi.s b/lib/ultralib/src/os/gettlbhi.s deleted file mode 100644 index 04c03e9..0000000 --- a/lib/ultralib/src/os/gettlbhi.s +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.set noreorder -.text -LEAF(__osGetTLBHi) - mtc0 a0, C0_INX - nop - tlbr - nop - nop - nop - mfc0 v0, C0_ENTRYHI - jr ra - nop -END(__osGetTLBHi) diff --git a/lib/ultralib/src/os/gettlblo0.s b/lib/ultralib/src/os/gettlblo0.s deleted file mode 100644 index 3b2c2ec..0000000 --- a/lib/ultralib/src/os/gettlblo0.s +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.set noreorder -.text -LEAF(__osGetTLBLo0) - mtc0 a0, C0_INX - nop - tlbr - nop - nop - nop - mfc0 v0, C0_ENTRYLO0 - jr ra - nop -END(__osGetTLBLo0) diff --git a/lib/ultralib/src/os/gettlblo1.s b/lib/ultralib/src/os/gettlblo1.s deleted file mode 100644 index a24baef..0000000 --- a/lib/ultralib/src/os/gettlblo1.s +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.set noreorder -.text -LEAF(__osGetTLBLo1) - mtc0 a0, C0_INX - nop - tlbr - nop - nop - nop - mfc0 v0, C0_ENTRYLO1 - jr ra - nop -END(__osGetTLBLo1) diff --git a/lib/ultralib/src/os/gettlbpagemask.s b/lib/ultralib/src/os/gettlbpagemask.s deleted file mode 100644 index de9954a..0000000 --- a/lib/ultralib/src/os/gettlbpagemask.s +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.set noreorder -.text -LEAF(__osGetTLBPageMask) - mtc0 a0, C0_INX - nop - tlbr - nop - nop - nop - mfc0 v0, C0_PAGEMASK - jr ra - nop -END(__osGetTLBPageMask) diff --git a/lib/ultralib/src/os/getwatchlo.s b/lib/ultralib/src/os/getwatchlo.s deleted file mode 100644 index 4eee9ee..0000000 --- a/lib/ultralib/src/os/getwatchlo.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osGetWatchLo) - STAY2(mfc0 v0, C0_WATCHLO) - jr ra -END(__osGetWatchLo) diff --git a/lib/ultralib/src/os/initialize.c b/lib/ultralib/src/os/initialize.c deleted file mode 100644 index 89f4b02..0000000 --- a/lib/ultralib/src/os/initialize.c +++ /dev/null @@ -1,224 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PR/os_version.h" -#include "../io/piint.h" - -typedef struct { - /* 0x0 */ unsigned int inst1; - /* 0x4 */ unsigned int inst2; - /* 0x8 */ unsigned int inst3; - /* 0xC */ unsigned int inst4; -} __osExceptionVector; -extern __osExceptionVector __osExceptionPreamble[]; - -extern OSPiHandle __Dom1SpeedParam; -extern OSPiHandle __Dom2SpeedParam; - -OSTime osClockRate = OS_CLOCK_RATE; -s32 osViClock = VI_NTSC_CLOCK; -u32 __osShutdown = 0; -u32 __OSGlobalIntMask = OS_IM_ALL; -#ifdef _FINALROM -u32 __osFinalrom; -#else -u32 __kmc_pt_mode; -#if BUILD_VERSION >= VERSION_K -void* __printfunc = NULL; -#endif -#endif - -#if BUILD_VERSION >= VERSION_K - -#define INITIALIZE_FUNC __osInitialize_common -#define SPEED_PARAM_FUNC __createSpeedParam -#else - -#define INITIALIZE_FUNC osInitialize -#define SPEED_PARAM_FUNC createSpeedParam -#if BUILD_VERSION >= VERSION_J -static void ptstart(void); -static void SPEED_PARAM_FUNC(void); -#endif -extern __osExceptionVector __ptExceptionPreamble[]; - -#endif - -#if BUILD_VERSION >= VERSION_K -void SPEED_PARAM_FUNC(void) { - __Dom1SpeedParam.type = DEVICE_TYPE_INIT; - __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); - __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); - __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); - __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); - - __Dom2SpeedParam.type = DEVICE_TYPE_INIT; - __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); - __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); - __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); - __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); -} -#endif - -void INITIALIZE_FUNC() { - u32 pifdata; -#if BUILD_VERSION < VERSION_K - u32 clock = 0; -#endif - -#ifdef _FINALROM - __osFinalrom = TRUE; -#endif - - __osSetSR(__osGetSR() | SR_CU1); // enable fpu - __osSetFpcCsr(FPCSR_FS | FPCSR_EV); // flush denorm to zero, enable invalid operation -#if BUILD_VERSION >= VERSION_K - __osSetWatchLo(0x4900000); -#endif - - while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)) { // last byte of joychannel ram - ; - } - while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)) { - ; // todo: magic contant - } - *(__osExceptionVector*)UT_VEC = *__osExceptionPreamble; - *(__osExceptionVector*)XUT_VEC = *__osExceptionPreamble; - *(__osExceptionVector*)ECC_VEC = *__osExceptionPreamble; - *(__osExceptionVector*)E_VEC = *__osExceptionPreamble; - osWritebackDCache((void*)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); - osInvalICache((void*)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); -#if BUILD_VERSION >= VERSION_J - SPEED_PARAM_FUNC(); - osUnmapTLBAll(); - osMapTLBRdb(); -#else - osMapTLBRdb(); - osPiRawReadIo(4, &clock); // Read clock rate from the ROM header - clock &= ~0xf; - if (clock != 0) - { - osClockRate = clock; - } -#endif - osClockRate = osClockRate * 3 / 4; - - if (osResetType == 0) { // cold reset - bzero(osAppNMIBuffer, OS_APP_NMI_BUFSIZE); - } - - if (osTvType == OS_TV_PAL) { - osViClock = VI_PAL_CLOCK; - } else if (osTvType == OS_TV_MPAL) { - osViClock = VI_MPAL_CLOCK; - } else { - osViClock = VI_NTSC_CLOCK; - } - -#if BUILD_VERSION >= VERSION_J - // Wait until there are no RCP interrupts - if (__osGetCause() & CAUSE_IP5) { - while (TRUE) { - ; - } - } - - IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); - IO_WRITE(AI_DACRATE_REG, AI_MAX_DAC_RATE - 1); - IO_WRITE(AI_BITRATE_REG, AI_MAX_BIT_RATE - 1); -#endif - -#if BUILD_VERSION < VERSION_K && !defined(_FINALROM) - if (!__kmc_pt_mode) { - int (*fnc)(); -#if BUILD_VERSION < VERSION_J - unsigned int c; - unsigned int c1; -#endif - unsigned int* src; - unsigned int* dst; - unsigned int monadr; - volatile unsigned int* mon; - volatile unsigned int* stat; - - stat = (unsigned*)0xbff08004; - mon = (unsigned*)0xBFF00000; - if (*mon != 0x4B4D4300) { - return; - } - - src = (unsigned*)__ptExceptionPreamble; - dst = (unsigned*)E_VEC; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - src += 2; - dst += 2; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - - osWritebackDCache(E_VEC, 0x24); - osInvalICache(E_VEC, 0x24); - - __kmc_pt_mode = TRUE; - - if ((*stat & 0x10) == 0) { - monadr = *(mon + 1); - if (monadr != 0xBFF00000) { - unsigned int* src; - unsigned int* dst = monadr | 0x20000000; - unsigned int ct = 0x2000 / 4; - - src = 0xBFF00000; - - while (ct != 0) { - *dst++ = *src++; - ct--; - } - } - fnc = monadr + 8; - fnc(0x4B4D4300, 0); - } - } -#endif -} - -#if !defined(_FINALROM) && BUILD_VERSION < VERSION_J -void ptstart() { - -} -#elif !defined(_FINALROM) && BUILD_VERSION < VERSION_K -static void ptstart() { - -} -#endif - -#if BUILD_VERSION >= VERSION_K -void __osInitialize_autodetect() { -#ifndef _FINALROM - if (__checkHardware_msp()) { - __osInitialize_msp(); - } else if (__checkHardware_kmc()) { - __osInitialize_kmc(); - } else if (__checkHardware_isv()) { - __osInitialize_isv(); - } else { - __osInitialize_emu(); - } -#endif -} -#elif BUILD_VERSION == VERSION_J -static void SPEED_PARAM_FUNC(void) { - __Dom1SpeedParam.type = DEVICE_TYPE_INIT; - __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); - __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); - __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); - __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); - - __Dom2SpeedParam.type = DEVICE_TYPE_INIT; - __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); - __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); - __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); - __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); -} -#endif diff --git a/lib/ultralib/src/os/initialize_emu.c b/lib/ultralib/src/os/initialize_emu.c deleted file mode 100644 index 7f7dd85..0000000 --- a/lib/ultralib/src/os/initialize_emu.c +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "PR/rdb.h" -#include "osint.h" - -typedef struct { - /* 0x0 */ unsigned int inst1; - /* 0x4 */ unsigned int inst2; - /* 0x8 */ unsigned int inst3; - /* 0xC */ unsigned int inst4; -} __osExceptionVector; - -static void* proutSyncPrintf(void* str, const char* buf, size_t n) { - size_t sent = 0; - - while (sent < n) { - sent += __osRdbSend(buf + sent, n - sent, RDB_TYPE_GtoH_PRINT); - } - return 1; -} - -void __osInitialize_emu(void) { - __printfunc = proutSyncPrintf; -} - -#endif diff --git a/lib/ultralib/src/os/initialize_isv.c b/lib/ultralib/src/os/initialize_isv.c deleted file mode 100644 index 50f6379..0000000 --- a/lib/ultralib/src/os/initialize_isv.c +++ /dev/null @@ -1,175 +0,0 @@ -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "osint.h" - -#include "macros.h" - -typedef struct { - /* 0x0 */ unsigned int inst1; - /* 0x4 */ unsigned int inst2; - /* 0x8 */ unsigned int inst3; - /* 0xC */ unsigned int inst4; -} __osExceptionVector; - -extern __osExceptionVector __isExpJP; - -void MonitorInitBreak(void); - -#define ISV_BASE gISVDbgPrnAdrs -#define ISV_MAGIC_ADDR (ISV_BASE + 0x00) -#define ISV_GET_ADDR (ISV_BASE + 0x04) -#define ISV_PUT_ADDR (ISV_BASE + 0x14) -#define ISV_BUFFER (ISV_BASE + 0x20) - -#define ISV_BUFFER_LEN (0x10000 - 0x20) - -#define IS64_MAGIC 'IS64' - -__osExceptionVector ramOldVector ALIGNED(8); -u32 gISVFlag; -u16 gISVChk; -u32 gISVDbgPrnAdrs; -u32 leoComuBuffAdd; - -static OSPiHandle* is_Handle; - -void isPrintfInit(void) { - is_Handle = osCartRomInit(); - - osEPiWriteIo(is_Handle, ISV_PUT_ADDR, 0); - osEPiWriteIo(is_Handle, ISV_GET_ADDR, 0); - osEPiWriteIo(is_Handle, ISV_MAGIC_ADDR, IS64_MAGIC); -} - -static void* is_proutSyncPrintf(void* arg, const u8* str, u32 count) { - u32 data; - s32 p; - s32 start; - s32 end; - - if (gISVDbgPrnAdrs == 0) { - return 0; - } - - osEPiReadIo(is_Handle, ISV_MAGIC_ADDR, &data); - if (data != IS64_MAGIC) { - return 1; - } - osEPiReadIo(is_Handle, ISV_GET_ADDR, &data); - p = data; - osEPiReadIo(is_Handle, ISV_PUT_ADDR, &data); - - start = data; - end = start + count; - - if (end >= ISV_BUFFER_LEN) { - end -= ISV_BUFFER_LEN; - if (p < end || start < p) { - return 1; - } - } else { - if (start < p && p < end) { - return 1; - } - } - while (count) { - if (*str != '\0') { - s32 shift = start & 3; - u32 addr = ISV_BUFFER + (start & 0xFFFFFFC); - - shift = (3 - shift) * 8; - - osEPiReadIo(is_Handle, addr, &data); - osEPiWriteIo(is_Handle, addr, (data & ~(0xff << shift)) | (*str << shift)); - - start++; - if (start >= ISV_BUFFER_LEN) { - start -= ISV_BUFFER_LEN; - } - } - count--; - str++; - } - osEPiWriteIo(is_Handle, ISV_PUT_ADDR, start); - - return 1; -} - -int __checkHardware_isv(void) { - u32 i = 0; - u32 data; - u32 save[4]; - OSPiHandle* hnd = osCartRomInit(); - - gISVDbgPrnAdrs = 0; - leoComuBuffAdd = 0; - gISVFlag = IS64_MAGIC; - gISVChk = 0; - - for (i = 0; i < 4; i++) { - osEPiReadIo(hnd, 0xB0000100 + i * 4, &save[i]); - } - -#ifndef __GNU__ // BUG: data is used uninitialized for GCC - data = 0; -#endif - osEPiWriteIo(hnd, 0xB000010C, data); - data = IS64_MAGIC; - osEPiWriteIo(hnd, 0xB0000100, IS64_MAGIC); - - for (i = 0; i < 0x20000; i++) { - osEPiReadIo(hnd, 0xB000010C, &data); - if (data == IS64_MAGIC) { - data = 0; - osEPiWriteIo(hnd, 0xB0000100, data); - gISVChk |= 1; - osEPiReadIo(hnd, 0xB0000104, &gISVDbgPrnAdrs); - osEPiReadIo(hnd, 0xB0000108, &leoComuBuffAdd); - break; - } - } - - for (i = 0; i < 4; i++) { - osEPiWriteIo(hnd, 0xB0000100 + i * 4, save[i]); - } - - osEPiReadIo(hnd, 0xBFF00000, &data); - - gISVChk |= ((data == IS64_MAGIC) ? 2 : 0); - - return (gISVChk != 0) ? TRUE : FALSE; -} - -void __osInitialize_isv(void) { - void (*fn)(void); - OSPiHandle* hnd; - s32 pad; - s32 pad2; - - if (gISVFlag == IS64_MAGIC || __checkHardware_isv()) { - if (gISVDbgPrnAdrs != 0) { - __printfunc = is_proutSyncPrintf; - isPrintfInit(); - } - if (gISVChk & 2) { - hnd = osCartRomInit(); - - ramOldVector = *(__osExceptionVector*)E_VEC; - *(__osExceptionVector*)E_VEC = __isExpJP; - - osWritebackDCache(&ramOldVector, 0x10); - osInvalICache(&ramOldVector, 0x10); - osWritebackDCache(0x80000000, 0x190); - osInvalICache(0x80000000, 0x190); - osEPiReadIo(hnd, 0xBFF00010, (u32*)&fn); - fn(); - } - if (gISVChk & 2) { - MonitorInitBreak(); - } - } -} - -#endif diff --git a/lib/ultralib/src/os/initialize_kmc.c b/lib/ultralib/src/os/initialize_kmc.c deleted file mode 100644 index 4952a0d..0000000 --- a/lib/ultralib/src/os/initialize_kmc.c +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "osint.h" - -typedef struct { - /* 0x0 */ unsigned int inst1; - /* 0x4 */ unsigned int inst2; - /* 0x8 */ unsigned int inst3; - /* 0xC */ unsigned int inst4; -} __osExceptionVector; - -extern __osExceptionVector __ptExceptionPreamble[]; - -static volatile unsigned int* stat = (unsigned*)0xbff08004; -static volatile unsigned int* wport = (unsigned*)0xbff08000; -static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); - -static void rmonPutchar(char c) { - u32 data; - - while (TRUE) { - osPiReadIo(stat, &data); - if (data & 4) { - osPiWriteIo(wport, c); - break; - } - } -} - -static void* kmc_proutSyncPrintf(void* str, const char* buf, int n) { - int i; - char c; - char* p; - char* q; - char xbuf[128]; - static int column = 0; - - p = &xbuf; - - for (i = 0; i < n; i++) { - c = *buf++; - - switch (c) { - case '\n': - *p++ = '\n'; - column = 0; - break; - case '\t': - do { - *p++ = ' '; - } while (++column % 8); - break; - default: - column++; - *p++ = c; - break; - } - - if (c == '\n' || (p - xbuf) > 100) { - rmonPutchar((p - xbuf) - 1); - - q = xbuf; - while (q != p) { - rmonPutchar(*q++); - } - p = xbuf; - } - } - if (p != xbuf) { - rmonPutchar((p - xbuf) - 1); - - q = xbuf; - while (q != p) { - rmonPutchar(*q++); - } - } - return (void*)1; -} - -extern u32 __kmc_pt_mode; - -void __osInitialize_kmc(void) { - if (!__kmc_pt_mode) { - int (*fnc)(); - unsigned int* src; - unsigned int* dst; - unsigned int monadr; - volatile unsigned int* mon; - volatile unsigned int* stat; - - stat = (unsigned*)0xbff08004; - mon = (unsigned*)0xBFF00000; - if (*mon != 0x4B4D4300) { - return; - } - - src = (unsigned*)__ptExceptionPreamble; - dst = (unsigned*)E_VEC; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - src += 2; - dst += 2; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - - osWritebackDCache(E_VEC, 0x24); - osInvalICache(E_VEC, 0x24); - - __kmc_pt_mode = TRUE; - - if ((*stat & 0x10) == 0) { - monadr = *(mon + 1); - if (monadr != 0xBFF00000) { - unsigned int* src; - unsigned int* dst = monadr | 0x20000000; - unsigned int ct = 0x2000 / 4; - - src = 0xBFF00000; - - while (ct != 0) { - *dst++ = *src++; - ct--; - } - } - fnc = monadr + 8; - fnc(0x4B4D4300, 0); - } - __printfunc = kmc_proutSyncPrintf; - } -} - -int __checkHardware_kmc(void) { - volatile unsigned int* mon = (unsigned*)0xBFF00000; - - if (*mon == 0x4B4D4300) { - mon = (unsigned*)0xBFF00010; - - if (*mon == 0xB0FFB000) { - return TRUE; - } else { - return FALSE; - } - } else { - return FALSE; - } -} - -#endif diff --git a/lib/ultralib/src/os/initialize_msp.c b/lib/ultralib/src/os/initialize_msp.c deleted file mode 100644 index 1f120e1..0000000 --- a/lib/ultralib/src/os/initialize_msp.c +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "osint.h" - -typedef struct { - /* 0x0 */ unsigned int inst1; - /* 0x4 */ unsigned int inst2; - /* 0x8 */ unsigned int inst3; - /* 0xC */ unsigned int inst4; -} __osExceptionVector; - -extern __osExceptionVector __ptExceptionPreamble[]; - -static volatile unsigned int* stat = (unsigned*)0xbff08004; -static volatile unsigned int* wport = (unsigned*)0xbff08000; -static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); - -static void rmonPutchar(char c) { - u32 data; - - while (TRUE) { - osPiReadIo(stat, &data); - if (data & 4) { - osPiWriteIo(wport, c); - break; - } - } -} - -static void* msp_proutSyncPrintf(void* str, const char* buf, int n) { - int i; - char c; - char* p; - char* q; - char xbuf[128]; - static int column = 0; - - p = &xbuf; - - for (i = 0; i < n; i++) { - c = *buf++; - - switch (c) { - case '\n': - *p++ = '\n'; - column = 0; - break; - case '\t': - do { - *p++ = ' '; - } while (++column % 8); - break; - default: - column++; - *p++ = c; - break; - } - - if (c == '\n' || (p - xbuf) > 100) { - rmonPutchar((p - xbuf) - 1); - - q = xbuf; - while (q != p) { - rmonPutchar(*q++); - } - p = xbuf; - } - } - if (p != xbuf) { - rmonPutchar((p - xbuf) - 1); - - q = xbuf; - while (q != p) { - rmonPutchar(*q++); - } - } - return (void*)1; -} - -extern u32 __kmc_pt_mode; - -void __osInitialize_msp(void) { - if (!__kmc_pt_mode) { - int (*fnc)(); - unsigned int* src; - unsigned int* dst; - unsigned int monadr; - volatile unsigned int* mon; - volatile unsigned int* stat; - - stat = (unsigned*)0xbff08004; - mon = (unsigned*)0xBFF00000; - if (*mon != 0x4B4D4300) { - return; - } - - src = (unsigned*)__ptExceptionPreamble; - dst = (unsigned*)E_VEC; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - src += 2; - dst += 2; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - - osWritebackDCache(E_VEC, 0x24); - osInvalICache(E_VEC, 0x24); - - __kmc_pt_mode = TRUE; - - if ((*stat & 0x10) == 0) { - monadr = *(mon + 1); - if (monadr != 0xBFF00000) { - unsigned int* src; - unsigned int* dst = monadr | 0x20000000; - unsigned int ct = 0x2000 / 4; - - src = 0xBFF00000; - - while (ct != 0) { - *dst++ = *src++; - ct--; - } - } - fnc = monadr + 8; - fnc(0x4B4D4300, 0); - } - __printfunc = msp_proutSyncPrintf; - } -} - -int __checkHardware_msp(void) { - volatile unsigned int* mon = (unsigned*)0xBFF00000; - - if (*mon == 0x4B4D4300) { - mon = (unsigned*)0xBFF00010; - - if (*mon == 0) { - return TRUE; - } else { - return FALSE; - } - } else { - return FALSE; - } -} - -#endif diff --git a/lib/ultralib/src/os/initrdb.c b/lib/ultralib/src/os/initrdb.c deleted file mode 100644 index 5537eb1..0000000 --- a/lib/ultralib/src/os/initrdb.c +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _FINALROM -#include "PR/rdb.h" -#include "PR/os_internal.h" - -rdbPacket* __osRdb_IP6_Data; -u32 __osRdb_IP6_Size; -u32 __osRdb_IP6_Ct; -u32 __osRdb_IP6_CurWrite; -u32 __osRdb_IP6_CurSend; - -void osInitRdb(u8* sendBuf, u32 sendSize) { - u32 mask; - - sendSize /= 4; - - if (((u32)sendBuf & 3) != 0) { - sendBuf = ((u32)sendBuf & 3) + 4; - sendSize--; - } - mask = __osDisableInt(); - - __osRdb_IP6_Data = sendBuf; - __osRdb_IP6_Size = sendSize; - __osRdb_IP6_Ct = 0; - __osRdb_IP6_CurWrite = 0; - __osRdb_IP6_CurSend = 0; - - __osRestoreInt(mask); -} - -#endif diff --git a/lib/ultralib/src/os/interrupt.s b/lib/ultralib/src/os/interrupt.s deleted file mode 100644 index 01efe1a..0000000 --- a/lib/ultralib/src/os/interrupt.s +++ /dev/null @@ -1,52 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" -#include "PR/os_version.h" - -.text -.set noreorder -LEAF(__osDisableInt) -#if BUILD_VERSION >= VERSION_J - la t2, __OSGlobalIntMask - lw t3, (t2) - andi t3, 0xFF00 - mfc0 t0, C0_SR - and t1, t0, ~SR_IE - mtc0 t1, C0_SR - andi v0, t0, SR_IE - lw t0, (t2) - andi t0, 0xFF00 - beq t0, t3, No_Change_Global_Int - la t2, __osRunningThread # this is intentionally a macro in the branch delay slot - lw t1, 280(t2) - andi t2, t1, 0xFF00 - and t2, t0 - and t1, 0xFFFF00FF - or t1, t2 - and t1, -2 - mtc0 t1, $12 - nop - nop -No_Change_Global_Int: - jr ra - nop -#else - mfc0 t0, C0_SR - and t1, t0, ~SR_IE - mtc0 t1, C0_SR - andi v0, t0, SR_IE - nop - jr ra - nop -#endif -END(__osDisableInt) - -LEAF(__osRestoreInt) - mfc0 t0, C0_SR - or t0, t0, a0 - mtc0 t0, C0_SR - nop - nop - jr ra - nop -END(__osRestoreInt) diff --git a/lib/ultralib/src/os/invaldcache.s b/lib/ultralib/src/os/invaldcache.s deleted file mode 100644 index ea6a657..0000000 --- a/lib/ultralib/src/os/invaldcache.s +++ /dev/null @@ -1,58 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(osInvalDCache) - blez a1, 3f - li t3, DCACHE_SIZE - bgeu a1, t3, 4f - - - move t0, a0 - addu t1, a0, a1 - bgeu t0, t1, 3f - - - addiu t1, t1, -DCACHE_LINESIZE - andi t2, t0, DCACHE_LINEMASK - beqz t2, 1f - - - subu t0, t0, t2 - CACHE((C_HWBINV|CACH_PD), (t0)) - bgeu t0, t1, 3f - - - addiu t0, t0, DCACHE_LINESIZE -1: - andi t2, t1, DCACHE_LINEMASK - beqz t2, 2f - - subu t1, t1, t2 - CACHE((C_HWBINV|CACH_PD), 0x10(t1)) - bltu t1, t0, 3f - -2: - CACHE((C_HINV|CACH_PD), (t0)) - .set noreorder - bltu t0, t1, 2b - addiu t0, t0, DCACHE_LINESIZE - .set reorder -3: - jr ra - -4: - li t0, KUSIZE - addu t1, t0, t3 - addiu t1, t1, -DCACHE_LINESIZE -5: - CACHE((C_IINV|CACH_PD), (t0)) - .set noreorder - bltu t0, t1, 5b - addiu t0, t0, DCACHE_LINESIZE - .set reorder - - jr ra - -END(osInvalDCache) diff --git a/lib/ultralib/src/os/invalicache.s b/lib/ultralib/src/os/invalicache.s deleted file mode 100644 index f5ceb58..0000000 --- a/lib/ultralib/src/os/invalicache.s +++ /dev/null @@ -1,41 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(osInvalICache) - blez a1, 2f - - li t3, ICACHE_SIZE - bgeu a1, t3, 3f - - move t0, a0 - addu t1, a0, a1 - bgeu t0, t1, 2f - - addiu t1, t1, -ICACHE_LINESIZE - andi t2, t0, ICACHE_LINEMASK - subu t0, t0, t2 -1: - CACHE((C_HINV|CACH_PI), (t0)) - .set noreorder - bltu t0, t1, 1b - addiu t0, t0, ICACHE_LINESIZE - .set reorder -2: - jr ra - -3: - li t0, KUSIZE - addu t1, t0, t3 - addiu t1, t1, -ICACHE_LINESIZE -4: - CACHE((C_IINV|CACH_PI), (t0)) - .set noreorder - bltu t0, t1, 4b - addiu t0, t0, ICACHE_LINESIZE - .set reorder - - jr ra - -END(osInvalICache) diff --git a/lib/ultralib/src/os/jammesg.c b/lib/ultralib/src/os/jammesg.c deleted file mode 100644 index cef68da..0000000 --- a/lib/ultralib/src/os/jammesg.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" - -s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) { - register u32 saveMask; - -#ifdef _DEBUG - if ((flag != OS_MESG_NOBLOCK) && (flag != OS_MESG_BLOCK)) { - __osError(ERR_OSJAMMESG, 1, flag); - return -1; - } -#endif - - saveMask = __osDisableInt(); - - while (mq->validCount >= mq->msgCount) { - if (flag == OS_MESG_BLOCK) { - __osRunningThread->state = OS_STATE_WAITING; - __osEnqueueAndYield(&mq->fullqueue); - } else { - __osRestoreInt(saveMask); - return -1; - } - } - - mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount; - mq->msg[mq->first] = msg; - mq->validCount++; - - if (mq->mtqueue->next != NULL) { - osStartThread(__osPopThread(&mq->mtqueue)); - } - - __osRestoreInt(saveMask); - return 0; -} diff --git a/lib/ultralib/src/os/maptlb.s b/lib/ultralib/src/os/maptlb.s deleted file mode 100644 index 20125b6..0000000 --- a/lib/ultralib/src/os/maptlb.s +++ /dev/null @@ -1,111 +0,0 @@ -#include "PR/ultraerror.h" -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -#define index a0 -#define pm a1 -#define vaddr a2 -#define evenpaddr a3 -#define oddpaddr 16(sp) -#define asid 20(sp) -.text -.set noreorder -LEAF(osMapTLB) -#if defined (_DEBUG) && defined (__sgi) - bgez index, 1f - nop - b 2f - nop -1: - li t0, 0x1F -.set noat - slt AT, index, t0 - bnez AT, 3f - nop -.set at -2: - move a2, a0 - li a0, ERR_OSMAPTLB_INDEX - li a1, 1 - j __osError - nop - -3: - lw t0, asid - li t1, -1 -.set noat - slt AT, t0, t1 - beqz AT, 4f - nop -.set at - b 5f - nop -4: - li t1, 0xFF -.set noat - slt AT, t1, t0 - beqz AT, 6f - nop -.set at -5: - move a2, t0 - li a0, ERR_OSMAPTLB_ASID - li a1, 1 - j __osError - nop -6: -.set reorder -#endif - STAY2(mfc0 t0, C0_ENTRYHI) - STAY2(mtc0 index, C0_INX) - STAY2(mtc0 pm, C0_PAGEMASK) -.set noreorder - lw t1, asid - beq t1, -1, 7f - li ta0, TLBLO_G - li t2, TLBLO_NONCOHRNT | TLBLO_D | TLBLO_V - b 8f - or vaddr, vaddr, t1 -.set reorder - -7: - li t2, TLBLO_NONCOHRNT | TLBLO_D | TLBLO_V | TLBLO_G -8: - STAY2(mtc0 vaddr, C0_ENTRYHI) - beq evenpaddr, -1, 9f - #nop - srl t3, evenpaddr, TLBLO_PFNSHIFT - or t3, t3, t2 - STAY2(mtc0 t3, C0_ENTRYLO0) - b 10f - #nop -9: - STAY2(mtc0 ta0, C0_ENTRYLO0) -10: - lw t3, oddpaddr - beq t3, -1, 11f - #nop - srl t3, t3, TLBLO_PFNSHIFT - or t3, t3, t2 - STAY2(mtc0 t3, C0_ENTRYLO1) - b 12f - #nop -11: - STAY2(mtc0 ta0, C0_ENTRYLO1) - bne evenpaddr, -1, 12f - #nop - li t3, K0BASE - STAY2(mtc0 t3, C0_ENTRYHI) -12: - .set noreorder - nop - tlbwi - nop - nop - nop - nop - STAY2(mtc0 t0, C0_ENTRYHI) - jr ra - #nop -END(osMapTLB) diff --git a/lib/ultralib/src/os/maptlbrdb.s b/lib/ultralib/src/os/maptlbrdb.s deleted file mode 100644 index c004362..0000000 --- a/lib/ultralib/src/os/maptlbrdb.s +++ /dev/null @@ -1,30 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -.set noreorder -LEAF(osMapTLBRdb) - mfc0 t0, C0_ENTRYHI - li t1, 31 - mtc0 t1, C0_INX - mtc0 zero, C0_PAGEMASK /*4k*/ - li t2, TLBLO_UNCACHED | TLBLO_D | TLBLO_V | TLBLO_G - li t1, K2BASE - mtc0 t1, C0_ENTRYHI - li t1, KUSIZE - srl t3, t1,TLBLO_PFNSHIFT - or t3, t3,t2 - mtc0 t3, C0_ENTRYLO0 - li t1, TLBLO_G - mtc0 t1, C0_ENTRYLO1 - nop - tlbwi - nop - nop - nop - nop - mtc0 t0, C0_ENTRYHI - jr ra - nop -END(osMapTLBRdb) diff --git a/lib/ultralib/src/os/osint.h b/lib/ultralib/src/os/osint.h deleted file mode 100644 index b73b609..0000000 --- a/lib/ultralib/src/os/osint.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef _OSINT_H -#define _OSINT_H -#include "PR/os_internal.h" -typedef struct __OSEventState -{ - OSMesgQueue *messageQueue; - OSMesg message; -} __OSEventState; -extern struct __osThreadTail -{ - OSThread *next; - OSPri priority; -} __osThreadTail; - -//maybe should be in exceptasm.h? -extern void __osEnqueueAndYield(OSThread **); -extern void __osDequeueThread(OSThread **, OSThread *); -extern void __osEnqueueThread(OSThread **, OSThread *); -extern OSThread *__osPopThread(OSThread **); -extern void __osDispatchThread(void); -extern void __osCleanupThread(void); - -extern void __osSetTimerIntr(OSTime); -extern OSTime __osInsertTimer(OSTimer *); -extern void __osTimerInterrupt(void); -extern u32 __osProbeTLB(void *); -extern int __osSpDeviceBusy(void); - -extern OSThread *__osRunningThread; -extern OSThread *__osActiveQueue; -extern OSThread *__osFaultedThread; -extern OSThread *__osRunQueue; - -extern OSTimer *__osTimerList; -extern OSTimer __osBaseTimer; -extern OSTime __osCurrentTime; -extern u32 __osBaseCounter; -extern u32 __osViIntrCount; -extern u32 __osTimerCounter; -extern u32 __osShutdown; - -extern OSMesgQueue __osProfTimerQ; -extern OSProf *__osProfileList; -extern OSProf *__osProfileListEnd; -extern u32 __osProfileOverflowBin; - -extern __OSEventState __osEventStateTab[]; - - -extern void __osTimerServicesInit(void); -extern s32 __osAiDeviceBusy(void); -extern int __osDpDeviceBusy(void); - -#ifndef _FINALROM -extern void* __printfunc; -#endif - -#endif diff --git a/lib/ultralib/src/os/parameters.s b/lib/ultralib/src/os/parameters.s deleted file mode 100644 index 450af31..0000000 --- a/lib/ultralib/src/os/parameters.s +++ /dev/null @@ -1,17 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -ABS(leoBootID, 0x800001a0) -ABS(osTvType, 0x80000300) -ABS(osRomType, 0x80000304) -ABS(osRomBase, 0x80000308) -ABS(osResetType, 0x8000030c) -ABS(osCicId, 0x80000310) -ABS(osVersion, 0x80000314) -ABS(osMemSize, 0x80000318) -ABS(osAppNMIBuffer, 0x8000031c) - -.space 0x60 -/* padded to 0x60 in the object file */ diff --git a/lib/ultralib/src/os/physicaltovirtual.c b/lib/ultralib/src/os/physicaltovirtual.c deleted file mode 100644 index 6fbb9c3..0000000 --- a/lib/ultralib/src/os/physicaltovirtual.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/R4300.h" - -void* osPhysicalToVirtual(u32 addr) { - return (void*)PHYS_TO_K0(addr); -} diff --git a/lib/ultralib/src/os/probetlb.s b/lib/ultralib/src/os/probetlb.s deleted file mode 100644 index 237db23..0000000 --- a/lib/ultralib/src/os/probetlb.s +++ /dev/null @@ -1,54 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -.set noreorder -LEAF(__osProbeTLB) - mfc0 t0, C0_ENTRYHI - andi t1, t0, TLBHI_PIDMASK - and t2, a0, -8192 # This also works: (TLBHI_VPN2MASK << 32) >> 32 - or t1, t1, t2 - mtc0 t1, C0_ENTRYHI - nop - nop - nop - tlbp - nop - nop - mfc0 t3, C0_INX - and t3, t3, TLBINX_PROBE - bnez t3, 3f - nop - tlbr - nop - nop - nop - mfc0 t3, C0_PAGEMASK - addi t3, t3, DCACHE_SIZE - srl t3, t3, 0x1 - and ta0, t3, a0 - bnez ta0, 1f - addi t3, t3,-1 - mfc0 v0, C0_ENTRYLO0 - b 2f - nop -1: - mfc0 v0, C0_ENTRYLO1 -2: - andi ta1, v0,TLBLO_V - beqz ta1, 3f - nop - and v0, v0, TLBLO_PFNMASK - sll v0, v0, TLBLO_PFNSHIFT - and ta1, a0, t3 - add v0, v0, ta1 - b 4f - nop -3: - li v0, -1 -4: - mtc0 t0, C0_ENTRYHI - jr ra - nop -END(__osProbeTLB) diff --git a/lib/ultralib/src/os/rdbsend.c b/lib/ultralib/src/os/rdbsend.c deleted file mode 100644 index 0dc111e..0000000 --- a/lib/ultralib/src/os/rdbsend.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rdb.h" -#include "PR/R4300.h" - -#ifndef _FINALROM -extern rdbPacket* __osRdb_IP6_Data; -extern u32 __osRdb_IP6_Size; -extern u32 __osRdb_IP6_Ct; -extern u32 __osRdb_IP6_CurWrite; - -u32 __osRdb_IP6_Empty = 1; - -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - -u32 __osRdbSend(u8* buf, u32 size, u32 type) { - rdbPacket* pPtr; - rdbPacket pkt; - u32 len; - u32 c; - u32 inCt = 0; - u32 needFirst = 0; - u32 mask; - u32 sent = 0; - - mask = __osDisableInt(); - - if (__osRdb_IP6_Empty != 0) { - __osRdb_IP6_Empty = 0; - pkt.type = type; - - len = MIN(size, sizeof(pkt.buf)); - - pkt.length = len; - - c = 0; - while (c < len) { - pkt.buf[c++] = buf[inCt++]; - } - - size -= len; - sent = len; - needFirst = 1; - } - - while (size != 0 && __osRdb_IP6_Ct < __osRdb_IP6_Size) { - len = MIN(size, sizeof(pPtr->buf)); - - pPtr = &__osRdb_IP6_Data[__osRdb_IP6_CurWrite]; - - pPtr->type = type; - pPtr->length = len; - - c = 0; - while (c < len) { - pPtr->buf[c++] = buf[inCt++]; - } - - __osRdb_IP6_CurWrite++; - if (__osRdb_IP6_CurWrite >= __osRdb_IP6_Size) { - __osRdb_IP6_CurWrite = 0; - } - - __osRdb_IP6_Ct++; - size -= len; - sent += len; - } - - if (needFirst) { - *(u32*)RDB_BASE_REG = *(u32*)&pkt; - } - __osRestoreInt(mask); - - return sent; -} - -#endif diff --git a/lib/ultralib/src/os/recvmesg.c b/lib/ultralib/src/os/recvmesg.c deleted file mode 100644 index 043ed21..0000000 --- a/lib/ultralib/src/os/recvmesg.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" - -s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags) { - register u32 saveMask; - -#ifdef _DEBUG - if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { - __osError(ERR_OSRECVMESG, 1, flags); - return -1; - } -#endif - - saveMask = __osDisableInt(); - - while (MQ_IS_EMPTY(mq)) { - if (flags == OS_MESG_NOBLOCK) { - __osRestoreInt(saveMask); - return -1; - } else { - __osRunningThread->state = OS_STATE_WAITING; - __osEnqueueAndYield(&mq->mtqueue); - } - } - - if (msg != NULL) { - *msg = mq->msg[mq->first]; - } - - mq->first = (mq->first + 1) % mq->msgCount; - mq->validCount--; - - if (mq->fullqueue->next != NULL) { - osStartThread(__osPopThread(&mq->fullqueue)); - } - - __osRestoreInt(saveMask); - return 0; -} diff --git a/lib/ultralib/src/os/resetglobalintmask.c b/lib/ultralib/src/os/resetglobalintmask.c deleted file mode 100644 index 780da7c..0000000 --- a/lib/ultralib/src/os/resetglobalintmask.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" - -void __osResetGlobalIntMask(OSHWIntr mask) { - register u32 saveMask = __osDisableInt(); - - __OSGlobalIntMask &= ~(mask & ~OS_IM_RCP); - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/sendmesg.c b/lib/ultralib/src/os/sendmesg.c deleted file mode 100644 index 19cf3de..0000000 --- a/lib/ultralib/src/os/sendmesg.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" - -s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags) { - register u32 saveMask; - register s32 last; - -#ifdef _DEBUG - if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { - __osError(ERR_OSSENDMESG, 1, flags); - return -1; - } -#endif - - saveMask = __osDisableInt(); - - while (MQ_IS_FULL(mq)) { - if (flags == OS_MESG_BLOCK) { - __osRunningThread->state = OS_STATE_WAITING; - __osEnqueueAndYield(&mq->fullqueue); - } else { - __osRestoreInt(saveMask); - return -1; - } - } - - last = (mq->first + mq->validCount) % mq->msgCount; - mq->msg[last] = msg; - mq->validCount++; - - if (mq->mtqueue->next != NULL) { - osStartThread(__osPopThread(&mq->mtqueue)); - } - - __osRestoreInt(saveMask); - return 0; -} diff --git a/lib/ultralib/src/os/setcause.s b/lib/ultralib/src/os/setcause.s deleted file mode 100644 index 52e4950..0000000 --- a/lib/ultralib/src/os/setcause.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osSetCause) - STAY2(mtc0 a0, C0_CAUSE) - jr ra -END(__osSetCause) diff --git a/lib/ultralib/src/os/setcompare.s b/lib/ultralib/src/os/setcompare.s deleted file mode 100644 index dec29a2..0000000 --- a/lib/ultralib/src/os/setcompare.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osSetCompare) - STAY2(mtc0 a0, C0_COMPARE) - jr ra -END(__osSetCompare) diff --git a/lib/ultralib/src/os/setconfig.s b/lib/ultralib/src/os/setconfig.s deleted file mode 100644 index 4f062bd..0000000 --- a/lib/ultralib/src/os/setconfig.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osSetConfig) - STAY2(mtc0 a0, C0_CONFIG) - jr ra -END(__osSetConfig) diff --git a/lib/ultralib/src/os/setcount.s b/lib/ultralib/src/os/setcount.s deleted file mode 100644 index f94f1d2..0000000 --- a/lib/ultralib/src/os/setcount.s +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osSetCount) - STAY2(mtc0 a0, C0_COUNT) - jr ra -END(__osSetCount) diff --git a/lib/ultralib/src/os/seterrorhandler.c b/lib/ultralib/src/os/seterrorhandler.c deleted file mode 100644 index 4e839e8..0000000 --- a/lib/ultralib/src/os/seterrorhandler.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/ultraerror.h" - -extern OSErrorHandler __osErrorHandler; - -OSErrorHandler osSetErrorHandler(OSErrorHandler handler) { - OSErrorHandler oldHandler = __osErrorHandler; - - __osErrorHandler = handler; - return oldHandler; -} diff --git a/lib/ultralib/src/os/seteventmesg.c b/lib/ultralib/src/os/seteventmesg.c deleted file mode 100644 index f59308c..0000000 --- a/lib/ultralib/src/os/seteventmesg.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" - -__OSEventState __osEventStateTab[OS_NUM_EVENTS] ALIGNED(8); -#if BUILD_VERSION >= VERSION_J -u32 __osPreNMI = FALSE; -#endif - -void osSetEventMesg(OSEvent event, OSMesgQueue* mq, OSMesg msg) { - register u32 saveMask; - __OSEventState* es; - -#ifdef _DEBUG - if (event >= OS_NUM_EVENTS) { - __osError(ERR_OSSETEVENTMESG, 1, event); - return; - } -#endif - - saveMask = __osDisableInt(); - - es = &__osEventStateTab[event]; - - es->messageQueue = mq; - es->message = msg; - -#if BUILD_VERSION >= VERSION_J - if (event == OS_EVENT_PRENMI) { - if (__osShutdown && !__osPreNMI) { - osSendMesg(mq, msg, OS_MESG_NOBLOCK); - } - __osPreNMI = TRUE; - } -#endif - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/setfpccsr.s b/lib/ultralib/src/os/setfpccsr.s deleted file mode 100644 index f288437..0000000 --- a/lib/ultralib/src/os/setfpccsr.s +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osSetFpcCsr) - STAY2(cfc1 v0, fcr31) - STAY2(ctc1 a0, fcr31) - jr ra -END(__osSetSR) # @bug: Should be __osGetFpcCsr diff --git a/lib/ultralib/src/os/setglobalintmask.c b/lib/ultralib/src/os/setglobalintmask.c deleted file mode 100644 index a718980..0000000 --- a/lib/ultralib/src/os/setglobalintmask.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" - -void __osSetGlobalIntMask(OSHWIntr mask) { - register u32 saveMask = __osDisableInt(); - - __OSGlobalIntMask |= mask; - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/sethwinterrupt.c b/lib/ultralib/src/os/sethwinterrupt.c deleted file mode 100644 index 9aafe1b..0000000 --- a/lib/ultralib/src/os/sethwinterrupt.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "PR/os_internal.h" - -// A stack frame was added to hardware interrupt handlers in 2.0J -#if BUILD_VERSION >= VERSION_J - -struct __osHwInt { - s32 (*handler)(void); - void* stackEnd; -}; - -extern struct __osHwInt __osHwIntTable[]; - -void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* stackEnd) { - register u32 saveMask = __osDisableInt(); - - __osHwIntTable[interrupt].handler = handler; - __osHwIntTable[interrupt].stackEnd = stackEnd; - __osRestoreInt(saveMask); -} - -#else - -extern struct s32 (*__osHwIntTable[])(void); - -void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void)) { - register u32 saveMask = __osDisableInt(); - - __osHwIntTable[interrupt] = handler; - __osRestoreInt(saveMask); -} - -#endif diff --git a/lib/ultralib/src/os/setintmask.s b/lib/ultralib/src/os/setintmask.s deleted file mode 100644 index f19ed17..0000000 --- a/lib/ultralib/src/os/setintmask.s +++ /dev/null @@ -1,124 +0,0 @@ -#include "PR/R4300.h" -#include "PR/rcp.h" -#include "PR/os.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -#define MI_INTR_MASK ((1 << 6) - 1) - -.globl __osRcpImTable - -.text -.set noreorder -LEAF(osSetIntMask) - mfc0 ta0, C0_SR - - andi v0, ta0, OS_IM_CPU - - la t0, __OSGlobalIntMask - lw t3, 0(t0) - - xor t0, t3,-1 - andi t0, t0,(SR_IMASK) - or v0, v0,t0 - - lw t2, PHYS_TO_K1(MI_INTR_MASK_REG) - beqz t2, 1f - srl t1, t3,0x10 - - xor t1, t1,-1 - andi t1, t1, MI_INTR_MASK - or t2, t2,t1 -1: - sll t2, t2,0x10 - or v0, v0,t2 - - and t0, a0, MI_INTR_MASK<<0x10 - and t0, t0,t3 - srl t0, t0,0xf - lhu t2, __osRcpImTable(t0) - sw t2, PHYS_TO_K1(MI_INTR_MASK_REG) - - andi t0, a0, OS_IM_CPU - andi t1, t3, SR_IMASK - and t0, t0,t1 - - and ta0, ta0, ~SR_IMASK - or ta0, ta0,t0 - - mtc0 ta0, C0_SR - nop - nop - jr ra - nop -END(osSetIntMask) - -.rdata -EXPORT(__osRcpImTable) -/* LUT to convert between MI_INTR and MI_INTR_MASK */ -/* MI_INTR is status for each interrupt whereas */ -/* MI_INTR_MASK has seperate bits for set/clr */ -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP -.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP diff --git a/lib/ultralib/src/os/setpiinterrupt.c b/lib/ultralib/src/os/setpiinterrupt.c deleted file mode 100644 index 1af72b5..0000000 --- a/lib/ultralib/src/os/setpiinterrupt.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "PR/os_internal.h" - -struct __osHwInt { - s32 (*handler)(void); - void* stackEnd; -}; - -extern struct __osHwInt __osPiIntTable; - -void __osSetPIIntrRoutine(struct __osHwInt* ir) { - register u32 saveMask = __osDisableInt(); - - __osPiIntTable.handler = ir->handler; - __osPiIntTable.stackEnd = ir->stackEnd; - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/setsr.s b/lib/ultralib/src/os/setsr.s deleted file mode 100644 index d7d98fa..0000000 --- a/lib/ultralib/src/os/setsr.s +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osSetSR) - STAY2(mtc0 a0, C0_SR) - NOP - jr ra -END(__osSetSR) diff --git a/lib/ultralib/src/os/setthreadpri.c b/lib/ultralib/src/os/setthreadpri.c deleted file mode 100644 index d836323..0000000 --- a/lib/ultralib/src/os/setthreadpri.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" - -void osSetThreadPri(OSThread* t, OSPri pri) { - register u32 saveMask; - -#ifdef _DEBUG - if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { - __osError(ERR_OSSETTHREADPRI, 1, pri); - return; - } -#endif - - saveMask = __osDisableInt(); - - if (t == NULL) { - t = __osRunningThread; - } - - if (t->priority != pri) { - t->priority = pri; - - if (t != __osRunningThread && t->state != OS_STATE_STOPPED) { - __osDequeueThread(t->queue, t); - __osEnqueueThread(t->queue, t); - } - - if (__osRunningThread->priority < __osRunQueue->priority) { - __osRunningThread->state = OS_STATE_RUNNABLE; - __osEnqueueAndYield(&__osRunQueue); - } - } - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/settime.c b/lib/ultralib/src/os/settime.c deleted file mode 100644 index b7d14e3..0000000 --- a/lib/ultralib/src/os/settime.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" -#include "../io/viint.h" - -void osSetTime(OSTime time) { - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSSETTIME, 0); - return; - } -#endif - - __osCurrentTime = time; -} diff --git a/lib/ultralib/src/os/settimer.c b/lib/ultralib/src/os/settimer.c deleted file mode 100644 index 252f63c..0000000 --- a/lib/ultralib/src/os/settimer.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" -#include "../io/viint.h" - -int osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg) { - OSTime time; -#if BUILD_VERSION >= VERSION_K - OSTimer* next; - u32 count; - u32 value; - u32 saveMask; -#endif - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSSETTIMER, 0); - return 0; - } -#endif - - t->next = NULL; - t->prev = NULL; - t->interval = interval; - t->value = (countdown != 0) ? countdown : interval; - t->mq = mq; - t->msg = msg; - -#if BUILD_VERSION >= VERSION_K - saveMask = __osDisableInt(); - if (__osTimerList->next == __osTimerList) { - - } else { - next = __osTimerList->next; - count = osGetCount(); - value = count - __osTimerCounter; - - if (value < next->value) { - next->value -= value; - } else { - next->value = 1; - } - } - - time = __osInsertTimer(t); - __osSetTimerIntr(__osTimerList->next->value); - __osRestoreInt(saveMask); -#else - time = __osInsertTimer(t); - if (__osTimerList->next == t) { - __osSetTimerIntr(time); - } -#endif - - return 0; -} diff --git a/lib/ultralib/src/os/settlbasid.s b/lib/ultralib/src/os/settlbasid.s deleted file mode 100644 index 13a17e8..0000000 --- a/lib/ultralib/src/os/settlbasid.s +++ /dev/null @@ -1,32 +0,0 @@ -#include "PR/ultraerror.h" -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(osSetTLBASID) -#if defined (_DEBUG) && defined (__sgi) -.set noreorder - bgez a0, 1f - nop - b 2f - nop -1: - li t1, 0xFF -.set noat - slt AT, t1, a0 - beqz AT, 3f - nop -.set at -2: - move a2, a0 - li a0, ERR_OSSETTLBASID - li a1, 1 - j __osError - nop -3: -.set reorder -#endif - STAY2(mtc0 a0, C0_ENTRYHI) - jr ra -END(osSetTLBASID) diff --git a/lib/ultralib/src/os/setwatchlo.s b/lib/ultralib/src/os/setwatchlo.s deleted file mode 100644 index 91cc58e..0000000 --- a/lib/ultralib/src/os/setwatchlo.s +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(__osSetWatchLo) - STAY2(mtc0 a0, C0_WATCHLO) - NOP - jr ra -END(__osSetWatchLo) diff --git a/lib/ultralib/src/os/startthread.c b/lib/ultralib/src/os/startthread.c deleted file mode 100644 index 2ce1546..0000000 --- a/lib/ultralib/src/os/startthread.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" - -void osStartThread(OSThread* t) { - register u32 saveMask = __osDisableInt(); - - switch (t->state) { - case OS_STATE_WAITING: - t->state = OS_STATE_RUNNABLE; - __osEnqueueThread(&__osRunQueue, t); - break; - case OS_STATE_STOPPED: - if (t->queue == NULL || t->queue == &__osRunQueue) { - t->state = OS_STATE_RUNNABLE; - __osEnqueueThread(&__osRunQueue, t); - } else { - t->state = OS_STATE_WAITING; - __osEnqueueThread(t->queue, t); - __osEnqueueThread(&__osRunQueue, __osPopThread(t->queue)); - } - break; -#ifdef _DEBUG - default: - __osError(ERR_OSSTARTTHREAD, 0); - __osRestoreInt(saveMask); - return; -#endif - } - - if (__osRunningThread == NULL) { - __osDispatchThread(); - } else if (__osRunningThread->priority < __osRunQueue->priority) { - __osRunningThread->state = OS_STATE_RUNNABLE; - __osEnqueueAndYield(&__osRunQueue); - } - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/stopthread.c b/lib/ultralib/src/os/stopthread.c deleted file mode 100644 index 9a51652..0000000 --- a/lib/ultralib/src/os/stopthread.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -void osStopThread(OSThread* t) { - register u32 saveMask = __osDisableInt(); - register u16 state; - - state = (t == NULL) ? OS_STATE_RUNNING: t->state; - - switch (state) { - case OS_STATE_RUNNING: - __osRunningThread->state = OS_STATE_STOPPED; - __osEnqueueAndYield(NULL); - break; - case OS_STATE_RUNNABLE: - case OS_STATE_WAITING: - t->state = OS_STATE_STOPPED; - __osDequeueThread(t->queue, t); - break; - } - - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/os/stoptimer.c b/lib/ultralib/src/os/stoptimer.c deleted file mode 100644 index b6db1c1..0000000 --- a/lib/ultralib/src/os/stoptimer.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "osint.h" -#include "../io/viint.h" - -int osStopTimer(OSTimer* t) { - register u32 savedMask; - OSTimer* timep; - -#ifdef _DEBUG - if (!__osViDevMgr.active) { - __osError(ERR_OSSTOPTIMER, 0); - return 0; - } -#endif - - if (t->next == NULL) { - return -1; - } - - savedMask = __osDisableInt(); - timep = t->next; - - if (timep != __osTimerList) { - timep->value += t->value; - } - - t->prev->next = t->next; - t->next->prev = t->prev; - t->next = NULL; - t->prev = NULL; - - if (__osTimerList->next == __osTimerList) { - __osSetCompare(0); - } - - __osRestoreInt(savedMask); - return 0; -} diff --git a/lib/ultralib/src/os/syncputchars.c b/lib/ultralib/src/os/syncputchars.c deleted file mode 100644 index d2d5332..0000000 --- a/lib/ultralib/src/os/syncputchars.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rdb.h" -#include "PR/rcp.h" -#include "PR/R4300.h" - -unsigned int __osRdbSendMessage = 0; -unsigned int __osRdbWriteOK = 1; - -void __osSyncPutChars(int type, int length, const char* buf) { - rdbPacket packet; - int i; - u32 mask; - - packet.type = type; - packet.length = length; - - for (i = 0; i < length; i++) { - packet.buf[i] = buf[i]; - } - - while (!__osAtomicDec(&__osRdbWriteOK)) { - ; - } - - mask = __osDisableInt(); - *(vu32*)RDB_BASE_REG = *(vu32*)&packet; - - while (!(__osGetCause() & CAUSE_IP6)) { - ; - } - - *(vu32*)RDB_READ_INTR_REG = 0; - __osRdbWriteOK++; - __osRestoreInt(mask); -} diff --git a/lib/ultralib/src/os/testhost.c b/lib/ultralib/src/os/testhost.c deleted file mode 100644 index c134317..0000000 --- a/lib/ultralib/src/os/testhost.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "PR/os_internal.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif diff --git a/lib/ultralib/src/os/thread.c b/lib/ultralib/src/os/thread.c deleted file mode 100644 index 9a4a141..0000000 --- a/lib/ultralib/src/os/thread.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -struct __osThreadTail __osThreadTail = { NULL, -1 }; -OSThread* __osRunQueue = (OSThread*)&__osThreadTail; -OSThread* __osActiveQueue = (OSThread*)&__osThreadTail; -OSThread* __osRunningThread = { 0 }; -OSThread* __osFaultedThread = { 0 }; - -void __osDequeueThread(register OSThread** queue, register OSThread* t) { - register OSThread* pred; - register OSThread* succ; - - pred = (OSThread*)queue; - succ = pred->next; - - while (succ != NULL) { - if (succ == t) { - pred->next = t->next; -#ifdef _DEBUG - t->next = NULL; -#endif - return; - } - pred = succ; - succ = pred->next; - } -} diff --git a/lib/ultralib/src/os/threadasm.h b/lib/ultralib/src/os/threadasm.h deleted file mode 100644 index dfd91b6..0000000 --- a/lib/ultralib/src/os/threadasm.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _THREADASM_H_ -#define _THREADASM_H_ - -/* Offsets of members in the OSThread struct */ -#define THREAD_NEXT 0 -#define THREAD_PRI 4 -#define THREAD_QUEUE 8 -#define THREAD_TLNEXT 12 -#define THREAD_STATE 16 -#define THREAD_FLAGS 18 -#define THREAD_ID 20 -#define THREAD_FP 24 -#define THREAD_GP1 32 -#define THREAD_GP2 40 -#define THREAD_GP3 48 -#define THREAD_GP4 56 -#define THREAD_GP5 64 -#define THREAD_GP6 72 -#define THREAD_GP7 80 -#define THREAD_GP8 88 -#define THREAD_GP9 96 -#define THREAD_GP10 104 -#define THREAD_GP11 112 -#define THREAD_GP12 120 -#define THREAD_GP13 128 -#define THREAD_GP14 136 -#define THREAD_GP15 144 -#define THREAD_GP16 152 -#define THREAD_GP17 160 -#define THREAD_GP18 168 -#define THREAD_GP19 176 -#define THREAD_GP20 184 -#define THREAD_GP21 192 -#define THREAD_GP22 200 -#define THREAD_GP23 208 -#define THREAD_GP24 216 -#define THREAD_GP25 224 -/* k0 and k1 are reserved for the kernel */ -#define THREAD_GP28 232 -#define THREAD_GP29 240 -#define THREAD_GP30 248 -#define THREAD_GP31 256 -#define THREAD_LO 264 -#define THREAD_HI 272 -#define THREAD_SR 280 -#define THREAD_PC 284 -#define THREAD_CAUSE 288 -#define THREAD_BADVADDR 292 -#define THREAD_RCP 296 -#define THREAD_FPCSR 300 -#define THREAD_FP0 304 -#define THREAD_FP2 312 -#define THREAD_FP4 320 -#define THREAD_FP6 328 -#define THREAD_FP8 336 -#define THREAD_FP10 344 -#define THREAD_FP12 352 -#define THREAD_FP14 360 -#define THREAD_FP16 368 -#define THREAD_FP18 376 -#define THREAD_FP20 384 -#define THREAD_FP22 392 -#define THREAD_FP24 400 -#define THREAD_FP26 408 -#define THREAD_FP28 416 -#define THREAD_FP30 424 - -#endif diff --git a/lib/ultralib/src/os/timerintr.c b/lib/ultralib/src/os/timerintr.c deleted file mode 100644 index 10dae50..0000000 --- a/lib/ultralib/src/os/timerintr.c +++ /dev/null @@ -1,141 +0,0 @@ -#include "macros.h" -#include "PR/os_internal.h" -#include "osint.h" - -OSTime __osCurrentTime; -u32 __osBaseCounter; -u32 __osViIntrCount; -u32 __osTimerCounter; -OSTimer __osBaseTimer; -OSTimer* __osTimerList = &__osBaseTimer; - -#ifndef _FINALROM -OSMesgQueue __osProfTimerQ ALIGNED(8); -OSProf* __osProfileList; -OSProf* __osProfileListEnd; -u32 __osProfileOverflowBin; -#endif - -void __osTimerServicesInit(void) { - __osCurrentTime = 0; - __osBaseCounter = 0; - __osViIntrCount = 0; - __osTimerList->next = __osTimerList->prev = __osTimerList; - __osTimerList->interval = __osTimerList->value = 0; - __osTimerList->mq = NULL; - __osTimerList->msg = 0; -} - -void __osTimerInterrupt(void) { - OSTimer* t; - u32 count; - u32 elapsed_cycles; - -#ifndef _FINALROM - u32 pc; - s32 offset; - OSProf* prof = __osProfileList; -#endif - - if (__osTimerList->next == __osTimerList) { - return; - } - for (;;) { - t = __osTimerList->next; - - if (t == __osTimerList) { - __osSetCompare(0); - __osTimerCounter = 0; - break; - } - - count = osGetCount(); - elapsed_cycles = count - __osTimerCounter; - __osTimerCounter = count; - - if (elapsed_cycles < t->value) { - t->value -= elapsed_cycles; - __osSetTimerIntr(t->value); - break; - } - - t->prev->next = t->next; - t->next->prev = t->prev; - t->next = NULL; - t->prev = NULL; - - if (t->mq != NULL) { -#ifdef _FINALROM - osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); - } -#else - if (t->mq != &__osProfTimerQ) { - osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); - } else { - pc = __osRunQueue->context.pc; - for (prof = __osProfileList; prof < __osProfileListEnd; prof++) { - offset = pc - (u32)prof->text_start; - - if (offset >= 0) { - if ((s32)prof->text_end - (s32)pc > 0) { - (*(u16*)(u32)((offset >> 2) + prof->histo_base))++; - goto __ProfDone; - } - } - } - - __osProfileOverflowBin++; - } - } -#endif - - __ProfDone: - - if (t->interval != 0) { - t->value = t->interval; - __osInsertTimer(t); - } - } -} - -void __osSetTimerIntr(OSTime tim) { - OSTime NewTime; - u32 savedMask; - -#if BUILD_VERSION >= VERSION_K - if (tim < 468) { - tim = 468; - } -#endif - - savedMask = __osDisableInt(); - __osTimerCounter = osGetCount(); - NewTime = __osTimerCounter + tim; - __osSetCompare(NewTime); - __osRestoreInt(savedMask); -} - -OSTime __osInsertTimer(OSTimer* t) { - OSTimer* timep; - OSTime tim; - u32 savedMask = __osDisableInt(); - - timep = __osTimerList->next; - tim = t->value; - for (; timep != __osTimerList && tim > timep->value; timep = timep->next) { - tim -= timep->value; - } - - t->value = tim; - - if (timep != __osTimerList) { - timep->value -= tim; - } - - t->next = timep; - t->prev = timep->prev; - timep->prev->next = t; - timep->prev = t; - __osRestoreInt(savedMask); - return tim; -} diff --git a/lib/ultralib/src/os/unmaptlb.s b/lib/ultralib/src/os/unmaptlb.s deleted file mode 100644 index 362fd1e..0000000 --- a/lib/ultralib/src/os/unmaptlb.s +++ /dev/null @@ -1,45 +0,0 @@ -#include "PR/ultraerror.h" -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -.set noreorder -LEAF(osUnmapTLB) -#if defined (_DEBUG) && defined (__sgi) - bgez a0, 1f - nop - b 2f - nop -1: - li t0, 0x1F -.set noat - slt AT, a0, t0 - bnez AT, 3f - nop -.set at -2: - move a2, a0 - li a0, ERR_OSUNMAPTLB - li a1, 1 - j __osError - nop -3: -#endif - mfc0 t0, C0_ENTRYHI - mtc0 a0, C0_INX - li t1, K0BASE - mtc0 t1, C0_ENTRYHI - mtc0 zero, C0_ENTRYLO0 - mtc0 zero, C0_ENTRYLO1 - nop - tlbwi - nop - nop - nop - nop - mtc0 t0, C0_ENTRYHI - jr ra - nop -END(osUnmapTLB) - diff --git a/lib/ultralib/src/os/unmaptlball.s b/lib/ultralib/src/os/unmaptlball.s deleted file mode 100644 index 6d4b264..0000000 --- a/lib/ultralib/src/os/unmaptlball.s +++ /dev/null @@ -1,26 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -.set noreorder -LEAF(osUnmapTLBAll) - mfc0 t0, C0_ENTRYHI - li t1, NTLBENTRIES-1 /* last reserved for rdb */ - li t2, KUSIZE - mtc0 t2, C0_ENTRYHI - mtc0 zero, C0_ENTRYLO0 - mtc0 zero, C0_ENTRYLO1 -1: - mtc0 t1, C0_INX - nop - tlbwi - nop - nop - addi t1, t1,-1 - bgez t1, 1b - nop - mtc0 t0, C0_ENTRYHI - jr ra - nop -END(osUnmapTLBAll) diff --git a/lib/ultralib/src/os/virtualtophysical.c b/lib/ultralib/src/os/virtualtophysical.c deleted file mode 100644 index 553fe68..0000000 --- a/lib/ultralib/src/os/virtualtophysical.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/R4300.h" -#include "osint.h" - -u32 osVirtualToPhysical(void* addr) { - if (IS_KSEG0(addr)) { - return K0_TO_PHYS(addr); - } else if (IS_KSEG1(addr)) { - return K1_TO_PHYS(addr); - } else { - return __osProbeTLB(addr); - } -} diff --git a/lib/ultralib/src/os/writebackdcache.s b/lib/ultralib/src/os/writebackdcache.s deleted file mode 100644 index 5f5b485..0000000 --- a/lib/ultralib/src/os/writebackdcache.s +++ /dev/null @@ -1,35 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(osWritebackDCache) - blez a1, 2f - li t3, DCACHE_SIZE - bgeu a1,t3, 3f - move t0, a0 - addu t1, a0,a1 - bgeu t0, t1, 2f - addiu t1, t1, -DCACHE_LINESIZE - andi t2, t0, DCACHE_LINEMASK - subu t0, t0,t2 -1: - .set noreorder - cache (C_HWB|CACH_PD), (t0) - bltu t0, t1, 1b - addiu t0, t0, DCACHE_LINESIZE - .set reorder -2: - jr ra -3: - li t0, KUSIZE - addu t1, t0,t3 - addiu t1, t1, -DCACHE_LINESIZE -4: - .set noreorder - cache (C_IWBINV|CACH_PD), (t0) - bltu t0, t1, 4b - addiu t0, t0, DCACHE_LINESIZE - .set reorder - jr ra -END(osWritebackDCache) diff --git a/lib/ultralib/src/os/writebackdcacheall.s b/lib/ultralib/src/os/writebackdcacheall.s deleted file mode 100644 index ee8df88..0000000 --- a/lib/ultralib/src/os/writebackdcacheall.s +++ /dev/null @@ -1,18 +0,0 @@ -#include "PR/R4300.h" -#include "sys/asm.h" -#include "sys/regdef.h" - -.text -LEAF(osWritebackDCacheAll) - li t0, KUSIZE - li t2, DCACHE_SIZE - addu t1, t0,t2 - addiu t1, t1, -DCACHE_LINESIZE -1: - .set noreorder - cache (C_IWBINV | CACH_PD), (t0) - bltu t0, t1, 1b - addiu t0, t0, DCACHE_LINESIZE - .set reorder - jr ra -END(osWritebackDCacheAll) diff --git a/lib/ultralib/src/os/yieldthread.c b/lib/ultralib/src/os/yieldthread.c deleted file mode 100644 index 9a4dafb..0000000 --- a/lib/ultralib/src/os/yieldthread.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "PR/os_internal.h" -#include "osint.h" - -void osYieldThread(void) { - register u32 saveMask = __osDisableInt(); - - __osRunningThread->state = OS_STATE_RUNNABLE; - __osEnqueueAndYield(&__osRunQueue); - __osRestoreInt(saveMask); -} diff --git a/lib/ultralib/src/rg/free.c b/lib/ultralib/src/rg/free.c deleted file mode 100644 index c426000..0000000 --- a/lib/ultralib/src/rg/free.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "PR/region.h" -#include "PR/R4300.h" -#include "PR/ultraerror.h" -#include "PR/os_internal.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void osFree(void* region, void* addr) { - register OSRegion* rp = region; - int i; - -#ifdef _DEBUG - assert((region != NULL) && (addr != NULL)); - if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { - __osError(ERR_OSFREE_REGION, 1, region); - return; - } -#endif - - i = ((u8*)addr - rp->r_startBufferAddress) / rp->r_bufferSize; - -#ifdef _DEBUG - if ((i < 0) || (i >= rp->r_bufferCount)) { - __osError(ERR_OSFREE_ADDR, 2, addr, region); - return; - } - - if (((unsigned char*)addr - rp->r_startBufferAddress) % (rp->r_bufferSize) != 0) { - __osError(ERR_OSFREE_ADDR, 2, addr, region); - return; - } -#endif - *(u16*)(&rp->r_startBufferAddress[i * rp->r_bufferSize]) = rp->r_freeList; - rp->r_freeList = i; -} diff --git a/lib/ultralib/src/rg/getbufcount.c b/lib/ultralib/src/rg/getbufcount.c deleted file mode 100644 index d4deeba..0000000 --- a/lib/ultralib/src/rg/getbufcount.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "PR/region.h" -#include "PR/ultraerror.h" -#include "PR/os_internal.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 osGetRegionBufCount(void* region) { - register OSRegion* rp = region; - -#ifdef _DEBUG - assert(rp != NULL); - if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { - __osError(ERR_OSGETREGIONBUFCOUNT, 1, region); - return 0; - } -#endif - return rp->r_bufferCount; -} diff --git a/lib/ultralib/src/rg/getsize.c b/lib/ultralib/src/rg/getsize.c deleted file mode 100644 index 2b1fb90..0000000 --- a/lib/ultralib/src/rg/getsize.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "PR/region.h" -#include "PR/ultraerror.h" -#include "PR/os_internal.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -s32 osGetRegionBufSize(void* region) { - register OSRegion* rp = region; - -#ifdef _DEBUG - assert(rp != NULL); - if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { - __osError(ERR_OSGETREGIONBUFSIZE, 1, region); - return 0; - } -#endif - - return rp->r_bufferSize; -} diff --git a/lib/ultralib/src/rg/malloc.c b/lib/ultralib/src/rg/malloc.c deleted file mode 100644 index 59c0399..0000000 --- a/lib/ultralib/src/rg/malloc.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "PR/region.h" -#include "PR/ultraerror.h" -#include "PR/os_internal.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void* osMalloc(void* region) { - register OSRegion* rp = region; - char* addr; - -#ifdef _DEBUG - assert(rp != NULL); - if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { - __osError(ERR_OSMALLOC, 1, region); - return NULL; - } -#endif - - if (rp->r_freeList == MAX_BUFCOUNT) { - return NULL; - } - - addr = &rp->r_startBufferAddress[rp->r_freeList * rp->r_bufferSize]; - rp->r_freeList = *(u16*)addr; - return addr; -} diff --git a/lib/ultralib/src/rg/printregion.c b/lib/ultralib/src/rg/printregion.c deleted file mode 100644 index 6db8f18..0000000 --- a/lib/ultralib/src/rg/printregion.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "os_version.h" -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J - -#include "../os/osint.h" -#include "PR/rmon.h" -#include "PR/region.h" - -void __osPrintRegion(void* region) { - register OSRegion* rp = region; - int i; - - rmonPrintf("Region = 0x%x\n", rp); - rmonPrintf("\tstartBufferAddress = 0x%x\n", RP(startBufferAddress)); - rmonPrintf("\tendAddress = 0x%x\n", RP(endAddress)); - rmonPrintf("\tbufferSize = %d\n", RP(bufferSize)); - rmonPrintf("\tbufferCount = %d\n", RP(bufferCount)); - rmonPrintf("\tfreeList = %d\n", RP(freeList)); - rmonPrintf("\talignSize = %d\n", RP(alignSize)); - rmonPrintf("\tMemory Header Layout:\n"); - - for (i = 0; i < RP(bufferCount); i++) { - rmonPrintf("\tBuf[%d]:\tAddress: 0x%x Value: 0x%x\n", i, RP(startBufferAddress) + i * RP(bufferSize), - *(u16*)(RP(startBufferAddress) + i * RP(bufferSize))); - } -} - -#endif diff --git a/lib/ultralib/src/rg/region.c b/lib/ultralib/src/rg/region.c deleted file mode 100644 index 377ec9e..0000000 --- a/lib/ultralib/src/rg/region.c +++ /dev/null @@ -1,232 +0,0 @@ -#include "PR/region.h" -#include "PR/ultraerror.h" -#include "os_internal_error.h" -#include "assert.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -void* osCreateRegion(void* startAddress, u32 length, u32 bufferSize, u32 alignSize) { - register OSRegion* rp; - register int i; - register char* addr; - - assert(startAddress != NULL); - -#ifdef _DEBUG - if ((alignSize != 0) && (alignSize != OS_RG_ALIGN_2B) && (alignSize != OS_RG_ALIGN_4B) && - (alignSize != OS_RG_ALIGN_8B) && (alignSize != OS_RG_ALIGN_16B)) { - __osError(ERR_OSCREATEREGION_ALIGN, 1, alignSize); - return 0; - } -#endif - - if (alignSize == 0) { - alignSize = OS_RG_ALIGN_DEFAULT; - } - - rp = (OSRegion*)ALIGN(startAddress, alignSize); - length = length - ((s32)rp - (s32)startAddress); - rp->r_bufferSize = ALIGN(bufferSize, alignSize); - rp->r_bufferCount = (s32)(length - ALIGN(sizeof(OSRegion), alignSize)) / rp->r_bufferSize; - -#ifdef _DEBUG - if (rp->r_bufferCount <= 0) { - __osError(ERR_OSCREATEREGION_SIZE, 2, length, bufferSize); - return 0; - } -#endif - - if (rp->r_bufferCount > MAX_BUFCOUNT) { - rp->r_bufferCount = MAX_BUFCOUNT; - } - - rp->r_startBufferAddress = (u8*)rp + ALIGN(sizeof(OSRegion), alignSize); - rp->r_endAddress = (u8*)rp + length; - addr = rp->r_startBufferAddress; - - for (i = 0; i < rp->r_bufferCount - 1; i++) { - *((s16*)(&addr[i * rp->r_bufferSize])) = i + 1; - } - - *((u16*)(&addr[i * rp->r_bufferSize])) = BUF_FREE_WO_NEXT; - rp->r_alignSize = alignSize; - rp->r_freeList = 0; - return rp; -} diff --git a/lib/ultralib/src/rmon/rmonbrk.c b/lib/ultralib/src/rmon/rmonbrk.c deleted file mode 100644 index 0eb3242..0000000 --- a/lib/ultralib/src/rmon/rmonbrk.c +++ /dev/null @@ -1,432 +0,0 @@ -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "dbgproto.h" -#include "PR/rcp.h" -#include "PR/sptask.h" -#include "rmonint.h" - -#include "macros.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -#define TMP_BP 0 -#define NUM_BREAKPOINTS 16 - -typedef struct { - TVushort type; - TVushort response; - TVid threadID; - void* pc; -} TVExceptionReplyMsg; - -typedef struct { - u32* breakAddress; - u32 oldInstruction; -} BREAKINFO; - -/* first breakpoint is reserved for implementing single-stepping */ -static BREAKINFO breakpoints[NUM_BREAKPOINTS] ALIGNED(8); -/* breakpoint for alternate branch target */ -static BREAKINFO altBreak; - -static BREAKINFO RCPbreakpoints[NUM_BREAKPOINTS] ALIGNED(8); - -u8 __rmonRcpAtBreak; - -static void rmonFindFaultedThreads(void); - -static void SetTempBreakpoint(u32* addr1, u32* addr2) { - STUBBED_PRINTF(("Set temp BP at %08x", addr1)); - if (addr2 != NULL) { - STUBBED_PRINTF((" and %08x", addr2)); - } - STUBBED_PRINTF(("\n")); - - /* Save the word at the target address to be restored later */ - breakpoints[TMP_BP].oldInstruction = *addr1; - /* Install a break instruction at the target address */ - *addr1 = MIPS_BREAK(16); - osWritebackDCache(addr1, sizeof(*addr1)); - osInvalICache(addr1, sizeof(*addr1)); - breakpoints[TMP_BP].breakAddress = addr1; - - /* Also do so for an alt address if required */ - if (addr2 != NULL) { - altBreak.oldInstruction = *addr2; - *addr2 = MIPS_BREAK(16); - osWritebackDCache(addr2, sizeof(*addr2)); - osInvalICache(addr2, sizeof(*addr2)); - altBreak.breakAddress = addr2; - } -} - -static void ClearTempBreakpoint(void) { - u32 inst; - - if (breakpoints[TMP_BP].breakAddress != NULL) { - inst = *breakpoints[TMP_BP].breakAddress; - - if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { - STUBBED_PRINTF(("ClearTempBreak @ %08x\n", breakpoints[TMP_BP].breakAddress)); - - /* After confirming that there is a break instruction with code at the target - address, restore the original contents of the word at the target address */ - *breakpoints[TMP_BP].breakAddress = breakpoints[TMP_BP].oldInstruction; - osWritebackDCache(breakpoints[TMP_BP].breakAddress, sizeof(*breakpoints[TMP_BP].breakAddress)); - osInvalICache(breakpoints[TMP_BP].breakAddress, sizeof(*breakpoints[TMP_BP].breakAddress)); - } - breakpoints[TMP_BP].breakAddress = NULL; - } - - /* Same as above for the alt breakpoint */ - if (altBreak.breakAddress != NULL) { - inst = *altBreak.breakAddress; - - if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { - STUBBED_PRINTF(("ClearTempBreak @ %08x\n", altBreak.breakAddress)); - - *altBreak.breakAddress = altBreak.oldInstruction; - osWritebackDCache(altBreak.breakAddress, sizeof(*altBreak.breakAddress)); - osInvalICache(altBreak.breakAddress, sizeof(*altBreak.breakAddress)); - } - altBreak.breakAddress = NULL; - } -} - -int __rmonSetBreak(KKHeader* req) { - register KKSetBkptRequest* request = (KKSetBkptRequest*)req; - register BREAKINFO* breakBase; - register BREAKINFO* whichBreak; - register BREAKINFO* lastBreak; - KKBkptEvent reply; - - STUBBED_PRINTF(("SetBreak at %08x, method %d\n", request->addr, req->method)); - - /* Select breakpoint list */ - if (req->method == RMON_RSP) { - breakBase = RCPbreakpoints; - whichBreak = &RCPbreakpoints[1]; - lastBreak = &RCPbreakpoints[NUM_BREAKPOINTS]; - } else { - breakBase = breakpoints; - whichBreak = &breakpoints[1]; - lastBreak = &breakpoints[NUM_BREAKPOINTS]; - } - - /* Find breakpoint slot */ - for (; whichBreak < lastBreak; whichBreak++) { - if (whichBreak->breakAddress != NULL) { - if (whichBreak->breakAddress == (u32*)request->addr) { - /* Breakpoint already set here */ - break; - } - continue; - } else { - /* Empty slot */ - break; - } - } - - /* No breakpoints available */ - if (whichBreak == lastBreak) { - return TV_ERROR_NO_MORE_IDS; - } - - /* Set breakpoint if not already set */ - if (whichBreak->breakAddress == NULL) { - if (req->method == RMON_RSP) { - whichBreak->oldInstruction = __rmonReadWordAt((u32*)request->addr); - __rmonWriteWordTo((u32*)request->addr, MIPS_BREAK((whichBreak - breakBase) + NUM_BREAKPOINTS)); - } else { - whichBreak->oldInstruction = *(u32*)request->addr; - *(u32*)request->addr = MIPS_BREAK((whichBreak - breakBase) + NUM_BREAKPOINTS); - osWritebackDCache((void*)request->addr, sizeof(whichBreak->oldInstruction)); - osInvalICache((void*)request->addr, sizeof(whichBreak->oldInstruction)); - } - whichBreak->breakAddress = (u32*)request->addr; - STUBBED_PRINTF(("* (%08x) = %08x (was %08x)\n", whichBreak->breakAddress, *whichBreak->breakAddress, - whichBreak->oldInstruction)); - } - - /* Send reply */ - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.object = request->object; - reply.bp = whichBreak - breakBase; - reply.instruction = whichBreak->oldInstruction; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonListBreak(KKHeader* request UNUSED) { - STUBBED_PRINTF(("ListBreak\n")); - - return TV_ERROR_ILLEGAL_CALL; -} - -int __rmonClearBreak(KKHeader* req) { - register KKClrBkptRequest* request = (KKClrBkptRequest*)req; - register BREAKINFO* whichBreak; - KKBkptEvent reply; - u32 inst; - - STUBBED_PRINTF(("ClearBreak\n")); - - /* Check valid breakpoint index */ - if (request->bp >= NUM_BREAKPOINTS) { - return TV_ERROR_INVALID_ID; - } - - /* Clear the breakpoint, restore whatever was there before */ - if (req->method == RMON_RSP) { - whichBreak = &RCPbreakpoints[request->bp]; - - if (whichBreak->breakAddress == NULL) { - return TV_ERROR_INVALID_ID; - } - - inst = __rmonReadWordAt(whichBreak->breakAddress); - if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { - __rmonWriteWordTo(whichBreak->breakAddress, whichBreak->oldInstruction); - } - } else { - whichBreak = &breakpoints[request->bp]; - - if (whichBreak->breakAddress == NULL) { - return TV_ERROR_INVALID_ID; - } - - inst = *whichBreak->breakAddress; - if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { - *whichBreak->breakAddress = whichBreak->oldInstruction; - osWritebackDCache(whichBreak->breakAddress, sizeof(*whichBreak->breakAddress)); - osInvalICache(whichBreak->breakAddress, sizeof(*whichBreak->breakAddress)); - } - } - whichBreak->breakAddress = NULL; - - /* Send reply */ - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.object = request->object; - reply.bp = request->bp; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -u32 __rmonGetBranchTarget(int method, int thread, char* addr) { - int inst; - - if (method == RMON_RSP) { - inst = __rmonReadWordAt((u32*)addr); - } else { - inst = *(u32*)addr; - } - - switch ((inst >> 26) & 0x3F) { - case 0: /* SPECIAL */ - if (((inst >> 5) & 0x7FFF) == 0 && (inst & 0x3F) == 8) { - /* JR */ - return __rmonGetRegisterContents(method, thread, (inst >> 21) & 0x1F); - } - if (((inst >> 16) & 0x1F) == 0 && (inst & 0x7FF) == 9) { - /* JALR */ - return __rmonGetRegisterContents(method, thread, (inst >> 21) & 0x1F); - } - break; - case 1: /* REGIMM */ - switch ((inst >> 16) & 0x1F) { - case 0: /* BLTZ */ - case 1: /* BGEZ */ - case 2: /* BLTZL */ - case 3: /* BGEZL */ - case 16: /* BLTZAL */ - case 17: /* BGEZAL */ - case 18: /* BLTZALL */ - case 19: /* BGEZALL */ - return (((inst << 0x10) >> 0xE) + addr + 4); - } - break; - case 2: /* J */ - case 3: /* JAL */ - return (((u32)inst << 6) >> 4) + (((s32)((u32)addr + 4) >> 0x1C) << 0x1C); - case 4: /* BEQ */ - case 5: /* BNE */ - case 20: /* BEQL */ - case 21: /* BNEL */ - return (((inst << 0x10) >> 0xE) + addr + 4); - case 6: /* BLEZ */ - case 7: /* BGTZ */ - case 22: /* BLEZL */ - case 23: /* BGTZL */ - if (((inst >> 16) & 0x1F) == 0) { - return (((inst << 0x10) >> 0xE) + addr + 4); - } - break; - case 16: /* COP0 */ - case 17: /* COP1 */ - case 18: /* COP2 */ - case 19: /* COP3 */ - if (((inst >> 21) & 0x1F) == 8) { - switch ((inst >> 16) & 0x1F) { - case 0: /* BCzF */ - case 1: /* BCzT */ - case 2: /* BCzFL */ - case 3: /* BCzTL */ - return (((inst << 0x10) >> 0xE) + addr + 4); - } - } - break; - } - return -1; -} - -static int IsJump(u32 inst) { - switch ((inst >> 26) & 0x3F) { - case 0: /* SPECIAL */ - if (((inst >> 5) & 0x7FFF) == 0 && (inst & 0x3F) == 8) { - /* JR */ - return TRUE; - } - if (((inst >> 16) & 0x1F) == 0 && (inst & 0x7FF) == 9) { - /* JALR */ - return TRUE; - } - break; - case 2: /* J */ - case 3: /* JAL */ - return TRUE; - } - return FALSE; -} - -int __rmonSetSingleStep(int thread, u32* instptr) { - u32 branchTarget = __rmonGetBranchTarget(RMON_CPU, thread, (void*)instptr); - - STUBBED_PRINTF(("SingleStep\n")); - - if ((branchTarget & 3) != 0) { - /* no branch target, set breakpoint at next pc */ - SetTempBreakpoint(instptr + 1, NULL); - } else if (branchTarget == (u32)instptr) { - /* branch target is this instruction, can't single step here */ - return FALSE; - } else if (IsJump(*instptr) || branchTarget == (u32)(instptr + 2)) { - /* unconditional branch, set at branch target */ - SetTempBreakpoint((u32*)branchTarget, NULL); - } else { - /* set two breakpoints for handling conditional branches */ - SetTempBreakpoint((u32*)branchTarget, instptr + 2); - } - return TRUE; -} - -void __rmonGetExceptionStatus(KKStatusEvent* reply) { - reply->status.flags = OS_STATE_STOPPED; - reply->status.why = 2; - reply->status.what = 0; - reply->status.rv = 0; - reply->status.info.major = 2; - reply->status.info.minor = 4; - reply->header.code = KK_CODE_THREAD_STATUS; - reply->header.error = TV_ERROR_NO_ERROR; - reply->header.length = sizeof(*reply); -} - -#define FAULT_BREAKNUM (NUM_BREAKPOINTS - 1) - -static void rmonSendBreakMessage(s32 whichThread, int breakNumber) { - KKStatusEvent reply; - - STUBBED_PRINTF(("Break %d in thread %d\n", breakNumber, whichThread)); - - /* Build thread exception status */ - __rmonGetThreadStatus(RMON_CPU, (whichThread != 0) ? whichThread : RMON_TID_NOTHREAD, &reply); - __rmonGetExceptionStatus(&reply); - - if (breakNumber == FAULT_BREAKNUM) { - /* Hit fault */ - reply.status.info.major = 1; - reply.status.info.minor = 2; - } - if (breakNumber < NUM_BREAKPOINTS) { - breakNumber = 0; - } else { - breakNumber -= NUM_BREAKPOINTS; - } - if (breakNumber != 0) { - /* Break not set by debugger, or set during single-step */ - reply.status.instr = MIPS_BREAK_OPCODE; - } - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_EXCEPTION); -} - -void __rmonHitBreak(void) { - STUBBED_PRINTF(("HitBreak\n")); - - /* Stop all user threads and report faulted threads */ - ClearTempBreakpoint(); - __rmonStopUserThreads(0); - rmonFindFaultedThreads(); -} - -void __rmonHitSpBreak(void) { - KKStatusEvent exceptionReply; - - STUBBED_PRINTF(("Hit SP Break\n")); - - /* Rewind RSP PC by one instruction to return to the location of the break instruction */ - __rmonWriteWordTo((u32*)SP_PC_REG, __rmonReadWordAt((u32*)SP_PC_REG) - 4); - - /* Report RSP break event */ - __rmonGetThreadStatus(RMON_RSP, RMON_TID_RSP, &exceptionReply); - __rmonGetExceptionStatus(&exceptionReply); - __rmonSendReply(&exceptionReply.header, sizeof(exceptionReply), KK_TYPE_EXCEPTION); - __rmonRcpAtBreak = TRUE; -} - -void __rmonHitCpuFault(void) { - STUBBED_PRINTF(("HitCpuFault\n")); - - /* Stop all user threads and report faulted threads */ - __rmonMaskIdleThreadInts(); - __rmonStopUserThreads(0); - rmonFindFaultedThreads(); -} - -static void rmonFindFaultedThreads(void) { - register OSThread* tptr = __osGetActiveQueue(); - - while (tptr->priority != -1) { - if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { - if (tptr->flags & OS_FLAG_CPU_BREAK) { - int inst = *(u32*)tptr->context.pc; - - STUBBED_PRINTF(("Brk in thread %d @ %08x, inst %08x\r\n", tptr->id, tptr->context.pc, inst)); - - if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { - rmonSendBreakMessage(tptr->id, inst >> 6); - } else { - rmonSendBreakMessage(tptr->id, 0); - } - } - if (tptr->flags & OS_FLAG_FAULT) { - __rmonSendFault(tptr); - rmonSendBreakMessage(tptr->id, FAULT_BREAKNUM); - } - } - tptr = tptr->tlnext; - } -} - -#endif diff --git a/lib/ultralib/src/rmon/rmoncmds.c b/lib/ultralib/src/rmon/rmoncmds.c deleted file mode 100644 index 88600a6..0000000 --- a/lib/ultralib/src/rmon/rmoncmds.c +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _FINALROM - -#include "dbgproto.h" -#include "rmonint.h" - -#include "macros.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -static int NotImplemented(KKHeader* dummy UNUSED) { - return TV_ERROR_ILLEGAL_CALL; -} - -static FUNPTR dispatchTable[] = { - __rmonLoadProgram, __rmonListProcesses, __rmonGetExeName, __rmonListThreads, __rmonThreadStatus, - NotImplemented, __rmonStopThread, __rmonRunThread, NotImplemented, NotImplemented, - __rmonSetFault, NotImplemented, __rmonGetRegionCount, __rmonGetRegions, __rmonGetGRegisters, - __rmonSetGRegisters, __rmonGetFRegisters, __rmonSetFRegisters, __rmonReadMem, __rmonWriteMem, - __rmonSetBreak, __rmonClearBreak, __rmonListBreak, NotImplemented, NotImplemented, - NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, - __rmonSetComm, NotImplemented, NotImplemented, NotImplemented, NotImplemented, - NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, - NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, - NotImplemented, NotImplemented, NotImplemented, NotImplemented, __rmonGetSRegs, - __rmonSetSRegs, __rmonGetVRegs, __rmonSetVRegs, NotImplemented, -}; - -int __rmonExecute(KKHeader* request) { - int retval; - KKHeader reply; - - if (request->code >= ARRLEN(dispatchTable) - 1) { - return TV_ERROR_ILLEGAL_CALL; - } - - retval = dispatchTable[(int)request->code](request); - if (retval < TV_ERROR_NO_ERROR) { - reply.code = request->code; - reply.error = retval; - __rmonSendReply(&reply, sizeof(reply), KK_TYPE_REPLY); - } - return retval; -} - -#endif diff --git a/lib/ultralib/src/rmon/rmonint.h b/lib/ultralib/src/rmon/rmonint.h deleted file mode 100644 index 59ad736..0000000 --- a/lib/ultralib/src/rmon/rmonint.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef _RMONINT_H -#define _RMONINT_H - -#include "dbgproto.h" -#include "PR/os_internal.h" - -/* mips */ - -#define MIPS_LWC2_OPCODE 50 -#define MIPS_SWC2_OPCODE 58 - -#define MIPS_LW_OPCODE 35 -#define MIPS_SW_OPCODE 43 - -#define MIPS_BREAK_OPCODE 0xD -#define MIPS_BREAK_MASK 0xFC00003F - -#define MIPS_BREAK(code) \ - ((((code) & 0xFFFFF) << 6) | MIPS_BREAK_OPCODE) - -/* R4300 General Purpose Register Indices */ -#define GREG_IDX_ZERO 0 -#define GREG_IDX_AT 1 -#define GREG_IDX_T9 25 -#define GREG_IDX_K0 26 -#define GREG_IDX_GP 28 -#define GREG_IDX_RA 31 -#define GREG_IDX_LO 32 -#define GREG_IDX_HI 33 -#define GREG_IDX_CAUSE 34 -#define GREG_IDX_PC 35 -#define GREG_IDX_SR 36 - -/* RSP Scalar Register Indices */ -#define SREG_IDX_ZERO 0 -#define SREG_IDX_RA 31 -#define SREG_IDX_DRAM_ADDR (32 + 0) -#define SREG_IDX_MEM_ADDR (32 + 1) -#define SREG_IDX_RD_LEN (32 + 2) -#define SREG_IDX_PC (32 + 3) -#define SREG_IDX_WR_LEN (32 + 4) -#define SREG_IDX_STATUS (32 + 5) -#define SREG_IDX_DMA_FULL (32 + 6) -#define SREG_IDX_DMA_BUSY (32 + 7) - -/* RSP Vector Register Properties */ -#define VREG_NUM 32 -#define VREG_SIZE 0x10 - -/* rmon */ - -#define RMON_MESG_CPU_BREAK 2 -#define RMON_MESG_SP_BREAK 4 -#define RMON_MESG_FAULT 8 - -#define RMON_CPU 0 -#define RMON_RSP 1 - -/* "thread id" for rsp */ -#define RMON_TID_RSP 1000 -/* "thread priority" for rsp */ -#define RMON_PRI_RSP 42 - -/* "thread id" for no thread running */ -#define RMON_TID_NOTHREAD 1003 - -#define RMON_PID_CPU 1002 -#define RMON_PID_RSP 1001 - -/* Largest serviceable read/write memory request */ -#define RMON_MAX_XFER_SIZE 1024 - -/* rmonmain */ - -void __rmonSendHeader(KKHeader* const block, u32 blockSize, u32 type); -void __rmonSendReply(KKHeader* const block, u32 blockSize, u32 replyType); -void __rmonSendData(char* const block, unsigned int blockSize); - -extern int __rmonActive; - -/* rmonmisc */ - -void __rmonInit(void); -void __rmonPanic(void); - -extern OSMesgQueue __rmonMQ; - -/* rmonmem */ - -void __rmonWriteWordTo(u32* addr, u32 val); -u32 __rmonReadWordAt(u32* addr); -void __rmonMemcpy(u8* dest, u8* srce, u32 count); -void __rmonCopyWords(u32* dest, u32* srce, u32 count); - -extern u8 __rmonUtilityBuffer[]; - -/* rmonsio */ - -void __rmonSendFault(OSThread* thread); -void __rmonIOflush(void); -void __rmonIOputw(u32 word); -void __rmonIOhandler(void); - -extern void* __osRdb_DbgRead_Buf; -extern u8 rmonRdbReadBuf[]; - -/* rmonrcp */ - -int __rmonRCPrunning(void); -void __rmonIdleRCP(void); -void __rmonStepRCP(void); -void __rmonRunRCP(void); - -/* rmonbrk */ - -u32 __rmonGetBranchTarget(int method, int thread, char* addr); -int __rmonSetSingleStep(int thread, u32* instptr); -void __rmonGetExceptionStatus(KKStatusEvent* reply); -void __rmonHitBreak(void); -void __rmonHitSpBreak(void); -void __rmonHitCpuFault(void); - -extern u8 __rmonRcpAtBreak; - -/* rmonregs */ - -u32 __rmonGetRegisterContents(int method, int threadNumber, int regNumber); - -/* rmontask */ - -void __rmonMaskIdleThreadInts(void); -OSThread* __rmonGetTCB(int threadNumber); -int __rmonStopUserThreads(int whichThread); -int __rmonGetThreadStatus(int method, int id, KKStatusEvent* reply); - -/* rmoncmds */ - -int __rmonExecute(KKHeader* request); - -/* commands */ - -typedef int (*FUNPTR)(); - -int __rmonLoadProgram(KKHeader* req); -int __rmonListProcesses(KKHeader* req); -int __rmonGetExeName(KKHeader* req); -int __rmonListThreads(KKHeader* req); -int __rmonThreadStatus(KKHeader* req); -int __rmonStopThread(KKHeader* req); -int __rmonRunThread(KKHeader* req); -int __rmonSetFault(KKHeader* req); -int __rmonGetRegionCount(KKHeader* req); -int __rmonGetRegions(KKHeader* req); -int __rmonGetGRegisters(KKHeader* req); -int __rmonSetGRegisters(KKHeader* req); -int __rmonGetFRegisters(KKHeader* req); -int __rmonSetFRegisters(KKHeader* req); -int __rmonReadMem(KKHeader* req); -int __rmonWriteMem(KKHeader* req); -int __rmonSetBreak(KKHeader* req); -int __rmonClearBreak(KKHeader* req); -int __rmonListBreak(KKHeader* req); -int __rmonSetComm(KKHeader* req); -int __rmonGetSRegs(KKHeader* req); -int __rmonSetSRegs(KKHeader* req); -int __rmonGetVRegs(KKHeader* req); -int __rmonSetVRegs(KKHeader* req); - -#endif diff --git a/lib/ultralib/src/rmon/rmonmain.c b/lib/ultralib/src/rmon/rmonmain.c deleted file mode 100644 index 564ac44..0000000 --- a/lib/ultralib/src/rmon/rmonmain.c +++ /dev/null @@ -1,138 +0,0 @@ -#include "PR/os_version.h" - -#if BUILD_VERSION < VERSION_J -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -#ifndef _FINALROM - -#include "dbgproto.h" -#include "PR/os_internal.h" -#include "rmonint.h" -#include "PR/rcp.h" -#include "sptask.h" -#include "PR/rdb.h" - -#include "macros.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#endif - -int __rmonActive = FALSE; - -static vu32 somethingToDo; -static u32 inbuffer[280] ALIGNED(0x10); -static u8 cmdinptr; -static u8 cmdoutptr; -static int state; -static char* inPointer; - -void __rmonSendHeader(KKHeader* const block, u32 blockSize, u32 type) { - int sent; - char* cPtr = (char*)block; - - block->rev = KK_REV; - block->type = type; - - sent = 0; - while (sent < blockSize) { - sent += __osRdbSend(cPtr + sent, blockSize - sent, RDB_TYPE_GtoH_DEBUG); - } -} - -void __rmonSendReply(KKHeader* const block, u32 blockSize, u32 replyType) { - char* cPtr; - int sent = 0; - - block->length = blockSize; - cPtr = (char*)&blockSize; - - /* send size */ - while (sent < (signed)sizeof(blockSize)) { - sent += __osRdbSend(cPtr + sent, sizeof(blockSize) - sent, RDB_TYPE_GtoH_DEBUG); - } - - /* send data */ - __rmonSendHeader(block, blockSize, replyType); - __rmonIOflush(); -} - -void __rmonSendData(char* const block, unsigned int blockSize) { - int* blockPointer = (int*)block; - unsigned int wordCount = (u32)(blockSize + 3) / 4; - u32 data; - union { - char bufBytes[4]; - u32 bufWord; - } buffer; - - if (((u32)block & 3) == 0) { - while (wordCount--) { - if ((u32)blockPointer >= SP_DMEM_START && (u32)blockPointer < 0x05000000) { - __osSpRawReadIo((u32)blockPointer++, &data); - __rmonIOputw(data); - } else { - __rmonIOputw(*(blockPointer++)); - } - } - } else - while (wordCount--) { - __rmonMemcpy((u8*)buffer.bufBytes, (u8*)blockPointer, sizeof(buffer)); - __rmonIOputw(buffer.bufWord); - blockPointer++; - } - __rmonIOflush(); -} - -void rmonMain(void) { - register int newChars UNUSED; - - STUBBED_PRINTF(("rmon: Thread %d created\n")); - STUBBED_PRINTF(("rmon: Thread %d destroyed\n")); - - somethingToDo = 0; - cmdoutptr = 0; - cmdinptr = 0; - - __rmonInit(); - __rmonActive = TRUE; - - - state = 0, newChars = 0, inPointer = (void*)&inbuffer; - for (;;) { - OSMesg work; - - osRecvMesg(&__rmonMQ, &work, OS_MESG_BLOCK); - - somethingToDo |= (u32)work; - - if (somethingToDo & RMON_MESG_CPU_BREAK) { - somethingToDo &= ~RMON_MESG_CPU_BREAK; - __rmonHitBreak(); - } - if (somethingToDo & RMON_MESG_SP_BREAK) { - somethingToDo &= ~RMON_MESG_SP_BREAK; - __rmonHitSpBreak(); - } - if (somethingToDo & RMON_MESG_FAULT) { - somethingToDo &= ~RMON_MESG_FAULT; - __rmonHitCpuFault(); - } - if (somethingToDo & 0x10) { - somethingToDo; - somethingToDo &= (u8)~0x10; - } - if (somethingToDo & 0x20) { - somethingToDo; - somethingToDo &= (u8)~0x20; - } - } -} - -#endif diff --git a/lib/ultralib/src/rmon/rmonmem.c b/lib/ultralib/src/rmon/rmonmem.c deleted file mode 100644 index a11051b..0000000 --- a/lib/ultralib/src/rmon/rmonmem.c +++ /dev/null @@ -1,283 +0,0 @@ -#include "PR/os_version.h" - -#if BUILD_VERSION < VERSION_J -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -#ifndef _FINALROM - -#include "dbgproto.h" -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PR/sptask.h" -#include "rmonint.h" -#include "PR/rdb.h" - -#include "macros.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#endif - -u8 __rmonUtilityBuffer[256] ALIGNED(8); - -void __rmonWriteWordTo(u32* addr, u32 val) { - while (__osSpRawWriteIo((u32)addr, val) != 0) { - ; - } -} - -u32 __rmonReadWordAt(u32* addr) { - u32 data; - - if ((u32)addr >= SP_DMEM_START && (u32)addr < 0x05000000) { - __osSpRawReadIo((u32)addr, &data); - return data; - } - return 0; -} - -void __rmonMemcpy(u8* dest, u8* srce, u32 count) { - while (count--) { - *dest++ = *srce++; - } -} - -void __rmonCopyWords(u32* dest, u32* srce, u32 count) { - while (count--) { - *dest++ = *srce++; - } -} - -static void strcpy(char* dest, char* srce) { - while ((*dest++ = *srce++)) { - ; - } -} - -int __rmonReadMem(KKHeader* req) { - char* cPtr; - int sent; - int dataSize; - KKReadRequest* request = (KKReadRequest*)req; - KKBufferEvent* reply = (KKBufferEvent*)__rmonUtilityBuffer; - u8* blockStart; - - STUBBED_PRINTF(("ReadMem @ %08x for %d\n", request->addr, request->nbytes)); - - reply->header.code = request->header.code; - reply->object = request->object; - reply->header.error = TV_ERROR_NO_ERROR; - - if (request->addr == (u32)-1) { - return TV_ERROR_INVALID_ADDRESS; - } - if (request->nbytes > RMON_MAX_XFER_SIZE) { - return TV_ERROR_INVALID_CAPABILITY; - } - - if (req->method == RMON_RSP) { - if (!((request->addr < SP_IMEM_START || (request->addr + request->nbytes) > SP_IMEM_END) ? FALSE : TRUE) && - !((request->addr < SP_DMEM_START || (request->addr + request->nbytes) > SP_DMEM_END) ? FALSE : TRUE)) { - return TV_ERROR_INVALID_ADDRESS; - } - } else if (osVirtualToPhysical((void*)request->addr) == (u32)-1) { - return TV_ERROR_INVALID_ADDRESS; - } - - blockStart = (u8*)request->addr; - reply->header.length = request->nbytes + sizeof(reply->header) + sizeof(reply->object); - dataSize = request->nbytes + sizeof(reply->header) + sizeof(reply->object); - - cPtr = (char*)&dataSize; - sent = 0; - while (sent < (signed)sizeof(dataSize)) { - sent += __osRdbSend(cPtr + sent, sizeof(dataSize) - sent, RDB_TYPE_GtoH_DEBUG); - } - - __rmonSendHeader(&reply->header, sizeof(reply->header) + sizeof(reply->object), KK_TYPE_REPLY); - __rmonSendData(blockStart, request->nbytes); - return TV_ERROR_NO_ERROR; -} - -int __rmonWriteMem(KKHeader* req) { - register KKWriteRequest* request = (KKWriteRequest*)req; - KKObjectEvent reply; - - STUBBED_PRINTF(("WriteMem\n")); - - /* Bad virtual address, abort */ - if (req->method == RMON_CPU && osVirtualToPhysical((u32*)request->writeHeader.addr) == (u32)-1) { - return TV_ERROR_INVALID_ADDRESS; - } - - /* Transfer size too large, abort */ - if (request->writeHeader.nbytes > RMON_MAX_XFER_SIZE) { - return TV_ERROR_INVALID_CAPABILITY; - } - - if (((request->writeHeader.addr < SP_DMEM_START || - (request->writeHeader.addr + request->writeHeader.nbytes) > 0x04FFFFFF) ? FALSE : TRUE)) { - int align; - u32 word; - - if ((align = request->writeHeader.addr & 3) != 0) { - STUBBED_PRINTF(("Long unaligned write...\n")); - - if (request->writeHeader.nbytes != 1) { - return TV_ERROR_INVALID_ADDRESS; - } - - /* Unaligned write; read the word, substitute in the written byte, write it back */ - word = __rmonReadWordAt((u32*)(request->writeHeader.addr & ~3)); - if (align == 1) { - word = (word & ~0xFF0000) | (request->buffer[0] << 0x10); - } else if (align == 2) { - word = (word & ~0xFF00) | (request->buffer[0] << 8); - } else { - word = (word & ~0xFF) | (request->buffer[0] << 0); - } - __rmonWriteWordTo((u32*)(request->writeHeader.addr & ~3), word); - } else { - int wordCount = request->writeHeader.nbytes / sizeof(u32); - u32* wordPointer = (u32*)request->buffer; - - if (request->writeHeader.nbytes % sizeof(u32) != 0) { - STUBBED_PRINTF(("RCP write not an integral number of words\n")); - return TV_ERROR_INVALID_ADDRESS; - } - - while (wordCount--) { - __rmonWriteWordTo((u32*)request->writeHeader.addr, *(wordPointer++)); - request->writeHeader.addr += sizeof(*wordPointer); - } - } - } else { - __rmonMemcpy((u8*)request->writeHeader.addr, (u8*)request->buffer, request->writeHeader.nbytes); - } - - reply.header.code = request->writeHeader.header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.object = request->writeHeader.object; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - - return TV_ERROR_NO_ERROR; -} - -int __rmonListProcesses(KKHeader* req) { - KKObjectRequest* request = (KKObjectRequest*)req; - KKObjsEvent reply; - - STUBBED_PRINTF(("ListProcesses\n")); - - reply.object = 0; - reply.objs.number = 1; - reply.objs.objects[0] = (req->method == RMON_RSP) ? RMON_PID_RSP : RMON_PID_CPU; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonLoadProgram(KKHeader* request UNUSED) { - STUBBED_PRINTF(("LoadProgram\n")); - - return TV_ERROR_ILLEGAL_CALL; -} - -int __rmonGetExeName(KKHeader* req) { - KKObjectRequest* request = (KKObjectRequest*)req; - KKBufferEvent* reply = (KKBufferEvent*)__rmonUtilityBuffer; - - STUBBED_PRINTF(("GetExeName\n")); - - reply->header.code = request->header.code; - reply->header.error = TV_ERROR_NO_ERROR; - reply->object = request->object; - - if (req->method == RMON_RSP) { - strcpy(reply->buffer, "imem"); - } else { - strcpy(reply->buffer, "rmon"); - } - __rmonSendReply(&reply->header, sizeof(reply->header) + sizeof(reply->object) + 8, KK_TYPE_REPLY); - - return TV_ERROR_NO_ERROR; -} - -int __rmonGetRegionCount(KKHeader* req) { - KKObjectRequest* request = (KKObjectRequest*)req; - KKNumberEvent reply; - - STUBBED_PRINTF(("GetRegionCount\n")); - - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.object = request->object; - - reply.number = (req->method == RMON_RSP) ? 2 : 5; - - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - - return TV_ERROR_NO_ERROR; -} - -int __rmonGetRegions(KKHeader* req) { - KKObjectRequest* request = (KKObjectRequest*)req; - KKRegionEvent* reply = (KKRegionEvent*)__rmonUtilityBuffer; - int numRegions; - - STUBBED_PRINTF(("GetRegions\n")); - - numRegions = (req->method == RMON_RSP) ? 2 : 6; - - reply->header.length = numRegions * sizeof(reply->regions[0]) + sizeof(*reply); - reply->header.code = request->header.code; - reply->header.error = TV_ERROR_NO_ERROR; - reply->object = request->object; - reply->number = numRegions; - - reply->regions[1].vaddr = SP_IMEM_START; - reply->regions[1].size = SP_IMEM_END + 1 - SP_IMEM_START; - reply->regions[1].flags = 1 | 2 | 4; - reply->regions[1].paddr = SP_IMEM_START; - - reply->regions[0].vaddr = SP_DMEM_START; - reply->regions[0].size = SP_DMEM_END + 1 - SP_DMEM_START; - reply->regions[0].flags = 1 | 2; - reply->regions[0].paddr = SP_DMEM_START; - - if (numRegions > 2) { - reply->regions[2].vaddr = 0x88200000; - reply->regions[2].size = 0x6130; - reply->regions[2].flags = 1 | 4; - reply->regions[2].paddr = 0; - - reply->regions[3].vaddr = 4; - reply->regions[3].size = 0x200000; - reply->regions[3].flags = 1 | 2; - reply->regions[3].paddr = 0; - - reply->regions[4].vaddr = 0x4002000; - reply->regions[4].size = 0x800000; - reply->regions[4].flags = 1 | 2; - reply->regions[4].paddr = 0; - - reply->regions[5].vaddr = 0x88206130; - reply->regions[5].size = 0x9000; - reply->regions[5].flags = 1 | 2; - reply->regions[5].paddr = 0; - } - - __rmonSendReply(&reply->header, reply->header.length, KK_TYPE_REPLY); - - return TV_ERROR_NO_ERROR; -} - -#endif diff --git a/lib/ultralib/src/rmon/rmonmisc.c b/lib/ultralib/src/rmon/rmonmisc.c deleted file mode 100644 index a1aa96c..0000000 --- a/lib/ultralib/src/rmon/rmonmisc.c +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef _FINALROM - -#include "dbgproto.h" -#include "PR/os_internal.h" -#include "PR/sptask.h" -#include "rmonint.h" - -#include "macros.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -int __rmonSetFault(KKHeader* req) { - KKFaultRequest* request = (KKFaultRequest*)req; - KKObjectEvent reply; - - STUBBED_PRINTF(("SetFault\n")); - - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.object = request->tid; - - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -OSMesgQueue __rmonMQ ALIGNED(8); -static OSThread rmonIOThread ALIGNED(8); -static OSMesg rmonMsgs[8] ALIGNED(8); -static u64 rmonIOStack[2048] ALIGNED(16); -static OSMesg rmonPiMsgs[8] ALIGNED(8); -static OSMesgQueue rmonPiMQ ALIGNED(8); - -void __rmonInit(void) { - osCreateMesgQueue(&__rmonMQ, rmonMsgs, ARRLEN(rmonMsgs)); - osSetEventMesg(OS_EVENT_CPU_BREAK, &__rmonMQ, (OSMesg)RMON_MESG_CPU_BREAK); - osSetEventMesg(OS_EVENT_SP_BREAK, &__rmonMQ, (OSMesg)RMON_MESG_SP_BREAK); - osSetEventMesg(OS_EVENT_FAULT, &__rmonMQ, (OSMesg)RMON_MESG_FAULT); - osSetEventMesg(OS_EVENT_THREADSTATUS, &__rmonMQ, NULL); - osCreateThread(&rmonIOThread, 0, (void (*)(void*))__rmonIOhandler, NULL, rmonIOStack + ARRLEN(rmonIOStack), - OS_PRIORITY_MAX); - osCreatePiManager(OS_PRIORITY_PIMGR, &rmonPiMQ, rmonPiMsgs, ARRLEN(rmonPiMsgs)); - osStartThread(&rmonIOThread); -} - -void __rmonPanic(void) { - STUBBED_PRINTF(("PANIC!!\n")); - - for (;;) { - ; - } -} - -int __rmonSetComm(KKHeader* req) { - KKObjectEvent reply; - - STUBBED_PRINTF(("SetComm\n")); - - reply.header.code = req->code; - reply.object = 0; - reply.header.error = TV_ERROR_NO_ERROR; - - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - - return TV_ERROR_NO_ERROR; -} - -#endif diff --git a/lib/ultralib/src/rmon/rmonprint.c b/lib/ultralib/src/rmon/rmonprint.c deleted file mode 100644 index 8ac91a5..0000000 --- a/lib/ultralib/src/rmon/rmonprint.c +++ /dev/null @@ -1 +0,0 @@ -/* Empty file */ diff --git a/lib/ultralib/src/rmon/rmonrcp.s b/lib/ultralib/src/rmon/rmonrcp.s deleted file mode 100644 index 539f41d..0000000 --- a/lib/ultralib/src/rmon/rmonrcp.s +++ /dev/null @@ -1,60 +0,0 @@ -#include "PR/os_version.h" -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J - -#include "sys/asm.h" -#include "sys/regdef.h" -#include "PR/rcp.h" -#include "PR/R4300.h" - -.text - -/* check if the rsp is currently running by polling HALT or BROKE bits in SP_STATUS */ -LEAF(__rmonRCPrunning) - move v0, zero - lw t0, PHYS_TO_K1(SP_STATUS_REG) - and t0, SP_STATUS_HALT | SP_STATUS_BROKE - bnez t0, isHalted - ori v0, 1 -isHalted: - jr ra -END(__rmonRCPrunning) - -/* stop the rsp, first wait for any ongoing dma to complete before setting HALT in SP_STATUS */ -LEAF(__rmonIdleRCP) - li a0, PHYS_TO_K1(SP_DMA_BUSY_REG) -wait4dma: - lw v0, (a0) - bnez v0, wait4dma - li a1, SP_CLR_INTR_BREAK | SP_SET_HALT - li a0, PHYS_TO_K1(SP_STATUS_REG) - sw a1, (a0) - -/* wait for the rsp to stop */ -awaitIdle: - li a0, PHYS_TO_K1(SP_STATUS_REG) - lw v0, (a0) - and v0, SP_STATUS_HALT | SP_STATUS_BROKE - beqz v0, awaitIdle - jr ra -END(__rmonIdleRCP) - -/* run the rsp in single-step mode to step one instruction */ -LEAF(__rmonStepRCP) - li a0, PHYS_TO_K1(SP_STATUS_REG) - li a1, SP_CLR_INTR_BREAK | SP_SET_SSTEP | SP_CLR_BROKE | SP_CLR_HALT - sw a1, (a0) - b awaitIdle -END(__rmonStepRCP) - -/* run the rsp normally */ -LEAF(__rmonRunRCP) - li a0, PHYS_TO_K1(MI_INTR_MASK_REG) - li a1, MI_INTR_MASK_SET_SP - sw a1, (a0) - li a0, PHYS_TO_K1(SP_STATUS_REG) - li a1, SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT - sw a1, (a0) - jr ra -END(__rmonRunRCP) - -#endif diff --git a/lib/ultralib/src/rmon/rmonregs.c b/lib/ultralib/src/rmon/rmonregs.c deleted file mode 100644 index 39cf5b2..0000000 --- a/lib/ultralib/src/rmon/rmonregs.c +++ /dev/null @@ -1,417 +0,0 @@ -#ifndef _FINALROM - -#include "dbgproto.h" -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PR/sptask.h" -#include "rmonint.h" -#include "PR/rdb.h" -#include "PR/os_version.h" - -#include "macros.h" - -// TODO: these come from headers -#if BUILD_VERSION >= VERSION_K -#ident "$Revision: 1.4 $" -// This revision was bumped down at K for some reason -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#elif BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#ident "$Revision: 3.71 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -static u32 RCPpc; -static u32 oldIMEMvalue; -static u32 DMEMbuffer[4] ALIGNED(8); - -typedef union { - u32 everything; - struct { - int opcode : 6; - int base : 5; - int rt : 5; - int offset : 16; - } scalarop; - struct { - int opcode : 6; - int base : 5; - int rt : 5; - int size : 5; - int element : 4; - int offset : 7; - } vectorop; -} INSTRUCTION; - -static void LoadStoreSU(int opcode, int regno) { - INSTRUCTION inst; - - /* Prepare a scalar load or store instruction at DMEM address 0 */ - inst.everything = 0; - inst.scalarop.opcode = opcode; - inst.scalarop.rt = regno; - __rmonWriteWordTo((u32*)SP_IMEM_START, inst.everything); - __rmonWriteWordTo((u32*)SP_PC_REG, 0); -} - -static void LoadStoreVU(int opcode, int regno) { - INSTRUCTION inst; - - /* Prepare a vector 128-bit load or store instruction at DMEM address 0 */ - inst.everything = 0; - inst.vectorop.opcode = opcode; - inst.vectorop.rt = regno; - inst.vectorop.size = 4; /* LQV / SQV */ - __rmonWriteWordTo((u32*)SP_IMEM_START, inst.everything); - __rmonWriteWordTo((u32*)SP_PC_REG, 0); -} - -static void SetUpForRCPop(int isVector) { - /* Save RSP data that would be overwritten when reading or writing registers */ - RCPpc = __rmonReadWordAt((u32*)SP_PC_REG); - oldIMEMvalue = __rmonReadWordAt((u32*)SP_IMEM_START); - DMEMbuffer[0] = __rmonReadWordAt((u32*)SP_DMEM_START); - if (isVector) { - DMEMbuffer[1] = __rmonReadWordAt((u32*)(SP_DMEM_START + 0x4)); - DMEMbuffer[2] = __rmonReadWordAt((u32*)(SP_DMEM_START + 0x8)); - DMEMbuffer[3] = __rmonReadWordAt((u32*)(SP_DMEM_START + 0xC)); - } -} - -static void CleanupFromRCPop(int isVector) { - /* Restore RSP data that was saved to read or write registers */ - __rmonWriteWordTo((u32*)SP_DMEM_START, DMEMbuffer[0]); - if (isVector) { - __rmonWriteWordTo((u32*)(SP_DMEM_START + 0x4), DMEMbuffer[1]); - __rmonWriteWordTo((u32*)(SP_DMEM_START + 0x8), DMEMbuffer[2]); - /* BUG: the last word is not restored properly */ - __rmonWriteWordTo((u32*)(SP_DMEM_START + 0xC), DMEMbuffer[2]); - } - __rmonWriteWordTo((u32*)SP_IMEM_START, oldIMEMvalue); - __rmonWriteWordTo((u32*)SP_PC_REG, RCPpc); -} - -int __rmonGetGRegisters(KKHeader* req) { - register KKObjectRequest* request = (KKObjectRequest*)req; - KKGregEvent reply; - - STUBBED_PRINTF(("GetGRegisters\n")); - - reply.tid = request->object; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - - if (request->header.method == RMON_CPU) { - OSThread* tptr = __rmonGetTCB(request->object); - u64* tcbregptr; - register s32 i; - - if (tptr == NULL) { - return TV_ERROR_INVALID_ID; - } - - for (i = GREG_IDX_AT, tcbregptr = &tptr->context.at; i < GREG_IDX_K0; i++, tcbregptr++) { - reply.registers.gregs[i] = *tcbregptr; - } - for (i = GREG_IDX_GP, tcbregptr = &tptr->context.gp; i < GREG_IDX_CAUSE; i++, tcbregptr++) { - reply.registers.gregs[i] = *tcbregptr; - } - - reply.registers.gregs[GREG_IDX_CAUSE] = tptr->context.cause; - reply.registers.gregs[GREG_IDX_PC] = tptr->context.pc; - reply.registers.gregs[GREG_IDX_SR] = tptr->context.sr; - reply.registers.gregs[GREG_IDX_ZERO] = 0; - } else { - return TV_ERROR_INVALID_ID; - } - - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonSetGRegisters(KKHeader* req) { - register KKGRegsetRequest* request = (KKGRegsetRequest*)req; - KKObjectEvent reply; - - STUBBED_PRINTF(("SetGRegisters\n")); - - if (request->header.method == RMON_CPU) { - OSThread* tptr = __rmonGetTCB(request->tid); - u64* tcbregptr; - register int i; - - if (tptr == NULL) { - return TV_ERROR_INVALID_ID; - } - - for (i = GREG_IDX_AT, tcbregptr = &tptr->context.at; i < GREG_IDX_K0; i++, tcbregptr++) { - *tcbregptr = (s32)request->registers.gregs[i]; - } - - for (i = GREG_IDX_GP, tcbregptr = &tptr->context.gp; i < GREG_IDX_CAUSE; i++, tcbregptr++) { - *tcbregptr = (s32)request->registers.gregs[i]; - } - - tptr->context.cause = request->registers.gregs[GREG_IDX_CAUSE]; - tptr->context.pc = request->registers.gregs[GREG_IDX_PC]; - tptr->context.sr = request->registers.gregs[GREG_IDX_SR]; - } else { - return TV_ERROR_INVALID_ID; - } - - reply.object = request->tid; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonGetFRegisters(KKHeader* req) { - register KKObjectRequest* request = (KKObjectRequest*)req; - KKFPregEvent reply; - OSThread* tptr; - volatile float f UNUSED; - - STUBBED_PRINTF(("GetFRegisters\n")); - - if (req->method != RMON_CPU) { - return TV_ERROR_INVALID_ID; - } - - /* touch fpu to ensure registers are saved to the context structure */ - f = 0.0f; - - tptr = __rmonGetTCB(request->object); - if (tptr == NULL) { - return TV_ERROR_INVALID_ID; - } - - __rmonCopyWords((u32*)reply.registers.fpregs.regs, (u32*)&tptr->context.fp0, ARRLEN(reply.registers.fpregs.regs)); - - reply.registers.fpcsr = tptr->context.fpcsr; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.tid = request->object; - - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonSetFRegisters(KKHeader* req) { - register KKFPRegsetRequest* request = (KKFPRegsetRequest*)req; - KKObjectEvent reply; - OSThread* tptr; - volatile float f UNUSED; - - STUBBED_PRINTF(("SetFRegisters\n")); - - if (req->method != RMON_CPU) { - return TV_ERROR_INVALID_ID; - } - - /* touch fpu to ensure registers are saved to the context structure */ - f = 0.0f; - - tptr = __rmonGetTCB(request->tid); - if (tptr == NULL) { - return TV_ERROR_INVALID_ID; - } - - __rmonCopyWords((u32*)&tptr->context.fp0, (u32*)request->registers.fpregs.regs, - ARRLEN(request->registers.fpregs.regs)); - tptr->context.fpcsr = request->registers.fpcsr; - - reply.object = request->tid; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -static u32 rmonGetRcpRegister(int regNumber) { - u32 contents; - - if (__rmonRCPrunning()) { - return 0; - } - - SetUpForRCPop(FALSE); - LoadStoreSU(MIPS_SW_OPCODE, regNumber); - __rmonStepRCP(); - contents = __rmonReadWordAt((u32*)SP_DMEM_START); - CleanupFromRCPop(FALSE); - - return contents; -} - -int __rmonGetSRegs(KKHeader* req) { - register KKObjectRequest* request = (KKObjectRequest*)req; - KKCpSregEvent reply; - register int i; - - STUBBED_PRINTF(("GetSRegisters\n")); - - if (__rmonRCPrunning()) { - return TV_ERROR_OPERATIONS_PROTECTED; - } - - reply.tid = request->object; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - - SetUpForRCPop(FALSE); - for (i = SREG_IDX_ZERO; i <= SREG_IDX_RA; i++) { - LoadStoreSU(MIPS_SW_OPCODE, i); - __rmonStepRCP(); - reply.registers.sregs[i] = __rmonReadWordAt((u32*)SP_DMEM_START); - } - CleanupFromRCPop(FALSE); - - reply.registers.sregs[SREG_IDX_DRAM_ADDR] = __rmonReadWordAt((u32*)SP_DRAM_ADDR_REG); - reply.registers.sregs[SREG_IDX_MEM_ADDR] = __rmonReadWordAt((u32*)SP_MEM_ADDR_REG); - reply.registers.sregs[SREG_IDX_RD_LEN] = __rmonReadWordAt((u32*)SP_RD_LEN_REG); - reply.registers.sregs[SREG_IDX_PC] = __rmonReadWordAt((u32*)SP_PC_REG) + SP_IMEM_START; - reply.registers.sregs[SREG_IDX_WR_LEN] = __rmonReadWordAt((u32*)SP_WR_LEN_REG); - reply.registers.sregs[SREG_IDX_STATUS] = __rmonReadWordAt((u32*)SP_STATUS_REG); - reply.registers.sregs[SREG_IDX_DMA_FULL] = __rmonReadWordAt((u32*)SP_DMA_FULL_REG); - reply.registers.sregs[SREG_IDX_DMA_BUSY] = __rmonReadWordAt((u32*)SP_DMA_BUSY_REG); - - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonSetSRegs(KKHeader* req) { - register KKCpScalarRegsetRequest* request = (KKCpScalarRegsetRequest*)req; - KKObjectEvent reply; - register int i; - - STUBBED_PRINTF(("SetSRegisters\n")); - - if (__rmonRCPrunning()) { - return TV_ERROR_OPERATIONS_PROTECTED; - } - - SetUpForRCPop(FALSE); - for (i = SREG_IDX_ZERO; i <= SREG_IDX_RA; i++) { - __rmonWriteWordTo((u32*)SP_DMEM_START, request->registers.sregs[i]); - LoadStoreSU(MIPS_LW_OPCODE, i); - __rmonStepRCP(); - } - CleanupFromRCPop(FALSE); - - __rmonWriteWordTo((u32*)SP_DRAM_ADDR_REG, request->registers.sregs[SREG_IDX_DRAM_ADDR]); - __rmonWriteWordTo((u32*)SP_MEM_ADDR_REG, request->registers.sregs[SREG_IDX_MEM_ADDR]); - __rmonWriteWordTo((u32*)SP_PC_REG, request->registers.sregs[SREG_IDX_PC] & 0xFFF); - __rmonWriteWordTo((u32*)SP_WR_LEN_REG, request->registers.sregs[SREG_IDX_WR_LEN]); - __rmonWriteWordTo((u32*)SP_STATUS_REG, request->registers.sregs[SREG_IDX_STATUS]); - - reply.object = request->tid; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonGetVRegs(KKHeader* req) { - char* cPtr; - int sent; - int dataSize; - register KKObjectRequest* request = (KKObjectRequest*)req; - KKCpVregEvent reply; - register int i; - - STUBBED_PRINTF(("GetVRegisters\n")); - - if (__rmonRCPrunning()) { - return TV_ERROR_OPERATIONS_PROTECTED; - } - - reply.tid = request->object; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.header.length = sizeof(reply); - - dataSize = sizeof(reply); - cPtr = (char*)&dataSize; - sent = 0; - while (sent < (signed)sizeof(dataSize)) { - sent += __osRdbSend(cPtr + sent, sizeof(dataSize) - sent, RDB_TYPE_GtoH_DEBUG); - } - - __rmonSendHeader(&reply.header, VREG_SIZE, KK_TYPE_REPLY); - - SetUpForRCPop(TRUE); - for (i = 0; i < VREG_NUM; i++) { - LoadStoreVU(MIPS_SWC2_OPCODE, i); - __rmonStepRCP(); - __rmonSendData((void*)SP_DMEM_START, VREG_SIZE); - } - CleanupFromRCPop(TRUE); - - return TV_ERROR_NO_ERROR; -} - -int __rmonSetVRegs(KKHeader* req) { - register KKCpVectorRegsetRequest* request = (KKCpVectorRegsetRequest*)req; - KKObjectEvent reply; - register int i; - - STUBBED_PRINTF(("SetVRegs\n")); - - if (__rmonRCPrunning()) { - return TV_ERROR_OPERATIONS_PROTECTED; - } - - SetUpForRCPop(TRUE); - for (i = 0; i < VREG_NUM; i++) { - __rmonCopyWords((u32*)SP_DMEM_START, (u32*)&request->registers.vregs[i], VREG_SIZE / sizeof(u32)); - LoadStoreVU(MIPS_LWC2_OPCODE, i); - __rmonStepRCP(); - } - CleanupFromRCPop(TRUE); - - reply.object = request->tid; - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -u32 __rmonGetRegisterContents(int method, int threadNumber, int regNumber) { - if (method == RMON_CPU) { - /* CPU register */ - u32* regPointer; - OSThread* tptr; - - if (regNumber >= GREG_IDX_AT && regNumber < GREG_IDX_K0) { - regNumber -= GREG_IDX_AT - GREG_IDX_ZERO; - } else if (regNumber >= GREG_IDX_GP && regNumber < GREG_IDX_LO) { - regNumber -= GREG_IDX_GP - GREG_IDX_T9; - } else { - return 0; - } - tptr = __rmonGetTCB(threadNumber); - if (tptr == NULL) { - return 0; - } - regPointer = (u32*)&tptr->context; - regPointer += regNumber; - return *regPointer; - } else { - /* RSP register */ - return rmonGetRcpRegister(regNumber); - } -} - -#endif diff --git a/lib/ultralib/src/rmon/rmonsio.c b/lib/ultralib/src/rmon/rmonsio.c deleted file mode 100644 index 3e45995..0000000 --- a/lib/ultralib/src/rmon/rmonsio.c +++ /dev/null @@ -1,89 +0,0 @@ -#include "PR/os_version.h" - -#if BUILD_VERSION < VERSION_J -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -#ifndef _FINALROM - -#include "PR/os_internal.h" -#include "PR/ultraerror.h" -#include "PR/ultralog.h" -#include "PR/sptask.h" -#include "dbgproto.h" -#include "rmonint.h" -#include "PR/ramrom.h" -#include "PR/rdb.h" -#include "PR/rmon.h" - -#include "macros.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#endif - -static OSMesgQueue IOmq ALIGNED(8); -static OSMesg IOmsgs; - -void* __osRdb_DbgRead_Buf; -u8 rmonRdbReadBuf[RMON_DBG_BUF_SIZE] ALIGNED(0x10); - -void __rmonSendFault(OSThread* thread) { - volatile float f UNUSED; - u8* tPtr; - u32 sent = 0; - - /* touch fpu to ensure registers are saved to the context structure */ - f = 0.0f; - - tPtr = (u8*)thread; - while (sent < sizeof(OSThread)) { - sent += __osRdbSend(tPtr + sent, sizeof(OSThread) - sent, RDB_TYPE_GtoH_FAULT); - } -} - -void __rmonIOflush(void) { - int sent = 0; - char tstr[4]; - - while (sent <= 0) { - sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_DEBUG_DONE); - } -} - -void __rmonIOputw(u32 word) { - int sent = 0; - char* cPtr = (char*)&word; - - while (sent < 4) { - sent += __osRdbSend(cPtr + sent, sizeof(word) - sent, RDB_TYPE_GtoH_DEBUG); - } -} - -void __rmonIOhandler(void) { - int sent; - char tstr[4]; - - osCreateMesgQueue(&IOmq, &IOmsgs, 1); - osSetEventMesg(OS_EVENT_RDB_DBG_DONE, &IOmq, NULL); - __osRdb_DbgRead_Buf = rmonRdbReadBuf; - - while (TRUE) { - osRecvMesg(&IOmq, NULL, OS_MESG_BLOCK); - - __rmonExecute((KKHeader*)&rmonRdbReadBuf); - __osRdb_DbgRead_Buf = rmonRdbReadBuf; - - sent = 0; - while (sent <= 0) { - sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_DEBUG_READY); - } - } -} - -#endif diff --git a/lib/ultralib/src/rmon/rmontask.c b/lib/ultralib/src/rmon/rmontask.c deleted file mode 100644 index 25757a7..0000000 --- a/lib/ultralib/src/rmon/rmontask.c +++ /dev/null @@ -1,343 +0,0 @@ -#ifndef _FINALROM - -#include "dbgproto.h" -#include "PR/os_internal.h" -#include "rmonint.h" -#include "PR/rcp.h" -#include "PR/sptask.h" - -#include "macros.h" - -// TODO: this comes from a header -#if BUILD_VERSION >= VERSION_J -#ident "$Revision: 1.4 $" -#else -#ident "$Revision: 3.70 $" -#ident "$Revision: 1.5 $" -#ident "$Revision: 1.2 $" -#ident "$Revision: 1.4 $" -#ident "$Revision: 1.3 $" -#endif - -void __rmonMaskIdleThreadInts(void) { - register OSThread* tptr = __osGetActiveQueue(); - - while (tptr->priority != -1) { - if (tptr->priority == OS_PRIORITY_IDLE) { - tptr->context.sr &= ~OS_IM_CPU; - tptr->context.sr |= (OS_IM_RDBREAD | OS_IM_RDBWRITE | OS_IM_CART); - break; - } - tptr = tptr->tlnext; - } -} - -OSThread* __rmonGetTCB(int threadNumber) { - register OSThread* tptr = __osGetActiveQueue(); - - if (threadNumber < 1) { - return NULL; - } - - while (tptr->priority != -1) { - if (tptr->id == threadNumber) { - return tptr; - } - tptr = tptr->tlnext; - } - - return NULL; -} - -int __rmonStopUserThreads(int whichThread) { - register int whichOne = 0; - register OSThread* tptr = __osGetActiveQueue(); - - STUBBED_PRINTF(("StopThreads %d\n", whichThread)); - - if (whichThread != 0) { - /* Stop specified thread */ - - while (tptr->priority != -1) { - if (tptr->id == whichThread) { - break; - } - tptr = tptr->tlnext; - } - - if (tptr->priority == -1) { - return 0; - } - - if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { - osStopThread(tptr); - if (tptr->state != OS_STATE_STOPPED) { - STUBBED_PRINTF(("Couldn't stop thread %d\n", tptr->id)); - } - whichOne = whichThread; - } - } else { - /* Stop all threads */ - - while (tptr->priority != -1) { - if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { - osStopThread(tptr); - if (tptr->state != OS_STATE_STOPPED) { - STUBBED_PRINTF(("Couldn\'t stop thread %d\n", tptr->id)); - } - whichOne = -1; - } - tptr = tptr->tlnext; - } - } - return whichOne; -} - -int __rmonListThreads(KKHeader* req) { - register KKObjectRequest* request = (KKObjectRequest*)req; - KKObjsEvent* reply = (KKObjsEvent*)__rmonUtilityBuffer; - - STUBBED_PRINTF(("ListThreads\n")); - - reply->object = (request->object == -1) ? RMON_PID_CPU : request->object; - - if (req->method == RMON_RSP) { - reply->objs.number = 1; - reply->objs.objects[0] = RMON_TID_RSP; - } else { - register OSThread* tptr = __osGetActiveQueue(); - - reply->objs.number = 0; - - while (tptr->priority != -1) { - if (tptr->id != 0) { - reply->objs.objects[reply->objs.number] = tptr->id; - reply->objs.number++; - } - tptr = tptr->tlnext; - } - } - reply->header.code = request->header.code; - reply->header.error = TV_ERROR_NO_ERROR; - __rmonSendReply(&reply->header, sizeof(*reply) + sizeof(reply->objs.objects[0]) * (reply->objs.number - 1), - KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonGetThreadStatus(int method, int id, KKStatusEvent* reply) { - u32 inst; - - STUBBED_PRINTF(("ThreadStatus %d method %d\n", id, method)); - - reply->status.tid = id; - reply->status.pid = (method == RMON_RSP) ? RMON_PID_RSP : RMON_PID_CPU; - reply->status.why = 1; - reply->status.what = 0; - reply->status.info.major = 0; - reply->status.info.minor = 0; - reply->status.rv = 0; - - if (method == RMON_RSP) { - reply->status.start = SP_IMEM_START; - reply->status.priority = RMON_PRI_RSP; - - if (__rmonRCPrunning()) { - reply->status.flags = OS_STATE_RUNNING; - /* Cannot read RSP PC or current instruction while the RSP is running */ - reply->status.info.addr = 0; - reply->status.instr = 0; - } else { - reply->status.flags = OS_STATE_STOPPED; - reply->status.info.addr = __rmonReadWordAt((u32*)SP_PC_REG) + SP_IMEM_START; - inst = __rmonReadWordAt((u32*)reply->status.info.addr); - if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { - inst = MIPS_BREAK_OPCODE; - } - if (__rmonRcpAtBreak) { - /* Report RSP break */ - reply->status.why = 2; - reply->status.info.major = 2; - reply->status.info.minor = 4; - } - reply->status.instr = inst; - } - } else { - OSThread* tptr = __osGetActiveQueue(); - - while (tptr->priority != -1) { - if (tptr->id == id) { - break; - } - tptr = tptr->tlnext; - } - if (tptr->priority == -1) { - return TV_ERROR_INVALID_ID; - } - - reply->status.priority = tptr->priority; - reply->status.flags = (tptr->state != 0) ? tptr->state : OS_STATE_STOPPED; - reply->status.info.addr = tptr->context.pc; - - inst = *(u32*)(tptr->context.pc); - if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { - inst = MIPS_BREAK_OPCODE; - } - - reply->status.instr = inst; - reply->status.start = (int)tptr; - - if (tptr->flags & OS_FLAG_CPU_BREAK) { - /* Report break */ - reply->status.why = 2; - reply->status.info.major = 2; - reply->status.info.minor = 4; - } else if (tptr->flags & OS_FLAG_FAULT) { - /* Report fault */ - reply->status.why = 2; - reply->status.info.major = 1; - reply->status.info.minor = 2; - } - } - - return TV_ERROR_NO_ERROR; -} - -int __rmonThreadStatus(KKHeader* req) { - KKObjectRequest* request = (KKObjectRequest*)req; - KKStatusEvent reply; - - if (__rmonGetThreadStatus(req->method, request->object, &reply) != TV_ERROR_NO_ERROR) { - return TV_ERROR_INVALID_ID; - } - - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - return TV_ERROR_NO_ERROR; -} - -int __rmonStopThread(KKHeader* req) { - KKObjectRequest* request = (KKObjectRequest*)req; - KKStatusEvent reply; - u32* pc; - - STUBBED_PRINTF(("StopThread %d\n", request->object)); - - switch (req->method) { - case RMON_CPU: - __rmonStopUserThreads(request->object); - break; - case RMON_RSP: - if (__rmonRCPrunning()) { - /* Stop the rsp */ - __rmonIdleRCP(); - pc = (u32*)__rmonReadWordAt((u32*)SP_PC_REG); - if (pc == NULL) { - break; - } - pc--; - /* Check if the RSP is stopped in a branch delay slot, if it is step out of it. The RSP would otherwise - lose information about whether the branch should or should not be taken when reading registers. */ - if (__rmonGetBranchTarget(RMON_RSP, RMON_TID_RSP, (void*)((u32)pc + SP_IMEM_START)) % 4 == 0) { - __rmonStepRCP(); - } - } - break; - default: - return TV_ERROR_OPERATIONS_PROTECTED; - } - - if (__rmonGetThreadStatus(req->method, request->object, &reply) != TV_ERROR_NO_ERROR) { - return TV_ERROR_INVALID_ID; - } - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - if (reply.status.flags == OS_STATE_STOPPED) { - reply.header.code = KK_CODE_THREAD_STATUS; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_EXCEPTION); - } - return TV_ERROR_NO_ERROR; -} - -int __rmonRunThread(KKHeader* req) { - KKRunThreadRequest* request = (KKRunThreadRequest*)req; - KKObjectEvent reply; - KKStatusEvent exceptionReply; - register OSThread* tptr; - register int runNeeded = FALSE; - - STUBBED_PRINTF(("RunThread %d\n", request->tid)); - - switch (req->method) { - case RMON_CPU: - tptr = __osGetActiveQueue(); - while (tptr->priority != -1) { - if (tptr->id == request->tid) { - break; - } - tptr = tptr->tlnext; - } - - if (tptr->priority == -1) { - return TV_ERROR_INVALID_ID; - } - if (tptr->state != OS_STATE_STOPPED) { - return TV_ERROR_OPERATIONS_PROTECTED; - } - tptr->flags &= ~(OS_FLAG_CPU_BREAK | OS_FLAG_FAULT); - if (request->actions.flags & KK_RUN_SETPC) { - tptr->context.pc = request->actions.vaddr; - } - if ((request->actions.flags & KK_RUN_SSTEP) && !__rmonSetSingleStep(request->tid, (u32*)tptr->context.pc)) { - return TV_ERROR_OPERATIONS_PROTECTED; - } - runNeeded = TRUE; - break; - case RMON_RSP: - if (__rmonRCPrunning()) { - return TV_ERROR_OPERATIONS_PROTECTED; - } - if (request->actions.flags & KK_RUN_SETPC) { - __rmonWriteWordTo((u32*)SP_PC_REG, request->actions.vaddr - SP_IMEM_START); - } - if (request->actions.flags & KK_RUN_SSTEP) { - /* If the RSP is stopped at a branch step twice so as to not stop in a branch delay slot. */ - if (__rmonGetBranchTarget(RMON_RSP, RMON_TID_RSP, - (void*)(__rmonReadWordAt((u32*)SP_PC_REG) + SP_IMEM_START)) % - 4 == - 0) { - __rmonStepRCP(); - } - __rmonStepRCP(); - __rmonRcpAtBreak = TRUE; - } else { - __rmonRcpAtBreak = FALSE; - __rmonRunRCP(); - } - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.object = request->tid; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - if (request->actions.flags & KK_RUN_SSTEP) { - __rmonGetThreadStatus(RMON_RSP, RMON_TID_RSP, &exceptionReply); - __rmonGetExceptionStatus(&exceptionReply); - __rmonSendReply(&exceptionReply.header, sizeof(exceptionReply), KK_TYPE_EXCEPTION); - } - return TV_ERROR_NO_ERROR; - default: - return TV_ERROR_OPERATIONS_PROTECTED; - } - - reply.header.code = request->header.code; - reply.header.error = TV_ERROR_NO_ERROR; - reply.object = request->tid; - __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); - - if (runNeeded) { - osStartThread(tptr); - } - return 1; -} - -#endif diff --git a/lib/ultralib/src/sched/Makefile b/lib/ultralib/src/sched/Makefile deleted file mode 100644 index d4cd659..0000000 --- a/lib/ultralib/src/sched/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -#!smake -# -# Makefile for the scheduler subdirectory -# - -include $(ROOT)/usr/include/make/PRdefs - - -# LCOPTS = -mips2 -non_shared -fullwarn -G 0 -LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include - -CFILES = \ - sched.c - -OBJECTS = $(CFILES:.c=.o) - -default: $(OBJECTS) - -include $(COMMONRULES) diff --git a/lib/ultralib/src/sched/sched.c b/lib/ultralib/src/sched/sched.c deleted file mode 100644 index 70ebf55..0000000 --- a/lib/ultralib/src/sched/sched.c +++ /dev/null @@ -1,620 +0,0 @@ -/*==================================================================== - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ -#include -#include -#include -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -/* - * private typedefs and defines - */ -#define VIDEO_MSG 666 -#define RSP_DONE_MSG 667 -#define RDP_DONE_MSG 668 -#define PRE_NMI_MSG 669 - -/* - * OSScTask state - */ -#define OS_SC_DP 0x0001 /* set if still needs dp */ -#define OS_SC_SP 0x0002 /* set if still needs sp */ -#define OS_SC_YIELD 0x0010 /* set if yield requested */ -#define OS_SC_YIELDED 0x0020 /* set if yield completed */ - -/* - * OSScTask->flags type identifier - */ -#define OS_SC_XBUS (OS_SC_SP | OS_SC_DP) -#define OS_SC_DRAM (OS_SC_SP | OS_SC_DP | OS_SC_DRAM_DLIST) -#define OS_SC_DP_XBUS (OS_SC_SP) -#define OS_SC_DP_DRAM (OS_SC_SP | OS_SC_DRAM_DLIST) -#define OS_SC_SP_XBUS (OS_SC_DP) -#define OS_SC_SP_DRAM (OS_SC_DP | OS_SC_DRAM_DLIST) - -/* - * private functions - */ -static void __scMain(void *arg); -static void __scHandleRetrace(OSSched *s); -static void __scHandleRSP(OSSched *s); -static void __scHandleRDP(OSSched *s); - -static void __scAppendList(OSSched *s, OSScTask *t); -OSScTask *__scTaskReady(OSScTask *t); -static s32 __scTaskComplete(OSSched *s,OSScTask *t); -static void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp); -static void __scYield(OSSched *s); -static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, - s32 availRCP); - - -/* -#define SC_LOGGING 1 -*/ - - -#ifdef SC_LOGGING -#define SC_LOG_LEN 32*1024 -static OSLog scLog; -static OSLog *l = &scLog; -static u32 logArray[SC_LOG_LEN/sizeof(u32)]; -#endif - -/*********************************************************************** - * Scheduler API - **********************************************************************/ -void osCreateScheduler(OSSched *sc, void *stack, OSPri priority, - u8 mode, u8 numFields) -{ - sc->curRSPTask = 0; - sc->curRDPTask = 0; - sc->clientList = 0; - sc->frameCount = 0; - sc->audioListHead = 0; - sc->gfxListHead = 0; - sc->audioListTail = 0; - sc->gfxListTail = 0; - sc->retraceMsg.type = OS_SC_RETRACE_MSG; /* sent to apps */ - sc->prenmiMsg.type = OS_SC_PRE_NMI_MSG; - - osCreateMesgQueue(&sc->interruptQ, sc->intBuf, OS_SC_MAX_MESGS); - osCreateMesgQueue(&sc->cmdQ, sc->cmdMsgBuf, OS_SC_MAX_MESGS); - - /* - * Set up video manager, listen for Video, RSP, and RDP interrupts - */ - osCreateViManager(OS_PRIORITY_VIMGR); - osViSetMode(&osViModeTable[mode]); - osViBlack(TRUE); - osSetEventMesg(OS_EVENT_SP, &sc->interruptQ, (OSMesg)RSP_DONE_MSG); - osSetEventMesg(OS_EVENT_DP, &sc->interruptQ, (OSMesg)RDP_DONE_MSG); - osSetEventMesg(OS_EVENT_PRENMI, &sc->interruptQ, (OSMesg)PRE_NMI_MSG); - - osViSetEvent(&sc->interruptQ, (OSMesg)VIDEO_MSG, numFields); - -#ifdef SC_LOGGING - osCreateLog(l, logArray, sizeof(logArray)); -#endif - - osCreateThread(&sc->thread, 4, __scMain, (void *)sc, stack, priority); - osStartThread(&sc->thread); -} - -/* - * Add a client to the scheduler. Clients receive messages at retrace time - */ -void osScAddClient(OSSched *sc, OSScClient *c, OSMesgQueue *msgQ) -{ - OSIntMask mask; - - mask = osSetIntMask(OS_IM_NONE); - - c->msgQ = msgQ; - c->next = sc->clientList; - sc->clientList = c; - - osSetIntMask(mask); -} - -void osScRemoveClient(OSSched *sc, OSScClient *c) -{ - OSScClient *client = sc->clientList; - OSScClient *prev = 0; - OSIntMask mask; - - mask = osSetIntMask(OS_IM_NONE); - - while (client != 0) { - if (client == c) { - if(prev) - prev->next = c->next; - else - sc->clientList = c->next; - break; - } - prev = client; - client = client->next; - } - - osSetIntMask(mask); -} - -OSMesgQueue *osScGetCmdQ(OSSched *sc) -{ - return &sc->cmdQ; -} - -/*********************************************************************** - * Scheduler implementation - **********************************************************************/ -static void __scMain(void *arg) -{ - OSMesg msg; - OSSched *sc = (OSSched *)arg; - OSScClient *client; - static int count = 0; - - while (1) { - - osRecvMesg(&sc->interruptQ, (OSMesg *)&msg, OS_MESG_BLOCK); - -#ifdef SC_LOGGING - if (++count % 1024 == 0) - osFlushLog(l); -#endif - - - switch ((int) msg) { - case (VIDEO_MSG): - __scHandleRetrace(sc); - break; - - case (RSP_DONE_MSG): - __scHandleRSP(sc); - break; - - case (RDP_DONE_MSG): - __scHandleRDP(sc); - break; - - case (PRE_NMI_MSG): - /* - * notify audio and graphics threads to fade out - */ - for (client = sc->clientList;client != 0;client = client->next) { - osSendMesg(client->msgQ, (OSMesg) &sc->prenmiMsg, - OS_MESG_NOBLOCK); - } - break; - } - } -} - -/* - * scHandleRetrace() - */ -static int dp_busy = 0; -static int dpCount = 0; - -void __scHandleRetrace(OSSched *sc) -{ - OSScTask *rspTask; - OSScClient *client; - s32 i; - s32 state; - OSScTask *sp = 0; - OSScTask *dp = 0; - - sc->frameCount++; - -#ifdef SC_LOGGING - osLogEvent(l, 500, 4, sc->frameCount, sc->curRSPTask, sc->curRDPTask); -#endif - - /* - * Read the task command queue and schedule tasks - */ - while (osRecvMesg(&sc->cmdQ, (OSMesg *)&rspTask, OS_MESG_NOBLOCK) != -1) { - __scAppendList(sc, rspTask); - } - - if (sc->doAudio && sc->curRSPTask) { - /* - * Preempt the running gfx task. Note: if the RSP - * component of the graphics task has finished, but the - * RDP component is still running, we can start an audio - * task which will freeze the RDP (and save the RDP cmd - * FIFO) while the audio RSP code is running. - */ - __scYield(sc); - } else { - state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); - if ( __scSchedule (sc, &sp, &dp, state) != state) - __scExec(sc, sp, dp); - } - - /* - * notify audio and graphics threads to start building the command - * lists for the next frame (client threads may choose not to - * build the list in overrun case) - */ - for (client = sc->clientList; client != 0; client = client->next) { - osSendMesg(client->msgQ, (OSMesg) &sc->retraceMsg, OS_MESG_NOBLOCK); - } -} - -/* - * __scHandleRSP is called when an RSP task signals that it has - * finished or yielded (at the hosts request) - */ -void __scHandleRSP(OSSched *sc) -{ - OSScTask *t, *sp = 0, *dp = 0; - s32 state; - - - assert(sc->curRSPTask); - - t = sc->curRSPTask; - sc->curRSPTask = 0; - -#ifdef SC_LOGGING - osLogEvent(l, 510, 3, t, t->state, t->flags); -#endif - - if ((t->state & OS_SC_YIELD) && osSpTaskYielded(&t->list)) { - t->state |= OS_SC_YIELDED; -#ifndef _FINALROM - t->totalTime += osGetTime() - t->startTime; -#endif - if ((t->flags & OS_SC_TYPE_MASK) == OS_SC_XBUS) { - /* push the task back on the list */ - t->next = sc->gfxListHead; - sc->gfxListHead = t; - if (sc->gfxListTail == 0) - sc->gfxListTail = t; - } - -#ifdef SC_LOGGING - osLogEvent(l, 521, 1, t); -#endif - - } else { - t->state &= ~OS_SC_NEEDS_RSP; - __scTaskComplete(sc, t); - } - - state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); - if ( (__scSchedule (sc, &sp, &dp, state)) != state) - __scExec(sc, sp, dp); -} - -/* - * __scHandleRDP is called when an RDP task signals that it has - * finished - */ -void __scHandleRDP(OSSched *sc) -{ - OSScTask *t, *sp = 0, *dp = 0; - s32 state; - - assert(sc->curRDPTask); - assert(sc->curRDPTask->list.t.type == M_GFXTASK); - - t = sc->curRDPTask; - sc->curRDPTask = 0; - -#ifdef SC_LOGGING - osLogEvent(l, 515, 3, t, t->state, t->flags); -#endif - - t->state &= ~OS_SC_NEEDS_RDP; - - __scTaskComplete(sc, t); - - state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); - if ( (__scSchedule (sc, &sp, &dp, state)) != state) - __scExec(sc, sp, dp); -} - -/* - * __scTaskReady checks to see if the graphics task is able to run - * based on the current state of the RCP. - */ -OSScTask *__scTaskReady(OSScTask *t) -{ - int rv = 0; - void *a; - void *b; - - if (t) { - /* - * If there is a pending swap bail out til later (next - * retrace). - */ - if ((a=osViGetCurrentFramebuffer()) != (b=osViGetNextFramebuffer())) { -#ifdef SC_LOGGING - osLogEvent(l, 513, 2, a, b); -#endif - return 0; - } - - return t; - } - - return 0; -} - -/* - * __scTaskComplete checks to see if the task is complete (all RCP - * operations have been performed) and sends the done message to the - * client if it is. - */ -s32 __scTaskComplete(OSSched *sc, OSScTask *t) -{ - int rv; - static int firsttime = 1; - - if ((t->state & OS_SC_RCP_MASK) == 0) { /* none of the needs bits set */ - - assert (t->msgQ); - -#ifndef _FINALROM - t->totalTime += osGetTime() - t->startTime; -#endif - -#ifdef SC_LOGGING - osLogEvent(l, 504, 1, t); -#endif - rv = osSendMesg(t->msgQ, t->msg, OS_MESG_BLOCK); - - if (t->list.t.type == M_GFXTASK) { - if ((t->flags & OS_SC_SWAPBUFFER) && (t->flags & OS_SC_LAST_TASK)){ - if (firsttime) { - osViBlack(FALSE); - firsttime = 0; - } - osViSwapBuffer(t->framebuffer); -#ifdef SC_LOGGING - osLogEvent(l, 525, 1, t->framebuffer); -#endif - } - } - return 1; - } - - return 0; -} - -/* - * Place task on either the audio or graphics queue - */ -void __scAppendList(OSSched *sc, OSScTask *t) -{ - long type = t->list.t.type; - - assert ( (type == M_AUDTASK) || (type == M_GFXTASK)); - - if (type == M_AUDTASK) { - if (sc->audioListTail) - sc->audioListTail->next = t; - else - sc->audioListHead = t; - - sc->audioListTail = t; - sc->doAudio = 1; -#ifdef SC_LOGGING - osLogEvent(l, 506, 1, t); -#endif - } else { - if (sc->gfxListTail) - sc->gfxListTail->next = t; - else - sc->gfxListHead = t; - - sc->gfxListTail = t; -#ifdef SC_LOGGING - osLogEvent(l, 507, 1, t); -#endif - } - - t->next = NULL; - t->state = t->flags & OS_SC_RCP_MASK; -} - -/* - * - */ -void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp) -{ - int rv; - -#ifdef SC_LOGGING - osLogEvent(l, 511, 2, sp, dp); -#endif - - assert(sc->curRSPTask == 0); - - if (sp) { - if (sp->list.t.type == M_AUDTASK) { - osWritebackDCacheAll(); /* flush the cache */ - } - - sp->state &= ~(OS_SC_YIELD | OS_SC_YIELDED); -#ifndef _FINALROM - sp->startTime = osGetTime(); -#endif - osSpTaskLoad(&sp->list); - osSpTaskStartGo(&sp->list); - sc->curRSPTask = sp; - if (sp == dp) - sc->curRDPTask = dp; - } - - if (dp && (dp != sp)) { - assert(dp->list.t.output_buff); - -#ifdef SC_LOGGING - osLogEvent(l, 523, 3, dp, dp->list.t.output_buff, - (u32)*dp->list.t.output_buff_size); -#endif - rv = osDpSetNextBuffer(dp->list.t.output_buff, - *dp->list.t.output_buff_size); - - dp_busy = 1; - dpCount = 0; - - assert(rv == 0); - - sc->curRDPTask = dp; - } -} - -static void __scYield(OSSched *sc) -{ - -#ifdef SC_LOGGING - osLogEvent(l, 503, 1, sc->curRSPTask ); -#endif - - if (sc->curRSPTask->list.t.type == M_GFXTASK) { - -/* assert(sc->curRSPTask->state & OS_SC_YIELD);*/ - - sc->curRSPTask->state |= OS_SC_YIELD; - - osSpTaskYield(); - } else { -#ifdef SC_LOGGING - osLogEvent(l, 508, 1, sc->curRSPTask); -#endif - } -} - -/* - * Schedules the tasks to be run on the RCP - */ -s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) -{ - s32 avail = availRCP; - OSScTask *gfx = sc->gfxListHead; - OSScTask *audio = sc->audioListHead; - -#ifdef SC_LOGGING - osLogEvent(l, 517, 3, *sp, *dp, availRCP); -#endif - - if (sc->doAudio && (avail & OS_SC_SP)) { - - if (gfx && (gfx->flags & OS_SC_PARALLEL_TASK)) { - *sp = gfx; - avail &= ~OS_SC_SP; - } else { - *sp = audio; - avail &= ~OS_SC_SP; - sc->doAudio = 0; - sc->audioListHead = sc->audioListHead->next; - if (sc->audioListHead == NULL) - sc->audioListTail = NULL; - } - } else { -#ifdef SC_LOGGING - osLogEvent(l, 520, 1, gfx); -#endif - if (__scTaskReady(gfx)) { - -#ifdef SC_LOGGING - osLogEvent(l, 522, 3, gfx, gfx->state, gfx->flags); -#endif - switch (gfx->flags & OS_SC_TYPE_MASK) { - case (OS_SC_XBUS): - if (gfx->state & OS_SC_YIELDED) { -#ifdef SC_LOGGING - osLogEvent(l, 518, 0); -#endif - /* can hit this if RDP finishes at yield req */ - /* assert(gfx->state & OS_SC_DP); */ - - if (avail & OS_SC_SP) { /* if SP is available */ -#ifdef SC_LOGGING - osLogEvent(l, 519, 0); -#endif - *sp = gfx; - avail &= ~OS_SC_SP; - - if (gfx->state & OS_SC_DP) { /* if it needs DP */ - *dp = gfx; - avail &= ~OS_SC_DP; - - if (avail & OS_SC_DP == 0) - assert(sc->curRDPTask == gfx); - - } - - sc->gfxListHead = sc->gfxListHead->next; - if (sc->gfxListHead == NULL) - sc->gfxListTail = NULL; - - } - } else { - if (avail == (OS_SC_SP | OS_SC_DP)) { - *sp = *dp = gfx; - avail &= ~(OS_SC_SP | OS_SC_DP); - sc->gfxListHead = sc->gfxListHead->next; - if (sc->gfxListHead == NULL) - sc->gfxListTail = NULL; - } - } - - break; - - case (OS_SC_DRAM): - case (OS_SC_DP_DRAM): - case (OS_SC_DP_XBUS): - if (gfx->state & OS_SC_SP) { /* if needs SP */ - if (avail & OS_SC_SP) { /* if SP is available */ - *sp = gfx; - avail &= ~OS_SC_SP; - } - } else if (gfx->state & OS_SC_DP) { /* if needs DP */ - if (avail & OS_SC_DP) { /* if DP available */ - *dp = gfx; - avail &= ~OS_SC_DP; - sc->gfxListHead = sc->gfxListHead->next; - if (sc->gfxListHead == NULL) - sc->gfxListTail = NULL; - } - } - break; - - case (OS_SC_SP_DRAM): - case (OS_SC_SP_XBUS): - default: - break; - } - } - } - - if (avail != availRCP) - avail = __scSchedule(sc, sp, dp, avail); - - return avail; - -} - diff --git a/lib/ultralib/src/sched/sched_log.fmt b/lib/ultralib/src/sched/sched_log.fmt deleted file mode 100644 index 50e042d..0000000 --- a/lib/ultralib/src/sched/sched_log.fmt +++ /dev/null @@ -1,19 +0,0 @@ -500 "__scHandleRetrace: framecount %d, curRSPTask 0x%x, curRDPTask 0x%x" -510 "__scHandleRSP: Current 0x%x state 0x%x flags 0x%x" -521 "__scHandleRSP: Yielded Task 0x%x" -515 "__scHandleRDP: Current 0x%x state 0x%x flags 0x%x" -513 "__scTaskReady: Pending swap bail - current 0x%x next 0x%x" -514 "__scTaskReady: Rendering bail - current 0x%x" -504 "__scTaskComplete: Task 0x%x" -525 "__scTaskComplete: Swapbuffer 0x%x" -506 "__scAppendList: Audio task 0x%x" -507 "__scAppendList: Gfx task 0x%x" -511 "__scExec: sp 0x%x, dp 0x%x" -523 "__scExec: DP only buf 0x%x, size %d" -503 "__scYield: curRSPtask 0x%x" -508 "__scYield: NOT A GFX TASK!! curRSPtask 0x%x" -517 "__scSchedule: sp 0x%x, dp 0x%x, avail 0x%x" -520 "__scSchedule: gfx task 0x%x" -522 "__scSchedule: gfx task ready 0x%x, state 0x%x, flags 0x%x" -518 "__scSchedule: Yielded" -519 "__scSchedule: SP available" diff --git a/lib/ultralib/src/sp/Makefile b/lib/ultralib/src/sp/Makefile deleted file mode 100644 index 7807431..0000000 --- a/lib/ultralib/src/sp/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -#!smake -# -# Makefile for the sp subdirectory -# - -include $(ROOT)/usr/include/make/PRdefs - - -# LCOPTS = -mips2 -non_shared -fullwarn -G 0 -LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include - -CFILES = \ - clearattribute.c \ - color.c \ - hide.c \ - setattribute.c \ - show.c \ - sprite.c \ - spriteex.c \ - spriteex2.c \ - spscale.c - - -ASFILES = - -OBJECTS = $(CFILES:.c=.o) - -default: $(OBJECTS) - -include $(COMMONRULES) diff --git a/lib/ultralib/src/sp/clearattribute.c b/lib/ultralib/src/sp/clearattribute.c deleted file mode 100644 index e5faf16..0000000 --- a/lib/ultralib/src/sp/clearattribute.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - */ - -#include - -/* - * spClearAttribute() - * - * Clears attributes about a sprite. - */ -void -spClearAttribute (Sprite *sp, s32 attr) -{ - sp->attr &= ~attr; -} diff --git a/lib/ultralib/src/sp/color.c b/lib/ultralib/src/sp/color.c deleted file mode 100644 index a5abc85..0000000 --- a/lib/ultralib/src/sp/color.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - */ - -#include - -/* - * spColor() - * - * Sets the color for IA or I images. - */ -void -spColor (Sprite *sp, unsigned char red, unsigned char green, - unsigned char blue, unsigned char alpha) -{ - sp->red = red; - sp->green = green; - sp->blue = blue; - sp->alpha = alpha; -} diff --git a/lib/ultralib/src/sp/hide.c b/lib/ultralib/src/sp/hide.c deleted file mode 100644 index 6223c2c..0000000 --- a/lib/ultralib/src/sp/hide.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - */ - -#include - -/* - * spHide() - * - * Hides a sprite so that it will not be drawn at the next spUpdate(). - */ -void -spHide (Sprite *sp) -{ - spSetAttribute (sp, SP_HIDDEN); -} diff --git a/lib/ultralib/src/sp/setattribute.c b/lib/ultralib/src/sp/setattribute.c deleted file mode 100644 index 887df08..0000000 --- a/lib/ultralib/src/sp/setattribute.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - */ - -#include - -/* - * spSetAttribute() - * - * Sets attributes about a sprite. - */ -void -spSetAttribute ( Sprite *sp, s32 attr) -{ - sp->attr |= attr; -} diff --git a/lib/ultralib/src/sp/show.c b/lib/ultralib/src/sp/show.c deleted file mode 100644 index dc0db54..0000000 --- a/lib/ultralib/src/sp/show.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - */ - -#include - -/* - * spShow() - * - * Shows a sprite so that it will be drawn at the next spUpdate(). - */ -void -spShow (Sprite *sp) -{ - spClearAttribute (sp, SP_HIDDEN); -} diff --git a/lib/ultralib/src/sp/sprite.c b/lib/ultralib/src/sp/sprite.c deleted file mode 100644 index 719a662..0000000 --- a/lib/ultralib/src/sp/sprite.c +++ /dev/null @@ -1,761 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - */ -#include -#include -#include -// TODO: this comes from a header -#ident "$Revision: 1.17 $" - -/* - * spSetZ() - * - */ -void -spSetZ (Sprite *sp, s32 z) -{ - -#ifdef DEBUG - emPrintf("spSetZ (Sprite 0x%08x, (%d))\n", sp, z ); -#endif - - sp->zdepth = (s16)z; -} - -/* - * spMove() - * - * Moves a sprite on the screen. - */ -void -spMove (Sprite *sp, s32 x, s32 y) -{ - -#ifdef DEBUG - emPrintf("spMove (Sprite 0x%08x, (%d,%d))\n", sp, x, y ); -#endif - - sp->x = (s16)x; - sp->y = (s16)y; -} - -static s32 scissor_xmax; -static s32 scissor_ymax; - -static s32 scissor_xmin; -static s32 scissor_ymin; - -/* - * spScissor() - * - * Sets the scissoring box to be used for subsequent Sprite Drawing - */ -void -spScissor (s32 xmin, s32 xmax, s32 ymin, s32 ymax ) -{ - scissor_xmin = xmin; - scissor_ymin = ymin; - - scissor_xmax = xmax; - scissor_ymax = ymax; -} - -static int *prev_bmbuf = NULL; - -/* - * drawbitmap() - * - * Draws a bitmap from a sprite at a location on the screen. If the - * "usevert" flag is set, then the routine will use vertices and triangles - * to draw the bitmap. Otherwise, the texture rectangle instruction - * will be used. - */ - -static void -drawbitmap (Gfx **glp, Sprite *s, Bitmap *b, - s32 x, s32 y, s32 xx, s32 yy, s32 fs, s32 ft, s32 sx, s32 sy) -{ - s32 rs, rt; - s32 rxh, ryh; - s32 rxl, ryl; - Gfx *gl; - s32 tex_width, tex_height; - Gtexrect gt, *g; - s32 s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod; - - g = > - - tex_width = b->width_img; - tex_height= s->bmHreal; - -#ifdef rmDEBUG - rmonPrintf("\tdrawbitmap (buf= 0x%08x; x,y= %d,%d; w,h= %d,%d )\n", - b->buf, x, y, b->width, s->bmheight ); -#endif - gl = *glp; - - /* Scissoring */ - if( (x >= scissor_xmax) || (y >= scissor_ymax) ) { -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: Upper Left corner (%d,%d) beyond range (%d,%d)\n", - x, y, scissor_xmax, scissor_ymax ); -#endif - return; - } - - if( (xx < scissor_xmin) || (yy < scissor_ymin) ) { -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: Lower Right corner (%d,%d) not in range (%d,%d)\n", - xx, yy, scissor_xmin, scissor_ymin ); -#endif - return; - } - - - if (x < scissor_xmin) { - rxh = scissor_xmin*4; - rs = (b->s<<5) + fs + (((scissor_xmin - x)*sx)>>5); -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: Left Edge (%d) not in range (%d,%d)\n", - x, scissor_xmin, scissor_xmax ); -#endif - } else { - rxh = x*4; - rs = (b->s<<5) + fs; - }; - - if (y < scissor_ymin) { - ryh = scissor_ymin*4; - rt = (b->t<<5) + ft + (((scissor_ymin-y)*sy)>>5); -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: Top Edge (%d) not in range (%d,%d)\n", - y, scissor_ymin, scissor_ymax ); -#endif - } else { - ryh = y*4; - rt = (b->t<<5) + ft; - } - - if( xx >= scissor_xmax ) { - rxl = scissor_xmax*4; -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: Right Edge (%d) not in range (%d,%d)\n", - xx, scissor_xmin, scissor_xmax ); -#endif - } else { - rxl = xx*4; - }; - - if( yy >= scissor_ymax ) { - ryl = scissor_ymax*4; -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: Bottom Edge (%d) not in range (%d,%d)\n", - yy, scissor_ymin, scissor_ymax ); -#endif - } else { - ryl = yy*4; - }; - - s_clamp = G_TX_CLAMP; t_clamp = G_TX_CLAMP; - s_mask = G_TX_NOMASK; t_mask = G_TX_NOMASK; - s_lod = G_TX_NOLOD; t_lod = G_TX_NOLOD; - -#define LOAD_TEX - -#ifdef LOAD_TEX - if( b->buf != prev_bmbuf ) { - switch(s->bmsiz) - { -#if BUILD_VERSION >= VERSION_J - case G_IM_SIZ_DD: - gDPLoadTextureTile_4b(gl++, b->buf, s->bmfmt, tex_width, tex_height, - b->s, b->t, - b->s + b->width,b->t + b->actualHeight, - 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - break; -#endif - case G_IM_SIZ_4b: - if (s->attr & SP_TEXSHUF) { - gDPLoadTextureBlock_4bS(gl++, b->buf, s->bmfmt, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - } else { - gDPLoadTextureBlock_4b(gl++, b->buf, s->bmfmt, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - }; - break; - - case G_IM_SIZ_8b: - if (s->attr & SP_TEXSHUF) { - gDPLoadTextureBlockS(gl++, b->buf, s->bmfmt, G_IM_SIZ_8b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - } else { - gDPLoadTextureBlock(gl++, b->buf, s->bmfmt, G_IM_SIZ_8b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - }; - break; - case G_IM_SIZ_16b: - if (s->bmfmt == G_IM_FMT_YUV ) { - if (s->attr & SP_TEXSHUF) { - gDPLoadTextureBlockYuvS(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - } else { - if( b->LUToffset != 0 ) { /* Split Y and UV areas */ - unsigned char *uv, *addr; - int j; - s32 tmem, siz; - - gDPSetTextureImage( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 1, b->buf); - gDPSetTile( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 0, 256, G_TX_LOADTILE, 0, - t_clamp, t_mask, t_lod, - s_clamp, s_mask, s_lod ); - gDPLoadSync( gl++ ); - gDPLoadBlock( gl++, G_TX_LOADTILE, 0,0, tex_width*tex_height -1, - CALC_DXT(tex_width,1) ); - gDPLoadSync( gl++ ); - - uv = ((unsigned char *)b->buf) + - ((tex_width*tex_height)/2)*b->LUToffset; - - for( j=0; j<=(tex_height/2); j++ ) { - addr = uv + ((tex_height/2) -2 -j)*tex_width; - siz = 3*tex_width; - tmem = (tex_width/8)*(tex_height - 2 - 2*j); - if( tmem < 0 ) { - addr += (-tmem)*8; - siz -= (-tmem)*8; - tmem = 0; - }; - if( j == 0 ) - siz = 2*tex_width; - - gDPSetTextureImage( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 1, addr); - gDPSetTile( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 0, tmem, - G_TX_LOADTILE, 0, - t_clamp, t_mask, t_lod, - s_clamp, s_mask, s_lod ); - gDPLoadSync( gl++ ); - gDPLoadBlock( gl++, G_TX_LOADTILE, 0,0, siz -1, - CALC_DXT(tex_width,1) ); - gDPLoadSync( gl++ ); - }; - - gDPSetTile( gl++, s->bmfmt, G_IM_SIZ_16b, (((tex_width) * 1)+7)>>3, 0, - G_TX_RENDERTILE, 0, - t_clamp, t_mask, t_lod, - s_clamp, s_mask, s_lod ); - gDPSetTileSize( gl++, G_TX_RENDERTILE, 0, 0, - ((tex_width)-1) << G_TEXTURE_IMAGE_FRAC, - ((tex_height)-1) << G_TEXTURE_IMAGE_FRAC ); - - } else { - gDPLoadTextureBlockYuv(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - }; - }; - } else { - if (s->attr & SP_TEXSHUF) { - gDPLoadTextureBlockS(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - } else { - gDPLoadTextureBlock(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - }; - }; - break; - case G_IM_SIZ_32b: - if (s->attr & SP_TEXSHUF) { - gDPLoadTextureBlockS(gl++, b->buf, s->bmfmt, G_IM_SIZ_32b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - } else { - gDPLoadTextureBlock(gl++, b->buf, s->bmfmt, G_IM_SIZ_32b, - tex_width, tex_height, 0, - s_clamp, t_clamp, - s_mask, t_mask, - s_lod, t_lod); - }; - break; - } - prev_bmbuf = b->buf; - } -#endif /* LOAD_TEX */ - - - g->cmd = G_TEXRECT; - g->tile = 0; - - g->xh = rxh; - g->xl = rxl; - g->yh = ryh; - g->yl = ryl; - - g->s = rs; - g->t = rt; - - if ((s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) - g->dsdx = sx * 4; - else - g->dsdx = sx; - - g->dtdy = sy; - -#ifdef rmDEBUG - rmonPrintf("\trect (xh,l= %d,%d, yh,l= %d,%d, s,t= %d,%d, dsdx=%d, dtdy=%d )\n", - rxh,rxl,ryh,ryl,rs,rt,g->dsdx,sy ); -#endif - - gSPTextureRectangle(gl++,g->xh,g->yh,g->xl,g->yl,g->tile,g->s,g->t,g->dsdx,g->dtdy); - - gDPPipeSync(gl++); - - *glp = gl; -} - -static u16 sp_attr = 0; - -void -spInit( Gfx **glistp ) -{ - Gfx *gl; - - gl = *glistp; - -#ifdef DEBUG - emPrintf("spInit ()\n" ); -#endif - sp_attr = 0; - - scissor_xmin = 0; - scissor_ymin = 0; - - scissor_xmax = 320; - scissor_ymax = 240; - - /* Turn on texturing */ - gDPPipeSync ( gl++ ); - gDPSetCycleType ( gl++, G_CYC_1CYCLE); - gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON); - gDPSetAlphaCompare ( gl++, G_AC_NONE ); - gDPSetTexturePersp ( gl++, G_TP_NONE ); - gDPSetTextureFilter ( gl++, G_TF_BILERP ); - gDPSetTextureConvert( gl++, G_TC_FILT ); - gDPSetTextureDetail ( gl++, G_TD_CLAMP ); - gDPSetTextureLOD ( gl++, G_TL_TILE ); - gDPSetTextureLUT ( gl++, G_TT_NONE ); - -#define SPRITE_SURF G_RM_TEX_EDGE -#define SPRITE_SURF2 G_RM_TEX_EDGE2 - - gDPSetRenderMode( gl++, SPRITE_SURF, SPRITE_SURF2); - - *glistp = gl; -} - - -/* - * spDraw() - * - * Draws all of the sprites that are associated with bitmaps and that - * are supposed to be drawn (spDraw()). They are drawn from 0 to maxsp, - * so sprites with higher numbers will overwrite lower-numbered sprites. - * - */ -Gfx * -spDraw ( Sprite *s ) -{ - int i; - s32 x, y; - float sx, sy; - Bitmap *b; - Gfx *gl; -#ifndef NDEBUG - Gfx *ogl; -#endif - Gfx *dl_start; - s32 isx, isy; - s32 tx, ty; - s32 tx2, ty2; - s32 x2, y2; - float ftx, fty; - s32 fs, ft; - s32 ex, ey; - -#ifdef rmDEBUG - rmonPrintf("spDraw (Sprite 0x%08x )\n", s ); -#endif - - if (s->attr & SP_HIDDEN) - return(NULL); - - prev_bmbuf = NULL; - - gl = s->rsp_dl_next; - if( gl == NULL ) - gl = s->rsp_dl; - dl_start = gl; - -#ifndef NDEBUG - ogl = gl; -#endif - - b = s->bitmap; - ex = 0; - ey = 0; - - if (sp_attr & SP_EXTERN) /* previous attr was extern? */ - sp_attr = ~s->attr; /* Assume previous modes are all different - from new ones */ - - if (s->attr & SP_EXTERN) /* current attr is extern? */ - sp_attr = s->attr; /* Assume all settings should remain the same */ - - if (s->attr != sp_attr) { - if ((s->attr & SP_TRANSPARENT) && !(sp_attr & SP_TRANSPARENT)) { - gDPSetRenderMode( gl++, G_RM_XLU_SURF, G_RM_XLU_SURF2); - } else if (!(s->attr & SP_TRANSPARENT) && - (sp_attr & SP_TRANSPARENT)) { - gDPSetRenderMode( gl++, - SPRITE_SURF, SPRITE_SURF2); - } - - if ((s->attr & SP_CUTOUT) && !(sp_attr & SP_CUTOUT)) { - gDPSetBlendColor ( gl++, 0xff, 0xff, 0xff, 0x01); - gDPSetAlphaCompare ( gl++, G_AC_THRESHOLD) ; - } else if (!(s->attr & SP_CUTOUT) && (sp_attr & SP_CUTOUT)) { - gDPSetAlphaCompare ( gl++, G_AC_NONE) ; - } - - if( (s->attr & SP_TEXSHIFT) && !(sp_attr & SP_TEXSHIFT) ) { - gDPSetTextureFilter( gl++, G_TF_AVERAGE ); - } else if( !(s->attr & SP_TEXSHIFT) && (sp_attr & SP_TEXSHIFT) ) { - gDPSetTextureFilter( gl++, G_TF_BILERP ); - }; - - }; - - sp_attr = s->attr; - - if( sp_attr & SP_Z ) { - gDPSetPrimDepth(gl++, s->zdepth, 0); - }; - - - gDPSetPrimColor( gl++, 0, 0, s->red, s->green, s->blue, s->alpha); - - if (s->bmfmt == G_IM_FMT_IA || s->bmfmt == G_IM_FMT_I) { - if( s->alpha == 255 ) { - gDPSetCombineMode ( gl++, - G_CC_MODULATEIDECALA_PRIM, - G_CC_MODULATEIDECALA_PRIM); - } else { - gDPSetCombineMode ( gl++, - G_CC_MODULATEIA_PRIM, - G_CC_MODULATEIA_PRIM); - }; - } else { - if( s->alpha == 255 ) { - gDPSetCombineMode ( gl++, - G_CC_MODULATEIDECALA_PRIM, - G_CC_MODULATEIDECALA_PRIM); - } else { - gDPSetCombineMode ( gl++, - G_CC_MODULATERGBA_PRIM, - G_CC_MODULATERGBA_PRIM); - }; - } - - - if( s->bmfmt == G_IM_FMT_CI ) { - gDPSetTextureLUT( gl++, G_TT_RGBA16); - gDPLoadTLUT( gl++, s->nTLUT, 256+s->startTLUT, s->LUT ); - gDPLoadSync( gl++ ); - }; - -#define MY_K0 (175 & 0x1ff) -#define MY_K1 (-43 & 0x1ff) -#define MY_K2 (-89 & 0x1ff) -#define MY_K3 (222 & 0x1ff) -#define MY_K4 (114 & 0x1ff) -#define MY_K5 (42 & 0x1ff) - - if( (s->bmfmt == G_IM_FMT_YUV) && (s->attr & SP_FASTCOPY) ) { - gDPSetTextureConvert( gl++, G_TC_CONV); - gDPSetTextureFilter( gl++, G_TF_POINT); - gDPSetCombineMode( gl++, G_CC_1CYUV2RGB, G_CC_1CYUV2RGB); - gDPSetConvert( gl++, MY_K0, MY_K1, MY_K2, MY_K3, MY_K4, MY_K5); - } else if(s->bmfmt == G_IM_FMT_YUV) { - gDPSetCycleType( gl++, G_CYC_2CYCLE ); - gDPSetTextureFilter( gl++, G_TF_BILERP); - gDPSetTextureConvert( gl++, G_TC_FILTCONV); - gDPSetConvert( gl++, MY_K0, MY_K1, MY_K2, MY_K3, MY_K4, MY_K5); - gDPSetCombineMode( gl++, G_CC_YUV2RGB, G_CC_PASS2); - } - - if (s->attr & SP_SCALE) { - sx = s->scalex; - sy = s->scaley; - } else { - sx = 1.0F; - sy = 1.0F; - } - - isx = (int) ((1<<10) / sx + 0.5F); - isy = (int) ((1<<10) / sy + 0.5F); - - if( b ) { - - if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) - gDPSetCycleType( gl++, G_CYC_COPY); - - x = 0.0F; - y = 0.0F; - - fty = s->y+y*sy; - ty = (int) ( fty + 0.99999F); - ft = (int) (isy * (ty - fty)); - ft = (ft + 16)>>5; - if( s->attr & SP_TEXSHIFT ) - ft += 16; /* 1/2 Texel for AntiAliasing */ - - if( s->attr & SP_FRACPOS ) - ft += s->frac_t; /* Micro-positioning */ - - y2 = y + s->bmheight; - ty2 = (int) (s->y+y2*sy + 0.99999F); - - if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) - ty2--; - - -#ifdef rmDEBUG - rmonPrintf("\tiscale=(%d,%d), %d bitmaps, sprite_size=(%d,%d)\n", - isx, isy, s->nbitmaps, s->width, s->height ); -#endif - - for( i=0; (i < s->nbitmaps) && (b->width > 0); i++, b++ ) { - - if( (x+b->width) > s->width ) { /* Next bitmap hits edge? */ - int bh; - - x = 0; - fs = 0; - ex = 0; - ey += s->expy; - y += s->bmheight; /* Wrap to next line */ - y2 = y + s->bmheight; /* Wrap to next line */ - - fty = s->y+y*sy; - ty = (int) ( fty + 0.9999F); - ft = (int) (isy * (ty - fty)); - ft = (ft + 16)>>5; - if( s->attr & SP_TEXSHIFT ) - ft += 16; /* 1/2 Texel for AntiAliasing */ - - if( s->attr & SP_FRACPOS ) - ft += s->frac_t; /* Micro-positioning */ - - ty2 = (int) (s->y+y2*sy + 0.9999F); - - ty += ey; - ty2 += ey; - - if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) - ty2--; - - /* Fill out to rect. bdy? */ - - if( (b->actualHeight != 0) ) - bh = b->actualHeight; - else - bh = s->bmheight; - - if( (y + bh) > s->height ) /* Can't wrap any more? */ - break; - }; - -#ifdef rmDEBUG - rmonPrintf("bm# %d, x,y=(%d,%d) width=%d \n", i, x, y, b->width ); -#endif - - ftx = s->x+x*sx; - tx = (s32) (ftx + 0.9999F); - fs = (s32) (isx * (tx - ftx)); - fs = (fs + 16)>>5; - if( s->attr & SP_TEXSHIFT ) - fs += 16; /* 1/2 Texel for AntiAliasing */ - - if( s->attr & SP_FRACPOS ) - fs += s->frac_s; /* Micro-positioning */ - - x2 = x + b->width; - tx2 = (int) (s->x+x2*sx + 0.9999F); - - if( (b->actualHeight != 0) ) { - y2 = y + b->actualHeight; - ty2 = (s32) (s->y+y2*sy + 0.9999F); - ty2 += ey; - - if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) - ty2--; - }; - -#ifdef rmDEBUG - rmonPrintf("\tfull(%g,%g) = int(%d,%d) + frac(%d,%d)\n", - ftx, fty, tx,ty, fs,ft ); -#endif - - tx += ex; - tx2 += ex; - - if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) - tx2--; - - if( b->buf != NULL ) /* Skip over null bitmaps (blanks) */ - drawbitmap ( &gl, s, b, tx, ty, tx2, ty2, fs, ft, isx, isy); - - x += b->width; - ex += s->expx; - } - - if (s->attr & SP_FASTCOPY) - gDPSetCycleType( gl++, G_CYC_1CYCLE); - - if(s->bmfmt == G_IM_FMT_YUV) { - gDPSetCycleType( gl++, G_CYC_1CYCLE); - gDPSetTextureFilter ( gl++, G_TF_BILERP ); - gDPSetTextureConvert( gl++, G_TC_FILT ); - }; - - } else { - int rgba; - - x = (s32)s->x; - y = (s32)s->y; - x2 = s->x + (s->width*sx)-1; - y2 = s->y + (s->height*sy)-1; - - if( ( x >= scissor_xmax) || (y >= scissor_ymax) ) { -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: FILL Upper Left corner (%d,%d) beyond range (%d,%d)\n", - x, y, scissor_xmax, scissor_ymax ); -#endif - } else if( ( x2 < scissor_xmin) || (y2 < scissor_ymin) ) { -#ifdef DEBUG_SCISSOR - emPrintf("Sprite Scissoring: FILL Lower Right corner (%d,%d) below range (%d,%d)\n", - x2, y2, scissor_xmin, scissor_ymin ); -#endif - } else { - - if( x < scissor_xmin ) - x = scissor_xmin; - - if( x2 >= scissor_xmax ) - x2 = scissor_xmax - 1; - - if( y < scissor_ymin ) - y = scissor_ymin; - - if( y2 >= scissor_ymax ) - y2 = scissor_ymax - 1; - - rgba = GPACK_RGBA5551((s->red), (s->green), (s->blue), (s->alpha>>7)); - - gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_OFF); - gDPSetCycleType( gl++, G_CYC_FILL); - gDPSetFillColor( gl++, (rgba << 16) | (rgba) ); - - gDPFillRectangle( gl++, x,y, x2,y2 ); - gDPSetCycleType( gl++, G_CYC_1CYCLE); - gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON); - } - } - - if( s->bmfmt == G_IM_FMT_CI ) { - gDPSetTextureLUT( gl++, G_TT_NONE); - }; - - gSPEndDisplayList ( gl++ ); - -#if BUILD_VERSION >= VERSION_J -#line 722 -#else -#line 714 -#endif - assert((gl - ogl) < s->ndisplist); - s->rsp_dl_next = gl; - return( dl_start ); -} - -void -spFinish( Gfx **glistp ) -{ - Gfx *gl; - - gl = *glistp; - - /* Turn off texturing */ - gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_OFF); - gDPSetCombineMode ( gl++, G_CC_SHADE, G_CC_SHADE); - - if (sp_attr & SP_TRANSPARENT) { - /* Turn off transparency */ - gDPSetRenderMode( gl++, G_RM_OPA_SURF, G_RM_OPA_SURF2); - } - - if (sp_attr & SP_CUTOUT) { - /* Turn off Alpha write enable */ - gDPSetAlphaCompare ( gl++, G_AC_NONE) ; - } - - gSPEndDisplayList ( gl++ ); - - *glistp = gl; -} diff --git a/lib/ultralib/src/sp/spriteex.c b/lib/ultralib/src/sp/spriteex.c deleted file mode 100644 index 772036f..0000000 --- a/lib/ultralib/src/sp/spriteex.c +++ /dev/null @@ -1,2 +0,0 @@ -#define F3DEX_GBI -#include "sprite.c" diff --git a/lib/ultralib/src/sp/spriteex2.c b/lib/ultralib/src/sp/spriteex2.c deleted file mode 100644 index 2ef1221..0000000 --- a/lib/ultralib/src/sp/spriteex2.c +++ /dev/null @@ -1,2 +0,0 @@ -#define F3DEX_GBI_2 -#include "sprite.c" diff --git a/lib/ultralib/src/sp/spscale.c b/lib/ultralib/src/sp/spscale.c deleted file mode 100644 index 4f1bd92..0000000 --- a/lib/ultralib/src/sp/spscale.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - */ - -#include - -/* - * spScale() - * - * Scales the sprite by a vertical and horizontal factor. - */ -void -spScale (Sprite *sp, float sx, float sy) -{ - - sp->scalex = sx; - sp->scaley = sy; - - if( (sx == 1.0F) && (sy == 1.0F) ) - spClearAttribute( sp, SP_SCALE ); - else - spSetAttribute( sp, SP_SCALE ); -} diff --git a/lib/ultralib/src/vimodes/vimodefpalhaf1.c b/lib/ultralib/src/vimodes/vimodefpalhaf1.c deleted file mode 100644 index 5ad95fa..0000000 --- a/lib/ultralib/src/vimodes/vimodefpalhaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalHaf1 = { - OS_VI_FPAL_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhan1.c b/lib/ultralib/src/vimodes/vimodefpalhan1.c deleted file mode 100644 index f29ff4b..0000000 --- a/lib/ultralib/src/vimodes/vimodefpalhan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalHan1 = { - OS_VI_FPAL_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpf1.c b/lib/ultralib/src/vimodes/vimodefpalhpf1.c deleted file mode 100644 index db0eb9d..0000000 --- a/lib/ultralib/src/vimodes/vimodefpalhpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalHpf1 = { - OS_VI_FPAL_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpf2.c b/lib/ultralib/src/vimodes/vimodefpalhpf2.c deleted file mode 100644 index dfd3d92..0000000 --- a/lib/ultralib/src/vimodes/vimodefpalhpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalHpf2 = { - OS_VI_FPAL_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpn1.c b/lib/ultralib/src/vimodes/vimodefpalhpn1.c deleted file mode 100644 index 8b665a8..0000000 --- a/lib/ultralib/src/vimodes/vimodefpalhpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalHpn1 = { - OS_VI_FPAL_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpn2.c b/lib/ultralib/src/vimodes/vimodefpalhpn2.c deleted file mode 100644 index c046e97..0000000 --- a/lib/ultralib/src/vimodes/vimodefpalhpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalHpn2 = { - OS_VI_FPAL_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallaf1.c b/lib/ultralib/src/vimodes/vimodefpallaf1.c deleted file mode 100644 index e4a8a9e..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLaf1 = { - OS_VI_FPAL_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallaf2.c b/lib/ultralib/src/vimodes/vimodefpallaf2.c deleted file mode 100644 index 8b3b608..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallaf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLaf2 = { - OS_VI_FPAL_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallan1.c b/lib/ultralib/src/vimodes/vimodefpallan1.c deleted file mode 100644 index f190f55..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLan1 = { - OS_VI_FPAL_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallan2.c b/lib/ultralib/src/vimodes/vimodefpallan2.c deleted file mode 100644 index 13c71e5..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallan2.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLan2 = { - OS_VI_FPAL_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpf1.c b/lib/ultralib/src/vimodes/vimodefpallpf1.c deleted file mode 100644 index d1c307c..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLpf1 = { - OS_VI_FPAL_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpf2.c b/lib/ultralib/src/vimodes/vimodefpallpf2.c deleted file mode 100644 index 385b1df..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLpf2 = { - OS_VI_FPAL_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(45, 615), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(47, 617), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpn1.c b/lib/ultralib/src/vimodes/vimodefpallpn1.c deleted file mode 100644 index 6fbcfe9..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLpn1 = { - OS_VI_FPAL_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpn2.c b/lib/ultralib/src/vimodes/vimodefpallpn2.c deleted file mode 100644 index c852cf9..0000000 --- a/lib/ultralib/src/vimodes/vimodefpallpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeFpalLpn2 = { - OS_VI_FPAL_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(47, 617), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempalhaf1.c b/lib/ultralib/src/vimodes/vimodempalhaf1.c deleted file mode 100644 index c9a74dc..0000000 --- a/lib/ultralib/src/vimodes/vimodempalhaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalHaf1 = { - OS_VI_MPAL_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - //[0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - //[1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempalhan1.c b/lib/ultralib/src/vimodes/vimodempalhan1.c deleted file mode 100644 index 038163b..0000000 --- a/lib/ultralib/src/vimodes/vimodempalhan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalHan1 = { - OS_VI_MPAL_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpf1.c b/lib/ultralib/src/vimodes/vimodempalhpf1.c deleted file mode 100644 index 4bbb0e5..0000000 --- a/lib/ultralib/src/vimodes/vimodempalhpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalHpf1 = { - OS_VI_MPAL_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpf2.c b/lib/ultralib/src/vimodes/vimodempalhpf2.c deleted file mode 100644 index b2fad3d..0000000 --- a/lib/ultralib/src/vimodes/vimodempalhpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalHpf2 = { - OS_VI_MPAL_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpn1.c b/lib/ultralib/src/vimodes/vimodempalhpn1.c deleted file mode 100644 index 3955a4f..0000000 --- a/lib/ultralib/src/vimodes/vimodempalhpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalHpn1 = { - OS_VI_MPAL_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpn2.c b/lib/ultralib/src/vimodes/vimodempalhpn2.c deleted file mode 100644 index b4c7a6d..0000000 --- a/lib/ultralib/src/vimodes/vimodempalhpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalHpn2 = { - OS_VI_MPAL_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallaf1.c b/lib/ultralib/src/vimodes/vimodempallaf1.c deleted file mode 100644 index 1369d39..0000000 --- a/lib/ultralib/src/vimodes/vimodempallaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLaf1 = { - OS_VI_MPAL_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallaf2.c b/lib/ultralib/src/vimodes/vimodempallaf2.c deleted file mode 100644 index 0502362..0000000 --- a/lib/ultralib/src/vimodes/vimodempallaf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLaf2 = { - OS_VI_MPAL_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallan1.c b/lib/ultralib/src/vimodes/vimodempallan1.c deleted file mode 100644 index a3f4e69..0000000 --- a/lib/ultralib/src/vimodes/vimodempallan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLan1 = { - OS_VI_MPAL_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallan2.c b/lib/ultralib/src/vimodes/vimodempallan2.c deleted file mode 100644 index 65817e7..0000000 --- a/lib/ultralib/src/vimodes/vimodempallan2.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLan2 = { - OS_VI_MPAL_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallpf1.c b/lib/ultralib/src/vimodes/vimodempallpf1.c deleted file mode 100644 index 7df1655..0000000 --- a/lib/ultralib/src/vimodes/vimodempallpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLpf1 = { - OS_VI_MPAL_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallpf2.c b/lib/ultralib/src/vimodes/vimodempallpf2.c deleted file mode 100644 index 285832e..0000000 --- a/lib/ultralib/src/vimodes/vimodempallpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLpf2 = { - OS_VI_MPAL_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(524), // vSync - HSYNC(3088, 0), // hSync - LEAP(3100, 3100), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(2, 2, 11, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallpn1.c b/lib/ultralib/src/vimodes/vimodempallpn1.c deleted file mode 100644 index 8914794..0000000 --- a/lib/ultralib/src/vimodes/vimodempallpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLpn1 = { - OS_VI_MPAL_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodempallpn2.c b/lib/ultralib/src/vimodes/vimodempallpn2.c deleted file mode 100644 index 40f381c..0000000 --- a/lib/ultralib/src/vimodes/vimodempallpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeMpalLpn2 = { - OS_VI_MPAL_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentschaf1.c b/lib/ultralib/src/vimodes/vimodentschaf1.c deleted file mode 100644 index e6ad8bc..0000000 --- a/lib/ultralib/src/vimodes/vimodentschaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscHaf1 = { - OS_VI_NTSC_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentschan1.c b/lib/ultralib/src/vimodes/vimodentschan1.c deleted file mode 100644 index 14711e7..0000000 --- a/lib/ultralib/src/vimodes/vimodentschan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscHan1 = { - OS_VI_NTSC_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentschpf1.c b/lib/ultralib/src/vimodes/vimodentschpf1.c deleted file mode 100644 index 8f70311..0000000 --- a/lib/ultralib/src/vimodes/vimodentschpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscHpf1 = { - OS_VI_NTSC_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentschpf2.c b/lib/ultralib/src/vimodes/vimodentschpf2.c deleted file mode 100644 index 8533e23..0000000 --- a/lib/ultralib/src/vimodes/vimodentschpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscHpf2 = { - OS_VI_NTSC_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentschpn1.c b/lib/ultralib/src/vimodes/vimodentschpn1.c deleted file mode 100644 index f82e277..0000000 --- a/lib/ultralib/src/vimodes/vimodentschpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscHpn1 = { - OS_VI_NTSC_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentschpn2.c b/lib/ultralib/src/vimodes/vimodentschpn2.c deleted file mode 100644 index d1b5974..0000000 --- a/lib/ultralib/src/vimodes/vimodentschpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscHpn2 = { - OS_VI_NTSC_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclaf1.c b/lib/ultralib/src/vimodes/vimodentsclaf1.c deleted file mode 100644 index fe12792..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLaf1 = { - OS_VI_NTSC_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclaf2.c b/lib/ultralib/src/vimodes/vimodentsclaf2.c deleted file mode 100644 index acf2c3c..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclaf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLaf2 = { - OS_VI_NTSC_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclan1.c b/lib/ultralib/src/vimodes/vimodentsclan1.c deleted file mode 100644 index 0092a00..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLan1 = { - OS_VI_NTSC_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclan2.c b/lib/ultralib/src/vimodes/vimodentsclan2.c deleted file mode 100644 index da2747b..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclan2.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLan2 = { - OS_VI_NTSC_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpf1.c b/lib/ultralib/src/vimodes/vimodentsclpf1.c deleted file mode 100644 index b6bb5e7..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLpf1 = { - OS_VI_NTSC_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpf2.c b/lib/ultralib/src/vimodes/vimodentsclpf2.c deleted file mode 100644 index f3f82c7..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLpf2 = { - OS_VI_NTSC_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(35, 509), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpn1.c b/lib/ultralib/src/vimodes/vimodentsclpn1.c deleted file mode 100644 index ecc68cb..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLpn1 = { - OS_VI_NTSC_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpn2.c b/lib/ultralib/src/vimodes/vimodentsclpn2.c deleted file mode 100644 index bce83b8..0000000 --- a/lib/ultralib/src/vimodes/vimodentsclpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModeNtscLpn2 = { - OS_VI_NTSC_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(37, 511), // vStart - BURST(4, 2, 14, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepalhaf1.c b/lib/ultralib/src/vimodes/vimodepalhaf1.c deleted file mode 100644 index 3ff1394..0000000 --- a/lib/ultralib/src/vimodes/vimodepalhaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalHaf1 = { - OS_VI_PAL_HAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepalhan1.c b/lib/ultralib/src/vimodes/vimodepalhan1.c deleted file mode 100644 index 3d32ba6..0000000 --- a/lib/ultralib/src/vimodes/vimodepalhan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalHan1 = { - OS_VI_PAL_HAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpf1.c b/lib/ultralib/src/vimodes/vimodepalhpf1.c deleted file mode 100644 index bdd0871..0000000 --- a/lib/ultralib/src/vimodes/vimodepalhpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalHpf1 = { - OS_VI_PAL_HPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(0.5, 0.5), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpf2.c b/lib/ultralib/src/vimodes/vimodepalhpf2.c deleted file mode 100644 index 565ac4f..0000000 --- a/lib/ultralib/src/vimodes/vimodepalhpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalHpf2 = { - OS_VI_PAL_HPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(640), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(0.5, 0.5), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(0.5, 0.5), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpn1.c b/lib/ultralib/src/vimodes/vimodepalhpn1.c deleted file mode 100644 index a0c1ecc..0000000 --- a/lib/ultralib/src/vimodes/vimodepalhpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalHpn1 = { - OS_VI_PAL_HPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpn2.c b/lib/ultralib/src/vimodes/vimodepalhpn2.c deleted file mode 100644 index d6e05b8..0000000 --- a/lib/ultralib/src/vimodes/vimodepalhpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalHpn2 = { - OS_VI_PAL_HPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(1280), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(2560), // origin - SCALE(1, 0), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(5120), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallaf1.c b/lib/ultralib/src/vimodes/vimodepallaf1.c deleted file mode 100644 index 3d03857..0000000 --- a/lib/ultralib/src/vimodes/vimodepallaf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLaf1 = { - OS_VI_PAL_LAF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallaf2.c b/lib/ultralib/src/vimodes/vimodepallaf2.c deleted file mode 100644 index 4fc496c..0000000 --- a/lib/ultralib/src/vimodes/vimodepallaf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLaf2 = { - OS_VI_PAL_LAF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallan1.c b/lib/ultralib/src/vimodes/vimodepallan1.c deleted file mode 100644 index 22a893c..0000000 --- a/lib/ultralib/src/vimodes/vimodepallan1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLan1 = { - OS_VI_PAL_LAN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallan2.c b/lib/ultralib/src/vimodes/vimodepallan2.c deleted file mode 100644 index d32360b..0000000 --- a/lib/ultralib/src/vimodes/vimodepallan2.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLan2 = { - OS_VI_PAL_LAN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallpf1.c b/lib/ultralib/src/vimodes/vimodepallpf1.c deleted file mode 100644 index 37d68e4..0000000 --- a/lib/ultralib/src/vimodes/vimodepallpf1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLpf1 = { - OS_VI_PAL_LPF1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallpf2.c b/lib/ultralib/src/vimodes/vimodepallpf2.c deleted file mode 100644 index c37ebe1..0000000 --- a/lib/ultralib/src/vimodes/vimodepallpf2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLpf2 = { - OS_VI_PAL_LPF2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(624), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0.25), // yScale - HSTART(93, 567), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0.75), // yScale - HSTART(95, 569), // vStart - BURST(105, 2, 13, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallpn1.c b/lib/ultralib/src/vimodes/vimodepallpn1.c deleted file mode 100644 index eafbe6b..0000000 --- a/lib/ultralib/src/vimodes/vimodepallpn1.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLpn1 = { - OS_VI_PAL_LPN1, // type - { - // comRegs - VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(640), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/vimodes/vimodepallpn2.c b/lib/ultralib/src/vimodes/vimodepallpn2.c deleted file mode 100644 index 49a26fd..0000000 --- a/lib/ultralib/src/vimodes/vimodepallpn2.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "PR/os.h" -#include "PR/rcp.h" -#include "../io/viint.h" - -OSViMode osViModePalLpn2 = { - OS_VI_PAL_LPN2, // type - { - // comRegs - VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | - VI_CTRL_PIXEL_ADV_3, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent - }, - { // fldRegs - { - // [0] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - }, - { - // [1] - ORIGIN(1280), // origin - SCALE(1, 0), // yScale - HSTART(95, 569), // vStart - BURST(107, 2, 9, 0), // vBurst - VINTR(2), // vIntr - } }, -}; diff --git a/lib/ultralib/src/voice/voicecheckresult.c b/lib/ultralib/src/voice/voicecheckresult.c deleted file mode 100644 index 5318652..0000000 --- a/lib/ultralib/src/voice/voicecheckresult.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* stat) { - s32 ret; - u8 buf[2]; - - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, stat); - if (ret == 0) { - if (*stat & 1) { - ret = CONT_ERR_VOICE_NO_RESPONSE; - } else { - ret = __osVoiceContRead2(hd->__mq, hd->__channel, 0, buf); - if (ret == 0) { - hd->cmd_status = buf[0] & 7; - - if (buf[0] & 0x40) { - ret = CONT_ERR_VOICE_NO_RESPONSE; - } else { - ret = buf[1] << 8; - } - } - } - } - return ret; -} diff --git a/lib/ultralib/src/voice/voicecheckword.c b/lib/ultralib/src/voice/voicecheckword.c deleted file mode 100644 index 05c2a59..0000000 --- a/lib/ultralib/src/voice/voicecheckword.c +++ /dev/null @@ -1,80 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" - -s32 osVoiceCheckWord(u8* word) { - s32 k; - s32 ret = 0; - u16 sjis; - u16 old = 0; - - for (k = 0; word[k] != 0; k += 2) { - sjis = (word[k] << 8) + word[k + 1]; - if (((sjis != 'ー') && (sjis < 'ぁ')) || ((sjis > 'ん') && (sjis < 'ァ')) || (sjis == 0x837F) || - (sjis > 'ヶ')) { - ret = CONT_ERR_VOICE_WORD; - } else if ((k == 0) && - ((sjis == 'ー') || (sjis == 'ん') || (sjis == 'っ') || (sjis == 'ゎ') || (sjis == 'ン') || - (sjis == 'ッ') || (sjis == 'ヮ') || (sjis == 'ヵ') || (sjis == 'ヶ'))) { - ret = CONT_ERR_VOICE_WORD; - } else if (((sjis == 'ぁ') || (sjis == 'ァ')) && (old != 'ふ') && (old != 'フ') && (old != 'ヴ')) { - ret = CONT_ERR_VOICE_WORD; - } else if (((sjis == 'ぃ') || (sjis == 'ィ')) && (old != 'う') && (old != 'て') && (old != 'で') && - (old != 'ふ') && (old != 'ウ') && (old != 'テ') && (old != 'デ') && (old != 'フ') && (old != 'ヴ')) { - ret = CONT_ERR_VOICE_WORD; - } else if (((sjis == 'ぅ') || (sjis == 'ゥ')) && (old != 'と') && (old != 'ど') && (old != 'ふ') && - (old != 'ト') && (old != 'ド') && (old != 'フ') && (old != 'ヴ')) { - ret = CONT_ERR_VOICE_WORD; - } else if (((sjis == 'ぇ') || (sjis == 'ェ')) && (old != 'う') && (old != 'し') && (old != 'じ') && - (old != 'ち') && (old != 'ぢ') && (old != 'つ') && (old != 'ふ') && (old != 'ウ') && (old != 'シ') && - (old != 'ジ') && (old != 'チ') && (old != 'ヂ') && (old != 'ツ') && (old != 'フ') && (old != 'ヴ')) { - ret = CONT_ERR_VOICE_WORD; - } else if (((sjis == 'ぉ') || (sjis == 'ォ')) && (old != 'う') && (old != 'ふ') && (old != 'ウ') && - (old != 'フ') && (old != 'ヴ')) { - ret = CONT_ERR_VOICE_WORD; - } else if (((sjis == 'ゃ') || (sjis == 'ゅ') || (sjis == 'ょ') || (sjis == 'ャ') || (sjis == 'ュ') || - (sjis == 'ョ')) && - (old != 'き') && (old != 'し') && (old != 'ち') && (old != 'に') && (old != 'ひ') && (old != 'み') && - (old != 'り') && (old != 'ぎ') && (old != 'じ') && (old != 'ぢ') && (old != 'び') && (old != 'ぴ') && - (old != 'キ') && (old != 'シ') && (old != 'チ') && (old != 'ニ') && (old != 'ヒ') && (old != 'ミ') && - (old != 'リ') && (old != 'ギ') && (old != 'ジ') && (old != 'ヂ') && (old != 'ビ') && (old != 'ピ') && - (old != 'ヴ')) { - ret = CONT_ERR_VOICE_WORD; - } else if ((sjis == 'ー') && ((old == 'ん') || (old == 'っ') || (old == 'ン') || (old == 'ッ'))) { - ret = CONT_ERR_VOICE_WORD; - } else if (((sjis == 'ん') || (sjis == 'ン')) && ((old == 'ん') || (old == 'ン'))) { - ret = CONT_ERR_VOICE_WORD; - } else if (((old == 'っ') || (old == 'ッ')) && - ((sjis == 'ー') || (sjis == 'あ') || (sjis == 'い') || (sjis == 'う') || (sjis == 'え') || - (sjis == 'お') || (sjis == 'な') || (sjis == 'に') || (sjis == 'ぬ') || (sjis == 'ね') || - (sjis == 'の') || (sjis == 'ま') || (sjis == 'み') || (sjis == 'む') || (sjis == 'め') || - (sjis == 'も') || (sjis == 'や') || (sjis == 'ゆ') || (sjis == 'よ') || (sjis == 'ら') || - (sjis == 'り') || (sjis == 'る') || (sjis == 'れ') || (sjis == 'ろ') || (sjis == 'わ') || - (sjis == 'ゐ') || (sjis == 'ゑ') || (sjis == 'を') || (sjis == 'ん') || (sjis == 'ぁ') || - (sjis == 'ぃ') || (sjis == 'ぅ') || (sjis == 'ぇ') || (sjis == 'ぉ') || (sjis == 'ゃ') || - (sjis == 'ゅ') || (sjis == 'ょ') || (sjis == 'っ') || (sjis == 'ゎ') - - || (sjis == 'ア') || (sjis == 'イ') || (sjis == 'ウ') || (sjis == 'エ') || (sjis == 'オ') || - (sjis == 'ナ') || (sjis == 'ニ') || (sjis == 'ヌ') || (sjis == 'ネ') || (sjis == 'ノ') || - (sjis == 'マ') || (sjis == 'ミ') || (sjis == 'ム') || (sjis == 'メ') || (sjis == 'モ') || - (sjis == 'ヤ') || (sjis == 'ユ') || (sjis == 'ヨ') || (sjis == 'ラ') || (sjis == 'リ') || - (sjis == 'ル') || (sjis == 'レ') || (sjis == 'ロ') || (sjis == 'ワ') || (sjis == 'ヰ') || - (sjis == 'ヱ') || (sjis == 'ヲ') || (sjis == 'ン') || (sjis == 'ァ') || (sjis == 'ィ') || - (sjis == 'ゥ') || (sjis == 'ェ') || (sjis == 'ォ') || (sjis == 'ャ') || (sjis == 'ュ') || - (sjis == 'ョ') || (sjis == 'ッ') || (sjis == 'ヮ'))) { - ret = CONT_ERR_VOICE_WORD; - } - - if (ret != 0) { - return ret; - } else { - old = sjis; - } - } - - if ((sjis == 'っ') || (sjis == 'ッ')) { - ret = CONT_ERR_VOICE_WORD; - } - - return ret; -} diff --git a/lib/ultralib/src/voice/voicecleardictionary.c b/lib/ultralib/src/voice/voicecleardictionary.c deleted file mode 100644 index 6ed1464..0000000 --- a/lib/ultralib/src/voice/voicecleardictionary.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words) { - s32 ret; - u8 stat; - u8 buf[4]; - - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); - if (ret != 0) { - return ret; - } else if (stat & 2) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - *(u32*)buf = 0x02000000; - buf[2] = words; - - ERRCK(__osVoiceContWrite4(hd->__mq, hd->__channel, 0, buf)); - - ret = __osVoiceCheckResult(hd, &stat); - if (ret & 0xFF00) { - ret = CONT_ERR_INVALID; - } - - return ret; -} diff --git a/lib/ultralib/src/voice/voicecontread2.c b/lib/ultralib/src/voice/voicecontread2.c deleted file mode 100644 index a204ffc..0000000 --- a/lib/ultralib/src/voice/voicecontread2.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" -#include "io/controller_voice.h" -#include "io/siint.h" - -#define READ2FORMAT(ptr) ((__OSVoiceRead2Format*)(ptr)) - -s32 __osVoiceContRead2(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { - s32 ret = 0; - u8 status; - int i; - u8* ptr; - int retry = 2; - - __osSiGetAccess(); - - do { - - ptr = (u8*)&__osPfsPifRam.ramarray; - - if ((__osContLastCmd != CONT_CMD_READ2_VOICE) || ((u32)__osPfsLastChannel != channel)) { - __osContLastCmd = CONT_CMD_READ2_VOICE; - __osPfsLastChannel = channel; - - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - READ2FORMAT(ptr)->dummy = CONT_CMD_NOP; - READ2FORMAT(ptr)->txsize = CONT_CMD_READ2_VOICE_TX; - READ2FORMAT(ptr)->rxsize = CONT_CMD_READ2_VOICE_RX; - READ2FORMAT(ptr)->cmd = CONT_CMD_READ2_VOICE; - READ2FORMAT(ptr)->datacrc = 0xFF; - - ptr[sizeof(__OSVoiceRead2Format)] = CONT_CMD_END; - } else { - ptr += channel; - } - - READ2FORMAT(ptr)->addrh = address >> 3; - READ2FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = CHNL_ERR(*READ2FORMAT(ptr)); - - if (ret == 0) { - if (__osVoiceContDataCrc(READ2FORMAT(ptr)->data, ARRLEN(READ2FORMAT(ptr)->data)) != - READ2FORMAT(ptr)->datacrc) { - ret = __osVoiceGetStatus(mq, channel, &status); - if (ret != 0) { - break; - } else { - ret = CONT_ERR_CONTRFAIL; - } - } else { - bcopy(READ2FORMAT(ptr)->data, buffer, ARRLEN(READ2FORMAT(ptr)->data)); - } - } else { - ret = CONT_ERR_NO_CONTROLLER; - } - - } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); - - __osSiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/voice/voicecontread36.c b/lib/ultralib/src/voice/voicecontread36.c deleted file mode 100644 index c537aff..0000000 --- a/lib/ultralib/src/voice/voicecontread36.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" -#include "io/controller_voice.h" -#include "io/siint.h" - -#define READ36FORMAT(ptr) ((__OSVoiceRead36Format*)(ptr)) - -s32 __osVoiceContRead36(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { - s32 ret = 0; - u8 status; - s32 i; - u8* ptr; - s32 retry = 2; - - __osSiGetAccess(); - - do { - - ptr = (u8*)&__osPfsPifRam.ramarray; - - if ((__osContLastCmd != CONT_CMD_READ36_VOICE) || ((u32)__osPfsLastChannel != channel)) { - __osContLastCmd = CONT_CMD_READ36_VOICE; - __osPfsLastChannel = channel; - - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - READ36FORMAT(ptr)->dummy = CONT_CMD_NOP; - READ36FORMAT(ptr)->txsize = CONT_CMD_READ36_VOICE_TX; - READ36FORMAT(ptr)->rxsize = CONT_CMD_READ36_VOICE_RX; - READ36FORMAT(ptr)->cmd = CONT_CMD_READ36_VOICE; - READ36FORMAT(ptr)->datacrc = 0xFF; - - ptr[sizeof(__OSVoiceRead36Format)] = CONT_CMD_END; - } else { - ptr += channel; - } - - READ36FORMAT(ptr)->addrh = address >> 3; - READ36FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = CHNL_ERR(*READ36FORMAT(ptr)); - - if (ret == 0) { - if (__osVoiceContDataCrc(READ36FORMAT(ptr)->data, ARRLEN(READ36FORMAT(ptr)->data)) != - READ36FORMAT(ptr)->datacrc) { - ret = __osVoiceGetStatus(mq, channel, &status); - if (ret != 0) { - break; - } else { - ret = CONT_ERR_CONTRFAIL; - } - } else { - bcopy(READ36FORMAT(ptr)->data, buffer, ARRLEN(READ36FORMAT(ptr)->data)); - } - } else { - ret = CONT_ERR_NO_CONTROLLER; - } - - } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); - - __osSiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/voice/voicecontrolgain.c b/lib/ultralib/src/voice/voicecontrolgain.c deleted file mode 100644 index 95e9bb2..0000000 --- a/lib/ultralib/src/voice/voicecontrolgain.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { - s32 ret; - u8 cmd; - - static u8 digital_table[] = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0 }; - - if (analog == 0) { - cmd = 0x18; - } else { - cmd = 0x98; - } - - ERRCK(__osVoiceSetADConverter(hd->__mq, hd->__channel, cmd)); - - if ((digital < ARRLEN(digital_table)) && (digital >= 0)) { - cmd = digital_table[digital] + 2; - } else { - return CONT_ERR_INVALID; - } - - ERRCK(__osVoiceSetADConverter(hd->__mq, hd->__channel, cmd)); - return ret; -} diff --git a/lib/ultralib/src/voice/voicecontwrite20.c b/lib/ultralib/src/voice/voicecontwrite20.c deleted file mode 100644 index d1a7446..0000000 --- a/lib/ultralib/src/voice/voicecontwrite20.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" -#include "io/controller_voice.h" -#include "io/siint.h" - -#define WRITE20FORMAT(ptr) ((__OSVoiceWrite20Format*)(ptr)) - -s32 __osVoiceContWrite20(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { - s32 ret = 0; - u8 status; - int i; - u8* ptr; - int retry = 2; - u8 crc; - - __osSiGetAccess(); - - do { - - ptr = (u8*)&__osPfsPifRam; - - if ((__osContLastCmd != CONT_CMD_WRITE20_VOICE) || ((u32)__osPfsLastChannel != channel)) { - __osContLastCmd = CONT_CMD_WRITE20_VOICE; - __osPfsLastChannel = channel; - - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - WRITE20FORMAT(ptr)->dummy = CONT_CMD_NOP; - WRITE20FORMAT(ptr)->txsize = CONT_CMD_WRITE20_VOICE_TX; - WRITE20FORMAT(ptr)->rxsize = CONT_CMD_WRITE20_VOICE_RX; - WRITE20FORMAT(ptr)->cmd = CONT_CMD_WRITE20_VOICE; - WRITE20FORMAT(ptr)->datacrc = 0xFF; - - ptr[sizeof(__OSVoiceWrite20Format)] = CONT_CMD_END; - } else { - ptr += channel; - } - - WRITE20FORMAT(ptr)->addrh = address >> 3; - WRITE20FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); - - bcopy(buffer, WRITE20FORMAT(ptr)->data, ARRLEN(WRITE20FORMAT(ptr)->data)); - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - crc = __osVoiceContDataCrc(buffer, ARRLEN(WRITE20FORMAT(ptr)->data)); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = CHNL_ERR(*WRITE20FORMAT(ptr)); - - if (ret == 0) { - if (crc != WRITE20FORMAT(ptr)->datacrc) { - ret = __osVoiceGetStatus(mq, channel, &status); - if (ret != 0) { - break; - } else { - ret = CONT_ERR_CONTRFAIL; - } - } - } else { - ret = CONT_ERR_NO_CONTROLLER; - } - - } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); - - __osSiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/voice/voicecontwrite4.c b/lib/ultralib/src/voice/voicecontwrite4.c deleted file mode 100644 index 6f00586..0000000 --- a/lib/ultralib/src/voice/voicecontwrite4.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" -#include "io/controller_voice.h" -#include "io/siint.h" - -#define WRITE4FORMAT(ptr) ((__OSVoiceWrite4Format*)(ptr)) - -s32 __osVoiceContWrite4(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { - s32 ret = 0; - u8 status; - int i; - u8* ptr; - s32 retry = 2; - u8 crc; - - __osSiGetAccess(); - - do { - - ptr = (u8*)&__osPfsPifRam; - - if ((__osContLastCmd != CONT_CMD_WRITE4_VOICE) || ((u32)__osPfsLastChannel != channel)) { - __osContLastCmd = CONT_CMD_WRITE4_VOICE; - __osPfsLastChannel = channel; - - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - WRITE4FORMAT(ptr)->dummy = CONT_CMD_NOP; - WRITE4FORMAT(ptr)->txsize = CONT_CMD_WRITE4_VOICE_TX; - WRITE4FORMAT(ptr)->rxsize = CONT_CMD_WRITE4_VOICE_RX; - WRITE4FORMAT(ptr)->cmd = CONT_CMD_WRITE4_VOICE; - WRITE4FORMAT(ptr)->datacrc = 0xFF; - - ptr[sizeof(__OSVoiceWrite4Format)] = CONT_CMD_END; - } else { - ptr += channel; - } - - WRITE4FORMAT(ptr)->addrh = address >> 3; - WRITE4FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); - - bcopy(buffer, WRITE4FORMAT(ptr)->data, ARRLEN(WRITE4FORMAT(ptr)->data)); - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - crc = __osVoiceContDataCrc(buffer, ARRLEN(WRITE4FORMAT(ptr)->data)); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = CHNL_ERR(*WRITE4FORMAT(ptr)); - - if (ret == 0) { - if (crc != WRITE4FORMAT(ptr)->datacrc) { - ret = __osVoiceGetStatus(mq, channel, &status); - if (ret != 0) { - break; - } else { - ret = CONT_ERR_CONTRFAIL; - } - } - } else { - ret = CONT_ERR_NO_CONTROLLER; - } - - } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); - - __osSiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/voice/voicecountsyllables.c b/lib/ultralib/src/voice/voicecountsyllables.c deleted file mode 100644 index b0112ef..0000000 --- a/lib/ultralib/src/voice/voicecountsyllables.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" - -// The VRU can store only 880 semisyllables of words in its dictionary. -// Use this function to determine the semisyllable count before adding a word with osVoiceSetWord, -// to properly see whether it will fit. - -void osVoiceCountSyllables(u8* data, u32* syllable) { - s32 k; - u16 sjis; - u16 old; - - old = 0; - *syllable = 1; - for (k = 0; data[k] != 0; k += 2) { - sjis = (data[k] << 8) + data[k + 1]; - if ((sjis == 'あ') || (sjis == 'い') || (sjis == 'う') || (sjis == 'え') || (sjis == 'お') || (sjis == 'ア') || - (sjis == 'イ') || (sjis == 'ウ') || (sjis == 'エ') || (sjis == 'オ')) { - if (k == 0) { - *syllable += 2; - } else { - *syllable += 1; - } - } else if ((sjis == 'か') || (sjis == 'き') || (sjis == 'く') || (sjis == 'け') || (sjis == 'こ') || - (sjis == 'た') || (sjis == 'ち') || (sjis == 'つ') || (sjis == 'て') || (sjis == 'と') || - (sjis == 'ぱ') || (sjis == 'ぴ') || (sjis == 'ぷ') || (sjis == 'ぺ') || (sjis == 'ぽ') || - (sjis == 'カ') || (sjis == 'キ') || (sjis == 'ク') || (sjis == 'ケ') || (sjis == 'コ') || - (sjis == 'タ') || (sjis == 'チ') || (sjis == 'ツ') || (sjis == 'テ') || (sjis == 'ト') || - (sjis == 'パ') || (sjis == 'ピ') || (sjis == 'プ') || (sjis == 'ペ') || (sjis == 'ポ')) { - if (k == 0) { - *syllable += 2; - } else if ((old == 'っ') || (old == 'ッ')) { - *syllable += 2; - } else { - *syllable += 3; - } - } else if ((sjis == 'ぁ') || (sjis == 'ぃ') || (sjis == 'ぅ') || (sjis == 'ぇ') || (sjis == 'ぉ') || - (sjis == 'ゃ') || (sjis == 'ゅ') || (sjis == 'ょ') || (sjis == 'ゎ') - - || (sjis == 'ァ') || (sjis == 'ィ') || (sjis == 'ゥ') || (sjis == 'ェ') || (sjis == 'ォ') || - (sjis == 'ャ') || (sjis == 'ュ') || (sjis == 'ョ') || (sjis == 'ヮ') || (sjis == 'ヵ') || - (sjis == 'ヶ')) { - if ((old == 'あ') || (old == 'い') || (old == 'う') || (old == 'え') || (old == 'お') || (old == 'ア') || - (old == 'イ') || (old == 'ウ') || (old == 'エ') || (old == 'オ')) { - *syllable += 1; - } - } else if ((sjis == 'ん') || (sjis == 'ー') || (sjis == 'っ') || (sjis == 'ン') || (sjis == 'ッ')) { - *syllable += 1; - } else { - *syllable += 2; - } - old = sjis; - } -} diff --git a/lib/ultralib/src/voice/voicecrc.c b/lib/ultralib/src/voice/voicecrc.c deleted file mode 100644 index 56b4838..0000000 --- a/lib/ultralib/src/voice/voicecrc.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" - -#define VOICE_CRC_LENGTH 8 -#define VOICE_CRC_GENERATOR 0x85 - -u8 __osVoiceContDataCrc(u8* data, u32 length) { - s32 temp = 0; - u32 i; - u32 j; - - for (i = length; i != 0; i--) { - // Loop over each j in the i starting with most significant - for (j = (1 << (VOICE_CRC_LENGTH - 1)); j != 0; j >>= 1) { - temp <<= 1; - if (*data & j) { - if (temp & (1 << VOICE_CRC_LENGTH)) { - // Same as temp++; temp ^= 0x85 since last j always 0 after the shift - temp ^= VOICE_CRC_GENERATOR - 1; - } else { - temp++; - } - } else if (temp & (1 << VOICE_CRC_LENGTH)) { - temp ^= VOICE_CRC_GENERATOR; - } - } - data++; - } - // Act like a i of zeros is appended to data - do { - temp <<= 1; - if (temp & (1 << VOICE_CRC_LENGTH)) { - temp ^= VOICE_CRC_GENERATOR; - } - } while (++i < VOICE_CRC_LENGTH); - - // Discarding the excess is done automatically by the return type - return temp; -} diff --git a/lib/ultralib/src/voice/voicegetreaddata.c b/lib/ultralib/src/voice/voicegetreaddata.c deleted file mode 100644 index d2f5063..0000000 --- a/lib/ultralib/src/voice/voicegetreaddata.c +++ /dev/null @@ -1,94 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* micdata) { - s32 ret = 0; - s32 i; - u8 stat; - u8 temp[36]; - static u8 c; - - switch (hd->__mode) { - case 1: - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); - if (ret != 0) { - return ret; - } else if (stat & 1) { - return CONT_ERR_NOT_READY; - } - - ERRCK(__osVoiceContRead2(hd->__mq, hd->__channel, 0, temp)); - - c = temp[0] & 7; - hd->cmd_status = c; - if ((c != 0) && (c != 7)) { - return CONT_ERR_NOT_READY; - } - case 2: - hd->__mode = 2; - - ERRCK(__osVoiceGetStatus(hd->__mq, hd->__channel, &stat)); - - if (stat & 2) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - *(u32*)temp = 0x600; - ERRCK(__osVoiceContWrite4(hd->__mq, hd->__channel, 0, temp)); - - case 3: - hd->__mode = 3; - - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); - if (ret != 0) { - return ret; - } else if (stat & 1) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - ERRCK(__osVoiceContRead36(hd->__mq, hd->__channel, 0, temp)); - - micdata->warning = temp[4] + (temp[5] << 8); - micdata->answer_num = temp[6]; - micdata->voice_level = temp[8] + (temp[9] << 8); - micdata->voice_sn = temp[10] + (temp[11] << 8); - micdata->voice_time = temp[12] + (temp[13] << 8); - - for (i = 0; i < 5; i++) { - micdata->answer[i] = temp[14 + (i << 2)] + (temp[15 + (i << 2)] << 8); - micdata->distance[i] = temp[16 + (i << 2)] + (temp[17 + (i << 2)] << 8); - } - - if (micdata->answer[0] == 0x7FFF) { - micdata->answer_num = 0; - } - - hd->cmd_status = temp[34] & 7; - if ((c == 0) || (hd->cmd_status == 0)) { - break; - } - case 4: - hd->__mode = 4; - - ERRCK(__osVoiceGetStatus(hd->__mq, hd->__channel, &stat)); - - if (stat & 1) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - ERRCK(__osVoiceContRead2(hd->__mq, hd->__channel, 0, temp)); - - hd->cmd_status = temp[0] & 7; - if (temp[0] & 7) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - break; - default: - return CONT_ERR_INVALID; - } - hd->__mode = 0; - return ret; -} diff --git a/lib/ultralib/src/voice/voicegetstatus.c b/lib/ultralib/src/voice/voicegetstatus.c deleted file mode 100644 index e7328c1..0000000 --- a/lib/ultralib/src/voice/voicegetstatus.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" -#include "io/siint.h" - -s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 port, u8* status) { - __OSContRequesFormatShort header; - s32 ret = 0; - s32 i; - u8* ptr = (u8*)&__osContPifRam.ramarray; - s32 retry = 2; - - __osSiGetAccess(); - - do { - if (ret != CONT_ERR_CONTRFAIL) { - __osContPifRam.pifstatus = CONT_CMD_EXE; - - for (i = 0; i < port; i++, *ptr++ = CONT_CMD_REQUEST_STATUS) { - ; - } - - *ptr++ = CONT_CMD_REQUEST_STATUS_TX; - *ptr++ = CONT_CMD_REQUEST_STATUS_RX; - *ptr = CONT_CMD_REQUEST_STATUS; - ptr += 4; - *ptr = CONT_CMD_END; - - __osContLastCmd = CONT_CMD_END; - ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - } - ret = __osSiRawStartDma(OS_READ, &__osContPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ptr = (u8*)&__osContPifRam.ramarray + port; - - header = *((__OSContRequesFormatShort*)ptr); - - ret = (u8)CHNL_ERR(header); - *status = header.status; - - if (ret == 0) { - if (header.typeh == 0 && header.typel == 1) { - if (header.status & 4) { - ret = CONT_ERR_CONTRFAIL; - } - } else { - ret = CONT_ERR_DEVICE; - } - } else if (ret & CONT_NO_RESPONSE_ERROR) { - ret = CONT_ERR_NO_CONTROLLER; - } else { - ret = CONT_ERR_CONTRFAIL; - } - } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); - - __osSiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/voice/voiceinit.c b/lib/ultralib/src/voice/voiceinit.c deleted file mode 100644 index 5074a84..0000000 --- a/lib/ultralib/src/voice/voiceinit.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 osVoiceInit(OSMesgQueue* mq, OSVoiceHandle* handle, int channel) { - s32 ret; - s32 i; - u8 stat = 0; - u8 buf[4]; - static u8 cmd[] = { 0x1E, 0x6E, 0x08, 0x56, 0x03 }; - - handle->__channel = channel; - handle->__mq = mq; - handle->__mode = 0; - - ERRCK(__osVoiceGetStatus(mq, channel, &stat)); - - ret = __osContChannelReset(mq, channel); - if (ret != 0) { - return CONT_ERR_CONTRFAIL; - } - - for (i = 0; i < ARRLEN(cmd); i++) { - ERRCK(__osVoiceSetADConverter(mq, channel, cmd[i])); - } - - ERRCK(__osVoiceGetStatus(mq, channel, &stat)); - if (stat & 2) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - *(u32*)buf = 0x100; - ERRCK(__osVoiceContWrite4(mq, channel, 0, buf)); - - ret = __osVoiceCheckResult(handle, &stat); - if (ret & 0xFF00) { - ret = CONT_ERR_INVALID; - } - - return ret; -} diff --git a/lib/ultralib/src/voice/voiceinternal.h b/lib/ultralib/src/voice/voiceinternal.h deleted file mode 100644 index 8dc6299..0000000 --- a/lib/ultralib/src/voice/voiceinternal.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef VOICE_INTERNAL_H -#define VOICE_INTERNAL_H - -// Various prototypes and externs that don't show up in os_voice.h -extern s32 __osPfsLastChannel; - -s32 __osContChannelReset(OSMesgQueue* mq, int channel); - -s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* stat); -s32 __osVoiceContRead2(OSMesgQueue* mq, int channel, u16 address, u8* buffer); -s32 __osVoiceContRead36(OSMesgQueue* mq, int channel, u16 address, u8* buffer); -s32 __osVoiceContWrite4(OSMesgQueue* mq, int channel, u16 address, u8* buffer); -s32 __osVoiceContWrite20(OSMesgQueue* mq, int channel, u16 address, u8* buffer); -u8 __osVoiceContDataCrc(u8* data, u32 length); -s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 port, u8* status); -s32 __osVoiceSetADConverter(OSMesgQueue*, s32 channel, u8 cmd); - -#endif diff --git a/lib/ultralib/src/voice/voicemaskdictionary.c b/lib/ultralib/src/voice/voicemaskdictionary.c deleted file mode 100644 index 39db7ac..0000000 --- a/lib/ultralib/src/voice/voicemaskdictionary.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 osVoiceMaskDictionary(OSVoiceHandle* hd, u8* pattern, int size) { - s32 ret = 0; - s32 i; - s32 j; - u8 stat; - u8 buf[20]; - - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); - if (ret != 0) { - return ret; - } else if (stat & 2) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - if (size & 1) { - j = size + 1; - } else { - j = size; - } - - bzero(&buf, ARRLEN(buf)); - - buf[18 - j] = 4; - - for (i = 0; i < j; i += 2) { - buf[i + ARRLEN(buf) - j] = pattern[i]; - buf[i + ARRLEN(buf) - j + 1] = pattern[i + 1]; - } - - if (size & 1) { - buf[ARRLEN(buf) - 1] = 0; - } - - ret = __osVoiceContWrite20(hd->__mq, hd->__channel, 0, (u8*)&buf); - if (ret == 0) { - ret = __osVoiceCheckResult(hd, &stat); - if (ret & 0xFF00) { - ret = CONT_ERR_INVALID; - } - } - - return ret; -} diff --git a/lib/ultralib/src/voice/voicesetadconverter.c b/lib/ultralib/src/voice/voicesetadconverter.c deleted file mode 100644 index d1c5eb2..0000000 --- a/lib/ultralib/src/voice/voicesetadconverter.c +++ /dev/null @@ -1,69 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" -#include "io/controller_voice.h" -#include "io/siint.h" - -#define SWRITEFORMAT(ptr) ((__OSVoiceSWriteFormat*)(ptr)) - -s32 __osVoiceSetADConverter(OSMesgQueue* mq, s32 channel, u8 data) { - s32 ret = 0; - int i; - u8* ptr; - u8 status; - int retry = 2; - - __osSiGetAccess(); - - do { - - ptr = (u8*)__osPfsPifRam.ramarray; - - if ((__osContLastCmd != CONT_CMD_SWRITE_VOICE) || (__osPfsLastChannel != channel)) { - __osContLastCmd = CONT_CMD_SWRITE_VOICE; - __osPfsLastChannel = channel; - - for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - - SWRITEFORMAT(ptr)->txsize = CONT_CMD_SWRITE_VOICE_TX; - SWRITEFORMAT(ptr)->rxsize = CONT_CMD_SWRITE_VOICE_RX; - SWRITEFORMAT(ptr)->cmd = CONT_CMD_SWRITE_VOICE; - SWRITEFORMAT(ptr)->datacrc = 0; - - ptr[sizeof(__OSVoiceSWriteFormat)] = CONT_CMD_END; - } else { - ptr += channel; - } - - SWRITEFORMAT(ptr)->data = data; - SWRITEFORMAT(ptr)->scrc = __osContAddressCrc(data << 3); - - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - - ret = CHNL_ERR(*SWRITEFORMAT(ptr)); - - if (ret == 0) { - if (SWRITEFORMAT(ptr)->datacrc & 1) { - ret = __osVoiceGetStatus(mq, channel, &status); - if (ret != 0) { - break; - } else { - ret = CONT_ERR_CONTRFAIL; - } - } - } else { - ret = CONT_ERR_NO_CONTROLLER; - } - - } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); - - __osSiRelAccess(); - - return ret; -} diff --git a/lib/ultralib/src/voice/voicesetword.c b/lib/ultralib/src/voice/voicesetword.c deleted file mode 100644 index 7969fae..0000000 --- a/lib/ultralib/src/voice/voicesetword.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word) { - s32 j; - s32 k; - s32 ret; - u8 stat; - u8 buf[40]; - - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); - if (ret != 0) { - return ret; - } else if (stat & 2) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - for (k = 0; word[k] != 0; k += 2) { - ; - } - -#ifndef NDEBUG - if (k >= 34) { - return CONT_ERR_VOICE_WORD; - } -#endif - - bzero(buf, ARRLEN(buf)); - - for (j = 0; j < k; j += 2) { - buf[ARRLEN(buf) - 1 - k + j] = word[j]; - buf[ARRLEN(buf) - 1 - k + j - 1] = word[j + 1]; - } - - buf[ARRLEN(buf) - 1 - j - 5] = 3; - - if (k >= 15) { - ERRCK(__osVoiceContWrite20(hd->__mq, hd->__channel, 0, buf)); - } - ERRCK(__osVoiceContWrite20(hd->__mq, hd->__channel, 0, buf + 20)); - ret = __osVoiceCheckResult(hd, &stat); - if (ret != 0) { - if (ret & 0x100) { - ret = CONT_ERR_VOICE_MEMORY; - } else if (ret & 0x200) { - ret = CONT_ERR_VOICE_WORD; - } else if (ret & 0xFF00) { - ret = CONT_ERR_INVALID; - } - } - return ret; -} diff --git a/lib/ultralib/src/voice/voicestartreaddata.c b/lib/ultralib/src/voice/voicestartreaddata.c deleted file mode 100644 index ea83da0..0000000 --- a/lib/ultralib/src/voice/voicestartreaddata.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" - -s32 osVoiceStartReadData(OSVoiceHandle* hd) { - s32 ret; - u8 stat; - u8 temp[4]; - - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); - if (ret != 0) { - return ret; - } else if (stat & 2) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - if (hd->__mode != 0) { - return CONT_ERR_INVALID; - } - - *(u32*)temp = 0x5000000; - ret = __osVoiceContWrite4(hd->__mq, hd->__channel, 0, temp); - - if (ret == 0) { - ret = __osVoiceCheckResult(hd, &stat); - - if (ret & 0xFF00) { - ret = CONT_ERR_INVALID; - } else { - hd->__mode = 1; - } - } - - return ret; -} diff --git a/lib/ultralib/src/voice/voicestopreaddata.c b/lib/ultralib/src/voice/voicestopreaddata.c deleted file mode 100644 index b43eb81..0000000 --- a/lib/ultralib/src/voice/voicestopreaddata.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "PR/os_internal.h" -#include "io/controller.h" -#include "PR/os_voice.h" -#include "voiceinternal.h" -#include "os_version.h" - -s32 osVoiceStopReadData(OSVoiceHandle* hd) { - s32 ret; -#if BUILD_VERSION >= VERSION_K - s32 i; -#endif - u8 stat; - u8 temp[4]; - - ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); - if (ret != 0) { - return ret; - } else if (stat & 2) { - return CONT_ERR_VOICE_NO_RESPONSE; - } - - if (hd->__mode == 0) { - return CONT_ERR_INVALID; - } - - *(u32*)temp = 0x700; - ret = __osVoiceContWrite4(hd->__mq, hd->__channel, 0, temp); - - if (ret == 0) { -#if BUILD_VERSION >= VERSION_K - i = 0; -#endif - do { - ret = __osVoiceCheckResult(hd, &stat); - if (ret & 0xFF00) { - if (((ret & 7) == 0) || ((ret & 7) == 7)) { - ret = 0; - hd->__mode = 0; - } else { - ret = CONT_ERR_INVALID; - } - } else { - hd->__mode = 0; - } -#if BUILD_VERSION >= VERSION_K - i++; - } while ((ret == CONT_ERR_VOICE_NO_RESPONSE) && (i < 20)); -#else - } while ((ret == CONT_ERR_VOICE_NO_RESPONSE)); -#endif - } -#if BUILD_VERSION >= VERSION_K - if (i >= 20) { - ret == CONT_ERR_VOICE_NO_RESPONSE; - } -#endif - - return ret; -} diff --git a/lib/ultralib/tools/Makefile b/lib/ultralib/tools/Makefile deleted file mode 100644 index cf0d35e..0000000 --- a/lib/ultralib/tools/Makefile +++ /dev/null @@ -1,46 +0,0 @@ - -.PHONY: all clean distclean - -# GCC -GCC_DIR := gcc -AR := $(GCC_DIR)/ar -GCC-2.7.2 := $(GCC_DIR)/gcc -STRIP-2.7 := $(GCC_DIR)/strip-2.7 - -# IDO -IDO_DIR := ido -IDO-5.3 := $(IDO_DIR)/cc - -all: $(AR) $(GCC-2.7.2) $(STRIP-2.7) $(IDO-5.3) - -$(AR): | $(GCC_DIR) - wget https://github.com/decompals/mips-binutils-2.6/releases/download/main/binutils-2.6-linux.tar.gz - tar xf binutils-2.6-linux.tar.gz -C $(GCC_DIR) - $(RM) binutils-2.6-linux.tar.gz - -$(GCC-2.7.2): | $(GCC_DIR) - wget https://github.com/decompals/mips-gcc-2.7.2/releases/download/main/gcc-2.7.2-linux.tar.gz - tar xf gcc-2.7.2-linux.tar.gz -C $(GCC_DIR) - $(RM) gcc-2.7.2-linux.tar.gz - -$(STRIP-2.7): | $(GCC_DIR) - wget https://github.com/decompals/mips-binutils-2.7/releases/download/release/binutils-2.7.tar.gz - tar xf binutils-2.7.tar.gz -C $(GCC_DIR) - $(RM) binutils-2.7.tar.gz - -$(GCC_DIR): - mkdir -p $@ - -$(IDO-5.3): | $(IDO_DIR) - wget https://github.com/decompals/ido-static-recomp/releases/latest/download/ido-5.3-recomp-linux.tar.gz - tar xf ido-5.3-recomp-linux.tar.gz -C $(IDO_DIR) - $(RM) ido-5.3-recomp-linux.tar.gz - -$(IDO_DIR): - mkdir -p $@ - -clean: - $(RM) -rf $(GCC_DIR) - $(RM) -rf $(IDO_DIR) - -distclean: clean diff --git a/lib/ultralib/tools/ar.py b/lib/ultralib/tools/ar.py deleted file mode 100755 index 0f3e574..0000000 --- a/lib/ultralib/tools/ar.py +++ /dev/null @@ -1,476 +0,0 @@ -#!/usr/bin/env python3 -# -# ar -# - -from genericpath import isfile -import os, struct, time -from dataclasses import dataclass -from libelf import ElfFile, SB_GLOBAL, SHN_UND - -class Archive: - @dataclass - class ArchiveFileRecord: - """ - AR file headers + data - - Offset Length Name Format - 0 16 File identifier ASCII - 16 12 File modification timestamp (in seconds) Decimal - 28 6 Owner ID Decimal - 34 6 Group ID Decimal - 40 8 File mode (type and permission) Octal - 48 10 File size in bytes Decimal - 58 2 Ending characters 0x60 0x0A - """ - name : str - time : int - uid : int - gid : int - mode : int - size : int - data : bytes - - def __init__(self): - self.files = [] # List[ArchiveFileRecord] - self.armap_entries = None - self.time = int(time.time()) - - def add_data(self, name, time, uid, gid, mode, size, data): - self.files.append(Archive.ArchiveFileRecord(name, time, uid, gid, mode, size, data)) - - def add_file(self, file_path): - if not os.path.isfile(file_path): - print(f"Error: No file named {file_path}") - return - - st = os.stat(file_path) - name = os.path.basename(file_path) - time = int(st.st_mtime) - uid = st.st_uid - gid = st.st_gid - mode = st.st_mode - size = st.st_size - - data = None - with open(file_path, "rb") as infile: - data = bytes(infile.read()) - - self.add_data(name, time, uid, gid, mode, size, data) - - def add_ar(self, file_path): - for file in Archive.from_file(file_path).files: - self.add_data(file) - - def build_image(self): - def add_bin(ba, bin): - for b in bin: - ba.append(b) - - def add_str(ba, s, pad_to_len=-1): - if pad_to_len != -1: - s = f"{s:{pad_to_len}}" - s = s.encode("ASCII") - for c in s: - ba.append(c) - - def add_pad(ba): - if len(ba) % 2 != 0: - ba.append(0) - - def add_ar_hdr(ba, name, time, uid, gid, mode, length): - add_str(ba, name, 16) - add_str(ba, str(time), 12) - add_str(ba, str(uid), 6) - add_str(ba, str(gid), 6) - add_str(ba, oct(mode)[2:], 8) - add_str(ba, str(length), 10) - add_str(ba, "`\n") - - b = bytearray() - - # MAGIC - - add_str(b, "!\n") - - # ARMAP - - armap_data= bytearray() - - armap_entries_files = [] - - num_entries = 0 - armap_size = 4 - armap_string_data = bytearray() - for i,file in enumerate(self.files): - elf = ElfFile(file.data) - if elf.symtab is not None: - for sym in elf.symtab.symbol_entries: - if sym.st_shndx != SHN_UND and sym.bind == SB_GLOBAL: - num_entries += 1 - armap_size += 4 + len(sym.name) + 1 - armap_string_data.extend(sym.name.encode("latin1") + b'\0') - armap_entries_files.append(i) - - armap_data.extend(struct.pack(">I", num_entries)) - armap_data.extend([0] * 4 * num_entries) # defer writing file positions until files are emplaced later - armap_data.extend(armap_string_data) - - if len(armap_data) % 4 != 0: - alsiz = (len(armap_data) + 3) & ~3 - armap_data.extend([0] * (alsiz - len(armap_data))) - - current_time = int(time.time()) - - add_ar_hdr(b, "/", current_time, 0, 0, 0, len(armap_data)) - armap_offsets_start = len(b) + 4 - add_bin(b, armap_data) - add_pad(b) - - # LONG STRINGS - - long_strings = "" - - file_names = [] - flag = False - for _,file in enumerate(self.files): - if len(file.name) >= 16: - fname = f"{file.name}/\n" - ind = len(long_strings) - long_strings += fname - else: - fname = f"{file.name}/" - ind = None - file_names.append((fname, ind)) - - # Weird hack - if len(long_strings) != 0 and not flag: - flag = True - long_strings += "/\n" - - long_strings += "/" - - add_ar_hdr(b, "//", current_time, 0, 0, 0, len(long_strings)) - add_str(b, long_strings) - add_pad(b) - - # FILES - - armap_pos = 0 - for i,(file,(fname,ind)) in enumerate(zip(self.files, file_names)): - file_pos = len(b) - add_ar_hdr(b, f"/{ind}" if ind is not None else fname, file.time, file.uid, file.gid, file.mode, file.size) - add_bin(b, file.data) - add_pad(b) - - # Patch the armap with file locations - while armap_pos < len(armap_entries_files) and armap_entries_files[armap_pos] == i: - b[armap_offsets_start+armap_pos*4:armap_offsets_start+armap_pos*4+4] = struct.pack(">I", file_pos) - armap_pos += 1 - - return b - - def write(self, file_path): - ar = self.build_image() - with open(file_path, "wb") as outfile: - outfile.write(ar) - - @staticmethod - def from_image(ar_data): - long_strings = None - ar = Archive() - - assert ar_data[:8].decode("ASCII") == "!\n" , "Not an archive file? Bad file magic value" - - i = 8 - while i < len(ar_data): - file_name = ar_data[i:][ 0:][:16].decode("ASCII").strip() - file_time = int(ar_data[i:][16:][:12].decode("ASCII").strip()) - file_uid = int(ar_data[i:][28:][: 6].decode("ASCII").strip()) - file_gid = int(ar_data[i:][34:][: 6].decode("ASCII").strip()) - file_mode = int(ar_data[i:][40:][: 8].decode("ASCII").strip(), 8) - file_size = int(ar_data[i:][48:][:10].decode("ASCII").strip()) - end = ar_data[i:][58:][:2].decode("ASCII") - assert end == "`\n" - - data = ar_data[i:][60:][:file_size] - assert len(data) == file_size - - if file_name == '/': - """ - "armap" - The special filename "/" denotes that this entry contains a symbol lookup table used by some libraries - to speed up file access. - The symbol table is comprised of three contiguous parts: - - A 32-bit Big Endian integer recording the number of symbol entries. - - A list of 32-bit Big Endian integers for each symbol entry, recording the position within the - archive of the header of the file containing the symbol. - - A list of null-terminated strings, the symbol names for each symbol entry. - - We rebuild this from scratch on write out. - """ - ar.time = file_time - assert file_uid == 0 - assert file_gid == 0 - assert file_mode == 0 - - # Code to interpret the armap, currently unused - """ - armap_n_syms = struct.unpack(">I", data[0:4])[0] - offsets = [i[0] for i in struct.iter_unpack(">I", data[4:4+4*armap_n_syms])] - - strings = [] - ofs = 4 + 4 * armap_n_syms - for _ in range(armap_n_syms): - to = data.find(b'\0', ofs) - assert to != -1 - string = data[ofs:to].decode('latin1') - strings.append(string) - ofs += len(string) + 1 - assert all([b == 0 for b in data[ofs:]]) - assert len(strings) == len(offsets) - - ar.armap_entries = list(zip(offsets, strings)) - """ - elif file_name == '//': - """ - Long string table. Strings larger than 16 are placed here and referenced from the header by /. - - We rebuild this from scratch on write out. - """ - assert file_time == ar.time - assert file_uid == 0 - assert file_gid == 0 - assert file_mode == 0 - long_strings = data.decode("ASCII") - else: - """ - Normal files. - """ - if file_name.startswith("/"): - assert long_strings is not None - # Fetch the name from the long string table - file_name = long_strings[int(file_name[1:]):].split("\n")[0] - # Add file - ar.add_data(file_name[:-1], file_time, file_uid, file_gid, file_mode, file_size, data) - - if file_size % 2 != 0: - file_size += 1 - i += 60 + file_size - - return ar - - @staticmethod - def from_file(file_path): - ar_file = None - with open(file_path, "rb") as infile: - ar_file = infile.read() - - return Archive.from_image(ar_file) - -def ar_usage(progname): - print(f"Usage: {progname} [-]{{dmpqrstx}}[abcDfilMNoOPsSTuvV] [member-name] [count] archive-file file...") - print(f" commands:") - print(f" d - delete file(s) from the archive") - print(f" m[ab] - move file(s) in the archive") - print(f" p - print file(s) found in the archive") - print(f" q[f] - quick append file(s) to the archive") - print(f" r[ab][f][u] - replace existing or insert new file(s) into the archive") - print(f" s - act as ranlib") - print(f" t[O][v] - display contents of the archive") - print(f" x[o] - extract file(s) from the archive") - print(f" command specific modifiers:") - print(f" [a] - put file(s) after [member-name]") - print(f" [b] - put file(s) before [member-name] (same as [i])") - print(f" [D] - use zero for timestamps and uids/gids (default)") - print(f" [U] - use actual timestamps and uids/gids") - print(f" [N] - use instance [count] of name") - print(f" [f] - truncate inserted file names") - print(f" [P] - use full path names when matching") - print(f" [o] - preserve original dates") - print(f" [O] - display offsets of files in the archive") - print(f" [u] - only replace files that are newer than current archive contents") - print(f" generic modifiers:") - print(f" [c] - do not warn if the library had to be created") - print(f" [s] - create an archive index (cf. ranlib)") - print(f" [S] - do not build a symbol table") - print(f" [v] - be verbose") - print(f" [V] - display the version number") - print(f" @ - read options from ") - print(f" --output=DIRNAME - specify the output directory for extraction operations") - return 1 - -def ar(argv): - if len(argv) < 2: - return ar_usage(argv[0]) - - progname = argv[0] - create_ok = False - make_ar_idx = False - no_symtab = False - verbose = False - - def verbose_print(msg): - if verbose: - print(msg) - - def dcmd(modifiers, args): - if modifiers != "": - print(f"{progname}: bad modifiers -- '{modifiers}'") - return ar_usage(progname) - - ar_file = args[0] - o_files = args[1:] - - ar = Archive.from_file(ar_file) - for file in ar.files: - if file.name in o_files: - ar.files.remove(file) - ar.write(ar_file) - return 0 - - def mcmd(modifiers, args): - print("") - return 1 - - def pcmd(modifiers, args): - if modifiers != "": - print(f"{progname}: bad modifiers -- '{modifiers}'") - return ar_usage(progname) - if len(args) != 1: - print(f"{progname} p: bad args") - return ar_usage(progname) - - ar_file = args[0] - - ar = Archive.from_file(ar_file) - for file in ar.files: - print(file.data) - return 0 - - def qcmd(modifiers, args): - print("") - return 1 - - def rcmd(modifiers, args): - if modifiers !="": - print("") - if len(args) < 2: - print(f"{progname} r: bad args") - return ar_usage(progname) - - ar_file = args[0] - o_files = args[1:] - - ar = Archive() - if os.path.isfile(ar_file): - ar = Archive.from_file(ar_file) - else: - if not create_ok: - print(f"Warning: Created file {ar_file}") - ar = Archive() - - for o_file in o_files: - ar.add_file(o_file) - - ar.write(ar_file) - - def scmd(modifiers, args): - print("") - return 1 - - def tcmd(modifiers, args): - # TODO modifiers - - if len(args) != 1: - print(f"{progname} t: bad args") - return ar_usage(progname) - - ar_file = args[0] - - ar = Archive.from_file(ar_file) - for file in ar.files: - print(file.name) - return 0 - - def xcmd(modifiers, args): - if modifiers not in ('', 'o'): - print(f"{progname}: bad modifiers -- '{modifiers}'") - return ar_usage(progname) - if len(args) not in (1, 3) or not (args[0].startswith("--output") or args[1].startswith("--output")): - print(f"{progname} t: bad args") - return ar_usage(progname) - - original_times = modifiers == 'o' - - if args[0].startswith("--output"): - out_dir = args[1] - ar_file = args[2] - elif args[1].startswith("--output"): - out_dir = args[2] - ar_file = args[0] - else: - ar_file = args[0] - out_dir = "" - - # Create dir if not exists - if not os.path.exists(out_dir): - os.makedirs(out_dir, exist_ok=True) - - if not os.path.isdir(out_dir): - print(f"Output directory {out_dir} is a file") - return ar_usage(progname) - - # Extract files to destination - ar = Archive.from_file(ar_file) - for file in ar.files: - opath =os.path.join(out_dir, file.name) - with open(opath, "wb") as ofile: - ofile.write(file.data) - - if not original_times: - t = time.time() - os.utime(opath, (t, t)) - # TODO patch with original dates etc. - - return 0 - - argtbl = { - 'd': dcmd, # delete file(s) from the archive - 'm': mcmd, # [ab] move file(s) in the archive - 'p': pcmd, # print file(s) found in the archive - 'q': qcmd, # [f] quick append file(s) to the archive - 'r': rcmd, # [ab][f][u] replace existing or insert new file(s) into the archive - 's': scmd, # act as ranlib - 't': tcmd, # [O][v] display contents of the archive - 'x': xcmd, # [o] extract file(s) from the archive - } - - arg1 = argv[1] - if arg1[0] == '-': - arg1 = arg1[1:] - cmd = arg1[0] - - if cmd not in argtbl: - print(f"{progname}: invalid option -- '{cmd}'") - return ar_usage(argv[0]) - - modifiers = arg1[1:] - - create_ok = "c" in modifiers - modifiers = modifiers.replace("c","") - make_ar_idx = "s" in modifiers - modifiers = modifiers.replace("s","") - no_symtab = "S" in modifiers - modifiers = modifiers.replace("S","") - verbose = "v" in modifiers - modifiers = modifiers.replace("v","") - - if "V" in modifiers: - print(f"{progname} v1.0") - - return argtbl[cmd](modifiers, argv[2:]) - -if __name__ == '__main__': - import sys - sys.exit(ar(sys.argv)) diff --git a/lib/ultralib/tools/asm_differ/.gitignore b/lib/ultralib/tools/asm_differ/.gitignore deleted file mode 100644 index eb176dc..0000000 --- a/lib/ultralib/tools/asm_differ/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.mypy_cache/ -__pycache__/ diff --git a/lib/ultralib/tools/asm_differ/.gitrepo b/lib/ultralib/tools/asm_differ/.gitrepo deleted file mode 100644 index 2e999c8..0000000 --- a/lib/ultralib/tools/asm_differ/.gitrepo +++ /dev/null @@ -1,12 +0,0 @@ -; DO NOT EDIT (unless you know what you are doing) -; -; This subdirectory is a git "subrepo", and this file is maintained by the -; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme -; -[subrepo] - remote = https://github.com/simonlindholm/asm-differ - branch = main - commit = 4b38c884c1efdc3bfa8b14f13015a69368a8d3a2 - parent = 32a1a8061de197c4f10d4904cd72a22dd7cf905c - method = merge - cmdver = 0.4.3 diff --git a/lib/ultralib/tools/asm_differ/.pre-commit-config.yaml b/lib/ultralib/tools/asm_differ/.pre-commit-config.yaml deleted file mode 100644 index 6695f71..0000000 --- a/lib/ultralib/tools/asm_differ/.pre-commit-config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -repos: -- repo: https://github.com/psf/black - rev: 20.8b1 - hooks: - - id: black - language_version: python3.6 diff --git a/lib/ultralib/tools/asm_differ/LICENSE b/lib/ultralib/tools/asm_differ/LICENSE deleted file mode 100644 index cf1ab25..0000000 --- a/lib/ultralib/tools/asm_differ/LICENSE +++ /dev/null @@ -1,24 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to diff --git a/lib/ultralib/tools/asm_differ/README.md b/lib/ultralib/tools/asm_differ/README.md deleted file mode 100644 index 4a7f329..0000000 --- a/lib/ultralib/tools/asm_differ/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# asm-differ - -Nice differ for assembly code. Currently supports MIPS, PPC, AArch64, and ARM32; should be easy to hack to support other instruction sets. - -![](screenshot.png) - -## Dependencies - -- Python >= 3.6 -- `python3 -m pip install --user colorama watchdog python-Levenshtein` (also `dataclasses` if on 3.6) - -## Usage - -Create a file `diff_settings.sh` in some directory (see the one in this repo for an example). Then from that directory, run - -```bash -/path/to/diff.sh [flags] (function|rom addr) -``` - -Recommended flags are `-mwo` (automatically run `make` on source file changes, and include symbols in diff). See `--help` for more details. - -### Tab completion - -[argcomplete](https://kislyuk.github.io/argcomplete/) can be optionally installed (with `python3 -m pip install argcomplete`) to enable tab completion in a bash shell, completing options and symbol names using the linker map. It also requires a bit more setup: - -If invoking the script **exactly** as `./diff.py`, the following should be added to the `.bashrc` according to argcomplete's instructions: - -```bash -eval "$(register-python-argcomplete ./diff.py)" -``` - -If that doesn't work, run `register-python-argcomplete ./diff.py` in your terminal and copy the output to `.bashrc`. - -If setup correctly (don't forget to restart the shell), `complete | grep ./diff.py` should output: - -```bash -complete -o bashdefault -o default -o nospace -F _python_argcomplete ./diff.py -``` - -Note for developers or for general troubleshooting: run `export _ARC_DEBUG=` to enable debug output during tab-completion, it may show otherwise silenced errors. Use `unset _ARC_DEBUG` or restart the terminal to disable. - -### Contributing - -Contributions are very welcome! Some notes on workflow: - -`black` is used for code formatting. You can either run `black diff.py` manually, or set up a pre-commit hook: -```bash -pip install pre-commit black -pre-commit install -``` - -Type annotations are used for all Python code. `mypy` should pass without any errors. - -PRs that skip the above are still welcome, however. - -The targeted Python version is 3.6. There are currently no tests. diff --git a/lib/ultralib/tools/asm_differ/diff-stylesheet.css b/lib/ultralib/tools/asm_differ/diff-stylesheet.css deleted file mode 100644 index 79da120..0000000 --- a/lib/ultralib/tools/asm_differ/diff-stylesheet.css +++ /dev/null @@ -1,67 +0,0 @@ -table.diff { - border: none; - font-family: Monospace; - white-space: pre; -} -tr.data-ref { - background-color: gray; -} -.immediate { - color: lightblue; -} -.stack { - color: yellow; -} -.register { - color: yellow; -} -.delay-slot { - font-weight: bold; - color: gray; -} -.diff-change { - color: lightblue; -} -.diff-add { - color: green; -} -.diff-remove { - color: red; -} -.source-filename { - font-weight: bold; -} -.source-function { - font-weight: bold; - text-decoration: underline; -} -.source-other { - font-style: italic; -} -.rotation-0 { - color: magenta; -} -.rotation-1 { - color: cyan; -} -.rotation-2 { - color: green; -} -.rotation-3 { - color: red; -} -.rotation-4 { - color: yellow; -} -.rotation-5 { - color: pink; -} -.rotation-6 { - color: blue; -} -.rotation-7 { - color: lime; -} -.rotation-8 { - color: gray; -} diff --git a/lib/ultralib/tools/asm_differ/diff.py b/lib/ultralib/tools/asm_differ/diff.py deleted file mode 100755 index 8ed764f..0000000 --- a/lib/ultralib/tools/asm_differ/diff.py +++ /dev/null @@ -1,2923 +0,0 @@ -#!/usr/bin/env python3 -# PYTHON_ARGCOMPLETE_OK -import argparse -import sys -from typing import ( - Any, - Callable, - Dict, - Iterator, - List, - Match, - NoReturn, - Optional, - Pattern, - Set, - Tuple, - Type, - Union, -) - - -def fail(msg: str) -> NoReturn: - print(msg, file=sys.stderr) - sys.exit(1) - - -def static_assert_unreachable(x: NoReturn) -> NoReturn: - raise Exception("Unreachable! " + repr(x)) - - -# ==== COMMAND-LINE ==== - -if __name__ == "__main__": - # Prefer to use diff_settings.py from the current working directory - sys.path.insert(0, ".") - try: - import diff_settings - except ModuleNotFoundError: - fail("Unable to find diff_settings.py in the same directory.") - sys.path.pop(0) - - try: - import argcomplete - except ModuleNotFoundError: - argcomplete = None - - parser = argparse.ArgumentParser( - description="Diff MIPS, PPC, AArch64, or ARM32 assembly." - ) - - start_argument = parser.add_argument( - "start", - help="Function name or address to start diffing from.", - ) - - if argcomplete: - - def complete_symbol( - prefix: str, parsed_args: argparse.Namespace, **kwargs: object - ) -> List[str]: - if not prefix or prefix.startswith("-"): - # skip reading the map file, which would - # result in a lot of useless completions - return [] - config: Dict[str, Any] = {} - diff_settings.apply(config, parsed_args) # type: ignore - mapfile = config.get("mapfile") - if not mapfile: - return [] - completes = [] - with open(mapfile) as f: - data = f.read() - # assume symbols are prefixed by a space character - search = f" {prefix}" - pos = data.find(search) - while pos != -1: - # skip the space character in the search string - pos += 1 - # assume symbols are suffixed by either a space - # character or a (unix-style) line return - spacePos = data.find(" ", pos) - lineReturnPos = data.find("\n", pos) - if lineReturnPos == -1: - endPos = spacePos - elif spacePos == -1: - endPos = lineReturnPos - else: - endPos = min(spacePos, lineReturnPos) - if endPos == -1: - match = data[pos:] - pos = -1 - else: - match = data[pos:endPos] - pos = data.find(search, endPos) - completes.append(match) - return completes - - setattr(start_argument, "completer", complete_symbol) - - parser.add_argument( - "end", - nargs="?", - help="Address to end diff at.", - ) - parser.add_argument( - "-o", - dest="diff_obj", - action="store_true", - help="""Diff .o files rather than a whole binary. This makes it possible to - see symbol names. (Recommended)""", - ) - parser.add_argument( - "-e", - "--elf", - dest="diff_elf_symbol", - metavar="SYMBOL", - help="""Diff a given function in two ELFs, one being stripped and the other - one non-stripped. Requires objdump from binutils 2.33+.""", - ) - parser.add_argument( - "-c", - "--source", - dest="show_source", - action="store_true", - help="Show source code (if possible). Only works with -o or -e.", - ) - parser.add_argument( - "-C", - "--source-old-binutils", - dest="source_old_binutils", - action="store_true", - help="""Tweak --source handling to make it work with binutils < 2.33. - Implies --source.""", - ) - parser.add_argument( - "-j", - "--section", - dest="diff_section", - default=".text", - metavar="SECTION", - help="Diff restricted to a given output section.", - ) - parser.add_argument( - "-L", - "--line-numbers", - dest="show_line_numbers", - action="store_const", - const=True, - help="""Show source line numbers in output, when available. May be enabled by - default depending on diff_settings.py.""", - ) - parser.add_argument( - "--no-line-numbers", - dest="show_line_numbers", - action="store_const", - const=False, - help="Hide source line numbers in output.", - ) - parser.add_argument( - "--inlines", - dest="inlines", - action="store_true", - help="Show inline function calls (if possible). Only works with -o or -e.", - ) - parser.add_argument( - "--base-asm", - dest="base_asm", - metavar="FILE", - help="Read assembly from given file instead of configured base img.", - ) - parser.add_argument( - "--write-asm", - dest="write_asm", - metavar="FILE", - help="Write the current assembly output to file, e.g. for use with --base-asm.", - ) - parser.add_argument( - "-m", - "--make", - dest="make", - action="store_true", - help="Automatically run 'make' on the .o file or binary before diffing.", - ) - parser.add_argument( - "-l", - "--skip-lines", - dest="skip_lines", - metavar="LINES", - type=int, - default=0, - help="Skip the first LINES lines of output.", - ) - parser.add_argument( - "-s", - "--stop-jr-ra", - dest="stop_jrra", - action="store_true", - help="""Stop disassembling at the first 'jr ra'. Some functions have - multiple return points, so use with care!""", - ) - parser.add_argument( - "-i", - "--ignore-large-imms", - dest="ignore_large_imms", - action="store_true", - help="Pretend all large enough immediates are the same.", - ) - parser.add_argument( - "-I", - "--ignore-addr-diffs", - dest="ignore_addr_diffs", - action="store_true", - help="Ignore address differences. Currently only affects AArch64 and ARM32.", - ) - parser.add_argument( - "-B", - "--no-show-branches", - dest="show_branches", - action="store_false", - help="Don't visualize branches/branch targets.", - ) - parser.add_argument( - "-S", - "--base-shift", - dest="base_shift", - metavar="N", - type=str, - default="0", - help="""Diff position N in our img against position N + shift in the base img. - Arithmetic is allowed, so e.g. |-S "0x1234 - 0x4321"| is a reasonable - flag to pass if it is known that position 0x1234 in the base img syncs - up with position 0x4321 in our img. Not supported together with -o.""", - ) - parser.add_argument( - "-w", - "--watch", - dest="watch", - action="store_true", - help="""Automatically update when source/object files change. - Recommended in combination with -m.""", - ) - parser.add_argument( - "-3", - "--threeway=prev", - dest="threeway", - action="store_const", - const="prev", - help="""Show a three-way diff between target asm, current asm, and asm - prior to -w rebuild. Requires -w.""", - ) - parser.add_argument( - "-b", - "--threeway=base", - dest="threeway", - action="store_const", - const="base", - help="""Show a three-way diff between target asm, current asm, and asm - when diff.py was started. Requires -w.""", - ) - parser.add_argument( - "--width", - dest="column_width", - metavar="COLS", - type=int, - default=50, - help="Sets the width of the left and right view column.", - ) - parser.add_argument( - "--algorithm", - dest="algorithm", - default="levenshtein", - choices=["levenshtein", "difflib"], - help="""Diff algorithm to use. Levenshtein gives the minimum diff, while difflib - aims for long sections of equal opcodes. Defaults to %(default)s.""", - ) - parser.add_argument( - "--max-size", - "--max-lines", - metavar="LINES", - dest="max_lines", - type=int, - default=1024, - help="The maximum length of the diff, in lines.", - ) - parser.add_argument( - "--no-pager", - dest="no_pager", - action="store_true", - help="""Disable the pager; write output directly to stdout, then exit. - Incompatible with --watch.""", - ) - parser.add_argument( - "--format", - choices=("color", "plain", "html", "json"), - default="color", - help="Output format, default is color. --format=html or json implies --no-pager.", - ) - parser.add_argument( - "-U", - "--compress-matching", - metavar="N", - dest="compress_matching", - type=int, - help="""Compress streaks of matching lines, leaving N lines of context - around non-matching parts.""", - ) - parser.add_argument( - "-V", - "--compress-sameinstr", - metavar="N", - dest="compress_sameinstr", - type=int, - help="""Compress streaks of lines with same instructions (but possibly - different regalloc), leaving N lines of context around other parts.""", - ) - - # Project-specific flags, e.g. different versions/make arguments. - add_custom_arguments_fn = getattr(diff_settings, "add_custom_arguments", None) - if add_custom_arguments_fn: - add_custom_arguments_fn(parser) - - if argcomplete: - argcomplete.autocomplete(parser) - -# ==== IMPORTS ==== - -# (We do imports late to optimize auto-complete performance.) - -import abc -import ast -from collections import Counter, defaultdict -from dataclasses import asdict, dataclass, field, replace -import difflib -import enum -import html -import itertools -import json -import os -import queue -import re -import string -import struct -import subprocess -import threading -import time -import traceback - - -MISSING_PREREQUISITES = ( - "Missing prerequisite python module {}. " - "Run `python3 -m pip install --user colorama watchdog python-Levenshtein cxxfilt` to install prerequisites (cxxfilt only needed with --source)." -) - -try: - from colorama import Back, Fore, Style - import watchdog -except ModuleNotFoundError as e: - fail(MISSING_PREREQUISITES.format(e.name)) - -# ==== CONFIG ==== - - -@dataclass -class ProjectSettings: - arch_str: str - objdump_executable: str - build_command: List[str] - map_format: str - mw_build_dir: str - baseimg: Optional[str] - myimg: Optional[str] - mapfile: Optional[str] - source_directories: Optional[List[str]] - source_extensions: List[str] - show_line_numbers_default: bool - disassemble_all: bool - - -@dataclass -class Compress: - context: int - same_instr: bool - - -@dataclass -class Config: - arch: "ArchSettings" - - # Build/objdump options - diff_obj: bool - make: bool - source_old_binutils: bool - diff_section: str - inlines: bool - max_function_size_lines: int - max_function_size_bytes: int - - # Display options - formatter: "Formatter" - threeway: Optional[str] - base_shift: int - skip_lines: int - compress: Optional[Compress] - show_branches: bool - show_line_numbers: bool - show_source: bool - stop_jrra: bool - ignore_large_imms: bool - ignore_addr_diffs: bool - algorithm: str - - # Score options - score_stack_differences = True - penalty_stackdiff = 1 - penalty_regalloc = 5 - penalty_reordering = 60 - penalty_insertion = 100 - penalty_deletion = 100 - - -def create_project_settings(settings: Dict[str, Any]) -> ProjectSettings: - return ProjectSettings( - arch_str=settings.get("arch", "mips"), - baseimg=settings.get("baseimg"), - myimg=settings.get("myimg"), - mapfile=settings.get("mapfile"), - build_command=settings.get( - "make_command", ["make", *settings.get("makeflags", [])] - ), - source_directories=settings.get("source_directories"), - source_extensions=settings.get( - "source_extensions", [".c", ".h", ".cpp", ".hpp", ".s"] - ), - objdump_executable=get_objdump_executable(settings.get("objdump_executable")), - map_format=settings.get("map_format", "gnu"), - mw_build_dir=settings.get("mw_build_dir", "build/"), - show_line_numbers_default=settings.get("show_line_numbers_default", True), - disassemble_all=settings.get("disassemble_all", False) - ) - - -def create_config(args: argparse.Namespace, project: ProjectSettings) -> Config: - arch = get_arch(project.arch_str) - - formatter: Formatter - if args.format == "plain": - formatter = PlainFormatter(column_width=args.column_width) - elif args.format == "color": - formatter = AnsiFormatter(column_width=args.column_width) - elif args.format == "html": - formatter = HtmlFormatter() - elif args.format == "json": - formatter = JsonFormatter(arch_str=arch.name) - else: - raise ValueError(f"Unsupported --format: {args.format}") - - compress = None - if args.compress_matching is not None: - compress = Compress(args.compress_matching, False) - if args.compress_sameinstr is not None: - if compress is not None: - raise ValueError( - "Cannot pass both --compress-matching and --compress-sameinstr" - ) - compress = Compress(args.compress_sameinstr, True) - - show_line_numbers = args.show_line_numbers - if show_line_numbers is None: - show_line_numbers = project.show_line_numbers_default - - return Config( - arch=arch, - # Build/objdump options - diff_obj=args.diff_obj, - make=args.make, - source_old_binutils=args.source_old_binutils, - diff_section=args.diff_section, - inlines=args.inlines, - max_function_size_lines=args.max_lines, - max_function_size_bytes=args.max_lines * 4, - # Display options - formatter=formatter, - threeway=args.threeway, - base_shift=eval_int( - args.base_shift, "Failed to parse --base-shift (-S) argument as an integer." - ), - skip_lines=args.skip_lines, - compress=compress, - show_branches=args.show_branches, - show_line_numbers=show_line_numbers, - show_source=args.show_source or args.source_old_binutils, - stop_jrra=args.stop_jrra, - ignore_large_imms=args.ignore_large_imms, - ignore_addr_diffs=args.ignore_addr_diffs, - algorithm=args.algorithm, - ) - - -def get_objdump_executable(objdump_executable: Optional[str]) -> str: - if objdump_executable is not None: - return objdump_executable - - objdump_candidates = [ - "mips-linux-gnu-objdump", - "mips64-elf-objdump", - "mips-elf-objdump", - ] - for objdump_cand in objdump_candidates: - try: - subprocess.check_call( - [objdump_cand, "--version"], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) - return objdump_cand - except subprocess.CalledProcessError: - pass - except FileNotFoundError: - pass - - return fail( - f"Missing binutils; please ensure {' or '.join(objdump_candidates)} exists, or configure objdump_executable." - ) - - -def get_arch(arch_str: str) -> "ArchSettings": - for settings in ARCH_SETTINGS: - if arch_str == settings.name: - return settings - raise ValueError(f"Unknown architecture: {arch_str}") - - -BUFFER_CMD: List[str] = ["tail", "-c", str(10 ** 9)] - -# -S truncates long lines instead of wrapping them -# -R interprets color escape sequences -# -i ignores case when searching -# -c something about how the screen gets redrawn; I don't remember the purpose -# -#6 makes left/right arrow keys scroll by 6 characters -LESS_CMD: List[str] = ["less", "-SRic", "-#6"] - -DEBOUNCE_DELAY: float = 0.1 - -# ==== FORMATTING ==== - - -@enum.unique -class BasicFormat(enum.Enum): - NONE = enum.auto() - IMMEDIATE = enum.auto() - STACK = enum.auto() - REGISTER = enum.auto() - DELAY_SLOT = enum.auto() - DIFF_CHANGE = enum.auto() - DIFF_ADD = enum.auto() - DIFF_REMOVE = enum.auto() - SOURCE_FILENAME = enum.auto() - SOURCE_FUNCTION = enum.auto() - SOURCE_LINE_NUM = enum.auto() - SOURCE_OTHER = enum.auto() - - -@dataclass(frozen=True) -class RotationFormat: - group: str - index: int - key: str - - -Format = Union[BasicFormat, RotationFormat] -FormatFunction = Callable[[str], Format] - - -class Text: - segments: List[Tuple[str, Format]] - - def __init__(self, line: str = "", f: Format = BasicFormat.NONE) -> None: - self.segments = [(line, f)] if line else [] - - def reformat(self, f: Format) -> "Text": - return Text(self.plain(), f) - - def plain(self) -> str: - return "".join(s for s, f in self.segments) - - def __repr__(self) -> str: - return f"" - - def __bool__(self) -> bool: - return any(s for s, f in self.segments) - - def __str__(self) -> str: - # Use Formatter.apply(...) instead - return NotImplemented - - def __eq__(self, other: object) -> bool: - return NotImplemented - - def __add__(self, other: Union["Text", str]) -> "Text": - if isinstance(other, str): - other = Text(other) - result = Text() - # If two adjacent segments have the same format, merge their lines - if ( - self.segments - and other.segments - and self.segments[-1][1] == other.segments[0][1] - ): - result.segments = ( - self.segments[:-1] - + [(self.segments[-1][0] + other.segments[0][0], self.segments[-1][1])] - + other.segments[1:] - ) - else: - result.segments = self.segments + other.segments - return result - - def __radd__(self, other: Union["Text", str]) -> "Text": - if isinstance(other, str): - other = Text(other) - return other + self - - def finditer(self, pat: Pattern[str]) -> Iterator[Match[str]]: - """Replacement for `pat.finditer(text)` that operates on the inner text, - and returns the exact same matches as `Text.sub(pat, ...)`.""" - for chunk, f in self.segments: - for match in pat.finditer(chunk): - yield match - - def sub(self, pat: Pattern[str], sub_fn: Callable[[Match[str]], "Text"]) -> "Text": - result = Text() - for chunk, f in self.segments: - i = 0 - for match in pat.finditer(chunk): - start, end = match.start(), match.end() - assert i <= start <= end <= len(chunk) - sub = sub_fn(match) - if i != start: - result.segments.append((chunk[i:start], f)) - result.segments.extend(sub.segments) - i = end - if chunk[i:]: - result.segments.append((chunk[i:], f)) - return result - - def ljust(self, column_width: int) -> "Text": - length = sum(len(x) for x, _ in self.segments) - return self + " " * max(column_width - length, 0) - - -@dataclass -class TableMetadata: - headers: Tuple[Text, ...] - current_score: int - max_score: int - previous_score: Optional[int] - - -class Formatter(abc.ABC): - @abc.abstractmethod - def apply_format(self, chunk: str, f: Format) -> str: - """Apply the formatting `f` to `chunk` and escape the contents.""" - ... - - @abc.abstractmethod - def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: - """Format a multi-column table with metadata""" - ... - - def apply(self, text: Text) -> str: - return "".join(self.apply_format(chunk, f) for chunk, f in text.segments) - - @staticmethod - def outputline_texts(lines: Tuple["OutputLine", ...]) -> Tuple[Text, ...]: - return tuple([lines[0].base or Text()] + [line.fmt2 for line in lines[1:]]) - - -@dataclass -class PlainFormatter(Formatter): - column_width: int - - def apply_format(self, chunk: str, f: Format) -> str: - return chunk - - def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: - rows = [meta.headers] + [self.outputline_texts(ls) for ls in lines] - return "\n".join( - "".join(self.apply(x.ljust(self.column_width)) for x in row) for row in rows - ) - - -@dataclass -class AnsiFormatter(Formatter): - # Additional ansi escape codes not in colorama. See: - # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters - STYLE_UNDERLINE = "\x1b[4m" - STYLE_NO_UNDERLINE = "\x1b[24m" - STYLE_INVERT = "\x1b[7m" - - BASIC_ANSI_CODES = { - BasicFormat.NONE: "", - BasicFormat.IMMEDIATE: Fore.LIGHTBLUE_EX, - BasicFormat.STACK: Fore.YELLOW, - BasicFormat.REGISTER: Fore.YELLOW, - BasicFormat.DELAY_SLOT: Fore.LIGHTBLACK_EX, - BasicFormat.DIFF_CHANGE: Fore.LIGHTBLUE_EX, - BasicFormat.DIFF_ADD: Fore.GREEN, - BasicFormat.DIFF_REMOVE: Fore.RED, - BasicFormat.SOURCE_FILENAME: Style.DIM + Style.BRIGHT, - BasicFormat.SOURCE_FUNCTION: Style.DIM + Style.BRIGHT + STYLE_UNDERLINE, - BasicFormat.SOURCE_LINE_NUM: Fore.LIGHTBLACK_EX, - BasicFormat.SOURCE_OTHER: Style.DIM, - } - - BASIC_ANSI_CODES_UNDO = { - BasicFormat.NONE: "", - BasicFormat.SOURCE_FILENAME: Style.NORMAL, - BasicFormat.SOURCE_FUNCTION: Style.NORMAL + STYLE_NO_UNDERLINE, - BasicFormat.SOURCE_OTHER: Style.NORMAL, - } - - ROTATION_ANSI_COLORS = [ - Fore.MAGENTA, - Fore.CYAN, - Fore.GREEN, - Fore.RED, - Fore.LIGHTYELLOW_EX, - Fore.LIGHTMAGENTA_EX, - Fore.LIGHTCYAN_EX, - Fore.LIGHTGREEN_EX, - Fore.LIGHTBLACK_EX, - ] - - column_width: int - - def apply_format(self, chunk: str, f: Format) -> str: - if f == BasicFormat.NONE: - return chunk - undo_ansi_code = Fore.RESET - if isinstance(f, BasicFormat): - ansi_code = self.BASIC_ANSI_CODES[f] - undo_ansi_code = self.BASIC_ANSI_CODES_UNDO.get(f, undo_ansi_code) - elif isinstance(f, RotationFormat): - ansi_code = self.ROTATION_ANSI_COLORS[ - f.index % len(self.ROTATION_ANSI_COLORS) - ] - else: - static_assert_unreachable(f) - return f"{ansi_code}{chunk}{undo_ansi_code}" - - def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: - rows = [(meta.headers, False)] + [ - (self.outputline_texts(line), line[1].is_data_ref) for line in lines - ] - return "\n".join( - "".join( - (self.STYLE_INVERT if is_data_ref else "") - + self.apply(x.ljust(self.column_width)) - for x in row - ) - for (row, is_data_ref) in rows - ) - - -@dataclass -class HtmlFormatter(Formatter): - rotation_formats: int = 9 - - def apply_format(self, chunk: str, f: Format) -> str: - chunk = html.escape(chunk) - if f == BasicFormat.NONE: - return chunk - if isinstance(f, BasicFormat): - class_name = f.name.lower().replace("_", "-") - data_attr = "" - elif isinstance(f, RotationFormat): - class_name = f"rotation-{f.index % self.rotation_formats}" - rotation_key = html.escape(f"{f.group};{f.key}", quote=True) - data_attr = f'data-rotation="{rotation_key}"' - else: - static_assert_unreachable(f) - return f"{chunk}" - - def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: - def table_row(line: Tuple[Text, ...], is_data_ref: bool, cell_el: str) -> str: - tr_attrs = " class='data-ref'" if is_data_ref else "" - output_row = f" " - for cell in line: - cell_html = self.apply(cell) - output_row += f"<{cell_el}>{cell_html}" - output_row += "\n" - return output_row - - output = "\n" - output += " \n" - output += table_row(meta.headers, False, "th") - output += " \n" - output += " \n" - output += "".join( - table_row(self.outputline_texts(line), line[1].is_data_ref, "td") - for line in lines - ) - output += " \n" - output += "
\n" - return output - - -@dataclass -class JsonFormatter(Formatter): - arch_str: str - - def apply_format(self, chunk: str, f: Format) -> str: - # This method is unused by this formatter - return NotImplemented - - def table(self, meta: TableMetadata, rows: List[Tuple["OutputLine", ...]]) -> str: - def serialize_format(s: str, f: Format) -> Dict[str, Any]: - if f == BasicFormat.NONE: - return {"text": s} - elif isinstance(f, BasicFormat): - return {"text": s, "format": f.name.lower()} - elif isinstance(f, RotationFormat): - attrs = asdict(f) - attrs.update( - { - "text": s, - "format": "rotation", - } - ) - return attrs - else: - static_assert_unreachable(f) - - def serialize(text: Optional[Text]) -> List[Dict[str, Any]]: - if text is None: - return [] - return [serialize_format(s, f) for s, f in text.segments] - - is_threeway = len(meta.headers) == 3 - - output: Dict[str, Any] = {} - output["arch_str"] = self.arch_str - output["header"] = { - name: serialize(h) - for h, name in zip(meta.headers, ("base", "current", "previous")) - } - output["current_score"] = meta.current_score - output["max_score"] = meta.max_score - if meta.previous_score is not None: - output["previous_score"] = meta.previous_score - output_rows: List[Dict[str, Any]] = [] - for row in rows: - output_row: Dict[str, Any] = {} - output_row["key"] = row[0].key2 - output_row["is_data_ref"] = row[1].is_data_ref - iters = [ - ("base", row[0].base, row[0].line1), - ("current", row[1].fmt2, row[1].line2), - ] - if is_threeway: - iters.append(("previous", row[2].fmt2, row[2].line2)) - if all(line is None for _, _, line in iters): - # Skip rows that were only for displaying source code - continue - for column_name, text, line in iters: - column: Dict[str, Any] = {} - column["text"] = serialize(text) - if line: - if line.line_num is not None: - column["line"] = line.line_num - if line.branch_target is not None: - column["branch"] = line.branch_target - if line.source_lines: - column["src"] = line.source_lines - if line.comment is not None: - column["src_comment"] = line.comment - if line.source_line_num is not None: - column["src_line"] = line.source_line_num - if line or column["text"]: - output_row[column_name] = column - output_rows.append(output_row) - output["rows"] = output_rows - return json.dumps(output) - - -def format_fields( - pat: Pattern[str], - out1: Text, - out2: Text, - color1: FormatFunction, - color2: Optional[FormatFunction] = None, -) -> Tuple[Text, Text]: - diffs = [ - of.group() != nf.group() - for (of, nf) in zip(out1.finditer(pat), out2.finditer(pat)) - ] - - it = iter(diffs) - - def maybe_color(color: FormatFunction, s: str) -> Text: - return Text(s, color(s)) if next(it, False) else Text(s) - - out1 = out1.sub(pat, lambda m: maybe_color(color1, m.group())) - it = iter(diffs) - out2 = out2.sub(pat, lambda m: maybe_color(color2 or color1, m.group())) - - return out1, out2 - - -def symbol_formatter(group: str, base_index: int) -> FormatFunction: - symbol_formats: Dict[str, Format] = {} - - def symbol_format(s: str) -> Format: - # TODO: it would be nice to use a unique Format for each symbol, so we could - # add extra UI elements in the HTML version - f = symbol_formats.get(s) - if f is None: - index = len(symbol_formats) + base_index - f = RotationFormat(key=s, index=index, group=group) - symbol_formats[s] = f - return f - - return symbol_format - - -# ==== LOGIC ==== - -ObjdumpCommand = Tuple[List[str], str, Optional[str]] - - -def maybe_eval_int(expr: str) -> Optional[int]: - try: - ret = ast.literal_eval(expr) - if not isinstance(ret, int): - raise Exception("not an integer") - return ret - except Exception: - return None - - -def eval_int(expr: str, emsg: str) -> int: - ret = maybe_eval_int(expr) - if ret is None: - fail(emsg) - return ret - - -def eval_line_num(expr: str) -> Optional[int]: - expr = expr.strip().replace(":", "") - if expr == "": - return None - return int(expr, 16) - - -def run_make(target: str, project: ProjectSettings) -> None: - subprocess.check_call(project.build_command + [target]) - - -def run_make_capture_output( - target: str, project: ProjectSettings -) -> "subprocess.CompletedProcess[bytes]": - return subprocess.run( - project.build_command + [target], - stderr=subprocess.PIPE, - stdout=subprocess.PIPE, - ) - - -def restrict_to_function(dump: str, fn_name: str) -> str: - try: - ind = dump.index("\n", dump.index(f"<{fn_name}>:")) - return dump[ind + 1 :] - except ValueError: - return "" - - -def serialize_data_references(references: List[Tuple[int, int, str]]) -> str: - return "".join( - f"DATAREF {text_offset} {from_offset} {from_section}\n" - for (text_offset, from_offset, from_section) in references - ) - - -def maybe_get_objdump_source_flags(config: Config) -> List[str]: - flags = [] - - if config.show_line_numbers or config.show_source: - flags.append("--line-numbers") - - if config.show_source: - flags.append("--source") - - if not config.source_old_binutils: - flags.append("--source-comment=│ ") - - if config.inlines: - flags.append("--inlines") - - return flags - - -def run_objdump(cmd: ObjdumpCommand, config: Config, project: ProjectSettings) -> str: - flags, target, restrict = cmd - try: - out = subprocess.run( - [project.objdump_executable] + config.arch.arch_flags + flags + [target], - check=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True, - ).stdout - except subprocess.CalledProcessError as e: - print(e.stdout) - print(e.stderr) - if "unrecognized option '--source-comment" in e.stderr: - fail("** Try using --source-old-binutils instead of --source **") - raise e - - obj_data: Optional[bytes] = None - if config.diff_obj: - with open(target, "rb") as f: - obj_data = f.read() - - return preprocess_objdump_out(restrict, obj_data, out, config) - - -def preprocess_objdump_out( - restrict: Optional[str], obj_data: Optional[bytes], objdump_out: str, config: Config -) -> str: - """ - Preprocess the output of objdump into a format that `process()` expects. - This format is suitable for saving to disk with `--write-asm`. - - - Optionally filter the output to a single function (`restrict`) - - Otherwise, strip objdump header (7 lines) - - Prepend .data references ("DATAREF" lines) when working with object files - """ - out = objdump_out - - if restrict is not None: - out = restrict_to_function(out, restrict) - else: - for i in range(7): - out = out[out.find("\n") + 1 :] - out = out.rstrip("\n") - - if obj_data: - out = serialize_data_references(parse_elf_data_references(obj_data, config)) + out - - return out - - -def search_map_file( - fn_name: str, project: ProjectSettings, config: Config -) -> Tuple[Optional[str], Optional[int]]: - if not project.mapfile: - fail(f"No map file configured; cannot find function {fn_name}.") - - try: - with open(project.mapfile) as f: - contents = f.read() - except Exception: - fail(f"Failed to open map file {project.mapfile} for reading.") - - if project.map_format == "gnu": - lines = contents.split("\n") - - try: - cur_objfile = None - ram_to_rom = None - cands = [] - last_line = "" - for line in lines: - if line.startswith(" " + config.diff_section): - cur_objfile = line.split()[3] - if "load address" in line: - tokens = last_line.split() + line.split() - ram = int(tokens[1], 0) - rom = int(tokens[5], 0) - ram_to_rom = rom - ram - if line.endswith(" " + fn_name): - ram = int(line.split()[0], 0) - if cur_objfile is not None and ram_to_rom is not None: - cands.append((cur_objfile, ram + ram_to_rom)) - last_line = line - except Exception as e: - traceback.print_exc() - fail(f"Internal error while parsing map file") - - if len(cands) > 1: - fail(f"Found multiple occurrences of function {fn_name} in map file.") - if len(cands) == 1: - return cands[0] - elif project.map_format == "mw": - section_pattern = re.escape(config.diff_section) - find = re.findall( - re.compile( - # ram elf rom - r" \S+ \S+ (\S+) (\S+) . " - + fn_name - # object name - + r"(?: \(entry of " + section_pattern + r"\))? \t(\S+)" - ), - contents, - ) - if len(find) > 1: - fail(f"Found multiple occurrences of function {fn_name} in map file.") - if len(find) == 1: - rom = int(find[0][1], 16) - objname = find[0][2] - # The metrowerks linker map format does not contain the full object path, - # so we must complete it manually. - objfiles = [ - os.path.join(dirpath, f) - for dirpath, _, filenames in os.walk(project.mw_build_dir) - for f in filenames - if f == objname - ] - if len(objfiles) > 1: - all_objects = "\n".join(objfiles) - fail( - f"Found multiple objects of the same name {objname} in {project.mw_build_dir}, " - f"cannot determine which to diff against: \n{all_objects}" - ) - if len(objfiles) == 1: - objfile = objfiles[0] - # TODO Currently the ram-rom conversion only works for diffing ELF - # executables, but it would likely be more convenient to diff DOLs. - # At this time it is recommended to always use -o when running the diff - # script as this mode does not make use of the ram-rom conversion. - return objfile, rom - else: - fail(f"Linker map format {project.map_format} unrecognised.") - return None, None - - -def parse_elf_data_references(data: bytes, config: Config) -> List[Tuple[int, int, str]]: - e_ident = data[:16] - if e_ident[:4] != b"\x7FELF": - return [] - - SHT_SYMTAB = 2 - SHT_REL = 9 - SHT_RELA = 4 - - is_32bit = e_ident[4] == 1 - is_little_endian = e_ident[5] == 1 - str_end = "<" if is_little_endian else ">" - str_off = "I" if is_32bit else "Q" - sym_size = {"B": 1, "H": 2, "I": 4, "Q": 8} - - def read(spec: str, offset: int) -> Tuple[int, ...]: - spec = spec.replace("P", str_off) - size = struct.calcsize(spec) - return struct.unpack(str_end + spec, data[offset : offset + size]) - - ( - e_type, - e_machine, - e_version, - e_entry, - e_phoff, - e_shoff, - e_flags, - e_ehsize, - e_phentsize, - e_phnum, - e_shentsize, - e_shnum, - e_shstrndx, - ) = read("HHIPPPIHHHHHH", 16) - if e_type != 1: # relocatable - return [] - assert e_shoff != 0 - assert e_shnum != 0 # don't support > 0xFF00 sections - assert e_shstrndx != 0 - - @dataclass - class Section: - sh_name: int - sh_type: int - sh_flags: int - sh_addr: int - sh_offset: int - sh_size: int - sh_link: int - sh_info: int - sh_addralign: int - sh_entsize: int - - sections = [ - Section(*read("IIPPPPIIPP", e_shoff + i * e_shentsize)) for i in range(e_shnum) - ] - shstr = sections[e_shstrndx] - sec_name_offs = [shstr.sh_offset + s.sh_name for s in sections] - sec_names = [data[offset : data.index(b"\0", offset)] for offset in sec_name_offs] - - symtab_sections = [i for i in range(e_shnum) if sections[i].sh_type == SHT_SYMTAB] - assert len(symtab_sections) == 1 - symtab = sections[symtab_sections[0]] - - section_name = config.diff_section.encode("utf-8") - text_sections = [i for i in range(e_shnum) if sec_names[i] == section_name and sections[i].sh_size != 0] - if len(text_sections) != 1: - return [] - text_section = text_sections[0] - - ret: List[Tuple[int, int, str]] = [] - for s in sections: - if s.sh_type == SHT_REL or s.sh_type == SHT_RELA: - if s.sh_info == text_section: - # Skip section_name -> section_name references - continue - sec_name = sec_names[s.sh_info].decode("latin1") - if sec_name == ".mwcats.text": - # Skip Metrowerks CATS Utility section - continue - sec_base = sections[s.sh_info].sh_offset - for i in range(0, s.sh_size, s.sh_entsize): - if s.sh_type == SHT_REL: - r_offset, r_info = read("PP", s.sh_offset + i) - else: - r_offset, r_info, r_addend = read("PPP", s.sh_offset + i) - - if is_32bit: - r_sym = r_info >> 8 - r_type = r_info & 0xFF - sym_offset = symtab.sh_offset + symtab.sh_entsize * r_sym - st_name, st_value, st_size, st_info, st_other, st_shndx = read( - "IIIBBH", sym_offset - ) - else: - r_sym = r_info >> 32 - r_type = r_info & 0xFFFFFFFF - sym_offset = symtab.sh_offset + symtab.sh_entsize * r_sym - st_name, st_info, st_other, st_shndx, st_value, st_size = read( - "IBBHQQ", sym_offset - ) - if st_shndx == text_section: - if s.sh_type == SHT_REL: - if e_machine == 8 and r_type == 2: # R_MIPS_32 - (r_addend,) = read("I", sec_base + r_offset) - else: - continue - text_offset = (st_value + r_addend) & 0xFFFFFFFF - ret.append((text_offset, r_offset, sec_name)) - return ret - - -def dump_elf( - start: str, - end: Optional[str], - diff_elf_symbol: str, - config: Config, - project: ProjectSettings, -) -> Tuple[str, ObjdumpCommand, ObjdumpCommand]: - if not project.baseimg or not project.myimg: - fail("Missing myimg/baseimg in config.") - if config.base_shift: - fail("--base-shift not compatible with -e") - - start_addr = eval_int(start, "Start address must be an integer expression.") - - if end is not None: - end_addr = eval_int(end, "End address must be an integer expression.") - else: - end_addr = start_addr + config.max_function_size_bytes - - flags1 = [ - f"--start-address={start_addr}", - f"--stop-address={end_addr}", - ] - - if project.disassemble_all: - disassemble_flag = "-D" - else: - disassemble_flag = "-d" - - flags2 = [ - f"--disassemble={diff_elf_symbol}", - ] - - objdump_flags = [disassemble_flag, "-rz", "-j", config.diff_section] - return ( - project.myimg, - (objdump_flags + flags1, project.baseimg, None), - ( - objdump_flags + flags2 + maybe_get_objdump_source_flags(config), - project.myimg, - None, - ), - ) - - -def dump_objfile( - start: str, end: Optional[str], config: Config, project: ProjectSettings -) -> Tuple[str, ObjdumpCommand, ObjdumpCommand]: - if config.base_shift: - fail("--base-shift not compatible with -o") - if end is not None: - fail("end address not supported together with -o") - if start.startswith("0"): - fail("numerical start address not supported with -o; pass a function name") - - objfile, _ = search_map_file(start, project, config) - if not objfile: - fail("Not able to find .o file for function.") - - if config.make: - run_make(objfile, project) - - if not os.path.isfile(objfile): - fail(f"Not able to find .o file for function: {objfile} is not a file.") - - refobjfile = "expected/" + objfile - if not os.path.isfile(refobjfile): - fail(f'Please ensure an OK .o file exists at "{refobjfile}".') - - if project.disassemble_all: - disassemble_flag = "-D" - else: - disassemble_flag = "-d" - - objdump_flags = [disassemble_flag, "-rz", "-j", config.diff_section] - return ( - objfile, - (objdump_flags, refobjfile, start), - (objdump_flags + maybe_get_objdump_source_flags(config), objfile, start), - ) - - -def dump_binary( - start: str, end: Optional[str], config: Config, project: ProjectSettings -) -> Tuple[str, ObjdumpCommand, ObjdumpCommand]: - if not project.baseimg or not project.myimg: - fail("Missing myimg/baseimg in config.") - if config.make: - run_make(project.myimg, project) - start_addr = maybe_eval_int(start) - if start_addr is None: - _, start_addr = search_map_file(start, project, config) - if start_addr is None: - fail("Not able to find function in map file.") - if end is not None: - end_addr = eval_int(end, "End address must be an integer expression.") - else: - end_addr = start_addr + config.max_function_size_bytes - objdump_flags = ["-Dz", "-bbinary"] + ["-EB" if config.arch.big_endian else "-EL"] - flags1 = [ - f"--start-address={start_addr + config.base_shift}", - f"--stop-address={end_addr + config.base_shift}", - ] - flags2 = [f"--start-address={start_addr}", f"--stop-address={end_addr}"] - return ( - project.myimg, - (objdump_flags + flags1, project.baseimg, None), - (objdump_flags + flags2, project.myimg, None), - ) - -# Example: "ldr r4, [pc, #56] ; (4c )" -ARM32_LOAD_POOL_PATTERN = r"(ldr\s+r([0-9]|1[0-3]),\s+\[pc,.*;\s*)(\([a-fA-F0-9]+.*\))" - - -# The base class is a no-op. -class AsmProcessor: - def __init__(self, config: Config) -> None: - self.config = config - - def process_reloc(self, row: str, prev: str) -> str: - return prev - - def normalize(self, mnemonic: str, row: str) -> str: - """This should be called exactly once for each line.""" - arch = self.config.arch - row = self._normalize_arch_specific(mnemonic, row) - if self.config.ignore_large_imms and mnemonic not in arch.branch_instructions: - row = re.sub(self.config.arch.re_large_imm, "", row) - return row - - def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: - return row - - def post_process(self, lines: List["Line"]) -> None: - return - - -class AsmProcessorMIPS(AsmProcessor): - def process_reloc(self, row: str, prev: str) -> str: - arch = self.config.arch - if "R_MIPS_NONE" in row: - # GNU as emits no-op relocations immediately after real ones when - # assembling with -mabi=64. Return without trying to parse 'imm' as an - # integer. - return prev - before, imm, after = parse_relocated_line(prev) - repl = row.split()[-1] - if imm != "0": - # MIPS uses relocations with addends embedded in the code as immediates. - # If there is an immediate, show it as part of the relocation. Ideally - # we'd show this addend in both %lo/%hi, but annoyingly objdump's output - # doesn't include enough information to pair up %lo's and %hi's... - # TODO: handle unambiguous cases where all addends for a symbol are the - # same, or show "+???". - mnemonic = prev.split()[0] - if ( - mnemonic in arch.instructions_with_address_immediates - and not imm.startswith("0x") - ): - imm = "0x" + imm - repl += "+" + imm if int(imm, 0) > 0 else imm - if "R_MIPS_LO16" in row: - repl = f"%lo({repl})" - elif "R_MIPS_HI16" in row: - # Ideally we'd pair up R_MIPS_LO16 and R_MIPS_HI16 to generate a - # correct addend for each, but objdump doesn't give us the order of - # the relocations, so we can't find the right LO16. :( - repl = f"%hi({repl})" - elif "R_MIPS_26" in row: - # Function calls - pass - elif "R_MIPS_PC16" in row: - # Branch to glabel. This gives confusing output, but there's not much - # we can do here. - pass - elif "R_MIPS_GPREL16" in row: - repl = f"%gp_rel({repl})" - else: - assert False, f"unknown relocation type '{row}' for line '{prev}'" - return before + repl + after - - -class AsmProcessorPPC(AsmProcessor): - def process_reloc(self, row: str, prev: str) -> str: - arch = self.config.arch - assert any( - r in row for r in ["R_PPC_REL24", "R_PPC_ADDR16", "R_PPC_EMB_SDA21"] - ), f"unknown relocation type '{row}' for line '{prev}'" - before, imm, after = parse_relocated_line(prev) - repl = row.split()[-1] - if "R_PPC_REL24" in row: - # function calls - pass - elif "R_PPC_ADDR16_HI" in row: - # absolute hi of addr - repl = f"{repl}@h" - elif "R_PPC_ADDR16_HA" in row: - # adjusted hi of addr - repl = f"{repl}@ha" - elif "R_PPC_ADDR16_LO" in row: - # lo of addr - repl = f"{repl}@l" - elif "R_PPC_ADDR16" in row: - # 16-bit absolute addr - if "+0x7" in repl: - # remove the very large addends as they are an artifact of (label-_SDA(2)_BASE_) - # computations and are unimportant in a diff setting. - if int(repl.split("+")[1], 16) > 0x70000000: - repl = repl.split("+")[0] - elif "R_PPC_EMB_SDA21" in row: - # small data area - pass - return before + repl + after - - -class AsmProcessorARM32(AsmProcessor): - def process_reloc(self, row: str, prev: str) -> str: - arch = self.config.arch - before, imm, after = parse_relocated_line(prev) - repl = row.split()[-1] - return before + repl + after - - def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: - if self.config.ignore_addr_diffs: - row = self._normalize_bl(mnemonic, row) - row = self._normalize_data_pool(row) - return row - - def _normalize_bl(self, mnemonic: str, row: str) -> str: - if mnemonic != "bl": - return row - - row, _ = split_off_address(row) - return row + "" - - def _normalize_data_pool(self, row: str) -> str: - pool_match = re.search(ARM32_LOAD_POOL_PATTERN, row) - return pool_match.group(1) if pool_match else row - - def post_process(self, lines: List["Line"]) -> None: - lines_by_line_number = {} - for line in lines: - lines_by_line_number[line.line_num] = line - for line in lines: - if line.data_pool_addr is None: - continue - - # Add data symbol and its address to the line. - line_original = lines_by_line_number[line.data_pool_addr].original - value = line_original.split()[1] - addr = "{:x}".format(line.data_pool_addr) - line.original = line.normalized_original + f"={value} ({addr})" - - -class AsmProcessorAArch64(AsmProcessor): - def __init__(self, config: Config) -> None: - super().__init__(config) - self._adrp_pair_registers: Set[str] = set() - - def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: - if self.config.ignore_addr_diffs: - row = self._normalize_adrp_differences(mnemonic, row) - row = self._normalize_bl(mnemonic, row) - return row - - def _normalize_bl(self, mnemonic: str, row: str) -> str: - if mnemonic != "bl": - return row - - row, _ = split_off_address(row) - return row + "" - - def _normalize_adrp_differences(self, mnemonic: str, row: str) -> str: - """Identifies ADRP + LDR/ADD pairs that are used to access the GOT and - suppresses any immediate differences. - - Whenever an ADRP is seen, the destination register is added to the set of registers - that are part of an ADRP + LDR/ADD pair. Registers are removed from the set as soon - as they are used for an LDR or ADD instruction which completes the pair. - - This method is somewhat crude but should manage to detect most such pairs. - """ - row_parts = row.split("\t", 1) - if mnemonic == "adrp": - self._adrp_pair_registers.add(row_parts[1].strip().split(",")[0]) - row, _ = split_off_address(row) - return row + "" - elif mnemonic == "ldr": - for reg in self._adrp_pair_registers: - # ldr xxx, [reg] - # ldr xxx, [reg, ] - if f", [{reg}" in row_parts[1]: - self._adrp_pair_registers.remove(reg) - return normalize_imms(row, AARCH64_SETTINGS) - elif mnemonic == "add": - for reg in self._adrp_pair_registers: - # add reg, reg, - if row_parts[1].startswith(f"{reg}, {reg}, "): - self._adrp_pair_registers.remove(reg) - return normalize_imms(row, AARCH64_SETTINGS) - - return row - - -@dataclass -class ArchSettings: - name: str - re_int: Pattern[str] - re_comment: Pattern[str] - re_reg: Pattern[str] - re_sprel: Pattern[str] - re_large_imm: Pattern[str] - re_imm: Pattern[str] - re_reloc: Pattern[str] - branch_instructions: Set[str] - instructions_with_address_immediates: Set[str] - forbidden: Set[str] = field(default_factory=lambda: set(string.ascii_letters + "_")) - arch_flags: List[str] = field(default_factory=list) - branch_likely_instructions: Set[str] = field(default_factory=set) - proc: Type[AsmProcessor] = AsmProcessor - big_endian: Optional[bool] = True - delay_slot_instructions: Set[str] = field(default_factory=set) - -MIPS_BRANCH_LIKELY_INSTRUCTIONS = { - "beql", - "bnel", - "beqzl", - "bnezl", - "bgezl", - "bgtzl", - "blezl", - "bltzl", - "bc1tl", - "bc1fl", -} -MIPS_BRANCH_INSTRUCTIONS = MIPS_BRANCH_LIKELY_INSTRUCTIONS.union( - { - "b", - "beq", - "bne", - "beqz", - "bnez", - "bgez", - "bgtz", - "blez", - "bltz", - "bc1t", - "bc1f", - } -) - -ARM32_PREFIXES = {"b", "bl"} -ARM32_CONDS = { - "", - "eq", - "ne", - "cs", - "cc", - "mi", - "pl", - "vs", - "vc", - "hi", - "ls", - "ge", - "lt", - "gt", - "le", - "al", -} -ARM32_SUFFIXES = {"", ".n", ".w"} -ARM32_BRANCH_INSTRUCTIONS = { - f"{prefix}{cond}{suffix}" - for prefix in ARM32_PREFIXES - for cond in ARM32_CONDS - for suffix in ARM32_SUFFIXES -} - -AARCH64_BRANCH_INSTRUCTIONS = { - "b", - "b.eq", - "b.ne", - "b.cs", - "b.hs", - "b.cc", - "b.lo", - "b.mi", - "b.pl", - "b.vs", - "b.vc", - "b.hi", - "b.ls", - "b.ge", - "b.lt", - "b.gt", - "b.le", - "cbz", - "cbnz", - "tbz", - "tbnz", -} - -PPC_BRANCH_INSTRUCTIONS = { - "b", - "beq", - "beq+", - "beq-", - "bne", - "bne+", - "bne-", - "blt", - "blt+", - "blt-", - "ble", - "ble+", - "ble-", - "bdnz", - "bdnz+", - "bdnz-", - "bge", - "bge+", - "bge-", - "bgt", - "bgt+", - "bgt-", -} - -MIPS_SETTINGS = ArchSettings( - name="mips", - re_int=re.compile(r"[0-9]+"), - re_comment=re.compile(r"<.*?>"), - re_reg=re.compile( - r"\$?\b(a[0-7]|t[0-9]|s[0-8]|at|v[01]|f[12]?[0-9]|f3[01]|kt?[01]|fp|ra|zero)\b" - ), - re_sprel=re.compile(r"(?<=,)([0-9]+|0x[0-9a-f]+)\(sp\)"), - re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), - re_imm=re.compile(r"(\b|-)([0-9]+|0x[0-9a-fA-F]+)\b(?!\(sp)|%(lo|hi)\([^)]*\)"), - re_reloc=re.compile(r"R_MIPS_"), - arch_flags=["-m", "mips:4300"], - branch_likely_instructions=MIPS_BRANCH_LIKELY_INSTRUCTIONS, - branch_instructions=MIPS_BRANCH_INSTRUCTIONS, - instructions_with_address_immediates=MIPS_BRANCH_INSTRUCTIONS.union({"jal", "j"}), - delay_slot_instructions=MIPS_BRANCH_INSTRUCTIONS.union({"j", "jal", "jr", "jalr"}), - proc=AsmProcessorMIPS, -) - -MIPSEL_SETTINGS = replace(MIPS_SETTINGS, name="mipsel", big_endian=False) - -ARM32_SETTINGS = ArchSettings( - name="arm32", - re_int=re.compile(r"[0-9]+"), - re_comment=re.compile(r"(<.*?>|//.*$)"), - # Includes: - # - General purpose registers: r0..13 - # - Frame pointer registers: lr (r14), pc (r15) - # - VFP/NEON registers: s0..31, d0..31, q0..15, fpscr, fpexc, fpsid - # SP should not be in this list. - re_reg=re.compile( - r"\$?\b([rq][0-9]|[rq]1[0-5]|pc|lr|[ds][12]?[0-9]|[ds]3[01]|fp(scr|exc|sid))\b" - ), - re_sprel=re.compile(r"sp, #-?(0x[0-9a-fA-F]+|[0-9]+)\b"), - re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), - re_imm=re.compile(r"(?|//.*$)"), - # GPRs and FP registers: X0-X30, W0-W30, [BHSDVQ]0..31 - # (FP registers may be followed by data width and number of elements, e.g. V0.4S) - # The zero registers and SP should not be in this list. - re_reg=re.compile(r"\$?\b([bhsdvq]([12]?[0-9]|3[01])(\.\d\d?[bhsdvq])?|[xw][12]?[0-9]|[xw]30)\b"), - re_sprel=re.compile(r"sp, #-?(0x[0-9a-fA-F]+|[0-9]+)\b"), - re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), - re_imm=re.compile(r"(?|//.*$)"), - re_reg=re.compile(r"\$?\b([rf][0-9]+)\b"), - re_sprel=re.compile(r"(?<=,)(-?[0-9]+|-?0x[0-9a-f]+)\(r1\)"), - re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), - re_imm=re.compile(r"(\b|-)([0-9]+|0x[0-9a-fA-F]+)\b(?!\(r1)|[^@]*@(ha|h|lo)"), - re_reloc=re.compile(r"R_PPC_"), - branch_instructions=PPC_BRANCH_INSTRUCTIONS, - instructions_with_address_immediates=PPC_BRANCH_INSTRUCTIONS.union({"bl"}), - proc=AsmProcessorPPC, -) - -ARCH_SETTINGS = [ - MIPS_SETTINGS, - MIPSEL_SETTINGS, - ARM32_SETTINGS, - ARMEL_SETTINGS, - AARCH64_SETTINGS, - PPC_SETTINGS, -] - - -def hexify_int(row: str, pat: Match[str], arch: ArchSettings) -> str: - full = pat.group(0) - if len(full) <= 1: - # leave one-digit ints alone - return full - start, end = pat.span() - if start and row[start - 1] in arch.forbidden: - return full - if end < len(row) and row[end] in arch.forbidden: - return full - return hex(int(full)) - - -def parse_relocated_line(line: str) -> Tuple[str, str, str]: - for c in ",\t ": - if c in line: - ind2 = line.rindex(c) - break - else: - raise Exception(f"failed to parse relocated line: {line}") - before = line[: ind2 + 1] - after = line[ind2 + 1 :] - ind2 = after.find("(") - if ind2 == -1: - imm, after = after, "" - else: - imm, after = after[:ind2], after[ind2:] - if imm == "0x0": - imm = "0" - return before, imm, after - - -def pad_mnemonic(line: str) -> str: - if "\t" not in line: - return line - mn, args = line.split("\t", 1) - return f"{mn:<7s} {args}" - - -@dataclass -class Line: - mnemonic: str - diff_row: str - original: str - normalized_original: str - scorable_line: str - line_num: Optional[int] = None - branch_target: Optional[int] = None - data_pool_addr: Optional[int] = None - source_filename: Optional[str] = None - source_line_num: Optional[int] = None - source_lines: List[str] = field(default_factory=list) - comment: Optional[str] = None - - -def process(dump: str, config: Config) -> List[Line]: - arch = config.arch - processor = arch.proc(config) - skip_next = False - source_lines = [] - source_filename = None - source_line_num = None - - i = 0 - num_instr = 0 - data_refs: Dict[int, Dict[str, List[int]]] = defaultdict(lambda: defaultdict(list)) - output: List[Line] = [] - stop_after_delay_slot = False - lines = dump.split("\n") - while i < len(lines): - row = lines[i] - i += 1 - - if not row: - continue - - if re.match(r"^[0-9a-f]+ <.*>:$", row): - continue - - if row.startswith("DATAREF"): - parts = row.split(" ", 3) - text_offset = int(parts[1]) - from_offset = int(parts[2]) - from_section = parts[3] - data_refs[text_offset][from_section].append(from_offset) - continue - - if config.diff_obj and num_instr >= config.max_function_size_lines: - output.append( - Line( - mnemonic="...", - diff_row="...", - original="...", - normalized_original="...", - scorable_line="...", - ) - ) - break - - if not re.match(r"^\s+[0-9a-f]+:\s+", row): - # This regex is conservative, and assumes the file path does not contain "weird" - # characters like colons, tabs, or angle brackets. - if re.match( - r"^[^ \t<>:][^\t<>:]*:[0-9]+( \(discriminator [0-9]+\))?$", row - ): - source_filename, _, tail = row.rpartition(":") - source_line_num = int(tail.partition(" ")[0]) - source_lines.append(row) - continue - - # If the instructions loads a data pool symbol, extract the address of - # the symbol. - data_pool_addr = None - pool_match = re.search(ARM32_LOAD_POOL_PATTERN, row) - if pool_match: - offset = pool_match.group(3).split(" ")[0][1:] - data_pool_addr = int(offset, 16) - - m_comment = re.search(arch.re_comment, row) - comment = m_comment[0] if m_comment else None - row = re.sub(arch.re_comment, "", row) - line_num_str = row.split(":")[0] - row = row.rstrip() - tabs = row.split("\t") - row = "\t".join(tabs[2:]) - line_num = eval_line_num(line_num_str.strip()) - - if line_num in data_refs: - refs = data_refs[line_num] - ref_str = "; ".join( - section_name + "+" + ",".join(hex(off) for off in offs) - for section_name, offs in refs.items() - ) - output.append( - Line( - mnemonic="", - diff_row="", - original=ref_str, - normalized_original=ref_str, - scorable_line="", - ) - ) - - if "\t" in row: - row_parts = row.split("\t", 1) - else: - # powerpc-eabi-objdump doesn't use tabs - row_parts = [part.lstrip() for part in row.split(" ", 1)] - mnemonic = row_parts[0].strip() - - if mnemonic not in arch.instructions_with_address_immediates: - row = re.sub(arch.re_int, lambda m: hexify_int(row, m, arch), row) - - # Let 'original' be 'row' with relocations applied, while we continue - # transforming 'row' into a coarser version that ignores registers and - # immediates. - original = row - - while i < len(lines): - reloc_row = lines[i] - if re.search(arch.re_reloc, reloc_row): - original = processor.process_reloc(reloc_row, original) - else: - break - i += 1 - - normalized_original = processor.normalize(mnemonic, original) - - scorable_line = normalized_original - if not config.score_stack_differences: - scorable_line = re.sub(arch.re_sprel, "addr(sp)", scorable_line) - if mnemonic in arch.branch_instructions: - # Replace the final argument with "" - scorable_line = re.sub(r"[^, \t]+$", "", scorable_line) - - if skip_next: - skip_next = False - row = "" - mnemonic = "" - scorable_line = "" - if mnemonic in arch.branch_likely_instructions: - skip_next = True - - row = re.sub(arch.re_reg, "", row) - row = re.sub(arch.re_sprel, "addr(sp)", row) - row_with_imm = row - if mnemonic in arch.instructions_with_address_immediates: - row = row.strip() - row, _ = split_off_address(row) - row += "" - else: - row = normalize_imms(row, arch) - - branch_target = None - if mnemonic in arch.branch_instructions: - branch_target = int(row_parts[1].strip().split(",")[-1], 16) - if mnemonic in arch.branch_likely_instructions: - branch_target -= 4 - - output.append( - Line( - mnemonic=mnemonic, - diff_row=row, - original=original, - normalized_original=normalized_original, - scorable_line=scorable_line, - line_num=line_num, - branch_target=branch_target, - data_pool_addr=data_pool_addr, - source_filename=source_filename, - source_line_num=source_line_num, - source_lines=source_lines, - comment=comment, - ) - ) - num_instr += 1 - source_lines = [] - - if config.stop_jrra and mnemonic == "jr" and row_parts[1].strip() == "ra": - stop_after_delay_slot = True - elif stop_after_delay_slot: - break - - processor.post_process(output) - return output - - -def normalize_imms(row: str, arch: ArchSettings) -> str: - return re.sub(arch.re_imm, "", row) - - -def normalize_stack(row: str, arch: ArchSettings) -> str: - return re.sub(arch.re_sprel, "addr(sp)", row) - - -def imm_matches_everything(row: str, arch: ArchSettings) -> bool: - # (this should probably be arch-specific) - return "(." in row - - -def split_off_address(line: str) -> Tuple[str, str]: - """Split e.g. 'beqz $r0,1f0' into 'beqz $r0,' and '1f0'.""" - parts = line.split(",") - if len(parts) < 2: - parts = line.split(None, 1) - off = len(line) - len(parts[-1]) - return line[:off], line[off:] - - -def diff_sequences_difflib( - seq1: List[str], seq2: List[str] -) -> List[Tuple[str, int, int, int, int]]: - differ = difflib.SequenceMatcher(a=seq1, b=seq2, autojunk=False) - return differ.get_opcodes() - - -def diff_sequences( - seq1: List[str], seq2: List[str], algorithm: str -) -> List[Tuple[str, int, int, int, int]]: - if ( - algorithm != "levenshtein" - or len(seq1) * len(seq2) > 4 * 10 ** 8 - or len(seq1) + len(seq2) >= 0x110000 - ): - return diff_sequences_difflib(seq1, seq2) - - # The Levenshtein library assumes that we compare strings, not lists. Convert. - # (Per the check above we know we have fewer than 0x110000 unique elements, so chr() works.) - remapping: Dict[str, str] = {} - - def remap(seq: List[str]) -> str: - seq = seq[:] - for i in range(len(seq)): - val = remapping.get(seq[i]) - if val is None: - val = chr(len(remapping)) - remapping[seq[i]] = val - seq[i] = val - return "".join(seq) - - rem1 = remap(seq1) - rem2 = remap(seq2) - import Levenshtein - - ret: List[Tuple[str, int, int, int, int]] = Levenshtein.opcodes(rem1, rem2) - return ret - - -def diff_lines( - lines1: List[Line], - lines2: List[Line], - algorithm: str, -) -> List[Tuple[Optional[Line], Optional[Line]]]: - ret = [] - for (tag, i1, i2, j1, j2) in diff_sequences( - [line.mnemonic for line in lines1], - [line.mnemonic for line in lines2], - algorithm, - ): - for line1, line2 in itertools.zip_longest(lines1[i1:i2], lines2[j1:j2]): - if tag == "replace": - if line1 is None: - tag = "insert" - elif line2 is None: - tag = "delete" - elif tag == "insert": - assert line1 is None - elif tag == "delete": - assert line2 is None - ret.append((line1, line2)) - - return ret - - -def score_diff_lines( - lines: List[Tuple[Optional[Line], Optional[Line]]], config: Config -) -> int: - # This logic is copied from `scorer.py` from the decomp permuter project - # https://github.com/simonlindholm/decomp-permuter/blob/main/src/scorer.py - score = 0 - deletions = [] - insertions = [] - - def lo_hi_match(old: str, new: str) -> bool: - # TODO: Make this arch-independent, like `imm_matches_everything()` - old_lo = old.find("%lo") - old_hi = old.find("%hi") - new_lo = new.find("%lo") - new_hi = new.find("%hi") - - if old_lo != -1 and new_lo != -1: - old_idx = old_lo - new_idx = new_lo - elif old_hi != -1 and new_hi != -1: - old_idx = old_hi - new_idx = new_hi - else: - return False - - if old[:old_idx] != new[:new_idx]: - return False - - old_inner = old[old_idx + 4 : -1] - new_inner = new[new_idx + 4 : -1] - return old_inner.startswith(".") or new_inner.startswith(".") - - def diff_sameline(old: str, new: str) -> None: - nonlocal score - if old == new: - return - - if lo_hi_match(old, new): - return - - ignore_last_field = False - if config.score_stack_differences: - oldsp = re.search(config.arch.re_sprel, old) - newsp = re.search(config.arch.re_sprel, new) - if oldsp and newsp: - oldrel = int(oldsp.group(1) or "0", 0) - newrel = int(newsp.group(1) or "0", 0) - score += abs(oldrel - newrel) * config.penalty_stackdiff - ignore_last_field = True - - # Probably regalloc difference, or signed vs unsigned - - # Compare each field in order - newfields, oldfields = new.split(","), old.split(",") - if ignore_last_field: - newfields = newfields[:-1] - oldfields = oldfields[:-1] - for nf, of in zip(newfields, oldfields): - if nf != of: - score += config.penalty_regalloc - # Penalize any extra fields - score += abs(len(newfields) - len(oldfields)) * config.penalty_regalloc - - def diff_insert(line: str) -> None: - # Reordering or totally different codegen. - # Defer this until later when we can tell. - insertions.append(line) - - def diff_delete(line: str) -> None: - deletions.append(line) - - # Find the end of the last long streak of matching mnemonics, if it looks - # like the objdump output was truncated. This is used to skip scoring - # misaligned lines at the end of the diff. - last_mismatch = -1 - max_index = None - lines_were_truncated = False - for index, (line1, line2) in enumerate(lines): - if (line1 and line1.original == "...") or (line2 and line2.original == "..."): - lines_were_truncated = True - if line1 and line2 and line1.mnemonic == line2.mnemonic: - if index - last_mismatch >= 50: - max_index = index - else: - last_mismatch = index - if not lines_were_truncated: - max_index = None - - for index, (line1, line2) in enumerate(lines): - if max_index is not None and index > max_index: - break - if line1 and line2 and line1.mnemonic == line2.mnemonic: - diff_sameline(line1.scorable_line, line2.scorable_line) - else: - if line1: - diff_delete(line1.scorable_line) - if line2: - diff_insert(line2.scorable_line) - - insertions_co = Counter(insertions) - deletions_co = Counter(deletions) - for item in insertions_co + deletions_co: - ins = insertions_co[item] - dels = deletions_co[item] - common = min(ins, dels) - score += ( - (ins - common) * config.penalty_insertion - + (dels - common) * config.penalty_deletion - + config.penalty_reordering * common - ) - - return score - - -@dataclass(frozen=True) -class OutputLine: - base: Optional[Text] = field(compare=False) - fmt2: Text = field(compare=False) - key2: Optional[str] - boring: bool = field(compare=False) - is_data_ref: bool = field(compare=False) - line1: Optional[Line] = field(compare=False) - line2: Optional[Line] = field(compare=False) - - -@dataclass(frozen=True) -class Diff: - lines: List[OutputLine] - score: int - max_score: int - - -def trim_nops(lines: List[Line], arch: ArchSettings) -> List[Line]: - lines = lines[:] - while lines and lines[-1].mnemonic == "nop" and (len(lines) == 1 or lines[-2].mnemonic not in arch.delay_slot_instructions): - lines.pop() - return lines - -def do_diff(lines1: List[Line], lines2: List[Line], config: Config) -> Diff: - if config.show_source: - import cxxfilt - arch = config.arch - fmt = config.formatter - output: List[OutputLine] = [] - - sc1 = symbol_formatter("base-reg", 0) - sc2 = symbol_formatter("my-reg", 0) - sc3 = symbol_formatter("base-stack", 4) - sc4 = symbol_formatter("my-stack", 4) - sc5 = symbol_formatter("base-branch", 0) - sc6 = symbol_formatter("my-branch", 0) - bts1: Set[int] = set() - bts2: Set[int] = set() - - if config.show_branches: - for (lines, btset, sc) in [ - (lines1, bts1, sc5), - (lines2, bts2, sc6), - ]: - for line in lines: - bt = line.branch_target - if bt is not None: - btset.add(bt) - sc(str(bt)) - - lines1 = trim_nops(lines1, arch) - lines2 = trim_nops(lines2, arch) - - diffed_lines = diff_lines(lines1, lines2, config.algorithm) - score = score_diff_lines(diffed_lines, config) - max_score = len(lines1) * config.penalty_deletion - - line_num_base = -1 - line_num_offset = 0 - line_num_2to1 = {} - for (line1, line2) in diffed_lines: - if line1 is not None and line1.line_num is not None: - line_num_base = line1.line_num - line_num_offset = 0 - else: - line_num_offset += 1 - if line2 is not None and line2.line_num is not None: - line_num_2to1[line2.line_num] = (line_num_base, line_num_offset) - - for (line1, line2) in diffed_lines: - line_color1 = line_color2 = sym_color = BasicFormat.NONE - line_prefix = " " - is_data_ref = False - out1 = Text() if not line1 else Text(pad_mnemonic(line1.original)) - out2 = Text() if not line2 else Text(pad_mnemonic(line2.original)) - if line1 and line2 and line1.diff_row == line2.diff_row: - if line1.diff_row == "": - if line1.normalized_original != line2.normalized_original: - line_prefix = "i" - sym_color = BasicFormat.DIFF_CHANGE - out1 = out1.reformat(sym_color) - out2 = out2.reformat(sym_color) - is_data_ref = True - elif ( - line1.normalized_original == line2.normalized_original - and line2.branch_target is None - ): - # Fast path: no coloring needed. We don't include branch instructions - # in this case because we need to check that their targets line up in - # the diff, and don't just happen to have the are the same address - # by accident. - pass - elif line1.diff_row == "": - # Don't draw attention to differing branch-likely delay slots: they - # typically mirror the branch destination - 1 so the real difference - # is elsewhere. Still, do mark them as different to avoid confusion. - # No need to consider branches because delay slots can't branch. - out1 = out1.reformat(BasicFormat.DELAY_SLOT) - out2 = out2.reformat(BasicFormat.DELAY_SLOT) - else: - mnemonic = line1.original.split()[0] - branchless1, address1 = out1.plain(), "" - branchless2, address2 = out2.plain(), "" - if mnemonic in arch.instructions_with_address_immediates: - branchless1, address1 = split_off_address(branchless1) - branchless2, address2 = split_off_address(branchless2) - - out1 = Text(branchless1) - out2 = Text(branchless2) - out1, out2 = format_fields( - arch.re_imm, out1, out2, lambda _: BasicFormat.IMMEDIATE - ) - - if line2.branch_target is not None: - target = line2.branch_target - line2_target = line_num_2to1.get(line2.branch_target) - if line2_target is None: - # If the target is outside the disassembly, extrapolate. - # This only matters near the bottom. - assert line2.line_num is not None - line2_line = line_num_2to1[line2.line_num] - line2_target = (line2_line[0] + (target - line2.line_num), 0) - - # Set the key for three-way diffing to a normalized version. - norm2, norm_branch2 = split_off_address(line2.normalized_original) - if norm_branch2 != "": - line2.normalized_original = norm2 + str(line2_target) - same_target = line2_target == (line1.branch_target, 0) - else: - # Do a naive comparison for non-branches (e.g. function calls). - same_target = address1 == address2 - - if normalize_imms(branchless1, arch) == normalize_imms( - branchless2, arch - ): - if imm_matches_everything(branchless2, arch): - # ignore differences due to %lo(.rodata + ...) vs symbol - out1 = out1.reformat(BasicFormat.NONE) - out2 = out2.reformat(BasicFormat.NONE) - elif line2.branch_target is not None and same_target: - # same-target branch, don't color - pass - else: - # must have an imm difference (or else we would have hit the - # fast path) - sym_color = BasicFormat.IMMEDIATE - line_prefix = "i" - else: - out1, out2 = format_fields(arch.re_sprel, out1, out2, sc3, sc4) - if normalize_stack(branchless1, arch) == normalize_stack( - branchless2, arch - ): - # only stack differences (luckily stack and imm - # differences can't be combined in MIPS, so we - # don't have to think about that case) - sym_color = BasicFormat.STACK - line_prefix = "s" - else: - # reg differences and maybe imm as well - out1, out2 = format_fields(arch.re_reg, out1, out2, sc1, sc2) - line_color1 = line_color2 = sym_color = BasicFormat.REGISTER - line_prefix = "r" - - if same_target: - address_imm_fmt = BasicFormat.NONE - else: - address_imm_fmt = BasicFormat.IMMEDIATE - out1 += Text(address1, address_imm_fmt) - out2 += Text(address2, address_imm_fmt) - elif line1 and line2: - line_prefix = "|" - line_color1 = line_color2 = sym_color = BasicFormat.DIFF_CHANGE - out1 = out1.reformat(line_color1) - out2 = out2.reformat(line_color2) - elif line1: - line_prefix = "<" - line_color1 = sym_color = BasicFormat.DIFF_REMOVE - out1 = out1.reformat(line_color1) - out2 = Text() - elif line2: - line_prefix = ">" - line_color2 = sym_color = BasicFormat.DIFF_ADD - out1 = Text() - out2 = out2.reformat(line_color2) - - if config.show_source and line2 and line2.comment: - out2 += f" {line2.comment}" - - def format_part( - out: Text, - line: Optional[Line], - line_color: Format, - btset: Set[int], - sc: FormatFunction, - ) -> Optional[Text]: - if line is None: - return None - if line.line_num is None: - return out - in_arrow = Text(" ") - out_arrow = Text() - if config.show_branches: - if line.line_num in btset: - in_arrow = Text("~>", sc(str(line.line_num))) - if line.branch_target is not None: - out_arrow = " " + Text("~>", sc(str(line.branch_target))) - formatted_line_num = Text(hex(line.line_num)[2:] + ":", line_color) - return formatted_line_num + " " + in_arrow + " " + out + out_arrow - - part1 = format_part(out1, line1, line_color1, bts1, sc5) - part2 = format_part(out2, line2, line_color2, bts2, sc6) - - if config.show_source and line2: - for source_line in line2.source_lines: - line_format = BasicFormat.SOURCE_OTHER - if config.source_old_binutils: - if source_line and re.fullmatch(".*\.c(?:pp)?:\d+", source_line): - line_format = BasicFormat.SOURCE_FILENAME - elif source_line and source_line.endswith("():"): - line_format = BasicFormat.SOURCE_FUNCTION - try: - source_line = cxxfilt.demangle( - source_line[:-3], external_only=False - ) - except: - pass - else: - # File names and function names - if source_line and source_line[0] != "│": - line_format = BasicFormat.SOURCE_FILENAME - # Function names - if source_line.endswith("():"): - line_format = BasicFormat.SOURCE_FUNCTION - try: - source_line = cxxfilt.demangle( - source_line[:-3], external_only=False - ) - except: - pass - padding = " " * 7 if config.show_line_numbers else " " * 2 - output.append( - OutputLine( - base=None, - fmt2=padding + Text(source_line, line_format), - key2=source_line, - boring=True, - is_data_ref=False, - line1=None, - line2=None, - ) - ) - - key2 = line2.normalized_original if line2 else None - boring = False - if line_prefix == " ": - boring = True - elif config.compress and config.compress.same_instr and line_prefix in "irs": - boring = True - - if config.show_line_numbers: - if line2 and line2.source_line_num is not None: - num_color = ( - BasicFormat.SOURCE_LINE_NUM - if sym_color == BasicFormat.NONE - else sym_color - ) - num2 = Text(f"{line2.source_line_num:5}", num_color) - else: - num2 = Text(" " * 5) - else: - num2 = Text() - - fmt2 = Text(line_prefix, sym_color) + num2 + " " + (part2 or Text()) - - output.append( - OutputLine( - base=part1, - fmt2=fmt2, - key2=key2, - boring=boring, - is_data_ref=is_data_ref, - line1=line1, - line2=line2, - ) - ) - - output = output[config.skip_lines :] - return Diff(lines=output, score=score, max_score=max_score) - - -def chunk_diff_lines( - diff: List[OutputLine], -) -> List[Union[List[OutputLine], OutputLine]]: - """Chunk a diff into an alternating list like A B A B ... A, where: - * A is a List[OutputLine] of insertions, - * B is a single non-insertion OutputLine, with .base != None.""" - cur_right: List[OutputLine] = [] - chunks: List[Union[List[OutputLine], OutputLine]] = [] - for output_line in diff: - if output_line.base is not None: - chunks.append(cur_right) - chunks.append(output_line) - cur_right = [] - else: - cur_right.append(output_line) - chunks.append(cur_right) - return chunks - - -def compress_matching( - li: List[Tuple[OutputLine, ...]], context: int -) -> List[Tuple[OutputLine, ...]]: - ret: List[Tuple[OutputLine, ...]] = [] - matching_streak: List[Tuple[OutputLine, ...]] = [] - context = max(context, 0) - - def flush_matching() -> None: - if len(matching_streak) <= 2 * context + 1: - ret.extend(matching_streak) - else: - ret.extend(matching_streak[:context]) - skipped = len(matching_streak) - 2 * context - filler = OutputLine( - base=Text(f"<{skipped} lines>", BasicFormat.SOURCE_OTHER), - fmt2=Text(), - key2=None, - boring=False, - is_data_ref=False, - line1=None, - line2=None, - ) - columns = len(matching_streak[0]) - ret.append(tuple([filler] * columns)) - if context > 0: - ret.extend(matching_streak[-context:]) - matching_streak.clear() - - for line in li: - if line[0].boring: - matching_streak.append(line) - else: - flush_matching() - ret.append(line) - - flush_matching() - return ret - - -def align_diffs( - old_diff: Diff, new_diff: Diff, config: Config -) -> Tuple[TableMetadata, List[Tuple[OutputLine, ...]]]: - meta: TableMetadata - diff_lines: List[Tuple[OutputLine, ...]] - padding = " " * 7 if config.show_line_numbers else " " * 2 - - if config.threeway: - meta = TableMetadata( - headers=( - Text("TARGET"), - Text(f"{padding}CURRENT ({new_diff.score})"), - Text(f"{padding}PREVIOUS ({old_diff.score})"), - ), - current_score=new_diff.score, - max_score=new_diff.max_score, - previous_score=old_diff.score, - ) - old_chunks = chunk_diff_lines(old_diff.lines) - new_chunks = chunk_diff_lines(new_diff.lines) - diff_lines = [] - empty = OutputLine(Text(), Text(), None, True, False, None, None) - assert len(old_chunks) == len(new_chunks), "same target" - for old_chunk, new_chunk in zip(old_chunks, new_chunks): - if isinstance(old_chunk, list): - assert isinstance(new_chunk, list) - if not old_chunk and not new_chunk: - # Most of the time lines sync up without insertions/deletions, - # and there's no interdiffing to be done. - continue - differ = difflib.SequenceMatcher( - a=old_chunk, b=new_chunk, autojunk=False - ) - for (tag, i1, i2, j1, j2) in differ.get_opcodes(): - if tag in ["equal", "replace"]: - for i, j in zip(range(i1, i2), range(j1, j2)): - diff_lines.append((empty, new_chunk[j], old_chunk[i])) - if tag in ["insert", "replace"]: - for j in range(j1 + i2 - i1, j2): - diff_lines.append((empty, new_chunk[j], empty)) - if tag in ["delete", "replace"]: - for i in range(i1 + j2 - j1, i2): - diff_lines.append((empty, empty, old_chunk[i])) - else: - assert isinstance(new_chunk, OutputLine) - # old_chunk.base and new_chunk.base have the same text since - # both diffs are based on the same target, but they might - # differ in color. Use the new version. - diff_lines.append((new_chunk, new_chunk, old_chunk)) - diff_lines = [ - (base, new, old if old != new else empty) for base, new, old in diff_lines - ] - else: - meta = TableMetadata( - headers=( - Text("TARGET"), - Text(f"{padding}CURRENT ({new_diff.score})"), - ), - current_score=new_diff.score, - max_score=new_diff.max_score, - previous_score=None, - ) - diff_lines = [(line, line) for line in new_diff.lines] - if config.compress: - diff_lines = compress_matching(diff_lines, config.compress.context) - return meta, diff_lines - - -def debounced_fs_watch( - targets: List[str], - outq: "queue.Queue[Optional[float]]", - config: Config, - project: ProjectSettings, -) -> None: - import watchdog.events - import watchdog.observers - - class WatchEventHandler(watchdog.events.FileSystemEventHandler): - def __init__( - self, queue: "queue.Queue[float]", file_targets: List[str] - ) -> None: - self.queue = queue - self.file_targets = file_targets - - def on_modified(self, ev: object) -> None: - if isinstance(ev, watchdog.events.FileModifiedEvent): - self.changed(ev.src_path) - - def on_moved(self, ev: object) -> None: - if isinstance(ev, watchdog.events.FileMovedEvent): - self.changed(ev.dest_path) - - def should_notify(self, path: str) -> bool: - for target in self.file_targets: - if os.path.normpath(path) == target: - return True - if config.make and any( - path.endswith(suffix) for suffix in project.source_extensions - ): - return True - return False - - def changed(self, path: str) -> None: - if self.should_notify(path): - self.queue.put(time.time()) - - def debounce_thread() -> NoReturn: - listenq: "queue.Queue[float]" = queue.Queue() - file_targets: List[str] = [] - event_handler = WatchEventHandler(listenq, file_targets) - observer = watchdog.observers.Observer() - observed = set() - for target in targets: - if os.path.isdir(target): - observer.schedule(event_handler, target, recursive=True) - else: - file_targets.append(os.path.normpath(target)) - target = os.path.dirname(target) or "." - if target not in observed: - observed.add(target) - observer.schedule(event_handler, target) - observer.start() - while True: - t = listenq.get() - more = True - while more: - delay = t + DEBOUNCE_DELAY - time.time() - if delay > 0: - time.sleep(delay) - # consume entire queue - more = False - try: - while True: - t = listenq.get(block=False) - more = True - except queue.Empty: - pass - outq.put(t) - - th = threading.Thread(target=debounce_thread, daemon=True) - th.start() - - -class Display: - basedump: str - mydump: str - last_refresh_key: object - config: Config - emsg: Optional[str] - last_diff_output: Optional[Diff] - pending_update: Optional[str] - ready_queue: "queue.Queue[None]" - watch_queue: "queue.Queue[Optional[float]]" - less_proc: "Optional[subprocess.Popen[bytes]]" - - def __init__(self, basedump: str, mydump: str, config: Config) -> None: - self.config = config - self.base_lines = process(basedump, config) - self.mydump = mydump - self.emsg = None - self.last_refresh_key = None - self.last_diff_output = None - - def run_diff(self) -> Tuple[str, object]: - if self.emsg is not None: - return (self.emsg, self.emsg) - - my_lines = process(self.mydump, self.config) - diff_output = do_diff(self.base_lines, my_lines, self.config) - last_diff_output = self.last_diff_output or diff_output - if self.config.threeway != "base" or not self.last_diff_output: - self.last_diff_output = diff_output - - meta, diff_lines = align_diffs(last_diff_output, diff_output, self.config) - output = self.config.formatter.table(meta, diff_lines) - refresh_key = ( - [line.key2 for line in diff_output.lines], - diff_output.score, - ) - return (output, refresh_key) - - def run_less( - self, output: str - ) -> "Tuple[subprocess.Popen[bytes], subprocess.Popen[bytes]]": - # Pipe the output through 'tail' and only then to less, to ensure the - # write call doesn't block. ('tail' has to buffer all its input before - # it starts writing.) This also means we don't have to deal with pipe - # closure errors. - buffer_proc = subprocess.Popen( - BUFFER_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE - ) - less_proc = subprocess.Popen(LESS_CMD, stdin=buffer_proc.stdout) - assert buffer_proc.stdin - assert buffer_proc.stdout - buffer_proc.stdin.write(output.encode()) - buffer_proc.stdin.close() - buffer_proc.stdout.close() - return (buffer_proc, less_proc) - - def run_sync(self) -> None: - output, _ = self.run_diff() - proca, procb = self.run_less(output) - procb.wait() - proca.wait() - - def run_async(self, watch_queue: "queue.Queue[Optional[float]]") -> None: - self.watch_queue = watch_queue - self.ready_queue = queue.Queue() - self.pending_update = None - output, refresh_key = self.run_diff() - self.last_refresh_key = refresh_key - dthread = threading.Thread(target=self.display_thread, args=(output,)) - dthread.start() - self.ready_queue.get() - - def display_thread(self, initial_output: str) -> None: - proca, procb = self.run_less(initial_output) - self.less_proc = procb - self.ready_queue.put(None) - while True: - ret = procb.wait() - proca.wait() - self.less_proc = None - if ret != 0: - # fix the terminal - os.system("tput reset") - if ret != 0 and self.pending_update is not None: - # killed by program with the intent to refresh - output = self.pending_update - self.pending_update = None - proca, procb = self.run_less(output) - self.less_proc = procb - self.ready_queue.put(None) - else: - # terminated by user, or killed - self.watch_queue.put(None) - self.ready_queue.put(None) - break - - def progress(self, msg: str) -> None: - # Write message to top-left corner - sys.stdout.write("\x1b7\x1b[1;1f{}\x1b8".format(msg + " ")) - sys.stdout.flush() - - def update(self, text: str, error: bool) -> None: - if not error and not self.emsg and text == self.mydump: - self.progress("Unchanged. ") - return - if not error: - self.mydump = text - self.emsg = None - else: - self.emsg = text - output, refresh_key = self.run_diff() - if refresh_key == self.last_refresh_key: - self.progress("Unchanged. ") - return - self.last_refresh_key = refresh_key - self.pending_update = output - if not self.less_proc: - return - self.less_proc.kill() - self.ready_queue.get() - - def terminate(self) -> None: - if not self.less_proc: - return - self.less_proc.kill() - self.ready_queue.get() - - -def main() -> None: - args = parser.parse_args() - - # Apply project-specific configuration. - settings: Dict[str, Any] = {} - diff_settings.apply(settings, args) # type: ignore - project = create_project_settings(settings) - - try: - config = create_config(args, project) - except ValueError as e: - fail(str(e)) - - if config.algorithm == "levenshtein": - try: - import Levenshtein - except ModuleNotFoundError as e: - fail(MISSING_PREREQUISITES.format(e.name)) - - if config.show_source: - try: - import cxxfilt - except ModuleNotFoundError as e: - fail(MISSING_PREREQUISITES.format(e.name)) - - if config.threeway and not args.watch: - fail("Threeway diffing requires -w.") - - if args.diff_elf_symbol: - make_target, basecmd, mycmd = dump_elf( - args.start, args.end, args.diff_elf_symbol, config, project - ) - elif config.diff_obj: - make_target, basecmd, mycmd = dump_objfile( - args.start, args.end, config, project - ) - else: - make_target, basecmd, mycmd = dump_binary(args.start, args.end, config, project) - - map_build_target_fn = getattr(diff_settings, "map_build_target", None) - if map_build_target_fn: - make_target = map_build_target_fn(make_target=make_target) - - if args.write_asm is not None: - mydump = run_objdump(mycmd, config, project) - with open(args.write_asm, "w") as f: - f.write(mydump) - print(f"Wrote assembly to {args.write_asm}.") - sys.exit(0) - - if args.base_asm is not None: - with open(args.base_asm) as f: - basedump = f.read() - else: - basedump = run_objdump(basecmd, config, project) - - mydump = run_objdump(mycmd, config, project) - - display = Display(basedump, mydump, config) - - if args.no_pager or args.format in ("html", "json"): - print(display.run_diff()[0]) - elif not args.watch: - display.run_sync() - else: - if not args.make: - yn = input( - "Warning: watch-mode (-w) enabled without auto-make (-m). " - "You will have to run make manually. Ok? (Y/n) " - ) - if yn.lower() == "n": - return - if args.make: - watch_sources = None - watch_sources_for_target_fn = getattr( - diff_settings, "watch_sources_for_target", None - ) - if watch_sources_for_target_fn: - watch_sources = watch_sources_for_target_fn(make_target) - watch_sources = watch_sources or project.source_directories - if not watch_sources: - fail("Missing source_directories config, don't know what to watch.") - else: - watch_sources = [make_target] - q: "queue.Queue[Optional[float]]" = queue.Queue() - debounced_fs_watch(watch_sources, q, config, project) - display.run_async(q) - last_build = 0.0 - try: - while True: - t = q.get() - if t is None: - break - if t < last_build: - continue - last_build = time.time() - if args.make: - display.progress("Building...") - ret = run_make_capture_output(make_target, project) - if ret.returncode != 0: - display.update( - ret.stderr.decode("utf-8-sig", "replace") - or ret.stdout.decode("utf-8-sig", "replace"), - error=True, - ) - continue - mydump = run_objdump(mycmd, config, project) - display.update(mydump, error=False) - except KeyboardInterrupt: - display.terminate() - - -if __name__ == "__main__": - main() diff --git a/lib/ultralib/tools/asm_differ/diff_settings.py b/lib/ultralib/tools/asm_differ/diff_settings.py deleted file mode 100644 index 183b96b..0000000 --- a/lib/ultralib/tools/asm_differ/diff_settings.py +++ /dev/null @@ -1,11 +0,0 @@ -def apply(config, args): - config["baseimg"] = "target.bin" - config["myimg"] = "source.bin" - config["mapfile"] = "build.map" - config["source_directories"] = ["."] - # config["show_line_numbers_default"] = True - # config["arch"] = "mips" - # config["map_format"] = "gnu" # gnu or mw - # config["mw_build_dir"] = "build/" # only needed for mw map format - # config["makeflags"] = [] - # config["objdump_executable"] = "" diff --git a/lib/ultralib/tools/asm_differ/mypy.ini b/lib/ultralib/tools/asm_differ/mypy.ini deleted file mode 100644 index 138b939..0000000 --- a/lib/ultralib/tools/asm_differ/mypy.ini +++ /dev/null @@ -1,17 +0,0 @@ -[mypy] -check_untyped_defs = True -disallow_any_generics = True -disallow_incomplete_defs = True -disallow_untyped_calls = True -disallow_untyped_decorators = True -disallow_untyped_defs = True -no_implicit_optional = True -warn_redundant_casts = True -warn_return_any = True -warn_unused_ignores = True -ignore_missing_imports = True -python_version = 3.6 -files = diff.py - -[mypy-diff_settings] -ignore_errors = True diff --git a/lib/ultralib/tools/asm_differ/screenshot.png b/lib/ultralib/tools/asm_differ/screenshot.png deleted file mode 100644 index 3230555328cd9acdf388ce1626415ceb78760535..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 99842 zcmd431yG#Zx~@w?g1b9Gg1b8j?(Ul4?yezdaCdiicXxMpXxtjt+nIC8T?|I+RzvN^@;bCxKz`(%Z#l?gaz`)*jgWgV15TGr};=9eDAJ8^p z>h@q@2))1G@8YNtaKXSnfr$%!RdPu^S#woWo_ig*yyF8fki`5Th6sk)PK;JWNis|Z zsu^+aDCNg#=!G|=0-dGpsRFN!*d=R5V@HWtjq$!zFb{tE^mFtRRO-tUcq%diOwffV zZ^T4S^`iOdq5b%}ds!X2tgI|Lksp!(6cH8H*o@VW-y=UH*`6J5CQL_(Z*_qu*{tga7bR<#a{)OOf4fWVsTgfN-|O~^HU_AgLGLcgL@F$H4n zWr;G-r0}(Es%!V>?c=6wf1ONQ`%w_<1L{LxpY?I@Q-aQ`neWb-rQz3gs#AUH&UsU< zY)xdWjZP#W(P)lq3pRdOxv<-GjZ?%dMuI)7(gO+PE$QRg!DbZbrc6Ovt=^Fq766-5)c zGoJ(ITpZQBar&%xo?I~-vuyJnJBZ*?jigQ@u}@?ogV3@)qEfx%#l}N|r64mG?-`8F zC|c7jt0s+N&^*JzapP;uL>btv30uhMTA6lvAKR9Z$Y&$&h6d2+Y>bJ=mZsGoa5s;2HN!v8s<;Ip1Pf~_@MNjk&d(l7Sf(N7P_`YCW+gYaKmom&3px9qBtjw3|*?;4C zWYSRGs%><_9@!+@vPfgbZQ1gw9dAhe97l8AtHUX3V!}u0`Y2W}g)=yRVqpgc^@(8# zyTX-TaYA|I>_d|(sgQU~Dt+Q^E9jyoI)Is(F}N?#8#r6M#|}oXTZaGM8>l!KbYZx+ zWFc2-%4&qLqa(Fjac)$@qY-EyBh#wN){174%ry zAqm9t3_bi5842voGw*BplO2k@d(jWyeuN{uoyPw$4`s@$wLCykf6TeBCMWjPzM z%;z6e7*CsAvzNXpNt)f;I+bb;H+x3iZG0TgDY@m+4`3xfTljS^I7TWLRB1HU(Z zcp=R2bPm{VtswGqVfo{lV~W`6#Hw<|7CWS}pz0RHc)XngJ_zMzS9$roDh95$b*p|w zq)2{m^ou2Tw9Oy(K1l~rqilZCk-}CTnLCkx8!9EaE=xK^^?Fm6<1LCdA&rsbu6}vZ$nN3VBk^*_{vTVn6%)|Ofsb!l z-*oP1^F5~!k3DN19EQGb@0und49n(;=)6EeiR zlh&o_FGPZ(o|0;5UT~(mr&Fkd)XGI0nJ|x)-?~F^KIEw+NSN(%%0NP(pkay0O>$;W z2XFC3WM6#KN9QK&m-571d0|efRqK`yQuxeijWy)jBR(EtCmZvZzC4o6}C?EOp=3f`~j66SNK z#;z<<$zn6Qs?!WPyIE2h0xrRMcWcJ|H3KjBP(j@yx?3CDj;;G`S;^`WMZdxlosn?rLJheNxys8Q zPKs6=j$^7Jcn6;C7;TxGO38>&4YAW9A*H3?*-)p=Q1gG6$fkec4&SV4pq(Gije6=GAa zLLusT?mQz}LF+S#H+lJY5*k(8Id^*^zRg;|9^GOICQy+X2xWW+ zJU5l{#Xfg}3w-33rRTArnXJ3Y^4UYkR-B!#82O^HkS?XWikPq>%aF!rIAl(BsmVW< zb}Pm>&}s*-W403IT%z$kHco1EFXov=AD(~Xj6HvGXG{KLS{pMVy{Y@gRZY0p5O>Ur z>+Z}KqTZN)%+r-wyVKZKacHABdkz z z1OUA2+f#o)ph6FB9W$7AY&~OQ^j%ruo`G^MYVCbEp(GD?tM~w*glB3_-Ij17 zPeeaNa)%8rjTvzxe;y?|TTOf%SImy@O*bx;o*)`%7!9gp6RJ5L*qk2k-#oX6AkqI6 zG5L@7aU;rK%*-7OyKCj|InW&*sS-IGG6&pe)GCie*{sq93x)#-kCx3&u{vy!?J?<$ z>=u%-_GoA3jZu!<@x=v!*|m$4o>_fOA%q#N-+Ry0GcInr8i~WW=+<`tLveMtt0Rj| zw1gGw!_GN4JgxlKQzywUlp!*Ula|xuwe%MpsM#i@0C*D4jE?H~62mgyyXaK!+k?ph z8(x}^u}U}wJcrv#D6h$V?y9MS2#EW?Fz=)o`}1C0@)7LGAJ0$kE0(+G7S*!hz2d?V zCeB`pkQu@d-^_+jgsr!409xURbw-O98hD8vku!%p*H(9;%oe&7ak_?!nU7j;5Bl+h z;q;HQ+dm1t0J6PyE9B0>zzMH3ztiEbQi~q&7F<_- zh=eEIW*dVTYk zB=@W=Kt`%*J!5O>>9`MeC_7>-rs8`N^|d%m(aVq>yFHmty1HhwE?6U8I1xE{5_Y|m zPNh1dccOYjM0ZtD-=740%>xNs3{Umv`$Hbismpk!H}J-Pgpb+Ou=|DzmHX@Jy){30 zc(+2?tC-K|knBi23IufUJEQlgMO13DJy^>51M ztgPkx`U4s5MYm2ZLj2iMau4kB7AsSgxqmj9e$%J%AgghThUD&t-%oj4Yfs6{>gSex zXmAr{;Fm-@@xs6a_iKxvXbt8k!u{d03ahU}*or?cY@&U8bd(#;4;2 z{LMIMUe~f^J~ojf__b~U9_-&!Dd_b8Q@EIJRy5@PaCb42Xlh}~?4_d<6brtDd4KMg zWl=E`h>eV~PZwE+yQ>`IvgUWF_9HM8R_(3Khp1L?Z+>Nr z#amATJH4>9=8{7aNxm_%{17sUVXlu*ujg`B zSS3YWC)yp6YgNz&6e_c3?0(3EGDIZZ330~o?n3ciSD$>a*IOsM!<64z5?c^i$7@ZL zeM3?C?T(DBI0cUsEO2MCRzeC_5^AZG|=5AWY`VnN&$A1?k*bZt1(gf zqvARNpEv37bXk%WO%dPfUyq<~@!&Qwkg$w|V;p--r+S0=pJU|U*Dy6ySG7J_h%%@@ zJgZd!x5i}Ve%)X4wm(yno+CuD;$N>-(mHsasmtuKwayJCQ6C4^*w}M$cK%ZQj-{;I zwPIbj1<17Q-B^b)Zm4#WT-OdmRh?`qH;{`+P<}vnDjc5|0#l(I8(XK zgeU=fw9m#L)2uo3b3pYRxQvp?AJ^~G@9S4eCA)){j?*_v;4T?ANV2l%%!G^%1^tqI zG}e)4y^^1Zf1h$KknrB@grDZ+f-s&c&g6D$Arx+T^xP6qZPfai{noqZ#1Qi8)H#<- z$evbP5MGlSEgFs=J8X<`p(wXtZS>B$mX){25^W?sW=qx~+RS{mPa3nQytA++V!)0V z8ZI>J&HSv50B_=NhjvjUz7tYuGFcIy0<&(uQ0RlYm|O zw`ia+DW|RxR^yBEwcDgw9Yh>$27zZ?!M;IM8I@9Xv$53|PrQYlYpkWkZ}PdE3TQMb z2;X;sKBZh+B7_lN_S@cAzn2BfJ5+M!4RBcbl&g*4UG zN@&dXqXaz3{}j&$LtY`HQs{lvDDiuy(XE;djd_XsQM${9B1jk?Cs<1-(hkWTC$==S z1vMO4#Dxbj`?8_IH>`(~@=7?2kAh6^g@2;b*%5UI6e9$9d|6vK_<1KRgGIEpd8C6I z^X!F(-LG7{slL$lA$1Zt|be?VA?tucJ<*ca6_vI$k9 zrz>Frd$9j)M?l>Huhn@87l}Ps&);Kfv4WhT+I$gws$Or|;&K-*7Ij2r)NeKGqzsMt zYg0Z&BxnGnSU(Lt2#Aeif)EAM&RJeTvWSoxUUGPv%Tt}p`)MlqI7thBERpc!-XTHb zLAP_-{??Sy3Lo18>bX9ho*r&FX@G&g~HU^GopaZ_)-w?M{WTADp=;v@^M z#vOjA>6kc5U7Rf=g3)n1_3rM68vB*E13o<@!uGhqM}10;Hn!+-8Px~r;Cf#)8XCM3=1-yM6*`;v986Y&NGwlheuuapE%(k?CG6e4cvDhiR!)lWP%vw}r;xb1!#sIiFMp zI^ChJ7E9e`P#a*O1raQ4i5Ge$-uZJmrbQHbsop;`{rs}a#DCPcX3_C9{f1sb+n=#M zOM?|Rly$C>?R{DtYB{UIkW`b%ZdfSfSsaC$TU}O?D?kT!B*5c3{Wv1jN7HFtIKPJvkbI3LN+^{4pP&a>AUW* zK*|W)!p6nI4sayw36#)TPc=A0;%Ej`c~0TI+A|&c3=qJC^Z8<*Xya2G<9BJ^B1JcR zAH{iMs*`0ZX}|xq2{+h8FjltzaWjM9lk?f_kSAV#UUUt&)lKqLmL%qK z+bmSzY>dV89nULnB0H3@^wx9{wTZbaP$VM#`e5CEp>>ThqNDrJw}k`6%*6dFS2R*> z&r!!YLLZnw&4J-PkD2c0vR}bnoql z$!rl{m7lTCpWtQh`ZzRFTgLUa3XkwI*ux*(%h6p#MT@3=UCkk4I11>Q@35Izgs`Nl zavl;tN_idPj0|}6*Nc8AN6J2lNyU5sH6He7O(ZlDzM%HV?bbbEd@PLPey-zzq?N^O z4^!y#-nOlPjC2h#Idwg6@&I zYjN46?amN=z}2BS=QF1{1b_Un2|SUIc;ugZi!petRmj)i*wXU|cSJR+1}Gq}FDgdQ zeh8<2EVv^f#Dz{444~RN5r*(Rg@X%YV-v#^kfGwb#ol<~ zE;{5xDUv`F4dV^DM$v<&9`R<8Kf1Ia81a2uj6awzdb9`fKS$+IXy!+E1QG+u{hyV5 zC>@(0r`Kwt-=S8+68TX$MFRzRFdm4t)+y^*+`ajjA#1baW0Z$JB=%z@^jl(a856Wi zmwhJnN6KaawUw8PyCF8%Mp`-4%wDTq^LZ~euD$70jiDF-Ixml_0OS^9&+Y}t9SNh@ zV!mYU8h*nmXxwJ$N55McJ2hw`Kce4lW%I5WU5>-J^(MPH80$@hm#pGygTYqs4vQNo`J8!v<Iy!dJAbL_Hm@Y~)hQ3F z@kQ@{RMMj(Fj`qwwm=94blq(gn);OLI{#25yWXucds@Vzv>rvyE{*&rjLqz+d1K)- z!S4$&ROG}-3h(bGFfO1WW(HH*-r3HIr&WO=#ZgzB(-9OmQ#cb4l`Q{bVi|n!^@d{%kwY_;dc85NSM*roxT%wZW{y1 zf%pRkeU|D*!jeOOh99IV4Rd1177YEY!&gbTy}Q>aqzM!djQbNMi$MM-vRVR0b-0i% zUhB|3)s1qj0?#;oU~*E;FYkD(!6C-M8tbZmY;94wg~kR z4o0l67~MB;{p=oV@xCk8u+^FZVLS_Nw$@&*+2|NEJy8h%;Y0at+;Wc*%Sb zqQW`GJm7bPsuxxZb*(|TUtGybx+hsj1!9!VWhp~cJJ<`x!=?AOlldns5ma=SIZW4} zolvW1My6YfVbpH`3x4W+jC}@|1KBQ8L?nzaS?z`bK?S0Auh8P-8#T0~0O5zM7GT2( zsQ|)@$Y9pS{cDrXv-uE1Kt0Yc|L2{wBF; zDmO@?KegJ6D?I-x>=-;m8Y^SNEb&K!$E?0koX1n%uAIJ|G*=Hbb3|sojlm|NxlAUo zT|Z5Iew(C!f&f+*`pxy$0Hi( z{2Rv#L6WhYFvC=gqJDtTCHXvp_2fpdh`UD2M9JHrBtwxxTB zpHpq?c8LEtCv9*Z+P3OK@fDq>ZFzE(CvoiEf+3hcl3~E^Giprg1PLeoFeZL5rACef z%NbAnS$G@+SxoG)D%A6LGHPe?U4mURssuW%&nv7!rvuYp{Ciez?Q?|T>9pKzgiJr? zMi`8w(pTcWBCHLJbuUaOriLm-TWfv#^w>3^4C9opF$(L@YbDxb>(L>Z~tUoFf{g*@gk=;T?yi6e!L%Kjt5H{kYiCF zpBEeU*!@0r){aK{rCBQ-1Z zqOo&9AIk`h4@3m2ab1F_+pDD zJTMy75`v6w;FYK@Lut{HKCL|98N#auLQe7R+W{p<`z!Pt&gJ_e}q|E33JFwKW+kVO2;Tswz@sdCpQJyi}EL-w*K>vDP~pX3L)44AB^-HhNur`YG(5 zjN+dSh?!+wuw%tYE#?HrcP|kZpGYmx&*(kHXCUS#2@vU~Q@qeZMBtK{utqits(Za) zVtCIVvgX4O+ETjsYm!>5=!dBA_%j4=SWyoj0&rUv*2*RS3K`pJ3nyzGO$SDxb2F3VpU2 zSw_I!gHYWb0sfL(ynT0VE2KNp-F_I-n3Az)(HuNp#CKLdq{Tz1-MgT@yv4h(*ecjz zv>JhF>-FYCxH6lQUXxzKpVnQygGqz?t$QM4oOrV}UFGITFYiN4=6f7+9TRomSrT)O z^z$8R@OfCpVs;aOv0UB6x(kLP5oMFvB7Sh=@xFO$IBMAqk8er;&d(e`B@W~VfF5O1lsJW(5lhbdOk=*(XESZ*h2oX&6J!&;X=tQyA{UJQrylC(Q`mR zao>Xv3eL*#B86#c*hFu(ymD!ov`y{cW^Y&u1wmZZ)E5DSOvk>lkKIlmVs09b<3tJF zeSXAzU48#k#;(r6)y?EGF>%2GYqNHSGGVcM@f5N zQO(Ll2b~bw=t*jk9>z%3X$wb2Y4#Cq;foz)GM5>Axp4yC`gzOlXO zsT#zMcf{P=2>JWJgD#KWxn`o{INiG6mT*^LJ!JVqS#q+7S#ofaf0M%(%EYUQuw3_!?Xu%3TM z=+3Q^d{3fTZwa`w>|ibl;cZ?9S8sM@vtFb;K(&f2)c9s>9FQ$bLdWKB(TCSEY*Yw+ zNxI%{YEPYZP4jU?0wW@IKY#LOIN`Tde1-VsZ%FDo@G%~mD4pPs|BnqxI~^rF=ZMQc zL`VP85+RerY=ht2;Xvf=oE#V{WoV@k>%v6zoJ?l55k*2n_~4UL z=dFCHmdiL@$U(`%`8BHI44nAN0XqyQils8>Y~M36FBG)B`&B8P%&7mX`H5gfVp?yeuecZA4xMA@jg~;tg(4nYY1d_sr8@XG@cG*F%la%Hc%dRbg1=dB#&O$pJ$| z#qfvm+gz~rBUq%)rn~PR@0e`VU?R_hfE(T29~w`SDV?&)dJ88?N#HzFmW=J1;`oKF z@=ywT4kSk=Kps8FHlAkvgE9yxiT!hQC9L)bg-{X$naad+r9~U=6!_*i334CvXAh4g zohKwdGm8m=oM+IJ?e9VZ`lD7w3)9f`$} zh~d-94E9zsfmZkzw^zM$bg``MUeC50=09pdSADD-8R6v311|(5CsxID)0j{Bo}#PZ z1@9kyDM68(SuTN~D{(s=P{4(d$y0-I>RHVmguocdbJ5ynRh&e?D4;cvyXT47PFNc*rAP&QgX{-xwt@Y-PT8~aK{5n| znm~6M6l&_r1;K(B}Rxz_~oj+b}&w%h*ktYW;?0Xszx+SRz#I{8Z0lYYtK z9Sr7M-xb1&Ckqw5A;wcf$~Lf6(%T<8nUtdu&$k!HhH6dDI`hXEnGTzg41fOpR6zNx z|1~0ZO6;bWQ{kJ&>xAPklwnKrH29O%cc7-M8rn z@r$J5$7tCqx9Nz~4$q>B|H=d$bPtJ|M`y=`T0xeYk155>jA;APIrPcu-B)sfZi0veq=Yj_`t3#Gmg+RA$%+<8j*zEV17PT2 zCRO_UqQUYjKAb~CZ8}$3FqGwt<*vGKv5Kl5TJ@LLtYV5?R^_SU^K7jz4L)-+v?503 zRx9cYU^H9Sk^~Hm+5Lo8nK;5ie`5&f=a;(Id8Z3JHl)_5vkYE3^~XxlFIN)sne0| zGwp_R3E(CsaqjiILIKFa=&7q3o7!*h`7JpjTAU?UOH}seo)GIXQh7cSKB-i)7b z-)%VCcje%>rEu8pNKlxfXZgy#TPYAKqADg}Np97S!~Uv<#didh?kV)vfQwQ|9Q1S>>vQ}u^M5WL)@kn0K%D#k z8y0fysEFrcd&2XqGotsj>S~c-gC?N#2a4d{MIXtN`mcn;<)-^dNJ+SXo?t}vx;1#p zc&r@00MunD$O_qBBGM-LBRVGJPx{Z1uAl$!C^~4Ht{?ULzU0TY!0D=dTWIBP5^3e_ z4tJ$WSEv&pufhe?RUt(Pw?id3|4a6Z>0N$RU!E;)z<5%iwW2w+ILOwJ{>@F;uxV7a zVkKrz*`kr#G!;iwh=}gNI%u@}vg zzCveQwqTpEP%^}RVTlHBtMheYpz8j@m!DpQ%Xr!I_Om{2z{L%u;zdM!k)t2d-X9E{ z!ujt&CfySz{FI#8+d)vTo<_f~pCotwsQU+>m+-SekxK0wBD6@1k9| zfX!UWY1<*w%m0|pG5vRU#clMaS^9qqL-_HYle)CvR9&+2VKww9I_@I;TtJH|{vRok zagXE@xoMaczPsW5>E$Z8qc?(*w*+q*YyoNR!D+^vBnHEGxZ~VY-s3cnvutjKsYRNq zd@20N$zR_FLeIx-HXK{3IQO~Yu4_{w8a3#L-PT%y{{cgmJ#c0JWFb=G#6n3#oVpA{ z4^OJ{pxTP}e<(=eP0pVSDk@KNWE;O`oB5=rVF&YtH7=r6quZZQrDT!y#;DEWQkvmZ zWnpsK_hy{GvPPU9f|spP2O1>19NXfQQd(TJ9Io&wr6B(%+A7g8F^_ zYPj(J!*KbH&+b@dK*x^te~vyTZ^d~Amc-!G$CAG#CC~;NqPFs|Xz{v-?~*U^6$ckX zhV7q~E1Y;>G2dug+)WrvZ~OM{-Mx!L6%pfTY+mT!Wn7@vl~6unFZ{_zlX&rb#QJxz zF%+(YA%K?lH?WcLUxJNw4+hRGt@i93b6ED*J^Y&8BM-m64c03F>+~w|9N11g%=Z1_kdUg;(?|?aF+V*DL4F>V`j6c|`dr~}Xfw2?`PQ3D&gwt$Rlw5U6{ozgi z32wWi*++Ok2D@6iNv8~CQoV-Wy#xS1v+b&Y%B4CDo^sj_u%FR;qAq)FP9E>D{u{m^ zs?p37uMo93H=%`^^hwi3@9o}kg)r#NXBVhIPgYXS~fId z?U<7nq8>Gp$jhIa*I{Asb%SeS{GFMGe>1Iy+(0uLLeX?-3E02q<-=L};*HKHjQ4-2 z%-U5`O+#yVoL2SL^rSd=v=5{5qEJSiD&nxzH?mmuOmYG*EU9#Lgx-NNd!pJOLGZWi zHkN6~)tA@592q7*oQ^|XL-D0)ctYwg(f8URw9!<}$(=S+8nqh|T=t19#l37ouRQsL zdJXP=dad47|B$5BIx-R0k=mQ2-ezmj=}ElV-4_qm;e@Cj@{0|i{~@z`h;I-57~(-5QtkVAQ3pE`wMvaETyBy3+w>$3##mupaQ9!zl0X zM|lyV&!jJEc5rbzmks-2>T$2CXhiRZTEP#n>n&yN30TVxb7Y z&r|Y>`|f*W{{o0m_u^I7dBON!~FO zz=0q=63(~lV~_=a0XjKQ^<&5Xp|{hM*pzeORNp6%BCT-EiD02NUX0(h+S)cHrR8Ec z=zi^9Mb?3mq4TGGbA#TZpsl!!L2oFc% zyS8HyK9AdDQVUfCz3zSUJZ|r-a^#$OFLCyP)siBqt7Zu^jcO&DIk zUXJ&HFPFrleWr5mUyi3zCRDw?Xd5##Wlvn(JsOs-qYt0bnoYXOL&0VYm8R`>h1>c* z?0YwylbIA=jw`gE;diAv8(qmZe|MyePj9`nLew$a?XnNASJTAFF(S2bJ0+J|!t)`Z zE!Xa6Y82J=nxrIS3_dzSx)=(`>Xg(+gherZ^>QWS)CC)I1;-%ge4~g4 zPO#zsNX8jmzkyxCPx%s{CtT(vh;_Mz#zgF)?#hOXX08#I)YFKG`f%K`L=!Q;wVI1+ zJ=b9@4iPIKb9Z&VRlqp2IBoRY+8WalI?~?hO%7-1p2jztxELE_PgX-oddD&%KEk~f zD^Yv2_UlM}>Rw7mlHVP*T94lDAi-Mw)H}&RaNy23!}!CjR82P5Dc5ZCbg$9BjIm4i)N`VS%&Zm5v5x$ zW?txtGn38;Gc6Q&S`CqJT4EnkFtHh`aKp4mA6{MTF6$xXYO%G}s}sYbI5{4!^*8;N z5(^?W-w^f!Y_kCV@1|u5NEv!kFf|&hj=VAL@3Q)nFv`p#ZMQ{b)<$WK#kBuJxM){I z6M^V>fZ^U9UHN!?^SghY%;$#-y70ABsgQjHi)B2LnB4^ZXyETz#&6f-D=8quvPqky znuN2C{%YJ?2Zk+6K813&1Q2A$27{-Q<&KLxUV$@^y^$^NvqOHva#<5FT=m}x5wWK#GbspCXo9zPwA&wk z+@e{cAR>BgQQ@yy=w7lmu!M&vVhY=XJVRz!;Qlscd?Bx+b?+r85B4{8D>DkaS zAZuF(xK-h3iL2ARI#Wt({5kIU+1IUgbh)PkwLsy(_4{DFf+F~$H?i+!nNDv1a>xh3 zkN&>E1hYKb>kiQ-p!#Mjb6-N=CrI85*;#{=<@6z;k zg4syRIF7b6eU;PS_Y;qmrf017-91dq-4s?R;(5t? zG7d;t3wb#op0nM;YK-+JYfJn?Ft)2<`RU=f#{b)Kd8O9Wm{f13KUN5ka=uB;{D=H{ zYe6iG+m|Uc293E$raKI}O=CA+lR6DwmCS3NM;NKGA!1GCLIcMM56?%A@_|Ff>Z-2n zLGWP761tBg`GQyv9-m5N8m9(GB3;kDrPWHdt_zLtIfg}5T_-gD8L8i6{ad15{+pcp z)f4S!_F$#XOknpH(|6uivI34CI+tIJwKAM4ctvOFyk#~Hb5%SX(UbH7{F4Mk+__BTgUyXxXS0kM zi+^~D0(&P=?E^;i(4HO$K&}~0O|##RVP-ZSSFip~KOmdFdGM;A8<%P+RUZ@hs}5o+ z%YG+BhIwnyc$})sLPdU+*M`4?wM4|u?zGWAU|TVTteu)NONen(MgDyf>Mz-VfYW6g zBMC8WL7YHS3Mp}-hGxLC@^ZrVeAF*QC%w0BS*sv75~*#aCu`r0fZ;g8?LctxHMOYAgx$WbzFh3r$QDMDx|(-l7;FHv>+ zJRq27@&IQ1r>X>z=66JY)%cJA{7LrSb>j70DMNo)XG+xZ444`Kd>Tn0Zla2`G1D*LZgfcMcTa`c_~cxa%x(6E%W{?nFec zf#g50vrx-rF&XEPh_fh@@dIB4xR&}V9wUgw_e-X zRJ^ZAAj=2Q!_L4lwb3h@MEF*eZ<7 zQ=uy(+l^5JX}&w)GyGf;fy=U<2(UQ$8XzK3}L8yU?cT z>c~b*4COnRh;t&9nb34!QQMV^uIs~fB-TR)?uCl)&eN=JPu<9+;fBX{f zuGG_FIYtVa>Or*LesDU7pyzD2dh|WEh_|GGH4U=G^|?$R?py9UQ-MHL3-=>c)$r|L3D}*kzOypP|Mj~MH&Ec zk)GHJKoI&a?SOmRDPVOvNra1f8H^C7{%tTLa3mtAW%PEOM(S$m!QsLK!8X9uWX_=C;kJLGT*-aYSY|t4XKtBc2&ZCH(oii9o@| zrc8iTP0}+NKb@E`R+yA9l6eWDZc-bYTUDK_^+U)Q(M0sCvVYZYt!Jy79$=A}6x;Xa z!`^9aNvz4r*AYYpqiAOqWcBPBR{i}bDl>Y8}5y831UvC zt%!u_nT+tfy4^sAYjt%tCqLPRhUISTGj>dQq^EOc49q6A)}LLk0NgZInNlyJIil@@ z<#=$W4R^JL_N~9`jLx~FWD>}~KX@3V=2>6p4t`6SfPoezGK>BDz8DUnbPbC&8N#ju z@2@U7OLcOud<%g=L95d!Sn=Q+j=I)h@0v zEsAe7DY6yJ2(WEe)Oen_y;d_cxtINs9E1L`1MI&=3y(f0X{!HWzt2ie|1J4{6Ybz9 zOxYL0mUC`sqxgcp>;p?1AiGyDh6qWffC*aDy#q4h8-F84t2oG#@0|lJ%@Fd>CDBr)B&cmZwOxOHH1>LV z!Nj0V>R#q#c0ENd8^43xTo6oG}qmIi?#t4)Z(N3UMP?102Z8u4W7R~amrp#+AA4RM-g$- zJ4fSjCFqps;NW?}oqqEc3oT1Kpw>Rta=o8)PDuRb-{Rs9V9n@zf|;83m=0|9ltr!G zduvD@DK0qQ9XmDL(7epPxu6WiU5yKpqn|y|w|IHb=hJZeF~gbFD9U8ADrRN25gp*e z=hAd6A7a1QV1hA0CrzV`A&>h7z@5+hU5q{Xv2eH7O202V;=#*UB(DURs<~?e5q<{a z-O*j5TTU+PpB8B8=lM#S1L0q@KeAYDX==h_Lz+g5oA}ftKd$=@P1~J7?V5|^y<|l~ ze``%JW1epMDtb*5po6>e{o^3?X!`b0b<*9Xz1E&&PO(2D&8r=%Cjp^wMz&jQCurzBycF z`*Z}P?&3+bdR(ehb0lde;5LQb=S|pbm=#P9NYj-y?ko*7Hr>n4<8k4ukJlzML~!=d zJU{fUczBi~ofpbWwcQyK&^Jc_RAS4EbMA#0ZG>cJ(FrfMFvWKhEe=*a2`xaCBmY#YPMtb?pR@O#YtFgWuBsv97fg6VNx7H-xQ+XSA{gRm`Y2r5NFU2_LMET| zcwdaR^Y)~kXQzxt_qlk~+XNLOOGZPR`5!t6qChwLOicJgpCPHmT#Rqu*X9ji>Uhof6D%f#QBx{aPv5(N~CA; zn0_6k6lTk24Lfvw@H#awC|KC_1Cz9&D0cWb5MdJ&ogbsmiqG{5MQ@y&_i&?sQUY z++Nz=Sn8h`JywGwEq5?ekEAhE0=Q2JEa4{F2Ymkny^ct6Qow{IA4Wq-ADrsu$jR#01)U$eH)l*yZ*FNQ}dQ+t-&=E9`7TWf=LmS$}=En{! zCoFlNNP+9bMmOhERDLChYg$>u`;0KME*2MV`)$0{oOSYL>-h57o1ZRfm-d3Im(S=Z? z_f!F+8P@j8-H+iD&o!qz`UVw0gji-1l2XJBT6l{UA~8BM?2sCp`}#Ek%rMX#?tinv)eK{h&h@6s1_g1XW)PPe2+xee0L`uij*@W2@OT{83XqL%GDLjap?hqqjXm+m z5~!bTY|#3f*yA3I%oZ!*OpCIAGZ)yW1o!?#b)dAs{wMrDc!(en2puJ5_qG4aW~?&< z0T$RXWi!?XYf~vY&AxqxB2`y{9d?E;wby#Cj-d%_fy9G*zS($&XZ2|H5fGClV9lIL zuibF+`lvWRq{?+wVk7qjiz|Ie5Z3Au=zBtY*}bxYZEH)LQ2~ycR3hgT&LoIngUuKS z-|0dXPPq=3Hq)v}`Vu87PD8a4uc`?FZy8{JieM#Pxrx<67A94d-t7HbI`HR?0&qPr zYa4Gb3m&}O&6B{lILk95Q!~c&&6AeCQ5jy7bx^_X3DN?dJV^z%#qdMLPphjN=@#Q< zZ`iwy$-E|Cpxf5rB$~lhM;y}YOPFR$Twny(lhXKE{a23IGkuNP$j#Xj>a{-Q=pk%* zWx~`}cv!soh@yE#A`JIwmz#jdbA|r!dmcm6y+@>y&GlEjvvW(sTTxzz&6iTwKtxqP z#`x>RxD1ejbDIc10A7&*DKCh>)yRi%lQJyJD?awVcQKrnF(dlT;^RFNiDMBgZ&1B-Gj$s|9VXJ=79fms?)QS&P8xW!ixIUDx{ZdPkKLeXI!TF z;c0NCDD86VJHN!+VYR%t?k&Y+3s?86;oCTjtKh_?wAa;%z?&2;zL*P8mBx7g^xfoT z?R4>SYaQmy|0lX7OvL&N)VXKK#libpn8MG&=?#o(k8N>iB~EePuCePU$P|VX@%5Ag zp{-Kx7ami1UEH#7_L-V=7GAVWnj4#wihm>#04TTL;jf2mUEw<+;jY3dMaLyP=^}^^86VDB1MY_F_!B)QfK0JW185N$3kf zKd7{XfR_5QpPwH_r89xh?V&&`qs0kZu#2MsXzX2i_7<+!$Pe?jCa|5aM`p5x1`nq% z;;5?K@&agx{jy@(M^Ij^%F~{|Z{U?~yQY9Z4+9AF*zbyqK5!H=9gI{|z^L7x`987? zx}_#0VkESCe}*j2QiHeMHJeCmR@Lh(F0LXG!-eS3K7ABBNvhq)I1 zGK1#n#79^ERZ*}cxq#5CLmsvshbam&L^O#8M$HgZw`cso^XsaTZh~gT;2WF}Y)bEI zpT^wDeXC9Ll);0NO~g%!(HuE}P{%iRT~YCg1re+PPddk>_kj^!$@iD1lX0yHa^SK) z2aNC257sjad0FhI#620nTa%-ul3t=JJ^VrtP;dcK*Ki^bj|t|kd>%@}@pLHj*AG{^ zX2B_A?aVnR&rS;_9;Wc4@s8^~#)gFCz=9I_`0E8w`aVE03n1mtsWMaIj_v;ZqjZ(` z)xNW(9twI?-VVx2sJab9AMW+YnD0o?c8fQgdOHGgS>^fJQt*lKx&plYX`Yjdv7KDz z1KGokM>s8SXSPf5k=6Kg>l8AF6-ylidyUB%)%se7dIhVuW#g+>=duc(oSiLw>>+K( zWU{2M=~8X>gIAB@>Qc}BDq?+c^;06LTJ>l;lI%EeUe8^P&?0)rYdk)qtIuB%%lZ6Ww{|GpJKy)>77 zRwS|_3s+*jI~_RXy6m=WO1ppjDEezA&|!O#T*^yFcJL>LdV=CvsAj^$@vW-)+XNTM z+DZhq|X$SI{aATShn~N6t`3Debvrg z6tn21XYqN&(mfw@_BL5jWMK4I{H-7 zKE`OOId1iLCo$Y-?+b^8eDwWl+i9vS?X=Lfto|xlX`|FRjXQ2v!~_h9{YTc>)|w<{ z_Wkv7IT%B=mtB%4E}n270_+C@aTQ}^)jxsnUo{c9l?-JYez)JYvwP!LV&QvCW=y7} zE!$D&p!e7MTxymN|H@UnEKq+ZU%fx5LnW2jO$bow9t;~`OnGStFN@NEPo z5%`|AjfT%p=*XeDB4expsGxFVgP3(E?V`3Ml|;8Ds_0Mng{0WBU#e~-ojp*?G)P!TLAgA8&J&EHi8SsE*iP zseoMgFM8G2%j0n7FmCMliI-coa>i3nUQp$OA7qdTlGxQ{IwpdR4iCk$i*Glu>z)+Z z+8Y(QeLMOmS{I0((6phiHpuJMu}ps>Xz!>uKtvplrb|eftec zH;2M)Y0of`MSxB3z*}O{kuyYh`YE1I*%n@m168c9@KC!uz{B z8h#YX)7n_5{A#pqwBK_L>U(BDxu29^v8m$7aVGejLSKQM%F8=E@-yP+JkIDeSP+dg zb}n($GAM!h3*Vpa$s^jI1Wi_*zlZK|%A~i~qPG%;=yMd=ew<-R4Sv_s`lfvz_=(wt zxY*=nyjS$yBp1lPAiA;p)*<iB1-^ z?aoo8M?+VBu&tLSG(Y>>O|LFPN`7)<|SvFoU^4>p!@>YozKnoiWn$YHs$# znjeSGP{FK(VS%@zYFl`bYL?g6_5BW$siTEe+JWWbFuKl_+M;z`yEo*zUvk#0{=SRr zb-*W_Mx#>z8d_Ov4VIxR7x5qC$?J7z^HQ~Dg-akIoBY~Hi((Ibn`-*Gu;H1iCs4+bN+F-z}kn<7m=!mgYVKpu_N zWrmpF1k$)Y$+kZ$h%va#0HS}_1kb^dsrYU~yY6FU4-y>UbF`JdEDILKj7Krwm{ldRv0^WrDkxT~!8O{9%O_=ZUp zsc40WwvuwzO!#j9mF^PfkuKLutiSuUmP&Dw?5)KKK!M}?kQ9N&(wIM*xf_d(zv+_f ziEwI$1SQ+Kji0~g{<;%$f31_Khj!aJNhLEV82)F6|Akv6-e+a@hKX*d^IM$z<(}3N ze-zu}`<}}bfst`_hNww1dcfliSocBB7JCZ*F6cYa>Iz;H-xWOq>|}%r!ga-Ih9Kl` zz#+L|-DfRLIE#+&FJ>i}r3*8f?U0GAvqbt#BVpFc*4kcMG!7<4GtUIa?A`{+I!<2b zFx^k-eTgyob)hfR)_*ZN|I>l=hk#zyuv9dBAET1!NtGqLyo;Vze$mxx3Kx&JJ59pF|+6stGk{tq}nz*0x-M$67{X!Srq~vTjV``8AYx-9e+Jzl9k?g z_MS}*Lpk}sxObW|5cdw8OZw5btf%$-Su>u}t-BBmncD?tEsZ6AD0T}L*XM4syIPS- z(=)?y-O)aJvy${Ie|KwAt@=c$BQ0N93oiZ|Egm#GBxh7L{rvSytOc`W1Xa+{#@B}@ z!C!^J@kmr_CCL822zXA8e<$F3l!i%#8_55IfOi-EK^fRg10qL2gK&Xk_v}jqfFDG^ z%Nq{S*QcYTZ}=o^pj0ldV8Sc>cMx;O$W3kYReVA2GXw%Y7Sr)qEcy1K@!~L0c0OKi zp-8qh>E{Ozo+}F3o4Oi{vj{KG-SrtH0WEz{9|w20b-V-TF$?o}R$gSoNkvl=J3*?oq|dh?fVX~^4g4oMRg zS!F?=e2d1vS2eUCA`q$o35XP+x^0yI9s^DMR}6%6{Dl(YJA~BMn|_6noV|9T+qB6| z2dqt5m&kL~x%F5OdS9`FW`QU%fHBc=;24m$i?qnm+25 zztr7KR!y#t1%<5sBbQVUSA%~ zK@5cYiaWF_mI7YJ4UKMqZATwtUpf%X&tJBx_~B~%+1%7Gt%{a9x6g#pG8V;hZvwbB zo;v4|(9qbB{r?JZrfU8(z}bv=O>1s{qNti_JOULHy3M)E#8_Y*ezXKMCW7jSJQek1 z$$EI<*xQF04PTKYOC8T;q?7Utah{Lo*@nI$SC%^ot+Qm2aIWths?KjYPvSbcKny&K z6iM3-7P)pAWkXrCcA|E5N~Qk}zB%8&>`6K~%C>5#c>UdYWhQXIY0Y&C^S*cdIC=d- z8L?P#I?=yxIyJQ4u3{h!tXk0By>Fk8YHh+;M`Owxt)wlRR>38UX_oojcn#zLIWi=d zWvwY=c3zw-G%)Ixlk(jU6GF_3;ct7SEs0ro z5z{-L{bb)m3&p^vX51DDrOr~iYu&3hIlWm}RXk}myk0wgai<21r-V&ELPRW{-Tc!F z@WSPFK)>sgX6utFdavT>jBouR^E_oDkYLU1C_f&hEeb7yXYV=l>#hpw%#_=v7>6bc z-F-+t8f{eBZSgGbY${zd<Tjck8Rl|7(Oek5`JZ}A!2Q?74PH2Z(qGF8DKxrWQs6N zCNXFty*yS#Q8#Hw@}9))-wB#=e;cp2DL0m$XmMry-HVCt+Y-hT6O*U=3&KZ?qU%U* z?pAr$y5Z_7v{md6T@L!|1g0H8y6B)T?N!U)aGGS>Wn@J}n;Ke(YhH_kF{PKxSe(Y19Ea-Ghn1A*EbwZ&F7_@Z}(|7S^q9hdkh)ecOK?%~<6nmFO7 z%JlbQ3U^JFx{iadt*$VeLxtw1lNA)l#}f5(5+j61M1NIx1=V+L^{ULS(!kX}?lGo% za`rw%8>vh-_19XHkb@9VD#liKbCr4pPXrR{x;IHGXs%dmb_$F zj`Mbi(#XplaGy0|y5MSgKKZ1E!_=qvWya=xEQkP zZED-O(UxI_HpN2Hj@18-6j7LW`fvw~CeSDHd8XCTb@)W-mw@s4l<=bT@G64`TDgH< z^e7M7q6ePkjKahuCW}ek>8BdD8P+YZ$Rx<>*#z6Pc4*5xHSF1x7`sUocd9k^<5{Eip-Uw!fTv^8T&C$Grf z%nK*|Zo)JpV1mnIfpzWzo6QydF|!xSX+e(xeGB;M(1R4Uq=u4|dD|A9=ZO^t4WX6i ziRS)Xd&IV>ePo|;ZFuRxH8Fg4n3e(_yL{5zh`;rRZ z{|-fP|2-5@U{lJ1rcI-@GGtcx|BN(fT1VP7#Q1Z=0qI+-tN=hs6{Y;1#3Plb?OU z$nI^lsjw7Ot(bXDa23{m-J%Y_`x-6W~+-BYMDpt|Fj&e*tDh`(ELj?BqmJzT<4@in1tnWM= zj;<;`X>tw8E{AsR(gY9CZ0niOhif{1%9v=ooAX3L21ehM_D6l zTBs!KtsT~=VGe=>q7Iz~|8R(~>^FS;_>uPKTXE)Cg7|@^h~sf+?o9{5C)sVDxAjaZ zsQ;^XWz8o6lR4YaQzp+EeLN>FAJct>?nziw?-$Q-=Qv;qOO<0@44Wru0fT3pyU%la zRWN{nD~+Hp1nCsHk5*H0Bopj^ICg}VUdSrt72R#5@UlDG0~Zad3ybAutf{skH~8#k zka?bOAC^A8CC(=Y)vu+qmzndQBN<|{mykxCLO$+}|FHozX?d6KkZ6Wt+CxrPdOlk2 zKYrec2wiD`G~^?Fif+y%XmTown+Rv=4)H(bz1rWpQhe1iaYuz*P6=?9cXl61L8ga* z)8i8&k<@*UJzd((8|m>T*RlS}Rt`7Vz*|k+;twey@on00Xu86j(F6AD#MGAQJ1i{c zKyAa&WM%Is@e z7yPG;u}l-0|36fWL>_c`e-VcF>tW3OwSf${xr}QCC7H{@l}J{%y&@%^luM>jO6XOK z`GrK<7{t8q{{ZSTEu6hTi>V+d)8C8su%~9ZLKznRs3eQ_(IdT_&2Qsla_QQG$fKZBRKf&v2^5>?O(nf4bE6BL zFx*S}u#3#nMO5cLF1msx)UUOiwHs|44G@=uG0*uuYIO2dfqp78B6&DwD|osAB^;%Z)zxgD6JsGj+-s*l7bz z++R(Qzej6HXj}x3GU&_q9WkcGE_X}X+%XWmZOG+2J@;c1yBsApQzHnH#4@01ec+ZH zX!Gkv`r14Qj?%SWsIj4YIYD|c&z13EW$S~2;Z2Dj%l9Y|)&sHE`IzsL%#HhU+9e11 zGhZwK@$a5whoogo9|2o;j!Pg3M9$vAqQ6R#C-@sBmT&;`INuowuS5I@uH{_VOCkYT zKmrs_M)YpFo`YkRcBwG=At+f#NW0jg+T@VG#-Kuk^w_`((qHUXeU1scVm96tMWx9q zC+6j;T4+Lo#O=Z_Is3!d07tLS$O!029?3|3Klq?;gTPjm1bWIogiGXbY(wCb!Q6j( z@kBRV`zj&g%-JKieY#&e*LanabEISiwO(NB*jq{4(;><7CfIW&{0)3}-=L8_?q2lU zglq98hBjZ%`I)Ls4eS=;UzcWGsAg}e8;G?ZOnwjDHIw^u({qx%UBN$0^HjsbR9=(s zqHAXQZ7o!>&3WOR@UYA*{7XuFBq&E&_trI=%`thpkvAp57fVilTGSZ0@GERJ@yCIU z#Ly|SOQCa<{^;+#wE9IS6(<^&Rok&%b{4;W#r^pjE0P3N{_O91qo>EHg z^|=xl?{qC#7FPuq9ixN5!SGy3bRTPJHqR2dyn*;_sUF^sMgyw(+g=`=r&4U#-D&#Y z&hdF2fX@48tYpbkP^rysD>eJAv0dZYV}eh0+4QK0Y!ooA_}Cgz{^JKyJ@CE^2nV>G z7c=!@`GwY zco)u(dfa=GgQ*?O3Pz0E^yOe3kai%h*+jMW-M-I|k0xvVYzGtfMFAKd`$vfUts;Z2 zrD3u?%ZVb{4%tGVwKH&7qYKC~jpH=eZOM}_cY`f~iz%=ST?;zF$BM%?BQnZ?njO)L zOfAeLohzq4&LK}}3Pf%KpGvuGJDhPb9-jrG8i}MEi`dS|W2Oc9R{yxM)uKJvDFrXY zB>~JuONLN+K^7anQUtDY;Z(s4_-ndB-6eFUP-qcPL|ZyR6UhH`@ltHiquXL7!%)>l z1LD4#xMQbmDQjbH}tK!$}hECblL?8mYiGB!|}nIij?ea zg_JJT!_yc7q043ciRHvmbWiCQX2~H7-HH#X+P^mT#m{`2B!+5qkjfw|qajeiEpLaw ze;YuvYR`u5?ldYeMZf#0o!OiO}Z$(>9a!FbCQk)fFX%ELR=X@%% z!VVr*Z)UEK17!)hX`4yd-GN{8dk?qja8HZTF<=N48H)Vof z&(qDgCff}CED^or4w7B?6lA*(+31!xFAh9Q(6w3^<;rzCT%>i`A-8^AcQw0W%S?|=5>Tjqe9@YjQ80o^FY8fm#kXHySc z<_PgSU~1=Zi@QnXCHbo7<~{66xXsDRP`y2Wj`~qt2UC-H*2oX{n4VW*p-q|VZgD4Y z;FAX{=iE`=(TN$89;+%>y~ri)pfG@tw&$>x!!SJit7%1ayW(!6p=`4(~wids&0{-bA%Bq>j7UW!3-8=<|uD^3MvG$*sMmk;M-9cp; zfE+oO%v;`uBpbQT;J=WA`hsmv_P`mcC@CPOeky)R z+>UA*b6t=#3g0nSP)`FeBpPSW)P*RW5vWX4=S8 zkH)EpZ74V$GFBloN?9Jmg?rD64lH##r_BzhRz60Uy1VcPoC4qgS!u@SHJtQ(RMeYr zwV~xi-ILtXB0xLR+@Hk-$5Y|fkM=b+L<`ixk!B1>%;o0|pdR}#uZZcnQV%L>*wN=J zQnVhH=*hVHPq;rc&MBxF4T;;6+;hAaR_+~=lh*n!&m)Xa}F$7j+Q-BL1}Yd35RW6Q+mBX3~i$P@MX%NaF+o zo1+3QlRu&%r?s#$k4A|UTK4GjSk13zAj%(j{pMcDIhY`Vbt6VBcbof7b%2}+AA?%U z&9FZHPH|J_u2V~(tr*Gdnt&HOgV6Ef()If}>AfT80iMY!mU+!_d2{1<&(I{)_DrpL z|A|L9V^2pS(mAYbI5aA1$5-v3j>M5=$EBL3b7A>nsZY;-SlB{7kM5p;hN_XW?%-TQ zJQ?r_H7V$Wist%>o>6Vlv$$~6qbVkuZs~I=nGC1CN@i<5zHXR>)<58lLeDjiZZP7- z4TEZc`SL2spLrHaT8&yPP;|&FEO1>V0$N&p zC~~2yN_b~75Dv0g&&bJ&LM(68RAwE@WAu0_qaOZg)l~j%X2UOQ#W(M}oVhH_z=iq1 zgz5BhOw$t(bW4cn0g6l~(euvoy~!YMMd+H2n)r{03$ov-L0N3pZd2V>M_55QvNQv zA~0~A5x)w81GJ@qyqek@mxG;d<$zlQ?VwA4x_}}0ey%}Zp)sD$>Gj1~N{nfpffI4% zP9+RcTi)TmlZh9k$yWT4=+pY~Gq8q64rHh*g#VLzomRlQ%}52#D~ljQeU<-^7Tu#f zEn0{;zv6FhOlB@xmQvWwm|QKsw5Y;DvRe|VUm+h3*Q6Q$#b!%ru&HNf1gCc)V>JQf zgD0?v1zPvET|ka9Xw~?~3{)j?0pXv`(S8$kfOkv;mE(8(l5Gnlj;i`X z9dr!ZD}*&~l17zeAeg5dabu7DKud|vl3d)L@YPfoI=oWb{Fq2Nf_RqiPQlh8-a@hs zk%0+xeSc0Td9@0vo%h$PfA{zQT{owL=+A@zdRFCWhs%+eh4DwCw$BW$-rNjACcT zuBk|)_NooCpE(PI4sR7JwzlV-9B&P9>4A_?xWAT_qDPv}gsR0c-1TSoYNc*-0>}El zaM6n&nsg?s4@#3>E*Fh>IP5qOnV4Ek3C^QsjMljwA6CG~bn5YVg6sp@kdcmp(!3)p zczwr2B@tp(C96u%1Q{WuImcjt)4?7_zbRU;VoDQ*s29F-8*6lt} z+I@dh{BGlsDPt`-bruQQ^rwRalv*_7eq}|nwwf{ZLH6eE(@eCD{$rl3I#$9sb9R&V z7x`n5yVqYV(Bjkx+Il1ERP*QG(%Izk+{UP)uQf;g#ia65AXIow#n`Y+U%mfbC^PvXXI*nzK z{1_`p#tbLuV0?WpS#ha%3lThI<0?8dEeQ+x3Ci)&tCTzlZ*tm z_hikgg9?DPF^i1i;tiV{rKCu~0XR&h2mULFAV0-)A31zTzTk6jP<11&dD=6IE@}Pq1N#%8NxXy>pk|upBp`d^c&&#o%3AfY6dNzok)VW=b4-FF+T%htF)ZiO8 zd_Jl`4Hibhtpu?Eq_h3PI` z!FbiK2_DCmibVyr+Yv`9ZuheQqPaBL*6qopN(xCJe!I(tiqFY%`g+H+-NLmYrt6OH znD-^+-EL`4j6v_V;nbTKZVfP zJi+G2O!6nu@{Sy;Qdp59pjg5Y)uv|E_X{D9zOpA86zoX&%#Iq5@AmU{T`Wp<~3mWkSM@#R_er{0$@B~KDvSkGm#Gkz@A0o6l8@p6*B z!=Tw2a`;g~43wsG&c+l|oz@V2?t?!*YM8ydkyNFYoHJE$?sf(*Ycg=+Y?R&N*I;k( zSapJXON-|t*3<4z15ljQSu0zzeB9ed8td3L-fQ+9I$x17sBhiGM(2A=(p}0@!G`2! zpS2nL?8I{ZorERPD+2F*p8C?2f`Gi~hBYkB(a-zRV^GQ~g1VNJDdJk zBzHb9V6^C~lLafLSN^O!8LJcV`#hU%DUPyQ%!bUol`ZMfpJCKnckr(!+4UpXE|#dW z#Ik=i=Nh`X#UjwSps0t@zckx^Rod=Y0f^Z1AMf!0o)T@Qp8Cvfay2W9eBH(FRZCKQ z^COo!iTM4Vq4jyt@!s+LDmEgsH!`9Bg)Jl|DTB+l3>$po*F^n|i{L^&hV|O}x7{0l zkWJ2534mQ8GNGpy%Q!&({CM1;`goGvuJORqhzNZ8vrikX&}+Vsh{y=Lb0T^0-s;TrX>>W#-RK=hz=4yk@9G**k z{ct>o&-Oh635q}{6OD6dY!ZIq~&aHdI%O;zkz-f@N3ioGy=IV@PjnLQkq@@=X7p|CU^Z=E+8_f z%zqXTslFf;!#6wO`rqB0#*Jl@ffQB-XwZ2YvYi4gBVp2F-`GNga;7Ouf<&t`9$+Lp z^8uh*bp6am+>!3G$l<`?%EvV}?c=N8CY9E9Hr!y=6RasRL^`RbWFOgtrG?LR-g+v~ zR^nL6C&)fBk#(}>Ay@~@uVD+*8`6djVBKRRwO`Lq@{CV?O>S(;qgI!dA0s)rDr-la zL8|-;Eiq-MmB!NTV}Ul{o&(nc?tQFZ;@LT5kyMW)@Y}(HzN{28(LgEPNF^u(D+lH* zOi@gdNn>}WSlH2w(*rdV*AvK^!U#S3mL0BPz<#}9R$nqmoq`gT1H*^04C7tk@4ZjE zIFa49*zlRg+D0IMq+n3sXK`N#Ck@itbTgZv{r5&K7_6=$vOA^n8eYYCMY$*O0TgRB z-5a>HTzdt17{i+Wsvd(e%Ga8AF)htty|sHDV)x?g6>>8ynI2{)?CZNiHR}%$Odu|- zY1_gtUdd`0KrYUs?76Su6yD!r&0Al2Mivg&zy@_(+Erapn3$vv)lbfZQ|r@%6?TZ64AD{`Er4?-$D9joA^79|t1rs@XBfKu44t&!KMYG?gcqtQIjZ!SCeFw> za2KJgiCImbJu{T@6j+0F28<+?mY$ zA@lAhdL3>|e-;taT*}1fuh{cXmo361RHsv+y=V!KYpL4IwXj*;>D9;mFv~!*ns?}u zcaEBBYW=FvIdsAWjS(YB(TwOE5AThLm8?|``PRS3ikb{zLKV{4cgBmlZ^Ej#_K4v! z_x1F>?tbsm8UME9-qUAAy`ENdCeBJ!$Cy3Bbx0kj78x4sOR@m+C+k^6j}-xT4^0h^ zmHoSxdT@#Cm6@Ol{RM7>&VPCVpb+mu_~Ier*b39BOyU8L2qCPLz-43pvVdlsZ#p0*3?76(Gp>(HX1y3nIZ`JgMx6&}%S8y}~h z4T8;njD4LrQQT@#0@``tZ;TpIZaR$IAmX=a7ooMbFe-X`op*xul76xZ(JAceg!66u zXPQGE?t9q|JjYv2`t}7oQCZ9wzw@bf*g7Ay8>=B3d?61WOyO9W$RS40R0`Da2-xwS za}Q+F(|l#!kd`Z&z~^sEJvlU5{5Pbb(bRku7MCY_X06JmMr}k@}hrCk;pX|bUg-T4&^6nFZ*eR((E+B$s-ezUf4(43* z5|erl5Y+}i1t3;_)H(#3e}{$KXv}TKB;bSarX&4v{y}J3)v9kQM(_Obu%AJd|9q+k ze>E!I7Ge-ut_Zw~EJ&ax=j&3~TIR}!ed4EYPyFRi%!>h>{tfpzPmJl&)Iuh+kB@_N z1jl)_zJ4VHv89B~xUz-_urg4t#9QO8Ime$eSWdXR`gvPY6}}lX879`puQec)!iOu6 z$q>GWN9wijlQ_Ib4^G!3t!|0K$-x7OgL6ruNnEyunLzh*=ZGXSZ@*@UFQS6K?%og~ zYLW(>Ip6uKDD-&Bl0?|1@pSr8grNVi=dxj08MNf4{=V+#wB7Y9$f0} zl;tE7|Bn)P##{}%d+zXrta@Ru%60u52JYDxO4RV6NxJo4biaS+K!F)6Y+idoXXMChhFgJ^x96pdgqH%+i`JKg>eTf_9AafcC{xADbZ_CS?s4 z_C+*Tb2TIZ^nkmOgy`aA>Ec%xznv+7+nwi>p}p84W(~#5+k0<%xi7;H&rMIZVe&jO zMi?hZOLmi4&+1<5MQh$}Nz-n%;5o1DF#S)9hGJg@)J$yp#L>U`S5w)=2f3aRVnb1D zMxS_KdeTjvZNQx2{&{MH|GpDspAKH!1qB*mnr_MK!|(N#SoKJwrJi^qq@1@4TQ89X ztG7B*8Y1imml4q{=>-O=kNPkHg8?wO{cu8!G$d`?E6pyQOlaYfA&Q*6g0it5^s*&N ztew7S9_qxAdr8wsi3hvJu_sxGyj{4(_iS;kx0vK8eMh~AhgqnT^j_~2_1{1H<~-LM zp%ZDqY1D*m+~Q1hKNKM&4cu?-aQ&DK%0|LOlSJ}v8F#>pIvDuW)dr}x4=NedvM2P| z1E0ZlXF;5pwGnpFAxVAFlzdHQYl1`&GkG^cziB(TOQ^9w z5FO(3X5MrJH}2pG2z&lIdB1Ib4i~UDN3og(bU+rH!fXw=BFA@iOUJFKq2cx})!D}X zdVJ{Myuh;Q(;(S=K(J>_Aevf_nC%F=$a6(u@d@Jm9daWrRDjCf{MnWOkC6oOLJ?2o zL}P46hHK?x2fB4FAn|12&|*N%o-((-`zv_G8#=7U@ZDV|p6M`4uVtkOwomxYn<{As z?~jrWxH_f?&l0rW8v7WUuzJY2N?zAvT$^ORC*!`v8n$L+bw_zbSGbIDAD@rU%=*}zRckb{RG~=OHtee0W%3vhTm@lG; zK3KdmxS_P)vos<^PLY%}zC+Uk>{KQZs`$LI+%yYen+gBXy&8lcUXV@4@V z+OOTf`F3#c1I+>r&Pi#m@4+p1KIOpSENYtdAHF2B*_>k9s8s`6wNUx>Sh?)Kj3{NE zT{8MVagFKZ%4vB80uV(|k*Gh?#75gW5$4WGyHzz9a56@+>1#;tYW+D@Fd1*7|N=4#-&zO(*lgs*YGvW-GzjccgI!f+dUZA z{Sr5T&l$PWh-+%3V5&-Dhrk63I4Az?1o?J$p5-xH1tjX>=w%3yGLAKh&GLwIr$43x zE*Q+S<{kpas>t9`V}j_sUM6hgPGzHgN#aN=A5ar9qgJL)wHK**1;ZsG2Ura%SYkOl zV*qE#s${79m`l%uGs6yIw^`@qW4Mlm*Vpk$!8%=V)R*2f-cf;7%i-(KWLce9fEx7s zO%yl0Zk!d@W9afxbi%ey9XC=;be+E%0F@Rk^%8Dn`Y94qqz_JQ{FCoc%mvAY9$APT z0#A73olW_mN&Bl}m7;3*PPEIq)E z;iMiuC&$|rbN%QUX)PPet}FQ}_q&A4FV41NcGZ;ez{+McZiPrhJcijIPbW?p+w*?M zfsH_AADrUdkkCR~-oDRi0fQ(a2gtljLD?g-fW!bcPo4-u*)fKCAUoQDDoZ}vVJzEa zmb1_!NqI0}N|FMpRcIONr4m1m-393@ZIA#G-_VB&to%!su|;I2wLyHzZ(tb=y6l=M z-z10gARO1cQ}Q=bo72=RN$PJ;LmMaK*jc=yb$XdXiPh5224Hv3xaQ}5ti1MQzk7B{ zAIVWV7F}N_B?VXK{Zc|ckuPXO)z4l?grz``4*OP(KN^5@-^?m9X=Jcv;BzPwY`pg)k`}F=hREkZ;5eqSeZ3rgFI_iw-|+)Us^QSbFdVm} zuo=s~>+OSaW;22x`!d4~E77y-{xudbB1ZT!8qPt*4AYHFkX^^(8TBzL-ne@sZHQ+9 zMvwt2QYfdjZBPsD&8NJBc%$D(SPhvw(_`Jra=3}sW{(k6TY;&p724kYmc}^89V)x`)i)iHFqt#~13s63f8f0Jm8u zhux`TxAn{ev_dv>;|x$mVE7g}c-#ITm_&Q3E9z?l zJ=oWGZeT82S3AQ0X52h3Hf$yz>@+9+k~aR2Bi>qb@tw)2Z>Ur+WN{{|{i9GFQ2~9_ zlBWk1Tfm&tC4&3zRD0#Tu5;SiB+f_-qtPz`^;upNnFlE%jzihPhL$72* z^NQhB#3`Cn^WnKgqIGUfqJJfd;tQIOVFoH>vHY*3-gyevDwZAJ%%};ipab3n(c#-P z+{Zb9njfdo=;u^aTqEO&4*cloI{jJ7kX^;D^a#oXN=j>RCz$X#R+*S+@yV>f#LMA#}J zTl!FI`^W%#;tcAa0D(O&OeY4|la;3n|MsEbn?T)($!TwhU!mN8=Ls_t>Oanb!Qb$| zpJ-a+Ui6oK?@?8rIE?&hi&WW)&T&c2S;akz=_7_m3y%VIRnJE4$(FZGeP$*X_ zlyv~3;fJl|N$lp0mN!Uh?$&5xbSpa%5R~Yn2Yk0F`v`3k93U(@A_>z0XYO_|)is`{ zeRX=DJG>J=%VGK%{PGs!etkRTYE1RtVdOfv5wlHP5biO=m}*a(QX|C32!8ZjQ>ey6 zfOKA}1mED8pvyQ?%Y3UOF6S{tK{XhAA(iR7G@wJgY4@9dK%!lZ$-%Y$Tz>s(07)gJVP|R`(UzEszgx1h zPbg%rX~9uDwROfb6jEbtkHN9$u_J9lC7f^@aN7_naX^}T+xy}fvxPu-Xgwx{RZ=I> zipr|)V!hRgtvnN~{3&}wEglAJGp+a)1f*GyQzO(uI}#4%yE_6efw2C;q>^-*Xlu3v|Ut}7`glcp0!{~y^%Xq>ipV>(36-0KRO{t zL3Gm!AM6Akj?6AzpJA9zf|zrIe}GRAg`nld;8ANj1h}vcJTntarcY)D3XwV}OlYYF z)X*jSy(-!?41mF%hX@}%g0e;|^pRK;wo&5(IShqC^2HdNERx0zXi^Q7G92lPVO$P< zIj*rTejBsMd2FquW_vcXK@8@D^r?f08qw^U@>bWJkIHwx7^(ogzNm{2AN&I{sG0>> z1cU3XHh+uO1ik3oYJVX>a4dPGvbx(rH#~Ta5G$^6Ly=lSKx+!>T;em^L-kTbP~780H3MWQ18)%%J?oN_S4mx=}lQ9!4+C+ z?fxNUfb!|E`v>*l8L(`$JZ$Ax5lf$4@TOP8guTNs-cExrk$($@#(c1DH(b3RjOAw% zllxta^IoNxr#Bo!Igj-$ohwUjslC2ozAuNQ{6UHC-pJCYvXY;Fh1bMxb^_l|^uT8jh1yBI_Y_o>9~W zj@92G-_#NGiSQahXx+3I({88?`r@$b$f~25COp=2WE;;%H^QhLiKz>!pbmL<_!9nZ z%VO<^i7G|Hs2{zc3EOecQR;NExsYfhfvZ0I?g`ysJwBUrHo8!X6qpdD)9cJ5`?x1N z3D`RO;HjvTw61KeLG;uU)e1O;{bUrS+x(sdM5TJaN8M*xd(n?@6=62eY`Rz_U4R0d zF5uVv&YVby(fLZ`(n$@h_eSRR%O@q&izM6()UC%+0b%7)neSMv&5U*pT4j*OK+-s< zv!{v&!eOCURO1j`&PZhrik{L+$9aziPgmo||j-02G#RR^Cox$brA+bPi zotY2qYe}CEwo$;c2Nwi1??;r%uqz;dh))dq4MLeJ27}kds8$mPbsmf)7m5R`#g&k7AROLIOhMT?pM|wS7F0BP(%uw_Vg4aX8I`5o*5w#6= zd^Q{NWA>?Rd`DTl$0GwE{yx#aST?Wag9fDI`~QU51uQKH?*8@E;Ad&xx`w&)SojxL;afI-r9jBc40c{EjR3~aBGkihVC7@i>A5o+UZtiI4e9GVB z4k<822J7+K8*vG7ZGx#~bY^Qgt^N^Pwt6}8=*HBYTqtN0;QF69JAVK_h%+lIB;#=)0}(O@`{Bn-Tk#m z-3wBMlBN*MXtVH@YIq@iO~#yK><(x+g_?HZZ0Zz&fb5WD@^@JM2Hs*?S9>9D_!m85 ziAUsOM5;&6fdk@}@xM`jqH?M;WfT4zQl}*DSaGNh$1kWpafCaAGtBF;ZbDaU7T1v4 zyCSel^KB1rSEt`^(ycGagUc!pJL7ha%4>;i9Wg{TQu*K4Fjp|uunr;RMw%gjj>uR5&e z43Lp@%LzN^A~vi{9=?il8qP6mM!dfX)vq~DE(l@1{0TlH>$n@P!G_D!Wl)^Kj~O;o zG{0t7eNuCLuX!%Y)|Gx4x;jHmXJw=rEotVf zNew?1ir`+@?Ya{H_{gg4a_Hl5`8*k|2 zpaDhPcE=su+D>I~M)D3R7+uw=L&I}7Mjs{M-H|1&AMkdos3&{~(*?o0%Ilkz6c=^zsoS`IMck^kZi8_Zd?%1&?Yq4}Sa++VN2EMKY z<26#$h=)2|%|Eo9#hI1B>P_-i@VHao`QUnc%=(_E2W{SdP+gHL??QLpH$=Rbs0-S) zX%%V75*wPNO^|jXX4C4x{%AZvhQ|Ag3Y*1aH+&}M!u0au~XYe=33nygd|9L?AD*Z`y0g~ z2Cqh@)Nqt(<+-{5lewwOIU?&kvcl-D-}AE|_&e~OPouJ}w*0(25Sn&{QYF62Hr`Qd z-X1*}R70A`|0<4DXbR=XaPrKMWXfz5#`_40n9`?6nu5VEnIfh&H@w-$z~q7DbcJo+ zwK)ywecpy#}giyIGHyu=w%}_Q>pE zG8mR7_{ohp5$+?y2?f2~|1H^JFEGz0BCazElR|30=L~vLx(7RCe@LhKJl-n;OB@mo zeJttHNQI!F^1PyDn$39D;m(8pAPE65lBU>jpxuHks+{TOYy0OYhm9!Po#~oBBlp3b zIZ2+_2ha4me~P-!s2N+WS+zxEIj5*EM+24dnWB>nOtmWl<5JWlcHJ-S3fVAa2}b7B zL*PA_Nz`7QCW`OBgg`#x_akNMM=fgk!%&|k>pOuP#_Sie8y%95g0dCJ-EZBOs;bbF zhI#^ZBcJ$;%81!GV2L-PblVB6Dp=HXQ1Va;6V-%qBb`HLAHG;y*N)F*;+^(Roc5MT z96h@jj0j>-P_BloKH}&NKCzb(*I>(C2Wtv;tEU!vkbQ*qI=n%q(3F>>>iY%77#4H` zMeT%#YXh|-MB#+%9x5&`6yU;qGgNtaE}Hpj^E_VMuM^qo!{B#P5B6dxY`Z%9-r<7P z$LK=qlw9|3DtikAGir=94@`^+oXZ0!4$juULZ37 z{n?!SRUW|23eUBN&|^P*Bod3KABVLXZsNLqr@S(+qplai`Pwr_$XyA~!g!TvB_LIx zo*6p(K!}tNq6*c}h$Z=&HlN1`30sMM28DuRt3PBQq19wI+5ujS2if(6!*=MhgPll( ze;DBh&c+uyr)4ckrH}mm1z+Y1B7B16iNypE(N1cQWgWAyuWoYit^=v&!Y=Ug*j7R* zSK{*tR8IN{3GRQ_mCf{7SP#Y!xSmW`?(#onPhH%9u8X-$FP{m`q3V2FP`F?Z?%H#U zPAE~pD2~T1_<~0*&C#b!nI)NZZOMQFsY3mU`|J-F>WJz7)ria65uuv0VJ|Cq52b~W zRHF^guwOmc{@-4Jo+CjHsh8UOt($L@9bi?-Yy1`lrwsahDSq#}EWI#EG=hDFLakUM zZxKruOe+BRiqq+x*uKd?)u8hEKt1WS?aa06m&s2#P(IHaq#kI^CM?(v&tWCmK*-VL z(um%uL1$SFy7-fuQm|kUMMyM6IO4C~RjLzIb-#m(%OC!c-V$;QqbG_%?-orP!Ux27 zK{AluWNb89OaF$`w9Kg`#;k7jX|vitn+LDjRGLBIKWU@EvJ+$c{8_CQ20#86a&Rz~ zQ~09Ve_=DSyw;$6pLQCSk9{>CFvo!f2#F-=1Lzzs*be7(qn}~}ituy=URUID3L*9wI`^5rlG3Xb-xf0c*L>b!`4e061_A%=MsYY1(60SrN=wM=hmY> z1RJ#zu8aNPV&C{911Hh;jKFo9cJW@*0zxV+82Z)7MqDhWf_dN@2${{ zEPe=A$Kt%=Jh#4^Zz!%5BXa^%h&o1twI)`6S-WhLc;Nu|CIyM8^y0MIP`SFW3cQf| zgaVxp9W%GFGc;zw{l4M(v=fgkskg-Jou~ury z$3JY+qBwS=;$PUd_l4N>aPqXP`=jmqDmH&;G$L-34%+ylTG7YlLoP zzVb@mmQOPWD3kTrtjBWc^~7%fL)?>oSNDcgx854mBy%ei&P+(%?k!|QnSu_-h=RuQ z>L%GJc>Zc1PfEf>0hJ1RbZ%m9cvhxqOSr^sE?5O5Y`pXh)GGcbD^(V>)U?vu^^zPu zBjpn#RetaDhFIy+IP0+fjZP}||3asPFbZCaDIU$`BfTx`B{I)n|yFi+l*&%hs-CxMwK0Eysr)Vq;7Desv4hF zr^jF^r`|Ge--ySMLS>@Re+NS_mmcIZ>dQ zw4@WxYymHNL^QMEC(9rSR-vfv0zpi($xw3c5$~%GH04&(!`N~k>`V@1q>!bFWdR$O zjqJ{bhpY%`>VT_-=#9|4P8GI4i)CiCE2Wx^DV_J!#VeVnizm`AD2S@QjXnQK`Wsx0 z6;F(O%G(OTzn0f!l>{-bFf{!AWJRP3O&%VL@cp%QFym75)AMY0?^?RgY#n zxgIWJJV=)9;@)wvE$Q-nKuIK!l8HMOh+Xx!|(W0xuJG`(R86%_oc z9u~Hk#-o^kvqm{k148|Gy)lc<{==L7SXFQ42Xo^=Q6^%i>_kNW$f2}cpox7z|r`^-g_{;Ghz(vI>NiDLsX^3 z?O>MX(ZhM}>U!SPpG&-`Vb=XQK$+?-j11;k^q{*el!asMzdppRnMw9dr69^JE=5WuHUq~~tgv?MvV-+f+ zD31T-?GsA6ut1SMb*uQPRo8w;8ALL_bGuUlYpKDLE3L#KH=&gyWy@}+(a}_$cs507 zXs?q$h_BXgPhr9;t

Rh_Ur|5z(u7J+6o#YAG+~)h8c>7Y=PVrVP8_0GU>Li{FJJ z>Eio7z(}J7D3kV{c@TMjVfXj2(6p2`tQBUmfeg=)1r-7rfLUAso_>(!#W2~JD$>cW zyRdYboRp==%?fnl*!i%Zs~E4z4eq@OT6eU*GvCZ-tmgo$ktVVcvB+j@d9~a$tlS@2 zdFdgT@7I0rGlgnaD%5O}yU_B35hw=@g zb1deyV3hc4JUQEIzWd)vk9*FZ8oU;?(Am_?63{!d!fra~osm}B`NKQ8EPdghx9=~8 zggC;RhvPYeYbMsd$@8M=AdW-R5jrG)f&P~Smk(dx5;Rdom+*_vELrvb_2ufC!CD!u zE9M4{VB3Z>ABqfRxV?*{{zyb;pZEJJ#z@BN!Qh%Ln^`!AJvr^$eg&Q1A4# zX-a_rOG{81S8S0(hEphghSQYYSkk9|;@tNp)B>-zC%7b)ve`Hb1QJPD>ZqA;}r3Wk=)B+<7@B$(1H6{-ILcB3vr?X+A{FAA=^ zPeq3ozp!&66mPCM<=xc8#wp8G(F*=kB)kMwF;2ykr*=Xv3tO+ft;9liAIMVsSLf#o zC3A!!id)XKb+xViRbcKyt_+ReHM5lpP9!$$Z@_P}RyRGY4AE=~6IITjR~&QAgNTQD z&v$>xg}KU6;U=GwsKfLil||*31F$c*-)~P{0BA- z(?JA4Jr1okMS2zoS&8y)xFD^%PEVgA#U?BxXP%Wy&BFU`!6VYp>6Eotj%)6tUYt5p zoC(uldf8NlLe0|tb!H1nh*|il_PDx-9eqdDunllJNZJuP{S)GwWZSZIkv`J9`Q1L^ z98gj%c1M<(%@T~isUZIf%_sBSOv(k(3ecr_qFxGBARIA2He*{o9F4wnN+@df4zhanT2HI z22K4lo{S@u(Wn&D*>{LJn0B{Zc4&r3TN2N}^APQ;H@bSbv?B0^qa&cxBW-j}?>`{X zorJIpx!xS-e#=eRJF7*?h$rB6Z`D{t zndQk~yrNo+j?||KRq_4CR9B`MPPQGFdn%;7rSG!$7+a{(eBv4bGY$f#E_CN3=H%PU z8!O{oCa`Gehq+D=hd_;<)TzyF~kKM~v{J+$&gAEKr z{xGsZ0ngQ#(D22AU#t+Q8z?mjyo}u<@glJTORI6lh^>Xue}#}jD-efS}M)j6~C5p+YzpiMWPKkP>K$j&M9#~4tivofko;D zBNHW4Od0tjQFROw8p9=%e6n!qiy<$M)GcOK4q`6?lo9S=6V7GZ>Dk1T)_iM=NuAI3 z;sk;oX5fOS(Q{w)d*Mn0qmIIa-~IgFMgxQlTZqCCTmEILT9!7iOai`zW?;Sn^*@C* zdYqIGV?6)#mHsy~=>k^QG^R$n-wDj~%xXGtu~$FI@uA%>hmTD}O`AQEzI?+2QY9EZ zR+@JdnHXzc2MDDr;Z4E8Kzv@$xh}6%e-XAc_6#ifL%r`a(0K1v^eGl=qCT9xqcHC6 zNe%rPU!M!d3nQHhaj>H6tlRNvC0$pJBf%Bpa+%yG=k31g7gtnl=@$^WZ+f@?8xM0_ z3f{c9%tOY*6I~N1vBcRw?sbxwpDTi;_(A33VDjWE;HwL-`$L*l19EajXTs*&o|w~H zC@0O&NCBB6AMplyTp8D-toyK!f?{HjcR?zm@~CO7+b6~`n0TxioAaZ@0M0&j-DI6V zgTI|Pen?(OwolJg4jRnVWS8xsJXc(JNHl*qx^2Gl_q{x(DPK}sO8wfpjubd8!+u^y~B?W;IqRv z{R$MjqVvDi5EQ%NdoI)`#Vb!GhKP4kI^#M^>S}6oZ2cQJG&l;=;eCazr57*N@o;6atvv&OYJ@dG$`{v228Xl>u+-_PeAQiCH3GnV{+M2yO1# zIx5v#OdP-P7zvQjhTJaGTU4BIXMox>WD8>OUWo^T6DhgJ7Xdb(M`I5bxZbe%pLr#3 z0b;`MhtK$xE!%vw*ZUCs?wuaH?n`{S#2sOK$cw6daRvyql~YE1>ZY$@a%JcvA4$Lm zIUs68ggCU~PZ=o@gumaAVs^k!~A}N-AH`N~`=(c&`S?|g% z^dT)TC}?o+R;F)CYYWtz{awLo1|GpQGW{WK&GeZD*T8v`yk;lmZ9vXQWWTMHJPgGqYz3AL{{f#Pc)aO1)ig+Qx`3CS z!Fg|c-a?ORX)3cB8-v5-&zR-JROW5Qz~wNp;glR3A)9Y94`@DM&9|%*Vn+H|!_fBo zt3G#8KuWftvfvlX$nRiVvd41T>__tMVf_2dRIwRrp9`ypdw19C(fe1CZh1H*B^*AG z{{6;iQ+c|Mfu@9RZO8=b)ru7PzCGE|2W_)R28Qb+vAVdXrnJxcwCd4QF%D7!FOlLoYe})1WaS91wm;Vi>7xG_ zAbX`*_4c}QRIoruQ{TaKy^>|@?0+unrt9|04xROcc;Q|AOgOAwk2wv;q>N+Vzh~9o zSnJI=VB7&kXB;22RM2UCij=1tg3C)?+4DQ5C^1R+(L1cv zxG}Kq?lbe~-PJ7aJt$y-?W&r5MdhpF?tSdVRy&4>TD74fX!Qcv3AxT<#V$3-E`E(9 z0Kq^6BkKIm4!b!o)ZHS6KlL(I^oa?*kC;wJgtD;q$DYJSH#aE3`%AAO)#UQx4~-pf zY@1UnG#XvCW*@fdWm=D6a`yZ?mv>vMebU1Oxryw(#V+2!CG<~!$U!0N*gI@Ds9|I; zd|jLSSl!!Xen5bj1oy4PD^L*QXyW~a6T$*9rzC8{ytnEi!HUL51AU0%G zn%fNHIw5C~j4Gp{l)HvKSUuaVV_Txp(`VlHA%shb+4s1%o^z|!GOu8e&vv;XYLRes zKJq|qb_BX&X=a^6XoHcAj0Rgop-_-XLiF=7p^@qvkG6fp)tktyKKL|dCtnh$sKu|J z;Cg|m>#1YVLF-Gf0Rbnl3Y#Q8>N7AwisW=n)!Tz6W0wcjk5$7QMXBCYV6Ds!9?L< zB#*I>=Dy0|2(FJFeY+eDMX9P=&f_tNQkX^Skk<2p^SD>;Ih_X5)UXdO>1QHRfW9~y0SKpS3$d+-C~Gg-#19+gYV006ET_JiVPvE^ z3x7Oeck2)y)`d2Eq`JMLp^#b(Pai#(Mq4n*&>a_I{QJ{+c)~k}p(7$lyhDKQmf(8Z zs-mkrJaq3|mev5f@xzho2C5I;DRLBIR}1bU}b?d3>)(-x)rvsZq;!mi>u&@tX!4%A+bv0 z@TTR7m{wnq=dX`To{_AA*Am1~1UkG11gl)gW2pLyxaL6$^|^)SSTq|P zcQnAJP<7j1w7p>$>0&$BeB!XloZ8Aon}P4wilU z@dj4OE@!j&SzGwwBhF_aF(VENCf3(Nj^nwxb=kU}O~$O8z*)~C5HPLhVlyT82&!yA zhQIrwc;)CW@;BRWaqQ2`tSq!VvqM+T*A;;~X!lnLCvKpkta0#J@%r;F`HRrml5kI! zZ834PhX9XIZ$%|vq_xhcL|A9NEF8&AmbO2 zd;5_~(AzV=|3iuY)TZx&20Bg`SHd2X+I3W(%$kEHcBrdB^LksV8Q?j1NmcMSL^Q>g z=X`ncIBV8zRbW{6t#}V7mRXc;b{x{ zk5xm~98FPUvnV1PU<4mwXA>zNM;B6jG|?118O!W(lL!{hcg|b}g>I@nUD7Aa77Zw+ z%;aLsX3J+{>r+H7f`t4V0+z&{XzoI65#1XcJW4}gvi9c(kww;KX)}I>@4Sx${mNKU zwM8&!`U;olW9;7OoTQhoJq-QL)Xjk;B3wE`8R@j~3|ON-{>%1+Zi-}qSf{-S@BUI^ zr9{YkRA=DPwXr2k&l>d3jL=p~x8Y@v$>$ze?Q|&5#8ORO$anGn;N}5}qCJBy`!x69 zfX}&K#oa-3&?ws@-@;V3Ft-6&Iy}uiM1NezF|Dwm5tJ{GtXM0qE-1z|+dtehZRG)# zpR|%smAO|7?GscYo#)~QT?B$;5nPGzj700hXbp`>8%`m;C%SQ8`<|b_Ad&}lA{4YV zqdQ$R!UJ3gzzL|hfx^^;F$KPOrka65i|MC|o&(aUKs`zP%ThVcbnAVO!OsS|)R#j> z2c=xM(W96$T8J@J%uwk@(h4KJ_aCEMOIZ0s7CYkn!K>~Xw~&kZ&*sb9>AI&6-a;q% z3XtY`CnBUkaVkWBhb1BY>65rbtx@wLq*J|C`TZhmQ{!1@q^go3S_UE4YRN9%)rT}DJH8Hn;7rjZr zb(_9`>q-CGoksjXH2V8&AK|Z}A=wn98%EizUeW2tvI8lsdrT;u73hKlg{ON9_qIZ6 z9pAW4L@V}JEP(9&jiL9FPt}PV&%A8at(ihqol*LbZ7s?M#YYQeqItwu@sA^C)t3V5 zz|d6&TV{syqZDq}D`kS*7wy8Jv7+alvUc#&4R(h<8-d%@f`LGO#L~G>v-A0+2$U29 z*>Lo4zx;!bs=6+?Dd?+{O72xX)i8RH8PWIox!t+2KCyXil- z$5G!p_AI}5%ETMEVvOszRruQ<3(`~X;`xU}9I5@biHdJb<~(|4YRN5);nV(pv8_?q z!{IB+^=+Y}rs_=k+#@j-i4ce(tA>DNHJNk}H!Mf2U@}MvJs)yEnMpAZeXSx0)%})> z6deuXoEqo%_fe0EjPzT4=nfQbM>4ZXo0uAIq@5M-n3N5Y=X8yXgPVh% zAW4Jn{>75hwtR5$SSpM8m8&2{I+be@a4Isc+ifK8a2cnrIige9gF=*&9nRM@=_9{wwHj{% zG(UT@N_wSc<;>^CX7=Y>q|}`5&@iWR!Dm#5s+1>#Ozf)8mZ=xTbN7U&i067yx*w@+ z+ubhqbW$ADOt*hVz;1ZP@~DUuzUxyMJc`n3b74?oGwN%#QZA%#3P~aN`a!pN>p;m9 zw;g%mA5^K!ezZsV&GA4r275(I{MVbjadM*LYwitVUJ_KZGkw2sKjF9g zFY_G@1Nq+AK7*V|wX7&cZ>lR?2#O}=nJJD&Ll3(l1Y&+29fU_#eY}xuFE@TwOrBXn z-=DEp#8Hb!i4p3)(H05SNtSldaKjv3!jO zUvat)Gm*yZ2LsnLs!(pJ2Zu#v6O_sBC=6_F^bWnxyQ8cY(;$yF~i;7d>5yu zgZSRDwCjMC&COoJvlOm|ym4y2?c&oUu2$12R~&&Db2Cw*rmDSO@|PHlK$!e}I&=|f z?=v}JPav0YcPqXowZc#Ctr32c+niOr%D)p^78i^!m|Woi;e~QM+1oy2~~$=n93+>?-LewbuuyPfcq6 z>er>EnE>sJ&K%;BR*U!~bmgIk0=e1*EArqc0(%ld;8VHC3*@y-(nMmKdLe}b8mTsl zASl&R07_Xgr7~lVqQni%h7E{pp;cqap5cb9`{h9EnnhvBY(jJDHI4gqr;O~z>w`OZoyfR)rQ+VxJ9a|c7USI* zd)4zxzkyKM$?q)F+s>5hi}CvjgmgR02e$6G>jGoPRg7-A{z~^NulmgKkH`9SmYL1* zrI}&wEA&6z)K|-|Ds%$ci|%uzF^jR38Q2Pnx_*6W#^9zzPUH4r?e_xrrDeZHFYpix zb~VJl#>h5;V4xRMo>s;^KKd=o>@A69M1 zm(bMxMvQUK$qyZWwt7cW3;DfwgOTgW`*UwEtlfUY-M}!x+Pm*^3dIS{ey-#NkdjK( z)3Na4+6ya`fPeISm}&<<+lVrMPO|4<>Qd)quBE(kT9o_I1HD>jIM-SjT|C(r?OkM| zb~g(~nrIf%D4rGB4<%*hnHShFl_C_oKIB~Q5cR{$+3d~qjNr=|!@-q4&n6rIyW{sg z(F&GRw)=fZ9LOrj8+h38a6X19ZsDALcw0>w8EGv*4fV%4r|(ZlSw?@CaNkw$nKLI4co-w!GA8d4(#A zqeqFATjWP~A@cg}t-cH2+3{eWOnumB4DjZ}v^!S$A)OC&p6I_dv)||)=eeCW+pTXkDJKk^Tm^5Xg?a8xe%%q^9TL457QXAR?RdyKd6-KEh_Mv0pN?Z(wJQ;~+>g71 z{Fs~Dg3W}Zy6PZVQnZDAp=v#?Z)&N z554d9d6V9H1>ak<#BlK3#!r#V7uUNue!3y=a`^~Ze8|FuL z&E?FoL%%tCZU64r)4=z?|c1Sv1tJI>&w$#x^* zy$p%YD*eWWqWcW_LL<$I$yM7Ds$-tw5$r3e7R#C9V>G+m*u)GgYImwJE_FKlYMiUL z({nb%o~HD{W((P0%9EUqkNU%Xz}k!Vf3i%>u4C@6>uCZ%$GwHpiK6|m;$3>)qGDwF z_6&Gb-)us_{2B-_dbZEDou|)o$6fNfPx)iIxz(-Z4sRy%aWaz5zkl`2?|t9kh_n3` zar353{XkV0N zLH8ZI|Fb^zYiek3c9`|oMUrxVyLtTPESn&2&T> zj!to@0fxNSO3GZBce4Ty4%DvpJLW9@blBjSWE=9}mH4sAHrykBMa)Zq<#FSr8K5zm%H*nikma?9})^N%@r!oa#> z9ylpZ+N^Z2+#G$q(KjS)dfR2Ic$sN_c){rRd7fBRZuLVtA@2xL%kLDDk?!?j?as|i zr|X`wH!78b5q&L0-`x^(+TRB~JPm0J4cGmaBGiC#wb#0DA*1pqOEF|m4K1-h&<30z zpHgzR>85sucXWLR0QF5y#)a>8BBzX^;%wPbUr?4f z6hW{aw4+>2-b>Pd9Z1~Nj+n0oP7agrT>Xj>xu5z_zO2E<@9F`^Sh*aIAi1z7KQWv!6?Kd25K$b`db^51cfp*0OCs+;{Q#Vl&oeLCRuL_6UB#n)qhxp*m$d`{$jVlI zh@)?M?7FPjH?E*TwyaFA)vK2vw5)n({2eVZZ;&c8(Zv;5JuJ>DsW!`-DuXxBG)$5ibJ#S1HxUb}l@#a|-Z(Dy;c-`B zg76AdyrIbgBdnl(W_*<+ep1%k-qr|3S%$P^-?eQ7}F5T7d!^YXiyXk{HPz zJYe5AnN(QFCn|s+57a`J0WDt3_mA5Wyl^}ykA{! zb3xJARc=e3CH=&k{I-4HF{3q+>4}i4q^VP@4;P_Rp&hqev}qaO=g#~a6`sssuq9t$_5h|T1-sj;5Z-t#pND^#k$1rA!ZKl5v`$ZtB#S<4v!XL_vT8TqoblVPVe8DPy|_{T_tI=MakB6hH+E~%vRwSw4|dx> zZEuR&NP|7;DSbTZv|Zy(n)s+@u4pCmJb_LNa)uNRE?&})wX7yNV~v~XLkD4GCK-@b zm@nvMFGApk-u~SDs)F^|!a2ddul*}_Io6GRVcQ(7t?P!NO0D(~gvo?O zkdfiNIah3J&hbSZqYf%K>V12bOT%w`v!Hes$)N||zW}TY0lv=icolAr&O@Mlvfs)C z&P4U+=Kk|EHLKCnz;JhVS4M_3787xF;Uv=aU{@=pGedn`-#IV#&ip$i#u%UXbM)`= zv`*O*2YVK?csWsgd@Py*_HW_q7GXUD%{=G|u+dNZGTf09qu}(+S=#5;fxg^kd}$gr zX76)L-7*ijby;LT)W1nlfP%|gfmSIWYmO+-p9hJ#FPcmJ%9Q?;cARUeu0OIj`{I1y zC|QEm<_BxsoqBoz*#~ZtL}X=e;Z`*!yLqEE!CZE^Q35EYs;O znC6<#QVkL1o}skwBCgiceW4%RP32fnn>QF^h^pF|HEH)en!*LUikI)!6U7Kv8TbA? zPFY?_5dR~mG2h>jjbMlIj;P(pHz6ivZKARn@n`wDiKkM^?S+aVf`$3oPBlBn3j>cG zR^8%9+AM!Ke4NIsgRwIa;Yb|*Vt`d>Wjg+1W7e0rwxX92{+uA@1D4M^CD{tYJ^`hE zXjV1jx(Rl}jd`)t%OIOurWSn)0ShvXWBQfZs}SM6El08&mw1OoWt&$IpN0e+EfOkm zLyye~BuN&E%|h(UCyewS2uA)j?S!eZFp}KVKYF1kDx|i~`DO}<^ihb?e`NlP^oKs0o zg}S)bng1;xMF99$jV8mxUkaOHw&AArOacEcjY@P{_7z^v=2~bzS0f=dTIpJ*#oHYugNt3I%{uG!f z8?U+$|90SH&~<(!hwf+;hp9;DAQZ+q!IjzTh9Nttq{Q5IZz*1jYEdyBxYV6^HxclW z;IC{w#qm`>{Azc2oH*Ez_FDmXR_y}V_H(IqcSx-Eg}&>5u=W-}akSmKXbA4^4uk6; z!JPnuySo$I9fG^N6C^-z2@rz2Yw+Oi?sg{m{(s-S_uco@tvaV>rmBl>x?k(}S@Nv4 zx)<|Yi8G}iroHdSxM1sFU(e1v`Iul&cF?Fsn%}DDF`MrYPW2Z@cvy;qFdwpSPu{i% zoOL|zmxVTGbKh41Kw)zIo?z<(57_$PB-_sD&c>cRw!JCCywP1tzS?reBPb9FQ7&{e z93!zMbLZsW_wu|S`}7d&2aDSJ^iW8ESva9T9InbF_sZSP6ReV^*L8nRa9YWmxpu$@ zA3su+qLE4A9gXXeFmMuN#s(=%ef1>uhQ8dxsuaRDtU zf+3mr!CARFs$)qL`q+S<`OFInzm?d7EvVj)S(B{Dv5MR@u^Yw8yoa-5Z!s>vhQu`! z0SDr^?vsy2&>t7sFv1q{SGI~9Z<)6d0e+e?Y9ZRuPY7~8b{H{ex# z{NO0_ZCMJ6hl5c{O|;9nSA<7qpnGT9H1*}5LS5=LQBQ&o3Wn-cuKB^#cne^3*p?*22df_mgzoB@OJ z2Okq%$(B+v4*90{^{;@>0H-(1IY2BO#AS&Dkl=qbUU=*j}d?fpn{~x&PhGxU2A4I!r3zZD*x9OQuZE?&MfY zl`?ttcj%)Z^iM9l*fq)Nu>5E{v-?fJmk!h~ZB_<2pE7@BMOsN{lhBbTP6O546cvpC z_g=uzAGQmqh0L>GzPOg|1F^^Ay9}osvN!s4^~8HlU+!x0j!pKtmVoIZS32-*2I1BH zlRw(LYguG5gBCbo$Bs~0T||cr`DSIhitx-!Q0P(`)?`gx(N|ma0pocr7EVa@$ZRJc zM9UG+=kaf=n*dS|oWz>^T6H3b8*vB+3+782{WxFlF<4^xk=4*GA=ndKLtJctJ3d<} z%YtLI%rfuqM#*BkK(g}4vlU|6RP8O%{mA{kDVbYXy8B{f1manRDbpgbmb%lC_TP#3 zJVkU#U|)q}8K{V{+0at~AcE3pD@GIF?Xfd5y*+^D4uz^Ug?9zpM03y_O$9AQ&{b=| zoz$a)8R2p7w31DaO88fSp#mur(hSk+J2V*xxJ2vWGCfFI5W+5rzFtOrWGx`#P|kQ5 zFFe(oj`91{ZSoBwD3|0wHk~blF_ljL61;po3!)9ff8T|G?~*{Flcd17xV2=GGb5`- zl@nnfh0urx9Tli~GK4}(6?+pE zF1qjqD|1zz$W1|I*0^gGDNu@O-ej!RrNB}E8 zB#pj*K+g_Am_oJn<$e~6Ur-cwafHQ=!Zto4(zFN*Zxd+V18^Er>Dr3H8Ve#X-{>EU zaRlo80uN4NcQ)!!<=0&ApcAD_c~FuzU;3P@_i!n}DdY7gv=Bm{p%ZpWIeqNbmN$9>IK!6+23A5iCg~lA#Z*aWRIG ziwC7gTjX>`d?ynNRy0w*U3QTKD^UHMz~ffNj2!5OikdtATW)he4os4OOtrGA7|zE4 zo4UOlv=Dg4Zvl#J7vYIOup_X70Pf_pF1sQ@GbrHs0whas>eW&>iQJoo#3~p83W$bT z!0<4Ca!@N`)g~iUL4z5@^P1@ayZd}ZzJp@(G2L>QkjYo6$Jjwmo}`+1lnCQ7yl(x}_o((jcH zAJjv==!lGqP1GU_GSoBQ<|B_TQTX|6TsZEYxx8?K_Zu%zzq7C*Xdxq|G79+du3zmS zC;P}2IkJ5EI%(T?=LfHp7g^Ik*fBYO6ucAv)DU;592(-t%U)9&s}v>p_9eDcp>GU+ z=}ldlb;(ztzLa{9*#4rZRUGSmj;eY{(`l`^MYZuP}*QMSHSzsh7+h0-AohS)AAX%%bg zoE=!d30P&Kv9lMu-~maD0iFrmXdFI^H(P`);A&xlNEf6NY4O^*QFsg~DkW=>rt^2u z=($`{@XWJBPevLl02E? z8$x$xziNIy4RR61in$N%jY>Pm=P$MK{TkUtcQLq~AAS;ht3V)g(l2h%Yh{Is%(5=1 zvL*Cb-gVuE*a5Un3JgC%W%bDyJrzFX2MNo47OB^!ox2K$a*f_GVx;$RG_MOH5<-V< zmlGMbXjHD)LB9>~Y|U#GrTpU0eXB5;13Jd0*Ajy{0tk6ROT1?}&X8cVrkH|=b%fwQ zVctX!V5I_Hr&kgkd#u*mqBJUatIdlPAr<-P`R5l>Lz!Yt`-#P|G|`JuF36cbe`iDH zoBLHzP>@G_^j88B7$k^L{{cU*B}MbN*~cyNwI^H|qfZULo0C6;pb2e}U65nhj*3p1 zn;P~)7Jh>$H}rGHf;?>P=ejkg1~*KsJ_otQrtEX{SayM3WeE-qygM?;04~IEiMzGk z0@}{?a&5ZOXye+?%2<7R_}xYg=oO1^H?&)Lq#=bfr6f6~DM{P8vWob}#n-ASu^N}W z{x}~BP*D|G=|X|)T{>peGB_i>WQ`5PZ+ikM(gaTpaG^N3UHw%i!KiI44f&nQ_?<>| zXjMn;aahW(>KqnC8fIvB_uSMU$+8I+wYk2ezT779Fo=sq$y@+S}is_Ywv z_Ei?1i#{e*^3>(QUYbAgRWsRcbcBm6gbcycuXm}zF{v;aPtZs}KAA($u>P>O1O zPUG7M4Tg|gr2zQ>{Q(MLJ1+k{A?&at`Op{iKlcKFra>UVyZ>;D{uL+woRF9PPluOg zJm5>=ZODi1Z3Y_mh)MpDlW+6P8PeDW*iB$Y*0H>zVv2l}WE15P{`p6;)BGC{V&tSl z?y~IaMk-HiL?9WJOo4bFu_)VWPZ%bW6%l*ewnDf`o#+Qc^49iuXE-ysf_lF#Y%l+l z_#5Up1D30cg9;9mMn4QTEW@|zNagRGlfaRBdIPKs6aK0IP%WbU*6$O@ulnqdcJ+6I zi%kRyGeowK?$^*+UQ+(e1)wXQMg8h17>UC{Ng-xgezcqr+MU@8q!NDpMJrL*{zen& z-NjlPQwL7BJ&!Z>3u?|vAA!Y=@@bn)bmP@N4uH(@FIh_*=84YnTAQzS9i3YHE1-%; z|5AbqsO@^49JuQ~eH-`QxUAjk)KMlv#YGI0#9~iKPUCcGdAZV-xp+74g9}xNuV(0I zqp=SkueWH@s?TU)W=%>ly6f(5Z%JG9NS2FDaGne70323KEe)xG)m$@T6*E|9Y>B{X zT$A+W(3hGyh6ryjBsZLyy5RtrUhPg7U&34vU3amBR-NNVq9 zKrb)D@U}U<`N4f23;ELfzG8SRSxa(D+^xqPFdf<_n^_dJ-^#b zB5$bREZCx`Sp`k)jA2dGp?mk_E{~#9#CR*QhuAT+-^qkOss?jPyoR(3c90zbA@S?* zj=lDxVvXJ*2T>vdQ)K61_%Ig`T6%}7Hqb2uu_F1ht__X!L~3*HI1aqlVb zdL%1N4i%((-{(+;3^7YRAwBg&(lGV%LD^Zre2mvQYf0?ZE=bbOi?a_ayR!HuLG6si zJP2fuc-I`(r`Y7y&KO1&TM4DCmg*bvlN|I~fKqW1!qG}e+uE9w_ydPvwUPL{)ds*S z|KE+JcFe&Msl1xJOie0%bFhe=td&3OOs&PR=PIz`4V?ynA1d!+@Kto!`tuO^B@JFU zHD`1>yjoUED_W{d##S5&TY|I|xA}bpB12|kS5YSXDaV(AirzL}&-!IYi{HIHhIm8( z|6ut~l_|1K*to@h!)Y+A95~bWkxAEk9TS;SE}uWI-= zsbU9n#*_(*C=f_}OeQ*F!_>9!YwMI5IzY388R1|-v1zb<^)WE39sfkRW>vD|uUBL| z`6wS9`SAp64(V&9#EGjn;J~8*2OIn4Sd&W>3~xV#2Jsd2MQy{sD``~X4_FJ5#U0f`9gr2i^fQSc{v3~v2X{8!9DqMr8;!74 zhO|YLD;jaC#iB>0WG|X5elZFcFT@mGh?bazVD&Wk7_w^kUqp>n+zHi0WNL9oth;0~ zPZcq4NgAa>>djgCg4OXNWh`hsA2kN(6eUI+#mItY1~KmF4}qNhL`Q)(KXW|TVoanz zw+;biL4@sGk#JsoaWud|g##Xtu{}!n+MHI?X?;8sN`jC+P5Yt*_3}^frg9-3O)B)- z9INvO{y5gt6StYHzIN`I-kCrHVt4U^UMpl0M6+9(6$LbK872CzBYf(zf@4^Q()gL1}l&n(C1g z>v`iL(`8$D43Ux!SgJ}j5uhQMwlME0nu$j~vz+y>=t`eBS?|%L&B7IPHGOF}=sHD) zysmRDJt+h@D#Ue-8*8icOn%lxOs}%HTbTlB>@s)2{M?YRsbFsq4a$G619Eg7g$b>O%!a z8S8}(B8XaRXuO%w`9?xNGZK~Pzo=0)z`DwciEgL3>Pa!1#j1oY2{r<7PyusVO4M8` zK$(FzANVO8T4uR?LyD4l=z1KV2{klE6vakXiQ^mP_ry7%Z@H>`N#hmLyZ}~JabOlB zK$(mmp3yDEGzz%a%du=olNxJGm@CS00?PeJ@HB|!)fT3S;BYOC-HsVpM7VJym3M>aQo2d6ITEZjwTIB&MxgO2TYQ* zOJP!QX6F|RU>vf^vN<)z@C}R!yqm#1wpS-;ZR1H zpC~P&)JXY84yNQ^6Awo8Rm8HNuOPz}LMQ9y!egU4y=XqBajEc+NE{=3kF!gfTI-1y zjByW8T|BtxZcP_8;bKk@1%Vp`A@whHy1)n@vs-{CxR5cbaarWNvMbmv!|SeD8)U>Z z1*)7FXzKa(z^+D_wCIjL$u|o4&f56JO5AyZMQTSGM(<-(&?cx5VUP&*!2xACEImW~ z-R~abQXM`6`W}n{_4j4;GG`?mBeeUbN}~eL|HnNzY$xLvrz)fYhAn^zgt$g}GEjkbarW7gD z4x{Ioxau5KK_E`d-&Ue=S`pr^m*!1dviYT|_S9Cx2T4EIA0NoMc#uaJhA_rNN%?ylg z9)4s9_S&4MVI;;MHl%}%%Mmm)++U#vvxs_<8#cTP!}IT=p8C1_B{%jtzDd$(?Eo?k z)P>m-k@htuLM~K89Z?j%h=YMPX1_(cU^SRFVlxAs%wHQ%k{rN=J$;*SgV@#;R>5E< z?i}KX%7*4q|Jl;z?e^BZ4eWrR?2jX5vA_R=LS-x&|97CyE7?NxbfN`t00sDe95%%P z_j7@N9s~XoyZ(cZ;A45|uspaZteM>gr&ouQPE!2g;%JvkbUSMOM>QN&F5<#R+i0FM z7&~pYQvfl*{{Iit*7M`de_`4>S-y2r@kjl5nr-rU$;)|b^O(;da+JdK9KD}|{Ovo& zD3RLYuC;DH}il1wy3nNV2g`xulc`Ekdm-Rtb-H}@D*P?3uv+j!nNn3-99 zd(95^u(`>GN~EuVA{p_e5!h%Zb23B3cRV@3$&!BB{m5t;nV{hwWHUTc9vR<>UE?40 z?Rc>FYjxq4cn9Tq&pR`=fjus(tWS57Fk-aBWG9Z10>9k8+Y6ts*dwlQ;!HL$^cy8vKr8Ibw%4yM8l6LvuOZdRf!Qa3|wl2Ay=K+(RhrTS7#DM|` zU-|e92SKK*&;lF(ED@HD7Gqu4 zeA|1UA+h>6>)VQv3C^^i6DH|~E9HCK8+Aoi0m`n|E^GdVT(Y+>zu>*?I>fz31EcNT z67SelT{TBr)Sk`-g*Qv}jUbQ(v$Mgu#3< zaY1wqbo0rsIrXWheClgM_VVk*$Ce{D@kFZmSqJkiG{5t&IY^%gHVK=!HuQmsuygoN zH_LmAQ&D9)+;H<({)PDmSB3zo95?KrB@c9-*J{TZqM|dQ-4@j2A zh!F0%hCLUWHGkK#ZQK_4x%;X2#89IpD(j;rbI4r4PqWp{z9tp!gdis4M>B)HOhkDT zkK9;r5P`n;@x-&QFW=ItD1sO+vx%1%)g6CR5Q&1$_joIC+?h4bgrWEsYzzqPL-)(o zE!1*;2{-Je!HBuY>dC;(X(N>RTF~p_>SW9G$k149Ey=+=aMbY+VR6$;E+_GH;PO z%(=4|i7ZOzS|_t#po({6SghKR&M;sgIhi?Rx?VQ~5TB`?uX|zsIOPP#zsTaR44?Ob zMEyxcy=U6t{x{w_SQkCE@u0tM=1d4-1Cak9#nPs>m`S{Ug=(2{+d2v$KDnx)#!V~6a0+BD)KFYz zY4at?CP>VfUAEgwq7t(#U+MaD93}?4GHX;-t*E7aAg_^^M5eVPv1%EZ2 zKm=#5*W}7VGtWUwffyT;RH|p3Ujfj8m=O99lbf`|tw- z;9`IS>6TwyWu)CyYMXs;dCfxpFn!VyV+3SX@X6%t-+L$tVLEJ&m7I!3-}+sizwGE|7I_P ziL5&RCq!1NLkEr`D?(u6uT1q(Ei!+Ogl??c@0_%s?dl5?y79*1ncNGtkW5FdDyBG+ z7pAZjoqrhL{2y{$FAhHQCZl63-kEa>oOmS&#f>oI$@a`}U6ot7yWXPVuP~14i|ZRS z?Oj#Y+?bJgJASmN?i=953w;eaO3fKEvDPmTgJp~HsjG85t8-V+;xT*GlTBBQURX+2 zVV$Bp@;KXqav#kcs~K=ptPD^F#{Hly^tt{edEBPHt*eo^G+TYOx|I9AA%FeY-g&0k z_4zUN?);E`M<97gp)Qm7CQv0zBY%3hlMsT&6@$ZX*J!1R(xZ`X>p6g`Li`Y#in1_W zJqu(W@C-LD8nPeOsK4TXl>N_)@Zr*cNz8cfuyms9cU>L&YXHzVIpV5artk7ZB;QGk z1UmH%exvSzKt)Q`u5IqAN-Tz&TxD>Yqr`#Y<0QyeZE0~UA=qlWqCUnv54n}a$Vq-z|+>!pKUmE zOrDccQ)AFz!Rt}HQS-s?H0?2;jQF@EKtg(Wei6;qcr_mSNXZLw{uDRYLwd+$v+_IA z=~Rkdb$<{nCyq`Zb#!~qNGKjFhC^>^GESPaQIIul>7v%UJ%ow-^M~v_7SD z$vWgw6UuaBH{Qd?$I<-`@YtP6{Gq9M8wwX?G&Kas2)OBcHD!GkKtC5o5Wo2Wu7EA>QuyiT9_*@2SDXjr80fWNF@J5B&$Pvl9)b#^n#K zvy$r`?-%s@fd;~6D{1VwXIrSXM{sswe``oYKX1elb)Uh!rfr;WD6Jzuk9$<3HMJG@ z8z{qlFVGZKRoP4%DA&$-zL%7AVB~x$y;9mC!+ATmvtwN8e0zS_tFR8wZ&uhj%=ml_l{DLa(OvA_!sm6X-Dksz0&wZ0=F~9# z^wG2GH}dL-7F$T8K09o{``Y%Cn?x8K@HS8PKe=4@1&=2FjM(j8S}L9*Ml?~;%(W7F zwLO=+9e^{4t7r9H*&kMFAefcfJ85}vA7vYXqgqZWO53S2Z{mbW|XT%0TX zlWNt=9LEQtYum=1wTR+Z6EJHPZ+d;Bfdc#Xw2$MUA+~0z20_Yokw*K(?Hl_Z@JAhz ztIi%J{Vyka2AM(Cv!c_hpH7vrdN-`TqqL(9GcP+jm9?=e*<<&PAHz?W!kR;GMZ8^3@@cDAQT{#ZT7WhU*!u`6dv9vgVRk#U^=ZP8dueIc+|Y$#YJ_=*)FwG?=TFdm2;p^*J@0rOolI(TT=#F35=$))pk<4 zL_$rCaaaZ;Oyg-og4X&LLp?HMHCOz1>OoAR9=?qK7t^vU_5X`$$*1w(39Cl~`ON>D zaA9U|IWTVjZvuVa>fQG)Ty<|=-V7{Ke|}oS)mg<|l+X5%BUU-0l9wKuYG})lvqrm~JF3F~&ytHW)x1v9+K@bQWa;nsfVZu;P0<>hl(F zGjdsAt<#cNF>!SPhw9_Xu{XMKCtxw2&Eq^je_wFJu5YI(Yw!jy_@O?dq~r3k3^RMC zJC-ZX@$TeEE4L}8a$}~W!fr(7*=t$yVS2@2%Xxglvu!rtXKHMeos8qUdP{kk-66iA z?t!tRC9AY4k-@$_itj7wo`!*Eh#hXt5s%L=^BZJ$r;!AM`XMx_(!;VAC@3L z%dMy=)LD<@UGC+n01V#v^lgZ<4{;U21@~&*GUdI|e&@3qZ)vwR5Zlu@_2Wt<)VmOm zKuUVpNba-!oMn=y?8IPNEhpET-nv&Ug8xRpg55fA315@t0YdJm}CW9qG7de?B=2dx(3xL6gKV4AYjX zY>rZ}X$c+v8rJ+a)KfxzzcuOD06)<>YtwquQ_*40>?v?|_0v5QWHfa52%*d%hw~8%iUVpWp=VTDTN2vhxOkmBu`-edyx?m3PP*j8p7z@zbmzJM^3n5vd>(g%P1JiawHsxzb2$wHf7c^h=ZDWnSZqzPV$NnDw6E>>83 z@Xltv#lBt9s4RG{8C>3V*b1E45~%s{-M#DyT>Bi!w?7<0S9#KnD`3}duAZH9S!+Ku zd3Ow};6qoTQK%$dC0?1xI|)*zEoZR|2o!#zYO-DI4%-Xy+*potFvNmn$Z|F7|9YUY zw%MNfbbpw3y2Y}>a&gC!*Q~Z>G>)8=k-;nB>`s)zmtxkm2C`lI(0-%u6TR%4p;TP) z`24mza>SJTN_uzE5L}2xDgCEIqo8pMS>A4~T^NS4i{q^lgIDSf0T&4SDf~TGv(b~? zO8*B81M4^183Nc9Wt9h2y$6U>-4~Fwvs|_&Zj86Vj<>-JusX-FT2dE-OZKVuSpTZEI^S1T77H$aClcNW+r{%pf2S2G^=5r>4@<(SrMPEGs>YjsyNnFj~@dpL?(x zP+|;bG_bQc1zi*lCBBi@5N4@S`t;FKen!}SUuiNOoUkWW-hysFtIHAB9YfOj%^RZJo+C9F zf1~9Y@q+mt&FhXOe3moTMkNF-DQWw;xm0F{vA;qqG(jV9n(?1WQhc(}H7bgJjE?!s5C_?nG zTDscRqzlzZIUKn}^!77%sSLJ}tU*w&SK6fe_3C5oBMMX9u&<@^hv)w8sb? zZ{j$Nm5#G(oHDl2a>0_x@m63zsS8{y&f_r+6zc5;b$C=nd>#{X?nNE?c|o0pe)micNE|-m5NO~ ztUgfpZcnb=ftnKSd@^0wBBMwveTZ`xb;xeTlzl&-3FqAaTlUk+#$@Z-aRc$NHt!+ zGrViDOi@vy@uN#(v%}!Z?WGFgOJEic;}gs!N|xR%VjN@<&Y&KyaZsik91@{(V3(`3 znWG9$=LffjNiS?Ashc)8YHl)c>;3BkUKhY^E8$gsPs+^x!x6!-J5}yMyIg0&sC0qQ{v=d(x*cDame~g0tK!#{eGu)0Z(c*i zeGB<9DSF>QBCziHV#S@|m6^mD4`3RO_Nx4}o5XHMEO~Wt%SavyM`X_LANeWB#w}O| zS9SE!Q`P~q8T3wQcngBT3qs>`u|ft8=qWXhI&iWYlJiLGWkuEN5?Ly&VkM9ctXs1Wu>xQX1%deA>g=?HRY z*YYk0;JIl~o{n0d&-K=LJ#})=yVa2;ZEZCgan2fzu72jKs(BPH*Nzh*9%`J-SRU02 zvhR{^SltUhTXX%?QKyCb8AtpIS{S>416l$?n+)P0_w|RBX!uCbwhs(Zc4N-MEZ1g6 zS^m|<%-&S2>8*JsGjZjk7m{ndsWl6|qSrSQ+q(?_Ca!;TaI@@wF%{36gO^z8I{)Z5 z>~u95)+h$0GPmq1frVOt;npoluVd8YNZLl3ZlIDX(uMhPtiVEqOQ@N=gJa0AjWFExr<#q!qT2bbuuU-skhWp5xdIFSw05C9+ zDMppx9dA87lGe14Wtfhbjz2)S(NvvDkNy^%4%6?HN9LKNOli|9XFx49=k&@aDm11u z-^qV_uUE9plE#@E()<^S?UGHi^aHfKaY@d+d)NFfDC9qFH87L+?$a%bIxqv81f;dq z+X>zPdm-s)+r$WqyIC<>ZSUD>FL(!o zmaTby(T5nKa8qDx35OT^D)ASy!a-KgjGMH7kxU#1B&qo?B*R@pSMS5)BxFT=pQiq= zOMwm-s3T=;*K{L_1FPM<^NIC)w1t=RTjg!<@9rT1u}%6en89eq(|9L4GymSqHxgnc zBTm=cZ|l4Swf*R>iTg8b&Q>!M|1>k!sJzc$DuJcw*UI zzf)g9)buU9z&fM-g{>KBKP7Sfi=lVTTP}4S-M9{PM)P2YDGd!Y_eZ+&F@u!37|#oP z@gt_QPGtI&{oOZjeGiMAIvkimdE6)<^1Sj!=664-sVank_05O99iJUsJ&mgN41f9n z-vj4&;D%by+oR_EP6xtTH>ahY*L@v$u_k48#(dur=X13EfkC2!`J7GB3pFi7VKcX> z*8s7S7o_~bt{~$20=H&qNxrRKm!T`&kJ8)5HIl=c%*e$Oka1 zAi-|%m@{>;;s{U(Gx3ZnJkkSb(>dSKU#LbTr-o}IGI@j<-K6JGf#r+EToe0rhq&Mt zx~$0Qk?Kq2oF7!g^g7%*SR1wc_^!6cb&I)&{ljlh)+FBv;W=l&g%^Si=SVb6S$|3H z73r1>tLY(HX1|6@R}XXhfCW_0&7$x--?@Qv97)i;kUagDLTud_Pwf)AAhrWvz?#)@ z$IXYms;f0GLYm*XK?}D&*WFHVP1pXVk&{s}j^3;LLIECM^B;7xw{A)!pln6K#m`^FqpB*uzPYJ|d}(tmB;b766VtA{X}1@<5|e@1~r{^pPnX9wPS|zp~j}$(*h*g&g?rS z{&th1Sb<1lh0j1tg_9N$${*k=#zhaZ!=}B^xQbgA!PEZ(FybLeeRR-c88*2Ua!7SGtQ1Wqj(rMs_2Hs zD@MHdr4Q*_o$&h(T$u(bt^b=S)Ps@H++Z^Hzf9<|H3;HUa#10E31|o-$7+PyZQQF_jZnbOytU4=GHC& zz^#4S4KSpc=m#*ninyr7E&j5)*M0WJV|a~b^_M_t{L0$HRGY=_6?`o8aM1L`v>Z_! zzF@ZOco0pt{Th2prL#2k6KCR|PLM%1LDHC;Bv*Aux5wnv3A0EN`T+BmqGnq#){^9|~zdB|#R-$|&U>6@=sIglS~sF&Lr&X51d!lc1D~U>hVkxgg5dRgw@*?&TDMORJO zJZfUXCH)Y3y|AWcxSbhC?b~%E-&Kk%S7iEf?8?sb#&|nxq7E8Ha_Vwnrd;EixU-+( zxU2V*2%mrqX-4Wy0~MN|NgN!sb1A{KoltV42#-W}atHUMYX}r}*gr4FB%SA{F_H}K zBS^(uAqiD;_vFFCA~l_L-VZ$>-7#!|hv2z%X-WIw>c0TJqs!W6>R3xKTA@XQK`q#` zz1@n2*}c$e?8$aD)?c9?kbz0#dpikEEtdjgJ{uRMbR$>;%v7{U_1qlReZ6jd{Shk98cHX!wQ5KRRlX z8fEJPNZQw`Vv_^LFzzFzM0Q;7=64t73^_J9uP1Z_eb12Rx!&N?5q4j8gO|BI&7~WY z*K6muk3khG^uf(gX%^#mD$wY|cD4il6^V};K826(3lb{828wX@7?5Q1-OHy}NpFOo zGm=jCo0y*|+6*Zxtw+vJJt87;q;$WBj*k&e`CR~h_)_90Q5vKvfuHj5Q^+)w{aUSD z6wc9+xg#5PMwO9X8xmL|mw*a(aI?1I3Eps$YGy zHVY@r} zfVg(C zMp()8st>)007INgeQ(i?&~QYNE`JmsZ58mq_bZZ#T=+V7^$`?UWE>xR=YT2L*rC+b zSRP$zw|c)bh=Qhi(eNK8TAORL<4SDq&B;GS|Z zsgBwP3fYhoYszq>`J)dHSRrB57eJX8DUPka$~V`+jZ1HQzye1_(k3o{<7q^mOvI|j ze{+RMyb?t!^#2sRW%TAZF@$;~Mm4H4*?UZnIJ+It%6eoy^Q(<5Ca-P9zqox5Z&V9| z(tq6@thGCEw*2JJ=jbj$MvXR!@Nyzx5@okYSegr+hlt!oqXVJ)9MKZ2!vroAu@+io zANttji7Z)f#Az#%^v(%SY)7YzwJ2h(Ik5Qi`@^oi{8s1H%Q@We2f+cUvE;%K7nI!L zkJzNf^K`luibRwI86x+PSwOI~k?}eO=)UX@BDh3b-6fGh(R`3?&<# zbKSZpH?!sA{loO98*exXdrG$I>~8s(_J@#k*xVkj^XtIKk5dWP| zlIZC(Ku?d^^NOkB#jICyBcj=6mWqd^_Z+DKs-9jqvnlOz)X)CS7GFTlA~OlXs_Dt9 z#ydkuAYy8p?`WnR45=Rzq=PP(pgym52|2lT1J7~44yv#+w-+94ZJ(TcwV%Qk=S8Ln zP)BeNlNU(FvG1BMgj2|htUptH+Z=5tFy29M)))z4n#(S3F}8ok^uIjtCsozASS9^E zfNTDe`t~YBYGg3s!F?_oj!w=a)Y=fYDnRWS)xGV~vJK@1ldzDzHiu)jFRp)*e5>LaC#^o+8MXp`vY?_>##J|W_&y*;qUws; z#28y+DbF%LA&26lg?vkb5MOn=xmDiHn7!1I(+%`BO9*nG0H-DJbg9TfmRu!oa##G! zeX`xAg6cds)#yZ0Yjw51dJj?XOQoh{D_V`H6;ZIuoy04U)Zdme#o}1Q?a;~OgoE?L zw8v$~Rxrhfs#%%k3pa|o_9C=2R4}N~CjPvN@TN%CBMqT^xV}N5GhRsVqvP+xX+asb z-=LG<7~)}PoyfadEc<8uG?Vx}9esK~?_Tq|D{*@MV%BJN*xbPZQcc@Y?{{-*GkHahcD1hRVeQ454et43P`&-Ex0Ez7|QZsyXQWWy!999S#;*rRJ-__yi4HlZkp&JkosU0~qbJpjE&0 zO&SB9k(Tzzf~De71~_BgpQ#^tCZ^aLWIr5Xi0Zxq_Sk3A#O_}0zTsNAoWNyYV4$h} zmYL02@sQ^L3W>`x6}hW99)EnxM_-Y35{z<%Cm#pR&dm*TQIDt^e(1QndAc`!VD~v- z7czaLts4GM;B1VS#5E#kE-@=@w_F#3I)QlA-9)<4NeiR?=gI%*=n-Q7-HeSzGD{U+ zrZD)xba2=wLJxN#5>%;eJbStV86^iLDRqr@UIXlaN1# zXz&#jPt5I<$JEVV>$A#}_Oue7h|GLy(bo7q!mC}WCnqkzsQE`&i2e%H;_SAjqN|_L z9O8h73 zV=c*WzD(T~bNLNUElq_#4N2pH6fW-hJ%eZLNiWx_cAeqphLv_991zzVktm<2c4GT` ziLh{VYX97u_49a_4&m2m>AUlt9wuEN>u<{)wX1epJH@j0vd`yX$=WcTQZB_HziNZN&dW;Su89iFNSV%(e? zyJADzjxiGMxdw#om5gtGEQXOt3_6}s(OpC{m!IC@6f<{41PcDZ>V49*^7H^sgtZEZ zz>zcOLaZMOHezd>w^+sZnrqvK3t8GyY~&0<`av%+TG?*LQSer$s$cobrA1nzHub{T zf4XO@N*IVUhdKXYRb^$h-lMfL8-d2_z@6sdWY;nprT6*N<_k`*ML;yNS57W zk?C~B^x39(ieIci>=ampKi!ilx!CwJOPOOx-cPurIf{5!)BZEe43xI}jNrEYAWs?% zUN4R!kM^G#P`$7CX@vL>nZA7Z-TS*a#)f2T3_QYe)~c;dKQ}?bk0W~ z#Fjs`bMcN~1HR57s~mQbTX3z?YpdJVrpK0X0-ST4>XT|FZO#U? zLa$x{wi{0j%S=1aa=|H#eR({KHK+(t(O$=FYt9jyxG#A|KI6s5iP$_sldwE>Sb~#K zzxO>Abp61a>Dmc8kh+L`-JmT!(3mZ_epkViXaBvq-&JMt!9@Nb0N|8J@XcjV#)S)W z?2wMMf5aBNH?p>XU6_&~>ot$@b391;eYuu?%jFYNlg4;&WsY{nF+|m0vyJ>*iT?4p zj?~iHVt-O4M0iw7p-09`4?%wz)pCxVmaOG=A6!8Q6x&8oXBs zI)AvFq{Kw;JhGME`cG-e#k(AA!peT7y>c&a0@{e!O{u~3tg$_5`^`*`u#Tes3XBVc*4MN<<4*Qlx5od-<`{1S5e6?LBlfb zIjy}#^PrCXdfM=3@Tf!R3Y#0m`+iGUQH7SVf@VN+SAz6VR&PU(Km(K{cqre(pku@S zvmtdnvVbPIl7_}9u5y5eAVFE!7pfX9ODPKd~9C=Dr##s-)_OqtKz_XPuD#!kD zJH6PFH_s+3vW3>VgujQVZ-OWFIQ_>(hWfWnMo}RcCTDcg_o*^a`;hIgUTh8PXhQtf z!7hSlAN7{cIPLBg<-{nc6ZI!2qlLEd(~d?c1|T^*RTEd#)|Z5k<}ES($L>fF5RN&? zE4F%jbC#zrdgXDClcs^n5-6KXvi_@BpzXa{|DEG$k73~c+8rV;&ecQWFk*ZkhHN1r zYQYv6&6&pEYgONj)0ra+0z()OFvUkW1_%eu(5}c%VpW98D(FT_|1=AnqtzZP>~tc^ zQj23CrV2n-15LrmiQ4PxZt)D(VVLg6W~|@NG7UVhFvYMfcRC zi36}dYCDzH_5*;gUzu7O zRIa;X!#{}%yLXGIFG>rpzN2DvdWWtVB4nho&m?gh@_b(JgL}WS@A&HMs3R%0u@HG8iOTNEB_U)*-R1(|&!QsKa*T7j!w%k5<+$KIJj z3v=BwgnyiFw~`R|W<`r-EbGM$Z+g%eFq@Zj+G&`S`c)KoQnGiff>1GWNtn_ra{_g* zu{_qo)pyV@SAdmoN6P1XPJ5U`@D{JKK7wU(UP7O^Kvpy)5r67rN9XUaVez;jjfD8q zxZ2hzM58i{@k=&LuwPqCeS}F=N;-uyed^6X(`$n>xQ)#AVYAeW_|)c~sK%1)9d$Hohtl!Hw0H@!b0Ov@l&4!H1TFvOcz;AgPCVZoPkv2Za|&5y>P8|R2!xdWLSfuPtHcj2O~3kjN4EIi={5hFOrwD4)*Cp1>Ts>!saK(Kt&t+FEJ)+#n;I&VXL&5tBB#&xV^U@a z-MXOO%_%2zkB99|3%WqtK4i4fBK2v&-dIuZ-zA`*59eySixROXN}cdWAm#a4IYaxZ z%Ob%&0=!S-8(~i`mkblGjq8g_sG)E>h^`+XeJtnfD@c-`TU*%7Q3~uc#>~TY-jeyy zO^pgk-;oi?5pKQzSWgZa%_p2a|3zKRSCIS3OvCAujYn+bj!*9hM*ho9HJckwNOE1! zWTYer1he*Dfc6{z&a^zrnB8hrYeAsf(%%e{*ObSrt$rr{b{)4x0O>rt{vTrS>WDLY zbDqFN4Z!%K=CUYrk1m*qDWp1}w%zDFcgfR4-@R}v_f+><$fu+&d zoahEp4EZA^Rr623J7B;Awv8}7GBf%iJfJtW7Ip+HIr<8*L?}HwV=Ce|ZG~sI!JX$a z+~nmr^{hLn`>z*GuHp%_@pWzdv1*Sf)0BhU3UYpKz?n80bGSOW=+-Ie<+GN37gvy7 z9TBDRf7vT^yKSQ1H(3{pEAF3aTNQn>O?pEX5EqG`# zN?bZWKZs-Z+p@&`b3K*OC-Jo75M|Mc8-+-pjJI|~tG^ufbLjrmf3VoM+?*M~;#(cu z7Id@R)abg;Biw<|DR7Mr=F4~ zt#tikvH0h##I7WZl|4Jb&T|^ntKUKHo$4M96y#p>alT!_3Aqg`e9QW=>(Zufjhmhy zHG%uNq{b=p;S<-Je(1bU>Eu_pYphz=Y`f3&uU?kGZ|M*WgR@{-B6U8`qi0@XGlT0| zIBIuY<20v5hYb+SdmeUmiTRcuA!e+!*oZKU-prUb;_DyNK@geKa}m6pW9_^wcFGu8 zd=#_jv!c9Rrko&*Q-3A&n_dkWqbaOX$g}Y#KJY!fLeShORYfO2a-RCg?mG>=b^7i= z>wI9!`11zsmIjr#S}ui!qR)_&lb>f8=y2HPKpQPq7q|u#Z)wrIInYpj9u3g}EpHFX z+|bhH7CT3*g!I3!ZHZ+to$M~xi5oOyCmS0*Yz?$icQI=dALOUwCVkp>na?w|+1zPc z(%Sk4Y@ureBx>FYkXc$Knl8Wc3o?|QJM$wrGq8+maUr=*x=wvoplD!eBoACTBXBJu z>3_iucN`LR7|8qhs=w}y=$!Rx5=y%N@<8+p0oE`Hrxf?GcZR3qT?j=q7lMdeJIbY} zXM~JUa)Q|ler9lZbyaFJmnOs!R|vcu{Q?v`=Qc>4Xc8VP>WL1)SCzMaDi6z|;5;lT zyyN-X^&<4Pje*FAB%D6hae&^vw*M+LwAZ<{g9;=*W0%oI7#pVghx=e2A*)%T{K{w&Nq@~@%V<>nTap_Ib93KN6euaONpm? z4=4 z=G(C!_GRbxS_c$24=Nrs7TCnYV{7j$`j!eeB_|8iS%&b4+z!{@M8?Y|R z265?&>4s8Y=04q;y;a0I1LOoY)rV{wB1q`O*)~Su?Fmvr5jU*}-br~q&z}?dc&1v2 z?$3H*S)PGw9kqQ~E{Ga@)tKkwmsc;>qp!C#LTrC(j;Aqa*1stoOkt&A9>p!Sc$1;) zLr8K8aK~Co_#V?f?j|arqK)>)G}uQ@xi59qy^7n!+xhd^TTx`a$S70-7$?$E!`Gj= zDY?skA2p$#1Xe_%y!K4+W-LYX?tH1@R-y(j4|3Ij>~Ksi^beyiqlt3Z+x`}UWuKnuza$)2dHRykk=?ibIz?e%5AWV*>jUt9m7pv-jnD|aBu7|p9T3WFxWMKS3hpI+^BSFpA-g0c78 zKi+Lluq19WhZ_)HAB;~YVgeZ*rY%_=K)3aS=BWc$!a~NLrb_HP<*DHZa!u0^s!j~L zcNupWyrjLI$d`UdIWF&hs#?28mZHD(>EGZp)4NSJS?_%><4k3=G(Es2uIW}nGTj3o zJu0_{c2fmHLP@I7FJIi2E*E2K=18ISj19&Z2T-*dVioiwZ?KpL^N#r64K^V%1FthJWlWOsh86KJ!I%gXLmU5*Jl zj1_H-3XGj{Ay*G4%{AR}$i>4BIj%T6pA7XJ-<2T$Q=P^YdQx87hlGPI&@(10e4-Q= zw~`{Er>GaVi<1KnkiL~*v;u|Y#|J6yvF6J9TTLNa_@VPH*M!iHcNui+>+dd;sC&yY zKV`_olx>29a4$sjW#h3M<{1PlQWY#*^?fN*V-22mEb=z)?;(Kbx0>9KBN13C+|9n9*8OM3SCGBTHr2S|jT- zI+=SAskKeb><{BM{j#Vx(Tw)%4Q053LpOJST&UJ1Zp{ZK3BPXS^m=SH;(6k||3}lS zQGpk{PM}oFo0)tpS&1%Z<}p#X#e0a5hU=K~O;C74-P&K}2X4V2U6!9agIXjZmD7> z2NnrkE_;6u5kFKE<#=H$PV@p>;w6Uh#FUu_m)GK!aoUL+6n7yyWk3VuGPI+#fBrd- z3+eD7v&8eP_g$ofcR_~_wPytA&}QTyXT?o^QB<`WxjyZ66D>U_#L!GY$AI+I(jD(F zFP@$N352Aa6~e)kriSF?q=d9C;O5uVS~gCOk<6QXA_WiXi6r>4e#KK9RROmYBJj() zFJ43RX5Fi)#yktzfK-Fi=59+B?8EJ{1>Ox1cJsnjO+cu^`eQ6DUIoTj)bXBS;jEVvzs-u5%E{fJx(2BQ7 z=^w8C1h>H$NQiVjSpRfP6ni3$@O%n}?QkVoIl%XnckM-jt}l;so~}|K%gPoam(QpEWfXuyi^HAtsJCM6LxPJ zgu`Wjvd4}f!JPWbqU4umz=s)}gBE0xG4Tc-OkzaQ?RB|B^(xVb%Ew)u>N2cs0(+gCpxS$BBy8jiukwJVuZ(!x!9tt7>=K=NelF&0B5pgSnE<-ub>`cmO8z*FiVh0N<~->l|CJu zIUR*AhOkTi49;gD^B{mrfX+8*4);V^mZ*WGC}s>h%oVsCE~-K{u`3}xD<7Z?*)fMa z+An2-0J(YZjR|#&+g0gCucUx5d$+z(*V)PnxFVMEt_CoaiA#FN_@`><|5 z;j7}x2Z|^>Bnb|%8;j8PAb|XsZHu6Av+7$z3KP*9SwdIts_&!0&%oKm zp9=1f8-X-WHa5bDu`AEa%9nv_mC|}d&kQ@m^{&*)J5)%yVmkx4RXsK`TT!-H3*CdV zvnmFloEM$rpV1{%uS+3~PlVNYu0nQ;;9APQod#}w`?4WdSE0#{Mv;NPnMjW3MP`ZWF4~{lgRuNgf&gIF+&R5Cv^iDt<3?(G3zceb# z3^$8L*0(fdIfOX+GAsLIFxg=;dm0n(`HDZ@G&16GL#sxz7ORU-=;X?|ZMJftbxXa< zqgo@2cpU|IZkd2#`E)0Ukkq=oOTi2B;LL~;L9-N(;uidPBI=r7ouQ9Xp}xNUhIfdq z9lZ9Qo@e7Br1N#>Xd>&6xprEiCU8qr%-SR2nxlw1DCP`9Um%8k)F{n{&G-&>ES=-n z-zLhM!?>0nB$d6Ac?2di{w7Vg5+P1q5Hf!-_)U7fJt~v%59bBwfB(&S5vSt$M}7Mv zul_S=-`vxb&354#c(w1oi%IFBnms$A^EZ^W8=MSR%8#zBQEsIUS zksbE`j#m>^T^`e1>OaAi2#TR7XANhY0|cIu%%Lykq3Nm?_mj(&5(K|@!udP;ba)VX}-!TQw+0M zaAIUg8LjkY`Q`KGMCDNr)40AcGO`tu%cBNb6`uEb-zx5L%_gCV=b@JneSol%%u zCSK(+x%OkQ4Iu4Go)36jk3MAU3le61AKyCfUxx>eEN9>=Hj(!&@-GThBavu**Y?Oyr-)8Y0uK2~ zjHl*#Iw{@UmO`lKd_}o*<`TiKb{L3`9OI)z_v6J3n$>3&`z<*E%a< zNm!sN?&S~PwKOGmcb9+lv?(ln=P<{FQweIiD}hk}53{8lD%BWuJy?PvGFj}kAxiBZ zjlx~Bj)AB~59h-)Rt_C)I4U+QX{iYhbSC6qx){W*!69{lJf(p%v-Hetzeb}|+{4tF zOznZWoURvV#zF`gEkb99ZVQ6~Nwj0}aB`WcEG(kK&&hGANd9Aa*=BA?M>;+$+W^yzy=f zI;f|lk*z~;>u;IG+DqBopN?%vsVD2BOVc=N?hH!u7%aG6&N1C!`c-*J(8R~KyXI*D zH(KtwVaa!0@0?uS;>)02?s`5Cn`t>aRC;_6g~WPOJO}?~mJ|wCq#H3WLDJMZ;%ZtN zyz#r|svzfC=#g_wV{s^pE~v3V`PwyD;w~4_x;-y;Ew})n+dG7~)f&ZhUb2~#HgM=_ zdP;zzD30PVK{onwnq0u(^@I@9-jUp6y7n1EX>7-9?c!ZRg_>x0tJ z%Z#3ei0f*28^$}Has}mnQgpr6ts*=zdCRr~DH%1@K4ocD(ZW+9{E!l1Jitcm*8RaGsw1%{90saVKMl9x2X51d@0+P6g6On%jPap}? z&7MzAMmkT}^ng}=b>)id+cZAO7b-s+0%3@?Z^&ur#;lPF8PVq~Vjgraa&RO5OSngZ zm2046_dhFhhvK~K<}n5ZMgNxc5$y? zXKcrJfW?1VV`bdr0!D6Gb@<)w>o@%?Bn0Rz#OvSAQJuT!R@=&DCDhby&qq?#jcz%J{o`=6gLprpoF@NXBKW`CaMCM*peySP2kf}Q z^P-bK_|POsO>T9xV6|mwO??cBkY<02QzyQ{7Jq8aFhpc3tfkq*E8t3F*7ay82F(wA z-~DmDvf#>dFb1sVD;IOSb8n+_(!Od<1$^*u_+e#)FFUO`(fpj7N6ZWm}BI z!&F1T*Bv(WCrfk_q+!RhOiT|9rRG5VALf$dqr{jS;)nS!v$EcP-om*Q&MA{p=p@`^ zhrytsf04d;@_-z%A!4Y_8JL0V1%P8h;t96VZ4>OzJ#ww`CvW-`!3U=Eo@G$YBI*xv z2S&gR48I@#_i7t?KV_GjnfSscy1uc?r-$|f{?{M4RjaS8OYLK{F2_7u?MKI8e@kjS zRi3el`reVkTzh$(yK;Ws)z@$9mjGJIx6k5Kv5-nW%5fCCGp7{;gb`%Dx@$2T^nbqK2RvZrnPRd*Q#I;GrKef8V_{F~&~T6a9c9EF?IM4rv!|yUEBpHip^AygEN} zX6|;nVPBc1wrI&znbh~W(m!NDiLp?i)rOC)rS~_VNJ@TZ!&|hI}WoI$8@n}tFyhO5J?U3btm6L z{3X>kycaZ<+)Lj~_F=Of9_tSy(2&K8!+nKp>aJ+?`lW7lywf0YVmf{%TRLC%?^q^1i(+I~# zYZa8^#A0G4i+>~hfp}(1{FZnUA~aB)=xHb5`yN78@Tjzw3fTUl@-(5^lirPCsnr%x zE`SdS{vA!^sO_8Wsa#7-ONUo$2J#wMl<-Fn>gD%BXpJ~reN%<+#%&OXks|QL_hjgs zu%WE_vpv7YF8Q}g(b$`pq(39WTsQ_yz6+H(Ki4wSnKJr56Q*$0YGFjmE+LS_)d(0Mz!Ee3w zdi}sU9pPPCowpkkjD2vaY(X=yqbfG>vArq*i1s`+(VHU;S@(7mP2k--h_W*NTA*%n zmyv}BAIPHp_UdLnjamT30UL`xM=h9>I?gF$EL}{XxGp8ayeSqr@?L`74me zQDInosmX0y?@-L`)VL^Q|AeLYLY>TmE6O|3WMD&-+vJnhnzy&+^{2F4I67^NQcKQ& zB$MFnFrn?J_bOKf9t<&#;IZxAPtCL$)o}{OGA~T0F@e>xJ2-5?%cNyX*Au0lo{Wvs zrLL#!?`u4f<5{C(raT_Zp0~Ds5U-}Yaa||H4v$|8Pt4M0mO8GS&~4fVBbsZ)z0C+$ zXZjih{GPradGZoFcE}x>8vqWOL1!bRm<&5CN&B%l#N*UnKT^%m(T8>m=!yg{Zg(J4 z&`c9+i^rAb!@nzW)<|@HSvy7Li7V5|jrZ#CzK0Y((Wkimu=TMmx}$%LA6&J`6W_O! z?jYuXFEeu?>Qy4i?gvsLJ272&;G8A0jLe1P!9!(LP1FvIY$vdg(A4q`EPKFWiS`Xx z$6(glP-8VuPH$`!t86G*`zLW&mIn&nE7n+8fVVw*wz1f zpY^Qq#xH`e3Hc!p$?9u4G;8V>+Stiw$$r~z;s}cZzvbpyEbh0EQX zQi^-L!YS)&|Ni4hNk>w;Kyt?;ryp-dwG!@-4EN~UrE<;51IG_q$AR4B6S~?j%Rr`` zP}_^k72gHx367QGSP7?eb(S`TnvsKpX6<3Tlf6dJsHo@aRXUiP3X3_pME^DDZBcuLS*wJ+G{ivHAa(bdU#f7?g?!vuw#@0tsMAv2ZQ85pn3mfOG zaV@7{0}m!FlKbs_!O@gCN!S=?QU2(ha2o-+o$fhv2Uilbv{%Yw^z@^L8IUWtYs_XW zC;xOd+?8f-=we<%E&g|x$B+G3=GB;ymZVBWv`{9(MP^NUDRG2Gq>906^EetmczdWBh z(H-4MsWnV~&)tsfihuEViXad#4PzD9(CjrBFE1Vn+pZ+yKOD6>tPG_YLdRd5h>c@E zo}c|i#AY0V04fAfIRJsf%IGP#9Dob?UE>7EP^h7ijPG#Ar)1 z+61esYrnqD-6BRn{T^yhQ*61|+r8U{hEGmO@KEe_!8C`)6WE7hH6KEpWAT?3GuqYU z02B^q5|mQqteYd!SK!+orv1A&tX!H}ZE=YT!%&O$KfM6EsyroZI*gocL>7o|0uAuk z@*LF^`|>N*b_D6FX-HM49?6a%#n4*$#LeUM{l*6W600ziNqCZjf{}WYe{canpAxQjX z?~omK|4;Y8uqIX0)k^-27Tz+hlFk!-h-wRCMz>nOwldfjgwnj?GOx1a=4gyK-tR2@ z2g~tzK%*^v<;faSlS>oY7eoH#1Mfl!Qmx9a)#VSNo}(Ix=5*@6B08G-&TJB_UQKO& z^-t`Ivnz@H+90@=GpgcczPq_fW(ph{f+vT+&yTc+Yd+BaY|kZE$RZ1G7Mz4ygOF`| z(o;kw!^qkN&CU(^)P`zl`B}j#@MGe7YamlOl15ws=lHpyJffA}T7Eg7Zx#=f+B5R^?cYX0;FHix1+Yd&RYr-E~_(Q_~VcKnOuuYwy@~80X{7n z0Vv0B`4?j`-R0uz9gzx3<+kzk!92^DSXc;g#mQ%70`PH|NyfN_Am6@I>KmyZ))m>L zbGYF=6A|GB@^Bm$A9?j8YY(?p<+^^K>Bm4vCk~5H;buawz<`YQa$r3U?3W+#*b(eR zv!|7>MO0Rwe*d6~`|ukxU?O93?x*~{=Nsa?>;Bh`S6j40T5UbAlofq-od!b#NGP?Q zjhvN^*aA!DS}9ddPCbi@ZZTZTuc-O%y!r>p+1tpVbo6%c=dbi{_0W>+Tmg|8(`iit zR!$_Xj!zmgGU*mt}k&PKl*hkqZHas~O@9A8p-Qj) zGSv0;B=-bR>#nV$>zgYTP@6-zy$Q7FRQo(%UkoHe$S1a>vECCkTOjf&-rg>-cl5>E zHf(cCFxFd}4LFDd{ZM3qQ^P7!Jq`0^n+|b+Ypf7X0tu1kW@t@8?;v#pb#{%fvWb%V z)O8m#ID?(9vh@X0G?4vfW_xK8(&vKDY|P?VadfJlq{wrSIeHfc`UwEew?#AROrL;b8T2a!LpJi~C{`6)D=;J8Ydb12B;GEx zUWZ4T%_z(;)rK>PCVzjcy`Ds=bbJ60Lp!CMv+jr0+0uPW1N>EQju8l!OatedxU303 zok!M-U6|2Et)_#Ha&9Tz?o|UbXLCr0jn~M!&iJ^xM;Y%>LOGfgJC3ZGY|9@Rnzr&S zQ)^UNXX#vg-7ETfKX#9DK9UC_kqm8r_NbJ%=d^-OL*nZx69>3X*F`}bQ?FeTe22y` z)HWy$dWo+Mzw{;;ZH*q^-4Cl=`bDDC~M0@dAQ&P)jfesK0YO%j~|CH_ft^RcDGy({Lwrv=aN_r}FzaIo4%rM(i$_q;-2}`L9GB@6=?z?q|U=M-hD%u|s+l<(GU6 z>8N88z6L;tKc2Y$>WoA6kkRqvf@I>MjUaw->90THz~fWxVUJaUL)a70m+8y1#2O2^ zVhZ5L9@x^=scXJY=c>vO{FL})@LiIw?hEI}=vCFk-uYTrx1s}tCUf9nlx;&#IG2%5dv*o%34d*?FE zbcwCp^V}|=lDFCzEX+-Ybd-+@|8k8|@2WXeN2%UZO1zM)tQHluM=}{cq1vOvoqXY4 zlzhipga6Oe#YEEt?z<%o%B@|r0*816^X>tV2)-po3jtESH4#A7J;{G%h5pDjRh;cETWw zq^|slZFzBr`&K*?;dBYqyj``OEGp(XGO_6{xM%&=c5)Q`?X&3%Oh)H8=-Wq7k`>Ax z*Z||Ld=$Oe#!m;Ws7b)#n!a4erGIkQqXJOe=VSy6X21%)0u6#Uuj~Sx9Xg8_mI>0b zFeY4q4~NCV63Mt*st)khB-)LAMBnocqv)`tKs1Q3F9QL>Z#fVl-`{LI$eChH+Pr563~+Vx9B-5K9@ z>9Aa|L1Rbw&CK#mQv?JyA>azcDWRXp$jIVJqu86jldT0!9BfYBetRDjeRX-iaaFS>LUABVcW-J3A< z?hN_GF297U@z;U=&=)@6(-kK;`n07+eX?6Ezwx`0XokMn_T&R5z~cMo_$=7&VabK& zW7qjFmFip3TZlPwiQ(J`ppilT&dTNk2AZ1EV@609!MNW+v(dq~-+x%XJsj6zV(vwjzX?>ZcM74@Hk^ z9n_li5p-;p`WRLls*ek8l8H8+npF6PZ4^yqov^{F;J$@jO&^n$jRX>n(ohglG&mX*Z$o)uGDD8N|isJP6(K+X`=Atz} z!Z~!$v@TRRgG-sOQJpF7S598OjR*cJa7QUoe7Rl0t!0;(PYo@!Lt09JPAf~hPb0d4 z_&7Mf?RE0~%Ao{l7nCs+ea`ns(Ft#l&ZVYvGKA1mShD}n)T=A^jE~wt=i4>cyLv+! z>gMN{_B!K=PH`VFakUYk6w&oX8l0NTNM?5>-CjRmQokyFn88Df(aUrF@tEtK)q>Cp zv*`g3;Y01q7b|f|y817i&n%vfI(5^VfaAEvWEKmycg?0a1kqWV$)u#SV-{z!a%y}S zHwT1MpOvAONi4ul$i3&^7NY{(Gty9&N$F2Cu4qbT78`BzfRv}_8rd+&A3K@Fy8O!2hx2_K zqv!QJjPqq&FU(Mui@jHznw+{3ezk(m*0FA2ydlAW^NSck>h^CiEh*?$2;I+5gA5!u z1E9rX8)FPM&$Cw(7)cU4heCH+5F*6Jp8!K*GCPY>2Fn9v5na`2p{n&y38F;DlMfV) zF*Fb(Y>%$rcP{Oc&FV;+0~oChY2rG)G9MOny1;bzhiqp}(@$5kIUSn3=fK-4K>SWNnD{O-LAAc z>_nVWtdR?*`P};@sP&pR6-k-OcqLL)h-*?ov&yS zx=1%#x(N7>XaZBMK4o-jRA-aW=E=yAPEJ6uYjEQ~J9hub$u-Gl@ky-fQgex|YX#EU zH~%DEMUs0lX6)wELBWEvdcGUfXbe^ott1>^Ms78Rif5-88ZF6Qt>Q`@Ss4sVc~&J} zMq>pSWb!u0>Oj#O-_dg0-+K@A$lR-h3DHrubMNGh=z17ZC*8FCCqjbyRxVr`H;t8) zjDcyS!M~zmR1I*Qk-~rte_?t6kDU$W%J9_}<8Dicu>uQJz!H&i^UL|b*R)JEb@)ry z03yYlhOEkx{@4FQPdtWO0zHFuCqT|!XsGPv&TtDT!F~O(FeBE66`Ej6^Zy!}zc>ms z&{}j1evlM5?QYM8Z%rJkzH6~|bhlqy&4bgE$I4sKJWdom9@(7D){_{1gH}A5fX7)& zojYIUP`cA+JhmT-x3aUF{+tpvJVD*}+04$Y;QPXUoJwI7`lr^P6mAU~WTjESE8AeP z#I`G@P_F`%jo}-;oKqw#MH=;e_gf59=lh0(N)<{u{Vv@$ph6Sf&EQ()|H4&2PA+7u zn93P6YO2BgY4t8;t+GTE*ix3s%hJ=UzCP%ZAvEBI%C~3I)JR)h*KBoIQ&wtE5_M|@ z{zZ-K;eVK!WS+VQLs4-^4EOvi+RXlo5Gp|PnAI3NBexMS%D~OBs0U-v>JfvM^^HK( z@q%ZBWcfw|)fz(Z6AtnK*db+uWoYx9dm>;0^;d2eLlL*L(xi0FskAOMBv#&p{ax;K zYK&zo%W)u>bfs#)8Xmi4oPNk`zb*Z8C}zccVUrHO_CSE?4*Z4VwT+t_V(bi>kBx z=;q|^1!c__G@k*B*6~05L*>wQxc&Xu!8kwqH0a$z4EK3@r~J zGH~#NWApQ}_e@$BJ?xG_d}@~*1aApB;oul|wzIk4f&JLyf2f*sup->Es z^MlhH{Kuj195Y#?u|)5_RGGl!povU%YX%E@Jwp6pt9F`ocO-+IHlORF2Vw75Yj!Ri zMsj<;jgZBz>wvqCB#)KG!A1uU&GIoyT`A!5zta^=`q-GL`|fH5%WI~4C^Qd!&H3WL z!_{_PipqT+D8!=|rPglsBA|jv2vkM|1Z@BX|K z;}YgIs6drO!{`>oxc2%vt71*2pgQ7KUnVG^>+StjKylluJviulmSpC$Y|xW&?RC2h zr~N$a$^XPuyw%eGm8pKA{_jlH$^uK1#e+e=Y#YlK7WKuBs+C&emJHCCwkcr1Ut5a%gM|XH|(}^E-3AIfq(mX}eu6 zzVxglU03o81|Kn~bpXNhRq~Y_+Gv{?PU2K7Kvm%o)H)FPn|1dbwQm3b3-e#^t5LtL zCIxNi^lF~jjHO;9j#gWE6haS+AZa}+Fi<44jgBX7aXq}r9&8gqs|0W4UXN`m4DvES zekE<5a(H@fbMxV%DeUaVto74qbX|A%0U-t_=pbVtu%4DH7ge1?E>geOA2X1-`X)nz z==u1elYG4k_NTjW0VBEJ$HF%rHnWfA3J(sSbDB=LzdpdjQw%ADFKnb>o`d56_dW`M z9;W-OPa*CCpuPzbvCqGZ=x^g&8nS_V>u+4tDwk7evkvA55uEwo$CM+X?m>u{BMH&V z2zxx=1>IX{s7;y@uJGd|mN%V=Ll(s=B)O9vJ3;e^*&S6T0?uTvNEYh$x{^y2a`Z=A+*UOa@l6=#i&^kYwcF_ylTzrLJ@g z|J@k_|L~c*=kIMl@~|S9O*1idt_asuED@lZJ)bkdjMHzxQX!00X~m@Csjg1=rlGbUIWq>&_}i*B>}@>x&K&BQcF_mM~}9LT-SbH7!3Mm*gm+}e^KTyP5nug_gP(192nfpv8go4sg-JY6+8%xarmOG3eHF| z^TcQmRi^$^4FzR;t9zv;teG+wK4-d7xe|2j8rHo_n<)C_o5g^dePr!Sf*=~yK<>BR z9jR-@&)fLS!AKN)HI4&6q}AG5Ljxkyun3)_5*n?8!c+li_IZ6QmWZ{Ys@1z0D!@lw z>kQ?n5l9cZF{l1u~Zn&ImKXq$Vv{ZY15c@#I;1M2qBLxcIT7QZsX- zm4iH8J+b3k0f@suwWC&!m}Yob+3)vWCdl5!_?|%VK0!U0Y#@8c;Ma+RERSm(} z*{T~uU3How0f4SyEHnF_Bm5j&dgWmYz9G7)e?atsR+BHPYZKE!%z;Qo#$xa-f0QF1 zdNeJDxrHC|%CikR=y%g;COYX?yuR6Z?s(uUO<7qU2e>XZ8A~ zW6YB!a#(^m73PpR_Bib8KDD+Qp8Ii;Lcy-4@}=@=8jeH7%ZTUv`wNk};c{48r1oCg zZwYV(d3j%FOQuv~=0JA|MX68;2hp2dCu~5?aP5T@i-*Y*50Lg8scmp9US*-6{3Yuk z{;t-xHl9k1ulrKRyKgbLhEbl=^7i7rT|ieUhjtTyXt23#blu`8IJm?(7BoT8QJp<@}oky9xgJ z+)zH3ba~2nTjX%EAurD1WZZS5-EeG2t>AIlb0}vPLGBiH*8YyzLizgS&&2`8rhP)T z-ys`*1yP0y0%Dt*;O#%mwspHU)I};}QEC^%_fbwPqHWss1f^6Djd;;^P;u0qNJ-Ih zan$aVa^kUOc`X_4>VA;(A{83yovwv_#h{X`oW=PlaQGdBT)+Y0_HmUY34B#RKBmR+ zx5+88phcCQM!a~0X1ul`m(jd^Tiz!t!aXAuWy^i$eIwr@i1DIsw*({X*E>D}a2 zRwwm8srGDWMvj_u%6cfChsA*~e^>!XGE&1Lc{hlJtcEKYt<6`)g{D9?1uNrzcU^G1 z)RlKlELvV*+(>dp!JLi5gb3g09 zyPv&!J!|jUZ~fk?;$L*j0&MX(J;BPOgvMVekhIySCeAJQ@fc*Pf3#LL7RsKNkuUzW zXmRu{V-!2D-ecp)=XElkb3Nr3vVc(yYML+YRpal!zH17kP1&2;?9!da*OOkb`&d9m z%xy)^V18^8XsS3q3<6$nOL!4BCe73weqXpJL=jw2tZ!P|pOl(oICXImdb@TG&eIN8 zr^;brX1yo=yY5xV`zq<7N@xv|Yg?`{mZM-}^GEXc{FJjSQrvbvt8@f@!_j zlMFK|Lc#;mv%gGMvt--y+Y9Z%3Z4iz~MPAePf=7d3ed&1G0xfsP(_hBU}jF_k)z7oYX)}lqc z`ezb4`qvOs2nu=JyamxlTKSwUtMPk3k!GH6b+9?Qpmve&(bd_9MbtnnDtOfXRP>)$ z_f?-|bYO~9!c1Qj!DTt^v46;n=g;Wq5!44peidBqZQ>c3D9QbAmACUJXr=N(v6%Gz z%U7rL^J5voC{|Gsxn1g%%Efb>x8n_&pD4dP{c6ak8!WI0^wlq_@*pG~`T4_XcvdZw zam4(o$rOIN2#@Z|Q9GZuvoUG@uts;?dm8-N-{hff>6=6rx z^l~XG->8ObO>uOGRVlB&Qx30%VY^Y5$D*~El%D)h2kBmDN%U zsz*jd$Qv@dSVH*9L^f2sfKDgKxI1tf_3QtIP@+`i_IaPnUWRBxB6{xP;mtn&-1du` z4BSRWSWS$LIU=gumfTrvWI=eDkH9IzoL`SCs&95VHHNl#2XSIy8yTt7)RD z8ROMggvJ(yj0B+4npM|rqn7y{{)x(Qc-BIcewziM=rgpH@q;>9;4*%+9$Z7TQAAUyyp1OokT9>_zoi zifg4u$lr^6dqAnO(}~KS56T8Gm_kDISV-$fhN=!!eBz#WKsn(l50(d?3HAPqMF0Q7 zo^ca;QbN~FAfudag5@Rr;MTZ9-gIp>ssBZ_cYFOi)jnzWmRA7IIoL2L(#uD<&C}sK zubNqjU&Izdi1M=N^8`A!KsJkwobtm%*V}d;{hf;3-qk7m38^*!gt}H!0JaG+9uMn(~F!Iky`*XXPzb&8gV`_a+#Vz$DeE!A$CFCh~CzVC_ ztAUd6l<*|j-ung%d6a`vn|P5C9rh&+q_6v?tCQTGzVec9-q5u35ht&eEob(NT3j1 zfLGSW&a?=}b`C)bu%y(y=~IYJ*^E(XK!zl=v*TU-GNkNay2W2xz5R^lD`cOF$;0w4 z{I|DrUZBi3#)kh?CBy8<>SBRVCm7q^ma006@;R-qwN%nFPS@tUykoA}oL2;TdPGSZ zF105!MA=>QssDLCV~v)t!#x`1yA0QGGxyqA&pwZJBme`Eh!pD0HOJ&xqx}~%Y!#^H z4_hphyh=l}5C4?^kVuVyJVzKmc7oYi*T*SS#wLmJ%V?5)zH2&>rDCg&Yw-NvP%Gpw z)XFlLmkBi` z&_`Z}e>SCMSRGADA!~T;oM!2%@WDD|4wMRh4@u6%2eWw_lP?0fri*-LGX!03(a0q& zId4*lu$rjG3MiDgwszJs3hGmRHo;^#h)``cVHaJI>?w#qU z?`vx$dX6gwFVT!-7aS2;#$NZ}hIW%a8=d95(ns6BPVNcDcGTiAp(;TB7uY*ssb1OG!9b$wwmj6qq*Fp>xx^&Ps{!v<@6f6^)?Eh zDQl^qHl#oFe1*5ItT@*{ReX>Vsv)YCK5zk9aFq_zX@{GQ zT*CTGz|Zm0zmV4H43K0)vggQDmciM7Pr|$1AM|kscDOh~pMsEYTw2ko&hOio5A<-` z>WXDxD*!anl&+ZLq&8sI$E|4oux-CHk)T3o6t}gXIGN)8V5&@D~Kyj;>q#|10r-FsL zW9;_jbbGonSp^C?g9nnX^wD{GwC#d4v*)i2T37BQRCqkUk+;>Z%leH*!RbPB2MDaP z{&g}>Yq@E)GgkcPFWaUN{W!4jdOTnB=jau zB-!WXjUR2!NV-^{KrTPm`jaE0y4s-n>l_=2hW%i&jF94>3b-7h8ZU{*dkueBX10xt z3#~iXB+KfbEJRAHc&RlO&?pw9&dtq6krJb3fXf49UFo@=tm=)G9_yjgn&)XSmKR5! zI&h;F@n68=`GZK$MIj3@*KM2{FmY*SX3Mc{&Tz*$^n9cpx`JL5mSCR)kWAMOEhaeI zUh*LPTEQpbs;*dkZMBVsFzZp&r_DCb{yuaA&8>tp1QN82roY{?GvU}s_Q-*LUd_Oe z>X>})m{q3E3ip@zpEfdA@Lyp2AN7B`g58@xNp+TlONIVm3IJ|Zl$z}#Pb_e0t09B4gmfQPtj)gft`4{scf__`JcHQH z*MMwr2n|lT+wyK#Uv`2c361@4BtlF}Xt**F?{bL`Zi*o+aY|amLKbEYR0My7-wlfj zmqW&pjhSg=t^y=__lPde4jz)P$tSw_!lc1Cq;kW3rDscQ9AT9sp za%X=nGSMmxhfJlLV$Kb|ia6AF_esH7Pt@|5BmE5_oCh zF5Hz@k%UMl>A2LyaBNulFbsoER^|3G3W1F)6$AF&{(cYrmP7wz62O_^txC-kAKPTy zt@D&-Ju4EW{h`=f^)i8-3CUj3`j;4*DF7x!y z+%EP`3NY%DKcu>7Tx*krOU~?~PzT?bjC2`%2fq|Wrn%15mEq+WO(}oen<$DSR#7b$ zH-3vxYIahkVt%y`9n?aw8IgI4yz%7HNAk4$E^!qXZ|NUETqRscwj9;N19l{PuKHLA zt&P#lp%);1X?YMBi^>@1DcnODZY-l2y+g$yguY<`tNEGDW7aD zx^!fQ*SW>z_n8TJx>Gnx@5c)I{F@3{nq#Zi@)h_w&_2nI{$C*RpF8QOCde@{gmMIj zvcx-hj%YrAr3O+3|HWtgn+F$@a;Fte5z+?L_Q)bFz$4Pp>LYP* zL>JYIzzm%?{lDb^p}Ag?*s5p;Evj$M7aP+|tMEDP)==ZXABljGOp)R@rmAcv zY1VgUi8KXH@wD&7Bap|Mm%9ttgjAT)Fu}S```twEAel<5K(-Rg7|9_7XIkUs#>OGM z9;Q;bIS|u7aro0-4+=<1w~|U)S`I6q5bKBG>RHO%l@z{z*|7806K(sGpD0UvB4+$ zC8=g&q4D?i*<4$1(8omTqM3{`nfO}rcP}dZ9zB4KmAjkNpDJgh;&=D$KIO>&eqFR< zox70w7_T^n{AzGo)9tCv#-A|!m0(zYR`y!j*>h?e7s8DJ3YjTZ3)j7G$dAsOV$Ob6xx z;cUmoJXS-cHzp!Ro@pmG;r1v~SrN`OW(9aXBeyF;^?;>gIX4QQDTaKfS+mz1(gRR- zKF+fcnqDr`h|~ACB*7sec6KN`YF@avY`g_SaG{dh=E+GE1v9v}LuaR7j2R%DY3E)F z+5Fkp&>t_x%!bhsRW3ELU)L&n(3Mf5T$k<6`4x4~MCu(3Jvq-^vGlFihl3k{Di|e! zl5nS*aH6?g@I}0M^-cpIC<>7ZFp=_dRN143YS)qQ-y{)2j>=#;L&kwaO0L}&R2uNu!Q)a}#a07gcz52tnF_rK zL4Oh%^x!~1QpAr+k@$*4D_Y44l&FpXrCY-5|!;)KSoYdg5G&EDEx?Q zl;Jpxs_G92E7W8P>T2Sf(CE7c;8M%ejbb&_QBmR-(y?$FAS9d11>|rV%#{7en+ps z(Ydh6I$(H1T&%THBfg`zA+spV#gC~h9Ql|JtW{CphSg!PxI?dX-+`y{!lSx;d44T_ zeBDH(AkK?b_EFPyWK9akRGYE|ACn|A$F4=?@UmVEP+0UrhOG`DYxd;?Jhbk^=T^sn zkQT(gN5WmwBG0ZHp&q{jnXhH(g>+!t*YD7V+0e>Vi-05MuO^L_T1i@%;kfP$p17I| zA)xwl@Eu@TB>x>%Bkt>T`c00b?e3YT#+TNg9tzIKf>AWDj@>q8x{{J5fMWwm7>mT9 z_$!a5{f8Z-r=;&uioz=tNk%#3hDvq@BXy9Bi=+$7 z5Y+6|7`Q08dmERb?R)aW0oF?4+@f~|`&w2igiAQx>V?0AVDEQdU)Lg3TD>$np7U4U zVj780sh5%}#wYvXiUn_if&*E%pUNBYNG*C0WN)dfKX>`+N*#u}#vl0+VhRMEBJ>cD z9ENjnrhi1JccSf5@h%>xiQ5y1&uU+=_Bi<%wXN>HqGKuR*qXRulm=O9^7a29hxqaC zwaKI*zJl#-dPpfzG45=8g!dyMkC->)d<4IIzYX*KYk&>X%~zJJb!+yw&YaDf3Zdgb zl;~+dq5Lh*E-Qc~qg~w0QcXK*zIcTB$&qQ&A)_mZbW|I;Laxvy&F+QHpZ=K&(%<#3 z?=gr7q?gizSGBuMZ)}EBei2SI*dtkpE*6tgrRU&P9yY0qF#;3vc&DsL@?(~Jw5r{Z zf#Ln^-in^-GH-<(v-U1;fEQ0+)D^t_nLd=)LRq`>@4AS)rKoXWcq0?d&<8VBCik=T zBv!uhEFVF9yY*!zoYJ6LGeQX!FRfmz3aVCCE2N6S8qMZ|lPn^rt$-v@5eQS%j0L!# zy+kAj8EgpSiO)I@xCuu}m0zY+MbE*jRbH*h&eQiQzxj>2QPMh&5Yrk6lre1$O?A*) zr!BPZ7d>41XE$)tBy5L_O-Uu6c*B8OpmFM^#psl6siE>m0&+e=4R;2)U%Ih5*Od>E z&sBmQ%C25FZ}6iN?30|G+P8wI?jk7-5MjS!{@$)N7bsGXNFt*6Pb+p?0^EOFWQ&t2 zv9U^CCpolq6#hHeV2cC|M=-vfB*>M*`?JIhk^_qsze{qvjE6B6o>as{l9p_YjT7sGC zTcc%qVK(Gj$QwwJaZ4tuMLOMI3`Y-Y*Q`7A5uwww7{dM#I~YKBM?6>^R`NtmnV8BA zlA1zG9lgnkw!7brh5mPYged}N{Zyge0*v&#M zVqThLAr%eKmOgc~@q$3v!xvmnz~W*M01dDW5JufVM0y*Z8A3uvNrp<+L(8DgJ6fI1 z?z$E=HyTFSTmg)H9nSTZtc7P4p#+gOgqF=P#3x$l`%5GWfbX*On%cdj9|`=V1F_sv z$Bnmix>vdzPsP*hM>R!3#m~sT=RYxYrpABi1@L0js~@bR2qP`cvKA9(+*Es8NSXLG=Cj0?9-!yw+)=#JyNO5iR)Ijua+P{-iV94KIdCa&Nqu+I z@uOa-i(+=Izq<@jwJiSpocA+4Jt< zwpdhmc(Iq!JGtIb=&C0j7;o&xD05>(hd*f9jr`?$wdozaUf4uE$;~l+t+3>iURG>A zRvbSn(fMhjhwuK4Khw*dPpJErff$$)j_n^YQ!k9T@ewgsUcU}VJwH>!g~6~c^qtq5 zpK>~zv4Pfz7|I@mH@Rc3u6#J!sne9RLjBo!VAC`|b&tWQ?^984(s2qVdMMYi&qWni z+p7x>=y*AWju9^4`Zh>E$nHSKkN@hEd}h3%KRTrYtu|2Y{#$X95rKogA1>9AXLXCx zVEF!pXohS2ND$jYk^p(5E-joo*PbyU$0__c!irRBR^{R#V!U^loq?X@%RrfS3~0qv zD=|tHj}DdM)c`md1#QS4f1BLV!_0_Ji9!tYmV2!!WcW^LFu7+D1smK_t*EG#H46d2XRP>Flcon)>h(fI$f|! znfi&qk(f7B?Rev{P7@wWr!(##S}S94hscsX+7PjrBELfLHe{fNf?R1`YT$=A#r0vy zn@S7=fAk27d3JV0FcaUe(1Dn!v#-D?w`4 z%+z)~#v$M8rOtCh;7emA7v5VP(3a2?j2)Hlo{l3 zMpCB1Vkt2AFj3E+v|D890KeN_oYPPkTZtxsuu=p6_3rpPK~Qqbsm2KnwGEC$Dq4?z zsP_ql=cR_R8;(S`kgEKBBJDf22|eVR;`7@Z<)R+1+MnQ!)ynheHA~A^<^7lqxMTHK zq#(wUcWubfgHmiBw~UMTc2R1SoVnXkAf7EN4J9DN76G9<3N_+Zoso%*-x;QUp65Xa zWl?ZB9R|jE%N{i;s7G70GbhIlB&Kot$p6yd$*S+Gvrw4x_Pc-l+(Z0+6;w7PR ztBLl9VN>h2HrO!PuH@j1ipM&m4B_8n;(n5s>*BoWo}ypS|e$n&LAJuraCt zd9cog9X!(`K0*9uS^1rja~t*MFlqQ~BgswuNH9VnUhr-NT!POe4#Ama6&d3D+A(=i zN!e5%TXiEh{>*`#y!614i4boCGk4N1>fs)6-L%q6Y&lMFOOeUAj&FwtLVt942t>Z$ zpay%29Cjs80{7{0z?F|aAVe~xa)zsdkW%Wf*Rt`)k|Iq=*+lOVIG>u^8iKScRN zh%53C=6#8v;3Q!~M#o}I54NxyLOOKg1U9T!@S|81<9nM;U}`+$sb4*BPK*u2u)hMI_4Ot6n1aI0HD7}-|R zQz692tKO{xNG(P5+|OIk2ELe>BFkE%Lb7C$=Cj6ko`!(z0+1;BVdoO<#yrz#*F4*3 z=dL3*tu_s`UGEPHz+R68bbwe0=B5xAUYX+S>)smWpx0e^!@D-FDD7|F#2vK^NC{2R zpVJQvi$HxCKjhG zQ)64TS&#Nb>c!!+7iY34uFowJ3-O|eXBQOQEZi(!E|=Te+XG%d{X;y$;!(&q_ZKJ& z^&d#aI%=Z8!in~e2|b069=Lfn{8eT4GbS4(?^6!zojqFedkN1y$3Mulb#uDw1gdPW zMq^?QjqviK=SM&(4v5kHvY@4z0c{tO$WUa5V%$rWd40IkDcSj%ZXCm9(ztANsZQmr zZ*cbF1sp(HOjva~*xt|b{@RKINd3;-8jr=6=`%VHlYi9~+u3$Umjq{F`^G1RT$9y? z6rdv7-k8(zZuwEe`3bo@f#5v{HAmZsXE?{iFMpT!#wvy^X{Lrc9 z8h|~jJ@GGWLIsKOgvGSB{SG{ zZ**VQGHq88lg6lh8JEOWm~iE7pcoG4mb8d`l*FXX!EAc`jJmT={M>mMm&)ZNhg-37 zMzquxJXfF_2i(4L=b9>lx>CZ)Jp65{8A>qt1GYU9|5&;zTc_-*)y3Url}^&dPtE#r zy}n}Hp*y|`zj|Bh6g)vcS-VCsio(#_zPyRq_5S?;q82nbOyX$0tAorJy!uU%YaY21 zN(Xxx%!lTp>ey?gnvw^i*h$e>Yw?FZz7`px=8vEChj|^@=ALWHq7TlL&v$k4B6T}Y zScbBHi=Eh>OX@TH+Lr&ls za9yf7_;vNPekRSWcKaijO{TDwmCtbK9&7J{bf7vz9dG!2wJjaX^BJAMr=g8=x`OZ3 z0Fg^*tHgmfe;oVSF6V$(k@4k^(c<3CY2Iyja4u*~DQo&k3g0n5na1!=kB;WCoX!3m z!AVR|sWn5GX_smf9H$8I(n1TwQT@FAO#oSAfH+?_haj!2swFcz|F{)yRi05xU11RT zG3m=O)wfio&R8mO5?3k0@_Lc-0oEi2@}!Z|Sh!{G`-*KE`Mq>+;)_Qso{HseHsLAL z_*1#0T<<) zv9Tc9`90x2H0p)f$QCqyW!gt%aOLF+U;e5K`;Gb!4<$tIj^>y%kDeM?S?|*$eaT~I zzO#8;fEQ;50-1rtj8PU|?iYwLhvGeH!?3z*hnF9&d)a9Nt_nXZYR8j6xwO{M@|w38 zke`p&?)?Q>V_Nco_W=7rN~Nknzg$aFt!Lk1`BzbEqNX?tdk4o4vKqKpO$KS0n|or8 zPf33q-f1=^g)cfR5(;gRLm%CY24tP&2~+hmdb$&?vc_)M7_=U?w;F9*gN9Dr{F0e@ zg%wfc?;GMYX7H*m`b7>B#Yd`}_%>UUQ_EZZ2h4>$&xr5@_%al&q7Iv~?M5xDx3=E( z%WvY$IToj&vzW}3udgJq6F4g~oOINId!9+k>zm651P(vjHZex2fdmKUNDY*sJvf2- zzxq&?1r9z7tTg(RJrQiGI5nH{D^pFB0WkDZAK40 z-P-gtG&IIF3@SzQT@Sw|3U1|psvM`^an_R#4DDktfT1&qT%g@u#o&{-y!;6FO`1Fw z-{+fio-HhYo%bSnbs$#%dpK|!w6T4RD10|f67C%6<+X@@o5kyl6HA_Q5SF5;4m5}^ k{tn*UrvHejAu`Vh%yklKNleV!FQ6Z3aRsq*5ktTK00t$#1ONa4 diff --git a/lib/ultralib/tools/compile_sjis.py b/lib/ultralib/tools/compile_sjis.py deleted file mode 100755 index 136bdc7..0000000 --- a/lib/ultralib/tools/compile_sjis.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python3 - -import sys, os -from shiftjis_conv import sjis_process - -os.chdir("../../") -WORKING_DIR = os.getcwd() - -fb = [] -original_c_file = [i for i in sys.argv if ".c" in i][0] -CC = [i for i in sys.argv if "-D__CC=" in i][0][7:] -build_dir = [i for i in sys.argv if "-D__BUILD_DIR" in i][0][14:] - -output_c_file = original_c_file - -sys.argv[sys.argv.index(original_c_file)] = output_c_file - -original_c_file = "src/voice/" + original_c_file - -with open(original_c_file) as f: - fb = f.read() - -os.chdir(build_dir + "/src/voice") - -with open(output_c_file, "w+") as outf: - sjis_process(fb, outf) - -os.system("%s %s" % (CC, " ".join(sys.argv[1:]))) diff --git a/lib/ultralib/tools/disassemble_elf.py b/lib/ultralib/tools/disassemble_elf.py deleted file mode 100755 index 1fa58a8..0000000 --- a/lib/ultralib/tools/disassemble_elf.py +++ /dev/null @@ -1,312 +0,0 @@ -#!/usr/bin/env python3 -# -# ELF disassembler that attempts to be matching -# - -import argparse, struct, sys - -from libelf import * -from mdebug import * -from mips_isa import * -from util import * - -def debug_log(msg): - print(msg, file=sys.stderr) - -class MipsDisasm: - """ - """ - - def __init__(self, elf_file) -> None: - self.elf_file = elf_file - mdebug_section = elf_file.find_section_by_type(SHT_MIPS_DEBUG) - if mdebug_section is not None: - self.mdebug = mdebug_section - self.has_mdebug = True - else: - self.has_mdebug = False - self.cur_file = None - self.comment_section_pos = 1 - self.section_local_labels = {} - - def add_section_local_label(self, section, offset): - if section not in self.section_local_labels: - self.section_local_labels.update({section : set()}) - self.section_local_labels[section].add(offset) - - def advance_file(self): - seen_cur_file = False - for sym in self.elf_file.symtab.symbol_entries: - if sym.type == ST_FILE: - if seen_cur_file or self.cur_file is None: - self.cur_file = sym - break - elif self.cur_file == sym: - seen_cur_file = True - return self.cur_file is not None - - def disassemble_all_sections(self): - print(MipsDisasm.asm_prelude()) - - # debug_log("Name Type Addr Off Size ES Flg Lk Inf Al") - for section in self.elf_file.sections: - local_labels = self.section_local_labels.get(section.name, None) - # debug_log(section) - if section.name in ['', '.strtab', '.shstrtab', '.symtab', '.reginfo', '.comment', '.note', '.options', '.mdebug', '.gptab.data', '.gptab.bss'] or \ - (section.sh_type == SHT_REL or section.sh_type == SHT_RELA): - continue - if section.sh_size == 0: - continue - print("") - print(MipsDisasm.begin_section(section)) - if section.is_executable(): - self.disassemble_exec(section) - elif section.sh_type == SHT_PROGBITS: - # TODO kmc as doesn't support incbin, byte array this - # print(f".incbin \"libultra.a\", 0x{section.sh_offset:08X}, 0x{section.sh_size:X}") - first = True - for i,b in enumerate(section.data): - if local_labels is not None and i in local_labels: - if not first: - print("") - print(f".{section.name[1].upper()}_{i:08X}:") - print(" .byte ", end='') - first = True - elif first: - print(" .byte ", end='') - if not first: - print(", ", end='') - print(f"0x{int(b):02X}", end='') - first = False - print("") - elif section.sh_type == SHT_NOBITS: - print(f".skip 0x{section.sh_size:X}") - else: - assert False, f"Unhandled section: {section.name}" - # debug_log("/// UNHANDLED ///") - - def pass_section(self, section): - pass - - @staticmethod - def asm_prelude(): - return f""".include "macro.inc" -#include "regdef.h" - -// assembler directives -.set noat // allow manual use of $at -.set noreorder // don't insert nops after branches""" - - @staticmethod - def begin_section(section): - section_flags = section.flags_str().lower().replace(' ', '') - if section_flags != "": - section_flags = f", \"{section_flags}\"" - section_type = "" - if section.sh_type == SHT_PROGBITS: - section_type = ", @progbits" - elif section.sh_type == SHT_NOBITS: - section_type = ", @nobits" - if section_type != "" and section_flags == "": - section_flags = ", \"\"" - - return f""".section {section.name}{section_flags}{section_type} -.balign {section.sh_addralign} -""" - - def get_label_name(self, addr, pdr=None, optional=False): - if pdr is not None: - sym = pdr.lookup_sym(addr, EcoffSt.LABEL) - if sym is not None: - return sym.name - if not optional: - return f".L{addr:08X}" - else: - return None - - def get_comment_string(self, start): - comment_section = self.elf_file.find_section_by_name(".comment") - end = comment_section.data.find(b'\0', start) - if end == -1: - return None, None - comment = comment_section.data[start:end].decode("ASCII") - return comment, end + 1 - - def print_end(self, vaddr, eof): - ends = eof.get(vaddr, None) - if ends is not None: - for sym in ends: - print(f" .type {sym.name}, @{'function' if sym.type == ST_FUNC else 'object'}") - if sym.st_size != 0: - print(f" .size {sym.name}, . - {sym.name}") - print(f" .end {sym.name}\n") - - def disassemble_exec(self, section): - raw_insns = as_word_list(section.data) - insns = [decode_insn(raw, section.sh_addr + j * 4) for j,raw in enumerate(raw_insns)] - - # enumerate branch labels - branch_labels = set() - - for i,insn in enumerate(insns): - if insn.id in MIPS_BRANCH_INSNS or insn.id == MIPS_INS_J: - branch_labels.add(insn.target if insn.id == MIPS_INS_J else insn.offset) - - eof = {} # vaddr : name - def add_end(vaddr, sym): - if vaddr not in eof: - eof[vaddr] = set() - eof[vaddr].add(sym) - - cur_fdr = None - cur_pdr = None - for i,insn in enumerate(insns): - mnemonic = insn.mnemonic - op_str = insn.op_str - - # Update mdebug info - src_inf = "" - if self.has_mdebug: - # Get new fdr if there is one - fdr = self.mdebug.fdr_foraddr(i * 4, extensions=('.c', '.s')) - if fdr is not None: - # debug_log(fdr.name) - cur_fdr = fdr - - # Get new pdr if there is one - if cur_fdr is not None: - pdr = cur_fdr.pdr_foraddr(i * 4) - if pdr is not None: - # debug_log(pdr) - cur_pdr = pdr - - # Line numbers - if cur_pdr is not None: - asm_line = i - cur_pdr.addr//4 - if asm_line < len(cur_pdr.lines): - src_inf = f" {cur_pdr.lines[asm_line]:4}" - else: - src_inf = " PADDING" - - # Symbols for this address - syms = section.get_sym(i * 4) - # if len(syms) != 0: - # debug_log("\n".join([str(sym) for sym in syms])) - - # Print end - self.print_end(insn.vaddr, eof) - - # Print symbol - for sym in syms: - if sym.name == "gcc2_compiled.": - print(f"// compiler generated") - if self.cur_file is None: - print(f".version \"01.01\"") - if self.advance_file(): - print(f".file 1 \"{self.cur_file.name}\"") - - comment_string = None - while comment_string != "\"GCC: (GNU) 2.7.2\"": - comment_string, self.comment_section_pos = self.get_comment_string(self.comment_section_pos) - if comment_string is None: - break - print(f".ident \"{comment_string}\"") - - if sym.bind == SB_GLOBAL: - print(f"glabel {sym.name}") - else: - print(f"{sym.name}:") - - if sym.st_size != 0: - print(f" .ent {sym.name}") - add_end(insn.vaddr + sym.st_size, sym) - else: - print(f" .type {sym.name}, @{'function' if sym.type == ST_FUNC else 'object'}\n") - - # Print branch labels - lbl = self.get_label_name(insn.vaddr, pdr=cur_pdr, optional=not insn.vaddr in branch_labels) - if lbl is not None: - print(f"{lbl}:") - - # Relocations for this address - rels = section.get_rel(i * 4) - assert len(rels) < 2 # There should never be more than 1 relocation for a single address, right? - # if len(rels) != 0: - # debug_log("\n".join([str(rel) for rel in rels])) - - # Apply relocation - if len(rels) != 0: - rel = rels[0] - if rel.rel_type == R_MIPS_26: - if insn.id == MIPS_INS_JAL: - op_str = rel.relocated_symbol.name - if op_str == ".text" and cur_fdr is not None: - pdr = cur_fdr.pdr_foraddr(insn.target) - if pdr is not None: - op_str = pdr.name - elif insn.id != MIPS_INS_J: # Branch labels for j instructions are also R_MIPS_26 relocations - assert False , f"Got unexpected R_MIPS_26 relocation {insn.id}" - elif rel.rel_type == R_MIPS_HI16: - assert insn.id in [MIPS_INS_LUI] - rel_name = rel.relocated_symbol.name - if rel.relocated_symbol.type == ST_SECTION: - rel_name = f".{rel_name[1].upper()}_00000000" - if cur_fdr is not None: - pass - - op_str = f"{insn.abi.gpr_names[insn.rt]}, %hi({rel_name})" - elif rel.rel_type == R_MIPS_LO16: - # Ideally this should be in the elf code so the relocations don't look identical - addend = insn.imm - rel_name = rel.relocated_symbol.name - if rel.relocated_symbol.type == ST_SECTION: - rel_name = f".{rel_name[1].upper()}_{addend:08X}" - self.add_section_local_label(rel.relocated_symbol.name, addend) - addend = 0 - addend_str = f" + 0x{addend:X}" if addend != 0 else "" - - if insn.id == MIPS_INS_ADDIU: - op_str = f"{insn.abi.gpr_names[insn.rt]}, {insn.abi.gpr_names[insn.rs]}, %lo({rel_name}{addend_str})" - elif insn.id in MIPS_LOAD_STORE_INSNS: - if insn.id in MIPS_FP_LOAD_STORE_INSNS: - op_str = f"{insn.abi.cop1_names[insn.ft]}, " - else: - op_str = f"{insn.abi.gpr_names[insn.rt]}, " - op_str += f"%lo({rel_name}{addend_str})({insn.abi.gpr_names[insn.base]})" - else: - assert False - else: - assert False - - # Apply branch labels - if insn.id in MIPS_BRANCH_INSNS: - op_str_parts = [] - for field in insn.fields: - if field == 'offset': - op_str_parts.append(self.get_label_name(insn.offset, cur_pdr)) - else: - op_str_parts.append(insn.format_field(field)) - op_str = ", ".join(op_str_parts) - elif insn.id == MIPS_INS_J: - op_str = self.get_label_name(insn.target, cur_pdr) - - print(f"/* {section.sh_offset + i * 4:06X} {insn.vaddr:08X} {insn.raw:08X}{src_inf} */ {mnemonic:12}{op_str:35}".rstrip()) - self.print_end(section.sh_addr + section.sh_size, eof) - -def main(): - parser = argparse.ArgumentParser(description="Disassemble relocatable ELF object.") - parser.add_argument("filepath", help="path to the ELF file") - # TODO unimplemented optionals - parser.add_argument("--compiler", help="original compiler that produced the ELF (IDO or GCC, IDO default)", default="IDO") - parser.add_argument("--strenc", help="string encoding, default is EUC-JP for IDO and SJIS for GCC") - args = parser.parse_args() - - elf_file = None - with open(args.filepath, "rb") as elf: - elf_file = ElfFile(bytearray(elf.read())) - - disassembler = MipsDisasm(elf_file) - disassembler.disassemble_all_sections() - -if __name__ == '__main__': - main() diff --git a/lib/ultralib/tools/fix_objfile.py b/lib/ultralib/tools/fix_objfile.py deleted file mode 100755 index 52a79bc..0000000 --- a/lib/ultralib/tools/fix_objfile.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python3 -# -# Fixes garbage data between sections and optionally rodata section flags -# - -import argparse -from libelf import * - -def fix_section_flags(elf): - for section in elf.sections: - # Unset Alloc flag in .rodata section - if section.name == ".rodata": - section.sh_flags &= ~SHF_ALLOC - -def fix_garbage(elf, original): - # Begin with the original data, and paste header and section data over it - result = original - if len(original) < len(elf.data): - result.extend([0]*(len(elf.data) - len(original))) - else: - result = result[:len(elf.data)] - - # NOTE: This only supports the elf header, program headers, section headers and section data at this time - - # emplace elf header - hdr = elf.elf_header.to_bin() - result[0:len(hdr)] = hdr - - # emplace program headers - for i,proghdr in enumerate(elf.progheaders): - offset = elf.elf_header.e_phoff + i * elf.elf_header.e_phentsize - result[offset:offset+elf.elf_header.e_phentsize] = proghdr.to_bin() - - # emplace section headers and section data - for i,section in enumerate(elf.sections): - offset = elf.elf_header.e_shoff + i * elf.elf_header.e_shentsize - section_header, section_data = section.to_bin() - result[offset:offset+elf.elf_header.e_shentsize] = section_header - if section_data is not None: - result[section.sh_offset:section.sh_offset+section.sh_size] = section_data - - return result - -def main(): - parser = argparse.ArgumentParser(description="Disassemble relocatable ELF object.") - parser.add_argument("compiled", help="path to the compiled ELF file") - parser.add_argument("original", help="path to the original ELF file") - parser.add_argument("--fix-section-flags", help="", action="store_true") - args = parser.parse_args() - - elf = None - with open(args.compiled, "rb") as elf_file: - elf = ElfFile(bytearray(elf_file.read())) - - original = None - with open(args.original, "rb") as original_file: - original = bytearray(original_file.read()) - - if args.fix_section_flags: - fix_section_flags(elf) - - result_data = fix_garbage(elf, original) - - with open(args.compiled, "wb") as elf_file: - elf_file.write(result_data) - -if __name__ == '__main__': - main() diff --git a/lib/ultralib/tools/libdiff.py b/lib/ultralib/tools/libdiff.py deleted file mode 100755 index ac6b139..0000000 --- a/lib/ultralib/tools/libdiff.py +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env python3 -from typing import Any, Dict, Optional -import json -import logging -import subprocess -import tempfile -import pathlib -import sys -import queue - -import asm_differ.diff as asm_differ - -MAX_FUNC_SIZE_LINES = 5000 - -class AsmDifferWrapper: - @staticmethod - def create_config(arch: asm_differ.ArchSettings) -> asm_differ.Config: - return asm_differ.Config( - arch=arch, - # Build/objdump options - diff_obj=True, - make=False, - source_old_binutils=True, - diff_section=".text", - inlines=False, - max_function_size_lines=MAX_FUNC_SIZE_LINES, - max_function_size_bytes=MAX_FUNC_SIZE_LINES * 4, - # Display options - formatter=asm_differ.AnsiFormatter(column_width=50), - threeway=None, - base_shift=0, - skip_lines=0, - compress=None, - show_branches=True, - show_line_numbers=False, - show_source=False, - stop_jrra=False, - ignore_large_imms=False, - ignore_addr_diffs=False, - algorithm="levenshtein", - ) - - @staticmethod - def run_objdump(target_data: bytes, config: asm_differ.Config, label: Optional[str]) -> Optional[str]: - flags = [ - "--disassemble", - "--disassemble-zeroes", - "--line-numbers", - "--reloc", - ] - - with tempfile.TemporaryDirectory() as tempdir: - target_path = pathlib.Path(tempdir) / "out.s" - target_path.write_bytes(target_data) - - start_addr = 0 - - if label: - nm_command = "mips-linux-gnu-nm" - - if nm_command: - try: - nm_proc = subprocess.run( - [nm_command] + [target_path], - capture_output=True, - universal_newlines=True - ) - except subprocess.CalledProcessError as e: - logger.error(f"Error running nm: {e}") - logger.error(e.stderr) - - if nm_proc.stdout: - for line in nm_proc.stdout.splitlines(): - if label in line: - start_addr = int(line.split()[0], 16) - break - else: - # logger.error(f"No nm command for {platform}") - return None - - flags.append(f"--start-address={start_addr}") - - objdump_command = "mips-linux-gnu-objdump" - cmds = [objdump_command] + config.arch.arch_flags + flags + [target_path] - - try: - objdump_proc = subprocess.run( - [objdump_command] + config.arch.arch_flags + flags + [target_path], - capture_output=True, - universal_newlines=True - ) - except subprocess.CalledProcessError as e: - # logger.error(e) - # logger.error(e.stderr) - return None - - out = objdump_proc.stdout - return out - - @staticmethod - def diff(target_elf: bytes, compiled_elf: bytes, diff_label:Optional[str]) -> Dict[str, Any]: - arch = asm_differ.get_arch("mips") - - config = AsmDifferWrapper.create_config(arch) - - # Base - if len(target_elf) == 0: - print("Base asm empty") - return - - basedump = AsmDifferWrapper.run_objdump(target_elf, config, diff_label) - if not basedump: - print("Error running asm-differ on basedump") - return - - if len(compiled_elf) == 0: - print("Creation of compilation elf_object failed") - return - - mydump = AsmDifferWrapper.run_objdump(compiled_elf, config, diff_label) - if not mydump: - print("Error running asm-differ") - return - - # Preprocess the dumps - basedump = asm_differ.preprocess_objdump_out(None, target_elf, basedump, config) - mydump = asm_differ.preprocess_objdump_out(None, compiled_elf, mydump, config) - - try: - display = asm_differ.Display(basedump, mydump, config) - except Exception: - print("Error running asm-differ") - return - - # Print the output - display.run_sync() - -if __name__ == "__main__": - if len(sys.argv) != 3 and len(sys.argv) != 4: - print(f"Usage: {sys.argv[0]} [path/to/target.o] [path/to/compiled.o] [function name (optional)]") - sys.exit(0) - target = pathlib.Path(sys.argv[1]) - compiled = pathlib.Path(sys.argv[2]) - if len(sys.argv) == 4: - label = sys.argv[3] - else: - label = None - target_bytes = target.read_bytes() - compiled_bytes = compiled.read_bytes() - AsmDifferWrapper.diff(target_bytes, compiled_bytes, label) diff --git a/lib/ultralib/tools/libelf.py b/lib/ultralib/tools/libelf.py deleted file mode 100755 index 11c4c03..0000000 --- a/lib/ultralib/tools/libelf.py +++ /dev/null @@ -1,1181 +0,0 @@ -#!/usr/bin/env python3 -# -# MIPS ELF library -# - -import struct - -from mdebug import EcoffHDRR, EcoffFdr, EcoffPdr, EcoffLiner, EcoffSymr - -# ===================================================================================================== -# Utility -# ===================================================================================================== - -def align_as(value, align): - if align == 0: - return value - while (value % align != 0): - value += 1 - return value - -# ===================================================================================================== -# ELF Identity -# ===================================================================================================== - -# Offsets into e_ident -EI_MAG0 = 0x00 # Magic char 0 , 0x7F -EI_MAG1 = 0x01 # Magic char 1 , 0x45 -EI_MAG2 = 0x02 # Magic char 2 , 0x4C -EI_MAG3 = 0x03 # Magic char 3 , 0x46 -EI_CLASS = 0x04 # -EI_DATA = 0x05 # -EI_VERSION = 0x06 # -EI_OSABI = 0x07 # -EI_ABIVERSION = 0x08 # -EI_PAD = 0x09 # -EI_NIDENT = 0x10 # - -# Values for e_ident[EI_DATA] -EI_DATA_LE = 1 # little endian -EI_DATA_BE = 2 # big endian - -EI_DATA_V = { - EI_DATA_LE : 'Little Endian', - EI_DATA_BE : 'Big Endian' -} - -# Values for e_ident[EI_CLASS] -EI_CLASS_32 = 1 # 32-bit -EI_CLASS_64 = 2 # 64-bit - -EI_CLASS_V = { - EI_CLASS_32 : 'ELF32', - EI_CLASS_64 : 'ELF64' -} - -# Values for e_ident[EI_OSABI] -EI_OSABI_V = { - 0x00 : 'UNIX / System V', - 0x01 : 'HP-UX', - 0x02 : 'NetBSD', - 0x03 : 'Linux', - 0x04 : 'GNU Hurd', - 0x06 : 'Solaris', - 0x07 : 'AIX', - 0x08 : 'IRIX', - 0x09 : 'FreeBSD', - 0x0A : 'Tru64', - 0x0B : 'Novell Modesto', - 0x0C : 'OpenBSD', - 0x0D : 'OpenVMS', - 0x0E : 'NonStop Kernel', - 0x0F : 'AROS', - 0x10 : 'Fenix OS', - 0x11 : 'CloudABI', - 0x12 : 'Stratus Technologies OpenVOS' -} - -# ===================================================================================================== -# ELF Types -# ===================================================================================================== - -ET_NONE = 0x0000 # -ET_REL = 0x0001 # relocatable -ET_EXEC = 0x0002 # -ET_DYN = 0x0003 # -ET_CORE = 0x0004 # -ET_LOOS = 0xFE00 # -ET_HIOS = 0xFEFF # -ET_LOPROC = 0xFF00 # -ET_HIPROC = 0xFFFF # - -E_TYPE = { - ET_NONE : 'ET_NONE', - ET_REL : 'ET_REL', - ET_EXEC : 'ET_EXEC', - ET_DYN : 'ET_DYN', - ET_CORE : 'ET_CORE', - ET_LOOS : 'ET_LOOS', - ET_HIOS : 'ET_HIOS', - ET_LOPROC : 'ET_LOPROC', - ET_HIPROC : 'ET_HIPROC' -} - -# ===================================================================================================== -# ELF Machines -# ===================================================================================================== - -EM_UNSPECIFIED = 0x00 -EM_ATNT_WE_32100 = 0x01 -EM_SPARC = 0x02 -EM_X86 = 0x03 -EM_MOTOROLA_68000 = 0x04 -EM_MOTOROLA_88000 = 0x05 -EM_INTEL_MCU = 0x06 -EM_INTEL_80860 = 0x07 -EM_MIPS = 0x08 -EM_IBM_SYSTEM_370 = 0x09 -EM_MIPS_RS3000_LE = 0x0A -EM_RESERVED_xB = 0x0B -EM_RESERVED_xC = 0x0C -EM_RESERVED_xD = 0x0D -EM_HEWLETT_PACKARD = 0x0E -EM_RESERVED_xF = 0x0F -EM_INTEL_80960 = 0x13 -EM_POWERPC = 0x14 -EM_POWERPC_64 = 0x15 -EM_5390 = 0x16 -EM_ARM = 0x28 -EM_SUPERH = 0x2A -EM_IA64 = 0x32 -EM_AMD64 = 0x3E -EM_TMS320C6000 = 0x8C -EM_ARM64 = 0xB7 -EM_RISC_V = 0xF3 - -E_MACHINE = { - EM_UNSPECIFIED : 'Unspecified', - EM_ATNT_WE_32100 : 'AT&T WE 32100', - EM_SPARC : 'SPARC', - EM_X86 : 'x86', - EM_MOTOROLA_68000 : 'Motorola 68000 (M68K)', - EM_MOTOROLA_88000 : 'Motorola 88000 (M88K)', - EM_INTEL_MCU : 'Intel MCU', - EM_INTEL_80860 : 'Intel 80860', - EM_MIPS : 'MIPS', - EM_IBM_SYSTEM_370 : 'IBM_System/370', - EM_MIPS_RS3000_LE : 'MIPS RS3000 Little-endian', - EM_RESERVED_xB : 'Reserved', - EM_RESERVED_xC : 'Reserved', - EM_RESERVED_xD : 'Reserved', - EM_HEWLETT_PACKARD : 'Hewlett-Packard PA-RISC', - EM_RESERVED_xF : 'Reserved', - EM_INTEL_80960 : 'Intel 80960', - EM_POWERPC : 'PowerPC', - EM_POWERPC_64 : 'PowerPC (64-bit)', - EM_5390 : 'S390, including S390x', - EM_ARM : 'ARM (up to ARMv7/Aarch32)', - EM_IA64 : 'SuperH', - EM_IA64 : 'IA-64', - EM_AMD64 : 'amd64', - EM_TMS320C6000 : 'TMS320C6000 Family', - EM_ARM64 : 'ARM 64-bits (ARMv8/Aarch64)', - EM_RISC_V : 'RISC-V' -} - -# ===================================================================================================== -# Program Types -# ===================================================================================================== - -PT_NULL = 0x00000000 # Program header table entry unused -PT_LOAD = 0x00000001 # Loadable segment -PT_DYNAMIC = 0x00000002 # Dynamic linking information -PT_INTERP = 0x00000003 # Interpreter information -PT_NOTE = 0x00000004 # Auxiliary information -PT_SHLIB = 0x00000005 # Reserved -PT_PHDR = 0x00000006 # Segment containing the program header table itself -PT_TLS = 0x00000007 # Thread-Local storage template -PT_LOOS = 0x60000000 # Inclusive reserved range for processor-specific semantics -PT_HIOS = 0x6FFFFFFF # ^ -PT_LOPROC = 0x70000000 # Inclusive reserved range for processor-specific semantics -PT_HIPROC = 0x7FFFFFFF # ^ - -P_TYPE = { - PT_NULL : 'PT_NULL' , - PT_LOAD : 'PT_LOAD' , - PT_DYNAMIC : 'PT_DYNAMIC', - PT_INTERP : 'PT_INTERP' , - PT_NOTE : 'PT_NOTE' , - PT_SHLIB : 'PT_SHLIB' , - PT_PHDR : 'PT_PHDR' , - PT_TLS : 'PT_TLS' , - PT_LOOS : 'PT_LOOS' , - PT_HIOS : 'PT_HIOS' , - PT_LOPROC : 'PT_LOPROC' , - PT_HIPROC : 'PT_HIPROC' -} - -# ===================================================================================================== -# Program Flags ( May be platform specific ! ) -# ===================================================================================================== - -PF_E = 1 << 0 # Execute -PF_W = 1 << 1 # Write -PF_R = 1 << 2 # Read - -# ===================================================================================================== -# Symbol Info -# ===================================================================================================== - -# Symbol Types - -ST_NOTYPE = 0 -ST_OBJECT = 1 -ST_FUNC = 2 -ST_SECTION = 3 -ST_FILE = 4 - -SYM_TYPE = { - ST_NOTYPE : 'NOTYPE', - ST_OBJECT : 'OBJECT', - ST_FUNC : 'FUNC', - ST_SECTION : 'SECTION', - ST_FILE : 'FILE' -} - -# Symbol Bind - -SB_LOCAL = 0 -SB_GLOBAL = 1 -SB_WEAK = 2 - -SYM_BIND = { - SB_LOCAL : 'LOCAL', - SB_GLOBAL : 'GLOBAL', - SB_WEAK : 'WEAK' -} - -# Symbol Visibility - -SV_DEFAULT = 0 - -SYM_VIS = { - SV_DEFAULT : 'DEFAULT' -} - -# NDX - -SHN_UND = 0x0000 -SHN_ABS = 0xFFF1 -SHN_COMMON = 0xFFF2 -SHN_XINDEX = 0xFFFF -SHN_LORESERVE = 0xFF00 - -SYM_NDX = { - SHN_UND : 'UND', - SHN_ABS : 'ABS', - SHN_COMMON : 'COMMON', - SHN_XINDEX : 'XINDEX', - SHN_LORESERVE : 'LORESERVE' -} - -# ===================================================================================================== -# Relocation Type -# ===================================================================================================== - -# EM_MIPS -R_MIPS_32 = 2 # Write the 32 bit address of the symbol -R_MIPS_26 = 4 # Write the 26 bit address of the symbol divided by four (for relocating branch instructions). Fail if address won't fit -R_MIPS_HI16 = 5 # Write the high 16 bits of the address of the symbol -R_MIPS_LO16 = 6 # Write the low 16 bits of the address of the symbol - -# EM_POWERPC -R_PPC_NONE = 0 # Do nothing. Skip this entry -R_PPC_ADDR32 = 1 # Write the 32 bit address of the symbol -R_PPC_ADDR24 = 2 # Write the 24 bit address of the symbol divided by four shifted up 2 bits to the 32 bit value (for relocating branch instructions). Fail if address won't fit -R_PPC_ADDR16 = 3 # Write the 16 bit address of the symbol. Fail if address more than 16 bits -R_PPC_ADDR16_LO = 4 # Write the low 16 bits of the address of the symbol -R_PPC_ADDR16_HI = 5 # Write the high 16 bits of the address of the symbol -R_PPC_ADDR16_HA = 6 # Write the high 16 bits of the address of the symbol plus 0x8000 -R_PPC_ADDR14 = 7 # Write the 14 bits of the address of the symbol divided by four shifted up 2 bits to the 32 bit value (for relocating conditional branch instructions). Fail if address won't fit -R_PPC_REL24 = 10 # Write the 24 bit address of the symbol minus the address of the relocation divided by four shifted up 2 bits to the 32 bit value (for relocating relative branch instructions). Fail if address won't fit -R_PPC_REL14 = 11 # Write the 14 bit address of the symbol minus the address of the relocation divided by four shifted up 2 bits to the 32 bit value (for relocating conditional relative branch instructions). Fail if address won't fit -R_PPC_EMB_SDA21 = 109 # Small Data Area - -# Gamecube/Wii custom relocations -R_DOLPHIN_NOP = 201 # Do nothing. Skip this entry. Carry the address of the symbol to the next entry -R_DOLPHIN_SECTION = 202 # Change which section relocations are being applied to. Set the offset into the section to 0 -R_DOLPHIN_END = 203 # Stop parsing the relocation table -R_DOLPHIN_MRKREF = 204 # Unknown - -RELOC_TYPE = { - EM_MIPS : { - R_MIPS_32 : 'R_MIPS_32', - R_MIPS_26 : 'R_MIPS_26', - R_MIPS_HI16 : 'R_MIPS_HI16', - R_MIPS_LO16 : 'R_MIPS_LO16' - }, - EM_POWERPC : { - R_PPC_NONE : 'R_PPC_NONE', - R_PPC_ADDR32 : 'R_PPC_ADDR32', - R_PPC_ADDR24 : 'R_PPC_ADDR24', - R_PPC_ADDR16 : 'R_PPC_ADDR16', - R_PPC_ADDR16_LO : 'R_PPC_ADDR16_LO', - R_PPC_ADDR16_HI : 'R_PPC_ADDR16_HI', - R_PPC_ADDR16_HA : 'R_PPC_ADDR16_HA', - R_PPC_ADDR14 : 'R_PPC_ADDR14', - 8 : 'R_PPC_ADDR14', - 9 : 'R_PPC_ADDR14', - R_PPC_REL24 : 'R_PPC_REL24', - R_PPC_REL14 : 'R_PPC_REL14', - 12 : 'R_PPC_REL14', - 13 : 'R_PPC_REL14', - R_PPC_EMB_SDA21 : 'R_PPC_EMB_SDA21', - R_DOLPHIN_NOP : 'R_DOLPHIN_NOP', - R_DOLPHIN_SECTION : 'R_DOLPHIN_SECTION', - R_DOLPHIN_END : 'R_DOLPHIN_END', - R_DOLPHIN_MRKREF : 'R_DOLPHIN_MRKREF' - } -} - -# ===================================================================================================== -# Section Types -# ===================================================================================================== - -SHT_NULL = 0x00000000 # Section header table entry unused -SHT_PROGBITS = 0x00000001 # Program data -SHT_SYMTAB = 0x00000002 # Symbol table -SHT_STRTAB = 0x00000003 # String table -SHT_RELA = 0x00000004 # Relocation entries with addends -SHT_HASH = 0x00000005 # Symbol hash table -SHT_DYNAMIC = 0x00000006 # Dynamic linking information -SHT_NOTE = 0x00000007 # Notes -SHT_NOBITS = 0x00000008 # Program space with no data (bss) -SHT_REL = 0x00000009 # Relocation entries, no addends -SHT_SHLIB = 0x0000000A # Reserved -SHT_DYNSYM = 0x0000000B # Dynamic linker symbol table -SHT_INIT_ARRAY = 0x0000000E # Array of constructors -SHT_FINI_ARRAY = 0x0000000F # Array of destructors -SHT_PREINIT_ARRAY = 0x00000010 # Array of pre-constructors -SHT_GROUP = 0x00000011 # Section group -SHT_SYMTAB_SHNDX = 0x00000012 # Extended section indices -SHT_NUM = 0x00000013 # Number of defined types. -SHT_LOOS = 0x60000000 # Start OS-specific. - -# MIPS specific -SHT_MIPS_DEBUG = 0x70000005 # .mdebug -SHT_MIPS_REGINFO = 0x70000006 # .reginfo -SHT_MIPS_OPTIONS = 0x7000000D # .options - -SH_TYPE = { - SHT_NULL : 'SHT_NULL', - SHT_PROGBITS : 'SHT_PROGBITS', - SHT_SYMTAB : 'SHT_SYMTAB', - SHT_STRTAB : 'SHT_STRTAB', - SHT_RELA : 'SHT_RELA', - SHT_HASH : 'SHT_HASH', - SHT_DYNAMIC : 'SHT_DYNAMIC', - SHT_NOTE : 'SHT_NOTE', - SHT_NOBITS : 'SHT_NOBITS', - SHT_REL : 'SHT_REL', - SHT_SHLIB : 'SHT_SHLIB', - SHT_DYNSYM : 'SHT_DYNSYM', - SHT_INIT_ARRAY : 'SHT_INIT_ARRAY', - SHT_FINI_ARRAY : 'SHT_FINI_ARRAY', - SHT_PREINIT_ARRAY : 'SHT_PREINIT_ARRAY', - SHT_GROUP : 'SHT_GROUP', - SHT_SYMTAB_SHNDX : 'SHT_SYMTAB_SHNDX', - SHT_NUM : 'SHT_NUM', - SHT_LOOS : 'SHT_LOOS', - - SHT_MIPS_DEBUG : 'SHT_MIPS_DEBUG', - SHT_MIPS_REGINFO : 'SHT_MIPS_REGINFO', - SHT_MIPS_OPTIONS : 'SHT_MIPS_OPTIONS', -} - -# ===================================================================================================== -# Section Flags -# ===================================================================================================== - -SHF_WRITE = 1 << 0 # Writable -SHF_ALLOC = 1 << 1 # Occupies memory during execution -SHF_EXECINSTR = 1 << 2 # Executable -SHF_MERGE = 1 << 4 # Might be merged -SHF_STRINGS = 1 << 5 # Contains null-terminated strings -SHF_INFO_LINK = 1 << 6 # 'sh_info' contains SHT index -SHF_LINK_ORDER = 1 << 7 # Preserve order after combining -SHF_OS_NONCONFORMING = 1 << 8 # Non-standard OS specific handling required -SHF_GROUP = 1 << 9 # Section is member of a group -SHF_TLS = 1 << 10 # Section hold thread-local data - -SHF_MASKOS = 0x0ff00000 # OS-specific -SHF_MASKPROC = 0xf0000000 # Processor-specific -SHF_ORDERED = 0x04000000 # Special ordering requirement (Solaris) -SHF_EXCLUDE = 0x08000000 # Section is excluded unless referenced or allocated (Solaris) - -SH_FLAG = { - SHF_WRITE : 'SHF_WRITE', - SHF_ALLOC : 'SHF_ALLOC', - SHF_EXECINSTR : 'SHF_EXECINSTR', - SHF_MERGE : 'SHF_MERGE', - SHF_STRINGS : 'SHF_STRINGS', - SHF_INFO_LINK : 'SHF_INFO_LINK', - SHF_LINK_ORDER : 'SHF_LINK_ORDER', - SHF_OS_NONCONFORMING : 'SHF_OS_NONCONFORMING', - SHF_GROUP : 'SHF_GROUP', - SHF_TLS : 'SHF_TLS', - SHF_MASKOS : 'SHF_MASKOS', - SHF_MASKPROC : 'SHF_MASKPROC', - SHF_ORDERED : 'SHF_ORDERED', - SHF_EXCLUDE : 'SHF_EXCLUDE' -} - -# ===================================================================================================== -# ELF Header -# ===================================================================================================== - -ELF32_BIG_STRUCT = '>HHIIIIIHHHHHH' -ELF32_LITTLE_STRUCT = 'IIIBBH', data) - assert self.st_shndx != SHN_XINDEX, "too many sections (SHN_XINDEX not supported)" - self.bind = st_info >> 4 - self.type = st_info & 0xF - self.visibility = self.st_other & 3 - self.parent_section = elf_file.sections[self.st_shndx] if self.st_shndx < SHN_LORESERVE else None - - self.name = name - if self.type == ST_SECTION: - self.name = elf_file.shstrtab.lookup_str(self.parent_section.sh_name) - if self.name == None: - self.name = elf_file.symtab.strtab.lookup_str(self.st_name) - - @staticmethod - def from_parts(st_name, st_value, st_size, st_info, st_other, st_shndx, strtab, name): - header = struct.pack('>IIIBBH', st_name, st_value, st_size, st_info, st_other, st_shndx) - return Symbol(header, strtab, name) - - def to_bin(self): - st_info = (self.bind << 4) | self.type - return struct.pack('>IIIBBH', self.st_name, self.st_value, self.st_size, st_info, self.st_other, self.st_shndx) - - def section_offset(self): - return self.st_value - self.parent_section.sh_addr - - def padded_size_n(self, n): - return align_as(self.st_size, n) - - def padded_size(self): - return self.padded_size_n(self.parent_section.sh_addralign) - - def __str__(self): - # Num: Value Size Type Bind Vis Ndx Name - ndx = ' ' + (SYM_NDX[self.st_shndx] if self.st_shndx in SYM_NDX.keys() else self.parent_section.name) - out = f"{self.st_value:08X} {self.st_size:06X} {SYM_TYPE[self.type]:7} {SYM_BIND[self.bind]:6} {SYM_VIS[self.visibility]:7} {ndx:12} {self.name}" - return out - -# ===================================================================================================== -# Relocation -# ===================================================================================================== - -class Relocation: - """ - typedef struct { - Elf32_Word r_offset; - struct { - Elf32_Word sym_index : 24; - Elf32_Word rel_type : 8; - } r_info; - Elf32_Word r_addend; - } Elf32_Reloc; - """ - - def __init__(self, data, elf_file, target_section, sh_type): - self.sh_type = sh_type - if sh_type == SHT_REL: - self.r_offset, self.r_info = struct.unpack('>II', data) - self.r_addend = 0 - else: - self.r_offset, self.r_info, self.r_addend = struct.unpack('>III', data) - self.sym_index = self.r_info >> 8 - self.rel_type = self.r_info & 0xff - self.relocated_symbol = elf_file.symtab.symbol_entries[self.sym_index] - self.elf_machine = elf_file.elf_header.e_machine - self.target_section = target_section - # TODO obtain the addend if the target section is executable - - def to_bin(self): - self.r_info = (self.sym_index << 8) | self.rel_type - if self.sh_type == SHT_REL: - return struct.pack('>II', self.r_offset, self.r_info) - else: - return struct.pack('>III', self.r_offset, self.r_info, self.r_addend) - - def relocated_symbol_in_section(self, symtab, section): - return symtab.lookup_symbol_in_section(symtab.symbol_entries[self.sym_index].st_value, section) - - def __str__(self): - relocated_symbol = self.relocated_symbol - # Offset Info Type Sym.Value Sym. Name + Addend - # 80135560 00091201 R_MY_RELOC_TYPE 800f39e0 ...data.0 + 0 - out = f"{self.r_offset:08X} {self.r_info:08X} {RELOC_TYPE[self.elf_machine][self.rel_type]:17} {relocated_symbol.st_value:08X} {relocated_symbol.name} + 0x{self.r_addend:X}" - return out - -# ===================================================================================================== -# Section -# ===================================================================================================== - -class Section: - """ - Describes a section - - typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; - } Elf32_Shdr; - -x00 x00 4 4 sh_name Offset to string in the .shstrtab section representing this section's name - -x04 x04 4 4 sh_type See SH_TYPE - -x08 x08 4 8 sh_flags See SH_FLAG - -x0C x10 4 8 sh_addr Virtual address of the section in memory (for loaded sections) - -x10 x18 4 8 sh_offset Offset of the section in the file image - -x14 x20 4 8 sh_size Size in bytes of the section in the file image - -x18 x28 4 4 sh_link Contains the section index of an associated section. This field is used for several purposes depending on section type - -x1C x2C 4 4 sh_info Contains extra information about the section. This field is used for several purposes, depending on section type - -x20 x30 4 8 sh_addralign Contains the required alignment of the section. This field must be a power of two - -x24 x38 4 8 sh_entsize Contains the size, in bytes, of each entry, for sections that contain fixed-size entries. Zero otherwise - -x28 x40 END - """ - - def __init__(self, header, elf_file, index): - self.late_init_done = False - self.sh_name, self.sh_type, \ - self.sh_flags, self.sh_addr, \ - self.sh_offset, self.sh_size, \ - self.sh_link, self.sh_info, \ - self.sh_addralign, self.sh_entsize = struct.unpack('>IIIIIIIIII', header) - assert not self.sh_flags & SHF_LINK_ORDER - if self.sh_entsize != 0: - assert self.sh_size % self.sh_entsize == 0 - if self.sh_type in [SHT_NULL, SHT_NOBITS]: - self.data = None - else: - self.data = elf_file.data[self.sh_offset:][:self.sh_size] - self.index = index - self.relocated_by = [] - self.elf_file = elf_file - - def late_init(self): - self.late_init_done = True - - @staticmethod - def from_parts(sh_name, sh_type, sh_flags, sh_link, sh_info, sh_addralign, sh_entsize, sh_addr, sh_offset, data, index): - header = struct.pack('>IIIIIIIIII', sh_name, sh_type, sh_flags, sh_addr, sh_offset, \ - len(data), sh_link, sh_info, sh_addralign, sh_entsize) - return Section(header, data, index) - - def to_bin(self): - if self.sh_type not in [SHT_NULL, SHT_NOBITS]: - self.sh_size = len(self.data) - header = struct.pack('>IIIIIIIIII', self.sh_name, self.sh_type, self.sh_flags, self.sh_addr, self.sh_offset, self.sh_size, self.sh_link, self.sh_info, self.sh_addralign, self.sh_entsize) - return header, self.data - - def get_rel(self, addr): - relocs = [] - for reloc_section in self.relocated_by: - reloc = reloc_section.find_reloc(addr) - if reloc is not None: - relocs.append(reloc) - return relocs - - def get_sym(self, addr): - symtab = self.elf_file.symtab - symbols = [] - for symbol in symtab.symbol_entries: - if symbol.st_value == addr and symbol.st_shndx == self.index and symbol.type != ST_SECTION: - symbols.append(symbol) - return symbols - - def is_rel(self): - return self.sh_type == SHT_REL or self.sh_type == SHT_RELA - - def is_allocable(self): - return (self.sh_flags & SHF_ALLOC) == SHF_ALLOC - - def is_executable(self): - return (self.sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR - - def is_writable(self): - return (self.sh_flags & SHF_WRITE) == SHF_WRITE - - def padded_size(self): - return align_as(self.sh_size, self.sh_addralign) - - def padded_size_4(self): - return align_as(self.sh_size, 4) - - def flags_str(self): - flags = "" - flags += "W" if self.is_writable() else " " - flags += "A" if self.is_allocable() else " " - flags += "X" if self.is_executable() else " " - return flags - - def __str__(self): - s_type = SH_TYPE[self.sh_type].replace('SHT_','') if self.sh_type in SH_TYPE.keys() else str(self.sh_type) - out = f"{self.name:12}{s_type:12} " - out += f"{self.sh_addr:08X} " - out += f"{self.sh_offset:06X} " - out += f"{self.sh_size:06X} " - out += f"{self.sh_entsize:2X} " - out += f"{self.flags_str():3} " - out += f"{self.sh_link:2} " - out += f"{self.sh_info:3} " - out += f"{self.sh_addralign:5X} " - return out - -class SymtabSection(Section): - """ - Symbol Table Section - """ - - def __init__(self, header, elf_file, index): - super().__init__(header, elf_file, index) - assert self.sh_entsize == 16 - - def late_init(self): - if self.late_init_done: - return - super().late_init() - self.strtab = self.elf_file.sections[self.sh_link] - self.symbol_entries = [] - for i in range(0, self.sh_size, self.sh_entsize): - self.symbol_entries.append(Symbol(self.data[i:i+self.sh_entsize], self.elf_file)) - - def to_bin(self): - header, _ = super().to_bin() - data = bytearray() - for sym in self.symbol_entries: - data.extend(sym.to_bin()) - return header, data - - def find_symbol(self, name): - for s in self.symbol_entries: - if s.name == name: - return (s.st_shndx, s.st_value) - return None - - def lookup_symbol(self, vaddr): - found = [] - for s in self.symbol_entries: - if s.st_value == vaddr and s.type != ST_SECTION: - found.append(s) - if len(found) != 0: - found.sort(reverse=True, key=(lambda s : s.type)) - return found[0] - return None - - def lookup_symbol_for_section(self, vaddr, shndx): - found = [] - for s in self.symbol_entries: - if s.st_value == vaddr and s.type != ST_SECTION and s.st_shndx == shndx: - found.append(s) - if len(found) != 0: - found.sort(reverse=True, key=(lambda s : s.type)) - return found[0] - return None - - def lookup_symbol_in_section(self, vaddr, section): - found = [] - for s in self.symbol_entries: - if s.st_value == vaddr and s.type != ST_SECTION and s.st_shndx == section.index: - found.append(s) - if len(found) != 0: - found.sort(reverse=True, key=(lambda s : s.type)) - return found[0] - return None - - def find_symbol_in_section(self, name, section): - pos = self.find_symbol(name) - assert pos is not None - assert pos[0] == section.index - return pos[1] - - def local_symbols(self): - return self.symbol_entries[:self.sh_info] - - def global_symbols(self): - return self.symbol_entries[self.sh_info:] - -class StrtabSection(Section): - """ - String Table Section - """ - def __init__(self, header, data, index): - super().__init__(header, data, index) - - def lookup_str(self, index): - to = self.data.find(b'\0', index) - assert to != -1 - return self.data[index:to].decode('latin1') - -class RelocationSection(Section): - """ - Relocation Section - """ - def __init__(self, header, data, index): - super().__init__(header, data, index) - - def late_init(self): - if self.late_init_done: - return - super().late_init() - self.rel_target = self.elf_file.sections[self.sh_info] - self.rel_target.relocated_by.append(self) - self.relocations = [] - for i in range(0, self.sh_size, self.sh_entsize): - self.relocations.append(Relocation(self.data[i:][:self.sh_entsize], self.elf_file, self.rel_target, self.sh_type)) - - def to_bin(self): - header, _ = super().to_bin() - data = bytearray() - for rel in self.relocations: - data.extend(rel.to_bin()) - return header, data - - def lookup_reloc(self, vaddr): - for r in self.relocations: - if r.r_offset - r.r_offset % 4 == vaddr: - return r - return None - - def find_reloc(self, vaddr): - for r in self.relocations: - if r.r_offset == vaddr: - return r - return None - - def lookup_jtbl_reloc(self, vaddr, symtab): - for r in self.relocations: - r_sym = r.relocated_symbol(symtab) - if r_sym.st_value + r.r_addend == vaddr: - return r - return None - -class MdebugSection(Section): - """ - MIPS Debugging Section - """ - def __init__(self, header, elf_file, index): - super().__init__(header, elf_file, index) - self.parent = self.elf_file - self.hdrr = EcoffHDRR(self.data) - - self.fdrs = [] - for i in range(self.hdrr.ifdMax): - fdr = EcoffFdr.from_binary(self, i) - self.fdrs.append(fdr) - - def late_init(self): - if self.late_init_done: - return - super().late_init() - for fdr in self.fdrs: - fdr.late_init() - - def fdr_forname(self, filename): - for fdr in self.fdrs: - # remove path and file ext - normalized_name = ".".join(fdr.name.split("/")[-1].split(".")[:-1]) - - if normalized_name == filename: - return fdr - return None - - def fdr_foraddr(self, addr, extensions=('.c')): - for fdr in self.fdrs: - if fdr.adr == addr and any((fdr.name.endswith(ext) for ext in extensions)): - return fdr - return None - - def read_string(self, index): - to = self.elf_file.data.find(b'\0', self.hdrr.cbSsOffset + index) - assert to != -1 - return self.elf_file.data[self.hdrr.cbSsOffset + index:to].decode("ASCII") - - def read_ext_string(self, index): - to = self.elf_file.data.find(b'\0', self.hdrr.cbSsExtOffset + index) - assert to != -1 - return self.elf_file.data[self.hdrr.cbSsExtOffset + index:to].decode("ASCII") - -class ReginfoSection(Section): - """ - MIPS Register Information Section - """ - def __init__(self, header, elf_file, index): - super().__init__(header, elf_file, index) - -# ===================================================================================================== -# Elf File -# ===================================================================================================== - -class ElfFile: - def __init__(self, data): - def init_section(i): - offset = self.elf_header.e_shoff + i * self.elf_header.e_shentsize - section_type = struct.unpack(">I", data[offset + 4:][:4])[0] - header_data = data[offset:][:self.elf_header.e_shentsize] - - if section_type == SHT_REL or section_type == SHT_RELA: - return RelocationSection(header_data, self, i) - elif section_type == SHT_SYMTAB: - return SymtabSection(header_data, self, i) - elif section_type == SHT_STRTAB: - return StrtabSection(header_data, self, i) - elif section_type == SHT_MIPS_DEBUG: - return MdebugSection(header_data, self, i) - elif section_type == SHT_MIPS_REGINFO: - return ReginfoSection(header_data, self, i) - else: - return Section(header_data, self, i) - - self.data = data - self.elf_header = ElfHeader(data[0:52]) - - num_progheaders = self.elf_header.e_phnum - num_sections = self.elf_header.e_shnum - - # Init program headers - self.progheaders = [] - for i in range(num_progheaders): - offset = self.elf_header.e_phoff + i * self.elf_header.e_phentsize - self.progheaders.append(ProgramHeader(data[offset:][:self.elf_header.e_phentsize], self.elf_header.e_ident[EI_CLASS])) - - # Init sections - self.sections = [] - for i in range(num_sections): - self.sections.append(init_section(i)) - - # Init shstrtab and name sections - self.shstrtab = self.sections[self.elf_header.e_shstrndx] - assert isinstance(self.shstrtab, StrtabSection) - - for s in self.sections: - s.name = self.shstrtab.lookup_str(s.sh_name) - - # Init symtab - symtab = None - for s in self.sections: - if s.sh_type == SHT_SYMTAB: - assert not symtab , "Found more than one symtab section?" - symtab = s - self.symtab = symtab - if self.symtab is not None: - self.symtab.late_init() - - # Late Init sections - for s in self.sections: - s.late_init() - - def find_section_by_name(self, name): - for s in self.sections: - if s.name == name: - return s - return None - - def find_section_by_type(self, type): - for s in self.sections: - if s.sh_type == type: - return s - return None - -### Tests - -if __name__ == "__main__": - import sys - - elf_file = None - - with open(sys.argv[1], "rb") as elf: - elf_file = ElfFile(bytearray(elf.read())) - - # Header Info Test - print(elf_file.elf_header) - # Program Headers Info Test - print("") - print("Program Headers:") - print(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align") - for phdr in elf_file.progheaders: - print(phdr) - # Section Headers Info Test - print("") - print("Section Headers:") - print(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al") - for i,s in enumerate(elf_file.sections,0): - print(f" [{i:2}] {s}") - # Symbols Info Test - if elf_file.symtab is not None: - print("") - print(f"Symbol table '{elf_file.symtab.name}' contains {len(elf_file.symtab.symbol_entries)} entries") - print(" Num: Value Size Type Bind Vis Ndx Name") - for i,sym in enumerate(elf_file.symtab.symbol_entries,0): - print(f"{i:6}: {sym}") - # Relocations Info Test - print("") - for s in elf_file.sections: - if s.is_rel(): - print(f"\nRelocation section '{s.name}' at offset 0x{s.sh_offset:06X} contains {len(s.relocations)} entries:") - print(" Offset Info Type Sym.Value Sym.Name + Addend") - for reloc in s.relocations: - print(f"{reloc}") - # mdebug Info Test - print("") - mdebug_section = elf_file.find_section_by_type(SHT_MIPS_DEBUG) - if mdebug_section is not None: - """ - for fdr in mdebug_section.fdrs: - print(fdr) - for symr in fdr.symrs: - print(symr) - for pdr in fdr.pdrs: - print(pdr) - for symr in pdr.symrs: - print(symr) - for liner in pdr.lines: - print(liner) - """ - for fdr in mdebug_section.fdrs: - print(fdr.c_str()) diff --git a/lib/ultralib/tools/m2ctx.py b/lib/ultralib/tools/m2ctx.py deleted file mode 100755 index 39c5dc5..0000000 --- a/lib/ultralib/tools/m2ctx.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import sys -import subprocess -import tempfile - -script_dir = os.path.dirname(os.path.realpath(__file__)) -root_dir = os.path.abspath(os.path.join(script_dir, "..")) -src_dir = root_dir + "src/" - -# Project-specific -CPP_FLAGS = [ - "-Iinclude", - "-Iinclude/PR", - "-Iinclude/gcc", - "-Isrc", - "-Isrc/libc", - "-Iver/current/build/include", - "-D_LANGUAGE_C", - "-DF3DEX_GBI_2", - "-D_MIPS_SZLONG=32", - "-DSCRIPT(...)={}" - "-D__attribute__(...)=", - "-D__asm__(...)=", - "-ffreestanding", - "-DM2CTX", -] - -def import_c_file(in_file) -> str: - in_file = os.path.relpath(in_file, root_dir) - cpp_command = ["gcc", "-E", "-P", "-dM", *CPP_FLAGS, in_file] - cpp_command2 = ["gcc", "-E", "-P", *CPP_FLAGS, in_file] - - with tempfile.NamedTemporaryFile(suffix=".c") as tmp: - stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-dM", tmp.name], cwd=root_dir, encoding="utf-8") - - out_text = "" - try: - out_text += subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") - out_text += subprocess.check_output(cpp_command2, cwd=root_dir, encoding="utf-8") - except subprocess.CalledProcessError: - print( - "Failed to preprocess input file, when running command:\n" - + cpp_command, - file=sys.stderr, - ) - sys.exit(1) - - if not out_text: - print("Output is empty - aborting") - sys.exit(1) - - for line in stock_macros.strip().splitlines(): - out_text = out_text.replace(line + "\n", "") - return out_text - -def main(): - parser = argparse.ArgumentParser( - description="""Create a context file which can be used for mips_to_c""" - ) - parser.add_argument( - "c_file", - help="""File from which to create context""", - ) - args = parser.parse_args() - - output = import_c_file(args.c_file) - - with open(os.path.join(root_dir, "ctx.c"), "w", encoding="UTF-8") as f: - f.write(output) - - -if __name__ == "__main__": - main() diff --git a/lib/ultralib/tools/mdebug.py b/lib/ultralib/tools/mdebug.py deleted file mode 100644 index 6f061ec..0000000 --- a/lib/ultralib/tools/mdebug.py +++ /dev/null @@ -1,938 +0,0 @@ -#!/usr/bin/env python3 -# -# .mdebug section -# - -""" -References: -https://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf -https://web.archive.org/web/20010628021622/http://reality.sgi.com/davea/objectinfo.html -https://github.com/astrelsky/ghidra_mdebug -https://github.com/Rozelette/print-mdebug/blob/master/print_mdebug.py -https://opensource.apple.com/source/gcc_legacy/gcc_legacy-938/gcc/mips-tdump.c.auto.html -https://github.com/uhhpctools/openuh/blob/master/osprey-gcc-4.2.0/gcc/mips-tdump.c -https://github.com/bminor/binutils-gdb/blob/master/gdb/mdebugread.c - -(stabs docs): -https://sourceware.org/gdb/current/onlinedocs/stabs.html - -(ecoff docs): -https://web.archive.org/web/20160305114748/http://h41361.www4.hp.com/docs/base_doc/DOCUMENTATION/V50A_ACRO_SUP/OBJSPEC.PDF -https://chromium.googlesource.com/native_client/nacl-toolchain/+/refs/tags/gcc-4.4.3/binutils/gas/ecoff.c -https://kernel.googlesource.com/pub/scm/linux/kernel/git/hjl/binutils/+/hjl/secondary/include/coff/sym.h -https://kernel.googlesource.com/pub/scm/linux/kernel/git/hjl/binutils/+/hjl/secondary/include/coff/symconst.h -""" - -from enum import IntEnum -import struct - -class EcoffBt(IntEnum): # Basic Type - NIL = 0 # - ADR = 1 # pointer-sized integer type - CHAR = 2 # char - UCHAR = 3 # unsigned char - SHORT = 4 # short - USHORT = 5 # unsigned short - INT = 6 # int - UINT = 7 # unsigned int - LONG = 8 # long - ULONG = 9 # unsigned long - FLOAT = 10 # float - DOUBLE = 11 # double - STRUCT = 12 # struct - UNION = 13 # union - ENUM = 14 # enum - TYPEDEF = 15 # type definition - RANGE = 16 # subrange of int - SET = 17 # pascal set - COMPLEX = 18 # FORTRAN complex - DCOMPLEX = 19 # FORTRAN double com[plex - INDIRECT = 20 # forward or unnamed typedef - FIXEDDEC = 21 # Fixed point decimal - FLOATDEC = 22 # Floating point decimal - STRING = 23 # Varying length character string - BIT = 24 # Aligned bit tring - PICTURE = 25 # picture - VOID = 26 # void - LONGLONG = 27 # long long int - ULONGLONG = 28 # unsigned long long int - LONG64 = 30 # - ULONG64 = 31 # - LONGLONG64 = 32 # - ULONGLONG64 = 33 # - ADR64 = 34 # - INT64 = 35 # - UINT64 = 36 # - - AGGREGATE = 63 # not a basic type - MAX = 64 # - -class EcoffSc(IntEnum): - NIL = 0 - TEXT = 1 # .text symbol - DATA = 2 # .data symbol - BSS = 3 # .bss symbol - REGISTER = 4 # value of symbol is register number - ABS = 5 # value of symbol is absolute - UNDEFINED = 6 # value of symbol is undefined - CDBLOCAL = 7 # variable value is in se->va.?? - BITS = 8 # variable is a bit field - CDBSYSTEM = 9 # variable value is in cdb address space - REGIMAGE = 10 # register value is saved on stack - INFO = 11 # symbol contains debugger information - USERSTRUCT = 12 # address in struct user for current process - SDATA = 13 # load time only small data - SBSS = 14 # load time only small common - RDATA = 15 # load time only read-only data - VAR = 16 # var parameter (FORTRAN, Pascal) - COMMON = 17 # common variable - SCOMMON = 18 # small common - VARREGISTER = 19 # var parameter in a register - VARIANT = 20 # variant record - SUNDEFINED = 21 # small undefined (external) data - INIT = 22 # .init section symbol - BASEDVAR = 23 # FORTRAN or PL/1 ptr based var - XDATA = 24 # exception handling data - PDATA = 25 # procedure section - FINI = 26 # .fini section - RCONST = 27 # .rconst section - MAX = 32 # - -class EcoffSt(IntEnum): - NIL = 0 # - GLOBAL = 1 # external symbol - STATIC = 2 # static symbol - PARAM = 3 # procedure argument - LOCAL = 4 # local variable - LABEL = 5 # label - PROC = 6 # procedure - BLOCK = 7 # beginning of block - END = 8 # end of something - MEMBER = 9 # member of struct/union/enum/.. - TYPEDEF = 10 # type definition - FILE = 11 # filename - REGRELOC = 12 # register relocation - FORWARD = 13 # forwarding address - STATICPROC = 14 # load time only static procedures - # (CONSTANT and STAPARAM are in different orders between different sources...) - CONSTANT = 15 # constant - STAPARAM = 16 # FORTRAN static parameters - STRUCT = 26 # structure - UNION = 27 # union - ENUM = 28 # enum - INDIRECT = 34 # - -class EcoffTq(IntEnum): # Type qualifier - NIL = 0 # - PTR = 1 # pointer - PROC = 2 # procedure - ARRAY = 3 # array - FAR = 4 # longer addressing - VOL = 5 # volatile - CONST = 6 # constant - MAX = 8 # - - UNK7 = 7 # invalid - UNK9 = 9 # invalid - UNK10 = 10 # invalid - UNK11 = 11 # invalid - UNK12 = 12 # invalid - UNK13 = 13 # invalid - UNK14 = 14 # invalid - UNK = 15 # invalid - -class EcoffLanguageCode(IntEnum): - C = 0 - PASCAL = 1 - FORTRAN = 2 - ASM = 3 - MACHINE = 4 - NIL = 5 - ADA = 6 - PL1 = 7 - COBOL = 8 - STDC = 9 - CPLUSPLUSV2 = 10 - MAX = 11 - -def get_bitrange(value, start, length): - return (value >> start) & ((1 << length) - 1) - -def sign_extend_16(value): - return (value & 0x7FFF) - (value & 0x8000) - -def sign_extend_4(value): - return (value & 0x7) - (value & 0x8) - -class EcoffLiner: - """ - ECOFF Line Numbers Mapping - - typedef struct sLINER { - s32 count : 4; - s32 delta : 4; - } tLINER, *pLINER; - """ - - def __init__(self, data) -> None: - self.count = get_bitrange(data[0], 0, 4) + 1 - self.delta = get_bitrange(data[0], 4, 4) - - if self.delta == 8: - self.is_extended = True - self.delta = sign_extend_16((data[1] << 8) | data[2]) - self.data = data[:3] - else: - self.is_extended = False - self.delta = sign_extend_4(self.delta) - self.data = data[:1] - - def __str__(self) -> str: - return f"""= EcoffLiner ============= -delta = {self.delta} -count = {self.count} -extended = {self.is_extended}""" - -class EcoffTir: - """ - ECOFF Type Information Record - - typedef struct { -#ifdef LITTLE_ENDIAN - u32 tq3 : 4; - u32 tq2 : 4; - u32 tq1 : 4; /* 6 type qualifiers - tqPtr, etc. */ - u32 tq0 : 4; - /* ---- 16 bit boundary ---- */ - u32 tq5 : 4; - u32 tq4 : 4; - u32 bt : 6; /* basic type */ - u32 continued : 1; /* indicates additional TQ info in next AUX */ - u32 fBitfield : 1; /* set if bit width is specified */ -#else - u32 fBitfield : 1; /* set if bit width is specified */ - u32 continued : 1; /* indicates additional TQ info in next AUX */ - u32 bt : 6; /* basic type */ - u32 tq4 : 4; - u32 tq5 : 4; - /* ---- 16 bit boundary ---- */ - u32 tq0 : 4; - u32 tq1 : 4; /* 6 type qualifiers - tqPtr, etc. */ - u32 tq2 : 4; - u32 tq3 : 4; -#endif - } TIR, *pTIR; // size = 4 - """ - SIZE = 4 - - def __init__(self, data, endian) -> None: - if endian == 1: - self.tq3 = EcoffTq(get_bitrange(data, 0, 4)) - self.tq2 = EcoffTq(get_bitrange(data, 4, 4)) - self.tq1 = EcoffTq(get_bitrange(data, 8, 4)) - self.tq0 = EcoffTq(get_bitrange(data, 12, 4)) - self.tq5 = EcoffTq(get_bitrange(data, 16, 4)) - self.tq4 = EcoffTq(get_bitrange(data, 20, 4)) - self.bt = EcoffBt(get_bitrange(data, 24, 6)) - self.continued = get_bitrange(data, 30, 1) - self.fBitfield = get_bitrange(data, 31, 1) - else: - self.fBitfield = get_bitrange(data, 0, 1) - self.continued = get_bitrange(data, 1, 1) - self.bt = EcoffBt(get_bitrange(data, 2, 6)) - self.tq4 = EcoffTq(get_bitrange(data, 8, 4)) - self.tq5 = EcoffTq(get_bitrange(data, 12, 4)) - self.tq0 = EcoffTq(get_bitrange(data, 16, 4)) - self.tq1 = EcoffTq(get_bitrange(data, 20, 4)) - self.tq2 = EcoffTq(get_bitrange(data, 24, 4)) - self.tq3 = EcoffTq(get_bitrange(data, 28, 4)) - self.tqs = (self.tq0, self.tq1, self.tq2, self.tq3, self.tq4, self.tq5) - - def __str__(self) -> str: - return f"""= EcoffTIR ============== -fBitfield = {self.fBitfield} -continued = {self.continued} -bt = {self.bt.name} -tq4 = {self.tq4} -tq5 = {self.tq5} -tq0 = {self.tq0} -tq1 = {self.tq1} -tq2 = {self.tq2} -tq3 = {self.tq3}""" - -class EcoffRNDXR: - """ - typedef struct { -#ifdef LITTLE_ENDIAN - u32 index : 20; /* index int sym/aux/iss tables */ - u32 rfd : 12; /* index into the file indirect table */ -#else - u32 rfd : 12; /* index into the file indirect table */ - u32 index : 20; /* index int sym/aux/iss tables */ -#endif - } RNDXR, *pRNDXR; // size = 4 - """ - SIZE = 4 - - def __init__(self, data, endian) -> None: - if endian == 1: - self.index = get_bitrange(data, 0, 20) - self.rfd = get_bitrange(data, 20, 12) - else: - self.rfd = get_bitrange(data, 0, 12) - self.index = get_bitrange(data, 12, 20) - - def __str__(self) -> str: - return f"""= EcoffRNDXR ============== -index = {self.index} -rfd = {self.rfd}""" - -class EcoffAux: - """ - typedef union __sgi_auxu_u { - TIR ti; /* type information record */ - RNDXR rndx; /* relative index into symbol table */ - long_i dnLow; /* low dimension of array */ - long_i dnHigh; /* high dimension of array */ - long_i isym; /* symbol table index (end of proc) */ - long_i iss; /* index into string space (not used) */ - long_i width; /* width for non-default sized struct fields */ - long_i count; /* count of ranges for variant arm */ - } AUXU, *pAUXU; // size = 4 - """ - SIZE = 4 - - def __init__(self, fdr, data, endian) -> None: - data = struct.unpack((">" if endian == 1 else "<") + "I", data)[0] - self.ti = EcoffTir(data, endian) - self.rndx = EcoffRNDXR(data, endian) - self.dnLow = self.dnHigh = self.isym = self.iss = self.width = self.count = data - self.fdr = fdr - - def __str__(self) -> str: - return f"""= EcoffAux ============== -ti = {{ -{self.ti} -}} -rndx = {{ -{self.rndx} -}} -dnLow = {self.dnLow:04X} -dnHigh = {self.dnHigh:04X} -isym = {self.isym:04X} -iss = {self.iss:04X} -width = {self.width:04X} -count = {self.count:04X}""" - -class EcoffSymr: - """ - ECOFF Local Symbol - - typedef struct sSymr { - s32 iss; /* index into String Space of name */ - s32 value; /* symbol value */ - /* value can be an address, size or frame offset depending on symbol type */ - EcoffSt st : 6; /* symbol type */ - EcoffSc sc : 5; /* storage class - text, data, etc */ - s32 _reserved : 1; /* reserved bit */ - s32 index : 20; /* index into sym/aux table */ - } tSymr, *pSymr; // size = 0xC - """ - SIZE = 0xC - - def __init__(self, parent, idx, data): - self.idx = idx - self.parent = parent # can be either Fdr or Pdr - self.pdr = parent if type(parent) == EcoffPdr else None - self.fdr = self.pdr.parent if self.pdr is not None else parent - - self.data = data[:EcoffSymr.SIZE] - - self.iss, self.value, bits = struct.unpack(">III", self.data) - self.st = EcoffSt(get_bitrange(bits, 26, 6)) - self.sc = EcoffSc(get_bitrange(bits, 21, 5)) - self._reserved = get_bitrange(bits, 20, 1) - self.index = get_bitrange(bits, 0, 20) - - self.name = self.fdr.read_string(self.iss) - self.type_name = None - - self.c_repr = None - - assert self._reserved == 0 # Sanity check - - def link_syms(self): - if self.st == EcoffSt.END: - self.start_sym = self.fdr.symrs[self.index] - elif self.st in [EcoffSt.BLOCK, EcoffSt.FILE, EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: - self.end_sym = self.fdr.symrs[self.index - 1] - elif self.st in [EcoffSt.PROC, EcoffSt.STATICPROC]: - aux = self.fdr.auxs[self.index] - self.end_sym = self.fdr.symrs[aux.isym - 1] - elif self.st in [EcoffSt.GLOBAL, EcoffSt.STATIC, EcoffSt.PARAM, EcoffSt.LOCAL, EcoffSt.MEMBER, EcoffSt.TYPEDEF, EcoffSt.FORWARD]: - pass - - def late_init(self): - if self.st == EcoffSt.END: - """ - END symbols index the associated begin symbol - """ - self.start_sym = self.fdr.symrs[self.index] - if self.start_sym.st == EcoffSt.BLOCK: - self.c_repr = "}" - elif self.start_sym.st == EcoffSt.FILE: - self.c_repr = f"// end of file: \"{self.start_sym.name}\"" - elif self.start_sym.st in [EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: - self.c_repr = "}" - if len(self.start_sym.type_name) != 0: - self.c_repr += " " + self.start_sym.type_name - self.c_repr += f";" - elif self.st in [EcoffSt.BLOCK, EcoffSt.FILE, EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: - """ - These symbols index the first symbol after their associated END symbol - """ - self.end_sym = self.fdr.symrs[self.index - 1] - if self.st == EcoffSt.BLOCK: - self.c_repr = "{" - elif self.st == EcoffSt.FILE: - self.c_repr = f"#line 1 \"{self.name}\"" - elif self.st in [EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: - keyword = "" - self.type_name = "" - next_sym = self.fdr.symrs[self.index] - if next_sym.st == EcoffSt.TYPEDEF: - # possible typedef struct/union/enum - # TODO check this by ensuring the typedef symbol references this symbol - keyword += "typedef " - self.type_name = next_sym.name - - if self.st == EcoffSt.UNION: - keyword += "union" - elif self.st == EcoffSt.ENUM: - keyword += "enum" - else: - keyword += "struct" - - name = self.name - if len(name) != 0: - name = ' ' + name - - self.c_repr = f"{keyword}{name} {{" - elif self.st in [EcoffSt.PROC, EcoffSt.STATICPROC]: - aux1 = self.fdr.auxs[self.index] - self.end_sym = self.fdr.symrs[aux1.isym - 1] - - self.c_repr = "" - if self.st == EcoffSt.STATICPROC: - self.c_repr += "static " - - self.return_type, _ = self.process_type_information(1) - self.c_repr += self.return_type - if len(self.return_type) != 0: - self.c_repr += " " - self.c_repr += self.name - self.c_repr += "()" - elif self.st in [EcoffSt.GLOBAL, EcoffSt.STATIC, EcoffSt.PARAM, EcoffSt.LOCAL, EcoffSt.MEMBER, EcoffSt.FORWARD]: - self.c_repr = "" - if self.st == EcoffSt.MEMBER: - # value of a stMember is the offset in bits - self.c_repr += f"/* 0x{self.value//8:X} */ " - - type_str, bitwidth = self.process_type_information(0) - self.c_repr += type_str - if len(self.c_repr) != 0: - self.c_repr += " " - self.c_repr += f"{self.name}{f' : {bitwidth}' if bitwidth is not None else ''};" - elif self.st == EcoffSt.TYPEDEF: - # TODO the typedef may already be absorbed into a struct or similar, check before emitting - type_str, _ = self.process_type_information(0) - self.c_repr = f"typedef {type_str} {self.name};" - elif self.st == EcoffSt.LABEL: - self.c_repr = f"{self.name}:" - - def process_type_information(self, ind): - c_bt_names = { - EcoffBt.NIL : None, - EcoffBt.ADR : None, - EcoffBt.CHAR : "signed char", - EcoffBt.UCHAR : "char", - EcoffBt.SHORT : "short", - EcoffBt.USHORT : "unsigned short", - EcoffBt.INT : "int", - EcoffBt.UINT : "unsigned int", - EcoffBt.LONG : "long", - EcoffBt.ULONG : "unsigned long", - EcoffBt.FLOAT : "float", - EcoffBt.DOUBLE : "double", - EcoffBt.STRUCT : "struct", - EcoffBt.UNION : "union", - EcoffBt.ENUM : "enum", - EcoffBt.TYPEDEF : "typedef", - EcoffBt.RANGE : None, - EcoffBt.SET : None, - EcoffBt.COMPLEX : "complex", - EcoffBt.DCOMPLEX : "double complex", - EcoffBt.INDIRECT : None, - EcoffBt.FIXEDDEC : None, - EcoffBt.FLOATDEC : None, - EcoffBt.STRING : "const char*", - EcoffBt.BIT : None, - EcoffBt.PICTURE : None, - EcoffBt.VOID : "void", - EcoffBt.LONGLONG : "long long", - EcoffBt.ULONGLONG : "unsigned long long", - EcoffBt.LONG64 : "long", - EcoffBt.ULONG64 : "unsigned long", - EcoffBt.LONGLONG64 : "long long", - EcoffBt.ULONGLONG64 : "unsigned long long", - EcoffBt.ADR64 : None, - EcoffBt.INT64 : None, - EcoffBt.UINT64 : None, - } - c_tq_str = { - EcoffTq.NIL : "", - EcoffTq.PTR : "*", - EcoffTq.PROC : "()", - EcoffTq.ARRAY : "[]", - EcoffTq.FAR : "/* FAR */", - EcoffTq.VOL : "volatile", - EcoffTq.CONST : "const", - } - - if self.index == 0xFFFFF: - # no type info - return "", None - - aux = self.fdr.auxs[self.index + ind] - ind += 1 - type_str = "" - - bit_width = None - if aux.ti.fBitfield == 1: - bit_width = self.fdr.auxs[self.index + ind].isym - ind += 1 - - if aux.ti.bt in [EcoffBt.STRUCT, EcoffBt.UNION, EcoffBt.ENUM, EcoffBt.TYPEDEF]: - type_ref_aux = self.fdr.auxs[self.index + ind] - ind += 1 - - fd_ref_idx = type_ref_aux.rndx.rfd - if fd_ref_idx == 4095: - fd_ref_idx = self.fdr.auxs[self.index + ind].isym - ind += 1 - - fdr_ref = self.fdr.parent.fdrs[fd_ref_idx] - sym_ref = fdr_ref.symrs[type_ref_aux.rndx.index] - # now we have the reference to the stStruct, stUnion, stEnum, or stTypeDef - type_str += f"{sym_ref.type_name if sym_ref.type_name is not None else sym_ref.name}" - else: - type_str += f"{c_bt_names[aux.ti.bt]}" - - # TODO improve emitting qualified types - tqs = "" - for tq in aux.ti.tqs: - if tq == EcoffTq.NIL: - continue - if tq == EcoffTq.ARRAY: - ind += 2 # skips over some info such as the type of index (always int for C) - array_low_aux = self.fdr.auxs[self.index + ind] - array_high_aux = self.fdr.auxs[self.index + ind + 1] - stride_aux = self.fdr.auxs[self.index + ind + 2] - ind += 3 - tqs += "[" - if array_high_aux.dnHigh != 0xFFFFFFFF: - tqs += '%d' % (array_high_aux.dnHigh + 1) - tqs += "]" - else: - tqs += c_tq_str[tq] - tqs += " " - tqs = tqs.strip() - if len(tqs) != 0: - type_str += " " + tqs - - return type_str, bit_width - - def __str__(self) -> str: - return f"""= EcoffSymr ============== {self.idx} -iss = 0x{self.iss:08X} -value = 0x{self.value:08X} -st = st{self.st.name} -sc = sc{self.sc.name} -_reserved = {self._reserved} -index = 0x{self.index:05X} -name = {self.name}""" - -class EcoffPdr: - """ - ECOFF Procedure Descriptor - - typedef struct sPDR { - s32 addr; /* memory address of start of procedure */ - s32 isym; /* start of local symbol entries */ - s32 iline; /* start of line number entries */ - s32 regmask; /* save register mask */ - s32 regoffset; /* save register offset */ - s32 iopt; /* start of optimization symbol entries */ - s32 fregmask; /* save floating point register mask */ - s32 fregoffset; /* save floating point register offset */ - s32 frameoffset; /* frame size */ - u16 framereg; /* frame pointer register */ - u16 pcreg; /* offset or reg of return pc */ - s32 lnLow; /* lowest line in the procedure */ - s32 lnHigh; /* highest line in the procedure */ - s32 cbLineOffset; /* byte offset for this procedure from the fd base */ -#ifdef 64_BIT - // TODO there's a bitfield in here - s32 gpPrologue; /* byte size of GP prologue */ - s32 gpUsed; /* true if the procedure uses GP */ - s32 regFrame; /* true if register frame procedure */ - s32 prof; /* true if compiled with -pg */ - s32 localOffset; /* offset of local variables from vfp */ -#endif - } tPDR, *pPDR; // size = 0x34 - """ - SIZE = 0x34 - - def __init__(self, fdr, data) -> None: - self.parent = fdr - self.data = data[:EcoffPdr.SIZE] - - self.addr, self.isym, self.iline, self.regmask, \ - self.regoffset, self.iopt, self.fregmask, self.fregoffset, \ - self.frameoffset, self.framereg, self.pcreg, self.lnLow, \ - self.lnHigh, self.cbLineOffset = struct.unpack(">IIIIIIIIIHHIII", self.data) - - self.symrs = [] - - i = self.isym - symr = self.parent.symrs[i] - assert symr.st == EcoffSt.PROC or symr.st == EcoffSt.STATICPROC - # Inherit procedure name from procedure symbol - self.name = symr.name - - self.symrs.append(symr) - while not (symr.st == EcoffSt.END and symr.name == self.symrs[0].name): - i += 1 - symr = self.parent.symrs[i] - self.symrs.append(symr) - - assert symr.st == EcoffSt.END and symr.sc == EcoffSc.TEXT - self.size = symr.value # value field of an stEND and scTEXT symbol is the procedure size - assert self.size % 4 == 0 - - # indexed by asm word offset from proc start - self.lines = [] - - # ilineMax = self.parent.parent.hdrr.ilineMax - # cbLine = self.parent.parent.hdrr.cbLine - # cbLineOffset = self.parent.parent.hdrr.cbLineOffset - # ilineBase = self.parent.ilineBase - # cline = self.parent.cline - # cbLineOffset = self.parent.cbLineOffset - # cbLine = self.parent.cbLine - # lnLow = self.lnLow - # lnHigh = self.lnHigh - # iline = self.iline - - elf_data = self.parent.parent.parent.data - - line_no = self.lnLow # first line in the procedure - line_data = self.parent.parent.hdrr.cbLineOffset + self.parent.cbLineOffset + self.cbLineOffset - # line_end = self.parent.parent.hdrr.cbLineOffset + self.parent.cbLineOffset + self.parent.cbLine - - # print(self) - # print(f"{self.name} [{self.lnLow}:{self.lnHigh}]") - # print(self.size//4) - while len(self.lines) < self.size//4: - # assert line_data < line_end , "Overflow in line numbers table" - - liner = EcoffLiner(elf_data[line_data:]) - line_no += liner.delta - # if line_no < self.lnLow or line_no > self.lnHigh: - # break - - # print(liner) - for i in range(liner.count): - # print(f"[{len(self.lines)}] {line_no}") - self.lines.append(line_no) - - line_data += len(liner.data) - - def lookup_sym(self, value, type=-1): - for sym in self.symrs: - if sym.value == value and (type == -1 or type == sym.st): - return sym - return None - - def __str__(self) -> str: - return f"""= EcoffPdr =============== -addr = 0x{self.addr:08X} -isym = 0x{self.isym:08X} -iline = 0x{self.iline:08X} -regmask = 0b{self.regmask:032b} -regoffset = 0x{self.regoffset:08X} -iopt = 0x{self.iopt:08X} -fregmask = 0b{self.fregmask:032b} -fregoffset = 0x{self.fregoffset:08X} -frameoffset = 0x{self.frameoffset:08X} -framereg = ${self.framereg} -pcreg = ${self.pcreg} -lnLow = {self.lnLow} -lnHigh = {self.lnHigh} -cbLineOffset = 0x{self.cbLineOffset:08X} -name = {self.name}""" - -class EcoffFdr: - """ - ECOFF File Descriptor - - typedef struct sFDR { - u32 adr; /* memory address of beginning of file */ - s32 rss; /* file name (of source, if known) */ - s32 issBase; /* file's string space */ - s32 cbSs; /* number of bytes in the ss */ - s32 isymBase; /* beginning of symbols */ - s32 csym; /* count file's of symbols */ - s32 ilineBase; /* file's line symbols */ - s32 cline; /* count of file's line symbols */ - s32 ioptBase; /* file's optimization entries */ - s32 copt; /* count of file's optimization entries */ - u16 ipdFirst; /* start of procedures for this file */ - u16 cpd; /* count of procedures for this file */ - s32 iauxBase; /* file's auxiliary entries */ - s32 caux; /* count of file's auxiliary entries */ - s32 rfdBase; /* index into the file indirect table */ - s32 crfd; /* count file indirect entries */ - EcoffLanguageCode lang : 5; /* language for this file */ - u32 fMerge : 1; /* whether this file can be merged */ - u32 fReadin : 1; /* true if it was read in (not just created) */ - u32 fBigEndian : 1; /* true if AUXU's are big endian */ - u32 glevel : 2; /* level this file was compiled with */ - u32 _reserved : 20; /* reserved bits */ - s32 cbLineOffset; /* byte offset from header for this file ln's */ - s32 cbLine; /* size of lines for this file */ - } tFDR, *pFDR; // size = 0x48 - """ - SIZE = 0x48 - - @staticmethod - def from_binary(mdebug, i): - # Init - if 'init' not in EcoffFdr.from_binary.__dict__: - EcoffFdr.from_binary.cache = {} - EcoffFdr.from_binary.init = True - # Parent Init - if mdebug not in EcoffFdr.from_binary.cache: - EcoffFdr.from_binary.cache[mdebug] = {} - # Cache hit - if i in EcoffFdr.from_binary.cache[mdebug]: - return EcoffFdr.from_binary.cache[mdebug][i] - # Cache miss - cbFdOffset = mdebug.hdrr.cbFdOffset - elf_data = mdebug.parent.data - EcoffFdr.from_binary.cache[mdebug][i] = EcoffFdr(mdebug, elf_data[cbFdOffset+i*EcoffFdr.SIZE:cbFdOffset+(i+1)*EcoffFdr.SIZE]) - return EcoffFdr.from_binary.cache[mdebug][i] - - def __init__(self, mdebug, data) -> None: - self.parent = mdebug - self.data = data[:EcoffFdr.SIZE] - - self.adr, self.rss, self.issBase, self.cbSs, \ - self.isymBase, self.csym, self.ilineBase, self.cline, \ - self.ioptBase, self.copt, self.ipdFirst, self.cpd, \ - self.iauxBase, self.caux, self.rfdBase, self.crfd, \ - bits, self.cbLineOffset, self.cbLine = struct.unpack(">IIIIIIIIIIHHIIIIIII", self.data) - - self.lang = EcoffLanguageCode(get_bitrange(bits, 27, 5)) - self.fMerge = get_bitrange(bits, 26, 1) - self.fReadin = get_bitrange(bits, 25, 1) - self.fBigEndian = get_bitrange(bits, 24, 1) - self.glevel = get_bitrange(bits, 22, 2) - self._reserved = get_bitrange(bits, 2, 20) - - self.name = self.parent.read_string(self.issBase + self.rss) - - # print(self) - - hdrr = self.parent.hdrr - elf_data = self.parent.parent.data - - # Aux Symbols - self.auxs = [] - for i in range(self.caux): - i += self.iauxBase - assert i < hdrr.iauxMax , "Out of bounds in Auxiliary Symbol Table" - aux = EcoffAux(self, elf_data[hdrr.cbAuxOffset+i*EcoffAux.SIZE:][:EcoffAux.SIZE], self.fBigEndian) - self.auxs.append(aux) - - # Symbols - self.symrs = [] - for i in range(self.csym): - j = i + self.isymBase - assert j < hdrr.isymMax , "Out of bounds in Local Symbol Table" - symr = EcoffSymr(self, i, elf_data[hdrr.cbSymOffset+j*EcoffSymr.SIZE:hdrr.cbSymOffset+(j+1)*EcoffSymr.SIZE]) - self.symrs.append(symr) - for symr in self.symrs: - symr.link_syms() - - # PDRs - self.pdrs = [] - for i in range(self.cpd): - i += self.ipdFirst - assert i < hdrr.ipdMax , "Out of bounds in Procedure Descriptor Table" - pdr = EcoffPdr(self, elf_data[hdrr.cbPdOffset+i*EcoffPdr.SIZE:hdrr.cbPdOffset+(i+1)*EcoffPdr.SIZE]) - self.pdrs.append(pdr) - - self.size = sum([pdr.size for pdr in self.pdrs]) - - def late_init(self): - for symr in self.symrs: - symr.late_init() - - def pdr_forname(self, procedure_name): - for pdr in self.pdrs: - if pdr.name == procedure_name: - return pdr - return None - - def pdr_foranyaddr(self, addr): - for pdr in self.pdrs: - if pdr.addr <= addr and pdr.addr + pdr.size > addr: - return pdr - return None - - def pdr_foraddr(self, addr): - for pdr in self.pdrs: - if pdr.addr == addr: - return pdr - return None - - def read_string(self, index): - return self.parent.read_string(self.issBase + index) - - def c_str(self) -> str: - """ - C prettyprint file - """ - def print_symbol(symr): - return f"{symr.st.name} :: {symr.c_repr}" - - indent = 0 - out = f"File: {self.name}\n" - - for symr in self.symrs: - if symr.st in [EcoffSt.END]: - indent -= 2 - - out += " " * indent - out += print_symbol(symr) - out += "\n" - - if symr.st in [EcoffSt.FILE, EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.PROC, EcoffSt.STATICPROC, EcoffSt.BLOCK]: - indent += 2 - - return out - - def __str__(self) -> str: - return f"""= EcoffFdr =============== -adr = 0x{self.adr:08X} -rss = 0x{self.rss:08X} -issBase = 0x{self.issBase:08X} -cbSs = 0x{self.cbSs:08X} -isymBase = 0x{self.isymBase:08X} -csym = 0x{self.csym:08X} -ilineBase = 0x{self.ilineBase:08X} -cline = 0x{self.cline:08X} -ioptBase = 0x{self.ioptBase:08X} -copt = 0x{self.copt:08X} -ipdFirst = 0x{self.ipdFirst:08X} -cpd = 0x{self.cpd:08X} -iauxBase = 0x{self.iauxBase:08X} -caux = 0x{self.caux:08X} -rfdBase = 0x{self.rfdBase:08X} -crfd = 0x{self.crfd:08X} -lang = {self.lang.name} -fMerge = {bool(self.fMerge)} -fReadin = {bool(self.fReadin)} -fBigEndian = {bool(self.fBigEndian)} -glevel = {self.glevel} -_reserved = {self._reserved} -cbLineOffset = 0x{self.cbLineOffset:08X} -cbLine = 0x{self.cbLine:08X} -name = {self.name}""" - -class EcoffHDRR: - """ - Symbolic Header - - typedef struct sHDRR { - u16 magic; /* 0x7009 */ - u16 vstamp; /* version stamp */ - s32 ilineMax; /* number of line number entries */ - s32 cbLine; /* number of bytes for line number entries */ - s32 cbLineOffset; /* offset to start of line number entries */ - s32 idnMax; /* max index into dense number table */ - s32 cbDnOffset; /* offset to start dense number table */ - s32 ipdMax; /* number of procedures */ - s32 cbPdOffset; /* offset to procedure descriptor table */ - s32 isymMax; /* number of local symbols */ - s32 cbSymOffset; /* offset to start of local symbols */ - s32 ioptMax; /* max index into optimization symbol entries */ - s32 cbOptOffset; /* offset to optimization symbol entries */ - s32 iauxMax; /* number of auxillary symbol entries */ - s32 cbAuxOffset; /* offset to start of auxillary symbol entries */ - s32 issMax; /* max index into local strings */ - s32 cbSsOffset; /* offset to start of local strings */ - s32 issExtMax; /* max index into external strings */ - s32 cbSsExtOffset; /* offset to start of external strings */ - s32 ifdMax; /* number of file descriptor entries */ - s32 cbFdOffset; /* offset to file descriptor table */ - s32 crfd; /* number of relative file descriptor entries */ - s32 cbRfdOffset; /* offset to relative file descriptor table */ - s32 iextMax; /* max index into external symbols */ - s32 cbExtOffset; /* offset to start of external symbol entries */ - } tHDRR, *pHDRR; // size = 0x60 - """ - HDRR_MAGIC = 0x7009 - SIZE = 0x60 - - def __init__(self, data) -> None: - self.data = data[:EcoffHDRR.SIZE] - - self.magic, self.vstamp, self.ilineMax, self.cbLine, \ - self.cbLineOffset, self.idnMax, self.cbDnOffset, self.ipdMax, \ - self.cbPdOffset, self.isymMax, self.cbSymOffset, self.ioptMax, \ - self.cbOptOffset, self.iauxMax, self.cbAuxOffset, self.issMax, \ - self.cbSsOffset, self.issExtMax, self.cbSsExtOffset, self.ifdMax, \ - self.cbFdOffset, self.crfd, self.cbRfdOffset, self.iextMax, \ - self.cbExtOffset = struct.unpack(">HHIIIIIIIIIIIIIIIIIIIIIII", self.data) - - assert self.magic == EcoffHDRR.HDRR_MAGIC , f"Symbolic Header magic value is incorrect. Got 0x{self.magic:04X}, expected 0x{EcoffHDRR.HDRR_MAGIC:04X}" - - def __str__(self) -> str: - return f"""= EcoffHDRR ============== -magic = 0x{self.magic:04X} -vstamp = 0x{self.vstamp:04X} -ilineMax = 0x{self.ilineMax:08X} -cbLine = 0x{self.cbLine:08X} -cbLineOffset = 0x{self.cbLineOffset:08X} -idnMax = 0x{self.idnMax:08X} -cbDnOffset = 0x{self.cbDnOffset:08X} -ipdMax = 0x{self.ipdMax:08X} -cbPdOffset = 0x{self.cbPdOffset:08X} -isymMax = 0x{self.isymMax:08X} -cbSymOffset = 0x{self.cbSymOffset:08X} -ioptMax = 0x{self.ioptMax:08X} -cbOptOffset = 0x{self.cbOptOffset:08X} -iauxMax = 0x{self.iauxMax:08X} -cbAuxOffset = 0x{self.cbAuxOffset:08X} -issMax = 0x{self.issMax:08X} -cbSsOffset = 0x{self.cbSsOffset:08X} -issExtMax = 0x{self.issExtMax:08X} -cbSsExtOffset = 0x{self.cbSsExtOffset:08X} -ifdMax = 0x{self.ifdMax:08X} -cbFdOffset = 0x{self.cbFdOffset:08X} -crfd = 0x{self.crfd:08X} -cbRfdOffset = 0x{self.cbRfdOffset:08X} -iextMax = 0x{self.iextMax:08X} -cbExtOffset = 0x{self.cbExtOffset:08X}""" diff --git a/lib/ultralib/tools/mips_isa.py b/lib/ultralib/tools/mips_isa.py deleted file mode 100644 index d99dcda..0000000 --- a/lib/ultralib/tools/mips_isa.py +++ /dev/null @@ -1,1309 +0,0 @@ -# TODO enum these constants -from enum import IntEnum, auto - -# Register IDs -class MipsGPReg(IntEnum): - R0 = 0 # 0 - AT = auto() # 1 - V0 = auto() # 2 - V1 = auto() # 3 - A0 = auto() # 4 - A1 = auto() # 5 - A2 = auto() # 6 - A3 = auto() # 7 - T0 = auto() # 8 - T1 = auto() # 9 - T2 = auto() # 10 - T3 = auto() # 11 - T4 = auto() # 12 - T5 = auto() # 13 - T6 = auto() # 14 - T7 = auto() # 15 - S0 = auto() # 16 - S1 = auto() # 17 - S2 = auto() # 18 - S3 = auto() # 19 - S4 = auto() # 20 - S5 = auto() # 21 - S6 = auto() # 22 - S7 = auto() # 23 - T8 = auto() # 24 - T9 = auto() # 25 - K0 = auto() # 26 - K1 = auto() # 27 - GP = auto() # 28 - SP = auto() # 29 - FP = auto() # 30 - RA = auto() # 31 - -class MipsFPReg(IntEnum): - F0 = 0 # 0 - F1 = auto() # 1 - F2 = auto() # 2 - F3 = auto() # 3 - F4 = auto() # 4 - F5 = auto() # 5 - F6 = auto() # 6 - F7 = auto() # 7 - F8 = auto() # 8 - F9 = auto() # 9 - F10 = auto() # 10 - F11 = auto() # 11 - F12 = auto() # 12 - F13 = auto() # 13 - F14 = auto() # 14 - F15 = auto() # 15 - F16 = auto() # 16 - F17 = auto() # 17 - F18 = auto() # 18 - F19 = auto() # 19 - F20 = auto() # 20 - F21 = auto() # 21 - F22 = auto() # 22 - F23 = auto() # 23 - F24 = auto() # 24 - F25 = auto() # 25 - F26 = auto() # 26 - F27 = auto() # 27 - F28 = auto() # 28 - F29 = auto() # 29 - F30 = auto() # 30 - F31 = auto() # 31 - -# Instruction Unique IDs -MIPS_INS_SLL = 0 -MIPS_INS_SRL = 1 -MIPS_INS_SRA = 2 -MIPS_INS_SLLV = 3 -MIPS_INS_SRLV = 4 -MIPS_INS_SRAV = 5 -MIPS_INS_JR = 6 -MIPS_INS_JALR = 7 -MIPS_INS_SYSCALL = 8 -MIPS_INS_BREAK = 9 -MIPS_INS_SYNC = 10 -MIPS_INS_MFHI = 11 -MIPS_INS_MTHI = 12 -MIPS_INS_MFLO = 13 -MIPS_INS_MTLO = 14 -MIPS_INS_DSLLV = 15 -MIPS_INS_DSRLV = 16 -MIPS_INS_DSRAV = 17 -MIPS_INS_MULT = 18 -MIPS_INS_MULTU = 19 -MIPS_INS_DIV = 20 -MIPS_INS_DIVU = 21 -MIPS_INS_DMULT = 22 -MIPS_INS_DMULTU = 23 -MIPS_INS_DDIV = 24 -MIPS_INS_DDIVU = 25 -MIPS_INS_ADD = 26 -MIPS_INS_ADDU = 27 -MIPS_INS_SUB = 28 -MIPS_INS_SUBU = 29 -MIPS_INS_AND = 30 -MIPS_INS_OR = 31 -MIPS_INS_XOR = 32 -MIPS_INS_NOR = 33 -MIPS_INS_SLT = 34 -MIPS_INS_SLTU = 35 -MIPS_INS_DADD = 36 -MIPS_INS_DADDU = 37 -MIPS_INS_DSUB = 38 -MIPS_INS_DSUBU = 39 -MIPS_INS_TGE = 40 -MIPS_INS_TGEU = 41 -MIPS_INS_TLT = 42 -MIPS_INS_TLTU = 43 -MIPS_INS_TEQ = 44 -MIPS_INS_TNE = 45 -MIPS_INS_DSLL = 46 -MIPS_INS_DSRL = 47 -MIPS_INS_DSRA = 48 -MIPS_INS_DSLL32 = 49 -MIPS_INS_DSRL32 = 50 -MIPS_INS_DSRA32 = 51 -MIPS_INS_BLTZ = 52 -MIPS_INS_BGEZ = 53 -MIPS_INS_BLTZL = 54 -MIPS_INS_BGEZL = 55 -MIPS_INS_TGEI = 56 -MIPS_INS_TGEIU = 57 -MIPS_INS_TLTI = 58 -MIPS_INS_TLTIU = 59 -MIPS_INS_TEQI = 60 -MIPS_INS_TNEI = 61 -MIPS_INS_BLTZAL = 62 -MIPS_INS_BGEZAL = 63 -MIPS_INS_BLTZALL = 64 -MIPS_INS_BGEZALL = 65 -MIPS_INS_J = 66 -MIPS_INS_JAL = 67 -MIPS_INS_BEQ = 68 -MIPS_INS_BNE = 69 -MIPS_INS_BLEZ = 70 -MIPS_INS_BGTZ = 71 -MIPS_INS_ADDI = 72 -MIPS_INS_ADDIU = 73 -MIPS_INS_SLTI = 74 -MIPS_INS_SLTIU = 75 -MIPS_INS_ANDI = 76 -MIPS_INS_ORI = 77 -MIPS_INS_XORI = 78 -MIPS_INS_LUI = 79 -MIPS_INS_MFC0 = 80 -MIPS_INS_MTC0 = 81 -MIPS_INS_TLBR = 82 -MIPS_INS_TLBWI = 83 -MIPS_INS_TLBWR = 84 -MIPS_INS_TLBP = 85 -MIPS_INS_ERET = 86 -MIPS_INS_MFC1 = 87 -MIPS_INS_DMFC1 = 88 -MIPS_INS_CFC1 = 89 -MIPS_INS_MTC1 = 90 -MIPS_INS_DMTC1 = 91 -MIPS_INS_CTC1 = 92 -MIPS_INS_BC1F = 93 -MIPS_INS_BC1T = 94 -MIPS_INS_BC1FL = 95 -MIPS_INS_BC1TL = 96 -MIPS_INS_ADD_S = 97 -MIPS_INS_SUB_S = 98 -MIPS_INS_MUL_S = 99 -MIPS_INS_DIV_S = 100 -MIPS_INS_SQRT_S = 101 -MIPS_INS_ABS_S = 102 -MIPS_INS_MOV_S = 103 -MIPS_INS_NEG_S = 104 -MIPS_INS_ROUND_L_S = 105 -MIPS_INS_TRUNC_L_S = 106 -MIPS_INS_CEIL_L_S = 107 -MIPS_INS_FLOOR_L_S = 108 -MIPS_INS_ROUND_W_S = 109 -MIPS_INS_TRUNC_W_S = 110 -MIPS_INS_CEIL_W_S = 111 -MIPS_INS_FLOOR_W_S = 112 -MIPS_INS_CVT_D_S = 113 -MIPS_INS_CVT_W_S = 114 -MIPS_INS_CVT_L_S = 115 -MIPS_INS_C_F_S = 116 -MIPS_INS_C_UN_S = 117 -MIPS_INS_C_EQ_S = 118 -MIPS_INS_C_UEQ_S = 119 -MIPS_INS_C_OLT_S = 120 -MIPS_INS_C_ULT_S = 121 -MIPS_INS_C_OLE_S = 122 -MIPS_INS_C_ULE_S = 123 -MIPS_INS_C_SF_S = 124 -MIPS_INS_C_NGLE_S = 125 -MIPS_INS_C_SEQ_S = 126 -MIPS_INS_C_NGL_S = 127 -MIPS_INS_C_LT_S = 128 -MIPS_INS_C_NGE_S = 129 -MIPS_INS_C_LE_S = 130 -MIPS_INS_C_NGT_S = 131 -MIPS_INS_ADD_D = 132 -MIPS_INS_SUB_D = 133 -MIPS_INS_MUL_D = 134 -MIPS_INS_DIV_D = 135 -MIPS_INS_SQRT_D = 136 -MIPS_INS_ABS_D = 137 -MIPS_INS_MOV_D = 138 -MIPS_INS_NEG_D = 139 -MIPS_INS_ROUND_L_D = 140 -MIPS_INS_TRUNC_L_D = 141 -MIPS_INS_CEIL_L_D = 142 -MIPS_INS_FLOOR_L_D = 143 -MIPS_INS_ROUND_W_D = 144 -MIPS_INS_TRUNC_W_D = 145 -MIPS_INS_CEIL_W_D = 146 -MIPS_INS_FLOOR_W_D = 147 -MIPS_INS_CVT_S_D = 148 -MIPS_INS_CVT_W_D = 149 -MIPS_INS_CVT_L_D = 150 -MIPS_INS_C_F_D = 151 -MIPS_INS_C_UN_D = 152 -MIPS_INS_C_EQ_D = 153 -MIPS_INS_C_UEQ_D = 154 -MIPS_INS_C_OLT_D = 155 -MIPS_INS_C_ULT_D = 156 -MIPS_INS_C_OLE_D = 157 -MIPS_INS_C_ULE_D = 158 -MIPS_INS_C_SF_D = 159 -MIPS_INS_C_NGLE_D = 160 -MIPS_INS_C_SEQ_D = 161 -MIPS_INS_C_NGL_D = 162 -MIPS_INS_C_LT_D = 163 -MIPS_INS_C_NGE_D = 164 -MIPS_INS_C_LE_D = 165 -MIPS_INS_C_NGT_D = 166 -MIPS_INS_CVT_S_W = 167 -MIPS_INS_CVT_D_W = 168 -MIPS_INS_CVT_S_L = 169 -MIPS_INS_CVT_D_L = 170 -MIPS_INS_BEQL = 171 -MIPS_INS_BNEL = 172 -MIPS_INS_BLEZL = 173 -MIPS_INS_BGTZL = 174 -MIPS_INS_DADDI = 175 -MIPS_INS_DADDIU = 176 -MIPS_INS_LDL = 177 -MIPS_INS_LDR = 178 -MIPS_INS_LB = 179 -MIPS_INS_LH = 180 -MIPS_INS_LWL = 181 -MIPS_INS_LW = 182 -MIPS_INS_LBU = 183 -MIPS_INS_LHU = 184 -MIPS_INS_LWR = 185 -MIPS_INS_LWU = 186 -MIPS_INS_SB = 187 -MIPS_INS_SH = 188 -MIPS_INS_SWL = 189 -MIPS_INS_SW = 190 -MIPS_INS_SDL = 191 -MIPS_INS_SDR = 192 -MIPS_INS_SWR = 193 -MIPS_INS_CACHE = 194 -MIPS_INS_LL = 195 -MIPS_INS_LWC1 = 196 -MIPS_INS_LWC2 = 197 -MIPS_INS_LLD = 198 -MIPS_INS_LDC1 = 199 -MIPS_INS_LDC2 = 200 -MIPS_INS_LD = 201 -MIPS_INS_SC = 202 -MIPS_INS_SWC1 = 203 -MIPS_INS_SWC2 = 204 -MIPS_INS_SCD = 205 -MIPS_INS_SDC1 = 206 -MIPS_INS_SDC2 = 207 -MIPS_INS_SD = 208 - -# RSP COP2 -MIPS_INS_VMULF = 209 -MIPS_INS_VMULU = 210 -MIPS_INS_VRNDP = 211 -MIPS_INS_VMULQ = 212 -MIPS_INS_VMUDL = 213 -MIPS_INS_VMUDM = 214 -MIPS_INS_VMUDN = 215 -MIPS_INS_VMUDH = 216 -MIPS_INS_VMACF = 217 -MIPS_INS_VMACU = 218 -MIPS_INS_VRNDN = 219 -MIPS_INS_VMACQ = 220 -MIPS_INS_VMADL = 221 -MIPS_INS_VMADM = 222 -MIPS_INS_VMADN = 223 -MIPS_INS_VMADH = 224 -MIPS_INS_VADD = 225 -MIPS_INS_VSUB = 226 -MIPS_INS_VABS = 227 -MIPS_INS_VADDC = 228 -MIPS_INS_VSUBC = 229 -MIPS_INS_VSAR = 230 -MIPS_INS_VLT = 231 -MIPS_INS_VEQ = 232 -MIPS_INS_VNE = 233 -MIPS_INS_VGE = 234 -MIPS_INS_VCL = 235 -MIPS_INS_VCH = 236 -MIPS_INS_VCR = 237 -MIPS_INS_VMRG = 238 -MIPS_INS_VAND = 239 -MIPS_INS_VNAND = 240 -MIPS_INS_VOR = 241 -MIPS_INS_VNOR = 242 -MIPS_INS_VXOR = 243 -MIPS_INS_VNXOR = 244 -MIPS_INS_VRCP = 245 -MIPS_INS_VRCPL = 246 -MIPS_INS_VRCPH = 247 -MIPS_INS_VMOV = 248 -MIPS_INS_VRSQ = 249 -MIPS_INS_VRSQL = 250 -MIPS_INS_VRSQH = 251 -MIPS_INS_VNOP = 252 -MIPS_INS_LBV = 253 -MIPS_INS_LSV = 254 -MIPS_INS_LLV = 255 -MIPS_INS_LDV = 256 -MIPS_INS_LQV = 257 -MIPS_INS_LRV = 258 -MIPS_INS_LPV = 259 -MIPS_INS_LUV = 260 -MIPS_INS_LHV = 261 -MIPS_INS_LFV = 262 -MIPS_INS_LTV = 263 -MIPS_INS_SBV = 264 -MIPS_INS_SSV = 265 -MIPS_INS_SLV = 266 -MIPS_INS_SDV = 267 -MIPS_INS_SQV = 268 -MIPS_INS_SRV = 269 -MIPS_INS_SPV = 270 -MIPS_INS_SUV = 271 -MIPS_INS_SHV = 272 -MIPS_INS_SFV = 273 -MIPS_INS_SWV = 274 -MIPS_INS_STV = 275 -MIPS_INS_MFC2 = 276 -MIPS_INS_MTC2 = 277 -MIPS_INS_CFC2 = 278 -MIPS_INS_CTC2 = 279 - -# Pseudo-Instruction Unique IDs -MIPS_INS_BEQZ = 280 -MIPS_INS_BNEZ = 281 -MIPS_INS_B = 282 -MIPS_INS_NOP = 283 -MIPS_INS_MOVE = 284 -MIPS_INS_NEGU = 285 -MIPS_INS_NOT = 286 - -# Invalid Instruction Unique ID -MIPS_INS_INVALID = -1 - -# Op IDs -# MIPS_OP_RS = 0 -# MIPS_OP_RT = 0 -# MIPS_OP_RD = 0 -# MIPS_OP_IMM = 0 - -# Instruction Groups - -MIPS_BRANCH_LIKELY_INSNS = [ - MIPS_INS_BEQL, MIPS_INS_BGEZALL, - MIPS_INS_BGEZL, MIPS_INS_BGTZL, - MIPS_INS_BLEZL, MIPS_INS_BLTZALL, - MIPS_INS_BLTZL, MIPS_INS_BNEL, - MIPS_INS_BC1TL, MIPS_INS_BC1FL, -] - -MIPS_BRANCH_INSNS = [ - *MIPS_BRANCH_LIKELY_INSNS, - - MIPS_INS_BEQ, - MIPS_INS_BGEZ, MIPS_INS_BGEZAL, - MIPS_INS_BGTZ, - MIPS_INS_BNE, - MIPS_INS_BLTZ, MIPS_INS_BLTZAL, - MIPS_INS_BLEZ, - MIPS_INS_BC1T, MIPS_INS_BC1F, - - MIPS_INS_BEQZ, - MIPS_INS_BNEZ, - MIPS_INS_B, -] - -MIPS_JUMP_INSNS = [ - MIPS_INS_JAL, MIPS_INS_JALR, MIPS_INS_J, MIPS_INS_JR -] - -MIPS_DELAY_SLOT_INSNS = [ - *MIPS_BRANCH_INSNS, *MIPS_JUMP_INSNS -] - -MIPS_FP_LOAD_INSNS = [ - MIPS_INS_LWC1, MIPS_INS_LDC1 -] - -MIPS_LOAD_INSNS = [ - MIPS_INS_LB, MIPS_INS_LBU, - MIPS_INS_LH, MIPS_INS_LHU, - MIPS_INS_LW, MIPS_INS_LWL, MIPS_INS_LWR, MIPS_INS_LWU, - MIPS_INS_LD, MIPS_INS_LDL, MIPS_INS_LDR, - MIPS_INS_LL, MIPS_INS_LLD, - *MIPS_FP_LOAD_INSNS -] - -MIPS_FP_STORE_INSNS = [ - MIPS_INS_SWC1, MIPS_INS_SDC1 -] - -MIPS_STORE_INSNS = [ - MIPS_INS_SB, - MIPS_INS_SH, - MIPS_INS_SW, MIPS_INS_SWL, MIPS_INS_SWR, - MIPS_INS_SD, MIPS_INS_SDL, MIPS_INS_SDR, - MIPS_INS_SC, MIPS_INS_SCD, - *MIPS_FP_STORE_INSNS -] - -MIPS_LOAD_STORE_INSNS = [ - *MIPS_LOAD_INSNS, - *MIPS_STORE_INSNS, -] - -MIPS_FP_LOAD_STORE_INSNS = [ - *MIPS_FP_LOAD_INSNS, *MIPS_FP_STORE_INSNS -] - -RSP_VECTOR_LOAD_STORES = [ - MIPS_INS_LBV, MIPS_INS_LSV, MIPS_INS_LLV, MIPS_INS_LDV, - MIPS_INS_LQV, MIPS_INS_LRV, MIPS_INS_LPV, MIPS_INS_LUV, - MIPS_INS_LHV, MIPS_INS_LFV, MIPS_INS_LTV, - - MIPS_INS_SBV, MIPS_INS_SSV, MIPS_INS_SLV, MIPS_INS_SDV, - MIPS_INS_SQV, MIPS_INS_SRV, MIPS_INS_SPV, MIPS_INS_SUV, - MIPS_INS_SHV, MIPS_INS_SFV, MIPS_INS_SWV, MIPS_INS_STV, -] - -# Labels - -# These labels can be referenced from pointers/loads/stores/etc. -LABEL_TYPE_FUNC = 0 -LABEL_TYPE_JTBL = 1 -LABEL_TYPE_DATA = 2 -LABEL_TYPE_BRANCH = 3 - -# Unknown -LABEL_TYPE_UNK = 20 - -class MipsLabel: - """ - Label - """ - - def __init__(self, vaddr, name=None, lbl_type=LABEL_TYPE_UNK, is_global=None) -> None: - self.name = name - self.vaddr = vaddr - self.lbl_type = lbl_type - self.is_global = is_global or (False if (lbl_type == LABEL_TYPE_BRANCH) else True) - - def __str__(self): - if self.name is not None: - return self.name - - if self.lbl_type == LABEL_TYPE_FUNC: - return f"func_{self.vaddr:08X}" - elif self.lbl_type == LABEL_TYPE_JTBL: - return f"jtbl_{self.vaddr:08X}" - elif self.lbl_type == LABEL_TYPE_BRANCH: - return f".L{self.vaddr:08X}" - elif (self.lbl_type == LABEL_TYPE_DATA or self.lbl_type == LABEL_TYPE_UNK): - return f"D_{self.vaddr:08X}" - assert False , f"Unimplemented default name for label type {self.lbl_type}" - -# Register Names - -mips_gpr_names = ( - "$zero", - "$at", - "$v0", "$v1", - "$a0", "$a1", "$a2", "$a3", - "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", - "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", - "$t8", "$t9", - "$k0", "$k1", - "$gp", - "$sp", - "$fp", - "$ra", -) - -rsp_gpr_names = ( - "$zero", - "$1", "$2", "$3", "$4", "$5", "$6", - "$7", "$8", "$9", "$10", "$11", "$12", - "$13", "$14", "$15", "$16", "$17", "$18", - "$19", "$20", "$21", "$22", "$23", "$24", - "$25", "$26", "$27", "$28", "$29", "$30", - "$ra", -) - -mips_cop0_names = ( - "Index" , "Random" , "EntryLo0" , "EntryLo1" , - "Context" , "PageMask" , "Wired" , "Reserved07", - "BadVaddr" , "Count" , "EntryHi" , "Compare" , - "Status" , "Cause" , "EPC" , "PRevID" , - "Config" , "LLAddr" , "WatchLo" , "WatchHi" , - "XContext" , "Reserved21", "Reserved22", "Reserved23", - "Reserved24", "Reserved25", "PErr" , "CacheErr" , - "TagLo" , "TagHi" , "ErrorEPC" , "Reserved31", -) - -rsp_cop0_names = ( - "SP_MEM_ADDR", "SP_DRAM_ADDR", "SP_RD_LEN" , "SP_WR_LEN" , - "SP_STATUS" , "SP_DMA_FULL" , "SP_DMA_BUSY" , "SP_SEMAPHORE", - "DPC_START" , "DPC_END" , "DPC_CURRENT" , "DPC_STATUS" , - "DPC_CLOCK" , "DPC_BUFBUSY" , "DPC_PIPEBUSY", "DPC_TMEM" , -) - -mips_cop1_names = ( - "$f0", "$f1", "$f2", "$f3", - "$f4", "$f5", "$f6", "$f7", "$f8", "$f9", "$f10", "$f11", - "$f12", "$f13", "$f14", "$f15", - "$f16", "$f17", "$f18", "$f19", - "$f20", "$f21", "$f22", "$f23", "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", - # Status register - "FpCsr", -) - -rsp_cop2_names = ( - "$v0", "$v1", "$v2", "$v3", "$v4", "$v5", "$v6", "$v7", - "$v8", "$v9", "$v10", "$v11", "$v12", "$v13", "$v14", "$v15", - "$v16", "$v17", "$v18", "$v19", "$v20", "$v21", "$v22", "$v23", - "$v24", "$v25", "$v26", "$v27", "$v28", "$v29", "$v30", "$v31", -) - -rsp_cop2_ctrl_names = ( - '$vco', '$vcc', '$vce' -) - -# Instruction sets - -class MipsAbi: - def __init__(self, name, gpr_names, cop0_names, cop1_names, cop2_names): - self.name = name - self.gpr_names, self.cop0_names, self.cop1_names, self.cop2_names = \ - gpr_names, cop0_names, cop1_names, cop2_names - -ABI_VR4300 = MipsAbi("VR4300", mips_gpr_names, mips_cop0_names, mips_cop1_names, None ) -ABI_RSP = MipsAbi("RSP", rsp_gpr_names, rsp_cop0_names, None, rsp_cop2_names) - -# Instruction field fetching - -def sign_extend_6(value): - if value & (1 << (6 - 1)): - return value - (1 << 6) - return value - -def sign_extend_16(value): - return (value & 0x7FFF) - (value & 0x8000) - -def mask_shift(v, s, w): - return (v >> s) & ((1 << w) - 1) - -mips_get_field = lambda raw,vaddr : mask_shift(raw, 26, 6) -mips_get_special = lambda raw,vaddr : mask_shift(raw, 0, 6) -mips_get_cop0 = lambda raw,vaddr : mask_shift(raw, 21, 5) -mips_get_cop1 = lambda raw,vaddr : mask_shift(raw, 21, 5) -mips_get_cop2 = lambda raw,vaddr : mask_shift(raw, 21, 4) -mips_get_regimm = lambda raw,vaddr : mask_shift(raw, 16, 5) -mips_get_tlb = lambda raw,vaddr : mask_shift(raw, 0, 5) -mips_get_function = lambda raw,vaddr : mask_shift(raw, 0, 6) - -mips_get_cond = lambda raw,vaddr : mask_shift(raw, 0, 4) -mips_get_fd = lambda raw,vaddr : MipsFPReg(mask_shift(raw, 6, 5)) -mips_get_fs = lambda raw,vaddr : MipsFPReg(mask_shift(raw, 11, 5)) -mips_get_ft = lambda raw,vaddr : MipsFPReg(mask_shift(raw, 16, 5)) -mips_get_fmt = lambda raw,vaddr : mask_shift(raw, 21, 5) -mips_get_ndtf = lambda raw,vaddr : mask_shift(raw, 16, 2) - -mips_get_target = lambda raw,vaddr : ((vaddr & 0xFC000000) | (mask_shift(raw, 0, 26) << 2)) -mips_get_offset = lambda raw,vaddr : vaddr + 4 + sign_extend_16(mask_shift(raw, 0, 16)) * 4 -mips_get_imm = lambda raw,vaddr : mask_shift(raw, 0, 16) - -mips_get_base = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 21, 5)) - -mips_get_cd = lambda raw,vaddr : mask_shift(raw, 11, 5) - -mips_get_code = lambda raw,vaddr : (mask_shift(raw, 6, 20) << 6) >> 16 -mips_get_op = lambda raw,vaddr : mask_shift(raw, 16, 5) - -mips_get_sa = lambda raw,vaddr : mask_shift(raw, 6, 5) - -mips_get_rd = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 11, 5)) -mips_get_rs = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 21, 5)) -mips_get_rt = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 16, 5)) - -rsp_load_store_multiplier = { - 0b00000 : 0x01, # lbv, sbv - 0b00001 : 0x02, # lsv, ssv - 0b00010 : 0x04, # llv, slv - 0b00011 : 0x08, # ldv, sdv - 0b00100 : 0x10, # lqv, sqv - 0b00101 : 0x10, # lrv, srv - 0b00110 : 0x08, # lpv, spv - 0b00111 : 0x08, # luv, suv - - 0b01000 : 0x02, # lhv, shv - 0b01001 : 0x04, # lfv, sfv - 0b01010 : 0x10, # swv - 0b01011 : 0x10, # ltv, stv -} - -mips_get_vc = lambda raw,vaddr : mask_shift(raw, 11, 5) -mips_get_vd = lambda raw,vaddr : mask_shift(raw, 6, 5) -mips_get_vs = lambda raw,vaddr : mask_shift(raw, 11, 5) -mips_get_vt = lambda raw,vaddr : mask_shift(raw, 16, 5) -mips_get_elem = lambda raw,vaddr : mask_shift(raw, 21, 4) -mips_get_elemd = lambda raw,vaddr : mask_shift(raw, 7, 4) -mips_get_cop2_func = lambda raw,vaddr : mask_shift(raw, 25, 1) -mips_get_lwc2 = lambda raw,vaddr : mask_shift(raw, 11, 5) -mips_get_swc2 = lambda raw,vaddr : mask_shift(raw, 11, 5) -mips_get_voffset = lambda raw,vaddr : sign_extend_6(mask_shift(raw, 0, 6)) * rsp_load_store_multiplier[mips_get_lwc2(raw,vaddr)] - -# Formatting - -def resolve_pseudo_insn(insn): - # move varies between assemblers - # IDO - move_insn = MIPS_INS_OR - # GCC - # move_insn = MIPS_INS_ADDU - - if insn.id == MIPS_INS_SLL and insn.rd == MipsGPReg.R0 and insn.rt == MipsGPReg.R0 and insn.sa == 0: - return MIPS_INS_NOP, "nop", (), () - elif insn.id == MIPS_INS_BEQ and insn.rs == MipsGPReg.R0 and insn.rt == MipsGPReg.R0: - return MIPS_INS_B, "b", ("offset",), (False,) - elif insn.id == move_insn and insn.rt == MipsGPReg.R0: - return MIPS_INS_MOVE, "move", ("rd","rs"), (True,False) - elif insn.id == MIPS_INS_BEQ and insn.rt == MipsGPReg.R0: - return MIPS_INS_BEQZ, "beqz", ("rs","offset"), (False,False) - elif insn.id == MIPS_INS_BNE and insn.rt == MipsGPReg.R0: - return MIPS_INS_BNEZ, "bnez", ("rs","offset"), (False,False) - elif insn.id == MIPS_INS_SUBU and insn.rs == MipsGPReg.R0: - return MIPS_INS_NEGU, "negu", ("rd","rt"), (True,False) - elif insn.id == MIPS_INS_NOR and insn.rt == MipsGPReg.R0: - return MIPS_INS_NOT, "not", ("rd","rs"), (True,False) - else: - return insn.id, insn.mnemonic, insn.fields, insn.writes - -def format_hex(v, signed, zeros, no_zero): - if abs(v) < 10: - if v == 0 and no_zero: - return "" - return f"{v}" - elif not signed: - return f"0x{v:{f'0{zeros}' if zeros > 0 else ''}x}" - else: - return f"{v:#x}" - -def format_vector_elem(insn, elem): - if insn.id in RSP_VECTOR_LOAD_STORES: - return f"[{elem}]" - elif (elem & 8) == 8: - return f"[{elem & 7}]" - elif (elem & 0xC) == 4: - return f"[{elem & 3}h]" - elif (elem & 0xE) == 2: - return f"[{elem & 1}q]" - else: - return "" - -mips_field_formatters = { - 'code' : (lambda insn : f'{insn.code}' if insn.code != 0 else ''), - 'cd' : (lambda insn : insn.abi.cop0_names[insn.cd]), - 'rd' : (lambda insn : insn.abi.gpr_names[insn.rd]), - 'rs' : (lambda insn : insn.abi.gpr_names[insn.rs]), - 'rt' : (lambda insn : insn.abi.gpr_names[insn.rt]), - 'fd' : (lambda insn : insn.abi.cop1_names[insn.fd]), - 'fs' : (lambda insn : insn.abi.cop1_names[insn.fs]), - 'ft' : (lambda insn : insn.abi.cop1_names[insn.ft]), - 'sa' : (lambda insn : format_hex(insn.sa, True, 0, False)), - 'op' : (lambda insn : format_hex(insn.op, False, 0, False)), - 'imm' : (lambda insn : format_hex(insn.imm, True, 0, False)), - 'offset(base)' : (lambda insn : f'{format_hex(insn.imm, True, 0, True)}({insn.abi.gpr_names[insn.base]})'), - 'offset' : (lambda insn : f'{format_hex(insn.offset, True, 0, False)}'), - 'target' : (lambda insn : f'{format_hex(insn.target, False, 0, False)}'), - 'vd' : (lambda insn : insn.abi.cop2_names[insn.vd]), - 'vs' : (lambda insn : insn.abi.cop2_names[insn.vs]), - 'vt' : (lambda insn : insn.abi.cop2_names[insn.vt]), - 'vt[e]' : (lambda insn : f"{insn.abi.cop2_names[insn.vt]}{format_vector_elem(insn, insn.elem)}"), - 'vt[ed]' : (lambda insn : f"{insn.abi.cop2_names[insn.vt]}{format_vector_elem(insn, insn.elemd)}"), - 'vd[e]' : (lambda insn : f"{insn.abi.cop2_names[insn.vd]}{format_vector_elem(insn, insn.elem)}"), - 'vd[ed]' : (lambda insn : f"{insn.abi.cop2_names[insn.vd]}{format_vector_elem(insn, insn.elemd)}"), - 'voffset' : (lambda insn : f'{format_hex(insn.voffset, True, 0, False)}'), - 'voffset(base)' : (lambda insn : f'{format_hex(insn.voffset, True, 0, True)}({insn.abi.gpr_names[insn.base]})'), - 'vc' : (lambda insn : rsp_cop2_ctrl_names[insn.vc]) -} - -class MipsInsn: - - def __init__(self, abi, raw, vaddr, values): - self.abi = abi - self.raw = raw - self.vaddr = vaddr - - if values is None: - values = MIPS_INS_INVALID, f"/* Invalid Instruction */ .4byte 0x{raw:08X}", (), () - - self.id, self.mnemonic, self.fields, self.writes = values - - # self.code = self.sa = self.op = self.cd = self.rd = self.rs = self.rt = self.fd = self.fs = self.ft = self.imm = self.offset = self.base = self.target = None - - for field in self.fields: - self.set_value(field) - - self.id, self.mnemonic, self.fields, self.writes = resolve_pseudo_insn(self) - - self.op_str = self.format_insn() - - def read_fields(self): - return [field for i,field in enumerate(self.fields) if self.writes[i] == False] - - def write_fields(self): - return [field for i,field in enumerate(self.fields) if self.writes[i] == True] - - def has_field(self, field): - return field in self.fields - - def format_field(self, field): - return mips_field_formatters[field](self) - - def format_insn(self): - return ", ".join([self.format_field(field) for field in self.fields]) - - def __str__(self): - return f"{self.mnemonic:12}{self.op_str}" - - # Field setters - - def set_code(self): - self.code = mips_get_code(self.raw, self.vaddr) - - def set_sa(self): - self.sa = mips_get_sa(self.raw, self.vaddr) - - def set_op(self): - self.op = mips_get_op(self.raw, self.vaddr) - - def set_cd(self): - self.cd = mips_get_cd(self.raw, self.vaddr) - - def set_rd(self): - self.rd = mips_get_rd(self.raw, self.vaddr) - - def set_rs(self): - self.rs = mips_get_rs(self.raw, self.vaddr) - - def set_rt(self): - self.rt = mips_get_rt(self.raw, self.vaddr) - - def set_fd(self): - self.fd = mips_get_fd(self.raw, self.vaddr) - - def set_fs(self): - self.fs = mips_get_fs(self.raw, self.vaddr) - - def set_ft(self): - self.ft = mips_get_ft(self.raw, self.vaddr) - - do_sign_extend = [ - MIPS_INS_ADDIU, MIPS_INS_SLTI, MIPS_INS_ADDI, MIPS_INS_DADDIU, - MIPS_INS_LB, MIPS_INS_LBU, - MIPS_INS_LH, MIPS_INS_LHU, - MIPS_INS_LW, MIPS_INS_LWL, MIPS_INS_LWR, MIPS_INS_LWU, - MIPS_INS_LWC1, - MIPS_INS_LD, MIPS_INS_LDL, MIPS_INS_LDR, - MIPS_INS_LDC1, - MIPS_INS_LL, MIPS_INS_LLD, - MIPS_INS_SB, - MIPS_INS_SH, - MIPS_INS_SW, MIPS_INS_SWL, MIPS_INS_SWR, - MIPS_INS_SWC1, - MIPS_INS_SD, MIPS_INS_SDL, MIPS_INS_SDR, - MIPS_INS_SDC1, - MIPS_INS_SC, MIPS_INS_SCD, - ] - - def set_imm(self): - self.imm = mips_get_imm(self.raw, self.vaddr) - if self.id in MipsInsn.do_sign_extend: # sign extended immediates - self.imm = sign_extend_16(self.imm) - - def set_offset(self): - self.offset = mips_get_offset(self.raw, self.vaddr) - - def set_base(self): - self.base = mips_get_base(self.raw, self.vaddr) - - def set_offset_base(self): - self.set_imm() - self.set_base() - - def set_target(self): - self.target = mips_get_target(self.raw, self.vaddr) - - def set_vd(self): - self.vd = mips_get_vd(self.raw, self.vaddr) - - def set_vs(self): - self.vs = mips_get_vs(self.raw, self.vaddr) - - def set_vt(self): - self.vt = mips_get_vt(self.raw, self.vaddr) - - def set_e(self): - self.elem = mips_get_elem(self.raw, self.vaddr) - - def set_ed(self): - self.elemd = mips_get_elemd(self.raw, self.vaddr) - - def set_vd_e(self): - self.set_vd() - self.set_e() - - def set_vt_ed(self): - self.set_vt() - self.set_ed() - - def set_vt_e(self): - self.set_vt() - self.set_e() - - def set_vd_ed(self): - self.set_vd() - self.set_ed() - - def set_voffset(self): - self.voffset = mips_get_voffset(self.raw, self.vaddr) - - def set_voffset_base(self): - self.set_voffset() - self.set_base() - - def set_vc(self): - self.vc = mips_get_vc(self.raw, self.vaddr) - - field_setters = { - 'code' : set_code, - 'sa' : set_sa, - 'op' : set_op, - 'cd' : set_cd, - 'rd' : set_rd, - 'rs' : set_rs, - 'rt' : set_rt, - 'fd' : set_fd, - 'fs' : set_fs, - 'ft' : set_ft, - 'imm' : set_imm, - 'offset' : set_offset, - 'base' : set_base, - 'offset(base)' : set_offset_base, - 'target' : set_target, - 'vd' : set_vd, - 'vs' : set_vs, - 'vt' : set_vt, - 'vt[e]' : set_vt_e, - 'vt[ed]' : set_vt_ed, - 'vd[e]' : set_vd_e, - 'vd[ed]' : set_vd_ed, - 'voffset' : set_voffset, - 'voffset(base)' : set_voffset_base, - 'vc' : set_vc - } - - def set_value(self, name): - MipsInsn.field_setters[name](self) - - # Field getters - - field_getters = { - 'code' : (lambda insn: insn.code), - 'sa' : (lambda insn: insn.sa), - 'op' : (lambda insn: insn.op), - 'cd' : (lambda insn: insn.cd), - 'rd' : (lambda insn: insn.rd), - 'rs' : (lambda insn: insn.rs), - 'rt' : (lambda insn: insn.rt), - 'fd' : (lambda insn: insn.fd), - 'fs' : (lambda insn: insn.fs), - 'ft' : (lambda insn: insn.ft), - 'imm' : (lambda insn: insn.imm), - 'offset' : (lambda insn: insn.offset), - 'base' : (lambda insn: insn.base), - 'offset(base)' : (lambda insn: (insn.offset, insn.base)), - 'target' : (lambda insn: insn.target), - 'vd' : (lambda insn: insn.vd), - 'vs' : (lambda insn: insn.vs), - 'vt' : (lambda insn: insn.vt), - 'vt[e]' : (lambda insn: (insn.vt, insn.elem)), - 'vt[ed]' : (lambda insn: (insn.vt, insn.elemd)), - 'vd[e]' : (lambda insn: (insn.vd, insn.elem)), - 'vd[ed]' : (lambda insn: (insn.vd, insn.elemd)), - 'voffset' : (lambda insn: insn.voffset), - 'voffset(base)' : (lambda insn: (insn.voffset, insn.base)), - 'vc' : (lambda insn: insn.vc), - } - - def value_forname(self, name): - return MipsInsn.field_getters[name](self) - -def fetch_insn(raw, vaddr, insn_set, func): - insn = insn_set.get(func(raw, vaddr), None) # default none for invalid instruction encoding - - if insn is not None and type(insn[1]) == dict: # extra decoding required - insn = fetch_insn(raw, vaddr, insn[1], insn[0]) - return insn - -def decode_insn(raw, vaddr): - return MipsInsn(ABI_VR4300, raw, vaddr, fetch_insn(raw, vaddr, mips_insns, mips_get_field)) - -def decode_rsp_insn(raw, vaddr): - return MipsInsn(ABI_RSP, raw, vaddr, fetch_insn(raw, vaddr, rsp_insns, mips_get_field)) - -mips_insns = { - 0b000000: (mips_get_special, { - # opcode id mnemonic fields field is written to - 0b000000: (MIPS_INS_SLL, "sll", ("rd","rt","sa"), (True , False, False)), - 0b000010: (MIPS_INS_SRL, "srl", ("rd","rt","sa"), (True , False, False)), - 0b000011: (MIPS_INS_SRA, "sra", ("rd","rt","sa"), (True , False, False)), - 0b000100: (MIPS_INS_SLLV, "sllv", ("rd","rt","rs"), (True , False, False)), - 0b000110: (MIPS_INS_SRLV, "srlv", ("rd","rt","rs"), (True , False, False)), - 0b000111: (MIPS_INS_SRAV, "srav", ("rd","rt","rs"), (True , False, False)), - 0b001000: (MIPS_INS_JR, "jr", ("rs", ), (False, )), - 0b001001: (MIPS_INS_JALR, "jalr", ("rs", ), (False, )), # technically also rd but it's always $ra - 0b001100: (MIPS_INS_SYSCALL, "syscall", ( ), ( )), - 0b001101: (MIPS_INS_BREAK, "break", ("code", ), (False, )), - 0b001111: (MIPS_INS_SYNC, "sync", ( ), ( )), - 0b010000: (MIPS_INS_MFHI, "mfhi", ("rd", ), (True , )), - 0b010001: (MIPS_INS_MTHI, "mthi", ("rs", ), (False, )), - 0b010010: (MIPS_INS_MFLO, "mflo", ("rd", ), (True , )), - 0b010011: (MIPS_INS_MTLO, "mtlo", ("rs", ), (False, )), - 0b010100: (MIPS_INS_DSLLV, "dsllv", ("rd","rt","rs"), (True , False, False)), - 0b010110: (MIPS_INS_DSRLV, "dsrlv", ("rd","rt","rs"), (True , False, False)), - 0b010111: (MIPS_INS_DSRAV, "dsrav", ("rd","rt","rs"), (True , False, False)), - 0b011000: (MIPS_INS_MULT, "mult", ("rs","rt" ), (False, False )), - 0b011001: (MIPS_INS_MULTU, "multu", ("rs","rt" ), (False, False )), - 0b011010: (MIPS_INS_DIV, "div", ("rd","rs","rt"), (False, False, False)), # for some reason gas hates div instructions - 0b011011: (MIPS_INS_DIVU, "divu", ("rd","rs","rt"), (False, False, False)), # with the correct number of operands - 0b011100: (MIPS_INS_DMULT, "dmult", ("rs","rt" ), (False, False )), - 0b011101: (MIPS_INS_DMULTU, "dmultu", ("rs","rt" ), (False, False )), - 0b011110: (MIPS_INS_DDIV, "ddiv", ("rd","rs","rt"), (False, False, False)), - 0b011111: (MIPS_INS_DDIVU, "ddivu", ("rd","rs","rt"), (False, False, False)), - 0b100000: (MIPS_INS_ADD, "add", ("rd","rs","rt"), (True , False, False)), - 0b100001: (MIPS_INS_ADDU, "addu", ("rd","rs","rt"), (True , False, False)), - 0b100010: (MIPS_INS_SUB, "sub", ("rd","rs","rt"), (True , False, False)), - 0b100011: (MIPS_INS_SUBU, "subu", ("rd","rs","rt"), (True , False, False)), - 0b100100: (MIPS_INS_AND, "and", ("rd","rs","rt"), (True , False, False)), - 0b100101: (MIPS_INS_OR, "or", ("rd","rs","rt"), (True , False, False)), - 0b100110: (MIPS_INS_XOR, "xor", ("rd","rs","rt"), (True , False, False)), - 0b100111: (MIPS_INS_NOR, "nor", ("rd","rs","rt"), (True , False, False)), - 0b101010: (MIPS_INS_SLT, "slt", ("rd","rs","rt"), (True , False, False)), - 0b101011: (MIPS_INS_SLTU, "sltu", ("rd","rs","rt"), (True , False, False)), - 0b101100: (MIPS_INS_DADD, "dadd", ("rd","rs","rt"), (True , False, False)), - 0b101101: (MIPS_INS_DADDU, "daddu", ("rd","rs","rt"), (True , False, False)), - 0b101110: (MIPS_INS_DSUB, "dsub", ("rd","rs","rt"), (True , False, False)), - 0b101111: (MIPS_INS_DSUBU, "dsubu", ("rd","rs","rt"), (True , False, False)), - 0b110000: (MIPS_INS_TGE, "tge", ("rs","rt" ), (False, False )), - 0b110001: (MIPS_INS_TGEU, "tgeu", ("rs","rt" ), (False, False )), - 0b110010: (MIPS_INS_TLT, "tlt", ("rs","rt" ), (False, False )), - 0b110011: (MIPS_INS_TLTU, "tltu", ("rs","rt" ), (False, False )), - 0b110100: (MIPS_INS_TEQ, "teq", ("rs","rt" ), (False, False )), - 0b110110: (MIPS_INS_TNE, "tne", ("rs","rt" ), (False, False )), - 0b111000: (MIPS_INS_DSLL, "dsll", ("rd","rt","sa"), (True , False, False)), - 0b111010: (MIPS_INS_DSRL, "dsrl", ("rd","rt","sa"), (True , False, False)), - 0b111011: (MIPS_INS_DSRA, "dsra", ("rd","rt","sa"), (True , False, False)), - 0b111100: (MIPS_INS_DSLL32, "dsll32", ("rd","rt","sa"), (True , False, False)), - 0b111110: (MIPS_INS_DSRL32, "dsrl32", ("rd","rt","sa"), (True , False, False)), - 0b111111: (MIPS_INS_DSRA32, "dsra32", ("rd","rt","sa"), (True , False, False)), - }), - 0b000001: (mips_get_regimm, { - 0b00000: (MIPS_INS_BLTZ, "bltz", ("rs","offset"), (False, False)), - 0b00001: (MIPS_INS_BGEZ, "bgez", ("rs","offset"), (False, False)), - 0b00010: (MIPS_INS_BLTZL, "bltzl", ("rs","offset"), (False, False)), - 0b00011: (MIPS_INS_BGEZL, "bgezl", ("rs","offset"), (False, False)), - 0b01000: (MIPS_INS_TGEI, "tgei", ("rs","imm" ), (False, False)), - 0b01001: (MIPS_INS_TGEIU, "tgeiu", ("rs","imm" ), (False, False)), - 0b01010: (MIPS_INS_TLTI, "tlti", ("rs","imm" ), (False, False)), - 0b01011: (MIPS_INS_TLTIU, "tltiu", ("rs","imm" ), (False, False)), - 0b01100: (MIPS_INS_TEQI, "teqi", ("rs","imm" ), (False, False)), - 0b01110: (MIPS_INS_TNEI, "tnei", ("rs","imm" ), (False, False)), - 0b10000: (MIPS_INS_BLTZAL, "bltzal", ("rs","offset"), (False, False)), - 0b10001: (MIPS_INS_BGEZAL, "bgezal", ("rs","offset"), (False, False)), - 0b10010: (MIPS_INS_BLTZALL, "bltzall", ("rs","offset"), (False, False)), - 0b10011: (MIPS_INS_BGEZALL, "bgezall", ("rs","offset"), (False, False)), - }), - 0b000010: (MIPS_INS_J, "j", ("target", ), (False, )), - 0b000011: (MIPS_INS_JAL, "jal", ("target", ), (False, )), - 0b000100: (MIPS_INS_BEQ, "beq", ("rs","rt","offset"), (False, False, False)), - 0b000101: (MIPS_INS_BNE, "bne", ("rs","rt","offset"), (False, False, False)), - 0b000110: (MIPS_INS_BLEZ, "blez", ("rs","offset" ), (False, False, )), - 0b000111: (MIPS_INS_BGTZ, "bgtz", ("rs","offset" ), (False, False, )), - 0b001000: (MIPS_INS_ADDI, "addi", ("rt","rs","imm" ), (True , False, False)), - 0b001001: (MIPS_INS_ADDIU, "addiu", ("rt","rs","imm" ), (True , False, False)), - 0b001010: (MIPS_INS_SLTI, "slti", ("rt","rs","imm" ), (True , False, False)), - 0b001011: (MIPS_INS_SLTIU, "sltiu", ("rt","rs","imm" ), (True , False, False)), - 0b001100: (MIPS_INS_ANDI, "andi", ("rt","rs","imm" ), (True , False, False)), - 0b001101: (MIPS_INS_ORI, "ori", ("rt","rs","imm" ), (True , False, False)), - 0b001110: (MIPS_INS_XORI, "xori", ("rt","rs","imm" ), (True , False, False)), - 0b001111: (MIPS_INS_LUI, "lui", ("rt","imm" ), (True , False )), - 0b010000: (mips_get_cop0, { - 0b00000: (MIPS_INS_MFC0, "mfc0", ("rt","cd"), (True , False)), - 0b00100: (MIPS_INS_MTC0, "mtc0", ("rt","cd"), (False, True )), - 0b10000: (mips_get_tlb, { - 0b000001: (MIPS_INS_TLBR, "tlbr", (), ()), - 0b000010: (MIPS_INS_TLBWI, "tlbwi", (), ()), - 0b000110: (MIPS_INS_TLBWR, "tlbwr", (), ()), - 0b001000: (MIPS_INS_TLBP, "tlbp", (), ()), - 0b011000: (MIPS_INS_ERET, "eret", (), ()), - }), - }), - 0b010001: (mips_get_cop1, { - 0b00000: (MIPS_INS_MFC1, "mfc1", ("rt","fs"), (True , False)), - 0b00001: (MIPS_INS_DMFC1, "dmfc1", ("rt","fs"), (True , False)), - 0b00010: (MIPS_INS_CFC1, "cfc1", ("rt","fs"), (True , False)), - 0b00100: (MIPS_INS_MTC1, "mtc1", ("rt","fs"), (False, True )), - 0b00101: (MIPS_INS_DMTC1, "dmtc1", ("rt","fs"), (False, True )), - 0b00110: (MIPS_INS_CTC1, "ctc1", ("rt","fs"), (False, True )), - 0b01000: (mips_get_ndtf, { - 0b00: (MIPS_INS_BC1F, "bc1f", ("offset",), (False,)), - 0b01: (MIPS_INS_BC1T, "bc1t", ("offset",), (False,)), - 0b10: (MIPS_INS_BC1FL, "bc1fl", ("offset",), (False,)), - 0b11: (MIPS_INS_BC1TL, "bc1tl", ("offset",), (False,)), - }), - 0b010000: (mips_get_function, { - 0b000000: (MIPS_INS_ADD_S, "add.s", ("fd","fs","ft"), (True , False, False)), - 0b000001: (MIPS_INS_SUB_S, "sub.s", ("fd","fs","ft"), (True , False, False)), - 0b000010: (MIPS_INS_MUL_S, "mul.s", ("fd","fs","ft"), (True , False, False)), - 0b000011: (MIPS_INS_DIV_S, "div.s", ("fd","fs","ft"), (True , False, False)), - 0b000100: (MIPS_INS_SQRT_S, "sqrt.s", ("fd","fs" ), (True , False )), - 0b000101: (MIPS_INS_ABS_S, "abs.s", ("fd","fs" ), (True , False )), - 0b000110: (MIPS_INS_MOV_S, "mov.s", ("fd","fs" ), (True , False )), - 0b000111: (MIPS_INS_NEG_S, "neg.s", ("fd","fs" ), (True , False )), - 0b001000: (MIPS_INS_ROUND_L_S, "round.l.s", ("fd","fs" ), (True , False )), - 0b001001: (MIPS_INS_TRUNC_L_S, "trunc.l.s", ("fd","fs" ), (True , False )), - 0b001010: (MIPS_INS_CEIL_L_S, "ceil.l.s", ("fd","fs" ), (True , False )), - 0b001011: (MIPS_INS_FLOOR_L_S, "floor.l.s", ("fd","fs" ), (True , False )), - 0b001100: (MIPS_INS_ROUND_W_S, "round.w.s", ("fd","fs" ), (True , False )), - 0b001101: (MIPS_INS_TRUNC_W_S, "trunc.w.s", ("fd","fs" ), (True , False )), - 0b001110: (MIPS_INS_CEIL_W_S, "ceil.w.s", ("fd","fs" ), (True , False )), - 0b001111: (MIPS_INS_FLOOR_W_S, "floor.w.s", ("fd","fs" ), (True , False )), - 0b100001: (MIPS_INS_CVT_D_S, "cvt.d.s", ("fd","fs" ), (True , False )), - 0b100100: (MIPS_INS_CVT_W_S, "cvt.w.s", ("fd","fs" ), (True , False )), - 0b100101: (MIPS_INS_CVT_L_S, "cvt.l.s", ("fd","fs" ), (True , False )), - 0b110000: (MIPS_INS_C_F_S, "c.f.s", ("fs","ft" ), (False, False )), - 0b110001: (MIPS_INS_C_UN_S, "c.un.s", ("fs","ft" ), (False, False )), - 0b110010: (MIPS_INS_C_EQ_S, "c.eq.s", ("fs","ft" ), (False, False )), - 0b110011: (MIPS_INS_C_UEQ_S, "c.ueq.s", ("fs","ft" ), (False, False )), - 0b110100: (MIPS_INS_C_OLT_S, "c.olt.s", ("fs","ft" ), (False, False )), - 0b110101: (MIPS_INS_C_ULT_S, "c.ult.s", ("fs","ft" ), (False, False )), - 0b110110: (MIPS_INS_C_OLE_S, "c.ole.s", ("fs","ft" ), (False, False )), - 0b110111: (MIPS_INS_C_ULE_S, "c.ule.s", ("fs","ft" ), (False, False )), - 0b111000: (MIPS_INS_C_SF_S, "c.sf.s", ("fs","ft" ), (False, False )), - 0b111001: (MIPS_INS_C_NGLE_S, "c.ngle.s", ("fs","ft" ), (False, False )), - 0b111010: (MIPS_INS_C_SEQ_S, "c.seq.s", ("fs","ft" ), (False, False )), - 0b111011: (MIPS_INS_C_NGL_S, "c.ngl.s", ("fs","ft" ), (False, False )), - 0b111100: (MIPS_INS_C_LT_S, "c.lt.s", ("fs","ft" ), (False, False )), - 0b111101: (MIPS_INS_C_NGE_S, "c.nge.s", ("fs","ft" ), (False, False )), - 0b111110: (MIPS_INS_C_LE_S, "c.le.s", ("fs","ft" ), (False, False )), - 0b111111: (MIPS_INS_C_NGT_S, "c.ngt.s", ("fs","ft" ), (False, False )), - }), - 0b010001: (mips_get_function, { - 0b000000: (MIPS_INS_ADD_D, "add.d", ("fd","fs","ft"), (True , False, False)), - 0b000001: (MIPS_INS_SUB_D, "sub.d", ("fd","fs","ft"), (True , False, False)), - 0b000010: (MIPS_INS_MUL_D, "mul.d", ("fd","fs","ft"), (True , False, False)), - 0b000011: (MIPS_INS_DIV_D, "div.d", ("fd","fs","ft"), (True , False, False)), - 0b000100: (MIPS_INS_SQRT_D, "sqrt.d", ("fd","fs" ), (True , False )), - 0b000101: (MIPS_INS_ABS_D, "abs.d", ("fd","fs" ), (True , False )), - 0b000110: (MIPS_INS_MOV_D, "mov.d", ("fd","fs" ), (True , False )), - 0b000111: (MIPS_INS_NEG_D, "neg.d", ("fd","fs" ), (True , False )), - 0b001000: (MIPS_INS_ROUND_L_D, "round.l.d", ("fd","fs" ), (True , False )), - 0b001001: (MIPS_INS_TRUNC_L_D, "trunc.l.d", ("fd","fs" ), (True , False )), - 0b001010: (MIPS_INS_CEIL_L_D, "ceil.l.d", ("fd","fs" ), (True , False )), - 0b001011: (MIPS_INS_FLOOR_L_D, "floor.l.d", ("fd","fs" ), (True , False )), - 0b001100: (MIPS_INS_ROUND_W_D, "round.w.d", ("fd","fs" ), (True , False )), - 0b001101: (MIPS_INS_TRUNC_W_D, "trunc.w.d", ("fd","fs" ), (True , False )), - 0b001110: (MIPS_INS_CEIL_W_D, "ceil.w.d", ("fd","fs" ), (True , False )), - 0b001111: (MIPS_INS_FLOOR_W_D, "floor.w.d", ("fd","fs" ), (True , False )), - 0b100000: (MIPS_INS_CVT_S_D, "cvt.s.d", ("fd","fs" ), (True , False )), - 0b100100: (MIPS_INS_CVT_W_D, "cvt.w.d", ("fd","fs" ), (True , False )), - 0b100101: (MIPS_INS_CVT_L_D, "cvt.l.d", ("fd","fs" ), (True , False )), - 0b110000: (MIPS_INS_C_F_D, "c.f.d", ("fs","ft" ), (False, False )), - 0b110001: (MIPS_INS_C_UN_D, "c.un.d", ("fs","ft" ), (False, False )), - 0b110010: (MIPS_INS_C_EQ_D, "c.eq.d", ("fs","ft" ), (False, False )), - 0b110011: (MIPS_INS_C_UEQ_D, "c.ueq.d", ("fs","ft" ), (False, False )), - 0b110100: (MIPS_INS_C_OLT_D, "c.olt.d", ("fs","ft" ), (False, False )), - 0b110101: (MIPS_INS_C_ULT_D, "c.ult.d", ("fs","ft" ), (False, False )), - 0b110110: (MIPS_INS_C_OLE_D, "c.ole.d", ("fs","ft" ), (False, False )), - 0b110111: (MIPS_INS_C_ULE_D, "c.ule.d", ("fs","ft" ), (False, False )), - 0b111000: (MIPS_INS_C_SF_D, "c.sf.d", ("fs","ft" ), (False, False )), - 0b111001: (MIPS_INS_C_NGLE_D, "c.ngle.d", ("fs","ft" ), (False, False )), - 0b111010: (MIPS_INS_C_SEQ_D, "c.seq.d", ("fs","ft" ), (False, False )), - 0b111011: (MIPS_INS_C_NGL_D, "c.ngl.d", ("fs","ft" ), (False, False )), - 0b111100: (MIPS_INS_C_LT_D, "c.lt.d", ("fs","ft" ), (False, False )), - 0b111101: (MIPS_INS_C_NGE_D, "c.nge.d", ("fs","ft" ), (False, False )), - 0b111110: (MIPS_INS_C_LE_D, "c.le.d", ("fs","ft" ), (False, False )), - 0b111111: (MIPS_INS_C_NGT_D, "c.ngt.d", ("fs","ft" ), (False, False )), - }), - 0b010100: (mips_get_function, { - 0b100000: (MIPS_INS_CVT_S_W, "cvt.s.w", ("fd","fs"), (True , False)), - 0b100001: (MIPS_INS_CVT_D_W, "cvt.d.w", ("fd","fs"), (True , False)), - }), - 0b010101: (mips_get_function, { - 0b100000: (MIPS_INS_CVT_S_L, "cvt.s.l", ("fd","fs"), (True , False)), - 0b100001: (MIPS_INS_CVT_D_L, "cvt.d.l", ("fd","fs"), (True , False)), - }), - }), - 0b010100: (MIPS_INS_BEQL, "beql", ("rs","rt","offset" ), (False, False, False)), - 0b010101: (MIPS_INS_BNEL, "bnel", ("rs","rt","offset" ), (False, False, False)), - 0b010110: (MIPS_INS_BLEZL, "blezl", ("rs","offset" ), (False, False )), - 0b010111: (MIPS_INS_BGTZL, "bgtzl", ("rs","offset" ), (False, False )), - 0b011000: (MIPS_INS_DADDI, "daddi", ("rt","rs","imm" ), (True , False, False)), - 0b011001: (MIPS_INS_DADDIU, "daddiu", ("rt","rs","imm" ), (True , False, False)), - 0b011010: (MIPS_INS_LDL, "ldl", ("rt","offset(base)"), (True , False )), - 0b011011: (MIPS_INS_LDR, "ldr", ("rt","offset(base)"), (True , False )), - 0b100000: (MIPS_INS_LB, "lb", ("rt","offset(base)"), (True , False )), - 0b100001: (MIPS_INS_LH, "lh", ("rt","offset(base)"), (True , False )), - 0b100010: (MIPS_INS_LWL, "lwl", ("rt","offset(base)"), (True , False )), - 0b100011: (MIPS_INS_LW, "lw", ("rt","offset(base)"), (True , False )), - 0b100100: (MIPS_INS_LBU, "lbu", ("rt","offset(base)"), (True , False )), - 0b100101: (MIPS_INS_LHU, "lhu", ("rt","offset(base)"), (True , False )), - 0b100110: (MIPS_INS_LWR, "lwr", ("rt","offset(base)"), (True , False )), - 0b100111: (MIPS_INS_LWU, "lwu", ("rt","offset(base)"), (True , False )), - 0b101000: (MIPS_INS_SB, "sb", ("rt","offset(base)"), (False, False )), - 0b101001: (MIPS_INS_SH, "sh", ("rt","offset(base)"), (False, False )), - 0b101010: (MIPS_INS_SWL, "swl", ("rt","offset(base)"), (False, False )), - 0b101011: (MIPS_INS_SW, "sw", ("rt","offset(base)"), (False, False )), - 0b101100: (MIPS_INS_SDL, "sdl", ("rt","offset(base)"), (False, False )), - 0b101101: (MIPS_INS_SDR, "sdr", ("rt","offset(base)"), (False, False )), - 0b101110: (MIPS_INS_SWR, "swr", ("rt","offset(base)"), (False, False )), - 0b101111: (MIPS_INS_CACHE, "cache", ("op","offset(base)"), (False, False, False)), - 0b110000: (MIPS_INS_LL, "ll", ("rt","offset(base)"), (True , False )), - 0b110001: (MIPS_INS_LWC1, "lwc1", ("ft","offset(base)"), (True , False )), - # lwc2 - 0b110100: (MIPS_INS_LLD, "lld", ("rt","offset(base)"), (True , False )), - 0b110101: (MIPS_INS_LDC1, "ldc1", ("ft","offset(base)"), (True , False )), - # ldc2 - 0b110111: (MIPS_INS_LD, "ld", ("rt","offset(base)"), (True , False )), - 0b111000: (MIPS_INS_SC, "sc", ("rt","offset(base)"), (False, False )), - 0b111001: (MIPS_INS_SWC1, "swc1", ("ft","offset(base)"), (False, False )), - # lwc2 - 0b111100: (MIPS_INS_SCD, "scd", ("rt","offset(base)"), (False, False )), - 0b111101: (MIPS_INS_SDC1, "sdc1", ("ft","offset(base)"), (False, False )), - # sdc2 - 0b111111: (MIPS_INS_SD, "sd", ("rt","offset(base)"), (False, False )), -} - -rsp_insns = { - 0b000000: (mips_get_special, { - # opcode id mnemonic fields field is written to - 0b000000: (MIPS_INS_SLL, "sll", ("rd","rt","sa"), (True , False, False)), - 0b000010: (MIPS_INS_SRL, "srl", ("rd","rt","sa"), (True , False, False)), - 0b000011: (MIPS_INS_SRA, "sra", ("rd","rt","sa"), (True , False, False)), - 0b000100: (MIPS_INS_SLLV, "sllv", ("rd","rt","rs"), (True , False, False)), - 0b000110: (MIPS_INS_SRLV, "srlv", ("rd","rt","rs"), (True , False, False)), - 0b000111: (MIPS_INS_SRAV, "srav", ("rd","rt","rs"), (True , False, False)), - 0b001000: (MIPS_INS_JR, "jr", ("rs", ), (False, )), - 0b001001: (MIPS_INS_JALR, "jalr", ("rs", ), (False, )), # technically also rd but it's always $ra - 0b001101: (MIPS_INS_BREAK, "break", ("code", ), (False, )), - 0b100000: (MIPS_INS_ADD, "add", ("rd","rs","rt"), (True , False, False)), - 0b100001: (MIPS_INS_ADDU, "addu", ("rd","rs","rt"), (True , False, False)), - 0b100010: (MIPS_INS_SUB, "sub", ("rd","rs","rt"), (True , False, False)), - 0b100011: (MIPS_INS_SUBU, "subu", ("rd","rs","rt"), (True , False, False)), - 0b100100: (MIPS_INS_AND, "and", ("rd","rs","rt"), (True , False, False)), - 0b100101: (MIPS_INS_OR, "or", ("rd","rs","rt"), (True , False, False)), - 0b100110: (MIPS_INS_XOR, "xor", ("rd","rs","rt"), (True , False, False)), - 0b100111: (MIPS_INS_NOR, "nor", ("rd","rs","rt"), (True , False, False)), - 0b101010: (MIPS_INS_SLT, "slt", ("rd","rs","rt"), (True , False, False)), - 0b101011: (MIPS_INS_SLTU, "sltu", ("rd","rs","rt"), (True , False, False)), - }), - 0b000001: (mips_get_regimm, { - 0b00000: (MIPS_INS_BLTZ, "bltz", ("rs","offset"), (False, False)), - 0b00001: (MIPS_INS_BGEZ, "bgez", ("rs","offset"), (False, False)), - 0b10000: (MIPS_INS_BLTZAL, "bltzal", ("rs","offset"), (False, False)), - 0b10001: (MIPS_INS_BGEZAL, "bgezal", ("rs","offset"), (False, False)), - }), - 0b000010: (MIPS_INS_J, "j", ("target", ), (False, )), - 0b000011: (MIPS_INS_JAL, "jal", ("target", ), (False, )), - 0b000100: (MIPS_INS_BEQ, "beq", ("rs","rt","offset"), (False, False, False)), - 0b000101: (MIPS_INS_BNE, "bne", ("rs","rt","offset"), (False, False, False)), - 0b000110: (MIPS_INS_BLEZ, "blez", ("rs","offset" ), (False, False )), - 0b000111: (MIPS_INS_BGTZ, "bgtz", ("rs","offset" ), (False, False )), - 0b001000: (MIPS_INS_ADDI, "addi", ("rt","rs","imm" ), (True , False, False)), - 0b001001: (MIPS_INS_ADDIU, "addiu", ("rt","rs","imm" ), (True , False, False)), - 0b001010: (MIPS_INS_SLTI, "slti", ("rt","rs","imm" ), (True , False, False)), - 0b001011: (MIPS_INS_SLTIU, "sltiu", ("rt","rs","imm" ), (True , False, False)), - 0b001100: (MIPS_INS_ANDI, "andi", ("rt","rs","imm" ), (True , False, False)), - 0b001101: (MIPS_INS_ORI, "ori", ("rt","rs","imm" ), (True , False, False)), - 0b001110: (MIPS_INS_XORI, "xori", ("rt","rs","imm" ), (True , False, False)), - 0b001111: (MIPS_INS_LUI, "lui", ("rt","imm" ), (True , False )), - 0b010000: (mips_get_cop0, { - 0b00000: (MIPS_INS_MFC0, "mfc0", ("rt","cd"), (True , False)), - 0b00100: (MIPS_INS_MTC0, "mtc0", ("rt","cd"), (False, True )), - }), - 0b010010: (mips_get_cop2_func, { # TODO this encoding got ugly, move to a mask matcher like gnu objdump - 0b0: (mips_get_cop2, { - 0b0000: (MIPS_INS_MFC2, "mfc2", ("rt", "vd[e]"), (True , False)), - 0b0100: (MIPS_INS_MTC2, "mtc2", ("rt", "vd[e]"), (False, True )), - 0b0010: (MIPS_INS_CFC2, "cfc2", ("rt", "vc" ), (True , False)), - 0b0110: (MIPS_INS_CTC2, "ctc2", ("rt", "vc" ), (False, True )), - }), - 0b1: (mips_get_function, { - 0b000000: (MIPS_INS_VMULF, "vmulf", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b000001: (MIPS_INS_VMULU, "vmulu", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b000010: (MIPS_INS_VRNDP, "vrndp", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b000011: (MIPS_INS_VMULQ, "vmulq", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b000100: (MIPS_INS_VMUDL, "vmudl", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b000101: (MIPS_INS_VMUDM, "vmudm", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b000110: (MIPS_INS_VMUDN, "vmudn", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b000111: (MIPS_INS_VMUDH, "vmudh", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001000: (MIPS_INS_VMACF, "vmacf", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001001: (MIPS_INS_VMACU, "vmacu", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001010: (MIPS_INS_VRNDN, "vrndn", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001011: (MIPS_INS_VMACQ, "vmacq", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001100: (MIPS_INS_VMADL, "vmadl", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001101: (MIPS_INS_VMADM, "vmadm", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001110: (MIPS_INS_VMADN, "vmadn", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b001111: (MIPS_INS_VMADH, "vmadh", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b010000: (MIPS_INS_VADD, "vadd", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b010001: (MIPS_INS_VSUB, "vsub", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b010011: (MIPS_INS_VABS, "vabs", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b010100: (MIPS_INS_VADDC, "vaddc", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b010101: (MIPS_INS_VSUBC, "vsubc", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b011101: (MIPS_INS_VSAR, "vsar", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100000: (MIPS_INS_VLT, "vlt", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100001: (MIPS_INS_VEQ, "veq", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100010: (MIPS_INS_VNE, "vne", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100011: (MIPS_INS_VGE, "vge", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100100: (MIPS_INS_VCL, "vcl", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100101: (MIPS_INS_VCH, "vch", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100110: (MIPS_INS_VCR, "vcr", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b100111: (MIPS_INS_VMRG, "vmrg", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b101000: (MIPS_INS_VAND, "vand", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b101001: (MIPS_INS_VNAND, "vnand", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b101010: (MIPS_INS_VOR, "vor", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b101011: (MIPS_INS_VNOR, "vnor", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b101100: (MIPS_INS_VXOR, "vxor", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b101101: (MIPS_INS_VNXOR, "vnxor", ("vd", "vs", "vt[e]"), (True , False, False)), - 0b110000: (MIPS_INS_VRCP, "vrcp", ("vd[ed]", "vt[e]" ), (True , False)), - 0b110001: (MIPS_INS_VRCPL, "vrcpl", ("vd[ed]", "vt[e]" ), (True , False)), - 0b110010: (MIPS_INS_VRCPH, "vrcph", ("vd[ed]", "vt[e]" ), (True , False)), - 0b110011: (MIPS_INS_VMOV, "vmov", ("vd[ed]", "vt[e]" ), (True , False)), - 0b110100: (MIPS_INS_VRSQ, "vrsq", ("vd[ed]", "vt[e]" ), (True , False)), - 0b110101: (MIPS_INS_VRSQL, "vrsql", ("vd[ed]", "vt[e]" ), (True , False)), - 0b110110: (MIPS_INS_VRSQH, "vrsqh", ("vd[ed]", "vt[e]" ), (True , False)), - 0b110111: (MIPS_INS_VNOP, "vnop", ( ), ()), - }), - }), - 0b100000: (MIPS_INS_LB, "lb", ("rt","offset(base)"), (True , False)), - 0b100001: (MIPS_INS_LH, "lh", ("rt","offset(base)"), (True , False)), - 0b100011: (MIPS_INS_LW, "lw", ("rt","offset(base)"), (True , False)), - 0b100100: (MIPS_INS_LBU, "lbu", ("rt","offset(base)"), (True , False)), - 0b100101: (MIPS_INS_LHU, "lhu", ("rt","offset(base)"), (True , False)), - 0b101000: (MIPS_INS_SB, "sb", ("rt","offset(base)"), (False, False)), - 0b101001: (MIPS_INS_SH, "sh", ("rt","offset(base)"), (False, False)), - 0b101011: (MIPS_INS_SW, "sw", ("rt","offset(base)"), (False, False)), - 0b110010: (mips_get_lwc2, { - 0b00000: (MIPS_INS_LBV, "lbv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b00001: (MIPS_INS_LSV, "lsv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b00010: (MIPS_INS_LLV, "llv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b00011: (MIPS_INS_LDV, "ldv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b00100: (MIPS_INS_LQV, "lqv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b00101: (MIPS_INS_LRV, "lrv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b00110: (MIPS_INS_LPV, "lpv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b00111: (MIPS_INS_LUV, "luv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b01000: (MIPS_INS_LHV, "lhv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b01001: (MIPS_INS_LFV, "lfv", ("vt[ed]", "voffset(base)"), (True , False)), - 0b01011: (MIPS_INS_LTV, "ltv", ("vt[ed]", "voffset(base)"), (True , False)), - }), - 0b111010: (mips_get_swc2, { - 0b00000: (MIPS_INS_SBV, "sbv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b00001: (MIPS_INS_SSV, "ssv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b00010: (MIPS_INS_SLV, "slv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b00011: (MIPS_INS_SDV, "sdv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b00100: (MIPS_INS_SQV, "sqv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b00101: (MIPS_INS_SRV, "srv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b00110: (MIPS_INS_SPV, "spv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b00111: (MIPS_INS_SUV, "suv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b01000: (MIPS_INS_SHV, "shv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b01001: (MIPS_INS_SFV, "sfv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b01010: (MIPS_INS_SWV, "swv", ("vt[ed]", "voffset(base)"), (False, False)), - 0b01011: (MIPS_INS_STV, "stv", ("vt[ed]", "voffset(base)"), (False, False)), - }), -} diff --git a/lib/ultralib/tools/patch_ar_meta.py b/lib/ultralib/tools/patch_ar_meta.py deleted file mode 100755 index d831785..0000000 --- a/lib/ultralib/tools/patch_ar_meta.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python3 -# -# Patch metadata in .ar files -# - -import argparse - -def ar_patch(ar, original, new_uid, new_gid, new_filemode): - """ - AR file headers - - Offset Length Name Format - 0 16 File identifier ASCII - 16 12 File modification timestamp (in seconds) Decimal - 28 6 Owner ID Decimal - 34 6 Group ID Decimal - 40 8 File mode (type and permission) Octal - 48 10 File size in bytes Decimal - 58 2 Ending characters 0x60 0x0A - """ - assert len(ar) > 0x24 , "Got empty archive?" - - armap_time1 = None - armap_time2 = None - - i = 8 - while i < len(original): - file_name = original[i:][0:][:16].decode("ASCII") - file_size = int(original[i:][48:][:10].decode("ASCII").strip()) - end = original[i:][58:][:2].decode("ASCII") - - assert end == "`\n" - - if file_name.strip() == "/": - armap_time1 = original[i+16:i+16+12] - elif file_name.strip() == "//": - armap_time2 = original[i+16:i+16+12] - - if file_size % 2 != 0: - file_size += 1 - i += file_size + 60 - - assert armap_time1 is not None - assert armap_time2 is not None - - i = 8 - while i < len(ar): - file_name = ar[i:][0:][:16].decode("ASCII") - file_size = int(ar[i:][48:][:10].decode("ASCII").strip()) - end = ar[i:][58:][:2].decode("ASCII") - - assert end == "`\n" - - if file_name.strip() == "/": - ar[i+16:i+16+12] = armap_time1 - elif file_name.strip() == "//": - ar[i+16:i+16+12] = armap_time2 - else: - ar[i+28:i+28+6] = f"{new_uid:<6}".encode("ASCII")[:6] - ar[i+34:i+34+6] = f"{new_gid:<6}".encode("ASCII")[:6] - ar[i+40:i+40+8] = f"{new_filemode:<8}".encode("ASCII")[:8] - - if file_size % 2 != 0: - file_size += 1 - i += file_size + 60 - -def main(): - parser = argparse.ArgumentParser(description="Patch metadata in .a files.") - parser.add_argument("target", help="path to the ar file to patch") - parser.add_argument("original", help="path to the original ar file") - parser.add_argument("uid", help="new uid") - parser.add_argument("gid", help="new gid") - parser.add_argument("filemode", help="new filemode") - args = parser.parse_args() - - ar = None - with open(args.target, "rb") as ar_file: - ar = bytearray(ar_file.read()) - - original = None - with open(args.original, "rb") as original_ar_file: - original = bytearray(original_ar_file.read()) - - ar_patch(ar, original, args.uid, args.gid, args.filemode) - - with open(args.target, "wb") as ar_file: - ar_file.write(ar) - -if __name__ == '__main__': - main() diff --git a/lib/ultralib/tools/print_mdebug.py b/lib/ultralib/tools/print_mdebug.py deleted file mode 100755 index e0b295a..0000000 --- a/lib/ultralib/tools/print_mdebug.py +++ /dev/null @@ -1,589 +0,0 @@ -#!/usr/bin/env python3 -''' -Resources: -http://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf -https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/include/coff/sym.h -https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/include/coff/symconst.h -https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/gas/ecoff.c -https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/bfd/ecoff.c -https://github.com/pathscale/absoft/blob/master/svn/trunk/ekopath-gcc/ekopath-gcc-4.2.0/gcc/mips-tdump.c -https://chromium.googlesource.com/native_client/nacl-toolchain/+/refs/tags/gcc-4.4.3/binutils/gas/ecoff.c -https://android.googlesource.com/toolchain/binutils/+/refs/heads/donut/binutils-2.17/bfd/ecofflink.c -https://kernel.googlesource.com/pub/scm/linux/kernel/git/hjl/binutils/+/hjl/secondary/include/coff/symconst.h -https://c0de.pw/bg/binutils-gdb/blob/cdbf20f73486c66e24f322400eba877eb534ae51/gdb/mdebugread.c -''' - -import os -import struct -import collections -import sys - -OFFSET = 0 # TODO why are the offsets in the symbolic header off by some amount? - -indent_level = 0 -is_comment = False - -symbol_type_list = [ - 'stNil', 'stGlobal', 'stStatic', 'stParam', 'stLocal', 'stLabel', 'stProc', 'stBlock', - 'stEnd', 'stMember', 'stTypedef', 'stFile', 'INVALID', 'INVALID', 'stStaticProc', 'stConstant', - 'stStaParam', 'INVALID', 'INVALID', 'INVALID', 'INVALID', 'INVALID', 'INVALID', 'INVALID', - 'INVALID', 'INVALID', 'stStruct', 'stUnion', 'stEnum', 'INVALID', 'INVALID', 'INVALID', - 'INVALID', 'INVALID', 'stIndirect'] -storage_class_list = ['scNil', 'scText', 'scData', 'scBss', 'scRegister', 'scAbs', 'scUndefined', 'reserved', - 'scBits', 'scDbx', 'scRegImage', 'scInfo', 'scUserStruct', 'scSData', 'scSBss', 'scRData', - 'scVar', 'scCommon', 'scSCommon', 'scVarRegister', 'scVariant', 'scUndefined', 'scInit'] -basic_type_c_list = ['nil', 'addr', 'signed char', 'unsigned char', 'short', 'unsigned short', 'int', 'unsigned int', - 'long', 'unsigned long', 'float', 'double', 'struct', 'union', 'enum', 'typedef', - 'range', 'set', 'complex', 'double complex', 'indirect', 'fixed decimal', 'float decimal', 'string', - 'bit', 'picture', 'void', 'long long', 'unsigned long long', 'INVALID', 'long', 'unsigned long', - 'long long', 'unsigned long long', 'addr', 'int64', 'unsigned int64'] - -def increase_indent(): - global indent_level - indent_level += 1 - -def decrease_indent(): - global indent_level - indent_level -= 1 - -def set_is_comment(set_to): - global is_comment - old = is_comment - is_comment = set_to - return old - -def get_indent(): - global indent_level - global is_comment - ret = '//' if is_comment else '' - for i in range(indent_level): - ret += ' ' - return ret - -def check_indent(): - global indent_level - assert indent_level == 0 - -def read_uint32_be(file_data, offset): - return struct.unpack('>I', file_data[offset:offset+4])[0] - -def read_uint16_be(file_data, offset): - return struct.unpack('>H', file_data[offset:offset+2])[0] - -def read_uint8_be(file_data, offset): - return struct.unpack('>B', file_data[offset:offset+1])[0] - -def read_elf_header(file_data, offset): - Header = collections.namedtuple('ElfHeader', - '''e_magic e_class e_data e_version e_osabi e_abiversion e_pad - e_type e_machine e_version2 e_entry e_phoff e_shoff e_flags - e_ehsize e_phentsize e_phnum e_shentsize e_shnum e_shstrndx''') - return Header._make(struct.unpack('>I5B7s2H5I6H', file_data[offset:offset+52])) - -def read_elf_section_header(file_data, offset): - Header = collections.namedtuple('SectionHeader', - '''sh_name sh_type sh_flags sh_addr sh_offset sh_size sh_link - sh_info sh_addralign sh_entsize''') - return Header._make(struct.unpack('>10I', file_data[offset:offset+40])) - -def read_symbolic_header(file_data, offset): - Header = collections.namedtuple('SymbolicHeader', - '''magic vstamp ilineMax cbLine cbLineOffset idnMax cbDnOffset - ipdMax cbPdOffset isymMax cbSymOffset ioptMax cbOptOffset - iauxMax cbAuxOffset issMax cbSsOffset issExtMax cbSsExtOffset - ifdMax cbFdOffset crfd cbRfdOffset iextMax cbExtOffset''') - return Header._make(struct.unpack('>2H23I', file_data[offset:offset+96])) - -# TODO find a better solution for the bitfield -def read_file_descriptor(file_data, offset): - if 'init' not in read_file_descriptor.__dict__: - read_file_descriptor.cache = {} - read_file_descriptor.header = collections.namedtuple('FileDescriptor', - '''adr rss issBase cbSs isymBase csym ilineBase cline ioptBase - copt ipdFirst cpd iauxBase caux rfdBase crfd XXX_bitfield - cbLineOffset cbLine''') - read_file_descriptor.init = True - if offset in read_file_descriptor.cache: - return read_file_descriptor.cache[offset] - read_file_descriptor.cache[offset] = read_file_descriptor.header._make( - struct.unpack('>I2iI6iHh4iI2I', file_data[offset:offset+72])) - return read_file_descriptor.cache[offset] - -def read_procedure_descriptor(file_data, offset): - Header = collections.namedtuple('ProcedureDescriptor', - '''adr isym iline regmask regoffset iopt fregmask fregoffset - frameoffset framereg pcreg lnLow lnHigh cbLineOffset''') - return Header._make(struct.unpack('>I8i2h2iI', file_data[offset:offset+52])) - -def read_symbol(file_data, offset): - if 'init' not in read_symbol.__dict__: - read_symbol.cache = {} - read_symbol.header = collections.namedtuple('Symbol', '''iss value st sc index''') - read_symbol.init = True - if offset in read_symbol.cache: - return read_symbol.cache[offset] - (word0, word1, word2) = struct.unpack('>iiI', file_data[offset:offset+12]) - read_symbol.cache[offset] = read_symbol.header._make(( - word0, word1, (word2 >> 26) & 0x3F, (word2 >> 21) & 0x1F, word2 & 0xFFFFF)) - return read_symbol.cache[offset] - -def read_auxiliary_symbol(file_data, offset): - if 'init' not in read_auxiliary_symbol.__dict__: - read_auxiliary_symbol.cache = {} - read_auxiliary_symbol.header = collections.namedtuple('AuxSymbol', - '''ti rndx dnLow dnHigh isym iss width count''') - read_auxiliary_symbol.type_info = collections.namedtuple('TypeInfo', - '''fBitfield continued bt tq4 tq5 tq0 tq1 tq2 tq3''') - read_auxiliary_symbol.rel_sym = collections.namedtuple('RelativeSymbol', '''rfd index''') - read_auxiliary_symbol.init = True - if offset in read_auxiliary_symbol.cache: - return read_auxiliary_symbol.cache[offset] - word0 = struct.unpack('>I', file_data[offset:offset+4])[0] - read_auxiliary_symbol.cache[offset] = read_auxiliary_symbol.header._make(( - read_auxiliary_symbol.type_info._make(((word0 >> 31) & 1, (word0 >> 30) & 1, (word0 >> 24) & 0x3F, (word0 >> 20) & 0xF, (word0 >> 16) & 0xF, (word0 >> 12) & 0xF, (word0 >> 8) & 0xF, (word0 >> 4) & 0xF, word0 & 0xF)), - read_auxiliary_symbol.rel_sym._make(((word0 >> 20) & 0xFFF, word0 & 0xFFFFF)), - word0, word0, word0, word0, word0, word0)) - return read_auxiliary_symbol.cache[offset] - -def read_string(file_data, offset): - current_offset = 0 - current_string = b'' - while True: - char = struct.unpack('c', file_data[offset+current_offset:offset+current_offset+1])[0] - if char == b'\0': - return current_string.decode('ascii') - else: - current_string += char - current_offset += 1 - -def map_relative_file_descriptor(file_data, fd, symbolic_header, rfd_num): - if fd.crfd == 0: - return rfd_num - - offset = symbolic_header.cbRfdOffset - OFFSET + (fd.rfdBase + rfd_num)*4 - return struct.unpack('>I', file_data[offset:offset+4])[0] - -def get_symbol_name_from_aux(file_data, fd, symbolic_header, aux_num, search_for_typedef): - aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + aux_num)*4) - fd_num = aux.rndx.rfd - next_aux = aux_num+1 - if fd_num == 4095: - aux2 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux)*4) - fd_num = aux2.isym - next_aux = next_aux+1; - fd_num = map_relative_file_descriptor(file_data, fd, symbolic_header, fd_num) - fd2 = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + fd_num*72) - sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (fd2.isymBase + aux.rndx.index)*12) - ret = '' - #print('%r' % (aux,)); - #print('%r' % (aux2,)); - #print('%r' % (sym,)); - if sym.st == 26 or sym.st == 27: #stStruct, stunion - ret = get_struct_or_union_string(file_data, fd2, symbolic_header, fd2.isymBase + aux.rndx.index, search_for_typedef) - elif sym.st == 28: #stEnum: - ret = get_enum_string(file_data, fd2, symbolic_header, fd2.isymBase + aux.rndx.index) - else: - ret = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd2.issBase + sym.iss) - return (ret, next_aux) - -def get_type_string(file_data, fd, symbolic_header, aux_num, name, search_for_typedef): - ret = '' - aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + aux_num)*4) - #print(''); - #print('%r' % (aux,)); - next_aux = aux_num+1 - has_bitfield = aux.ti.fBitfield == 1 - bitwidth = 0 - if has_bitfield: - bit_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux)*4) - bitwidth = bit_aux.isym - next_aux = next_aux+1 - if aux.ti.bt == 12: # btStruct - (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) - elif aux.ti.bt == 13: # btUnion - (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) - elif aux.ti.bt == 15: # btTypedef - (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) - elif aux.ti.bt == 14: # btEnum - (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) - else: - if aux.ti.bt >= 36: - print('Error unknow bt: %d' % (aux.ti.bt)) - ret = basic_type_c_list[aux.ti.bt] - - tq_list = (aux.ti.tq0, aux.ti.tq1, aux.ti.tq2, aux.ti.tq3, aux.ti.tq4, aux.ti.tq5) - - # TODO this is very naive and probably does not work in a large amount of cases - last_was_proc = False # if we see a tqProc, assume the next will be a tqPtr - for tq in tq_list: - if tq == 0: # tqNil - break; - elif tq == 1: # tqPtr - if last_was_proc: - last_was_proc = False - continue - ret += '*' - elif tq == 2: # tqProc - last_was_proc = True - name = '(*%s)(/* ECOFF does not store param types */)' % name - elif tq == 3: # tqArray - next_aux += 2 # todo what does this skip over? (Apparantly the type of the index, so always int for C) - array_low_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux)*4) - array_high_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux+1)*4) - stride_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux+2)*4) - next_aux += 3 - if array_high_aux.dnHigh == 0xFFFFFFFF: - name += '[]' - else: - name += '[%d]' % (array_high_aux.dnHigh + 1) - elif tq == 4: # tqFar - print('ERROR tqFar in get_type_name') - elif tq == 5: # tqVol - ret = 'volatile ' + ret - elif tq == 6: # tqConst - ret = 'const ' + ret - if has_bitfield: - name += ' : %d' % bitwidth - return ret + ' ' + name - -def get_enum_string(file_data, fd, symbolic_header, enum_sym_num): - ret = '' - start_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + enum_sym_num*12) - if start_sym.st != 28: - print('ERROR unknown type in get_enum_string start:%d' % start_sym.st) - return ret - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + start_sym.iss) - if name != '': - name += ' ' - ret += 'enum %s{\n' % name - increase_indent() - sym_num = enum_sym_num + 1 - while sym_num < fd.isymBase + start_sym.index: - sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - if sym.st == 8: # stEnd - decrease_indent() - ret += get_indent() - ret += '}' - elif sym.st == 9: # stMember - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) - ret += get_indent() - ret += '%s = %d,\n' % (name, sym.value) - else: - print('ERROR unknown type in get_enum_string:%d' % sym.st) - break - sym_num += 1 - return ret - -def get_struct_or_union_string(file_data, fd, symbolic_header, union_sym_num, search_for_typedef): - ret = '' - start_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + union_sym_num*12) - if search_for_typedef: - typedef_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (fd.isymBase + start_sym.index)*12) - if typedef_sym.st == 10: # stTypedef - return read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + typedef_sym.iss) - else: - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + start_sym.iss) - if name != '': - return name - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + start_sym.iss) - if name != '': - name += ' ' - if start_sym.st == 26: # stStruct - ret += 'struct %s{\n' % name - increase_indent() - elif start_sym.st == 27: # stUnion - ret += 'union %s{\n' % name - increase_indent() - else: - print('ERROR unknown type in get_struct_or_union_string start:%d' % start_sym.st) - return ret - sym_num = union_sym_num + 1 - while sym_num < fd.isymBase + start_sym.index: - sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - if sym.st == 8: # stEnd - decrease_indent() - ret += get_indent() - ret += '}' - elif sym.st == 9: # stMember - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) - ret += get_indent() - ret += '/* 0x%X */ %s;\n' % (sym.value // 8, get_type_string(file_data, fd, symbolic_header, sym.index, name, True)) - elif sym.st == 26 or sym.st == 27: #stStruct, stUnion - sym_num = fd.isymBase + sym.index - continue - elif sym.st == 34: # stIndirect - # TODO what even is a stIndirect? - sym_num += 1 - else: - print('ERROR unknown type in get_struct_or_union_string:%d' % sym.st) - break - sym_num += 1 - return ret - -def print_typedef_symbols(file_data, fd, symbolic_header, typedef_sym_num): - typedef_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + typedef_sym_num*12) - if typedef_sym.st != 10: # stTypedef - print('ERROR expected stTypedef symbol in print_typedef_symbols, found:%d' % typedef_sym.st) - return - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + typedef_sym.iss) - print('typedef %s;' % get_type_string(file_data, fd, symbolic_header, typedef_sym.index, name, False)) - -def print_procedure(file_data, fd, symbolic_header, proc_sym_num): - proc_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + proc_sym_num*12) - proc_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + proc_sym.iss) - print('%s(' % get_type_string(file_data, fd, symbolic_header, proc_sym.index+1, proc_name, True), end='') - sym_num = proc_sym_num+1 - param_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - first = True - while param_sym.st == 3: # stParam - param_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + param_sym.iss) - print('%s%s' % ('' if first else ', ', - get_type_string(file_data, fd, symbolic_header, param_sym.index, param_name, True)), - end='') - sym_num += 1 - param_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - first = False - - print(');') - - check_indent(); - - comment_old = set_is_comment(True) - while sym_num < fd.isymBase + fd.csym: - sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - sym_num += 1 - if sym.st == 7: # stBlock - print('%s{' % get_indent()) - increase_indent() - elif sym.st == 8: # stEnd - end_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) - if end_name == proc_name: - break - if end_name != '': - # this is a stEnd for something other than the function. Let's back out and return - sym_num -= 1 - break - decrease_indent() - print('%s}' % get_indent()) - elif sym.st == 4: # stLocal - local_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) - is_reg = sym.sc == 4 # scRegister - print('%s%s%s;' % (get_indent(), - 'register ' if is_reg else '', - get_type_string(file_data, fd, symbolic_header, sym.index, local_name, True))) - elif sym.st == 2: # stStatic - static_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) - if sym.index == 0xFFFFF: - print('%sstatic %s; // no type symbol' % (get_indent(),static_name)) - else: - print('%sstatic %s;' % (get_indent(),get_type_string(file_data, fd, symbolic_header, sym.index, static_name, True))) - elif sym.st == 5: # stLabel - label_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) - print('%sLabel: %s @ %d;' % (get_indent(), label_name, sym.value)) - elif sym.st == 6: # stProc - # multiple name for function? - sym_num = print_procedure(file_data, fd, symbolic_header, sym_num-1) - elif sym.st == 26 or sym.st == 27: # stStruct, stUnion - print('%s%s;' % (get_indent(), get_struct_or_union_string(file_data, fd, symbolic_header, sym_num-1, False))) - sym_num = fd.isymBase + sym.index - elif sym.st == 28: # stEnum - print('%s%s;' % (get_indent(), get_enum_string(file_data, fd, symbolic_header, sym_num-1))) - sym_num = fd.isymBase + sym.index - elif sym.st == 34: # stIndirect - # TODO what even is a stIndirect? - indirect_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) - print('%sTODO Indirect: %s;' % (get_indent(), indirect_name)) - else: - print('ERROR unknown st in print_procedure: %d' % sym.st) - set_is_comment(comment_old) - - check_indent(); - - return sym_num - -def print_symbols(file_data, fd, symbolic_header): - sym_num = fd.isymBase - indirects = [] - typedefs = [] - while sym_num < fd.isymBase + fd.csym: - root_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - if root_sym.st == 10: # stTypedef - aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + root_sym.index)*4) - offset = 0 - if aux.ti.fBitfield == 1: - offset = 1 - if aux.ti.bt == 12 or aux.ti.bt == 13 or aux.ti.bt == 14 or aux.ti.bt == 15: # btStruct, btUnion, btEnum, btTypedef - aux2 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + root_sym.index + 1 + offset)*4) - fd_num = aux2.rndx.rfd - if fd_num == 4095: - fd_num = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + root_sym.index + 2 + offset)*4).isym - fd_num = map_relative_file_descriptor(file_data, fd, symbolic_header, fd_num) - fd2 = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + fd_num*72) - sym2 = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (fd2.isymBase + aux2.rndx.index)*12) - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd2.issBase + sym2.iss) - if name != '': - typedefs.append(name) - elif root_sym.st == 34: # stIndirect - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + root_sym.iss) - indirects.append(name); - sym_num += 1 - sym_num = fd.isymBase - while sym_num < fd.isymBase + fd.csym: - root_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - if root_sym.st == 11: # stFile - file_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + root_sym.iss) - print('// begin file %s\n' % file_name) - sym_num += 1 - leaf_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - while leaf_sym.st != 8: # stEnd - if leaf_sym.st == 26 or leaf_sym.st == 27: # stStruct, stUnion - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss) - if (name != '') and ((name in indirects) or (name not in typedefs)): # TODO - print('%s;\n' % get_struct_or_union_string(file_data, fd, symbolic_header, sym_num, False)) - sym_num = fd.isymBase + leaf_sym.index - elif leaf_sym.st == 28: # stEnum - name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss) - if (name != '') and (name not in typedefs): # TODO - print('%s;\n' % get_enum_string(file_data, fd, symbolic_header, sym_num)) - sym_num = fd.isymBase + leaf_sym.index - elif leaf_sym.st == 10: # stTypedef - # TODO typedef for stIndirect shoulf print the keyword i.e. typdef >struct< THING thing - print_typedef_symbols(file_data, fd, symbolic_header, sym_num) - sym_num += 1 - print('') - elif leaf_sym.st == 6 or leaf_sym.st == 14: # stProc, stStaticProc - # TODO how do stProc and stStaticProc differ? stStaticProc isn't exported? - sym_num = print_procedure(file_data, fd, symbolic_header, sym_num) - print('') - elif leaf_sym.st == 2: # stStatic - static_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss) - if leaf_sym.sc == 2 or leaf_sym.sc == 3 or leaf_sym.sc == 5 or leaf_sym.sc == 15: # scData, scBss, scAbsolute, scRData - if leaf_sym.index != 0xFFFFF: # looks like it's an invalid value for .s files - print('static %s;\n' % get_type_string(file_data, fd, symbolic_header, leaf_sym.index, static_name, True)) - else: - print('static %s;\n' % static_name) - else: - print('ERROR unknown sc for stStatic in print_symbols: %d' % leaf_sym.sc) - sym_num += 1 - elif leaf_sym.st == 34: # stIndirect - # stIndirect is put out when the compiler sees a struct when it is not yet defined - # TODO more info - sym_num += 1 - elif leaf_sym.st == 5: # stLabel - print('// label: %s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss)) - sym_num += 1 - elif leaf_sym.st == 0: # stNil - print('// nil: %s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss)) - sym_num += 1 - else: - print('ERROR unknown st in leaf_sym in print_symbols: %d' % leaf_sym.st) - sym_num += 1 - leaf_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - sym_num = fd.isymBase + root_sym.index - print('// end file %s' % file_name) - else: - print('ERROR expected st of stFile as only root type in print_symbols:%d' % root_sym.st) - return - -def main(): - global OFFSET - if len(sys.argv) < 2: - return # TODO print usage - - filename = sys.argv[1] - - try: - with open(filename, 'rb') as f: - file_data = f.read() - except IOError: - print('failed to read file ' + filename) - return - - elf_header = read_elf_header(file_data, 0) - section_headers = [] - debug_index = 0xFFFFFFFF - #print('%r' % (elf_header,)) - for i in range(elf_header.e_shnum): - section_headers.append(read_elf_section_header(file_data, elf_header.e_shoff + i*40)) - #print('%r' % (section_headers[i],)) - if section_headers[i].sh_type == 0x70000005: - debug_index = i - - if debug_index != 0xFFFFFFFF: - symbolic_header = read_symbolic_header(file_data, section_headers[debug_index].sh_offset) - file_descriptors = [] - print('%r' % (symbolic_header,)) - # Set offset by assuming that there are no optimization symbols so cbOptOffset points to the start of the symbolic header - #OFFSET = symbolic_header.cbOptOffset - section_headers[debug_index].sh_offset - #print('Using OFFSET of %d' % OFFSET) - #for sym_num in range(symbolic_header.isymMax): - #sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - #print('%d:%r' % (sym_num, (sym,))); - #for aux_num in range(symbolic_header.iauxMax): - #aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + aux_num*4) - #print('%d:%r' % (aux_num, (aux,))); - for file_num in range(symbolic_header.ifdMax): - fd = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + file_num*72) - file_descriptors.append(fd) - for file_num in range(symbolic_header.ifdMax): - fd = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + file_num*72) - print('%r' % (fd,)) - print(' name:%s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + fd.rss)) - - ''' - print(' Relative File Descriptors:') - for rfd_num in range(fd.rfdBase, fd.rfdBase + fd.crfd): - offset = symbolic_header.cbRfdOffset - OFFSET + rfd_num*4 - rfd_index = struct.unpack('>I', file_data[offset:offset+4])[0] - rfd = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + rfd_index*72) - print(' %d:%r' % (rfd_index, (rfd,))) - ''' - - ''' - print(' procedures:') - for proc_num in range(fd.ipdFirst, fd.ipdFirst + fd.cpd): - pd = read_procedure_descriptor(file_data, symbolic_header.cbPdOffset - OFFSET + proc_num*52) - print(' %r' % ((pd,))) - ''' - - ''' - print(' symbols:') - for sym_num in range(fd.isymBase, fd.isymBase + fd.csym): - sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) - print(' %r' % ((sym,))) - print(' name:%s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss)) - print(' type:%s(%d)' % (symbol_type_list[sym.st], sym.st)) - print(' storage class:%s(%d)' % (storage_class_list[sym.sc], sym.sc)) - if sym.st == 3 or sym.st == 4 or sym.st == 9 or sym.st == 10 or sym.st == 28: # stParam, stLocal, stMember, stTypedef, stEnum - aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index)*4) - print(' %r' % ((aux,))) - offset = 0 - if aux.ti.fBitfield == 1: - bitfield_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index + 1)*4) - print(' %r' % ((bitfield_aux,))) - offset = 1 - if aux.ti.bt == 12 or aux.ti.bt == 13 or aux.ti.bt == 14 or aux.ti.bt == 15: # btStruct, btUnion, btEnum, btTypedef - aux2 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index + 1 + offset)*4) - print(' %r' % ((aux2,))) - fd_num = aux2.rndx.rfd - if fd_num == 4095: - aux3 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index + 2 + offset)*4) - print(' %r' % ((aux3,))) - fd_num = aux3.isym - fd_num = map_relative_file_descriptor(file_data, fd, symbolic_header, fd_num) - sym2 = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (file_descriptors[fd_num].isymBase + aux2.rndx.index)*12) - print(' %r' % (sym2,)) - print(' name:%s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + file_descriptors[aux3.isym].issBase + sym2.iss)) - if sym.st == 6 or sym.st == 14: # stProc, stStaticProc - # TODO what is the first aux symbol for? - aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index)*4) - type_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index+1)*4) - print(' %r' % ((aux,))) - print(' %r' % ((type_aux,))) - ''' - - print(' pretty print:') - print_symbols(file_data, fd, symbolic_header) - - -main() \ No newline at end of file diff --git a/lib/ultralib/tools/set_o32abi_bit.py b/lib/ultralib/tools/set_o32abi_bit.py deleted file mode 100755 index fc22d2c..0000000 --- a/lib/ultralib/tools/set_o32abi_bit.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 -import argparse, struct, sys - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - - parser.add_argument('file', help='input file') - args = parser.parse_args() - - with open(args.file, 'r+b') as f: - magic = struct.unpack('>I', f.read(4))[0] - if magic != 0x7F454C46: - print('Error: Not an ELF file') - sys.exit(1) - - f.seek(36) - flags = struct.unpack('>I', f.read(4))[0] - # if flags & 0xF0000000 != 0x20000000: # test for mips3 - # print('Error: Architecture not mips3') - # sys.exit(1) - - flags |= 0x00001000 # set EF_MIPS_ABI_O32 - f.seek(36) - f.write(struct.pack('>I', flags)) - diff --git a/lib/ultralib/tools/shiftjis_conv.py b/lib/ultralib/tools/shiftjis_conv.py deleted file mode 100755 index 73037d2..0000000 --- a/lib/ultralib/tools/shiftjis_conv.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 -import sys - -# Converts a file with UTF-8 Japanese glyphs in char literals, -# into one that uses u16 constants - -# Follows the layout in the manual page for easier cross reference -sjis_table = { - "ー": 0x815B, "ぜ": 0x82BA, "へ": 0x82D6, "ァ": 0x8340, "ソ": 0x835C, "ペ": 0x8379, - "ぁ": 0x829F, "そ": 0x82BB, "べ": 0x82D7, "ア": 0x8341, "ゾ": 0x835D, "ホ": 0x837A, - "あ": 0x82A0, "ぞ": 0x82BC, "ぺ": 0x82D8, "ィ": 0x8342, "タ": 0x835E, "ボ": 0x837B, - "ぃ": 0x82A1, "た": 0x82BD, "ほ": 0x82D9, "イ": 0x8343, "ダ": 0x835F, "ポ": 0x837C, - "い": 0x82A2, "だ": 0x82BE, "ぼ": 0x82DA, "ゥ": 0x8344, "チ": 0x8360, "マ": 0x837D, - "ぅ": 0x82A3, "ち": 0x82BF, "ぽ": 0x82DB, "ウ": 0x8345, "ヂ": 0x8361, "ミ": 0x837E, - "う": 0x82A4, "ぢ": 0x82C0, "ま": 0x82DC, "ェ": 0x8346, "ッ": 0x8362, "ム": 0x8380, - "ぇ": 0x82A5, "っ": 0x82C1, "み": 0x82DD, "エ": 0x8347, "ツ": 0x8363, "メ": 0x8381, - "え": 0x82A6, "つ": 0x82C2, "む": 0x82DE, "ォ": 0x8348, "ヅ": 0x8364, "モ": 0x8382, - "ぉ": 0x82A7, "づ": 0x82C3, "め": 0x82DF, "オ": 0x8349, "テ": 0x8365, "ャ": 0x8383, - "お": 0x82A8, "て": 0x82C4, "も": 0x82E0, "カ": 0x834A, "デ": 0x8366, "ヤ": 0x8384, - "か": 0x82A9, "で": 0x82C5, "ゃ": 0x82E1, "ガ": 0x834B, "ト": 0x8367, "ュ": 0x8385, - "が": 0x82AA, "と": 0x82C6, "や": 0x82E2, "キ": 0x834C, "ド": 0x8368, "ユ": 0x8386, - "き": 0x82AB, "ど": 0x82C7, "ゅ": 0x82E3, "ギ": 0x834D, "ナ": 0x8369, "ョ": 0x8387, - "ぎ": 0x82AC, "な": 0x82C8, "ゆ": 0x82E4, "ク": 0x834E, "ニ": 0x836A, "ヨ": 0x8388, - "く": 0x82AD, "に": 0x82C9, "ょ": 0x82E5, "グ": 0x834F, "ヌ": 0x836B, "ラ": 0x8389, - "ぐ": 0x82AE, "ぬ": 0x82CA, "よ": 0x82E6, "ケ": 0x8350, "ネ": 0x836C, "リ": 0x838A, - "け": 0x82AF, "ね": 0x82CB, "ら": 0x82E7, "ゲ": 0x8351, "ノ": 0x836D, "ル": 0x838B, - "げ": 0x82B0, "の": 0x82CC, "り": 0x82E8, "コ": 0x8352, "ハ": 0x836E, "レ": 0x838C, - "こ": 0x82B1, "は": 0x82CD, "る": 0x82E9, "ゴ": 0x8353, "バ": 0x836F, "ロ": 0x838D, - "ご": 0x82B2, "ば": 0x82CE, "れ": 0x82EA, "サ": 0x8354, "パ": 0x8370, "ヮ": 0x838E, - "さ": 0x82B3, "ぱ": 0x82CF, "ろ": 0x82EB, "ザ": 0x8355, "ヒ": 0x8371, "ワ": 0x838F, - "ざ": 0x82B4, "ひ": 0x82D0, "ゎ": 0x82EC, "シ": 0x8356, "ビ": 0x8372, "ヰ": 0x8390, - "し": 0x82B5, "び": 0x82D1, "わ": 0x82ED, "ジ": 0x8357, "ピ": 0x8373, "ヱ": 0x8391, - "じ": 0x82B6, "ぴ": 0x82D2, "ゐ": 0x82EE, "ス": 0x8358, "フ": 0x8374, "ヲ": 0x8392, - "す": 0x82B7, "ふ": 0x82D3, "ゑ": 0x82EF, "ズ": 0x8359, "ブ": 0x8375, "ン": 0x8393, - "ず": 0x82B8, "ぶ": 0x82D4, "を": 0x82F0, "セ": 0x835A, "プ": 0x8376, "ヴ": 0x8394, - "せ": 0x82B9, "ぷ": 0x82D5, "ん": 0x82F1, "ゼ": 0x835B, "ヘ": 0x8377, "ヵ": 0x8395, - "ベ": 0x8378, "ヶ": 0x8396, -} - -skipTimer = 0 - -def sjis_process(buf, outfile): - global skipTimer - - for i, char in enumerate(buf): - if skipTimer > 0: - skipTimer -= 1 - continue - if char == "'" and buf[i+1] in sjis_table: - if sjis_table[buf[i+1]] == 0: - print("Error: Please map %s in %s" % (buf[i+1], sys.argv[0])) - exit(1) - outfile.write("0x%X" % sjis_table[buf[i+1]]) - skipTimer = 2 - else: - outfile.write(char) - - diff --git a/lib/ultralib/tools/strip_debug.sh b/lib/ultralib/tools/strip_debug.sh deleted file mode 100755 index 4a8be78..0000000 --- a/lib/ultralib/tools/strip_debug.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/bash - -cd $1 - -mkdir -p .cmp - -for f in *.o ; -do - ${CROSS}objcopy -p --strip-debug $f .cmp/${f/.o/.cmp.o} -done diff --git a/lib/ultralib/tools/util.py b/lib/ultralib/tools/util.py deleted file mode 100644 index b6c6155..0000000 --- a/lib/ultralib/tools/util.py +++ /dev/null @@ -1,44 +0,0 @@ - -import struct - -def enumerate_stepped(l, start=0, step=1): - p = start - for e in l: - yield p, e - p += step - -def back_align(x, al): - return x - (x % al) - -def forward_align(x, al): - return (x + (al - 1)) & ~(al - 1) - -def as_double(b): - return struct.unpack(">d", b)[0] - -def as_dword(b): - return struct.unpack(">Q", b)[0] - -def as_float(b): - return struct.unpack(">f", b)[0] - -def as_word(b): - return struct.unpack(">I", b)[0] - -def as_hword(b): - return struct.unpack(">H", b)[0] - -def as_double_list(b): - return [i[0] for i in struct.iter_unpack(">d", b)] - -def as_dword_list(b): - return [i[0] for i in struct.iter_unpack(">Q", b)] - -def as_float_list(b): - return [i[0] for i in struct.iter_unpack(">f", b)] - -def as_word_list(b): - return [i[0] for i in struct.iter_unpack(">I", b)] - -def as_hword_list(b): - return [h[0] for h in struct.iter_unpack(">H", b)] From 04b6ff32b7c9a20e878f01a88dfcfc03b6abe47c Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sat, 24 Feb 2024 18:09:57 -0800 Subject: [PATCH 5/6] git subrepo clone git@github.com:decompals/ultralib.git lib/ultralib subrepo: subdir: "lib/ultralib" merged: "299d7fa" upstream: origin: "git@github.com:decompals/ultralib.git" branch: "main" commit: "299d7fa" git-subrepo: version: "0.4.6" origin: "git@github.com:ingydotnet/git-subrepo.git" commit: "110b9eb" --- lib/ultralib/.github/workflows/ci_egcs.txt | 42 + lib/ultralib/.github/workflows/ci_gcc.yml | 41 + lib/ultralib/.github/workflows/ci_ido.yml | 41 + lib/ultralib/.gitignore | 29 + lib/ultralib/.gitrepo | 12 + lib/ultralib/Makefile | 234 + lib/ultralib/Makefile.gcc | 67 + lib/ultralib/Makefile.ido | 60 + lib/ultralib/README.md | 72 + lib/ultralib/base/I/libgultra.txt | 404 ++ lib/ultralib/base/I/libgultra_d.txt | 404 ++ lib/ultralib/base/I/libgultra_rom.txt | 404 ++ lib/ultralib/base/I/libultra.txt | 400 ++ lib/ultralib/base/I/libultra_d.txt | 404 ++ lib/ultralib/base/I/libultra_rom.txt | 370 ++ lib/ultralib/base/J/libgultra.txt | 446 ++ lib/ultralib/base/J/libgultra_d.txt | 451 ++ lib/ultralib/base/J/libgultra_rom.txt | 416 ++ lib/ultralib/base/J/libultra.txt | 446 ++ lib/ultralib/base/J/libultra_d.txt | 451 ++ lib/ultralib/base/J/libultra_rom.txt | 418 ++ lib/ultralib/base/K/libgultra.txt | 468 ++ lib/ultralib/base/K/libgultra_d.txt | 471 ++ lib/ultralib/base/K/libgultra_rom.txt | 425 ++ lib/ultralib/base/K/libultra.txt | 468 ++ lib/ultralib/base/K/libultra_d.txt | 471 ++ lib/ultralib/base/K/libultra_rom.txt | 427 ++ lib/ultralib/base/L/libgultra.txt | 483 ++ lib/ultralib/base/L/libgultra_d.txt | 486 ++ lib/ultralib/base/L/libgultra_rom.txt | 440 ++ lib/ultralib/base/L/libultra.txt | 483 ++ lib/ultralib/base/L/libultra_d.txt | 486 ++ lib/ultralib/base/L/libultra_rom.txt | 442 ++ lib/ultralib/include/PR/R4300.h | 453 ++ lib/ultralib/include/PR/abi.h | 410 ++ lib/ultralib/include/PR/gbi.h | 4572 +++++++++++++++++ lib/ultralib/include/PR/gs2dex.h | 392 ++ lib/ultralib/include/PR/gt.h | 365 ++ lib/ultralib/include/PR/gu.h | 270 + lib/ultralib/include/PR/libaudio.h | 947 ++++ lib/ultralib/include/PR/mbi.h | 100 + lib/ultralib/include/PR/os.h | 108 + lib/ultralib/include/PR/os_ai.h | 92 + lib/ultralib/include/PR/os_cache.h | 96 + lib/ultralib/include/PR/os_cont.h | 208 + lib/ultralib/include/PR/os_convert.h | 111 + lib/ultralib/include/PR/os_debug.h | 117 + lib/ultralib/include/PR/os_eeprom.h | 107 + lib/ultralib/include/PR/os_error.h | 86 + lib/ultralib/include/PR/os_exception.h | 86 + lib/ultralib/include/PR/os_flash.h | 77 + lib/ultralib/include/PR/os_gbpak.h | 107 + lib/ultralib/include/PR/os_gio.h | 86 + lib/ultralib/include/PR/os_host.h | 166 + lib/ultralib/include/PR/os_internal.h | 49 + lib/ultralib/include/PR/os_internal_debug.h | 43 + lib/ultralib/include/PR/os_internal_error.h | 45 + .../include/PR/os_internal_exception.h | 57 + lib/ultralib/include/PR/os_internal_flash.h | 40 + lib/ultralib/include/PR/os_internal_gio.h | 45 + lib/ultralib/include/PR/os_internal_host.h | 42 + lib/ultralib/include/PR/os_internal_reg.h | 57 + lib/ultralib/include/PR/os_internal_rsp.h | 48 + lib/ultralib/include/PR/os_internal_si.h | 46 + lib/ultralib/include/PR/os_internal_thread.h | 43 + lib/ultralib/include/PR/os_internal_tlb.h | 47 + lib/ultralib/include/PR/os_libc.h | 100 + lib/ultralib/include/PR/os_message.h | 162 + lib/ultralib/include/PR/os_motor.h | 84 + lib/ultralib/include/PR/os_pfs.h | 200 + lib/ultralib/include/PR/os_pi.h | 221 + lib/ultralib/include/PR/os_rdp.h | 92 + lib/ultralib/include/PR/os_reg.h | 90 + lib/ultralib/include/PR/os_rsp.h | 86 + lib/ultralib/include/PR/os_si.h | 86 + lib/ultralib/include/PR/os_system.h | 118 + lib/ultralib/include/PR/os_thread.h | 161 + lib/ultralib/include/PR/os_time.h | 114 + lib/ultralib/include/PR/os_tlb.h | 107 + lib/ultralib/include/PR/os_version.h | 26 + lib/ultralib/include/PR/os_vi.h | 298 ++ lib/ultralib/include/PR/os_voice.h | 108 + lib/ultralib/include/PR/ramrom.h | 113 + lib/ultralib/include/PR/rcp.h | 848 +++ lib/ultralib/include/PR/rdb.h | 93 + lib/ultralib/include/PR/region.h | 123 + lib/ultralib/include/PR/rmon.h | 39 + lib/ultralib/include/PR/sched.h | 115 + lib/ultralib/include/PR/sp.h | 196 + lib/ultralib/include/PR/sptask.h | 201 + lib/ultralib/include/PR/ucode.h | 192 + lib/ultralib/include/PR/ultraerror.h | 165 + lib/ultralib/include/PR/ultralog.h | 74 + lib/ultralib/include/PR/ultratypes.h | 85 + lib/ultralib/include/asm.h | 1 + lib/ultralib/include/assert.h | 12 + lib/ultralib/include/dbgdefs.h | 8 + lib/ultralib/include/dbgproto.h | 402 ++ lib/ultralib/include/fpregdef.h | 0 lib/ultralib/include/gcc/math.h | 1 + lib/ultralib/include/gcc/memory.h | 23 + lib/ultralib/include/gcc/sgidefs.h | 44 + lib/ultralib/include/gcc/stdarg.h | 121 + lib/ultralib/include/gcc/stdio.h | 1 + lib/ultralib/include/gcc/stdlib.h | 81 + lib/ultralib/include/gcc/string.h | 42 + lib/ultralib/include/ido/math.h | 1 + lib/ultralib/include/ido/memory.h | 23 + lib/ultralib/include/ido/stdarg.h | 33 + lib/ultralib/include/ido/stdio.h | 1 + lib/ultralib/include/ido/stdlib.h | 81 + lib/ultralib/include/ido/string.h | 42 + lib/ultralib/include/macros.h | 16 + lib/ultralib/include/regdef.h | 3 + lib/ultralib/include/sgidefs.h | 3 + lib/ultralib/include/sys/asm.h | 116 + lib/ultralib/include/sys/fpregdef.h | 0 lib/ultralib/include/sys/regdef.h | 187 + lib/ultralib/include/ultra64.h | 40 + lib/ultralib/include/ultrahost.h | 59 + lib/ultralib/src/audio/Makefile | 120 + lib/ultralib/src/audio/auxbus.c | 65 + lib/ultralib/src/audio/bnkf.c | 143 + lib/ultralib/src/audio/cents2ratio.c | 33 + lib/ultralib/src/audio/copy.c | 35 + lib/ultralib/src/audio/cseq.c | 409 ++ lib/ultralib/src/audio/cseq.h | 11 + lib/ultralib/src/audio/cseqp.h | 10 + lib/ultralib/src/audio/cspdelete.c | 29 + lib/ultralib/src/audio/cspgetchlvol.c | 27 + lib/ultralib/src/audio/cspgetfxmix.c | 27 + lib/ultralib/src/audio/cspgetpan.c | 27 + lib/ultralib/src/audio/cspgetpriority.c | 26 + lib/ultralib/src/audio/cspgetprogram.c | 42 + lib/ultralib/src/audio/cspgetseq.c | 29 + lib/ultralib/src/audio/cspgetstate.c | 29 + lib/ultralib/src/audio/cspgettempo.c | 31 + lib/ultralib/src/audio/cspgetvol.c | 27 + lib/ultralib/src/audio/csplayer.c | 882 ++++ lib/ultralib/src/audio/cspplay.c | 34 + lib/ultralib/src/audio/cspsendmidi.c | 40 + lib/ultralib/src/audio/cspsetbank.c | 32 + lib/ultralib/src/audio/cspsetchlvol.c | 35 + lib/ultralib/src/audio/cspsetfxmix.c | 35 + lib/ultralib/src/audio/cspsetpan.c | 35 + lib/ultralib/src/audio/cspsetpriority.c | 32 + lib/ultralib/src/audio/cspsetprogram.c | 35 + lib/ultralib/src/audio/cspsetseq.c | 34 + lib/ultralib/src/audio/cspsettempo.c | 36 + lib/ultralib/src/audio/cspsetvol.c | 32 + lib/ultralib/src/audio/cspstop.c | 32 + lib/ultralib/src/audio/drvrnew.c | 303 ++ lib/ultralib/src/audio/env.c | 591 +++ lib/ultralib/src/audio/event.c | 272 + lib/ultralib/src/audio/filter.c | 32 + lib/ultralib/src/audio/heapalloc.c | 65 + lib/ultralib/src/audio/heapcheck.c | 71 + lib/ultralib/src/audio/heapinit.c | 37 + lib/ultralib/src/audio/initfx.h | 59 + lib/ultralib/src/audio/load.c | 471 ++ lib/ultralib/src/audio/mainbus.c | 67 + lib/ultralib/src/audio/parse_abi.c | 47 + lib/ultralib/src/audio/resample.c | 150 + lib/ultralib/src/audio/reverb.c | 452 ++ lib/ultralib/src/audio/save.c | 70 + lib/ultralib/src/audio/seq.c | 343 ++ lib/ultralib/src/audio/seq.h | 9 + lib/ultralib/src/audio/seqp.h | 37 + lib/ultralib/src/audio/seqpdelete.c | 39 + lib/ultralib/src/audio/seqpgetchlvol.c | 27 + lib/ultralib/src/audio/seqpgetfxmix.c | 27 + lib/ultralib/src/audio/seqpgetpan.c | 27 + lib/ultralib/src/audio/seqpgetpriority.c | 26 + lib/ultralib/src/audio/seqpgetprogram.c | 42 + lib/ultralib/src/audio/seqpgetseq.c | 29 + lib/ultralib/src/audio/seqpgetstate.c | 29 + lib/ultralib/src/audio/seqpgettempo.c | 31 + lib/ultralib/src/audio/seqpgetvol.c | 27 + lib/ultralib/src/audio/seqplayer.c | 1228 +++++ lib/ultralib/src/audio/seqploop.c | 35 + lib/ultralib/src/audio/seqpplay.c | 48 + lib/ultralib/src/audio/seqpsendmidi.c | 40 + lib/ultralib/src/audio/seqpsetbank.c | 32 + lib/ultralib/src/audio/seqpsetchlvol.c | 35 + lib/ultralib/src/audio/seqpsetfxmix.c | 35 + lib/ultralib/src/audio/seqpsetpan.c | 35 + lib/ultralib/src/audio/seqpsetpriority.c | 32 + lib/ultralib/src/audio/seqpsetprogram.c | 36 + lib/ultralib/src/audio/seqpsetseq.c | 34 + lib/ultralib/src/audio/seqpsettempo.c | 36 + lib/ultralib/src/audio/seqpsetvol.c | 32 + lib/ultralib/src/audio/seqpstop.c | 33 + lib/ultralib/src/audio/sl.c | 65 + lib/ultralib/src/audio/sndp.h | 102 + lib/ultralib/src/audio/sndpallocate.c | 43 + lib/ultralib/src/audio/sndpdeallocate.c | 35 + lib/ultralib/src/audio/sndpdelete.c | 44 + lib/ultralib/src/audio/sndpgetsound.c | 27 + lib/ultralib/src/audio/sndpgetstate.c | 29 + lib/ultralib/src/audio/sndplayer.c | 297 ++ lib/ultralib/src/audio/sndpplay.c | 36 + lib/ultralib/src/audio/sndpplayat.c | 32 + lib/ultralib/src/audio/sndpsetfxmix.c | 42 + lib/ultralib/src/audio/sndpsetpan.c | 42 + lib/ultralib/src/audio/sndpsetpitch.c | 48 + lib/ultralib/src/audio/sndpsetpriority.c | 38 + lib/ultralib/src/audio/sndpsetsound.c | 36 + lib/ultralib/src/audio/sndpsetvol.c | 42 + lib/ultralib/src/audio/sndpstop.c | 35 + lib/ultralib/src/audio/synaddplayer.c | 34 + lib/ultralib/src/audio/synallocfx.c | 32 + lib/ultralib/src/audio/synallocvoice.c | 132 + lib/ultralib/src/audio/syndelete.c | 27 + lib/ultralib/src/audio/synfreefx.c | 26 + lib/ultralib/src/audio/synfreevoice.c | 54 + lib/ultralib/src/audio/syngetfxref.c | 33 + lib/ultralib/src/audio/syngetpriority.c | 27 + lib/ultralib/src/audio/synremoveplayer.c | 49 + lib/ultralib/src/audio/synsetfxmix.c | 60 + lib/ultralib/src/audio/synsetfxparam.c | 29 + lib/ultralib/src/audio/synsetpan.c | 50 + lib/ultralib/src/audio/synsetpitch.c | 50 + lib/ultralib/src/audio/synsetpriority.c | 27 + lib/ultralib/src/audio/synsetvol.c | 50 + lib/ultralib/src/audio/synstartvoice.c | 48 + lib/ultralib/src/audio/synstartvoiceparam.c | 75 + lib/ultralib/src/audio/synstopvoice.c | 44 + lib/ultralib/src/audio/synthInternals.h | 344 ++ lib/ultralib/src/audio/synthesizer.c | 323 ++ lib/ultralib/src/debug/assert.c | 12 + lib/ultralib/src/debug/assertbreak.s | 14 + lib/ultralib/src/debug/atomic.c | 16 + lib/ultralib/src/debug/kdebugserver.c | 96 + lib/ultralib/src/debug/osint_debug.h | 11 + lib/ultralib/src/debug/profile.c | 176 + lib/ultralib/src/debug/threadprofile.c | 22 + lib/ultralib/src/debug/threadprofileclear.c | 11 + lib/ultralib/src/debug/threadprofileinit.c | 16 + .../src/debug/threadprofilereadcount.c | 39 + .../src/debug/threadprofilereadtime.c | 51 + lib/ultralib/src/debug/threadprofilestart.c | 22 + lib/ultralib/src/debug/threadprofilestop.c | 47 + lib/ultralib/src/error/commonerror.c | 193 + lib/ultralib/src/error/error.c | 30 + lib/ultralib/src/error/errorasm.s | 33 + lib/ultralib/src/flash/flashallerase.c | 33 + lib/ultralib/src/flash/flashallerasethrough.c | 8 + lib/ultralib/src/flash/flashchange.c | 8 + lib/ultralib/src/flash/flashcheckeraseend.c | 23 + lib/ultralib/src/flash/flashclearstatus.c | 10 + lib/ultralib/src/flash/flashgetaddr.c | 15 + lib/ultralib/src/flash/flashinit.c | 44 + lib/ultralib/src/flash/flashreadarray.c | 51 + lib/ultralib/src/flash/flashreadid.c | 27 + lib/ultralib/src/flash/flashreadstatus.c | 17 + lib/ultralib/src/flash/flashreinit.c | 14 + lib/ultralib/src/flash/flashsectorerase.c | 32 + .../src/flash/flashsectorerasethrough.c | 8 + lib/ultralib/src/flash/flashwritearray.c | 34 + lib/ultralib/src/flash/flashwritebuffer.c | 20 + lib/ultralib/src/gio/giointerrupt.c | 8 + lib/ultralib/src/gio/giorawinterrupt.c | 13 + lib/ultralib/src/gt/Makefile | 19 + lib/ultralib/src/gt/dumpturbo.c | 260 + lib/ultralib/src/gt/gt.c | 155 + lib/ultralib/src/gt/gtint.h | 36 + lib/ultralib/src/gu/Makefile | 52 + lib/ultralib/src/gu/align.c | 75 + lib/ultralib/src/gu/cosf.c | 137 + lib/ultralib/src/gu/coss.c | 45 + lib/ultralib/src/gu/dump_gbi.c | 274 + lib/ultralib/src/gu/frustum.c | 42 + lib/ultralib/src/gu/guint.h | 42 + lib/ultralib/src/gu/guloadtile_bug.c | 235 + lib/ultralib/src/gu/libm_vals.s | 5 + lib/ultralib/src/gu/loadtextureblockmipmap.c | 717 +++ lib/ultralib/src/gu/lookat.c | 83 + lib/ultralib/src/gu/lookathil.c | 185 + lib/ultralib/src/gu/lookatref.c | 111 + lib/ultralib/src/gu/lookatstereo.c | 111 + lib/ultralib/src/gu/mtxcatf.c | 63 + lib/ultralib/src/gu/mtxcatl.c | 57 + lib/ultralib/src/gu/mtxutil.c | 73 + lib/ultralib/src/gu/normalize.c | 23 + lib/ultralib/src/gu/ortho.c | 41 + lib/ultralib/src/gu/parse_gbi.c | 139 + lib/ultralib/src/gu/parse_rdp.c | 36 + lib/ultralib/src/gu/parse_string.c | 35 + lib/ultralib/src/gu/perspective.c | 58 + lib/ultralib/src/gu/position.c | 73 + lib/ultralib/src/gu/poslight.c | 69 + lib/ultralib/src/gu/poslighthil.c | 168 + lib/ultralib/src/gu/random.c | 33 + lib/ultralib/src/gu/readme.txt | 17 + lib/ultralib/src/gu/rotate.c | 72 + lib/ultralib/src/gu/rotaterpy.c | 58 + lib/ultralib/src/gu/scale.c | 32 + lib/ultralib/src/gu/sinf.c | 157 + lib/ultralib/src/gu/sins.c | 61 + lib/ultralib/src/gu/sintable.h | 1031 ++++ lib/ultralib/src/gu/sqrtf.s | 25 + lib/ultralib/src/gu/translate.c | 31 + lib/ultralib/src/gu/us2dex.c | 73 + lib/ultralib/src/gu/us2dex2_emu.c | 12 + lib/ultralib/src/gu/us2dex_emu.c | 521 ++ lib/ultralib/src/gu/usprite.c | 39 + lib/ultralib/src/host/host_ptn64.c | 209 + lib/ultralib/src/host/readhost.c | 36 + lib/ultralib/src/host/writehost.c | 57 + lib/ultralib/src/io/ai.c | 15 + lib/ultralib/src/io/aigetlen.c | 8 + lib/ultralib/src/io/aigetstat.c | 8 + lib/ultralib/src/io/aisetfreq.c | 53 + lib/ultralib/src/io/aisetnextbuf.c | 52 + lib/ultralib/src/io/cartrominit.c | 95 + lib/ultralib/src/io/contchannelreset.c | 28 + lib/ultralib/src/io/conteeplongread.c | 15 + lib/ultralib/src/io/conteeplongwrite.c | 17 + lib/ultralib/src/io/conteepprobe.c | 34 + lib/ultralib/src/io/conteepread.c | 139 + lib/ultralib/src/io/conteepwrite.c | 203 + lib/ultralib/src/io/contpfs.c | 393 ++ lib/ultralib/src/io/contquery.c | 25 + lib/ultralib/src/io/contramread.c | 163 + lib/ultralib/src/io/contramwrite.c | 165 + lib/ultralib/src/io/contreaddata.c | 68 + lib/ultralib/src/io/contreset.c | 51 + lib/ultralib/src/io/controller.c | 101 + lib/ultralib/src/io/controller.h | 289 ++ lib/ultralib/src/io/controller_gbpak.h | 8 + lib/ultralib/src/io/controller_voice.h | 59 + lib/ultralib/src/io/contsetch.c | 19 + lib/ultralib/src/io/crc.c | 114 + lib/ultralib/src/io/devmgr.c | 108 + lib/ultralib/src/io/dp.c | 15 + lib/ultralib/src/io/dpctr.c | 9 + lib/ultralib/src/io/dpgetstat.c | 9 + lib/ultralib/src/io/dpsetnextbuf.c | 39 + lib/ultralib/src/io/dpsetstat.c | 9 + lib/ultralib/src/io/driverominit.c | 31 + lib/ultralib/src/io/epidma.c | 61 + lib/ultralib/src/io/epigettype.c | 7 + lib/ultralib/src/io/epilinkhandle.c | 11 + lib/ultralib/src/io/epirawdma.c | 53 + lib/ultralib/src/io/epirawread.c | 48 + lib/ultralib/src/io/epirawwrite.c | 22 + lib/ultralib/src/io/epiread.c | 19 + lib/ultralib/src/io/epiwrite.c | 19 + lib/ultralib/src/io/gbpakcheckconnector.c | 131 + lib/ultralib/src/io/gbpakgetbank.c | 28 + lib/ultralib/src/io/gbpakgetstatus.c | 39 + lib/ultralib/src/io/gbpakinit.c | 90 + lib/ultralib/src/io/gbpakpower.c | 34 + lib/ultralib/src/io/gbpakreadid.c | 97 + lib/ultralib/src/io/gbpakreadwrite.c | 74 + lib/ultralib/src/io/gbpaksetbank.c | 35 + lib/ultralib/src/io/leodiskinit.c | 36 + lib/ultralib/src/io/leointerrupt.c | 194 + lib/ultralib/src/io/motor.c | 332 ++ lib/ultralib/src/io/pfsallocatefile.c | 371 ++ lib/ultralib/src/io/pfschecker.c | 258 + lib/ultralib/src/io/pfsdeletefile.c | 180 + lib/ultralib/src/io/pfsfilestate.c | 112 + lib/ultralib/src/io/pfsfreeblocks.c | 31 + lib/ultralib/src/io/pfsgetlabel.c | 25 + lib/ultralib/src/io/pfsgetstatus.c | 100 + lib/ultralib/src/io/pfsinit.c | 25 + lib/ultralib/src/io/pfsinitpak.c | 129 + lib/ultralib/src/io/pfsisplug.c | 97 + lib/ultralib/src/io/pfsnumfiles.c | 34 + lib/ultralib/src/io/pfsreadwritefile.c | 124 + lib/ultralib/src/io/pfsreformat.c | 71 + lib/ultralib/src/io/pfsrepairid.c | 73 + lib/ultralib/src/io/pfssearchfile.c | 56 + lib/ultralib/src/io/pfsselectbank.c | 22 + lib/ultralib/src/io/pfssetlabel.c | 41 + lib/ultralib/src/io/pi.c | 15 + lib/ultralib/src/io/piacs.c | 25 + lib/ultralib/src/io/pidma.c | 66 + lib/ultralib/src/io/pigetcmdq.c | 10 + lib/ultralib/src/io/pigetstat.c | 9 + lib/ultralib/src/io/pigettype.c | 8 + lib/ultralib/src/io/piint.h | 197 + lib/ultralib/src/io/pimgr.c | 114 + lib/ultralib/src/io/pirawdma.c | 53 + lib/ultralib/src/io/pirawread.c | 66 + lib/ultralib/src/io/pirawwrite.c | 21 + lib/ultralib/src/io/piread.c | 19 + lib/ultralib/src/io/piwrite.c | 19 + lib/ultralib/src/io/si.c | 15 + lib/ultralib/src/io/siacs.c | 25 + lib/ultralib/src/io/sigetstat.c | 9 + lib/ultralib/src/io/siint.h | 15 + lib/ultralib/src/io/sirawdma.c | 85 + lib/ultralib/src/io/sirawread.c | 62 + lib/ultralib/src/io/sirawwrite.c | 61 + lib/ultralib/src/io/sp.c | 17 + lib/ultralib/src/io/spgetstat.c | 9 + lib/ultralib/src/io/sprawdma.c | 77 + lib/ultralib/src/io/sprawread.c | 61 + lib/ultralib/src/io/sprawwrite.c | 61 + lib/ultralib/src/io/spsetpc.c | 15 + lib/ultralib/src/io/spsetstat.c | 9 + lib/ultralib/src/io/sptask.c | 82 + lib/ultralib/src/io/sptaskyield.c | 6 + lib/ultralib/src/io/sptaskyielded.c | 18 + lib/ultralib/src/io/vi.c | 39 + lib/ultralib/src/io/viblack.c | 17 + lib/ultralib/src/io/viextendvstart.c | 19 + lib/ultralib/src/io/vifade.c | 18 + lib/ultralib/src/io/vigetcurrcontext.c | 9 + lib/ultralib/src/io/vigetcurrframebuf.c | 20 + lib/ultralib/src/io/vigetfield.c | 6 + lib/ultralib/src/io/vigetline.c | 6 + lib/ultralib/src/io/vigetmode.c | 21 + lib/ultralib/src/io/vigetnextcontext.c | 6 + lib/ultralib/src/io/vigetnextframebuf.c | 20 + lib/ultralib/src/io/vigetstat.c | 6 + lib/ultralib/src/io/viint.h | 71 + lib/ultralib/src/io/vimgr.c | 126 + lib/ultralib/src/io/virepeatline.c | 17 + lib/ultralib/src/io/visetevent.c | 70 + lib/ultralib/src/io/visetmode.c | 67 + lib/ultralib/src/io/visetspecial.c | 72 + lib/ultralib/src/io/visetxscale.c | 37 + lib/ultralib/src/io/visetyscale.c | 34 + lib/ultralib/src/io/viswapbuf.c | 75 + lib/ultralib/src/io/viswapcontext.c | 80 + lib/ultralib/src/io/vitbl.c | 1740 +++++++ lib/ultralib/src/libc/bcmp.s | 96 + lib/ultralib/src/libc/bcopy.s | 220 + lib/ultralib/src/libc/bzero.s | 64 + lib/ultralib/src/libc/ldiv.c | 34 + lib/ultralib/src/libc/ll.c | 48 + lib/ultralib/src/libc/llbit.c | 52 + lib/ultralib/src/libc/llcvt.c | 31 + lib/ultralib/src/libc/sprintf.c | 22 + lib/ultralib/src/libc/string.c | 36 + lib/ultralib/src/libc/syncprintf.c | 154 + lib/ultralib/src/libc/xldtob.c | 309 ++ lib/ultralib/src/libc/xlitob.c | 58 + lib/ultralib/src/libc/xprintf.c | 257 + lib/ultralib/src/libc/xstdio.h | 37 + lib/ultralib/src/log/delay.s | 24 + lib/ultralib/src/log/log.c | 124 + lib/ultralib/src/log/logfloat.c | 11 + lib/ultralib/src/mgu/Makefile | 36 + lib/ultralib/src/mgu/asm.h | 49 + lib/ultralib/src/mgu/mtxcatf.s | 103 + lib/ultralib/src/mgu/mtxcatl.c | 44 + lib/ultralib/src/mgu/mtxf2l.s | 80 + lib/ultralib/src/mgu/mtxident.s | 60 + lib/ultralib/src/mgu/mtxidentf.s | 60 + lib/ultralib/src/mgu/mtxl2f.s | 80 + lib/ultralib/src/mgu/mtxxfmf.c | 40 + lib/ultralib/src/mgu/mtxxfml.c | 41 + lib/ultralib/src/mgu/normalize.s | 56 + lib/ultralib/src/mgu/regdef.h | 187 + lib/ultralib/src/mgu/rotate.c | 73 + lib/ultralib/src/mgu/scale.s | 85 + lib/ultralib/src/mgu/scalef.s | 57 + lib/ultralib/src/mgu/translate.s | 101 + lib/ultralib/src/mgu/translatef.s | 58 + lib/ultralib/src/monutil.s | 188 + lib/ultralib/src/os/ackramromread.c | 16 + lib/ultralib/src/os/ackramromwrite.c | 15 + lib/ultralib/src/os/afterprenmi.c | 5 + lib/ultralib/src/os/atomic.c | 16 + lib/ultralib/src/os/createmesgqueue.c | 20 + lib/ultralib/src/os/createthread.c | 54 + lib/ultralib/src/os/destroythread.c | 49 + lib/ultralib/src/os/exceptasm.h | 29 + lib/ultralib/src/os/exceptasm.s | 1069 ++++ lib/ultralib/src/os/exit.c | 9 + lib/ultralib/src/os/getactivequeue.c | 6 + lib/ultralib/src/os/getcause.s | 9 + lib/ultralib/src/os/getcompare.s | 9 + lib/ultralib/src/os/getconfig.s | 9 + lib/ultralib/src/os/getcount.s | 9 + lib/ultralib/src/os/getcurrfaultthread.c | 6 + lib/ultralib/src/os/getfpccsr.s | 9 + lib/ultralib/src/os/gethwinterrupt.c | 21 + lib/ultralib/src/os/getintmask.s | 33 + lib/ultralib/src/os/getmemsize.c | 53 + lib/ultralib/src/os/getnextfaultthread.c | 23 + lib/ultralib/src/os/getsr.s | 9 + lib/ultralib/src/os/getthreadid.c | 10 + lib/ultralib/src/os/getthreadpri.c | 10 + lib/ultralib/src/os/gettime.c | 25 + lib/ultralib/src/os/gettlbasid.s | 11 + lib/ultralib/src/os/gettlbhi.s | 17 + lib/ultralib/src/os/gettlblo0.s | 17 + lib/ultralib/src/os/gettlblo1.s | 17 + lib/ultralib/src/os/gettlbpagemask.s | 17 + lib/ultralib/src/os/getwatchlo.s | 9 + lib/ultralib/src/os/initialize.c | 224 + lib/ultralib/src/os/initialize_emu.c | 27 + lib/ultralib/src/os/initialize_isv.c | 175 + lib/ultralib/src/os/initialize_kmc.c | 152 + lib/ultralib/src/os/initialize_msp.c | 152 + lib/ultralib/src/os/initrdb.c | 31 + lib/ultralib/src/os/interrupt.s | 52 + lib/ultralib/src/os/invaldcache.s | 58 + lib/ultralib/src/os/invalicache.s | 41 + lib/ultralib/src/os/jammesg.c | 37 + lib/ultralib/src/os/maptlb.s | 111 + lib/ultralib/src/os/maptlbrdb.s | 30 + lib/ultralib/src/os/osint.h | 58 + lib/ultralib/src/os/parameters.s | 17 + lib/ultralib/src/os/physicaltovirtual.c | 6 + lib/ultralib/src/os/probetlb.s | 54 + lib/ultralib/src/os/rdbsend.c | 76 + lib/ultralib/src/os/recvmesg.c | 40 + lib/ultralib/src/os/resetglobalintmask.c | 9 + lib/ultralib/src/os/sendmesg.c | 38 + lib/ultralib/src/os/setcause.s | 9 + lib/ultralib/src/os/setcompare.s | 9 + lib/ultralib/src/os/setconfig.s | 9 + lib/ultralib/src/os/setcount.s | 9 + lib/ultralib/src/os/seterrorhandler.c | 10 + lib/ultralib/src/os/seteventmesg.c | 39 + lib/ultralib/src/os/setfpccsr.s | 10 + lib/ultralib/src/os/setglobalintmask.c | 9 + lib/ultralib/src/os/sethwinterrupt.c | 32 + lib/ultralib/src/os/setintmask.s | 124 + lib/ultralib/src/os/setpiinterrupt.c | 16 + lib/ultralib/src/os/setsr.s | 10 + lib/ultralib/src/os/setthreadpri.c | 36 + lib/ultralib/src/os/settime.c | 16 + lib/ultralib/src/os/settimer.c | 56 + lib/ultralib/src/os/settlbasid.s | 32 + lib/ultralib/src/os/setwatchlo.s | 10 + lib/ultralib/src/os/startthread.c | 39 + lib/ultralib/src/os/stopthread.c | 23 + lib/ultralib/src/os/stoptimer.c | 39 + lib/ultralib/src/os/syncputchars.c | 35 + lib/ultralib/src/os/testhost.c | 12 + lib/ultralib/src/os/thread.c | 28 + lib/ultralib/src/os/threadasm.h | 68 + lib/ultralib/src/os/timerintr.c | 141 + lib/ultralib/src/os/unmaptlb.s | 45 + lib/ultralib/src/os/unmaptlball.s | 26 + lib/ultralib/src/os/virtualtophysical.c | 13 + lib/ultralib/src/os/writebackdcache.s | 35 + lib/ultralib/src/os/writebackdcacheall.s | 18 + lib/ultralib/src/os/yieldthread.c | 10 + lib/ultralib/src/rg/free.c | 73 + lib/ultralib/src/rg/getbufcount.c | 57 + lib/ultralib/src/rg/getsize.c | 57 + lib/ultralib/src/rg/malloc.c | 70 + lib/ultralib/src/rg/printregion.c | 27 + lib/ultralib/src/rg/region.c | 232 + lib/ultralib/src/rmon/rmonbrk.c | 432 ++ lib/ultralib/src/rmon/rmoncmds.c | 54 + lib/ultralib/src/rmon/rmonint.h | 169 + lib/ultralib/src/rmon/rmonmain.c | 138 + lib/ultralib/src/rmon/rmonmem.c | 283 + lib/ultralib/src/rmon/rmonmisc.c | 76 + lib/ultralib/src/rmon/rmonprint.c | 1 + lib/ultralib/src/rmon/rmonrcp.s | 60 + lib/ultralib/src/rmon/rmonregs.c | 417 ++ lib/ultralib/src/rmon/rmonsio.c | 89 + lib/ultralib/src/rmon/rmontask.c | 343 ++ lib/ultralib/src/sched/Makefile | 19 + lib/ultralib/src/sched/sched.c | 620 +++ lib/ultralib/src/sched/sched_log.fmt | 19 + lib/ultralib/src/sp/Makefile | 30 + lib/ultralib/src/sp/clearattribute.c | 35 + lib/ultralib/src/sp/color.c | 39 + lib/ultralib/src/sp/hide.c | 35 + lib/ultralib/src/sp/setattribute.c | 35 + lib/ultralib/src/sp/show.c | 35 + lib/ultralib/src/sp/sprite.c | 761 +++ lib/ultralib/src/sp/spriteex.c | 2 + lib/ultralib/src/sp/spriteex2.c | 2 + lib/ultralib/src/sp/spscale.c | 42 + lib/ultralib/src/vimodes/vimodefpalhaf1.c | 37 + lib/ultralib/src/vimodes/vimodefpalhan1.c | 37 + lib/ultralib/src/vimodes/vimodefpalhpf1.c | 37 + lib/ultralib/src/vimodes/vimodefpalhpf2.c | 37 + lib/ultralib/src/vimodes/vimodefpalhpn1.c | 37 + lib/ultralib/src/vimodes/vimodefpalhpn2.c | 37 + lib/ultralib/src/vimodes/vimodefpallaf1.c | 37 + lib/ultralib/src/vimodes/vimodefpallaf2.c | 37 + lib/ultralib/src/vimodes/vimodefpallan1.c | 37 + lib/ultralib/src/vimodes/vimodefpallan2.c | 36 + lib/ultralib/src/vimodes/vimodefpallpf1.c | 37 + lib/ultralib/src/vimodes/vimodefpallpf2.c | 37 + lib/ultralib/src/vimodes/vimodefpallpn1.c | 37 + lib/ultralib/src/vimodes/vimodefpallpn2.c | 37 + lib/ultralib/src/vimodes/vimodempalhaf1.c | 37 + lib/ultralib/src/vimodes/vimodempalhan1.c | 37 + lib/ultralib/src/vimodes/vimodempalhpf1.c | 37 + lib/ultralib/src/vimodes/vimodempalhpf2.c | 37 + lib/ultralib/src/vimodes/vimodempalhpn1.c | 37 + lib/ultralib/src/vimodes/vimodempalhpn2.c | 37 + lib/ultralib/src/vimodes/vimodempallaf1.c | 37 + lib/ultralib/src/vimodes/vimodempallaf2.c | 37 + lib/ultralib/src/vimodes/vimodempallan1.c | 37 + lib/ultralib/src/vimodes/vimodempallan2.c | 36 + lib/ultralib/src/vimodes/vimodempallpf1.c | 37 + lib/ultralib/src/vimodes/vimodempallpf2.c | 37 + lib/ultralib/src/vimodes/vimodempallpn1.c | 37 + lib/ultralib/src/vimodes/vimodempallpn2.c | 37 + lib/ultralib/src/vimodes/vimodentschaf1.c | 37 + lib/ultralib/src/vimodes/vimodentschan1.c | 37 + lib/ultralib/src/vimodes/vimodentschpf1.c | 37 + lib/ultralib/src/vimodes/vimodentschpf2.c | 37 + lib/ultralib/src/vimodes/vimodentschpn1.c | 37 + lib/ultralib/src/vimodes/vimodentschpn2.c | 37 + lib/ultralib/src/vimodes/vimodentsclaf1.c | 37 + lib/ultralib/src/vimodes/vimodentsclaf2.c | 37 + lib/ultralib/src/vimodes/vimodentsclan1.c | 37 + lib/ultralib/src/vimodes/vimodentsclan2.c | 36 + lib/ultralib/src/vimodes/vimodentsclpf1.c | 37 + lib/ultralib/src/vimodes/vimodentsclpf2.c | 37 + lib/ultralib/src/vimodes/vimodentsclpn1.c | 37 + lib/ultralib/src/vimodes/vimodentsclpn2.c | 37 + lib/ultralib/src/vimodes/vimodepalhaf1.c | 37 + lib/ultralib/src/vimodes/vimodepalhan1.c | 37 + lib/ultralib/src/vimodes/vimodepalhpf1.c | 37 + lib/ultralib/src/vimodes/vimodepalhpf2.c | 37 + lib/ultralib/src/vimodes/vimodepalhpn1.c | 37 + lib/ultralib/src/vimodes/vimodepalhpn2.c | 37 + lib/ultralib/src/vimodes/vimodepallaf1.c | 37 + lib/ultralib/src/vimodes/vimodepallaf2.c | 37 + lib/ultralib/src/vimodes/vimodepallan1.c | 37 + lib/ultralib/src/vimodes/vimodepallan2.c | 36 + lib/ultralib/src/vimodes/vimodepallpf1.c | 37 + lib/ultralib/src/vimodes/vimodepallpf2.c | 37 + lib/ultralib/src/vimodes/vimodepallpn1.c | 37 + lib/ultralib/src/vimodes/vimodepallpn2.c | 37 + lib/ultralib/src/voice/voicecheckresult.c | 28 + lib/ultralib/src/voice/voicecheckword.c | 80 + lib/ultralib/src/voice/voicecleardictionary.c | 29 + lib/ultralib/src/voice/voicecontread2.c | 73 + lib/ultralib/src/voice/voicecontread36.c | 73 + lib/ultralib/src/voice/voicecontrolgain.c | 28 + lib/ultralib/src/voice/voicecontwrite20.c | 74 + lib/ultralib/src/voice/voicecontwrite4.c | 74 + lib/ultralib/src/voice/voicecountsyllables.c | 55 + lib/ultralib/src/voice/voicecrc.c | 40 + lib/ultralib/src/voice/voicegetreaddata.c | 94 + lib/ultralib/src/voice/voicegetstatus.c | 62 + lib/ultralib/src/voice/voiceinit.c | 42 + lib/ultralib/src/voice/voiceinternal.h | 18 + lib/ultralib/src/voice/voicemaskdictionary.c | 48 + lib/ultralib/src/voice/voicesetadconverter.c | 69 + lib/ultralib/src/voice/voicesetword.c | 54 + lib/ultralib/src/voice/voicestartreaddata.c | 36 + lib/ultralib/src/voice/voicestopreaddata.c | 59 + lib/ultralib/tools/Makefile | 46 + lib/ultralib/tools/ar.py | 476 ++ lib/ultralib/tools/asm_differ/.gitignore | 2 + lib/ultralib/tools/asm_differ/.gitrepo | 12 + .../tools/asm_differ/.pre-commit-config.yaml | 6 + lib/ultralib/tools/asm_differ/LICENSE | 24 + lib/ultralib/tools/asm_differ/README.md | 56 + .../tools/asm_differ/diff-stylesheet.css | 67 + lib/ultralib/tools/asm_differ/diff.py | 2923 +++++++++++ .../tools/asm_differ/diff_settings.py | 11 + lib/ultralib/tools/asm_differ/mypy.ini | 17 + lib/ultralib/tools/asm_differ/screenshot.png | Bin 0 -> 99842 bytes lib/ultralib/tools/compile_sjis.py | 28 + lib/ultralib/tools/disassemble_elf.py | 312 ++ lib/ultralib/tools/fix_objfile.py | 68 + lib/ultralib/tools/libdiff.py | 150 + lib/ultralib/tools/libelf.py | 1181 +++++ lib/ultralib/tools/m2ctx.py | 76 + lib/ultralib/tools/mdebug.py | 938 ++++ lib/ultralib/tools/mips_isa.py | 1309 +++++ lib/ultralib/tools/patch_ar_meta.py | 90 + lib/ultralib/tools/print_mdebug.py | 589 +++ lib/ultralib/tools/set_o32abi_bit.py | 25 + lib/ultralib/tools/shiftjis_conv.py | 58 + lib/ultralib/tools/strip_debug.sh | 10 + lib/ultralib/tools/util.py | 44 + 677 files changed, 75409 insertions(+) create mode 100644 lib/ultralib/.github/workflows/ci_egcs.txt create mode 100644 lib/ultralib/.github/workflows/ci_gcc.yml create mode 100644 lib/ultralib/.github/workflows/ci_ido.yml create mode 100644 lib/ultralib/.gitignore create mode 100644 lib/ultralib/.gitrepo create mode 100644 lib/ultralib/Makefile create mode 100644 lib/ultralib/Makefile.gcc create mode 100644 lib/ultralib/Makefile.ido create mode 100644 lib/ultralib/README.md create mode 100644 lib/ultralib/base/I/libgultra.txt create mode 100644 lib/ultralib/base/I/libgultra_d.txt create mode 100644 lib/ultralib/base/I/libgultra_rom.txt create mode 100644 lib/ultralib/base/I/libultra.txt create mode 100644 lib/ultralib/base/I/libultra_d.txt create mode 100644 lib/ultralib/base/I/libultra_rom.txt create mode 100644 lib/ultralib/base/J/libgultra.txt create mode 100644 lib/ultralib/base/J/libgultra_d.txt create mode 100644 lib/ultralib/base/J/libgultra_rom.txt create mode 100644 lib/ultralib/base/J/libultra.txt create mode 100644 lib/ultralib/base/J/libultra_d.txt create mode 100644 lib/ultralib/base/J/libultra_rom.txt create mode 100644 lib/ultralib/base/K/libgultra.txt create mode 100644 lib/ultralib/base/K/libgultra_d.txt create mode 100644 lib/ultralib/base/K/libgultra_rom.txt create mode 100644 lib/ultralib/base/K/libultra.txt create mode 100644 lib/ultralib/base/K/libultra_d.txt create mode 100644 lib/ultralib/base/K/libultra_rom.txt create mode 100644 lib/ultralib/base/L/libgultra.txt create mode 100644 lib/ultralib/base/L/libgultra_d.txt create mode 100644 lib/ultralib/base/L/libgultra_rom.txt create mode 100644 lib/ultralib/base/L/libultra.txt create mode 100644 lib/ultralib/base/L/libultra_d.txt create mode 100644 lib/ultralib/base/L/libultra_rom.txt create mode 100644 lib/ultralib/include/PR/R4300.h create mode 100644 lib/ultralib/include/PR/abi.h create mode 100644 lib/ultralib/include/PR/gbi.h create mode 100644 lib/ultralib/include/PR/gs2dex.h create mode 100644 lib/ultralib/include/PR/gt.h create mode 100644 lib/ultralib/include/PR/gu.h create mode 100644 lib/ultralib/include/PR/libaudio.h create mode 100644 lib/ultralib/include/PR/mbi.h create mode 100644 lib/ultralib/include/PR/os.h create mode 100644 lib/ultralib/include/PR/os_ai.h create mode 100644 lib/ultralib/include/PR/os_cache.h create mode 100644 lib/ultralib/include/PR/os_cont.h create mode 100644 lib/ultralib/include/PR/os_convert.h create mode 100644 lib/ultralib/include/PR/os_debug.h create mode 100644 lib/ultralib/include/PR/os_eeprom.h create mode 100644 lib/ultralib/include/PR/os_error.h create mode 100644 lib/ultralib/include/PR/os_exception.h create mode 100644 lib/ultralib/include/PR/os_flash.h create mode 100644 lib/ultralib/include/PR/os_gbpak.h create mode 100644 lib/ultralib/include/PR/os_gio.h create mode 100644 lib/ultralib/include/PR/os_host.h create mode 100644 lib/ultralib/include/PR/os_internal.h create mode 100644 lib/ultralib/include/PR/os_internal_debug.h create mode 100644 lib/ultralib/include/PR/os_internal_error.h create mode 100644 lib/ultralib/include/PR/os_internal_exception.h create mode 100644 lib/ultralib/include/PR/os_internal_flash.h create mode 100644 lib/ultralib/include/PR/os_internal_gio.h create mode 100644 lib/ultralib/include/PR/os_internal_host.h create mode 100644 lib/ultralib/include/PR/os_internal_reg.h create mode 100644 lib/ultralib/include/PR/os_internal_rsp.h create mode 100644 lib/ultralib/include/PR/os_internal_si.h create mode 100644 lib/ultralib/include/PR/os_internal_thread.h create mode 100644 lib/ultralib/include/PR/os_internal_tlb.h create mode 100644 lib/ultralib/include/PR/os_libc.h create mode 100644 lib/ultralib/include/PR/os_message.h create mode 100644 lib/ultralib/include/PR/os_motor.h create mode 100644 lib/ultralib/include/PR/os_pfs.h create mode 100644 lib/ultralib/include/PR/os_pi.h create mode 100644 lib/ultralib/include/PR/os_rdp.h create mode 100644 lib/ultralib/include/PR/os_reg.h create mode 100644 lib/ultralib/include/PR/os_rsp.h create mode 100644 lib/ultralib/include/PR/os_si.h create mode 100644 lib/ultralib/include/PR/os_system.h create mode 100644 lib/ultralib/include/PR/os_thread.h create mode 100644 lib/ultralib/include/PR/os_time.h create mode 100644 lib/ultralib/include/PR/os_tlb.h create mode 100644 lib/ultralib/include/PR/os_version.h create mode 100644 lib/ultralib/include/PR/os_vi.h create mode 100644 lib/ultralib/include/PR/os_voice.h create mode 100644 lib/ultralib/include/PR/ramrom.h create mode 100644 lib/ultralib/include/PR/rcp.h create mode 100644 lib/ultralib/include/PR/rdb.h create mode 100644 lib/ultralib/include/PR/region.h create mode 100644 lib/ultralib/include/PR/rmon.h create mode 100644 lib/ultralib/include/PR/sched.h create mode 100644 lib/ultralib/include/PR/sp.h create mode 100644 lib/ultralib/include/PR/sptask.h create mode 100644 lib/ultralib/include/PR/ucode.h create mode 100644 lib/ultralib/include/PR/ultraerror.h create mode 100644 lib/ultralib/include/PR/ultralog.h create mode 100644 lib/ultralib/include/PR/ultratypes.h create mode 100644 lib/ultralib/include/asm.h create mode 100644 lib/ultralib/include/assert.h create mode 100644 lib/ultralib/include/dbgdefs.h create mode 100644 lib/ultralib/include/dbgproto.h create mode 100644 lib/ultralib/include/fpregdef.h create mode 100644 lib/ultralib/include/gcc/math.h create mode 100644 lib/ultralib/include/gcc/memory.h create mode 100644 lib/ultralib/include/gcc/sgidefs.h create mode 100644 lib/ultralib/include/gcc/stdarg.h create mode 100644 lib/ultralib/include/gcc/stdio.h create mode 100644 lib/ultralib/include/gcc/stdlib.h create mode 100644 lib/ultralib/include/gcc/string.h create mode 100644 lib/ultralib/include/ido/math.h create mode 100644 lib/ultralib/include/ido/memory.h create mode 100644 lib/ultralib/include/ido/stdarg.h create mode 100644 lib/ultralib/include/ido/stdio.h create mode 100644 lib/ultralib/include/ido/stdlib.h create mode 100644 lib/ultralib/include/ido/string.h create mode 100644 lib/ultralib/include/macros.h create mode 100644 lib/ultralib/include/regdef.h create mode 100644 lib/ultralib/include/sgidefs.h create mode 100644 lib/ultralib/include/sys/asm.h create mode 100644 lib/ultralib/include/sys/fpregdef.h create mode 100644 lib/ultralib/include/sys/regdef.h create mode 100644 lib/ultralib/include/ultra64.h create mode 100644 lib/ultralib/include/ultrahost.h create mode 100644 lib/ultralib/src/audio/Makefile create mode 100644 lib/ultralib/src/audio/auxbus.c create mode 100644 lib/ultralib/src/audio/bnkf.c create mode 100644 lib/ultralib/src/audio/cents2ratio.c create mode 100644 lib/ultralib/src/audio/copy.c create mode 100644 lib/ultralib/src/audio/cseq.c create mode 100644 lib/ultralib/src/audio/cseq.h create mode 100644 lib/ultralib/src/audio/cseqp.h create mode 100644 lib/ultralib/src/audio/cspdelete.c create mode 100644 lib/ultralib/src/audio/cspgetchlvol.c create mode 100644 lib/ultralib/src/audio/cspgetfxmix.c create mode 100644 lib/ultralib/src/audio/cspgetpan.c create mode 100644 lib/ultralib/src/audio/cspgetpriority.c create mode 100644 lib/ultralib/src/audio/cspgetprogram.c create mode 100644 lib/ultralib/src/audio/cspgetseq.c create mode 100644 lib/ultralib/src/audio/cspgetstate.c create mode 100644 lib/ultralib/src/audio/cspgettempo.c create mode 100644 lib/ultralib/src/audio/cspgetvol.c create mode 100644 lib/ultralib/src/audio/csplayer.c create mode 100644 lib/ultralib/src/audio/cspplay.c create mode 100644 lib/ultralib/src/audio/cspsendmidi.c create mode 100644 lib/ultralib/src/audio/cspsetbank.c create mode 100644 lib/ultralib/src/audio/cspsetchlvol.c create mode 100644 lib/ultralib/src/audio/cspsetfxmix.c create mode 100644 lib/ultralib/src/audio/cspsetpan.c create mode 100644 lib/ultralib/src/audio/cspsetpriority.c create mode 100644 lib/ultralib/src/audio/cspsetprogram.c create mode 100644 lib/ultralib/src/audio/cspsetseq.c create mode 100644 lib/ultralib/src/audio/cspsettempo.c create mode 100644 lib/ultralib/src/audio/cspsetvol.c create mode 100644 lib/ultralib/src/audio/cspstop.c create mode 100644 lib/ultralib/src/audio/drvrnew.c create mode 100644 lib/ultralib/src/audio/env.c create mode 100644 lib/ultralib/src/audio/event.c create mode 100644 lib/ultralib/src/audio/filter.c create mode 100644 lib/ultralib/src/audio/heapalloc.c create mode 100644 lib/ultralib/src/audio/heapcheck.c create mode 100644 lib/ultralib/src/audio/heapinit.c create mode 100644 lib/ultralib/src/audio/initfx.h create mode 100644 lib/ultralib/src/audio/load.c create mode 100644 lib/ultralib/src/audio/mainbus.c create mode 100644 lib/ultralib/src/audio/parse_abi.c create mode 100644 lib/ultralib/src/audio/resample.c create mode 100644 lib/ultralib/src/audio/reverb.c create mode 100644 lib/ultralib/src/audio/save.c create mode 100644 lib/ultralib/src/audio/seq.c create mode 100644 lib/ultralib/src/audio/seq.h create mode 100644 lib/ultralib/src/audio/seqp.h create mode 100644 lib/ultralib/src/audio/seqpdelete.c create mode 100644 lib/ultralib/src/audio/seqpgetchlvol.c create mode 100644 lib/ultralib/src/audio/seqpgetfxmix.c create mode 100644 lib/ultralib/src/audio/seqpgetpan.c create mode 100644 lib/ultralib/src/audio/seqpgetpriority.c create mode 100644 lib/ultralib/src/audio/seqpgetprogram.c create mode 100644 lib/ultralib/src/audio/seqpgetseq.c create mode 100644 lib/ultralib/src/audio/seqpgetstate.c create mode 100644 lib/ultralib/src/audio/seqpgettempo.c create mode 100644 lib/ultralib/src/audio/seqpgetvol.c create mode 100644 lib/ultralib/src/audio/seqplayer.c create mode 100644 lib/ultralib/src/audio/seqploop.c create mode 100644 lib/ultralib/src/audio/seqpplay.c create mode 100644 lib/ultralib/src/audio/seqpsendmidi.c create mode 100644 lib/ultralib/src/audio/seqpsetbank.c create mode 100644 lib/ultralib/src/audio/seqpsetchlvol.c create mode 100644 lib/ultralib/src/audio/seqpsetfxmix.c create mode 100644 lib/ultralib/src/audio/seqpsetpan.c create mode 100644 lib/ultralib/src/audio/seqpsetpriority.c create mode 100644 lib/ultralib/src/audio/seqpsetprogram.c create mode 100644 lib/ultralib/src/audio/seqpsetseq.c create mode 100644 lib/ultralib/src/audio/seqpsettempo.c create mode 100644 lib/ultralib/src/audio/seqpsetvol.c create mode 100644 lib/ultralib/src/audio/seqpstop.c create mode 100644 lib/ultralib/src/audio/sl.c create mode 100644 lib/ultralib/src/audio/sndp.h create mode 100644 lib/ultralib/src/audio/sndpallocate.c create mode 100644 lib/ultralib/src/audio/sndpdeallocate.c create mode 100644 lib/ultralib/src/audio/sndpdelete.c create mode 100644 lib/ultralib/src/audio/sndpgetsound.c create mode 100644 lib/ultralib/src/audio/sndpgetstate.c create mode 100644 lib/ultralib/src/audio/sndplayer.c create mode 100644 lib/ultralib/src/audio/sndpplay.c create mode 100644 lib/ultralib/src/audio/sndpplayat.c create mode 100644 lib/ultralib/src/audio/sndpsetfxmix.c create mode 100644 lib/ultralib/src/audio/sndpsetpan.c create mode 100644 lib/ultralib/src/audio/sndpsetpitch.c create mode 100644 lib/ultralib/src/audio/sndpsetpriority.c create mode 100644 lib/ultralib/src/audio/sndpsetsound.c create mode 100644 lib/ultralib/src/audio/sndpsetvol.c create mode 100644 lib/ultralib/src/audio/sndpstop.c create mode 100644 lib/ultralib/src/audio/synaddplayer.c create mode 100644 lib/ultralib/src/audio/synallocfx.c create mode 100644 lib/ultralib/src/audio/synallocvoice.c create mode 100644 lib/ultralib/src/audio/syndelete.c create mode 100644 lib/ultralib/src/audio/synfreefx.c create mode 100644 lib/ultralib/src/audio/synfreevoice.c create mode 100644 lib/ultralib/src/audio/syngetfxref.c create mode 100644 lib/ultralib/src/audio/syngetpriority.c create mode 100644 lib/ultralib/src/audio/synremoveplayer.c create mode 100644 lib/ultralib/src/audio/synsetfxmix.c create mode 100644 lib/ultralib/src/audio/synsetfxparam.c create mode 100644 lib/ultralib/src/audio/synsetpan.c create mode 100644 lib/ultralib/src/audio/synsetpitch.c create mode 100644 lib/ultralib/src/audio/synsetpriority.c create mode 100644 lib/ultralib/src/audio/synsetvol.c create mode 100644 lib/ultralib/src/audio/synstartvoice.c create mode 100644 lib/ultralib/src/audio/synstartvoiceparam.c create mode 100644 lib/ultralib/src/audio/synstopvoice.c create mode 100644 lib/ultralib/src/audio/synthInternals.h create mode 100644 lib/ultralib/src/audio/synthesizer.c create mode 100644 lib/ultralib/src/debug/assert.c create mode 100644 lib/ultralib/src/debug/assertbreak.s create mode 100644 lib/ultralib/src/debug/atomic.c create mode 100644 lib/ultralib/src/debug/kdebugserver.c create mode 100644 lib/ultralib/src/debug/osint_debug.h create mode 100644 lib/ultralib/src/debug/profile.c create mode 100644 lib/ultralib/src/debug/threadprofile.c create mode 100644 lib/ultralib/src/debug/threadprofileclear.c create mode 100644 lib/ultralib/src/debug/threadprofileinit.c create mode 100644 lib/ultralib/src/debug/threadprofilereadcount.c create mode 100644 lib/ultralib/src/debug/threadprofilereadtime.c create mode 100644 lib/ultralib/src/debug/threadprofilestart.c create mode 100644 lib/ultralib/src/debug/threadprofilestop.c create mode 100644 lib/ultralib/src/error/commonerror.c create mode 100644 lib/ultralib/src/error/error.c create mode 100644 lib/ultralib/src/error/errorasm.s create mode 100644 lib/ultralib/src/flash/flashallerase.c create mode 100644 lib/ultralib/src/flash/flashallerasethrough.c create mode 100644 lib/ultralib/src/flash/flashchange.c create mode 100644 lib/ultralib/src/flash/flashcheckeraseend.c create mode 100644 lib/ultralib/src/flash/flashclearstatus.c create mode 100644 lib/ultralib/src/flash/flashgetaddr.c create mode 100644 lib/ultralib/src/flash/flashinit.c create mode 100644 lib/ultralib/src/flash/flashreadarray.c create mode 100644 lib/ultralib/src/flash/flashreadid.c create mode 100644 lib/ultralib/src/flash/flashreadstatus.c create mode 100644 lib/ultralib/src/flash/flashreinit.c create mode 100644 lib/ultralib/src/flash/flashsectorerase.c create mode 100644 lib/ultralib/src/flash/flashsectorerasethrough.c create mode 100644 lib/ultralib/src/flash/flashwritearray.c create mode 100644 lib/ultralib/src/flash/flashwritebuffer.c create mode 100644 lib/ultralib/src/gio/giointerrupt.c create mode 100644 lib/ultralib/src/gio/giorawinterrupt.c create mode 100644 lib/ultralib/src/gt/Makefile create mode 100644 lib/ultralib/src/gt/dumpturbo.c create mode 100644 lib/ultralib/src/gt/gt.c create mode 100644 lib/ultralib/src/gt/gtint.h create mode 100644 lib/ultralib/src/gu/Makefile create mode 100644 lib/ultralib/src/gu/align.c create mode 100644 lib/ultralib/src/gu/cosf.c create mode 100644 lib/ultralib/src/gu/coss.c create mode 100644 lib/ultralib/src/gu/dump_gbi.c create mode 100644 lib/ultralib/src/gu/frustum.c create mode 100644 lib/ultralib/src/gu/guint.h create mode 100644 lib/ultralib/src/gu/guloadtile_bug.c create mode 100644 lib/ultralib/src/gu/libm_vals.s create mode 100644 lib/ultralib/src/gu/loadtextureblockmipmap.c create mode 100644 lib/ultralib/src/gu/lookat.c create mode 100644 lib/ultralib/src/gu/lookathil.c create mode 100644 lib/ultralib/src/gu/lookatref.c create mode 100644 lib/ultralib/src/gu/lookatstereo.c create mode 100644 lib/ultralib/src/gu/mtxcatf.c create mode 100644 lib/ultralib/src/gu/mtxcatl.c create mode 100644 lib/ultralib/src/gu/mtxutil.c create mode 100644 lib/ultralib/src/gu/normalize.c create mode 100644 lib/ultralib/src/gu/ortho.c create mode 100644 lib/ultralib/src/gu/parse_gbi.c create mode 100644 lib/ultralib/src/gu/parse_rdp.c create mode 100644 lib/ultralib/src/gu/parse_string.c create mode 100644 lib/ultralib/src/gu/perspective.c create mode 100644 lib/ultralib/src/gu/position.c create mode 100644 lib/ultralib/src/gu/poslight.c create mode 100644 lib/ultralib/src/gu/poslighthil.c create mode 100644 lib/ultralib/src/gu/random.c create mode 100644 lib/ultralib/src/gu/readme.txt create mode 100644 lib/ultralib/src/gu/rotate.c create mode 100644 lib/ultralib/src/gu/rotaterpy.c create mode 100644 lib/ultralib/src/gu/scale.c create mode 100644 lib/ultralib/src/gu/sinf.c create mode 100644 lib/ultralib/src/gu/sins.c create mode 100644 lib/ultralib/src/gu/sintable.h create mode 100644 lib/ultralib/src/gu/sqrtf.s create mode 100644 lib/ultralib/src/gu/translate.c create mode 100644 lib/ultralib/src/gu/us2dex.c create mode 100644 lib/ultralib/src/gu/us2dex2_emu.c create mode 100644 lib/ultralib/src/gu/us2dex_emu.c create mode 100644 lib/ultralib/src/gu/usprite.c create mode 100644 lib/ultralib/src/host/host_ptn64.c create mode 100644 lib/ultralib/src/host/readhost.c create mode 100644 lib/ultralib/src/host/writehost.c create mode 100644 lib/ultralib/src/io/ai.c create mode 100644 lib/ultralib/src/io/aigetlen.c create mode 100644 lib/ultralib/src/io/aigetstat.c create mode 100644 lib/ultralib/src/io/aisetfreq.c create mode 100644 lib/ultralib/src/io/aisetnextbuf.c create mode 100644 lib/ultralib/src/io/cartrominit.c create mode 100644 lib/ultralib/src/io/contchannelreset.c create mode 100644 lib/ultralib/src/io/conteeplongread.c create mode 100644 lib/ultralib/src/io/conteeplongwrite.c create mode 100644 lib/ultralib/src/io/conteepprobe.c create mode 100644 lib/ultralib/src/io/conteepread.c create mode 100644 lib/ultralib/src/io/conteepwrite.c create mode 100644 lib/ultralib/src/io/contpfs.c create mode 100644 lib/ultralib/src/io/contquery.c create mode 100644 lib/ultralib/src/io/contramread.c create mode 100644 lib/ultralib/src/io/contramwrite.c create mode 100644 lib/ultralib/src/io/contreaddata.c create mode 100644 lib/ultralib/src/io/contreset.c create mode 100644 lib/ultralib/src/io/controller.c create mode 100644 lib/ultralib/src/io/controller.h create mode 100644 lib/ultralib/src/io/controller_gbpak.h create mode 100644 lib/ultralib/src/io/controller_voice.h create mode 100644 lib/ultralib/src/io/contsetch.c create mode 100644 lib/ultralib/src/io/crc.c create mode 100644 lib/ultralib/src/io/devmgr.c create mode 100644 lib/ultralib/src/io/dp.c create mode 100644 lib/ultralib/src/io/dpctr.c create mode 100644 lib/ultralib/src/io/dpgetstat.c create mode 100644 lib/ultralib/src/io/dpsetnextbuf.c create mode 100644 lib/ultralib/src/io/dpsetstat.c create mode 100644 lib/ultralib/src/io/driverominit.c create mode 100644 lib/ultralib/src/io/epidma.c create mode 100644 lib/ultralib/src/io/epigettype.c create mode 100644 lib/ultralib/src/io/epilinkhandle.c create mode 100644 lib/ultralib/src/io/epirawdma.c create mode 100644 lib/ultralib/src/io/epirawread.c create mode 100644 lib/ultralib/src/io/epirawwrite.c create mode 100644 lib/ultralib/src/io/epiread.c create mode 100644 lib/ultralib/src/io/epiwrite.c create mode 100644 lib/ultralib/src/io/gbpakcheckconnector.c create mode 100644 lib/ultralib/src/io/gbpakgetbank.c create mode 100644 lib/ultralib/src/io/gbpakgetstatus.c create mode 100644 lib/ultralib/src/io/gbpakinit.c create mode 100644 lib/ultralib/src/io/gbpakpower.c create mode 100644 lib/ultralib/src/io/gbpakreadid.c create mode 100644 lib/ultralib/src/io/gbpakreadwrite.c create mode 100644 lib/ultralib/src/io/gbpaksetbank.c create mode 100644 lib/ultralib/src/io/leodiskinit.c create mode 100644 lib/ultralib/src/io/leointerrupt.c create mode 100644 lib/ultralib/src/io/motor.c create mode 100644 lib/ultralib/src/io/pfsallocatefile.c create mode 100644 lib/ultralib/src/io/pfschecker.c create mode 100644 lib/ultralib/src/io/pfsdeletefile.c create mode 100644 lib/ultralib/src/io/pfsfilestate.c create mode 100644 lib/ultralib/src/io/pfsfreeblocks.c create mode 100644 lib/ultralib/src/io/pfsgetlabel.c create mode 100644 lib/ultralib/src/io/pfsgetstatus.c create mode 100644 lib/ultralib/src/io/pfsinit.c create mode 100644 lib/ultralib/src/io/pfsinitpak.c create mode 100644 lib/ultralib/src/io/pfsisplug.c create mode 100644 lib/ultralib/src/io/pfsnumfiles.c create mode 100644 lib/ultralib/src/io/pfsreadwritefile.c create mode 100644 lib/ultralib/src/io/pfsreformat.c create mode 100644 lib/ultralib/src/io/pfsrepairid.c create mode 100644 lib/ultralib/src/io/pfssearchfile.c create mode 100644 lib/ultralib/src/io/pfsselectbank.c create mode 100644 lib/ultralib/src/io/pfssetlabel.c create mode 100644 lib/ultralib/src/io/pi.c create mode 100644 lib/ultralib/src/io/piacs.c create mode 100644 lib/ultralib/src/io/pidma.c create mode 100644 lib/ultralib/src/io/pigetcmdq.c create mode 100644 lib/ultralib/src/io/pigetstat.c create mode 100644 lib/ultralib/src/io/pigettype.c create mode 100644 lib/ultralib/src/io/piint.h create mode 100644 lib/ultralib/src/io/pimgr.c create mode 100644 lib/ultralib/src/io/pirawdma.c create mode 100644 lib/ultralib/src/io/pirawread.c create mode 100644 lib/ultralib/src/io/pirawwrite.c create mode 100644 lib/ultralib/src/io/piread.c create mode 100644 lib/ultralib/src/io/piwrite.c create mode 100644 lib/ultralib/src/io/si.c create mode 100644 lib/ultralib/src/io/siacs.c create mode 100644 lib/ultralib/src/io/sigetstat.c create mode 100644 lib/ultralib/src/io/siint.h create mode 100644 lib/ultralib/src/io/sirawdma.c create mode 100644 lib/ultralib/src/io/sirawread.c create mode 100644 lib/ultralib/src/io/sirawwrite.c create mode 100644 lib/ultralib/src/io/sp.c create mode 100644 lib/ultralib/src/io/spgetstat.c create mode 100644 lib/ultralib/src/io/sprawdma.c create mode 100644 lib/ultralib/src/io/sprawread.c create mode 100644 lib/ultralib/src/io/sprawwrite.c create mode 100644 lib/ultralib/src/io/spsetpc.c create mode 100644 lib/ultralib/src/io/spsetstat.c create mode 100644 lib/ultralib/src/io/sptask.c create mode 100644 lib/ultralib/src/io/sptaskyield.c create mode 100644 lib/ultralib/src/io/sptaskyielded.c create mode 100644 lib/ultralib/src/io/vi.c create mode 100644 lib/ultralib/src/io/viblack.c create mode 100644 lib/ultralib/src/io/viextendvstart.c create mode 100644 lib/ultralib/src/io/vifade.c create mode 100644 lib/ultralib/src/io/vigetcurrcontext.c create mode 100644 lib/ultralib/src/io/vigetcurrframebuf.c create mode 100644 lib/ultralib/src/io/vigetfield.c create mode 100644 lib/ultralib/src/io/vigetline.c create mode 100644 lib/ultralib/src/io/vigetmode.c create mode 100644 lib/ultralib/src/io/vigetnextcontext.c create mode 100644 lib/ultralib/src/io/vigetnextframebuf.c create mode 100644 lib/ultralib/src/io/vigetstat.c create mode 100644 lib/ultralib/src/io/viint.h create mode 100644 lib/ultralib/src/io/vimgr.c create mode 100644 lib/ultralib/src/io/virepeatline.c create mode 100644 lib/ultralib/src/io/visetevent.c create mode 100644 lib/ultralib/src/io/visetmode.c create mode 100644 lib/ultralib/src/io/visetspecial.c create mode 100644 lib/ultralib/src/io/visetxscale.c create mode 100644 lib/ultralib/src/io/visetyscale.c create mode 100644 lib/ultralib/src/io/viswapbuf.c create mode 100644 lib/ultralib/src/io/viswapcontext.c create mode 100644 lib/ultralib/src/io/vitbl.c create mode 100644 lib/ultralib/src/libc/bcmp.s create mode 100644 lib/ultralib/src/libc/bcopy.s create mode 100644 lib/ultralib/src/libc/bzero.s create mode 100644 lib/ultralib/src/libc/ldiv.c create mode 100644 lib/ultralib/src/libc/ll.c create mode 100644 lib/ultralib/src/libc/llbit.c create mode 100644 lib/ultralib/src/libc/llcvt.c create mode 100644 lib/ultralib/src/libc/sprintf.c create mode 100644 lib/ultralib/src/libc/string.c create mode 100644 lib/ultralib/src/libc/syncprintf.c create mode 100644 lib/ultralib/src/libc/xldtob.c create mode 100644 lib/ultralib/src/libc/xlitob.c create mode 100644 lib/ultralib/src/libc/xprintf.c create mode 100644 lib/ultralib/src/libc/xstdio.h create mode 100644 lib/ultralib/src/log/delay.s create mode 100644 lib/ultralib/src/log/log.c create mode 100644 lib/ultralib/src/log/logfloat.c create mode 100644 lib/ultralib/src/mgu/Makefile create mode 100644 lib/ultralib/src/mgu/asm.h create mode 100644 lib/ultralib/src/mgu/mtxcatf.s create mode 100644 lib/ultralib/src/mgu/mtxcatl.c create mode 100644 lib/ultralib/src/mgu/mtxf2l.s create mode 100644 lib/ultralib/src/mgu/mtxident.s create mode 100644 lib/ultralib/src/mgu/mtxidentf.s create mode 100644 lib/ultralib/src/mgu/mtxl2f.s create mode 100644 lib/ultralib/src/mgu/mtxxfmf.c create mode 100644 lib/ultralib/src/mgu/mtxxfml.c create mode 100644 lib/ultralib/src/mgu/normalize.s create mode 100644 lib/ultralib/src/mgu/regdef.h create mode 100644 lib/ultralib/src/mgu/rotate.c create mode 100644 lib/ultralib/src/mgu/scale.s create mode 100644 lib/ultralib/src/mgu/scalef.s create mode 100644 lib/ultralib/src/mgu/translate.s create mode 100644 lib/ultralib/src/mgu/translatef.s create mode 100644 lib/ultralib/src/monutil.s create mode 100644 lib/ultralib/src/os/ackramromread.c create mode 100644 lib/ultralib/src/os/ackramromwrite.c create mode 100644 lib/ultralib/src/os/afterprenmi.c create mode 100644 lib/ultralib/src/os/atomic.c create mode 100644 lib/ultralib/src/os/createmesgqueue.c create mode 100644 lib/ultralib/src/os/createthread.c create mode 100644 lib/ultralib/src/os/destroythread.c create mode 100644 lib/ultralib/src/os/exceptasm.h create mode 100644 lib/ultralib/src/os/exceptasm.s create mode 100644 lib/ultralib/src/os/exit.c create mode 100644 lib/ultralib/src/os/getactivequeue.c create mode 100644 lib/ultralib/src/os/getcause.s create mode 100644 lib/ultralib/src/os/getcompare.s create mode 100644 lib/ultralib/src/os/getconfig.s create mode 100644 lib/ultralib/src/os/getcount.s create mode 100644 lib/ultralib/src/os/getcurrfaultthread.c create mode 100644 lib/ultralib/src/os/getfpccsr.s create mode 100644 lib/ultralib/src/os/gethwinterrupt.c create mode 100644 lib/ultralib/src/os/getintmask.s create mode 100644 lib/ultralib/src/os/getmemsize.c create mode 100644 lib/ultralib/src/os/getnextfaultthread.c create mode 100644 lib/ultralib/src/os/getsr.s create mode 100644 lib/ultralib/src/os/getthreadid.c create mode 100644 lib/ultralib/src/os/getthreadpri.c create mode 100644 lib/ultralib/src/os/gettime.c create mode 100644 lib/ultralib/src/os/gettlbasid.s create mode 100644 lib/ultralib/src/os/gettlbhi.s create mode 100644 lib/ultralib/src/os/gettlblo0.s create mode 100644 lib/ultralib/src/os/gettlblo1.s create mode 100644 lib/ultralib/src/os/gettlbpagemask.s create mode 100644 lib/ultralib/src/os/getwatchlo.s create mode 100644 lib/ultralib/src/os/initialize.c create mode 100644 lib/ultralib/src/os/initialize_emu.c create mode 100644 lib/ultralib/src/os/initialize_isv.c create mode 100644 lib/ultralib/src/os/initialize_kmc.c create mode 100644 lib/ultralib/src/os/initialize_msp.c create mode 100644 lib/ultralib/src/os/initrdb.c create mode 100644 lib/ultralib/src/os/interrupt.s create mode 100644 lib/ultralib/src/os/invaldcache.s create mode 100644 lib/ultralib/src/os/invalicache.s create mode 100644 lib/ultralib/src/os/jammesg.c create mode 100644 lib/ultralib/src/os/maptlb.s create mode 100644 lib/ultralib/src/os/maptlbrdb.s create mode 100644 lib/ultralib/src/os/osint.h create mode 100644 lib/ultralib/src/os/parameters.s create mode 100644 lib/ultralib/src/os/physicaltovirtual.c create mode 100644 lib/ultralib/src/os/probetlb.s create mode 100644 lib/ultralib/src/os/rdbsend.c create mode 100644 lib/ultralib/src/os/recvmesg.c create mode 100644 lib/ultralib/src/os/resetglobalintmask.c create mode 100644 lib/ultralib/src/os/sendmesg.c create mode 100644 lib/ultralib/src/os/setcause.s create mode 100644 lib/ultralib/src/os/setcompare.s create mode 100644 lib/ultralib/src/os/setconfig.s create mode 100644 lib/ultralib/src/os/setcount.s create mode 100644 lib/ultralib/src/os/seterrorhandler.c create mode 100644 lib/ultralib/src/os/seteventmesg.c create mode 100644 lib/ultralib/src/os/setfpccsr.s create mode 100644 lib/ultralib/src/os/setglobalintmask.c create mode 100644 lib/ultralib/src/os/sethwinterrupt.c create mode 100644 lib/ultralib/src/os/setintmask.s create mode 100644 lib/ultralib/src/os/setpiinterrupt.c create mode 100644 lib/ultralib/src/os/setsr.s create mode 100644 lib/ultralib/src/os/setthreadpri.c create mode 100644 lib/ultralib/src/os/settime.c create mode 100644 lib/ultralib/src/os/settimer.c create mode 100644 lib/ultralib/src/os/settlbasid.s create mode 100644 lib/ultralib/src/os/setwatchlo.s create mode 100644 lib/ultralib/src/os/startthread.c create mode 100644 lib/ultralib/src/os/stopthread.c create mode 100644 lib/ultralib/src/os/stoptimer.c create mode 100644 lib/ultralib/src/os/syncputchars.c create mode 100644 lib/ultralib/src/os/testhost.c create mode 100644 lib/ultralib/src/os/thread.c create mode 100644 lib/ultralib/src/os/threadasm.h create mode 100644 lib/ultralib/src/os/timerintr.c create mode 100644 lib/ultralib/src/os/unmaptlb.s create mode 100644 lib/ultralib/src/os/unmaptlball.s create mode 100644 lib/ultralib/src/os/virtualtophysical.c create mode 100644 lib/ultralib/src/os/writebackdcache.s create mode 100644 lib/ultralib/src/os/writebackdcacheall.s create mode 100644 lib/ultralib/src/os/yieldthread.c create mode 100644 lib/ultralib/src/rg/free.c create mode 100644 lib/ultralib/src/rg/getbufcount.c create mode 100644 lib/ultralib/src/rg/getsize.c create mode 100644 lib/ultralib/src/rg/malloc.c create mode 100644 lib/ultralib/src/rg/printregion.c create mode 100644 lib/ultralib/src/rg/region.c create mode 100644 lib/ultralib/src/rmon/rmonbrk.c create mode 100644 lib/ultralib/src/rmon/rmoncmds.c create mode 100644 lib/ultralib/src/rmon/rmonint.h create mode 100644 lib/ultralib/src/rmon/rmonmain.c create mode 100644 lib/ultralib/src/rmon/rmonmem.c create mode 100644 lib/ultralib/src/rmon/rmonmisc.c create mode 100644 lib/ultralib/src/rmon/rmonprint.c create mode 100644 lib/ultralib/src/rmon/rmonrcp.s create mode 100644 lib/ultralib/src/rmon/rmonregs.c create mode 100644 lib/ultralib/src/rmon/rmonsio.c create mode 100644 lib/ultralib/src/rmon/rmontask.c create mode 100644 lib/ultralib/src/sched/Makefile create mode 100644 lib/ultralib/src/sched/sched.c create mode 100644 lib/ultralib/src/sched/sched_log.fmt create mode 100644 lib/ultralib/src/sp/Makefile create mode 100644 lib/ultralib/src/sp/clearattribute.c create mode 100644 lib/ultralib/src/sp/color.c create mode 100644 lib/ultralib/src/sp/hide.c create mode 100644 lib/ultralib/src/sp/setattribute.c create mode 100644 lib/ultralib/src/sp/show.c create mode 100644 lib/ultralib/src/sp/sprite.c create mode 100644 lib/ultralib/src/sp/spriteex.c create mode 100644 lib/ultralib/src/sp/spriteex2.c create mode 100644 lib/ultralib/src/sp/spscale.c create mode 100644 lib/ultralib/src/vimodes/vimodefpalhaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpalhan1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpalhpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpalhpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodefpalhpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpalhpn2.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallaf2.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallan1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallan2.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodefpallpn2.c create mode 100644 lib/ultralib/src/vimodes/vimodempalhaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodempalhan1.c create mode 100644 lib/ultralib/src/vimodes/vimodempalhpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodempalhpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodempalhpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodempalhpn2.c create mode 100644 lib/ultralib/src/vimodes/vimodempallaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodempallaf2.c create mode 100644 lib/ultralib/src/vimodes/vimodempallan1.c create mode 100644 lib/ultralib/src/vimodes/vimodempallan2.c create mode 100644 lib/ultralib/src/vimodes/vimodempallpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodempallpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodempallpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodempallpn2.c create mode 100644 lib/ultralib/src/vimodes/vimodentschaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodentschan1.c create mode 100644 lib/ultralib/src/vimodes/vimodentschpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodentschpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodentschpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodentschpn2.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclaf2.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclan1.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclan2.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodentsclpn2.c create mode 100644 lib/ultralib/src/vimodes/vimodepalhaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodepalhan1.c create mode 100644 lib/ultralib/src/vimodes/vimodepalhpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodepalhpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodepalhpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodepalhpn2.c create mode 100644 lib/ultralib/src/vimodes/vimodepallaf1.c create mode 100644 lib/ultralib/src/vimodes/vimodepallaf2.c create mode 100644 lib/ultralib/src/vimodes/vimodepallan1.c create mode 100644 lib/ultralib/src/vimodes/vimodepallan2.c create mode 100644 lib/ultralib/src/vimodes/vimodepallpf1.c create mode 100644 lib/ultralib/src/vimodes/vimodepallpf2.c create mode 100644 lib/ultralib/src/vimodes/vimodepallpn1.c create mode 100644 lib/ultralib/src/vimodes/vimodepallpn2.c create mode 100644 lib/ultralib/src/voice/voicecheckresult.c create mode 100644 lib/ultralib/src/voice/voicecheckword.c create mode 100644 lib/ultralib/src/voice/voicecleardictionary.c create mode 100644 lib/ultralib/src/voice/voicecontread2.c create mode 100644 lib/ultralib/src/voice/voicecontread36.c create mode 100644 lib/ultralib/src/voice/voicecontrolgain.c create mode 100644 lib/ultralib/src/voice/voicecontwrite20.c create mode 100644 lib/ultralib/src/voice/voicecontwrite4.c create mode 100644 lib/ultralib/src/voice/voicecountsyllables.c create mode 100644 lib/ultralib/src/voice/voicecrc.c create mode 100644 lib/ultralib/src/voice/voicegetreaddata.c create mode 100644 lib/ultralib/src/voice/voicegetstatus.c create mode 100644 lib/ultralib/src/voice/voiceinit.c create mode 100644 lib/ultralib/src/voice/voiceinternal.h create mode 100644 lib/ultralib/src/voice/voicemaskdictionary.c create mode 100644 lib/ultralib/src/voice/voicesetadconverter.c create mode 100644 lib/ultralib/src/voice/voicesetword.c create mode 100644 lib/ultralib/src/voice/voicestartreaddata.c create mode 100644 lib/ultralib/src/voice/voicestopreaddata.c create mode 100644 lib/ultralib/tools/Makefile create mode 100755 lib/ultralib/tools/ar.py create mode 100644 lib/ultralib/tools/asm_differ/.gitignore create mode 100644 lib/ultralib/tools/asm_differ/.gitrepo create mode 100644 lib/ultralib/tools/asm_differ/.pre-commit-config.yaml create mode 100644 lib/ultralib/tools/asm_differ/LICENSE create mode 100644 lib/ultralib/tools/asm_differ/README.md create mode 100644 lib/ultralib/tools/asm_differ/diff-stylesheet.css create mode 100755 lib/ultralib/tools/asm_differ/diff.py create mode 100644 lib/ultralib/tools/asm_differ/diff_settings.py create mode 100644 lib/ultralib/tools/asm_differ/mypy.ini create mode 100644 lib/ultralib/tools/asm_differ/screenshot.png create mode 100755 lib/ultralib/tools/compile_sjis.py create mode 100755 lib/ultralib/tools/disassemble_elf.py create mode 100755 lib/ultralib/tools/fix_objfile.py create mode 100755 lib/ultralib/tools/libdiff.py create mode 100755 lib/ultralib/tools/libelf.py create mode 100755 lib/ultralib/tools/m2ctx.py create mode 100644 lib/ultralib/tools/mdebug.py create mode 100644 lib/ultralib/tools/mips_isa.py create mode 100755 lib/ultralib/tools/patch_ar_meta.py create mode 100755 lib/ultralib/tools/print_mdebug.py create mode 100755 lib/ultralib/tools/set_o32abi_bit.py create mode 100755 lib/ultralib/tools/shiftjis_conv.py create mode 100755 lib/ultralib/tools/strip_debug.sh create mode 100644 lib/ultralib/tools/util.py diff --git a/lib/ultralib/.github/workflows/ci_egcs.txt b/lib/ultralib/.github/workflows/ci_egcs.txt new file mode 100644 index 0000000..b6d8fe7 --- /dev/null +++ b/lib/ultralib/.github/workflows/ci_egcs.txt @@ -0,0 +1,42 @@ +# CI file for EGCS builds +# TODO: rename to `ci_egcs.yml` when the repo has EGCS / iQue support + +name: Build EGCS libultra + +# Build on every branch push, tag push, and pull request change: +on: [push, pull_request_target] + +jobs: + build_repo: + name: Build repo + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + version: [ique_v1.5] + suffix: [_rom] # [~, _d, _rom] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install package requirements + run: sudo apt-get install -y build-essential python3 + + - name: Get extra dependencies + uses: actions/checkout@v3 + with: + repository: ${{ secrets.SECRETREPO }} + token: ${{ secrets.SECRETTOKEN }} + path: deps_repo + - name: Get the dependency + run: cp deps_repo/libultra/${{ matrix.version }}/* . + + - name: Setup + run: make setup -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} + + - name: Build libultra${{ matrix.suffix }} ${{ matrix.version }} + run: make -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} diff --git a/lib/ultralib/.github/workflows/ci_gcc.yml b/lib/ultralib/.github/workflows/ci_gcc.yml new file mode 100644 index 0000000..31efff8 --- /dev/null +++ b/lib/ultralib/.github/workflows/ci_gcc.yml @@ -0,0 +1,41 @@ +# CI file for GCC/KMC builds + +name: Build GCC libgultra + +# Build on every branch push, tag push, and pull request change: +on: [push, pull_request_target] + +jobs: + build_repo: + name: Build repo + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + version: [I, J, K, L] # [H, I, I_patch, J, K, L] + suffix: [~, _d, _rom] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install package requirements + run: sudo apt-get install -y build-essential python3 + + - name: Get extra dependencies + uses: actions/checkout@v3 + with: + repository: ${{ secrets.SECRETREPO }} + token: ${{ secrets.SECRETTOKEN }} + path: deps_repo + - name: Get the dependency + run: cp deps_repo/libultra/${{ matrix.version }}/* base/${{ matrix.version }} + + - name: Setup + run: make setup -j $(nproc) TARGET=libgultra${{ matrix.suffix }} VERSION=${{ matrix.version }} + + - name: Build libgultra${{ matrix.suffix }} ${{ matrix.version }} + run: make -j $(nproc) TARGET=libgultra${{ matrix.suffix }} VERSION=${{ matrix.version }} diff --git a/lib/ultralib/.github/workflows/ci_ido.yml b/lib/ultralib/.github/workflows/ci_ido.yml new file mode 100644 index 0000000..1410108 --- /dev/null +++ b/lib/ultralib/.github/workflows/ci_ido.yml @@ -0,0 +1,41 @@ +# CI file for IDO builds + +name: Build IDO libultra + +# Build on every branch push, tag push, and pull request change: +on: [push, pull_request_target] + +jobs: + build_repo: + name: Build repo + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + version: [I, J, K, L] # [E, F, G, H, I, I_patch, J, K, L] + suffix: [~, _rom] # [~, _d, _rom] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install package requirements + run: sudo apt-get install -y build-essential python3 binutils-mips-linux-gnu + + - name: Get extra dependencies + uses: actions/checkout@v3 + with: + repository: ${{ secrets.SECRETREPO }} + token: ${{ secrets.SECRETTOKEN }} + path: deps_repo + - name: Get the dependency + run: cp deps_repo/libultra/${{ matrix.version }}/* base/${{ matrix.version }} + + - name: Setup + run: make setup -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} + + - name: Build libultra${{ matrix.suffix }} ${{ matrix.version }} + run: make -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }} diff --git a/lib/ultralib/.gitignore b/lib/ultralib/.gitignore new file mode 100644 index 0000000..1193e99 --- /dev/null +++ b/lib/ultralib/.gitignore @@ -0,0 +1,29 @@ +# Cache files +__pycache__/ +.pyc +.DS_Store + +# Text editor remnants +.vscode/ +.vs/ +.idea/ +CMakeLists.txt +cmake-build-debug +venv/ +.venv + +# Project-specific ignores +base_*/ +build/ +expected/ +notes/ +tools/gcc +tools/ido +*.elf +*.o +*.a + +# Tool artifacts +ctx.c + +libultra_collection/ diff --git a/lib/ultralib/.gitrepo b/lib/ultralib/.gitrepo new file mode 100644 index 0000000..cba8141 --- /dev/null +++ b/lib/ultralib/.gitrepo @@ -0,0 +1,12 @@ +; DO NOT EDIT (unless you know what you are doing) +; +; This subdirectory is a git "subrepo", and this file is maintained by the +; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme +; +[subrepo] + remote = git@github.com:decompals/ultralib.git + branch = main + commit = 299d7faf8798cbe75e3247ccdf4e65c09f5270dd + parent = a3476fcc3a0fc47aa0c31f3ef04d08181daf3050 + method = merge + cmdver = 0.4.6 diff --git a/lib/ultralib/Makefile b/lib/ultralib/Makefile new file mode 100644 index 0000000..a4714b6 --- /dev/null +++ b/lib/ultralib/Makefile @@ -0,0 +1,234 @@ +COMPARE ?= 1 +FIXUPS ?= 0 + +ifneq ($(FIXUPS),0) +COMPARE := 0 +endif + +# One of: +# libgultra_rom, libgultra_d, libgultra +# libultra_rom, libultra_d, libultra +TARGET ?= libgultra_rom +VERSION ?= L +CROSS ?= mips-linux-gnu- + +BASE_DIR := extracted/$(VERSION)/$(TARGET) +BASE_AR := base/$(VERSION)/$(TARGET).a +BUILD_ROOT := build +BUILD_DIR := $(BUILD_ROOT)/$(VERSION)/$(TARGET) +BUILD_AR := $(BUILD_DIR)/$(TARGET).a + +WORKING_DIR := $(shell pwd) + +CPP := cpp -P +AR := ar + +VERSION_D := 1 +VERSION_E := 2 +VERSION_F := 3 +VERSION_G := 4 +VERSION_H := 5 +VERSION_I := 6 +VERSION_J := 7 +VERSION_K := 8 +VERSION_L := 9 + +VERSION_DEFINE := -DBUILD_VERSION=$(VERSION_$(VERSION)) -DBUILD_VERSION_STRING=\"2.0$(VERSION)\" + +ifeq ($(findstring _d,$(TARGET)),_d) +DEBUGFLAG := -D_DEBUG +else +DEBUGFLAG := -DNDEBUG +endif + +ifeq ($(findstring libgultra,$(TARGET)),libgultra) +-include Makefile.gcc +else ifeq ($(findstring libultra,$(TARGET)),libultra) +-include Makefile.ido +else +$(error Invalid Target) +endif + +ifeq ($(findstring _rom,$(TARGET)),_rom) +CPPFLAGS += -D_FINALROM +endif + +SRC_DIRS := $(shell find src -type d) +C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) +S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s)) + +# Versions J and below used the C matrix math implementations +MGU_MATRIX_FILES := mtxcatf normalize scale translate +ifneq ($(filter $(VERSION),D E F G H I J),) +S_FILES := $(filter-out $(addprefix src/mgu/,$(MGU_MATRIX_FILES:=.s)),$(S_FILES)) +else +C_FILES := $(filter-out $(addprefix src/gu/,$(MGU_MATRIX_FILES:=.c)),$(C_FILES)) +endif + +C_O_FILES := $(foreach f,$(C_FILES:.c=.o),$(BUILD_DIR)/$f) +S_O_FILES := $(foreach f,$(S_FILES:.s=.o),$(BUILD_DIR)/$f) +O_FILES := $(S_O_FILES) $(C_O_FILES) +# Because we patch the object file timestamps, we can't use them as the targets since they'll always be older than the C file +# Therefore instead we use marker files that have actual timestamps as the dependencies for the archive +C_MARKER_FILES := $(C_O_FILES:.o=.marker) +S_MARKER_FILES := $(S_O_FILES:.o=.marker) +S_MARKER_FILES := $(filter-out $(MDEBUG_FILES),$(S_MARKER_FILES)) +MARKER_FILES := $(C_MARKER_FILES) $(S_MARKER_FILES) $(MDEBUG_FILES) + +ifneq ($(COMPARE),0) +COMPARE_OBJ = cmp $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o) && echo "$(@:.marker=.o): OK" +COMPARE_AR = cmp $(BASE_AR) $@ && echo "$@: OK" +ifeq ($(COMPILER),ido) +COMPARE_OBJ = $(CROSS)objcopy -p --strip-debug $(WORKING_DIR)/$(@:.marker=.o) $(WORKING_DIR)/$(@:.marker=.cmp.o) && \ + cmp $(BASE_DIR)/.cmp/$(@F:.marker=.cmp.o) $(WORKING_DIR)/$(@:.marker=.cmp.o) && echo "$(@:.marker=.o): OK" +COMPARE_AR = echo "$@: Cannot compare archive currently" +endif +else +COMPARE_OBJ := +COMPARE_AR := +AR_OLD := $(AR) +endif + +BASE_OBJS := $(wildcard $(BASE_DIR)/*.o) + +# Check to make sure the current version has been set up +ifneq ($(COMPARE),0) +ifeq ($(BASE_OBJS),) +# Ignore this check if the user is currently running setup, clean or distclean +ifeq ($(filter $(MAKECMDGOALS),setup clean distclean),) +$(error Current version ($(TARGET) 2.0$(VERSION)) has not been setup!) +endif +endif +endif + +AR_OBJECTS := $(shell cat base/$(VERSION)/$(TARGET).txt) +# If the version and target doesn't have a text file yet, resort back to using the base archive to get objects +ifeq ($(AR_OBJECTS),) +AR_OBJECTS := $(shell ar t $(BASE_AR)) +endif + + +# Try to find a file corresponding to an archive file in src/ or the base directory, prioritizing src then the original file +AR_ORDER = $(foreach f,$(AR_OBJECTS),$(shell find $(BUILD_DIR)/src $(BASE_DIR) -iname $f -type f -print -quit)) +MATCHED_OBJS = $(filter-out $(BASE_DIR)/%,$(AR_ORDER)) +UNMATCHED_OBJS = $(filter-out $(MATCHED_OBJS),$(AR_ORDER)) +NUM_OBJS = $(words $(AR_ORDER)) +NUM_OBJS_MATCHED = $(words $(MATCHED_OBJS)) +NUM_OBJS_UNMATCHED = $(words $(UNMATCHED_OBJS)) + +$(shell mkdir -p $(BASE_DIR) src $(foreach dir,$(SRC_DIRS),$(BUILD_DIR)/$(dir))) + +.PHONY: all clean distclean setup +all: $(BUILD_AR) + +$(BUILD_AR): $(MARKER_FILES) + $(AR_OLD) rcs $@ $(AR_ORDER) +ifneq ($(COMPARE),0) +# patch archive creation time and individual files' ownership & permissions + dd bs=1 skip=24 seek=24 count=12 conv=notrunc if=$(BASE_AR) of=$@ status=none + python3 tools/patch_ar_meta.py $@ $(BASE_AR) $(PATCH_AR_FLAGS) + @$(COMPARE_AR) + @echo "Matched: $(NUM_OBJS_MATCHED)/$(NUM_OBJS)" +endif + +clean: + $(RM) -rf $(BUILD_DIR) + +distclean: + $(MAKE) -C tools distclean + $(RM) -rf extracted/ $(BUILD_ROOT) + +setup: + $(MAKE) -C tools +ifneq ($(COMPARE),0) + cd $(BASE_DIR) && $(AR) xo $(WORKING_DIR)/$(BASE_AR) + chmod -R +rw $(BASE_DIR) +ifeq ($(COMPILER),ido) + export CROSS=$(CROSS) && ./tools/strip_debug.sh $(BASE_DIR) +endif +endif + +$(BUILD_DIR)/$(BASE_DIR)/%.marker: $(BASE_DIR)/%.o + cp $< $(@:.marker=.o) +ifneq ($(COMPARE),0) +# change file timestamps to match original + @touch -r $(BASE_DIR)/$(@F:.marker=.o) $(@:.marker=.o) + @$(COMPARE_OBJ) + @touch $@ +endif + +GBIDEFINE := -DF3DEX_GBI + +$(BUILD_DIR)/src/gu/parse_gbi.marker: GBIDEFINE := -DF3D_GBI +$(BUILD_DIR)/src/gu/us2dex_emu.marker: GBIDEFINE := +$(BUILD_DIR)/src/gu/us2dex2_emu.marker: GBIDEFINE := +$(BUILD_DIR)/src/sp/sprite.marker: GBIDEFINE := -DF3D_GBI +$(BUILD_DIR)/src/sp/spriteex.marker: GBIDEFINE := +$(BUILD_DIR)/src/sp/spriteex2.marker: GBIDEFINE := +$(BUILD_DIR)/src/voice/%.marker: OPTFLAGS += -DLANG_JAPANESE -I$(WORKING_DIR)/src -I$(WORKING_DIR)/src/voice +$(BUILD_DIR)/src/voice/%.marker: CC := tools/compile_sjis.py -D__CC=$(WORKING_DIR)/$(CC) -D__BUILD_DIR=$(BUILD_DIR) + +$(C_MARKER_FILES): $(BUILD_DIR)/%.marker: %.c + cd $( + +/* + * Segment base addresses and sizes + */ +#define KUBASE 0 +#define KUSIZE 0x80000000 +#define K0BASE 0x80000000 +#define K0SIZE 0x20000000 +#define K1BASE 0xA0000000 +#define K1SIZE 0x20000000 +#define K2BASE 0xC0000000 +#define K2SIZE 0x20000000 + +/* + * Exception vectors + */ +#define SIZE_EXCVEC 0x80 /* Size of an exc. vec */ +#define UT_VEC K0BASE /* utlbmiss vector */ +#define R_VEC (K1BASE+0x1fc00000) /* reset vector */ +#define XUT_VEC (K0BASE+0x80) /* extended address tlbmiss */ +#define ECC_VEC (K0BASE+0x100) /* Ecc exception vector */ +#define E_VEC (K0BASE+0x180) /* Gen. exception vector */ + +/* + * Address conversion macros + */ +#ifdef _LANGUAGE_ASSEMBLY + +#define K0_TO_K1(x) ((x)|0xA0000000) /* kseg0 to kseg1 */ +#define K1_TO_K0(x) ((x)&0x9FFFFFFF) /* kseg1 to kseg0 */ +#define K0_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg0 to physical */ +#define K1_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg1 to physical */ +#define KDM_TO_PHYS(x) ((x)&0x1FFFFFFF) /* direct mapped to physical */ +#define PHYS_TO_K0(x) ((x)|0x80000000) /* physical to kseg0 */ +#define PHYS_TO_K1(x) ((x)|0xA0000000) /* physical to kseg1 */ + +#else /* _LANGUAGE_C */ + +#define K0_TO_K1(x) ((u32)(x)|0xA0000000) /* kseg0 to kseg1 */ +#define K1_TO_K0(x) ((u32)(x)&0x9FFFFFFF) /* kseg1 to kseg0 */ +#define K0_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg0 to physical */ +#define K1_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg1 to physical */ +#define KDM_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* direct mapped to physical */ +#define PHYS_TO_K0(x) ((u32)(x)|0x80000000) /* physical to kseg0 */ +#define PHYS_TO_K1(x) ((u32)(x)|0xA0000000) /* physical to kseg1 */ + +#endif /* _LANGUAGE_ASSEMBLY */ + +/* + * Address predicates + */ +#define IS_KSEG0(x) ((u32)(x) >= K0BASE && (u32)(x) < K1BASE) +#define IS_KSEG1(x) ((u32)(x) >= K1BASE && (u32)(x) < K2BASE) +#define IS_KSEGDM(x) ((u32)(x) >= K0BASE && (u32)(x) < K2BASE) +#define IS_KSEG2(x) ((u32)(x) >= K2BASE && (u32)(x) < KPTE_SHDUBASE) +#define IS_KPTESEG(x) ((u32)(x) >= KPTE_SHDUBASE) +#define IS_KUSEG(x) ((u32)(x) < K0BASE) + +/* + * TLB size constants + */ + +#define NTLBENTRIES 31 /* entry 31 is reserved by rdb */ + +#define TLBHI_VPN2MASK 0xffffe000 +#define TLBHI_VPN2SHIFT 13 +#define TLBHI_PIDMASK 0xff +#define TLBHI_PIDSHIFT 0 +#define TLBHI_NPID 255 /* 255 to fit in 8 bits */ + +#define TLBLO_PFNMASK 0x3fffffc0 +#define TLBLO_PFNSHIFT 6 +#define TLBLO_CACHMASK 0x38 /* cache coherency algorithm */ +#define TLBLO_CACHSHIFT 3 +#define TLBLO_UNCACHED 0x10 /* not cached */ +#define TLBLO_NONCOHRNT 0x18 /* Cacheable non-coherent */ +#define TLBLO_EXLWR 0x28 /* Exclusive write */ +#define TLBLO_D 0x4 /* writeable */ +#define TLBLO_V 0x2 /* valid bit */ +#define TLBLO_G 0x1 /* global access bit */ + +#define TLBINX_PROBE 0x80000000 +#define TLBINX_INXMASK 0x3f +#define TLBINX_INXSHIFT 0 + +#define TLBRAND_RANDMASK 0x3f +#define TLBRAND_RANDSHIFT 0 + +#define TLBWIRED_WIREDMASK 0x3f + +#define TLBCTXT_BASEMASK 0xff800000 +#define TLBCTXT_BASESHIFT 23 +#define TLBCTXT_BASEBITS 9 + +#define TLBCTXT_VPNMASK 0x7ffff0 +#define TLBCTXT_VPNSHIFT 4 + +#define TLBPGMASK_4K 0x0 +#define TLBPGMASK_16K 0x6000 +#define TLBPGMASK_64K 0x1e000 + +/* + * Status register + */ +#define SR_CUMASK 0xf0000000 /* coproc usable bits */ + +#define SR_CU3 0x80000000 /* Coprocessor 3 usable */ +#define SR_CU2 0x40000000 /* Coprocessor 2 usable */ +#define SR_CU1 0x20000000 /* Coprocessor 1 usable */ +#define SR_CU0 0x10000000 /* Coprocessor 0 usable */ +#define SR_RP 0x08000000 /* Reduced power (quarter speed) */ +#define SR_FR 0x04000000 /* MIPS III FP register mode */ +#define SR_RE 0x02000000 /* Reverse endian */ +#define SR_ITS 0x01000000 /* Instruction trace support */ +#define SR_BEV 0x00400000 /* Use boot exception vectors */ +#define SR_TS 0x00200000 /* TLB shutdown */ +#define SR_SR 0x00100000 /* Soft reset occured */ +#define SR_CH 0x00040000 /* Cache hit for last 'cache' op */ +#define SR_CE 0x00020000 /* Create ECC */ +#define SR_DE 0x00010000 /* ECC of parity does not cause error */ + +/* + * Interrupt enable bits + * (NOTE: bits set to 1 enable the corresponding level interrupt) + */ +#define SR_IMASK 0x0000ff00 /* Interrupt mask */ +#define SR_IMASK8 0x00000000 /* mask level 8 */ +#define SR_IMASK7 0x00008000 /* mask level 7 */ +#define SR_IMASK6 0x0000c000 /* mask level 6 */ +#define SR_IMASK5 0x0000e000 /* mask level 5 */ +#define SR_IMASK4 0x0000f000 /* mask level 4 */ +#define SR_IMASK3 0x0000f800 /* mask level 3 */ +#define SR_IMASK2 0x0000fc00 /* mask level 2 */ +#define SR_IMASK1 0x0000fe00 /* mask level 1 */ +#define SR_IMASK0 0x0000ff00 /* mask level 0 */ + +#define SR_IBIT8 0x00008000 /* bit level 8 */ +#define SR_IBIT7 0x00004000 /* bit level 7 */ +#define SR_IBIT6 0x00002000 /* bit level 6 */ +#define SR_IBIT5 0x00001000 /* bit level 5 */ +#define SR_IBIT4 0x00000800 /* bit level 4 */ +#define SR_IBIT3 0x00000400 /* bit level 3 */ +#define SR_IBIT2 0x00000200 /* bit level 2 */ +#define SR_IBIT1 0x00000100 /* bit level 1 */ + +#define SR_IMASKSHIFT 8 + +#define SR_KX 0x00000080 /* extended-addr TLB vec in kernel */ +#define SR_SX 0x00000040 /* xtended-addr TLB vec supervisor */ +#define SR_UX 0x00000020 /* xtended-addr TLB vec in user mode */ +#define SR_KSU_MASK 0x00000018 /* mode mask */ +#define SR_KSU_USR 0x00000010 /* user mode */ +#define SR_KSU_SUP 0x00000008 /* supervisor mode */ +#define SR_KSU_KER 0x00000000 /* kernel mode */ +#define SR_ERL 0x00000004 /* Error level, 1=>cache error */ +#define SR_EXL 0x00000002 /* Exception level, 1=>exception */ +#define SR_IE 0x00000001 /* interrupt enable, 1=>enable */ + +/* + * Cause Register + */ +#define CAUSE_BD 0x80000000 /* Branch delay slot */ +#define CAUSE_CEMASK 0x30000000 /* coprocessor error */ +#define CAUSE_CESHIFT 28 + +/* Interrupt pending bits */ +#define CAUSE_IP8 0x00008000 /* External level 8 pending - COMPARE */ +#define CAUSE_IP7 0x00004000 /* External level 7 pending - INT4 */ +#define CAUSE_IP6 0x00002000 /* External level 6 pending - INT3 */ +#define CAUSE_IP5 0x00001000 /* External level 5 pending - INT2 */ +#define CAUSE_IP4 0x00000800 /* External level 4 pending - INT1 */ +#define CAUSE_IP3 0x00000400 /* External level 3 pending - INT0 */ +#define CAUSE_SW2 0x00000200 /* Software level 2 pending */ +#define CAUSE_SW1 0x00000100 /* Software level 1 pending */ + +#define CAUSE_IPMASK 0x0000FF00 /* Pending interrupt mask */ +#define CAUSE_IPSHIFT 8 + +#define CAUSE_EXCMASK 0x0000007C /* Cause code bits */ + +#define CAUSE_EXCSHIFT 2 + +/* Cause register exception codes */ + +#define EXC_CODE(x) ((x)<<2) + +/* Hardware exception codes */ +#define EXC_INT EXC_CODE(0) /* interrupt */ +#define EXC_MOD EXC_CODE(1) /* TLB mod */ +#define EXC_RMISS EXC_CODE(2) /* Read TLB Miss */ +#define EXC_WMISS EXC_CODE(3) /* Write TLB Miss */ +#define EXC_RADE EXC_CODE(4) /* Read Address Error */ +#define EXC_WADE EXC_CODE(5) /* Write Address Error */ +#define EXC_IBE EXC_CODE(6) /* Instruction Bus Error */ +#define EXC_DBE EXC_CODE(7) /* Data Bus Error */ +#define EXC_SYSCALL EXC_CODE(8) /* SYSCALL */ +#define EXC_BREAK EXC_CODE(9) /* BREAKpoint */ +#define EXC_II EXC_CODE(10) /* Illegal Instruction */ +#define EXC_CPU EXC_CODE(11) /* CoProcessor Unusable */ +#define EXC_OV EXC_CODE(12) /* OVerflow */ +#define EXC_TRAP EXC_CODE(13) /* Trap exception */ +#define EXC_VCEI EXC_CODE(14) /* Virt. Coherency on Inst. fetch */ +#define EXC_FPE EXC_CODE(15) /* Floating Point Exception */ +#define EXC_WATCH EXC_CODE(23) /* Watchpoint reference */ +#define EXC_VCED EXC_CODE(31) /* Virt. Coherency on data read */ + +/* C0_PRID Defines */ +#define C0_IMPMASK 0xff00 +#define C0_IMPSHIFT 8 +#define C0_REVMASK 0xff +#define C0_MAJREVMASK 0xf0 +#define C0_MAJREVSHIFT 4 +#define C0_MINREVMASK 0xf + +/* + * Coprocessor 0 operations + */ +#define C0_READI 0x1 /* read ITLB entry addressed by C0_INDEX */ +#define C0_WRITEI 0x2 /* write ITLB entry addressed by C0_INDEX */ +#define C0_WRITER 0x6 /* write ITLB entry addressed by C0_RAND */ +#define C0_PROBE 0x8 /* probe for ITLB entry addressed by TLBHI */ +#define C0_RFE 0x10 /* restore for exception */ + +/* + * 'cache' instruction definitions + */ + +/* Target cache */ +#define CACH_PI 0x0 /* specifies primary inst. cache */ +#define CACH_PD 0x1 /* primary data cache */ +#define CACH_SI 0x2 /* secondary instruction cache */ +#define CACH_SD 0x3 /* secondary data cache */ + +/* Cache operations */ +#define C_IINV 0x0 /* index invalidate (inst, 2nd inst) */ +#define C_IWBINV 0x0 /* index writeback inval (d, sd) */ +#define C_ILT 0x4 /* index load tag (all) */ +#define C_IST 0x8 /* index store tag (all) */ +#define C_CDX 0xc /* create dirty exclusive (d, sd) */ +#define C_HINV 0x10 /* hit invalidate (all) */ +#define C_HWBINV 0x14 /* hit writeback inv. (d, sd) */ +#define C_FILL 0x14 /* fill (i) */ +#define C_HWB 0x18 /* hit writeback (i, d, sd) */ +#define C_HSV 0x1c /* hit set virt. (si, sd) */ + +/* + * Cache size definitions + */ +#define ICACHE_SIZE 0x4000 /* 16K */ +#define ICACHE_LINESIZE 32 /* 8 words */ +#define ICACHE_LINEMASK (ICACHE_LINESIZE-1) + +#define DCACHE_SIZE 0x2000 /* 8K */ +#define DCACHE_LINESIZE 16 /* 4 words */ +#define DCACHE_LINEMASK (DCACHE_LINESIZE-1) + +/* + * C0_CONFIG register definitions + */ +#define CONFIG_CM 0x80000000 /* 1 == Master-Checker enabled */ +#define CONFIG_EC 0x70000000 /* System Clock ratio */ +#define CONFIG_EC_1_1 0x6 /* System Clock ratio 1 :1 */ +#define CONFIG_EC_3_2 0x7 /* System Clock ratio 1.5 :1 */ +#define CONFIG_EC_2_1 0x0 /* System Clock ratio 2 :1 */ +#define CONFIG_EC_3_1 0x1 /* System Clock ratio 3 :1 */ +#define CONFIG_EP 0x0f000000 /* Transmit Data Pattern */ +#define CONFIG_SB 0x00c00000 /* Secondary cache block size */ + +#define CONFIG_SS 0x00200000 /* Split scache: 0 == I&D combined */ +#define CONFIG_SW 0x00100000 /* scache port: 0==128, 1==64 */ +#define CONFIG_EW 0x000c0000 /* System Port width: 0==64, 1==32 */ +#define CONFIG_SC 0x00020000 /* 0 -> 2nd cache present */ +#define CONFIG_SM 0x00010000 /* 0 -> Dirty Shared Coherency enabled*/ +#define CONFIG_BE 0x00008000 /* Endian-ness: 1 --> BE */ +#define CONFIG_EM 0x00004000 /* 1 -> ECC mode, 0 -> parity */ +#define CONFIG_EB 0x00002000 /* Block order:1->sequent,0->subblock */ + +#define CONFIG_IC 0x00000e00 /* Primary Icache size */ +#define CONFIG_DC 0x000001c0 /* Primary Dcache size */ +#define CONFIG_IB 0x00000020 /* Icache block size */ +#define CONFIG_DB 0x00000010 /* Dcache block size */ +#define CONFIG_CU 0x00000008 /* Update on Store-conditional */ +#define CONFIG_K0 0x00000007 /* K0SEG Coherency algorithm */ + +#define CONFIG_UNCACHED 0x00000002 /* K0 is uncached */ +#define CONFIG_NONCOHRNT 0x00000003 +#define CONFIG_COHRNT_EXLWR 0x00000005 +#define CONFIG_SB_SHFT 22 /* shift SB to bit position 0 */ +#define CONFIG_IC_SHFT 9 /* shift IC to bit position 0 */ +#define CONFIG_DC_SHFT 6 /* shift DC to bit position 0 */ +#define CONFIG_BE_SHFT 15 /* shift BE to bit position 0 */ + +/* + * C0_TAGLO definitions for setting/getting cache states and physaddr bits + */ +#define SADDRMASK 0xFFFFE000 /* 31..13 -> scache paddr bits 35..17 */ +#define SVINDEXMASK 0x00000380 /* 9..7: prim virt index bits 14..12 */ +#define SSTATEMASK 0x00001c00 /* bits 12..10 hold scache line state */ +#define SINVALID 0x00000000 /* invalid --> 000 == state 0 */ +#define SCLEANEXCL 0x00001000 /* clean exclusive --> 100 == state 4 */ +#define SDIRTYEXCL 0x00001400 /* dirty exclusive --> 101 == state 5 */ +#define SECC_MASK 0x0000007f /* low 7 bits are ecc for the tag */ +#define SADDR_SHIFT 4 /* shift STagLo (31..13) to 35..17 */ + +#define PADDRMASK 0xFFFFFF00 /* PTagLo31..8->prim paddr bits35..12 */ +#define PADDR_SHIFT 4 /* roll bits 35..12 down to 31..8 */ +#define PSTATEMASK 0x00C0 /* bits 7..6 hold primary line state */ +#define PINVALID 0x0000 /* invalid --> 000 == state 0 */ +#define PCLEANEXCL 0x0080 /* clean exclusive --> 10 == state 2 */ +#define PDIRTYEXCL 0x00C0 /* dirty exclusive --> 11 == state 3 */ +#define PPARITY_MASK 0x0001 /* low bit is parity bit (even). */ + +/* + * C0_CACHE_ERR definitions. + */ +#define CACHERR_ER 0x80000000 /* 0: inst ref, 1: data ref */ +#define CACHERR_EC 0x40000000 /* 0: primary, 1: secondary */ +#define CACHERR_ED 0x20000000 /* 1: data error */ +#define CACHERR_ET 0x10000000 /* 1: tag error */ +#define CACHERR_ES 0x08000000 /* 1: external ref, e.g. snoop*/ +#define CACHERR_EE 0x04000000 /* error on SysAD bus */ +#define CACHERR_EB 0x02000000 /* complicated, see spec. */ +#define CACHERR_EI 0x01000000 /* complicated, see spec. */ +#define CACHERR_SIDX_MASK 0x003ffff8 /* secondary cache index */ +#define CACHERR_PIDX_MASK 0x00000007 /* primary cache index */ +#define CACHERR_PIDX_SHIFT 12 /* bits 2..0 are paddr14..12 */ + +/* R4000 family supports hardware watchpoints: + * C0_WATCHLO: + * bits 31..3 are bits 31..3 of physaddr to watch + * bit 2: reserved; must be written as 0. + * bit 1: when set causes a watchpoint trap on load accesses to paddr. + * bit 0: when set traps on stores to paddr; + * C0_WATCHHI + * bits 31..4 are reserved and must be written as zeros. + * bits 3..0 are bits 35..32 of the physaddr to watch + */ +#define WATCHLO_WTRAP 0x00000001 +#define WATCHLO_RTRAP 0x00000002 +#define WATCHLO_ADDRMASK 0xfffffff8 +#define WATCHLO_VALIDMASK 0xfffffffb +#define WATCHHI_VALIDMASK 0x0000000f + +/* + * Coprocessor 0 registers + */ +#ifdef _LANGUAGE_ASSEMBLY +#define C0_INX $0 +#define C0_RAND $1 +#define C0_ENTRYLO0 $2 +#define C0_ENTRYLO1 $3 +#define C0_CONTEXT $4 +#define C0_PAGEMASK $5 /* page mask */ +#define C0_WIRED $6 /* # wired entries in tlb */ +#define C0_BADVADDR $8 +#define C0_COUNT $9 /* free-running counter */ +#define C0_ENTRYHI $10 +#define C0_SR $12 +#define C0_CAUSE $13 +#define C0_EPC $14 +#define C0_PRID $15 /* revision identifier */ +#define C0_COMPARE $11 /* counter comparison reg. */ +#define C0_CONFIG $16 /* hardware configuration */ +#define C0_LLADDR $17 /* load linked address */ +#define C0_WATCHLO $18 /* watchpoint */ +#define C0_WATCHHI $19 /* watchpoint */ +#define C0_ECC $26 /* S-cache ECC and primary parity */ +#define C0_CACHE_ERR $27 /* cache error status */ +#define C0_TAGLO $28 /* cache operations */ +#define C0_TAGHI $29 /* cache operations */ +#define C0_ERROR_EPC $30 /* ECC error prg. counter */ + +# else /* ! _LANGUAGE_ASSEMBLY */ + +#define C0_INX 0 +#define C0_RAND 1 +#define C0_ENTRYLO0 2 +#define C0_ENTRYLO1 3 +#define C0_CONTEXT 4 +#define C0_PAGEMASK 5 /* page mask */ +#define C0_WIRED 6 /* # wired entries in tlb */ +#define C0_BADVADDR 8 +#define C0_COUNT 9 /* free-running counter */ +#define C0_ENTRYHI 10 +#define C0_SR 12 +#define C0_CAUSE 13 +#define C0_EPC 14 +#define C0_PRID 15 /* revision identifier */ +#define C0_COMPARE 11 /* counter comparison reg. */ +#define C0_CONFIG 16 /* hardware configuration */ +#define C0_LLADDR 17 /* load linked address */ +#define C0_WATCHLO 18 /* watchpoint */ +#define C0_WATCHHI 19 /* watchpoint */ +#define C0_ECC 26 /* S-cache ECC and primary parity */ +#define C0_CACHE_ERR 27 /* cache error status */ +#define C0_TAGLO 28 /* cache operations */ +#define C0_TAGHI 29 /* cache operations */ +#define C0_ERROR_EPC 30 /* ECC error prg. counter */ + +#endif /* _LANGUAGE_ASSEMBLY */ + +/* + * floating-point status register + */ +#define FPCSR_FS 0x01000000 /* flush denorm to zero */ +#define FPCSR_C 0x00800000 /* condition bit */ +#define FPCSR_CE 0x00020000 /* cause: unimplemented operation */ +#define FPCSR_CV 0x00010000 /* cause: invalid operation */ +#define FPCSR_CZ 0x00008000 /* cause: division by zero */ +#define FPCSR_CO 0x00004000 /* cause: overflow */ +#define FPCSR_CU 0x00002000 /* cause: underflow */ +#define FPCSR_CI 0x00001000 /* cause: inexact operation */ +#define FPCSR_EV 0x00000800 /* enable: invalid operation */ +#define FPCSR_EZ 0x00000400 /* enable: division by zero */ +#define FPCSR_EO 0x00000200 /* enable: overflow */ +#define FPCSR_EU 0x00000100 /* enable: underflow */ +#define FPCSR_EI 0x00000080 /* enable: inexact operation */ +#define FPCSR_FV 0x00000040 /* flag: invalid operation */ +#define FPCSR_FZ 0x00000020 /* flag: division by zero */ +#define FPCSR_FO 0x00000010 /* flag: overflow */ +#define FPCSR_FU 0x00000008 /* flag: underflow */ +#define FPCSR_FI 0x00000004 /* flag: inexact operation */ +#define FPCSR_RM_MASK 0x00000003 /* rounding mode mask */ +#define FPCSR_RM_RN 0x00000000 /* round to nearest */ +#define FPCSR_RM_RZ 0x00000001 /* round to zero */ +#define FPCSR_RM_RP 0x00000002 /* round to positive infinity */ +#define FPCSR_RM_RM 0x00000003 /* round to negative infinity */ + +#endif /* __R4300_H */ diff --git a/lib/ultralib/include/PR/abi.h b/lib/ultralib/include/PR/abi.h new file mode 100644 index 0000000..e121526 --- /dev/null +++ b/lib/ultralib/include/PR/abi.h @@ -0,0 +1,410 @@ +#ifndef _ABI_H_ +#define _ABI_H_ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.32 $ + * $Date: 1997/02/11 08:16:37 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/abi.h,v $ + * + **************************************************************************/ + +/* + * Header file for the Audio Binary Interface. + * This is included in the Media Binary Interface file + * mbi.h. + * + * This file follows the framework used for graphics. + * + */ + +/* Audio commands: */ +#define A_SPNOOP 0 +#define A_ADPCM 1 +#define A_CLEARBUFF 2 +#define A_ENVMIXER 3 +#define A_LOADBUFF 4 +#define A_RESAMPLE 5 +#define A_SAVEBUFF 6 +#define A_SEGMENT 7 +#define A_SETBUFF 8 +#define A_SETVOL 9 +#define A_DMEMMOVE 10 +#define A_LOADADPCM 11 +#define A_MIXER 12 +#define A_INTERLEAVE 13 +#define A_POLEF 14 +#define A_SETLOOP 15 + +#define ACMD_SIZE 32 +/* + * Audio flags + */ + +#define A_INIT 0x01 +#define A_CONTINUE 0x00 +#define A_LOOP 0x02 +#define A_OUT 0x02 +#define A_LEFT 0x02 +#define A_RIGHT 0x00 +#define A_VOL 0x04 +#define A_RATE 0x00 +#define A_AUX 0x08 +#define A_NOAUX 0x00 +#define A_MAIN 0x00 +#define A_MIX 0x10 + +/* + * BEGIN C-specific section: (typedef's) + */ +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* + * Data Structures. + */ + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int addr; +} Aadpcm; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int addr; +} Apolef; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; +} Aenvelope; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int dmem:16; + unsigned int pad2:16; + unsigned int count:16; +} Aclearbuff; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int pad2:16; + unsigned int inL:16; + unsigned int inR:16; +} Ainterleave; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int addr; +} Aloadbuff; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; +} Aenvmixer; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int dmemi:16; + unsigned int dmemo:16; +} Amixer; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int dmem2:16; + unsigned int addr; +} Apan; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pitch:16; + unsigned int addr; +} Aresample; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; +} Areverb; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int addr; +} Asavebuff; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int pad2:2; + unsigned int number:4; + unsigned int base:24; +} Asegment; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int dmemin:16; + unsigned int dmemout:16; + unsigned int count:16; +} Asetbuff; + +typedef struct { + unsigned int cmd:8; + unsigned int flags:8; + unsigned int vol:16; + unsigned int voltgt:16; + unsigned int volrate:16; +} Asetvol; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int dmemin:16; + unsigned int dmemout:16; + unsigned int count:16; +} Admemmove; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int count:16; + unsigned int addr; +} Aloadadpcm; + +typedef struct { + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int pad2:16; + unsigned int addr; +} Asetloop; + +/* + * Generic Acmd Packet + */ + +typedef struct { + unsigned int w0; + unsigned int w1; +} Awords; + +typedef union { + Awords words; + Aadpcm adpcm; + Apolef polef; + Aclearbuff clearbuff; + Aenvelope envelope; + Ainterleave interleave; + Aloadbuff loadbuff; + Aenvmixer envmixer; + Aresample resample; + Areverb reverb; + Asavebuff savebuff; + Asegment segment; + Asetbuff setbuff; + Asetvol setvol; + Admemmove dmemmove; + Aloadadpcm loadadpcm; + Amixer mixer; + Asetloop setloop; + long long int force_union_align; /* dummy, force alignment */ +} Acmd; + +/* + * ADPCM State + */ +#define ADPCMVSIZE 8 +#define ADPCMFSIZE 16 +typedef short ADPCM_STATE[ADPCMFSIZE]; + +/* + * Pole filter state + */ +typedef short POLEF_STATE[4]; + +/* + * Resampler state + */ +typedef short RESAMPLE_STATE[16]; + +/* + * Resampler constants + */ +#define UNITY_PITCH 0x8000 +#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */ + +/* + * Enveloper/Mixer state + */ +typedef short ENVMIX_STATE[40]; + +/* + * Macros to assemble the audio command list + */ + +#define aADPCMdec(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (unsigned int)(s); \ +} + +#define aPoleFilter(pkt, f, g, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(g, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ +} + +#define aClearBuffer(pkt, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_CLEARBUFF, 24, 8) | _SHIFTL(d, 0, 24); \ + _a->words.w1 = (unsigned int)(c); \ +} + +#define aEnvMixer(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ENVMIXER, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (unsigned int)(s); \ +} + +#define aInterleave(pkt, l, r) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8); \ + _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ +} + +#define aLoadBuffer(pkt, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8); \ + _a->words.w1 = (unsigned int)(s); \ +} + +#define aMix(pkt, f, g, i, o) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(g, 0, 16)); \ + _a->words.w1 = _SHIFTL(i,16, 16) | _SHIFTL(o, 0, 16); \ +} + +#define aPan(pkt, f, d, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(d, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ +} + +#define aResample(pkt, f, p, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | _SHIFTL(f, 16, 8) |\ + _SHIFTL(p, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ +} + +#define aSaveBuffer(pkt, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8); \ + _a->words.w1 = (unsigned int)(s); \ +} + +#define aSegment(pkt, s, b) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ + _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ +} + +#define aSetBuffer(pkt, f, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(i, 0, 16)); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ +} + +#define aSetVolume(pkt, f, v, t, r) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ + _SHIFTL(v, 0, 16)); \ + _a->words.w1 = _SHIFTL(t, 16, 16) | _SHIFTL(r, 0, 16); \ +} + +#define aSetLoop(pkt, a) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + _a->words.w0 = _SHIFTL(A_SETLOOP, 24, 8); \ + _a->words.w1 = (unsigned int)(a); \ +} + +#define aDMEMMove(pkt, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ +} + +#define aLoadADPCM(pkt, c, d) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ + _a->words.w1 = (unsigned int) d; \ +} + +#endif /* _LANGUAGE_C */ + +#endif /* !_ABI_H_ */ + + + diff --git a/lib/ultralib/include/PR/gbi.h b/lib/ultralib/include/PR/gbi.h new file mode 100644 index 0000000..80ba602 --- /dev/null +++ b/lib/ultralib/include/PR/gbi.h @@ -0,0 +1,4572 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ +/************************************************************************** + * + * $Revision: 1.141 $ + * $Date: 1999/09/03 03:43:08 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gbi.h,v $ + * + **************************************************************************/ + +#ifndef _GBI_H_ +#define _GBI_H_ + +#include + +/* + * To use the F3DEX ucodes, define F3DEX_GBI before include this file. + * + * #define F3DEX_GBI + * #include + * + * or + * + * cc -c -DF3DEX_GBI -I.... foo.c + * + */ + +/************************************************************************** + * + * Graphics Binary Interface + * + **************************************************************************/ + +/* + * Graphics Commands, 'xxx' parts may be generated from ucode + * + * The command format is + * + * |00xxxxxx| = DMA 0,..,127 + * |10xxxxxx| = Immediate Mode -65,..,-128 + * |11xxxxxx| = RDP cmds -1,..,-64 + * + * Note: in order for the RSP microcode to process RDP commands opaquely, + * we need to further identify those RDP commands that need DRAM address + * "fixup". To do this, we have the dummy command G_RDP_ADDR_FIXUP, and + * all |RDP commands| less than this are commands with embedded DRAM + * addresses. Further, the format of these commands should be similar so + * only one fixup routine is needed. + * + * Further explanation: + * The names of the commands are somewhat misleading. Here is clarification: + * + * - a 'DMA' type command has a pointer to additional data and + * causes a DMA transfer to bring that into DMEM. + * + * - an 'Immediate' type command isn't really 'immediate', in the + * traditional sense. This just means that the entire command fits + * in the 64-bit word, and the ucode can execute it 'immediately' + * without additional memory transfers. + * + * - an 'RDP' command is identified as such because the RDP + * commands can be passed-thru the RSP and sent to the RDP + * directly. One further confusing thing, is that some 'DP' + * macros below actually generate immediate commands, not + * not direct DP commands. + * + * IMPLEMENTATION NOTE: + * There is another group of RDP commands that includes the triangle commands + * generated by the RSP code. These are the raw commands the rasterizer + * hardware chews on, with slope info, etc. They will follow the RDP + * ordering... + * + * IMPLEMENTATION NOTE: + * The RDP hardware has some of these bit patterns wired up. If the hardware + * changes, we must adjust this table, likewise we can't change/add things + * once the hardware is frozen. (actually, the RDP hardware only looks at + * the lower 6 bits of the command byte) + * + */ + +#ifdef F3DEX_GBI_2 +# ifndef F3DEX_GBI +# define F3DEX_GBI +# endif +#define G_NOOP 0x00 +#define G_RDPHALF_2 0xf1 +#define G_SETOTHERMODE_H 0xe3 +#define G_SETOTHERMODE_L 0xe2 +#define G_RDPHALF_1 0xe1 +#define G_SPNOOP 0xe0 +#define G_ENDDL 0xdf +#define G_DL 0xde +#define G_LOAD_UCODE 0xdd +#define G_MOVEMEM 0xdc +#define G_MOVEWORD 0xdb +#define G_MTX 0xda +#define G_GEOMETRYMODE 0xd9 +#define G_POPMTX 0xd8 +#define G_TEXTURE 0xd7 +#define G_DMA_IO 0xd6 +#define G_SPECIAL_1 0xd5 +#define G_SPECIAL_2 0xd4 +#define G_SPECIAL_3 0xd3 + +#define G_VTX 0x01 +#define G_MODIFYVTX 0x02 +#define G_CULLDL 0x03 +#define G_BRANCH_Z 0x04 +#define G_TRI1 0x05 +#define G_TRI2 0x06 +#define G_QUAD 0x07 +#define G_LINE3D 0x08 +#else /* F3DEX_GBI_2 */ + +/* DMA commands: */ +#define G_SPNOOP 0 /* handle 0 gracefully */ +#define G_MTX 1 +#define G_RESERVED0 2 /* not implemeted */ +#define G_MOVEMEM 3 /* move a block of memory (up to 4 words) to dmem */ +#define G_VTX 4 +#define G_RESERVED1 5 /* not implemeted */ +#define G_DL 6 +#define G_RESERVED2 7 /* not implemeted */ +#define G_RESERVED3 8 /* not implemeted */ +#define G_SPRITE2D_BASE 9 /* sprite command */ + +/* IMMEDIATE commands: */ +#define G_IMMFIRST -65 +#define G_TRI1 (G_IMMFIRST-0) +#define G_CULLDL (G_IMMFIRST-1) +#define G_POPMTX (G_IMMFIRST-2) +#define G_MOVEWORD (G_IMMFIRST-3) +#define G_TEXTURE (G_IMMFIRST-4) +#define G_SETOTHERMODE_H (G_IMMFIRST-5) +#define G_SETOTHERMODE_L (G_IMMFIRST-6) +#define G_ENDDL (G_IMMFIRST-7) +#define G_SETGEOMETRYMODE (G_IMMFIRST-8) +#define G_CLEARGEOMETRYMODE (G_IMMFIRST-9) +#define G_LINE3D (G_IMMFIRST-10) +#define G_RDPHALF_1 (G_IMMFIRST-11) +#define G_RDPHALF_2 (G_IMMFIRST-12) +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +# define G_MODIFYVTX (G_IMMFIRST-13) +# define G_TRI2 (G_IMMFIRST-14) +# define G_BRANCH_Z (G_IMMFIRST-15) +# define G_LOAD_UCODE (G_IMMFIRST-16) +#else +# define G_RDPHALF_CONT (G_IMMFIRST-13) +#endif + +/* We are overloading 2 of the immediate commands + to keep the byte alignment of dmem the same */ + +#define G_SPRITE2D_SCALEFLIP (G_IMMFIRST-1) +#define G_SPRITE2D_DRAW (G_IMMFIRST-2) + +/* RDP commands: */ +#define G_NOOP 0xc0 /* 0 */ + +#endif /* F3DEX_GBI_2 */ + +/* RDP commands: */ +#define G_SETCIMG 0xff /* -1 */ +#define G_SETZIMG 0xfe /* -2 */ +#define G_SETTIMG 0xfd /* -3 */ +#define G_SETCOMBINE 0xfc /* -4 */ +#define G_SETENVCOLOR 0xfb /* -5 */ +#define G_SETPRIMCOLOR 0xfa /* -6 */ +#define G_SETBLENDCOLOR 0xf9 /* -7 */ +#define G_SETFOGCOLOR 0xf8 /* -8 */ +#define G_SETFILLCOLOR 0xf7 /* -9 */ +#define G_FILLRECT 0xf6 /* -10 */ +#define G_SETTILE 0xf5 /* -11 */ +#define G_LOADTILE 0xf4 /* -12 */ +#define G_LOADBLOCK 0xf3 /* -13 */ +#define G_SETTILESIZE 0xf2 /* -14 */ +#define G_LOADTLUT 0xf0 /* -16 */ +#define G_RDPSETOTHERMODE 0xef /* -17 */ +#define G_SETPRIMDEPTH 0xee /* -18 */ +#define G_SETSCISSOR 0xed /* -19 */ +#define G_SETCONVERT 0xec /* -20 */ +#define G_SETKEYR 0xeb /* -21 */ +#define G_SETKEYGB 0xea /* -22 */ +#define G_RDPFULLSYNC 0xe9 /* -23 */ +#define G_RDPTILESYNC 0xe8 /* -24 */ +#define G_RDPPIPESYNC 0xe7 /* -25 */ +#define G_RDPLOADSYNC 0xe6 /* -26 */ +#define G_TEXRECTFLIP 0xe5 /* -27 */ +#define G_TEXRECT 0xe4 /* -28 */ + + +/* + * The following commands are the "generated" RDP commands; the user + * never sees them, the RSP microcode generates them. + * + * The layout of the bits is magical, to save work in the ucode. + * These id's are -56, -52, -54, -50, -55, -51, -53, -49, ... + * edge, shade, texture, zbuff bits: estz + */ +#define G_TRI_FILL 0xc8 /* fill triangle: 11001000 */ +#define G_TRI_SHADE 0xcc /* shade triangle: 11001100 */ +#define G_TRI_TXTR 0xca /* texture triangle: 11001010 */ +#define G_TRI_SHADE_TXTR 0xce /* shade, texture triangle: 11001110 */ +#define G_TRI_FILL_ZBUFF 0xc9 /* fill, zbuff triangle: 11001001 */ +#define G_TRI_SHADE_ZBUFF 0xcd /* shade, zbuff triangle: 11001101 */ +#define G_TRI_TXTR_ZBUFF 0xcb /* texture, zbuff triangle: 11001011 */ +#define G_TRI_SHADE_TXTR_ZBUFF 0xcf /* shade, txtr, zbuff trngl: 11001111 */ + +/* + * A TRI_FILL triangle is just the edges. You need to set the DP + * to use primcolor, in order to see anything. (it is NOT a triangle + * that gets rendered in 'fill mode'. Triangles can't be rendered + * in 'fill mode') + * + * A TRI_SHADE is a gouraud triangle that has colors interpolated. + * Flat-shaded triangles (from the software) are still gouraud shaded, + * it's just the colors are all the same and the deltas are 0. + * + * Other triangle types, and combinations are more obvious. + */ + +/* masks to build RDP triangle commands: */ +#define G_RDP_TRI_FILL_MASK 0x08 +#define G_RDP_TRI_SHADE_MASK 0x04 +#define G_RDP_TRI_TXTR_MASK 0x02 +#define G_RDP_TRI_ZBUFF_MASK 0x01 + +/* + * HACK: + * This is a dreadful hack. For version 1.0 hardware, there are still + * some 'bowtie' hangs. This parameter can be increased to avoid + * the hangs. Every increase of 4 chops one scanline off of every + * triangle. Values of 4,8,12 should be sufficient to avoid any + * bowtie hang. + * + * Change this value, then recompile ALL of your program (including static + * display lists!) + * + * THIS WILL BE REMOVED FOR HARDWARE VERSION 2.0! + */ +#define BOWTIE_VAL 0 + + +/* gets added to RDP command, in order to test for addres fixup: */ +#define G_RDP_ADDR_FIXUP 3 /* |RDP cmds| <= this, do addr fixup */ +#ifdef _LANGUAGE_ASSEMBLY +#define G_RDP_TEXRECT_CHECK ((-1*G_TEXRECTFLIP)& 0xff) +#endif + +/* macros for command parsing: */ +#define GDMACMD(x) (x) +#define GIMMCMD(x) (G_IMMFIRST-(x)) +#define GRDPCMD(x) (0xff-(x)) + +#define G_DMACMDSIZ 128 +#define G_IMMCMDSIZ 64 +#define G_RDPCMDSIZ 64 + +/* + * Coordinate shift values, number of bits of fraction + */ +#define G_TEXTURE_IMAGE_FRAC 2 +#define G_TEXTURE_SCALE_FRAC 16 +#define G_SCALE_FRAC 8 +#define G_ROTATE_FRAC 16 + +/* + * Parameters to graphics commands + */ + +/* + * Data packing macros + */ + +/* + * Maximum z-buffer value, used to initialize the z-buffer. + * Note : this number is NOT the viewport z-scale constant. + * See the comment next to G_MAXZ for more info. + */ +#define G_MAXFBZ 0x3fff /* 3b exp, 11b mantissa */ + +#define GPACK_RGBA5551(r, g, b, a) ((((r)<<8) & 0xf800) | \ + (((g)<<3) & 0x7c0) | \ + (((b)>>2) & 0x3e) | ((a) & 0x1)) +#define GPACK_ZDZ(z, dz) ((z) << 2 | (dz)) + +/* + * G_MTX: parameter flags + */ +#ifdef F3DEX_GBI_2 +# define G_MTX_MODELVIEW 0x00 /* matrix types */ +# define G_MTX_PROJECTION 0x04 +# define G_MTX_MUL 0x00 /* concat or load */ +# define G_MTX_LOAD 0x02 +# define G_MTX_NOPUSH 0x00 /* push or not */ +# define G_MTX_PUSH 0x01 +#else /* F3DEX_GBI_2 */ +# define G_MTX_MODELVIEW 0x00 /* matrix types */ +# define G_MTX_PROJECTION 0x01 +# define G_MTX_MUL 0x00 /* concat or load */ +# define G_MTX_LOAD 0x02 +# define G_MTX_NOPUSH 0x00 /* push or not */ +# define G_MTX_PUSH 0x04 +#endif /* F3DEX_GBI_2 */ + +/* + * flags for G_SETGEOMETRYMODE + * (this rendering state is maintained in RSP) + * + * DO NOT USE THE LOW 8 BITS OF GEOMETRYMODE: + * The weird bit-ordering is for the micro-code: the lower byte + * can be OR'd in with G_TRI_SHADE (11001100) to construct + * the triangle command directly. Don't break it... + * + * DO NOT USE THE HIGH 8 BITS OF GEOMETRYMODE: + * The high byte is OR'd with 0x703 to form the clip code mask. + * If it is set to 0x04, this will cause near clipping to occur. + * If it is zero, near clipping will not occur. + * + * Further explanation: + * G_SHADE is necessary in order to see the color that you passed + * down with the vertex. If G_SHADE isn't set, you need to set the DP + * appropriately and use primcolor to see anything. + * + * G_SHADING_SMOOTH enabled means use all 3 colors of the triangle. + * If it is not set, then do 'flat shading', where only one vertex color + * is used (and all 3 vertices are set to that same color by the ucode) + * See the man page for gSP1Triangle(). + * + */ +#define G_ZBUFFER 0x00000001 +#define G_SHADE 0x00000004 /* enable Gouraud interp */ +/* rest of low byte reserved for setup ucode */ +#ifdef F3DEX_GBI_2 +# define G_TEXTURE_ENABLE 0x00000000 /* Ignored */ +# define G_SHADING_SMOOTH 0x00200000 /* flat or smooth shaded */ +# define G_CULL_FRONT 0x00000200 +# define G_CULL_BACK 0x00000400 +# define G_CULL_BOTH 0x00000600 /* To make code cleaner */ +#else +# define G_TEXTURE_ENABLE 0x00000002 /* Microcode use only */ +# define G_SHADING_SMOOTH 0x00000200 /* flat or smooth shaded */ +# define G_CULL_FRONT 0x00001000 +# define G_CULL_BACK 0x00002000 +# define G_CULL_BOTH 0x00003000 /* To make code cleaner */ +#endif +#define G_FOG 0x00010000 +#define G_LIGHTING 0x00020000 +#define G_TEXTURE_GEN 0x00040000 +#define G_TEXTURE_GEN_LINEAR 0x00080000 +#define G_LOD 0x00100000 /* NOT IMPLEMENTED */ +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +# define G_CLIPPING 0x00800000 +#else +# define G_CLIPPING 0x00000000 +#endif + +#ifdef _LANGUAGE_ASSEMBLY +#define G_FOG_H (G_FOG/0x10000) +#define G_LIGHTING_H (G_LIGHTING/0x10000) +#define G_TEXTURE_GEN_H (G_TEXTURE_GEN/0x10000) +#define G_TEXTURE_GEN_LINEAR_H (G_TEXTURE_GEN_LINEAR/0x10000) +#define G_LOD_H (G_LOD/0x10000) /* NOT IMPLEMENTED */ +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +# define G_CLIPPING_H (G_CLIPPING/0x10000) +#endif +#endif + +/* Need these defined for Sprite Microcode */ +#ifdef _LANGUAGE_ASSEMBLY +#define G_TX_LOADTILE 7 +#define G_TX_RENDERTILE 0 + +#define G_TX_NOMIRROR 0 +#define G_TX_WRAP 0 +#define G_TX_MIRROR 0x1 +#define G_TX_CLAMP 0x2 +#define G_TX_NOMASK 0 +#define G_TX_NOLOD 0 +#endif + +/* + * G_SETIMG fmt: set image formats + */ +#define G_IM_FMT_RGBA 0 +#define G_IM_FMT_YUV 1 +#define G_IM_FMT_CI 2 +#define G_IM_FMT_IA 3 +#define G_IM_FMT_I 4 + +/* + * G_SETIMG siz: set image pixel size + */ +#define G_IM_SIZ_4b 0 +#define G_IM_SIZ_8b 1 +#define G_IM_SIZ_16b 2 +#define G_IM_SIZ_32b 3 +#define G_IM_SIZ_DD 5 + +#define G_IM_SIZ_4b_BYTES 0 +#define G_IM_SIZ_4b_TILE_BYTES G_IM_SIZ_4b_BYTES +#define G_IM_SIZ_4b_LINE_BYTES G_IM_SIZ_4b_BYTES + +#define G_IM_SIZ_8b_BYTES 1 +#define G_IM_SIZ_8b_TILE_BYTES G_IM_SIZ_8b_BYTES +#define G_IM_SIZ_8b_LINE_BYTES G_IM_SIZ_8b_BYTES + +#define G_IM_SIZ_16b_BYTES 2 +#define G_IM_SIZ_16b_TILE_BYTES G_IM_SIZ_16b_BYTES +#define G_IM_SIZ_16b_LINE_BYTES G_IM_SIZ_16b_BYTES + +#define G_IM_SIZ_32b_BYTES 4 +#define G_IM_SIZ_32b_TILE_BYTES 2 +#define G_IM_SIZ_32b_LINE_BYTES 2 + +#define G_IM_SIZ_4b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_8b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_16b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_32b_LOAD_BLOCK G_IM_SIZ_32b + +#define G_IM_SIZ_4b_SHIFT 2 +#define G_IM_SIZ_8b_SHIFT 1 +#define G_IM_SIZ_16b_SHIFT 0 +#define G_IM_SIZ_32b_SHIFT 0 + +#define G_IM_SIZ_4b_INCR 3 +#define G_IM_SIZ_8b_INCR 1 +#define G_IM_SIZ_16b_INCR 0 +#define G_IM_SIZ_32b_INCR 0 + +/* + * G_SETCOMBINE: color combine modes + */ +/* Color combiner constants: */ +#define G_CCMUX_COMBINED 0 +#define G_CCMUX_TEXEL0 1 +#define G_CCMUX_TEXEL1 2 +#define G_CCMUX_PRIMITIVE 3 +#define G_CCMUX_SHADE 4 +#define G_CCMUX_ENVIRONMENT 5 +#define G_CCMUX_CENTER 6 +#define G_CCMUX_SCALE 6 +#define G_CCMUX_COMBINED_ALPHA 7 +#define G_CCMUX_TEXEL0_ALPHA 8 +#define G_CCMUX_TEXEL1_ALPHA 9 +#define G_CCMUX_PRIMITIVE_ALPHA 10 +#define G_CCMUX_SHADE_ALPHA 11 +#define G_CCMUX_ENV_ALPHA 12 +#define G_CCMUX_LOD_FRACTION 13 +#define G_CCMUX_PRIM_LOD_FRAC 14 +#define G_CCMUX_NOISE 7 +#define G_CCMUX_K4 7 +#define G_CCMUX_K5 15 +#define G_CCMUX_1 6 +#define G_CCMUX_0 31 + +/* Alpha combiner constants: */ +#define G_ACMUX_COMBINED 0 +#define G_ACMUX_TEXEL0 1 +#define G_ACMUX_TEXEL1 2 +#define G_ACMUX_PRIMITIVE 3 +#define G_ACMUX_SHADE 4 +#define G_ACMUX_ENVIRONMENT 5 +#define G_ACMUX_LOD_FRACTION 0 +#define G_ACMUX_PRIM_LOD_FRAC 6 +#define G_ACMUX_1 6 +#define G_ACMUX_0 7 + +/* typical CC cycle 1 modes */ +#define G_CC_PRIMITIVE 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE +#define G_CC_SHADE 0, 0, 0, SHADE, 0, 0, 0, SHADE +#define G_CC_MODULATEI TEXEL0, 0, SHADE, 0, 0, 0, 0, SHADE +#define G_CC_MODULATEIA TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0 +#define G_CC_MODULATEIDECALA TEXEL0, 0, SHADE, 0, 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB G_CC_MODULATEI +#define G_CC_MODULATERGBA G_CC_MODULATEIA +#define G_CC_MODULATERGBDECALA G_CC_MODULATEIDECALA +#define G_CC_MODULATEI_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0 +#define G_CC_MODULATEIDECALA_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB_PRIM G_CC_MODULATEI_PRIM +#define G_CC_MODULATERGBA_PRIM G_CC_MODULATEIA_PRIM +#define G_CC_MODULATERGBDECALA_PRIM G_CC_MODULATEIDECALA_PRIM +#define G_CC_DECALRGB 0, 0, 0, TEXEL0, 0, 0, 0, SHADE +#define G_CC_DECALRGBA 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0 +#define G_CC_BLENDI ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDIA ENVIRONMENT, SHADE, TEXEL0, SHADE, TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDIDECALA ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_BLENDRGBA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDRGBDECALA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_ADDRGB 1, 0, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_ADDRGBDECALA 1, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_REFLECTRGB ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_REFLECTRGBDECALA ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_HILITERGB PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_HILITERGBA PRIMITIVE, SHADE, TEXEL0, SHADE, PRIMITIVE, SHADE, TEXEL0, SHADE +#define G_CC_HILITERGBDECALA PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_SHADEDECALA 0, 0, 0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_BLENDPE PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDPEDECALA PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, TEXEL0 + +/* oddball modes */ +#define _G_CC_BLENDPE ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, SHADE, 0 +#define _G_CC_BLENDPEDECALA ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, 0, 0, 0, TEXEL0 +#define _G_CC_TWOCOLORTEX PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +/* used for 1-cycle sparse mip-maps, primitive color has color of lowest LOD */ +#define _G_CC_SPARSEST PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0, PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0 +#define G_CC_TEMPLERP TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0 + +/* typical CC cycle 1 modes, usually followed by other cycle 2 modes */ +#define G_CC_TRILERP TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0, TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0 +#define G_CC_INTERFERENCE TEXEL0, 0, TEXEL1, 0, TEXEL0, 0, TEXEL1, 0 + +/* + * One-cycle color convert operation + */ +#define G_CC_1CYUV2RGB TEXEL0, K4, K5, TEXEL0, 0, 0, 0, SHADE + +/* + * NOTE: YUV2RGB expects TF step1 color conversion to occur in 2nd clock. + * Therefore, CC looks for step1 results in TEXEL1 + */ +#define G_CC_YUV2RGB TEXEL1, K4, K5, TEXEL1, 0, 0, 0, 0 + +/* typical CC cycle 2 modes */ +#define G_CC_PASS2 0, 0, 0, COMBINED, 0, 0, 0, COMBINED +#define G_CC_MODULATEI2 COMBINED, 0, SHADE, 0, 0, 0, 0, SHADE +#define G_CC_MODULATEIA2 COMBINED, 0, SHADE, 0, COMBINED, 0, SHADE, 0 +#define G_CC_MODULATERGB2 G_CC_MODULATEI2 +#define G_CC_MODULATERGBA2 G_CC_MODULATEIA2 +#define G_CC_MODULATEI_PRIM2 COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM2 COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0 +#define G_CC_MODULATERGB_PRIM2 G_CC_MODULATEI_PRIM2 +#define G_CC_MODULATERGBA_PRIM2 G_CC_MODULATEIA_PRIM2 +#define G_CC_DECALRGB2 0, 0, 0, COMBINED, 0, 0, 0, SHADE +/* + * ? +#define G_CC_DECALRGBA2 COMBINED, SHADE, COMBINED_ALPHA, SHADE, 0, 0, 0, SHADE +*/ +#define G_CC_BLENDI2 ENVIRONMENT, SHADE, COMBINED, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDIA2 ENVIRONMENT, SHADE, COMBINED, SHADE, COMBINED, 0, SHADE, 0 +#define G_CC_CHROMA_KEY2 TEXEL0, CENTER, SCALE, 0, 0, 0, 0, 0 +#define G_CC_HILITERGB2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, SHADE +#define G_CC_HILITERGBA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, ENVIRONMENT, COMBINED, TEXEL0, COMBINED +#define G_CC_HILITERGBDECALA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, TEXEL0 +#define G_CC_HILITERGBPASSA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, COMBINED + +/* + * G_SETOTHERMODE_L sft: shift count + */ +#define G_MDSFT_ALPHACOMPARE 0 +#define G_MDSFT_ZSRCSEL 2 +#define G_MDSFT_RENDERMODE 3 +#define G_MDSFT_BLENDER 16 + +/* + * G_SETOTHERMODE_H sft: shift count + */ +#define G_MDSFT_BLENDMASK 0 /* unsupported */ +#define G_MDSFT_ALPHADITHER 4 +#define G_MDSFT_RGBDITHER 6 + +#define G_MDSFT_COMBKEY 8 +#define G_MDSFT_TEXTCONV 9 +#define G_MDSFT_TEXTFILT 12 +#define G_MDSFT_TEXTLUT 14 +#define G_MDSFT_TEXTLOD 16 +#define G_MDSFT_TEXTDETAIL 17 +#define G_MDSFT_TEXTPERSP 19 +#define G_MDSFT_CYCLETYPE 20 +#define G_MDSFT_COLORDITHER 22 /* unsupported in HW 2.0 */ +#define G_MDSFT_PIPELINE 23 + +/* G_SETOTHERMODE_H gPipelineMode */ +#define G_PM_1PRIMITIVE (1 << G_MDSFT_PIPELINE) +#define G_PM_NPRIMITIVE (0 << G_MDSFT_PIPELINE) + +/* G_SETOTHERMODE_H gSetCycleType */ +#define G_CYC_1CYCLE (0 << G_MDSFT_CYCLETYPE) +#define G_CYC_2CYCLE (1 << G_MDSFT_CYCLETYPE) +#define G_CYC_COPY (2 << G_MDSFT_CYCLETYPE) +#define G_CYC_FILL (3 << G_MDSFT_CYCLETYPE) + +/* G_SETOTHERMODE_H gSetTexturePersp */ +#define G_TP_NONE (0 << G_MDSFT_TEXTPERSP) +#define G_TP_PERSP (1 << G_MDSFT_TEXTPERSP) + +/* G_SETOTHERMODE_H gSetTextureDetail */ +#define G_TD_CLAMP (0 << G_MDSFT_TEXTDETAIL) +#define G_TD_SHARPEN (1 << G_MDSFT_TEXTDETAIL) +#define G_TD_DETAIL (2 << G_MDSFT_TEXTDETAIL) + +/* G_SETOTHERMODE_H gSetTextureLOD */ +#define G_TL_TILE (0 << G_MDSFT_TEXTLOD) +#define G_TL_LOD (1 << G_MDSFT_TEXTLOD) + +/* G_SETOTHERMODE_H gSetTextureLUT */ +#define G_TT_NONE (0 << G_MDSFT_TEXTLUT) +#define G_TT_RGBA16 (2 << G_MDSFT_TEXTLUT) +#define G_TT_IA16 (3 << G_MDSFT_TEXTLUT) + +/* G_SETOTHERMODE_H gSetTextureFilter */ +#define G_TF_POINT (0 << G_MDSFT_TEXTFILT) +#define G_TF_AVERAGE (3 << G_MDSFT_TEXTFILT) +#define G_TF_BILERP (2 << G_MDSFT_TEXTFILT) + +/* G_SETOTHERMODE_H gSetTextureConvert */ +#define G_TC_CONV (0 << G_MDSFT_TEXTCONV) +#define G_TC_FILTCONV (5 << G_MDSFT_TEXTCONV) +#define G_TC_FILT (6 << G_MDSFT_TEXTCONV) + +/* G_SETOTHERMODE_H gSetCombineKey */ +#define G_CK_NONE (0 << G_MDSFT_COMBKEY) +#define G_CK_KEY (1 << G_MDSFT_COMBKEY) + +/* G_SETOTHERMODE_H gSetColorDither */ +#define G_CD_MAGICSQ (0 << G_MDSFT_RGBDITHER) +#define G_CD_BAYER (1 << G_MDSFT_RGBDITHER) +#define G_CD_NOISE (2 << G_MDSFT_RGBDITHER) + +#ifndef _HW_VERSION_1 +#define G_CD_DISABLE (3 << G_MDSFT_RGBDITHER) +#define G_CD_ENABLE G_CD_NOISE /* HW 1.0 compatibility mode */ +#else +#define G_CD_ENABLE (1 << G_MDSFT_COLORDITHER) +#define G_CD_DISABLE (0 << G_MDSFT_COLORDITHER) +#endif + +/* G_SETOTHERMODE_H gSetAlphaDither */ +#define G_AD_PATTERN (0 << G_MDSFT_ALPHADITHER) +#define G_AD_NOTPATTERN (1 << G_MDSFT_ALPHADITHER) +#define G_AD_NOISE (2 << G_MDSFT_ALPHADITHER) +#define G_AD_DISABLE (3 << G_MDSFT_ALPHADITHER) + +/* G_SETOTHERMODE_L gSetAlphaCompare */ +#define G_AC_NONE (0 << G_MDSFT_ALPHACOMPARE) +#define G_AC_THRESHOLD (1 << G_MDSFT_ALPHACOMPARE) +#define G_AC_DITHER (3 << G_MDSFT_ALPHACOMPARE) + +/* G_SETOTHERMODE_L gSetDepthSource */ +#define G_ZS_PIXEL (0 << G_MDSFT_ZSRCSEL) +#define G_ZS_PRIM (1 << G_MDSFT_ZSRCSEL) + +/* G_SETOTHERMODE_L gSetRenderMode */ +#define AA_EN 0x8 +#define Z_CMP 0x10 +#define Z_UPD 0x20 +#define IM_RD 0x40 +#define CLR_ON_CVG 0x80 +#define CVG_DST_CLAMP 0 +#define CVG_DST_WRAP 0x100 +#define CVG_DST_FULL 0x200 +#define CVG_DST_SAVE 0x300 +#define ZMODE_OPA 0 +#define ZMODE_INTER 0x400 +#define ZMODE_XLU 0x800 +#define ZMODE_DEC 0xc00 +#define CVG_X_ALPHA 0x1000 +#define ALPHA_CVG_SEL 0x2000 +#define FORCE_BL 0x4000 +#define TEX_EDGE 0x0000 /* used to be 0x8000 */ + +#define G_BL_CLR_IN 0 +#define G_BL_CLR_MEM 1 +#define G_BL_CLR_BL 2 +#define G_BL_CLR_FOG 3 +#define G_BL_1MA 0 +#define G_BL_A_MEM 1 +#define G_BL_A_IN 0 +#define G_BL_A_FOG 1 +#define G_BL_A_SHADE 2 +#define G_BL_1 2 +#define G_BL_0 3 + +#define GBL_c1(m1a, m1b, m2a, m2b) \ + (m1a) << 30 | (m1b) << 26 | (m2a) << 22 | (m2b) << 18 +#define GBL_c2(m1a, m1b, m2a, m2b) \ + (m1a) << 28 | (m1b) << 24 | (m2a) << 20 | (m2b) << 16 + +#define RM_AA_ZB_OPA_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_ZB_OPA_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_XLU_SURF(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ + FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_OPA_DECAL(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | ALPHA_CVG_SEL | \ + ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_ZB_OPA_DECAL(clk) \ + AA_EN | Z_CMP | CVG_DST_WRAP | ALPHA_CVG_SEL | \ + ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_XLU_DECAL(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ + FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_OPA_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ALPHA_CVG_SEL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_ZB_OPA_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ + ALPHA_CVG_SEL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_XLU_INTER(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ + FORCE_BL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_XLU_LINE(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_DEC_LINE(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_TEX_EDGE(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_TEX_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_INTER | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_SUB_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_PCL_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_OPA_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_TEX_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_SUB_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + + +#define RM_AA_OPA_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_OPA_SURF(clk) \ + AA_EN | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_XLU_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | \ + ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_XLU_LINE(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_DEC_LINE(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_TEX_EDGE(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_SUB_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_PCL_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_OPA_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_TEX_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_SUB_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + + +#define RM_ZB_OPA_SURF(clk) \ + Z_CMP | Z_UPD | CVG_DST_FULL | ALPHA_CVG_SEL | \ + ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_ZB_XLU_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_OPA_DECAL(clk) \ + Z_CMP | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_ZB_XLU_DECAL(clk) \ + Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_CLD_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_OVL_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_PCL_SURF(clk) \ + Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \ + G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + + +#define RM_OPA_SURF(clk) \ + CVG_DST_CLAMP | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +#define RM_XLU_SURF(clk) \ + IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_TEX_EDGE(clk) \ + CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL |\ + ZMODE_OPA | TEX_EDGE | AA_EN | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +#define RM_CLD_SURF(clk) \ + IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_PCL_SURF(clk) \ + CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ + G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +#define RM_ADD(clk) \ + IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_1) + +#define RM_NOOP(clk) \ + GBL_c##clk(0, 0, 0, 0) + +#define RM_VISCVG(clk) \ + IM_RD | FORCE_BL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_BL, G_BL_A_MEM) + +/* for rendering to an 8-bit framebuffer */ +#define RM_OPA_CI(clk) \ + CVG_DST_CLAMP | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + + + +#define G_RM_AA_ZB_OPA_SURF RM_AA_ZB_OPA_SURF(1) +#define G_RM_AA_ZB_OPA_SURF2 RM_AA_ZB_OPA_SURF(2) +#define G_RM_AA_ZB_XLU_SURF RM_AA_ZB_XLU_SURF(1) +#define G_RM_AA_ZB_XLU_SURF2 RM_AA_ZB_XLU_SURF(2) +#define G_RM_AA_ZB_OPA_DECAL RM_AA_ZB_OPA_DECAL(1) +#define G_RM_AA_ZB_OPA_DECAL2 RM_AA_ZB_OPA_DECAL(2) +#define G_RM_AA_ZB_XLU_DECAL RM_AA_ZB_XLU_DECAL(1) +#define G_RM_AA_ZB_XLU_DECAL2 RM_AA_ZB_XLU_DECAL(2) +#define G_RM_AA_ZB_OPA_INTER RM_AA_ZB_OPA_INTER(1) +#define G_RM_AA_ZB_OPA_INTER2 RM_AA_ZB_OPA_INTER(2) +#define G_RM_AA_ZB_XLU_INTER RM_AA_ZB_XLU_INTER(1) +#define G_RM_AA_ZB_XLU_INTER2 RM_AA_ZB_XLU_INTER(2) +#define G_RM_AA_ZB_XLU_LINE RM_AA_ZB_XLU_LINE(1) +#define G_RM_AA_ZB_XLU_LINE2 RM_AA_ZB_XLU_LINE(2) +#define G_RM_AA_ZB_DEC_LINE RM_AA_ZB_DEC_LINE(1) +#define G_RM_AA_ZB_DEC_LINE2 RM_AA_ZB_DEC_LINE(2) +#define G_RM_AA_ZB_TEX_EDGE RM_AA_ZB_TEX_EDGE(1) +#define G_RM_AA_ZB_TEX_EDGE2 RM_AA_ZB_TEX_EDGE(2) +#define G_RM_AA_ZB_TEX_INTER RM_AA_ZB_TEX_INTER(1) +#define G_RM_AA_ZB_TEX_INTER2 RM_AA_ZB_TEX_INTER(2) +#define G_RM_AA_ZB_SUB_SURF RM_AA_ZB_SUB_SURF(1) +#define G_RM_AA_ZB_SUB_SURF2 RM_AA_ZB_SUB_SURF(2) +#define G_RM_AA_ZB_PCL_SURF RM_AA_ZB_PCL_SURF(1) +#define G_RM_AA_ZB_PCL_SURF2 RM_AA_ZB_PCL_SURF(2) +#define G_RM_AA_ZB_OPA_TERR RM_AA_ZB_OPA_TERR(1) +#define G_RM_AA_ZB_OPA_TERR2 RM_AA_ZB_OPA_TERR(2) +#define G_RM_AA_ZB_TEX_TERR RM_AA_ZB_TEX_TERR(1) +#define G_RM_AA_ZB_TEX_TERR2 RM_AA_ZB_TEX_TERR(2) +#define G_RM_AA_ZB_SUB_TERR RM_AA_ZB_SUB_TERR(1) +#define G_RM_AA_ZB_SUB_TERR2 RM_AA_ZB_SUB_TERR(2) + +#define G_RM_RA_ZB_OPA_SURF RM_RA_ZB_OPA_SURF(1) +#define G_RM_RA_ZB_OPA_SURF2 RM_RA_ZB_OPA_SURF(2) +#define G_RM_RA_ZB_OPA_DECAL RM_RA_ZB_OPA_DECAL(1) +#define G_RM_RA_ZB_OPA_DECAL2 RM_RA_ZB_OPA_DECAL(2) +#define G_RM_RA_ZB_OPA_INTER RM_RA_ZB_OPA_INTER(1) +#define G_RM_RA_ZB_OPA_INTER2 RM_RA_ZB_OPA_INTER(2) + +#define G_RM_AA_OPA_SURF RM_AA_OPA_SURF(1) +#define G_RM_AA_OPA_SURF2 RM_AA_OPA_SURF(2) +#define G_RM_AA_XLU_SURF RM_AA_XLU_SURF(1) +#define G_RM_AA_XLU_SURF2 RM_AA_XLU_SURF(2) +#define G_RM_AA_XLU_LINE RM_AA_XLU_LINE(1) +#define G_RM_AA_XLU_LINE2 RM_AA_XLU_LINE(2) +#define G_RM_AA_DEC_LINE RM_AA_DEC_LINE(1) +#define G_RM_AA_DEC_LINE2 RM_AA_DEC_LINE(2) +#define G_RM_AA_TEX_EDGE RM_AA_TEX_EDGE(1) +#define G_RM_AA_TEX_EDGE2 RM_AA_TEX_EDGE(2) +#define G_RM_AA_SUB_SURF RM_AA_SUB_SURF(1) +#define G_RM_AA_SUB_SURF2 RM_AA_SUB_SURF(2) +#define G_RM_AA_PCL_SURF RM_AA_PCL_SURF(1) +#define G_RM_AA_PCL_SURF2 RM_AA_PCL_SURF(2) +#define G_RM_AA_OPA_TERR RM_AA_OPA_TERR(1) +#define G_RM_AA_OPA_TERR2 RM_AA_OPA_TERR(2) +#define G_RM_AA_TEX_TERR RM_AA_TEX_TERR(1) +#define G_RM_AA_TEX_TERR2 RM_AA_TEX_TERR(2) +#define G_RM_AA_SUB_TERR RM_AA_SUB_TERR(1) +#define G_RM_AA_SUB_TERR2 RM_AA_SUB_TERR(2) + +#define G_RM_RA_OPA_SURF RM_RA_OPA_SURF(1) +#define G_RM_RA_OPA_SURF2 RM_RA_OPA_SURF(2) + +#define G_RM_ZB_OPA_SURF RM_ZB_OPA_SURF(1) +#define G_RM_ZB_OPA_SURF2 RM_ZB_OPA_SURF(2) +#define G_RM_ZB_XLU_SURF RM_ZB_XLU_SURF(1) +#define G_RM_ZB_XLU_SURF2 RM_ZB_XLU_SURF(2) +#define G_RM_ZB_OPA_DECAL RM_ZB_OPA_DECAL(1) +#define G_RM_ZB_OPA_DECAL2 RM_ZB_OPA_DECAL(2) +#define G_RM_ZB_XLU_DECAL RM_ZB_XLU_DECAL(1) +#define G_RM_ZB_XLU_DECAL2 RM_ZB_XLU_DECAL(2) +#define G_RM_ZB_CLD_SURF RM_ZB_CLD_SURF(1) +#define G_RM_ZB_CLD_SURF2 RM_ZB_CLD_SURF(2) +#define G_RM_ZB_OVL_SURF RM_ZB_OVL_SURF(1) +#define G_RM_ZB_OVL_SURF2 RM_ZB_OVL_SURF(2) +#define G_RM_ZB_PCL_SURF RM_ZB_PCL_SURF(1) +#define G_RM_ZB_PCL_SURF2 RM_ZB_PCL_SURF(2) + +#define G_RM_OPA_SURF RM_OPA_SURF(1) +#define G_RM_OPA_SURF2 RM_OPA_SURF(2) +#define G_RM_XLU_SURF RM_XLU_SURF(1) +#define G_RM_XLU_SURF2 RM_XLU_SURF(2) +#define G_RM_CLD_SURF RM_CLD_SURF(1) +#define G_RM_CLD_SURF2 RM_CLD_SURF(2) +#define G_RM_TEX_EDGE RM_TEX_EDGE(1) +#define G_RM_TEX_EDGE2 RM_TEX_EDGE(2) +#define G_RM_PCL_SURF RM_PCL_SURF(1) +#define G_RM_PCL_SURF2 RM_PCL_SURF(2) +#define G_RM_ADD RM_ADD(1) +#define G_RM_ADD2 RM_ADD(2) +#define G_RM_NOOP RM_NOOP(1) +#define G_RM_NOOP2 RM_NOOP(2) +#define G_RM_VISCVG RM_VISCVG(1) +#define G_RM_VISCVG2 RM_VISCVG(2) +#define G_RM_OPA_CI RM_OPA_CI(1) +#define G_RM_OPA_CI2 RM_OPA_CI(2) + + +#define G_RM_FOG_SHADE_A GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA) +#define G_RM_FOG_PRIM_A GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA) +#define G_RM_PASS GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +/* + * G_SETCONVERT: K0-5 + */ +#define G_CV_K0 175 +#define G_CV_K1 -43 +#define G_CV_K2 -89 +#define G_CV_K3 222 +#define G_CV_K4 114 +#define G_CV_K5 42 + +/* + * G_SETSCISSOR: interlace mode + */ +#define G_SC_NON_INTERLACE 0 +#define G_SC_ODD_INTERLACE 3 +#define G_SC_EVEN_INTERLACE 2 + +/* flags to inhibit pushing of the display list (on branch) */ +#define G_DL_PUSH 0x00 +#define G_DL_NOPUSH 0x01 + +/* + * BEGIN C-specific section: (typedef's) + */ +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* + * Data Structures + * + * NOTE: + * The DMA transfer hardware requires 64-bit aligned, 64-bit multiple- + * sized transfers. This important hardware optimization is unfortunately + * reflected in the programming interface, with some structures + * padded and alignment enforced. + * + * Since structures are aligned to the boundary of the "worst-case" + * element, we can't depend on the C compiler to align things + * properly. + * + * 64-bit structure alignment is enforced by wrapping structures with + * unions that contain a dummy "long long int". Why this works is + * explained in the ANSI C Spec, or on page 186 of the second edition + * of K&R, "The C Programming Language". + * + * The price we pay for this is a little awkwardness referencing the + * structures through the union. There is no memory penalty, since + * all the structures are at least 64-bits the dummy alignment field + * does not increase the size of the union. + * + * Static initialization of these union structures works because + * the ANSI C spec states that static initialization for unions + * works by using the first union element. We put the dummy alignment + * field last for this reason. + * + * (it's possible a newer 64-bit compiler from MIPS might make this + * easier with a flag, but we can't wait for it...) + * + */ + +/* + * Vertex (set up for use with colors) + */ +typedef struct { + short ob[3]; /* x, y, z */ + unsigned short flag; + short tc[2]; /* texture coord */ + unsigned char cn[4]; /* color & alpha */ +} Vtx_t; + +/* + * Vertex (set up for use with normals) + */ +typedef struct { + short ob[3]; /* x, y, z */ + unsigned short flag; + short tc[2]; /* texture coord */ + signed char n[3]; /* normal */ + unsigned char a; /* alpha */ +} Vtx_tn; + +typedef union { + Vtx_t v; /* Use this one for colors */ + Vtx_tn n; /* Use this one for normals */ + long long int force_structure_alignment; +} Vtx; + +/* + * Sprite structure + */ + +typedef struct { + void *SourceImagePointer; + void *TlutPointer; + short Stride; + short SubImageWidth; + short SubImageHeight; + char SourceImageType; + char SourceImageBitSize; + short SourceImageOffsetS; + short SourceImageOffsetT; + /* 20 bytes for above */ + + /* padding to bring structure size to 64 bit allignment */ + char dummy[4]; + +} uSprite_t; + +typedef union { + uSprite_t s; + + /* Need to make sure this is 64 bit aligned */ + long long int force_structure_allignment[3]; +} uSprite; + +/* + * Triangle face + */ +typedef struct { + unsigned char flag; + unsigned char v[3]; +} Tri; + +/* + * 4x4 matrix, fixed point s15.16 format. + * First 8 words are integer portion of the 4x4 matrix + * Last 8 words are the fraction portion of the 4x4 matrix + */ +typedef long Mtx_t[4][4]; + +typedef union { + Mtx_t m; + long long int force_structure_alignment; +} Mtx; + +/* + * Viewport + */ + +/* + * + * This magic value is the maximum INTEGER z-range of the hardware + * (there are also 16-bits of fraction, which are introduced during + * any transformations). This is not just a good idea, it's the law. + * Feeding the hardware eventual z-coordinates (after any transforms + * or scaling) bigger than this, will not work. + * + * This number is DIFFERENT than G_MAXFBZ, which is the maximum value + * you want to use to initialize the z-buffer. + * + * The reason these are different is mildly interesting, but too long + * to explain here. It is basically the result of optimizations in the + * hardware. A more generic API might hide this detail from the users, + * but we don't have the ucode to do that... + * + */ +#define G_MAXZ 0x03ff /* 10 bits of integer screen-Z precision */ + +/* + * The viewport structure elements have 2 bits of fraction, necessary + * to accomodate the sub-pixel positioning scaling for the hardware. + * This can also be exploited to handle odd-sized viewports. + * + * Accounting for these fractional bits, using the default projection + * and viewing matrices, the viewport structure is initialized thusly: + * + * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, G_MAXZ, 0, + * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, 0, 0, + */ +typedef struct { + short vscale[4]; /* scale, 2 bits fraction */ + short vtrans[4]; /* translate, 2 bits fraction */ + /* both the above arrays are padded to 64-bit boundary */ +} Vp_t; + +typedef union { + Vp_t vp; + long long int force_structure_alignment; +} Vp; + +/* + * MOVEMEM indices + * + * Each of these indexes an entry in a dmem table + * which points to a 1-4 word block of dmem in + * which to store a 1-4 word DMA. + * + */ +#ifdef F3DEX_GBI_2 +/* 0,4 are reserved by G_MTX */ +# define G_MV_MMTX 2 +# define G_MV_PMTX 6 +# define G_MV_VIEWPORT 8 +# define G_MV_LIGHT 10 +# define G_MV_POINT 12 +# define G_MV_MATRIX 14 /* NOTE: this is in moveword table */ +# define G_MVO_LOOKATX (0*24) +# define G_MVO_LOOKATY (1*24) +# define G_MVO_L0 (2*24) +# define G_MVO_L1 (3*24) +# define G_MVO_L2 (4*24) +# define G_MVO_L3 (5*24) +# define G_MVO_L4 (6*24) +# define G_MVO_L5 (7*24) +# define G_MVO_L6 (8*24) +# define G_MVO_L7 (9*24) +#else /* F3DEX_GBI_2 */ +# define G_MV_VIEWPORT 0x80 +# define G_MV_LOOKATY 0x82 +# define G_MV_LOOKATX 0x84 +# define G_MV_L0 0x86 +# define G_MV_L1 0x88 +# define G_MV_L2 0x8a +# define G_MV_L3 0x8c +# define G_MV_L4 0x8e +# define G_MV_L5 0x90 +# define G_MV_L6 0x92 +# define G_MV_L7 0x94 +# define G_MV_TXTATT 0x96 +# define G_MV_MATRIX_1 0x9e /* NOTE: this is in moveword table */ +# define G_MV_MATRIX_2 0x98 +# define G_MV_MATRIX_3 0x9a +# define G_MV_MATRIX_4 0x9c +#endif /* F3DEX_GBI_2 */ + +/* + * MOVEWORD indices + * + * Each of these indexes an entry in a dmem table + * which points to a word in dmem in dmem where + * an immediate word will be stored. + * + */ +#define G_MW_MATRIX 0x00 /* NOTE: also used by movemem */ +#define G_MW_NUMLIGHT 0x02 +#define G_MW_CLIP 0x04 +#define G_MW_SEGMENT 0x06 +#define G_MW_FOG 0x08 +#define G_MW_LIGHTCOL 0x0a +#ifdef F3DEX_GBI_2 +# define G_MW_FORCEMTX 0x0c +#else /* F3DEX_GBI_2 */ +# define G_MW_POINTS 0x0c +#endif /* F3DEX_GBI_2 */ +#define G_MW_PERSPNORM 0x0e + +/* + * These are offsets from the address in the dmem table + */ +#define G_MWO_NUMLIGHT 0x00 +#define G_MWO_CLIP_RNX 0x04 +#define G_MWO_CLIP_RNY 0x0c +#define G_MWO_CLIP_RPX 0x14 +#define G_MWO_CLIP_RPY 0x1c +#define G_MWO_SEGMENT_0 0x00 +#define G_MWO_SEGMENT_1 0x01 +#define G_MWO_SEGMENT_2 0x02 +#define G_MWO_SEGMENT_3 0x03 +#define G_MWO_SEGMENT_4 0x04 +#define G_MWO_SEGMENT_5 0x05 +#define G_MWO_SEGMENT_6 0x06 +#define G_MWO_SEGMENT_7 0x07 +#define G_MWO_SEGMENT_8 0x08 +#define G_MWO_SEGMENT_9 0x09 +#define G_MWO_SEGMENT_A 0x0a +#define G_MWO_SEGMENT_B 0x0b +#define G_MWO_SEGMENT_C 0x0c +#define G_MWO_SEGMENT_D 0x0d +#define G_MWO_SEGMENT_E 0x0e +#define G_MWO_SEGMENT_F 0x0f +#define G_MWO_FOG 0x00 +#define G_MWO_aLIGHT_1 0x00 +#define G_MWO_bLIGHT_1 0x04 +#ifdef F3DEX_GBI_2 +#define G_MWO_aLIGHT_2 0x18 +#define G_MWO_bLIGHT_2 0x1c +#define G_MWO_aLIGHT_3 0x30 +#define G_MWO_bLIGHT_3 0x34 +#define G_MWO_aLIGHT_4 0x48 +#define G_MWO_bLIGHT_4 0x4c +#define G_MWO_aLIGHT_5 0x60 +#define G_MWO_bLIGHT_5 0x64 +#define G_MWO_aLIGHT_6 0x78 +#define G_MWO_bLIGHT_6 0x7c +#define G_MWO_aLIGHT_7 0x90 +#define G_MWO_bLIGHT_7 0x94 +#define G_MWO_aLIGHT_8 0xa8 +#define G_MWO_bLIGHT_8 0xac +#else +#define G_MWO_aLIGHT_2 0x20 +#define G_MWO_bLIGHT_2 0x24 +#define G_MWO_aLIGHT_3 0x40 +#define G_MWO_bLIGHT_3 0x44 +#define G_MWO_aLIGHT_4 0x60 +#define G_MWO_bLIGHT_4 0x64 +#define G_MWO_aLIGHT_5 0x80 +#define G_MWO_bLIGHT_5 0x84 +#define G_MWO_aLIGHT_6 0xa0 +#define G_MWO_bLIGHT_6 0xa4 +#define G_MWO_aLIGHT_7 0xc0 +#define G_MWO_bLIGHT_7 0xc4 +#define G_MWO_aLIGHT_8 0xe0 +#define G_MWO_bLIGHT_8 0xe4 +#endif +#define G_MWO_MATRIX_XX_XY_I 0x00 +#define G_MWO_MATRIX_XZ_XW_I 0x04 +#define G_MWO_MATRIX_YX_YY_I 0x08 +#define G_MWO_MATRIX_YZ_YW_I 0x0c +#define G_MWO_MATRIX_ZX_ZY_I 0x10 +#define G_MWO_MATRIX_ZZ_ZW_I 0x14 +#define G_MWO_MATRIX_WX_WY_I 0x18 +#define G_MWO_MATRIX_WZ_WW_I 0x1c +#define G_MWO_MATRIX_XX_XY_F 0x20 +#define G_MWO_MATRIX_XZ_XW_F 0x24 +#define G_MWO_MATRIX_YX_YY_F 0x28 +#define G_MWO_MATRIX_YZ_YW_F 0x2c +#define G_MWO_MATRIX_ZX_ZY_F 0x30 +#define G_MWO_MATRIX_ZZ_ZW_F 0x34 +#define G_MWO_MATRIX_WX_WY_F 0x38 +#define G_MWO_MATRIX_WZ_WW_F 0x3c +#define G_MWO_POINT_RGBA 0x10 +#define G_MWO_POINT_ST 0x14 +#define G_MWO_POINT_XYSCREEN 0x18 +#define G_MWO_POINT_ZSCREEN 0x1c + +/* + * Light structure. + * + * Note: only directional (infinite) lights are currently supported. + * + * Note: the weird order is for the DMEM alignment benefit of + * the microcode. + * + */ + +typedef struct { + unsigned char col[3]; /* diffuse light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of diffuse light value (rgba) */ + char pad2; + signed char dir[3]; /* direction of light (normalized) */ + char pad3; +} Light_t; + +typedef struct { + unsigned char col[3]; /* ambient light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of ambient light value (rgba) */ + char pad2; +} Ambient_t; + +typedef struct { + int x1,y1,x2,y2; /* texture offsets for highlight 1/2 */ +} Hilite_t; + +typedef union { + Light_t l; + long long int force_structure_alignment[2]; +} Light; + +typedef union { + Ambient_t l; + long long int force_structure_alignment[1]; +} Ambient; + +typedef struct { + Ambient a; + Light l[7]; +} Lightsn; + +typedef struct { + Ambient a; + Light l[1]; +} Lights0; + +typedef struct { + Ambient a; + Light l[1]; +} Lights1; + +typedef struct { + Ambient a; + Light l[2]; +} Lights2; + +typedef struct { + Ambient a; + Light l[3]; +} Lights3; + +typedef struct { + Ambient a; + Light l[4]; +} Lights4; + +typedef struct { + Ambient a; + Light l[5]; +} Lights5; + +typedef struct { + Ambient a; + Light l[6]; +} Lights6; + +typedef struct { + Ambient a; + Light l[7]; +} Lights7; + +typedef struct { + Light l[2]; +} LookAt; + +typedef union { + Hilite_t h; + long int force_structure_alignment[4]; +} Hilite; + +#define gdSPDefLights0(ar,ag,ab) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ { 0, 0, 0},0,{ 0, 0, 0},0,{ 0, 0, 0},0}}} } +#define gdSPDefLights1(ar,ag,ab,r1,g1,b1,x1,y1,z1) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}} } +#define gdSPDefLights2(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}} } +#define gdSPDefLights3(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}} } +#define gdSPDefLights4(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}} } +#define gdSPDefLights5(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ + {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}} } + + +#define gdSPDefLights6(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ + {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \ + {{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}} } + + +#define gdSPDefLights7(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6,r7,g7,b7,x7,y7,z7) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ + {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \ + {{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}, \ + {{ {r7,g7,b7},0,{r7,g7,b7},0,{x7,y7,z7},0}}} } + + +#define gdSPDefLookAt(rightx,righty,rightz,upx,upy,upz) \ + { {{ {{0,0,0},0,{0,0,0},0,{rightx,righty,rightz},0}}, \ + { {{0,0x80,0},0,{0,0x80,0},0,{upx,upy,upz},0}}} } + +/* + * Graphics DMA Packet + */ +typedef struct { + int cmd:8; + unsigned int par:8; + unsigned int len:16; + unsigned int addr; +} Gdma; + +/* + * Graphics Immediate Mode Packet types + */ +typedef struct { + int cmd:8; + int pad:24; + Tri tri; +} Gtri; + +typedef struct { + int cmd:8; + int pad1:24; + int pad2:24; + unsigned char param:8; +} Gpopmtx; + +/* + * typedef struct { + * int cmd:8; + * int pad0:24; + * int pad1:4; + * int number:4; + * int base:24; + * } Gsegment; + */ +typedef struct { + int cmd:8; + int pad0:8; + int mw_index:8; + int number:8; + int pad1:8; + int base:24; +} Gsegment; + +typedef struct { + int cmd:8; + int pad0:8; + int sft:8; + int len:8; + unsigned int data:32; +} GsetothermodeL; + +typedef struct { + int cmd:8; + int pad0:8; + int sft:8; + int len:8; + unsigned int data:32; +} GsetothermodeH; + +typedef struct { + unsigned char cmd; + unsigned char lodscale; + unsigned char tile; + unsigned char on; + unsigned short s; + unsigned short t; +} Gtexture; + +typedef struct { + int cmd:8; + int pad:24; + Tri line; +} Gline3D; + +typedef struct { + int cmd:8; + int pad1:24; + short int pad2; + short int scale; +} Gperspnorm; + + +/* + * RDP Packet types + */ +typedef struct { + int cmd:8; + unsigned int fmt:3; + unsigned int siz:2; + unsigned int pad:7; + unsigned int wd:12; /* really only 10 bits, extra */ + unsigned int dram; /* to account for 1024 */ +} Gsetimg; + +typedef struct { + int cmd:8; + unsigned int muxs0:24; + unsigned int muxs1:32; +} Gsetcombine; + +typedef struct { + int cmd:8; + unsigned char pad; + unsigned char prim_min_level; + unsigned char prim_level; + unsigned long color; +} Gsetcolor; + +typedef struct { + int cmd:8; + int x0:10; + int x0frac:2; + int y0:10; + int y0frac:2; + unsigned int pad:8; + int x1:10; + int x1frac:2; + int y1:10; + int y1frac:2; +} Gfillrect; + +typedef struct { + int cmd:8; + unsigned int fmt:3; + unsigned int siz:2; + unsigned int pad0:1; + unsigned int line:9; + unsigned int tmem:9; + unsigned int pad1:5; + unsigned int tile:3; + unsigned int palette:4; + unsigned int ct:1; + unsigned int mt:1; + unsigned int maskt:4; + unsigned int shiftt:4; + unsigned int cs:1; + unsigned int ms:1; + unsigned int masks:4; + unsigned int shifts:4; +} Gsettile; + +typedef struct { + int cmd:8; + unsigned int sl:12; + unsigned int tl:12; + int pad:5; + unsigned int tile:3; + unsigned int sh:12; + unsigned int th:12; +} Gloadtile; + +typedef Gloadtile Gloadblock; + +typedef Gloadtile Gsettilesize; + +typedef Gloadtile Gloadtlut; + +typedef struct { + unsigned int cmd:8; /* command */ + unsigned int xl:12; /* X coordinate of upper left */ + unsigned int yl:12; /* Y coordinate of upper left */ + unsigned int pad1:5; /* Padding */ + unsigned int tile:3; /* Tile descriptor index */ + unsigned int xh:12; /* X coordinate of lower right */ + unsigned int yh:12; /* Y coordinate of lower right */ + unsigned int s:16; /* S texture coord at top left */ + unsigned int t:16; /* T texture coord at top left */ + unsigned int dsdx:16;/* Change in S per change in X */ + unsigned int dtdy:16;/* Change in T per change in Y */ +} Gtexrect; + +#define MakeTexRect(xh,yh,flip,tile,xl,yl,s,t,dsdx,dtdy) \ + G_TEXRECT, xh, yh, 0, flip, 0, tile, xl, yl, s, t, dsdx, dtdy + +/* + * Textured rectangles are 128 bits not 64 bits + */ +typedef struct { + unsigned long w0; + unsigned long w1; + unsigned long w2; + unsigned long w3; +} TexRect; + +/* + * Generic Gfx Packet + */ +typedef struct { + unsigned int w0; + unsigned int w1; +} Gwords; + +/* + * This union is the fundamental type of the display list. + * It is, by law, exactly 64 bits in size. + */ +typedef union { + Gwords words; + Gdma dma; + Gtri tri; + Gline3D line; + Gpopmtx popmtx; + Gsegment segment; + GsetothermodeH setothermodeH; + GsetothermodeL setothermodeL; + Gtexture texture; + Gperspnorm perspnorm; + Gsetimg setimg; + Gsetcombine setcombine; + Gsetcolor setcolor; + Gfillrect fillrect; /* use for setscissor also */ + Gsettile settile; + Gloadtile loadtile; /* use for loadblock also, th is dxt */ + Gsettilesize settilesize; + Gloadtlut loadtlut; + long long int force_structure_alignment; +} Gfx; + +/* + * Macros to assemble the graphics display list + */ + +/* + * DMA macros + */ +#define gDma0p(pkt, c, s, l) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24); \ + _g->words.w1 = (unsigned int)(s); \ +} + +#define gsDma0p(c, s, l) \ +{{ \ + _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24), (unsigned int)(s) \ +}} + +#define gDma1p(pkt, c, s, l, p) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ + _SHIFTL((l), 0, 16)); \ + _g->words.w1 = (unsigned int)(s); \ +} + +#define gsDma1p(c, s, l, p) \ +{{ \ + (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ + _SHIFTL((l), 0, 16)), \ + (unsigned int)(s) \ +}} + +#define gDma2p(pkt, c, adrs, len, idx, ofs) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ + _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)); \ + _g->words.w1 = (unsigned int)(adrs); \ +} +#define gsDma2p(c, adrs, len, idx, ofs) \ +{{ \ + (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ + _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)), \ + (unsigned int)(adrs) \ +}} + +#define gSPNoOp(pkt) gDma0p(pkt, G_SPNOOP, 0, 0) +#define gsSPNoOp() gsDma0p(G_SPNOOP, 0, 0) + +#ifdef F3DEX_GBI_2 +# define gSPMatrix(pkt, m, p) \ + gDma2p((pkt),G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) +# define gsSPMatrix(m, p) \ + gsDma2p( G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) +#else /* F3DEX_GBI_2 */ +# define gSPMatrix(pkt, m, p) gDma1p(pkt, G_MTX, m, sizeof(Mtx), p) +# define gsSPMatrix(m, p) gsDma1p(G_MTX, m, sizeof(Mtx), p) +#endif /* F3DEX_GBI_2 */ + +#if defined(F3DEX_GBI_2) +/* + * F3DEX_GBI_2: G_VTX GBI format was changed. + * + * +--------+----+---+---+----+------+-+ + * G_VTX | cmd:8 |0000| n:8 |0000|v0+n:7|0| + * +-+---+--+----+---+---+----+------+-+ + * | |seg| address | + * +-+---+-----------------------------+ + */ +# define gSPVertex(pkt, v, n, v0) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = \ + _SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7); \ + _g->words.w1 = (unsigned int)(v); \ +} +# define gsSPVertex(v, n, v0) \ +{{ \ + (_SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7)), \ + (unsigned int)(v) \ +}} +#elif (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +/* + * F3DEX_GBI: G_VTX GBI format was changed to support 64 vertice. + * + * +--------+--------+------+----------+ + * G_VTX | cmd:8 | v0:8 | n:6 |length:10 | + * +-+---+--+--------+------+----------+ + * | |seg| address | + * +-+---+-----------------------------+ + */ +# define gSPVertex(pkt, v, n, v0) \ + gDma1p((pkt),G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) +# define gsSPVertex(v, n, v0) \ + gsDma1p(G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) +#else +# define gSPVertex(pkt, v, n, v0) \ + gDma1p(pkt, G_VTX, v, sizeof(Vtx)*(n),((n)-1)<<4|(v0)) +# define gsSPVertex(v, n, v0) \ + gsDma1p(G_VTX, v, sizeof(Vtx)*(n), ((n)-1)<<4|(v0)) +#endif + + +#ifdef F3DEX_GBI_2 +# define gSPViewport(pkt, v) \ + gDma2p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) +# define gsSPViewport(v) \ + gsDma2p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) +#else /* F3DEX_GBI_2 */ +# define gSPViewport(pkt,v) \ + gDma1p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) +# define gsSPViewport(v) \ + gsDma1p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) +#endif /* F3DEX_GBI_2 */ + +#define gSPDisplayList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_PUSH) +#define gsSPDisplayList( dl) gsDma1p( G_DL,dl,0,G_DL_PUSH) + +#define gSPBranchList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_NOPUSH) +#define gsSPBranchList( dl) gsDma1p( G_DL,dl,0,G_DL_NOPUSH) + +#define gSPSprite2DBase(pkt, s) gDma1p(pkt, G_SPRITE2D_BASE, s, sizeof(uSprite), 0) +#define gsSPSprite2DBase(s) gsDma1p(G_SPRITE2D_BASE, s, sizeof(uSprite), 0) + +/* + * RSP short command (no DMA required) macros + */ +#define gImmp0(pkt, c) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ +} + +#define gsImmp0(c) \ +{{ \ + _SHIFTL((c), 24, 8) \ +}} + +#define gImmp1(pkt, c, p0) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = (unsigned int)(p0); \ +} + +#define gsImmp1(c, p0) \ +{{ \ + _SHIFTL((c), 24, 8), (unsigned int)(p0) \ +}} + +#define gImmp2(pkt, c, p0, p1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8); \ +} + +#define gsImmp2(c, p0, p1) \ +{{ \ + _SHIFTL((c), 24, 8), _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8)\ +}} + +#define gImmp3(pkt, c, p0, p1, p2) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = (_SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8) | \ + _SHIFTL((p2), 0, 8)); \ +} + +#define gsImmp3(c, p0, p1, p2) \ +{{ \ + _SHIFTL((c), 24, 8), (_SHIFTL((p0), 16, 16) | \ + _SHIFTL((p1), 8, 8) | _SHIFTL((p2), 0, 8))\ +}} + +#define gImmp21(pkt, c, p0, p1, dat) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | \ + _SHIFTL((p1), 0, 8)); \ + _g->words.w1 = (unsigned int) (dat); \ +} + +#define gsImmp21(c, p0, p1, dat) \ +{{ \ + _SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | _SHIFTL((p1), 0, 8),\ + (unsigned int) (dat) \ +}} + +#ifdef F3DEX_GBI_2 +#define gMoveWd(pkt, index, offset, data) \ + gDma1p((pkt), G_MOVEWORD, data, offset, index) +#define gsMoveWd( index, offset, data) \ + gsDma1p( G_MOVEWORD, data, offset, index) +#else /* F3DEX_GBI_2 */ +#define gMoveWd(pkt, index, offset, data) \ + gImmp21((pkt), G_MOVEWORD, offset, index, data) +#define gsMoveWd( index, offset, data) \ + gsImmp21( G_MOVEWORD, offset, index, data) +#endif /* F3DEX_GBI_2 */ + +/* Sprite immediate macros, there is also a sprite dma macro above */ + +#define gSPSprite2DScaleFlip(pkt, sx, sy, fx, fy) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ + _SHIFTL((fx), 8, 8) | \ + _SHIFTL((fy), 0, 8)); \ + _g->words.w1 = (_SHIFTL((sx), 16, 16) | \ + _SHIFTL((sy), 0, 16)); \ +} + +#define gsSPSprite2DScaleFlip(sx, sy, fx, fy) \ +{{ \ + (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ + _SHIFTL((fx), 8, 8) | \ + _SHIFTL((fy), 0, 8)), \ + (_SHIFTL((sx), 16, 16) | \ + _SHIFTL((sy), 0, 16)) \ +}} + +#define gSPSprite2DDraw(pkt, px, py) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)); \ + _g->words.w1 = (_SHIFTL((px), 16, 16) | \ + _SHIFTL((py), 0, 16)); \ +} + +#define gsSPSprite2DDraw(px, py) \ +{{ \ + (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)), \ + (_SHIFTL((px), 16, 16) | \ + _SHIFTL((py), 0, 16)) \ +}} + + +/* + * Note: the SP1Triangle() and line macros multiply the vertex indices + * by 10, this is an optimization for the microcode. + */ +#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) +# define __gsSP1Triangle_w1(v0, v1, v2) \ + (_SHIFTL((v0)*2,16,8)|_SHIFTL((v1)*2,8,8)|_SHIFTL((v2)*2,0,8)) +# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v0): \ + __gsSP1Triangle_w1(v2, v0, v1)) +# define __gsSPLine3D_w1(v0, v1, wd) \ + (_SHIFTL((v0)*2,16,8)|_SHIFT((v1)*2,8,8)|_SHIFT((wd),0,8)) +# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ + (((flag) == 0) ? __gsSPLine3D_w1(v0, v1, wd): \ + __gsSPLine3D_w1(v1, v0, wd)) +# define __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v3): \ + ((flag) == 2) ? __gsSP1Triangle_w1(v2, v3, v0): \ + __gsSP1Triangle_w1(v3, v0, v1)) +# define __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v2, v3): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v3, v0): \ + ((flag) == 2) ? __gsSP1Triangle_w1(v2, v0, v1): \ + __gsSP1Triangle_w1(v3, v1, v2)) +#else +# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ + (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ + _SHIFTL((v1)*10, 8,8)|_SHIFTL((v2)*10, 0,8)) +# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ + (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ + _SHIFTL((v1)*10, 8,8)|_SHIFTL((wd), 0,8)) +#endif + +#ifdef F3DEX_GBI_2 +/*** + *** 1 Triangle + ***/ +#define gSP1Triangle(pkt, v0, v1, v2, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_TRI1, 24, 8)| \ + __gsSP1Triangle_w1f(v0, v1, v2, flag); \ + _g->words.w1 = 0; \ +} +#define gsSP1Triangle(v0, v1, v2, flag) \ +{{ \ + _SHIFTL(G_TRI1, 24, 8)|__gsSP1Triangle_w1f(v0, v1, v2, flag), \ + 0 \ +}} + +/*** + *** Line + ***/ +#define gSPLine3D(pkt, v0, v1, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ + __gsSPLine3D_w1f(v0, v1, 0, flag); \ + _g->words.w1 = 0; \ +} +#define gsSPLine3D(v0, v1, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, 0, flag), \ + 0 \ +}} + +/*** + *** LineW + ***/ +/* these macros are the same as SPLine3D, except they have an + * additional parameter for width. The width is added to the "minimum" + * thickness, which is 1.5 pixels. The units for width are in + * half-pixel units, so a width of 1 translates to (.5 + 1.5) or + * a 2.0 pixels wide line. + */ +#define gSPLineW3D(pkt, v0, v1, wd, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ + __gsSPLine3D_w1f(v0, v1, wd, flag); \ + _g->words.w1 = 0; \ +} +#define gsSPLineW3D(v0, v1, wd, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, wd, flag), \ + 0 \ +}} + +/*** + *** 1 Quadrangle + ***/ +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_QUAD, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ +} + +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ +{{ \ + (_SHIFTL(G_QUAD, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ +}} +#else /* F3DEX_GBI_2 */ + +/*** + *** 1 Triangle + ***/ +#define gSP1Triangle(pkt, v0, v1, v2, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_TRI1, 24, 8); \ + _g->words.w1 = __gsSP1Triangle_w1f(v0, v1, v2, flag); \ +} +#define gsSP1Triangle(v0, v1, v2, flag) \ +{{ \ + _SHIFTL(G_TRI1, 24, 8), \ + __gsSP1Triangle_w1f(v0, v1, v2, flag) \ +}} + +/*** + *** Line + ***/ +#define gSPLine3D(pkt, v0, v1, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ + _g->words.w1 = __gsSPLine3D_w1f(v0, v1, 0, flag); \ +} +#define gsSPLine3D(v0, v1, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8), \ + __gsSPLine3D_w1f(v0, v1, 0, flag) \ +}} + +/*** + *** LineW + ***/ +/* these macros are the same as SPLine3D, except they have an + * additional parameter for width. The width is added to the "minimum" + * thickness, which is 1.5 pixels. The units for width are in + * half-pixel units, so a width of 1 translates to (.5 + 1.5) or + * a 2.0 pixels wide line. + */ +#define gSPLineW3D(pkt, v0, v1, wd, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ + _g->words.w1 = __gsSPLine3D_w1f(v0, v1, wd, flag); \ +} +#define gsSPLineW3D(v0, v1, wd, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8), \ + __gsSPLine3D_w1f(v0, v1, wd, flag) \ +}} + +/*** + *** 1 Quadrangle + ***/ +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ +} + +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ +{{ \ + (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ +}} +#endif /* F3DEX_GBI_2 */ + +#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) +/*** + *** 2 Triangles + ***/ +#define gSP2Triangles(pkt, v00, v01, v02, flag0, v10, v11, v12, flag1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Triangle_w1f(v00, v01, v02, flag0)); \ + _g->words.w1 = __gsSP1Triangle_w1f(v10, v11, v12, flag1); \ +} + +#define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ +{{ \ + (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Triangle_w1f(v00, v01, v02, flag0)), \ + __gsSP1Triangle_w1f(v10, v11, v12, flag1) \ +}} + +#endif /* F3DEX_GBI/F3DLP_GBI */ + +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +#define gSPCullDisplayList(pkt,vstart,vend) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ + _SHIFTL((vstart)*2, 0, 16); \ + _g->words.w1 = _SHIFTL((vend)*2, 0, 16); \ +} + +#define gsSPCullDisplayList(vstart,vend) \ +{{ \ + _SHIFTL(G_CULLDL, 24, 8) | _SHIFTL((vstart)*2, 0, 16), \ + _SHIFTL((vend)*2, 0, 16) \ +}} + +#else +#define gSPCullDisplayList(pkt,vstart,vend) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ + ((0x0f & (vstart))*40); \ + _g->words.w1 = (unsigned int)((0x0f & ((vend)+1))*40); \ +} + +#define gsSPCullDisplayList(vstart,vend) \ +{{ \ + _SHIFTL(G_CULLDL, 24, 8) | ((0x0f & (vstart))*40), \ + ((0x0f & ((vend)+1))*40) \ +}} +#endif + +#define gSPSegment(pkt, segment, base) \ + gMoveWd(pkt, G_MW_SEGMENT, (segment)*4, base) +#define gsSPSegment(segment, base) \ + gsMoveWd( G_MW_SEGMENT, (segment)*4, base) + +/* + * Clipping Macros + */ +#define FR_NEG_FRUSTRATIO_1 0x00000001 +#define FR_POS_FRUSTRATIO_1 0x0000ffff +#define FR_NEG_FRUSTRATIO_2 0x00000002 +#define FR_POS_FRUSTRATIO_2 0x0000fffe +#define FR_NEG_FRUSTRATIO_3 0x00000003 +#define FR_POS_FRUSTRATIO_3 0x0000fffd +#define FR_NEG_FRUSTRATIO_4 0x00000004 +#define FR_POS_FRUSTRATIO_4 0x0000fffc +#define FR_NEG_FRUSTRATIO_5 0x00000005 +#define FR_POS_FRUSTRATIO_5 0x0000fffb +#define FR_NEG_FRUSTRATIO_6 0x00000006 +#define FR_POS_FRUSTRATIO_6 0x0000fffa +/* + * r should be one of: FRUSTRATIO_1, FRUSTRATIO_2, FRUSTRATIO_3, ... FRUSTRATIO_6 + */ +#define gSPClipRatio(pkt, r) \ +{ \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r); \ +} + +#define gsSPClipRatio(r) \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r) + +/* + * Insert values into Matrix + * + * where = element of matrix (byte offset) + * num = new element (32 bit value replacing 2 int or 2 frac matrix + * componants + */ +#ifdef F3DEX_GBI_2 +#define gSPInsertMatrix(pkt, where, num) \ + ERROR!! gSPInsertMatrix is no longer supported. +#define gsSPInsertMatrix(where, num) \ + ERROR!! gsSPInsertMatrix is no longer supported. +#else +#define gSPInsertMatrix(pkt, where, num) \ + gMoveWd(pkt, G_MW_MATRIX, where, num) +#define gsSPInsertMatrix(where, num) \ + gsMoveWd(G_MW_MATRIX, where, num) +#endif + +/* + * Load new matrix directly + * + * mptr = pointer to matrix + */ +#ifdef F3DEX_GBI_2 +#define gSPForceMatrix(pkt, mptr) \ +{ gDma2p((pkt),G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0); \ + gMoveWd((pkt), G_MW_FORCEMTX,0,0x00010000); \ +} +#define gsSPForceMatrix(mptr) \ + gsDma2p(G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0), \ + gsMoveWd(G_MW_FORCEMTX,0,0x00010000) + +#else /* F3DEX_GBI_2 */ +#define gSPForceMatrix(pkt, mptr) \ +{ \ + gDma1p(pkt, G_MOVEMEM, mptr, 16, G_MV_MATRIX_1); \ + gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2); \ + gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3); \ + gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4); \ +} +#define gsSPForceMatrix(mptr) \ + gsDma1p( G_MOVEMEM, mptr, 16, G_MV_MATRIX_1), \ + gsDma1p( G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2), \ + gsDma1p( G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3), \ + gsDma1p( G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4) +#endif /* F3DEX_GBI_2 */ + +/* + * Insert values into Points + * + * point = point number 0-15 + * where = which element of point to modify (byte offset into point) + * num = new value (32 bit) + */ +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +# define gSPModifyVertex(pkt, vtx, where, val) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(G_MODIFYVTX,24,8)| \ + _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16)); \ + _g->words.w1 = (unsigned int)(val); \ +} +# define gsSPModifyVertex(vtx, where, val) \ +{{ \ + _SHIFTL(G_MODIFYVTX,24,8)| \ + _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16), \ + (unsigned int)(val) \ +}} +#else +# define gSPModifyVertex(pkt, vtx, where, val) \ + gMoveWd(pkt, G_MW_POINTS, (vtx)*40+(where), val) +# define gsSPModifyVertex(vtx, where, val) \ + gsMoveWd(G_MW_POINTS, (vtx)*40+(where), val) +#endif + +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +/* + * gSPBranchLessZ Branch DL if (vtx.z) less than or equal (zval). + * + * dl = DL branch to + * vtx = Vertex + * zval = Screen depth + * near = Near plane + * far = Far plane + * flag = G_BZ_PERSP or G_BZ_ORTHO + */ + +#define G_BZ_PERSP 0 +#define G_BZ_ORTHO 1 + +#define G_DEPTOZSrg(zval, near, far, flag, zmin, zmax) \ +(((unsigned int)FTOFIX32(((flag) == G_BZ_PERSP ? \ + (1.0f-(float)(near)/(float)(zval)) / \ + (1.0f-(float)(near)/(float)(far )) : \ + ((float)(zval) - (float)(near)) / \ + ((float)(far ) - (float)(near))))) * \ + (((int)((zmax) - (zmin)))&~1) + (int)FTOFIX32(zmin)) + +#define G_DEPTOZS(zval, near, far, flag) \ + G_DEPTOZSrg(zval, near, far, flag, 0, G_MAXZ) + +#define gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, zmin, zmax) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ + _g->words.w1 = (unsigned int)(dl); \ + _g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ + _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ + _g->words.w1 = G_DEPTOZSrg(zval, near, far, flag, zmin, zmax); \ +} + +#define gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, zmin, zmax) \ +{{ _SHIFTL(G_RDPHALF_1,24,8), \ + (unsigned int)(dl), }}, \ +{{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ + G_DEPTOZSrg(zval, near, far, flag, zmin, zmax), }} + +#define gSPBranchLessZ(pkt, dl, vtx, zval, near, far, flag) \ + gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, 0, G_MAXZ) +#define gsSPBranchLessZ(dl, vtx, zval, near, far, flag) \ + gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, 0, G_MAXZ) + +/* + * gSPBranchLessZraw Branch DL if (vtx.z) less than or equal (raw zval). + * + * dl = DL branch to + * vtx = Vertex + * zval = Raw value of screen depth + */ +#define gSPBranchLessZraw(pkt, dl, vtx, zval) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ + _g->words.w1 = (unsigned int)(dl); \ + _g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ + _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ + _g->words.w1 = (unsigned int)(zval); \ +} + +#define gsSPBranchLessZraw(dl, vtx, zval) \ +{{ _SHIFTL(G_RDPHALF_1,24,8), \ + (unsigned int)(dl), }}, \ +{{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ + (unsigned int)(zval), }} + +/* + * gSPLoadUcode RSP loads specified ucode. + * + * uc_start = ucode text section start + * uc_dstart = ucode data section start + */ +#define gSPLoadUcodeEx(pkt, uc_start, uc_dstart, uc_dsize) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ + _g->words.w1 = (unsigned int)(uc_dstart); \ + _g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(G_LOAD_UCODE,24,8)| \ + _SHIFTL((int)(uc_dsize)-1,0,16)); \ + _g->words.w1 = (unsigned int)(uc_start); \ +} + +#define gsSPLoadUcodeEx(uc_start, uc_dstart, uc_dsize) \ +{{ _SHIFTL(G_RDPHALF_1,24,8), \ + (unsigned int)(uc_dstart), }}, \ +{{ _SHIFTL(G_LOAD_UCODE,24,8)| \ + _SHIFTL((int)(uc_dsize)-1,0,16), \ + (unsigned int)(uc_start), }} + +#define gSPLoadUcode(pkt, uc_start, uc_dstart) \ + gSPLoadUcodeEx((pkt), (uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) +#define gsSPLoadUcode(uc_start, uc_dstart) \ + gsSPLoadUcodeEx((uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) + +#define gSPLoadUcodeL(pkt, ucode) \ + gSPLoadUcode((pkt), OS_K0_TO_PHYSICAL(&##ucode##TextStart), \ + OS_K0_TO_PHYSICAL(&##ucode##DataStart)) +#define gsSPLoadUcodeL(ucode) \ + gsSPLoadUcode(OS_K0_TO_PHYSICAL(&##ucode##TextStart), \ + OS_K0_TO_PHYSICAL(&##ucode##DataStart)) +#endif + +#ifdef F3DEX_GBI_2 +/* + * gSPDma_io DMA to/from DMEM/IMEM for DEBUG. + */ +#define gSPDma_io(pkt, flag, dmem, dram, size) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ + _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12); \ + _g->words.w1 = (unsigned int)(dram); \ +} + +#define gsSPDma_io(flag, dmem, dram, size) \ +{{ \ + _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ + _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12), \ + (unsigned int)(dram) \ +}} + +#define gSPDmaRead(pkt,dmem,dram,size) gSPDma_io((pkt),0,(dmem),(dram),(size)) +#define gsSPDmaRead(dmem,dram,size) gsSPDma_io(0,(dmem),(dram),(size)) +#define gSPDmaWrite(pkt,dmem,dram,size) gSPDma_io((pkt),1,(dmem),(dram),(size)) +#define gsSPDmaWrite(dmem,dram,size) gsSPDma_io(1,(dmem),(dram),(size)) +#endif + +/* + * Lighting Macros + */ +#ifdef F3DEX_GBI_2 +# define NUML(n) ((n)*24) +#else +# define NUML(n) (((n)+1)*32 + 0x80000000) +#endif +#define NUMLIGHTS_0 1 +#define NUMLIGHTS_1 1 +#define NUMLIGHTS_2 2 +#define NUMLIGHTS_3 3 +#define NUMLIGHTS_4 4 +#define NUMLIGHTS_5 5 +#define NUMLIGHTS_6 6 +#define NUMLIGHTS_7 7 +/* + * n should be one of: NUMLIGHTS_0, NUMLIGHTS_1, ..., NUMLIGHTS_7 + * NOTE: in addition to the number of directional lights specified, + * there is always 1 ambient light + */ +#define gSPNumLights(pkt, n) \ + gMoveWd(pkt, G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) +#define gsSPNumLights(n) \ + gsMoveWd( G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) + +#define LIGHT_1 1 +#define LIGHT_2 2 +#define LIGHT_3 3 +#define LIGHT_4 4 +#define LIGHT_5 5 +#define LIGHT_6 6 +#define LIGHT_7 7 +#define LIGHT_8 8 +/* + * l should point to a Light struct + * n should be one of: LIGHT_1, LIGHT_2, ..., LIGHT_8 + * NOTE: the highest numbered light is always the ambient light (eg if there are + * 3 directional lights defined: gsSPNumLights(NUMLIGHTS_3), then lights + * LIGHT_1 through LIGHT_3 will be the directional lights and light + * LIGHT_4 will be the ambient light. + */ +#ifdef F3DEX_GBI_2 +# define gSPLight(pkt, l, n) \ + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) +# define gsSPLight(l, n) \ + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) +#else /* F3DEX_GBI_2 */ +# define gSPLight(pkt, l, n) \ + gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) +# define gsSPLight(l, n) \ + gsDma1p( G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) +#endif /* F3DEX_GBI_2 */ + +/* + * gSPLightColor changes color of light without recalculating light direction + * col is a 32 bit word with r,g,b,a (alpha is ignored) + * n should be one of LIGHT_1, LIGHT_2, ..., LIGHT_8 + */ +#define gSPLightColor(pkt, n, col) \ +{ \ + gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_a##n, col); \ + gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_b##n, col); \ +} +#define gsSPLightColor(n, col) \ + gsMoveWd(G_MW_LIGHTCOL, G_MWO_a##n, col), \ + gsMoveWd(G_MW_LIGHTCOL, G_MWO_b##n, col) + +/* These macros use a structure "name" which is init'd with the gdSPDefLights macros*/ + +#define gSPSetLights0(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_0); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.a,2); \ +} +#define gsSPSetLights0(name) \ + gsSPNumLights(NUMLIGHTS_0), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.a,2) + +#define gSPSetLights1(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_1); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.a,2); \ +} +#define gsSPSetLights1(name) \ + gsSPNumLights(NUMLIGHTS_1), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.a,2) + +#define gSPSetLights2(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_2); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.a,3); \ +} +#define gsSPSetLights2(name) \ + gsSPNumLights(NUMLIGHTS_2), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.a,3) + +#define gSPSetLights3(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_3); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.a,4); \ +} +#define gsSPSetLights3(name) \ + gsSPNumLights(NUMLIGHTS_3), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.a,4) + +#define gSPSetLights4(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_4); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.a,5); \ +} +#define gsSPSetLights4(name) \ + gsSPNumLights(NUMLIGHTS_4), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.a,5) + +#define gSPSetLights5(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_5); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.l[4],5); \ + gSPLight(pkt,&name.a,6); \ +} + +#define gsSPSetLights5(name) \ + gsSPNumLights(NUMLIGHTS_5), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.l[4],5), \ + gsSPLight(&name.a,6) + +#define gSPSetLights6(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_6); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.l[4],5); \ + gSPLight(pkt,&name.l[5],6); \ + gSPLight(pkt,&name.a,7); \ +} + +#define gsSPSetLights6(name) \ + gsSPNumLights(NUMLIGHTS_6), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.l[4],5), \ + gsSPLight(&name.l[5],6), \ + gsSPLight(&name.a,7) + +#define gSPSetLights7(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_7); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.l[4],5); \ + gSPLight(pkt,&name.l[5],6); \ + gSPLight(pkt,&name.l[6],7); \ + gSPLight(pkt,&name.a,8); \ +} + +#define gsSPSetLights7(name) \ + gsSPNumLights(NUMLIGHTS_7), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.l[4],5), \ + gsSPLight(&name.l[5],6), \ + gsSPLight(&name.l[6],7), \ + gsSPLight(&name.a,8) + +/* + * Reflection/Hiliting Macros + */ +#ifdef F3DEX_GBI_2 +# define gSPLookAtX(pkt, l) \ + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) +# define gsSPLookAtX(l) \ + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) +# define gSPLookAtY(pkt, l) \ + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) +# define gsSPLookAtY(l) \ + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) +#else /* F3DEX_GBI_2 */ +# define gSPLookAtX(pkt, l) \ + gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) +# define gsSPLookAtX(l) \ + gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) +# define gSPLookAtY(pkt, l) \ + gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) +# define gsSPLookAtY(l) \ + gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) +#endif /* F3DEX_GBI_2 */ + +#define gSPLookAt(pkt, la) \ +{ \ + gSPLookAtX(pkt,la) \ + gSPLookAtY(pkt,(char *)(la)+16) \ +} +#define gsSPLookAt(la) \ + gsSPLookAtX(la), \ + gsSPLookAtY((char *)(la)+16) + +#define gDPSetHilite1Tile(pkt, tile, hilite, width, height) \ + gDPSetTileSize(pkt, tile, (hilite)->h.x1 & 0xfff, (hilite)->h.y1 & 0xfff, \ + ((((width)-1)*4)+(hilite)->h.x1) & 0xfff, ((((height)-1)*4)+(hilite)->h.y1) & 0xfff) + +#define gDPSetHilite2Tile(pkt, tile, hilite, width, height) \ + gDPSetTileSize(pkt, tile, (hilite)->h.x2 & 0xfff, (hilite)->h.y2 & 0xfff, \ + ((((width)-1)*4)+(hilite)->h.x2) & 0xfff, ((((height)-1)*4)+(hilite)->h.y2) & 0xfff) + + +/* + * FOG macros + * fm = z multiplier + * fo = z offset + * FOG FORMULA: alpha(fog) = (eyespace z) * fm + fo CLAMPED 0 to 255 + * note: (eyespace z) ranges -1 to 1 + * + * Alternate method of setting fog: + * min, max: range 0 to 1000: 0=nearplane, 1000=farplane + * min is where fog begins (usually less than max and often 0) + * max is where fog is thickest (usually 1000) + * + */ +#define gSPFogFactor(pkt, fm, fo) \ + gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) + +#define gsSPFogFactor(fm, fo) \ + gsMoveWd(G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) + +#define gSPFogPosition(pkt, min, max) \ + gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL((128000/((max)-(min))),16,16) | \ + _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) + +#define gsSPFogPosition(min, max) \ + gsMoveWd(G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL((128000/((max)-(min))),16,16) | \ + _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) + +#ifdef F3DEX_GBI_2 +/* + * Macros to turn texture on/off + */ +# define gSPTexture(pkt, s, t, level, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ + _SHIFTL(BOWTIE_VAL,16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ + _SHIFTL((on),1,7)); \ + _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ +} +# define gsSPTexture(s, t, level, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL(BOWTIE_VAL,16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ + (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ +}} +/* + * Different version of SPTexture macro, has an additional parameter + * which is currently reserved in the microcode. + */ +# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ + _SHIFTL((xparam),16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ + _SHIFTL((on),1,7)); \ + _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ +} +# define gsSPTextureL(s, t, level, xparam, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL((xparam),16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ + (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ +}} +#else +/* + * Macros to turn texture on/off + */ +# define gSPTexture(pkt, s, t, level, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)|\ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ + _SHIFTL((on),0,8)); \ + _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ +} +# define gsSPTexture(s, t, level, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ + (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ +}} +/* + * Different version of SPTexture macro, has an additional parameter + * which is currently reserved in the microcode. + */ +# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ + _SHIFTL((on),0,8)); \ + _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ +} +# define gsSPTextureL(s, t, level, xparam, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ + (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ +}} +#endif + +#define gSPPerspNormalize(pkt, s) gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) +#define gsSPPerspNormalize(s) gsMoveWd( G_MW_PERSPNORM, 0, (s)) + +#ifdef F3DEX_GBI_2 +# define gSPPopMatrixN(pkt, n, num) gDma2p((pkt),G_POPMTX,(num)*64,64,2,0) +# define gsSPPopMatrixN(n, num) gsDma2p( G_POPMTX,(num)*64,64,2,0) +# define gSPPopMatrix(pkt, n) gSPPopMatrixN((pkt), (n), 1) +# define gsSPPopMatrix(n) gsSPPopMatrixN( (n), 1) +#else /* F3DEX_GBI_2 */ +# define gSPPopMatrix(pkt, n) gImmp1(pkt, G_POPMTX, n) +# define gsSPPopMatrix(n) gsImmp1( G_POPMTX, n) +#endif /* F3DEX_GBI_2 */ + +#define gSPEndDisplayList(pkt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_ENDDL, 24, 8); \ + _g->words.w1 = 0; \ +} + +#define gsSPEndDisplayList() \ +{{ \ + _SHIFTL(G_ENDDL, 24, 8), 0 \ +}} + +#ifdef F3DEX_GBI_2 +/* + * One gSPGeometryMode(pkt,c,s) GBI is equal to these two GBIs. + * + * gSPClearGeometryMode(pkt,c) + * gSPSetGeometryMode(pkt,s) + * + * gSPLoadGeometryMode(pkt, word) sets GeometryMode directly. + */ +#define gSPGeometryMode(pkt, c, s) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24);\ + _g->words.w1 = (u32)(s); \ +} + +#define gsSPGeometryMode(c, s) \ +{{ \ + (_SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24)),(u32)(s) \ +}} +#define gSPSetGeometryMode(pkt, word) gSPGeometryMode((pkt),0,(word)) +#define gsSPSetGeometryMode(word) gsSPGeometryMode(0,(word)) +#define gSPClearGeometryMode(pkt, word) gSPGeometryMode((pkt),(word),0) +#define gsSPClearGeometryMode(word) gsSPGeometryMode((word),0) +#define gSPLoadGeometryMode(pkt, word) gSPGeometryMode((pkt),-1,(word)) +#define gsSPLoadGeometryMode(word) gsSPGeometryMode(-1,(word)) + +#else /* F3DEX_GBI_2 */ +#define gSPSetGeometryMode(pkt, word) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETGEOMETRYMODE, 24, 8); \ + _g->words.w1 = (unsigned int)(word); \ +} + +#define gsSPSetGeometryMode(word) \ +{{ \ + _SHIFTL(G_SETGEOMETRYMODE, 24, 8), (unsigned int)(word) \ +}} + +#define gSPClearGeometryMode(pkt, word) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8); \ + _g->words.w1 = (unsigned int)(word); \ +} + +#define gsSPClearGeometryMode(word) \ +{{ \ + _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8), (unsigned int)(word) \ +}} +#endif /* F3DEX_GBI_2 */ + +#ifdef F3DEX_GBI_2 +#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)| \ + _SHIFTL((len)-1,0,8)); \ + _g->words.w1 = (unsigned int)(data); \ +} + +#define gsSPSetOtherMode(cmd, sft, len, data) \ +{{ \ + _SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)|_SHIFTL((len)-1,0,8), \ + (unsigned int)(data) \ +}} +#else +#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | \ + _SHIFTL(len, 0, 8)); \ + _g->words.w1 = (unsigned int)(data); \ +} + +#define gsSPSetOtherMode(cmd, sft, len, data) \ +{{ \ + _SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | _SHIFTL(len, 0, 8), \ + (unsigned int)(data) \ +}} +#endif + +/* + * RDP setothermode register commands - register shadowed in RSP + */ +#define gDPPipelineMode(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) +#define gsDPPipelineMode(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) + +#define gDPSetCycleType(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) +#define gsDPSetCycleType(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) + +#define gDPSetTexturePersp(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) +#define gsDPSetTexturePersp(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) + +#define gDPSetTextureDetail(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) +#define gsDPSetTextureDetail(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) + +#define gDPSetTextureLOD(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) +#define gsDPSetTextureLOD(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) + +#define gDPSetTextureLUT(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) +#define gsDPSetTextureLUT(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) + +#define gDPSetTextureFilter(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) +#define gsDPSetTextureFilter(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) + +#define gDPSetTextureConvert(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) +#define gsDPSetTextureConvert(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) + +#define gDPSetCombineKey(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) +#define gsDPSetCombineKey(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) + +#ifndef _HW_VERSION_1 +#define gDPSetColorDither(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) +#define gsDPSetColorDither(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) +#else +#define gDPSetColorDither(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) +#define gsDPSetColorDither(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) +#endif + +#ifndef _HW_VERSION_1 +#define gDPSetAlphaDither(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) +#define gsDPSetAlphaDither(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) +#endif + +/* 'blendmask' is not supported anymore. + * The bits are reserved for future use. + * Fri May 26 13:45:55 PDT 1995 + */ +#define gDPSetBlendMask(pkt, mask) gDPNoOp(pkt) +#define gsDPSetBlendMask(mask) gsDPNoOp() + +#define gDPSetAlphaCompare(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) +#define gsDPSetAlphaCompare(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) + +#define gDPSetDepthSource(pkt, src) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) +#define gsDPSetDepthSource(src) \ + gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) + +#define gDPSetRenderMode(pkt, c0, c1) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ + (c0) | (c1)) +#define gsDPSetRenderMode(c0, c1) \ + gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ + (c0) | (c1)) + +#define gSetImage(pkt, cmd, fmt, siz, width, i) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ + _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12); \ + _g->words.w1 = (unsigned int)(i); \ +} + +#define gsSetImage(cmd, fmt, siz, width, i) \ +{{ \ + _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ + _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12), \ + (unsigned int)(i) \ +}} + +#define gDPSetColorImage(pkt, f, s, w, i) gSetImage(pkt, G_SETCIMG, f, s, w, i) +#define gsDPSetColorImage(f, s, w, i) gsSetImage(G_SETCIMG, f, s, w, i) + + +/* use these for new code */ +#define gDPSetDepthImage(pkt, i) gSetImage(pkt, G_SETZIMG, 0, 0, 1, i) +#define gsDPSetDepthImage(i) gsSetImage(G_SETZIMG, 0, 0, 1, i) +/* kept for compatibility */ +#define gDPSetMaskImage(pkt, i) gDPSetDepthImage(pkt, i) +#define gsDPSetMaskImage(i) gsDPSetDepthImage(i) + +#define gDPSetTextureImage(pkt, f, s, w, i) gSetImage(pkt, G_SETTIMG, f, s, w, i) +#define gsDPSetTextureImage(f, s, w, i) gsSetImage(G_SETTIMG, f, s, w, i) + +/* + * RDP macros + */ + +#define gDPSetCombine(pkt, muxs0, muxs1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24);\ + _g->words.w1 = (unsigned int)(muxs1); \ +} + +#define gsDPSetCombine(muxs0, muxs1) \ +{{ \ + _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24), \ + (unsigned int)(muxs1) \ +}} + +#define GCCc0w0(saRGB0, mRGB0, saA0, mA0) \ + (_SHIFTL((saRGB0), 20, 4) | _SHIFTL((mRGB0), 15, 5) | \ + _SHIFTL((saA0), 12, 3) | _SHIFTL((mA0), 9, 3)) + +#define GCCc1w0(saRGB1, mRGB1) \ + (_SHIFTL((saRGB1), 5, 4) | _SHIFTL((mRGB1), 0, 5)) + +#define GCCc0w1(sbRGB0, aRGB0, sbA0, aA0) \ + (_SHIFTL((sbRGB0), 28, 4) | _SHIFTL((aRGB0), 15, 3) | \ + _SHIFTL((sbA0), 12, 3) | _SHIFTL((aA0), 9, 3)) + +#define GCCc1w1(sbRGB1, saA1, mA1, aRGB1, sbA1, aA1) \ + (_SHIFTL((sbRGB1), 24, 4) | _SHIFTL((saA1), 21, 3) | \ + _SHIFTL((mA1), 18, 3) | _SHIFTL((aRGB1), 6, 3) | \ + _SHIFTL((sbA1), 3, 3) | _SHIFTL((aA1), 0, 3)) + +#define gDPSetCombineLERP(pkt, a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ + a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | \ + _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ + G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ + GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), \ + 0, 24); \ + _g->words.w1 = (unsigned int)(GCCc0w1(G_CCMUX_##b0, \ + G_CCMUX_##d0, \ + G_ACMUX_##Ab0, \ + G_ACMUX_##Ad0) | \ + GCCc1w1(G_CCMUX_##b1, \ + G_ACMUX_##Aa1, \ + G_ACMUX_##Ac1, \ + G_CCMUX_##d1, \ + G_ACMUX_##Ab1, \ + G_ACMUX_##Ad1)); \ +} + +#define gsDPSetCombineLERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ + a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ +{{ \ + _SHIFTL(G_SETCOMBINE, 24, 8) | \ + _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ + G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ + GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), 0, 24), \ + (unsigned int)(GCCc0w1(G_CCMUX_##b0, G_CCMUX_##d0, \ + G_ACMUX_##Ab0, G_ACMUX_##Ad0) | \ + GCCc1w1(G_CCMUX_##b1, G_ACMUX_##Aa1, \ + G_ACMUX_##Ac1, G_CCMUX_##d1, \ + G_ACMUX_##Ab1, G_ACMUX_##Ad1)) \ +}} + +/* + * SetCombineMode macros are NOT redunant. It allow the C preprocessor + * to substitute single parameter which includes commas in the token and + * rescan for higher parameter count macro substitution. + * + * eg. gsDPSetCombineMode(G_CC_MODULATE, G_CC_MODULATE) turns into + * gsDPSetCombineLERP(TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0, + * TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0) + */ + +#define gDPSetCombineMode(pkt, a, b) gDPSetCombineLERP(pkt, a, b) +#define gsDPSetCombineMode(a, b) gsDPSetCombineLERP(a, b) + +#define gDPSetColor(pkt, c, d) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(c, 24, 8); \ + _g->words.w1 = (unsigned int)(d); \ +} + +#define gsDPSetColor(c, d) \ +{{ \ + _SHIFTL(c, 24, 8), (unsigned int)(d) \ +}} + +#define DPRGBColor(pkt, cmd, r, g, b, a) \ + gDPSetColor(pkt, cmd, \ + (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ + _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) +#define sDPRGBColor(cmd, r, g, b, a) \ + gsDPSetColor(cmd, \ + (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ + _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) + +#define gDPSetEnvColor(pkt, r, g, b, a) \ + DPRGBColor(pkt, G_SETENVCOLOR, r,g,b,a) +#define gsDPSetEnvColor(r, g, b, a) \ + sDPRGBColor(G_SETENVCOLOR, r,g,b,a) +#define gDPSetBlendColor(pkt, r, g, b, a) \ + DPRGBColor(pkt, G_SETBLENDCOLOR, r,g,b,a) +#define gsDPSetBlendColor(r, g, b, a) \ + sDPRGBColor(G_SETBLENDCOLOR, r,g,b,a) +#define gDPSetFogColor(pkt, r, g, b, a) \ + DPRGBColor(pkt, G_SETFOGCOLOR, r,g,b,a) +#define gsDPSetFogColor(r, g, b, a) \ + sDPRGBColor(G_SETFOGCOLOR, r,g,b,a) +#define gDPSetFillColor(pkt, d) \ + gDPSetColor(pkt, G_SETFILLCOLOR, (d)) +#define gsDPSetFillColor(d) \ + gsDPSetColor(G_SETFILLCOLOR, (d)) + +#define gDPSetPrimDepth(pkt, z, dz) \ + gDPSetColor(pkt, G_SETPRIMDEPTH, \ + _SHIFTL(z, 16, 16) | _SHIFTL(dz, 0, 16)) +#define gsDPSetPrimDepth(z, dz) \ + gsDPSetColor(G_SETPRIMDEPTH, _SHIFTL(z, 16, 16) | \ + _SHIFTL(dz, 0, 16)) + +#define gDPSetPrimColor(pkt, m, l, r, g, b, a) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | \ + _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)); \ + _g->words.w1 = (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ + _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8)); \ +} + +#define gsDPSetPrimColor(m, l, r, g, b, a) \ +{{ \ + (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | _SHIFTL(m, 8, 8) | \ + _SHIFTL(l, 0, 8)), \ + (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | \ + _SHIFTL(a, 0, 8)) \ +}} + +/* + * gDPSetOtherMode (This is for expert user.) + * + * This command makes all othermode parameters set. + * Do not use this command in the same DL with another g*SPSetOtherMode DLs. + * + * [Usage] + * gDPSetOtherMode(pkt, modeA, modeB) + * + * 'modeA' is described all parameters of GroupA GBI command. + * 'modeB' is also described all parameters of GroupB GBI command. + * + * GroupA: + * gDPPipelineMode, gDPSetCycleType, gSPSetTexturePersp, + * gDPSetTextureDetail, gDPSetTextureLOD, gDPSetTextureLUT, + * gDPSetTextureFilter, gDPSetTextureConvert, gDPSetCombineKey, + * gDPSetColorDither, gDPSetAlphaDither + * + * GroupB: + * gDPSetAlphaCompare, gDPSetDepthSource, gDPSetRenderMode + * + * Use 'OR' operation to get modeA and modeB. + * + * modeA = G_PM_* | G_CYC_* | G_TP_* | G_TD_* | G_TL_* | G_TT_* | G_TF_* + * G_TC_* | G_CK_* | G_CD_* | G_AD_*; + * + * modeB = G_AC_* | G_ZS_* | G_RM_* | G_RM_*2; + */ +#define gDPSetOtherMode(pkt, mode0, mode1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24);\ + _g->words.w1 = (unsigned int)(mode1); \ +} + +#define gsDPSetOtherMode(mode0, mode1) \ +{{ \ + _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24), \ + (unsigned int)(mode1) \ +}} + +/* + * Texturing macros + */ + +/* These are also defined defined above for Sprite Microcode */ + +#define G_TX_LOADTILE 7 +#define G_TX_RENDERTILE 0 + +#define G_TX_NOMIRROR 0 +#define G_TX_WRAP 0 +#define G_TX_MIRROR 0x1 +#define G_TX_CLAMP 0x2 +#define G_TX_NOMASK 0 +#define G_TX_NOLOD 0 + + +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif +/* + * Dxt is the inverse of the number of 64-bit words in a line of + * the texture being loaded using the load_block command. If + * there are any 1's to the right of the 11th fractional bit, + * dxt should be rounded up. The following macros accomplish + * this. The 4b macros are a special case since 4-bit textures + * are loaded as 8-bit textures. Dxt is fixed point 1.11. RJM + */ +#define G_TX_DXT_FRAC 11 + +/* + * For RCP 2.0, the maximum number of texels that can be loaded + * using a load_block command is 2048. In order to load the total + * 4kB of Tmem, change the texel size when loading to be G_IM_SIZ_16b, + * then change the tile to the proper texel size after the load. + * The g*DPLoadTextureBlock macros already do this, so this change + * will be transparent if you use these macros. If you use + * the g*DPLoadBlock macros directly, you will need to handle this + * tile manipulation yourself. RJM. + */ +#ifdef _HW_VERSION_1 +#define G_TX_LDBLK_MAX_TXL 4095 +#else +#define G_TX_LDBLK_MAX_TXL 2047 +#endif /* _HW_VERSION_1 */ + +#define TXL2WORDS(txls, b_txl) MAX(1, ((txls)*(b_txl)/8)) +#define CALC_DXT(width, b_txl) \ + (((1 << G_TX_DXT_FRAC) + TXL2WORDS(width, b_txl) - 1) / \ + TXL2WORDS(width, b_txl)) + +#define TXL2WORDS_4b(txls) MAX(1, ((txls)/16)) +#define CALC_DXT_4b(width) \ + (((1 << G_TX_DXT_FRAC) + TXL2WORDS_4b(width) - 1) / \ + TXL2WORDS_4b(width)) + +#define gDPLoadTileGeneric(pkt, c, tile, uls, ult, lrs, lrt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | \ + _SHIFTL(ult, 0, 12); \ + _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | \ + _SHIFTL(lrt, 0, 12); \ +} + +#define gsDPLoadTileGeneric(c, tile, uls, ult, lrs, lrt) \ +{{ \ + _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12), \ + _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | _SHIFTL(lrt, 0, 12)\ +}} + +#define gDPSetTileSize(pkt, t, uls, ult, lrs, lrt) \ + gDPLoadTileGeneric(pkt, G_SETTILESIZE, t, uls, ult, lrs, lrt) +#define gsDPSetTileSize(t, uls, ult, lrs, lrt) \ + gsDPLoadTileGeneric(G_SETTILESIZE, t, uls, ult, lrs, lrt) +#define gDPLoadTile(pkt, t, uls, ult, lrs, lrt) \ + gDPLoadTileGeneric(pkt, G_LOADTILE, t, uls, ult, lrs, lrt) +#define gsDPLoadTile(t, uls, ult, lrs, lrt) \ + gsDPLoadTileGeneric(G_LOADTILE, t, uls, ult, lrs, lrt) + +#define gDPSetTile(pkt, fmt, siz, line, tmem, tile, palette, cmt, \ + maskt, shiftt, cms, masks, shifts) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) |\ + _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | \ + _SHIFTL(tmem, 0, 9); \ + _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ + _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ + _SHIFTL(shiftt, 10, 4) |_SHIFTL(cms, 8, 2) | \ + _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4); \ +} + +#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, \ + maskt, shiftt, cms, masks, shifts) \ +{{ \ + (_SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) | \ + _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | _SHIFTL(tmem, 0, 9)),\ + (_SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ + _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ + _SHIFTL(shiftt, 10, 4) | _SHIFTL(cms, 8, 2) | \ + _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4)) \ +}} + +/* + * For RCP 2.0, the maximum number of texels that can be loaded + * using a load_block command is 2048. In order to load the total + * 4kB of Tmem, change the texel size when loading to be G_IM_SIZ_16b, + * then change the tile to the proper texel size after the load. + * The g*DPLoadTextureBlock macros already do this, so this change + * will be transparent if you use these macros. If you use + * the g*DPLoadBlock macros directly, you will need to handle this + * tile manipulation yourself. RJM. + */ +#define gDPLoadBlock(pkt, tile, uls, ult, lrs, dxt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_LOADBLOCK, 24, 8) | \ + _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | \ + _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) |\ + _SHIFTL(dxt, 0, 12)); \ +} + +#define gsDPLoadBlock(tile, uls, ult, lrs, dxt) \ +{{ \ + (_SHIFTL(G_LOADBLOCK, 24, 8) | _SHIFTL(uls, 12, 12) | \ + _SHIFTL(ult, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | \ + _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) | \ + _SHIFTL(dxt, 0, 12)) \ +}} + +#define gDPLoadTLUTCmd(pkt, tile, count) \ +{ \ + Gfx *_g = (Gfx *)pkt; \ + \ + _g->words.w0 = _SHIFTL(G_LOADTLUT, 24, 8); \ + _g->words.w1 = _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10);\ +} + +#define gsDPLoadTLUTCmd(tile, count) \ +{{ \ + _SHIFTL(G_LOADTLUT, 24, 8), \ + _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10) \ +}} + +#define gDPLoadTextureBlock(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +#define gDPLoadTextureBlockYuv(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * 1)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* Load fix rww 27jun95 */ +/* The S at the end means odd lines are already word Swapped */ + +#define gDPLoadTextureBlockS(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * Allow tmem address and render tile to be specified. + * The S at the end means odd lines are already word Swapped + */ +#define gDPLoadMultiBlockS(pkt, timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * siz##_LINE_BYTES)+7)>>3, tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + + +#define gDPLoadTextureBlockYuvS(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * 1)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * allows tmem address to be specified + */ +#define _gDPLoadTextureBlock(pkt, timg, tmem, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ + tmem, G_TX_RENDERTILE, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * allows tmem address and render tile to be specified + */ +#define _gDPLoadTextureBlockTile(pkt, timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ + tmem, rtile, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * allows tmem address and render tile to be specified + */ +#define gDPLoadMultiBlock(pkt, timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ + tmem, rtile, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* Here is the static form of the pre-swapped texture block loading */ +/* See gDPLoadTextureBlockS() for reference. Basically, just don't + calculate DxT, use 0 */ + +#define gsDPLoadTextureBlockS(timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0 , \ + cmt, maskt,shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* + * Allow tmem address to be specified + */ +#define _gsDPLoadTextureBlock(timg, tmem, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, \ + ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * Allow tmem address and render_tile to be specified + */ +#define _gsDPLoadTextureBlockTile(timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, \ + ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * Allow tmem address and render_tile to be specified, useful when loading + * mutilple tiles at a time. + */ +#define gsDPLoadMultiBlock(timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, \ + ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* + * Allows tmem and render tile to be specified. Useful when loading + * several tiles at a time. + * + * Here is the static form of the pre-swapped texture block loading + * See gDPLoadTextureBlockS() for reference. Basically, just don't + * calculate DxT, use 0 + */ + +#define gsDPLoadMultiBlockS(timg, tmem, rtile, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0 , \ + cmt, maskt,shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), tmem,\ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +#define gDPLoadTextureBlock_4b(pkt, timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* Load fix rww 27jun95 */ +/* The S at the end means odd lines are already word Swapped */ + +#define gDPLoadTextureBlock_4bS(pkt, timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, 0 ); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * 4-bit load block. Useful when loading multiple tiles + */ +#define gDPLoadMultiBlock_4b(pkt, timg, tmem, rtile, fmt, width, height,\ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * 4-bit load block. Allows tmem and render tile to be specified. Useful when + * loading multiple tiles. The S means odd lines are already word swapped. + */ +#define gDPLoadMultiBlock_4bS(pkt, timg, tmem, rtile, fmt, width, height,\ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, 0 ); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + + +#define _gDPLoadTextureBlock_4b(pkt, timg, tmem, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +#define gsDPLoadTextureBlock_4b(timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +#define gsDPLoadTextureBlock_4bS(timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* + * 4-bit load block. Allows tmem address and render tile to be specified. + * Useful when loading multiple tiles. + */ +#define gsDPLoadMultiBlock_4b(timg, tmem, rtile, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * 4-bit load block. Allows tmem address and render tile to be specified. + * Useful when loading multiple tiles. S means odd lines are already swapped. + */ +#define gsDPLoadMultiBlock_4bS(timg, tmem, rtile, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * Allows tmem address to be specified + */ +#define _gsDPLoadTextureBlock_4b(timg, tmem, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +#ifndef _HW_VERSION_1 + +#define gDPLoadTextureTile(pkt, timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz, width, timg); \ + gDPSetTile(pkt, fmt, siz, \ + (((((lrs)-(uls)+1) * siz##_TILE_BYTES)+7)>>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, \ + (uls)<>3), tmem, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, \ + (uls)<>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks,\ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, \ + (uls)<>3), \ + tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<>3), \ + tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, \ + (uls)<>1), timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, \ + (uls)<>1), timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, \ + (uls)<>1), timg), \ + gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, \ + (uls)<>1), timg), \ + gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ + tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ + tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, \ + (uls)<words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(uly)*4.0F), 0, 12); \ + _g->words.w1 = _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(lry)*4.0F), 0, 12); \ +} + + +#define gDPSetScissorFrac(pkt, mode, ulx, uly, lrx, lry) \ +{ \ + Gfx *_g = (Gfx *)pkt; \ + \ + _g->words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((ulx)), 12, 12) | \ + _SHIFTL((int)((uly)), 0, 12); \ + _g->words.w1 = _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)((lrx)), 12, 12) | \ + _SHIFTL((int)((lry)), 0, 12); \ +} + +#define gsDPSetScissor(mode, ulx, uly, lrx, lry) \ +{{ \ + _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(uly)*4.0F), 0, 12), \ + _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(lry)*4.0F), 0, 12) \ +}} + +#define gsDPSetScissorFrac(mode, ulx, uly, lrx, lry) \ +{{ \ + _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((ulx)), 12, 12) | \ + _SHIFTL((int)((uly)), 0, 12), \ + _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)(lrx), 12, 12) | \ + _SHIFTL((int)(lry), 0, 12) \ +}} + +/* Fraction never used in fill */ +#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ + _SHIFTL((lrx), 14, 10) | _SHIFTL((lry), 2, 10));\ + _g->words.w1 = (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10));\ +} + +#define gsDPFillRectangle(ulx, uly, lrx, lry) \ +{{ \ + (_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 14, 10) | \ + _SHIFTL((lry), 2, 10)), \ + (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10)) \ +}} + +/* like gDPFillRectangle but accepts negative arguments */ +#define gDPScisFillRectangle(pkt, ulx, uly, lrx, lry) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ + _SHIFTL(MAX((lrx),0), 14, 10) | \ + _SHIFTL(MAX((lry),0), 2, 10)); \ + _g->words.w1 = (_SHIFTL(MAX((ulx),0), 14, 10) | \ + _SHIFTL(MAX((uly),0), 2, 10)); \ +} + +#define gDPSetConvert(pkt, k0, k1, k2, k3, k4, k5) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETCONVERT, 24, 8) | \ + _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | \ + _SHIFTR(k2, 5, 4)); \ + _g->words.w1 = (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | \ + _SHIFTL(k4, 9, 9) | _SHIFTL(k5, 0, 9)); \ +} + +#define gsDPSetConvert(k0, k1, k2, k3, k4, k5) \ +{{ \ + (_SHIFTL(G_SETCONVERT, 24, 8) | \ + _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | _SHIFTR(k2, 5, 4)), \ + (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | _SHIFTL(k4, 9, 9) | \ + _SHIFTL(k5, 0, 9)) \ +}} + +#define gDPSetKeyR(pkt, cR, sR, wR) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETKEYR, 24, 8); \ + _g->words.w1 = (_SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | \ + _SHIFTL(sR, 0, 8)); \ +} + +#define gsDPSetKeyR(cR, sR, wR) \ +{{ \ + _SHIFTL(G_SETKEYR, 24, 8), \ + _SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | _SHIFTL(sR, 0, 8) \ +}} + +#define gDPSetKeyGB(pkt, cG, sG, wG, cB, sB, wB) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETKEYGB, 24, 8) | \ + _SHIFTL(wG, 12, 12) | _SHIFTL(wB, 0, 12)); \ + _g->words.w1 = (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | \ + _SHIFTL(cB, 8, 8) | _SHIFTL(sB, 0, 8)); \ +} + +#define gsDPSetKeyGB(cG, sG, wG, cB, sB, wB) \ +{{ \ + (_SHIFTL(G_SETKEYGB, 24, 8) | _SHIFTL(wG, 12, 12) | \ + _SHIFTL(wB, 0, 12)), \ + (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | _SHIFTL(cB, 8, 8) | \ + _SHIFTL(sB, 0, 8)) \ +}} + +#define gDPNoParam(pkt, cmd) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8); \ + _g->words.w1 = 0; \ +} + +#define gsDPNoParam(cmd) \ +{{ \ + _SHIFTL(cmd, 24, 8), 0 \ +}} + +#define gDPParam(pkt, cmd, param) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8); \ + _g->words.w1 = (param); \ +} + +#define gsDPParam(cmd, param) \ +{{ \ + _SHIFTL(cmd, 24, 8), (param) \ +}} + +/* Notice that textured rectangles are 128-bit commands, therefore + * gsDPTextureRectangle() should not be used in display lists + * under normal circumstances (use gsSPTextureRectangle()). + * That is also why there is no gDPTextureRectangle() macros. + */ +#define gsDPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +{{ \ + (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ +}}, \ +{{ \ + _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ + _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ +}} + +#define gDPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + if (pkt); \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + _g ++; \ + _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ +} + +#define gsDPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +{{ \ + (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ +}}, \ +{{ \ + _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ + _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ +}} + +#define gDPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + if (pkt); \ + _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + _g ++; \ + _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ +} + +#define gsSPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + {{(_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)),\ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12))}}, \ + gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ + gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) + +#define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)));\ +} + +/* like gSPTextureRectangle but accepts negative position arguments */ +#define gSPScisTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | \ + _SHIFTL(MAX((s16)(xh),0), 12, 12) | \ + _SHIFTL(MAX((s16)(yh),0), 0, 12)); \ + _g->words.w1 = (_SHIFTL((tile), 24, 3) | \ + _SHIFTL(MAX((s16)(xl),0), 12, 12) | \ + _SHIFTL(MAX((s16)(yl),0), 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, \ + (_SHIFTL(((s) - \ + (((s16)(xl) < 0) ? \ + (((s16)(dsdx) < 0) ? \ + (MAX((((s16)(xl)*(s16)(dsdx))>>7),0)) : \ + (MIN((((s16)(xl)*(s16)(dsdx))>>7),0))) : 0)), \ + 16, 16) | \ + _SHIFTL(((t) - \ + (((yl) < 0) ? \ + (((s16)(dtdy) < 0) ? \ + (MAX((((s16)(yl)*(s16)(dtdy))>>7),0)) : \ + (MIN((((s16)(yl)*(s16)(dtdy))>>7),0))) : 0)), \ + 0, 16))); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL((dsdx), 16, 16) | \ + _SHIFTL((dtdy), 0, 16))); \ +} + +#define gsSPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + {{(_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12))}}, \ + gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ + gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) + +#define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) |\ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \ +} + +#define gsDPWord(wordhi, wordlo) \ + gsImmp1(G_RDPHALF_1, (unsigned int)(wordhi)), \ + gsImmp1(G_RDPHALF_2, (unsigned int)(wordlo)) + +#define gDPWord(pkt, wordhi, wordlo) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + gImmp1(pkt, G_RDPHALF_1, (unsigned int)(wordhi)); \ + gImmp1(pkt, G_RDPHALF_2, (unsigned int)(wordlo)); \ +} + +#define gDPFullSync(pkt) gDPNoParam(pkt, G_RDPFULLSYNC) +#define gsDPFullSync() gsDPNoParam(G_RDPFULLSYNC) +#define gDPTileSync(pkt) gDPNoParam(pkt, G_RDPTILESYNC) +#define gsDPTileSync() gsDPNoParam(G_RDPTILESYNC) +#define gDPPipeSync(pkt) gDPNoParam(pkt, G_RDPPIPESYNC) +#define gsDPPipeSync() gsDPNoParam(G_RDPPIPESYNC) +#define gDPLoadSync(pkt) gDPNoParam(pkt, G_RDPLOADSYNC) +#define gsDPLoadSync() gsDPNoParam(G_RDPLOADSYNC) +#define gDPNoOp(pkt) gDPNoParam(pkt, G_NOOP) +#define gsDPNoOp() gsDPNoParam(G_NOOP) +#define gDPNoOpTag(pkt, tag) gDPParam(pkt, G_NOOP, tag) +#define gsDPNoOpTag(tag) gsDPParam(G_NOOP, tag) + +#endif /* _LANGUAGE_C */ + + +#endif /* _GBI_H_ */ diff --git a/lib/ultralib/include/PR/gs2dex.h b/lib/ultralib/include/PR/gs2dex.h new file mode 100644 index 0000000..ced4685 --- /dev/null +++ b/lib/ultralib/include/PR/gs2dex.h @@ -0,0 +1,392 @@ +/*--------------------------------------------------------------------- + Copyright (C) 1997, Nintendo. + + File gs2dex.h + Coded by Yoshitaka Yasumoto. Jul 31, 1997. + Modified by + Comments Header file for S2DEX ucode. + + $Id: gs2dex.h,v 1.21 1998/05/28 00:14:49 has Exp $ + ---------------------------------------------------------------------*/ + +#ifndef _GS2DEX_H_ +#define _GS2DEX_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +/*===========================================================================* + * Macro + *===========================================================================*/ +#define GS_CALC_DXT(line) (((1<< G_TX_DXT_FRAC)-1)/(line)+1) +#define GS_PIX2TMEM(pix, siz) ((pix)>>(4-(siz))) +#define GS_PIX2DXT(pix, siz) GS_CALC_DXT(GS_PIX2TMEM((pix), (siz))) + +/*===========================================================================* + * Data structures for S2DEX microcode + *===========================================================================*/ + +/*---------------------------------------------------------------------------* + * Background + *---------------------------------------------------------------------------*/ +#define G_BGLT_LOADBLOCK 0x0033 +#define G_BGLT_LOADTILE 0xfff4 + +#define G_BG_FLAG_FLIPS 0x01 +#define G_BG_FLAG_FLIPT 0x10 + +/* Non scalable background plane */ +typedef struct { + u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */ + u16 imageW; /* width of the texture (u10.2) */ + s16 frameX; /* upper-left position of transferred frame (s10.2) */ + u16 frameW; /* width of transferred frame (u10.2) */ + + u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */ + u16 imageH; /* height of the texture (u10.2) */ + s16 frameY; /* upper-left position of transferred frame (s10.2) */ + u16 frameH; /* height of transferred frame (u10.2) */ + + u64 *imagePtr; /* texture source address on DRAM */ + u16 imageLoad; /* which to use, LoadBlock or LoadTile */ + u8 imageFmt; /* format of texel - G_IM_FMT_* */ + u8 imageSiz; /* size of texel - G_IM_SIZ_* */ + u16 imagePal; /* pallet number */ + u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ + + /* The following is set in the initialization routine guS2DInitBg(). There is no need for the user to set it. */ + u16 tmemW; /* TMEM width and Word size of frame 1 line. + At LoadBlock, GS_PIX2TMEM(imageW/4,imageSiz) + At LoadTile GS_PIX2TMEM(frameW/4,imageSiz)+1 */ + u16 tmemH; /* height of TMEM loadable at a time (s13.2) 4 times value + When the normal texture, 512/tmemW*4 + When the CI texture, 256/tmemW*4 */ + u16 tmemLoadSH; /* SH value + At LoadBlock, tmemSize/2-1 + At LoadTile, tmemW*16-1 */ + u16 tmemLoadTH; /* TH value or Stride value + At LoadBlock, GS_CALC_DXT(tmemW) + At LoadTile, tmemH-1 */ + u16 tmemSizeW; /* skip value of imagePtr for image 1-line + At LoadBlock, tmemW*2 + At LoadTile, GS_PIX2TMEM(imageW/4,imageSiz)*2 */ + u16 tmemSize; /* skip value of imagePtr for 1-loading + = tmemSizeW*tmemH */ +} uObjBg_t; /* 40 bytes */ + +/* Scalable background plane */ +typedef struct { + u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */ + u16 imageW; /* width of texture (u10.2) */ + s16 frameX; /* upper-left position of transferred frame (s10.2) */ + u16 frameW; /* width of transferred frame (u10.2) */ + + u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */ + u16 imageH; /* height of texture (u10.2) */ + s16 frameY; /* upper-left position of transferred frame (s10.2) */ + u16 frameH; /* height of transferred frame (u10.2) */ + + u64 *imagePtr; /* texture source address on DRAM */ + u16 imageLoad; /* Which to use, LoadBlock or LoadTile? */ + u8 imageFmt; /* format of texel - G_IM_FMT_* */ + u8 imageSiz; /* size of texel - G_IM_SIZ_* */ + u16 imagePal; /* pallet number */ + u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ + + u16 scaleW; /* scale value of X-direction (u5.10) */ + u16 scaleH; /* scale value of Y-direction (u5.10) */ + s32 imageYorig; /* start point of drawing on image (s20.5) */ + + u8 padding[4]; + +} uObjScaleBg_t; /* 40 bytes */ + +typedef union { + uObjBg_t b; + uObjScaleBg_t s; + long long int force_structure_alignment; +} uObjBg; + +/*---------------------------------------------------------------------------* + * 2D Objects + *---------------------------------------------------------------------------*/ +#define G_OBJ_FLAG_FLIPS 1<<0 /* inversion to S-direction */ +#define G_OBJ_FLAG_FLIPT 1<<4 /* nversion to T-direction */ + +typedef struct { + s16 objX; /* s10.2 OBJ x-coordinate of upper-left end */ + u16 scaleW; /* u5.10 Scaling of u5.10 width direction */ + u16 imageW; /* u10.5 width of u10.5 texture (length of S-direction) */ + u16 paddingX; /* Unused - Always 0 */ + s16 objY; /* s10.2 OBJ y-coordinate of s10.2 OBJ upper-left end */ + u16 scaleH; /* u5.10 Scaling of u5.10 height direction */ + u16 imageH; /* u10.5 height of u10.5 texture (length of T-direction) */ + u16 paddingY; /* Unused - Always 0 */ + u16 imageStride; /* folding width of texel (In units of 64bit word) */ + u16 imageAdrs; /* texture header position in TMEM (In units of 64bit word) */ + u8 imageFmt; /* format of texel - G_IM_FMT_* */ + u8 imageSiz; /* size of texel - G_IM_SIZ_* */ + u8 imagePal; /* pallet number (0-7) */ + u8 imageFlags; /* The display flag - G_OBJ_FLAG_FLIP* */ +} uObjSprite_t; /* 24 bytes */ + +typedef union { + uObjSprite_t s; + long long int force_structure_alignment; +} uObjSprite; + +/*---------------------------------------------------------------------------* + * 2D Matrix + *---------------------------------------------------------------------------*/ +typedef struct { + s32 A, B, C, D; /* s15.16 */ + s16 X, Y; /* s10.2 */ + u16 BaseScaleX; /* u5.10 */ + u16 BaseScaleY; /* u5.10 */ +} uObjMtx_t; /* 24 bytes */ + +typedef union { + uObjMtx_t m; + long long int force_structure_alignment; +} uObjMtx; + +typedef struct { + s16 X, Y; /* s10.2 */ + u16 BaseScaleX; /* u5.10 */ + u16 BaseScaleY; /* u5.10 */ +} uObjSubMtx_t; /* 8 bytes */ + +typedef union { + uObjSubMtx_t m; + long long int force_structure_alignment; +} uObjSubMtx; + +/*---------------------------------------------------------------------------* + * Loading into TMEM + *---------------------------------------------------------------------------*/ +#define G_OBJLT_TXTRBLOCK 0x00001033 +#define G_OBJLT_TXTRTILE 0x00fc1034 +#define G_OBJLT_TLUT 0x00000030 + +#define GS_TB_TSIZE(pix,siz) (GS_PIX2TMEM((pix),(siz))-1) +#define GS_TB_TLINE(pix,siz) (GS_CALC_DXT(GS_PIX2TMEM((pix),(siz)))) + +typedef struct { + u32 type; /* G_OBJLT_TXTRBLOCK divided into types */ + u64 *image; /* texture source address on DRAM */ + u16 tmem; /* loaded TMEM word address (8byteWORD) */ + u16 tsize; /* Texture size, Specified by macro GS_TB_TSIZE() */ + u16 tline; /* width of Texture 1-line, Specified by macro GS_TB_TLINE() */ + u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ + u32 flag; /* STATE flag */ + u32 mask; /* STATE mask */ +} uObjTxtrBlock_t; /* 24 bytes */ + +#define GS_TT_TWIDTH(pix,siz) ((GS_PIX2TMEM((pix), (siz))<<2)-1) +#define GS_TT_THEIGHT(pix,siz) (((pix)<<2)-1) + +typedef struct { + u32 type; /* G_OBJLT_TXTRTILE divided into types */ + u64 *image; /* texture source address on DRAM */ + u16 tmem; /* loaded TMEM word address (8byteWORD)*/ + u16 twidth; /* width of Texture (Specified by macro GS_TT_TWIDTH()) */ + u16 theight; /* height of Texture (Specified by macro GS_TT_THEIGHT()) */ + u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ + u32 flag; /* STATE flag */ + u32 mask; /* STATE mask */ +} uObjTxtrTile_t; /* 24 bytes */ + +#define GS_PAL_HEAD(head) ((head)+256) +#define GS_PAL_NUM(num) ((num)-1) + +typedef struct { + u32 type; /* G_OBJLT_TLUT divided into types */ + u64 *image; /* texture source address on DRAM */ + u16 phead; /* pallet number of load header (Between 256 and 511) */ + u16 pnum; /* loading pallet number -1 */ + u16 zero; /* Assign 0 all the time */ + u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12)*/ + u32 flag; /* STATE flag */ + u32 mask; /* STATE mask */ +} uObjTxtrTLUT_t; /* 24 bytes */ + +typedef union { + uObjTxtrBlock_t block; + uObjTxtrTile_t tile; + uObjTxtrTLUT_t tlut; + long long int force_structure_alignment; +} uObjTxtr; + +/*---------------------------------------------------------------------------* + * Loading into TMEM & 2D Objects + *---------------------------------------------------------------------------*/ +typedef struct { + uObjTxtr txtr; + uObjSprite sprite; +} uObjTxSprite; /* 48 bytes */ + +/*===========================================================================* + * GBI Commands for S2DEX microcode + *===========================================================================*/ +/* GBI Header */ +#ifdef F3DEX_GBI_2 +#define G_OBJ_RECTANGLE_R 0xda +#define G_OBJ_MOVEMEM 0xdc +#define G_RDPHALF_0 0xe4 +#define G_OBJ_RECTANGLE 0x01 +#define G_OBJ_SPRITE 0x02 +#define G_SELECT_DL 0x04 +#define G_OBJ_LOADTXTR 0x05 +#define G_OBJ_LDTX_SPRITE 0x06 +#define G_OBJ_LDTX_RECT 0x07 +#define G_OBJ_LDTX_RECT_R 0x08 +#define G_BG_1CYC 0x09 +#define G_BG_COPY 0x0a +#define G_OBJ_RENDERMODE 0x0b +#else +#define G_BG_1CYC 0x01 +#define G_BG_COPY 0x02 +#define G_OBJ_RECTANGLE 0x03 +#define G_OBJ_SPRITE 0x04 +#define G_OBJ_MOVEMEM 0x05 +#define G_SELECT_DL 0xb0 +#define G_OBJ_RENDERMODE 0xb1 +#define G_OBJ_RECTANGLE_R 0xb2 +#define G_OBJ_LOADTXTR 0xc1 +#define G_OBJ_LDTX_SPRITE 0xc2 +#define G_OBJ_LDTX_RECT 0xc3 +#define G_OBJ_LDTX_RECT_R 0xc4 +#define G_RDPHALF_0 0xe4 +#endif + +/*---------------------------------------------------------------------------* + * Background wrapped screen + *---------------------------------------------------------------------------*/ +#define gSPBgRectangle(pkt, m, mptr) gDma0p((pkt),(m),(mptr),0) +#define gsSPBgRectangle(m, mptr) gsDma0p( (m),(mptr),0) +#define gSPBgRectCopy(pkt, mptr) gSPBgRectangle((pkt), G_BG_COPY, (mptr)) +#define gsSPBgRectCopy(mptr) gsSPBgRectangle( G_BG_COPY, (mptr)) +#define gSPBgRect1Cyc(pkt, mptr) gSPBgRectangle((pkt), G_BG_1CYC, (mptr)) +#define gsSPBgRect1Cyc(mptr) gsSPBgRectangle( G_BG_1CYC, (mptr)) + +/*---------------------------------------------------------------------------* + * 2D Objects + *---------------------------------------------------------------------------*/ +#define gSPObjSprite(pkt, mptr) gDma0p((pkt),G_OBJ_SPRITE, (mptr),0) +#define gsSPObjSprite(mptr) gsDma0p( G_OBJ_SPRITE, (mptr),0) +#define gSPObjRectangle(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE, (mptr),0) +#define gsSPObjRectangle(mptr) gsDma0p( G_OBJ_RECTANGLE, (mptr),0) +#define gSPObjRectangleR(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE_R,(mptr),0) +#define gsSPObjRectangleR(mptr) gsDma0p( G_OBJ_RECTANGLE_R,(mptr),0) + +/*---------------------------------------------------------------------------* + * 2D Matrix + *---------------------------------------------------------------------------*/ +#define gSPObjMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),0,23) +#define gsSPObjMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),0,23) +#define gSPObjSubMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),2, 7) +#define gsSPObjSubMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),2, 7) + +/*---------------------------------------------------------------------------* + * Loading into TMEM + *---------------------------------------------------------------------------*/ +#define gSPObjLoadTxtr(pkt, tptr) gDma0p((pkt),G_OBJ_LOADTXTR, (tptr),23) +#define gsSPObjLoadTxtr(tptr) gsDma0p( G_OBJ_LOADTXTR, (tptr),23) +#define gSPObjLoadTxSprite(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_SPRITE,(tptr),47) +#define gsSPObjLoadTxSprite(tptr) gsDma0p( G_OBJ_LDTX_SPRITE,(tptr),47) +#define gSPObjLoadTxRect(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT, (tptr),47) +#define gsSPObjLoadTxRect(tptr) gsDma0p( G_OBJ_LDTX_RECT, (tptr),47) +#define gSPObjLoadTxRectR(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT_R,(tptr),47) +#define gsSPObjLoadTxRectR(tptr) gsDma0p( G_OBJ_LDTX_RECT_R,(tptr),47) + +/*---------------------------------------------------------------------------* + * Select Display List + *---------------------------------------------------------------------------*/ +#define gSPSelectDL(pkt, mptr, sid, flag, mask) \ +{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } +#define gsSPSelectDL(mptr, sid, flag, mask) \ +{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } +#define gSPSelectBranchDL(pkt, mptr, sid, flag, mask) \ +{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } +#define gsSPSelectBranchDL(mptr, sid, flag, mask) \ +{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } + +/*---------------------------------------------------------------------------* + * Set general status + *---------------------------------------------------------------------------*/ +#define G_MW_GENSTAT 0x08 /* Note that it is the same value of G_MW_FOG */ + +#define gSPSetStatus(pkt, sid, val) \ + gMoveWd((pkt), G_MW_GENSTAT, (sid), (val)) +#define gsSPSetStatus(sid, val) \ + gsMoveWd( G_MW_GENSTAT, (sid), (val)) + +/*---------------------------------------------------------------------------* + * Set Object Render Mode + *---------------------------------------------------------------------------*/ +#define G_OBJRM_NOTXCLAMP 0x01 +#define G_OBJRM_XLU 0x02 /* Ignored */ +#define G_OBJRM_ANTIALIAS 0x04 /* Ignored */ +#define G_OBJRM_BILERP 0x08 +#define G_OBJRM_SHRINKSIZE_1 0x10 +#define G_OBJRM_SHRINKSIZE_2 0x20 +#define G_OBJRM_WIDEN 0x40 + +#define gSPObjRenderMode(pkt, mode) gImmp1((pkt),G_OBJ_RENDERMODE,(mode)) +#define gsSPObjRenderMode(mode) gsImmp1( G_OBJ_RENDERMODE,(mode)) + +/*===========================================================================* + * Render Mode Macro + *===========================================================================*/ +#define RM_RA_SPRITE(clk) \ + AA_EN | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define G_RM_SPRITE G_RM_OPA_SURF +#define G_RM_SPRITE2 G_RM_OPA_SURF2 +#define G_RM_RA_SPRITE RM_RA_SPRITE(1) +#define G_RM_RA_SPRITE2 RM_RA_SPRITE(2) +#define G_RM_AA_SPRITE G_RM_AA_TEX_TERR +#define G_RM_AA_SPRITE2 G_RM_AA_TEX_TERR2 +#define G_RM_XLU_SPRITE G_RM_XLU_SURF +#define G_RM_XLU_SPRITE2 G_RM_XLU_SURF2 +#define G_RM_AA_XLU_SPRITE G_RM_AA_XLU_SURF +#define G_RM_AA_XLU_SPRITE2 G_RM_AA_XLU_SURF2 + +/*===========================================================================* + * External functions + *===========================================================================*/ +extern u64 gspS2DEX_fifoTextStart[], gspS2DEX_fifoTextEnd[]; +extern u64 gspS2DEX_fifoDataStart[], gspS2DEX_fifoDataEnd[]; +extern u64 gspS2DEX_fifo_dTextStart[], gspS2DEX_fifo_dTextEnd[]; +extern u64 gspS2DEX_fifo_dDataStart[], gspS2DEX_fifo_dDataEnd[]; +extern u64 gspS2DEX2_fifoTextStart[], gspS2DEX2_fifoTextEnd[]; +extern u64 gspS2DEX2_fifoDataStart[], gspS2DEX2_fifoDataEnd[]; +extern u64 gspS2DEX2_xbusTextStart[], gspS2DEX2_xbusTextEnd[]; +extern u64 gspS2DEX2_xbusDataStart[], gspS2DEX2_xbusDataEnd[]; +extern void guS2DInitBg(uObjBg *); + +#ifdef F3DEX_GBI_2 +# define guS2DEmuBgRect1Cyc guS2D2EmuBgRect1Cyc /*Wrapper*/ +# define guS2DEmuSetScissor guS2D2EmuSetScissor /*Wrapper*/ + extern void guS2D2EmuSetScissor(u32, u32, u32, u32, u8); + extern void guS2D2EmuBgRect1Cyc(Gfx **, uObjBg *); +#else + extern void guS2DEmuSetScissor(u32, u32, u32, u32, u8); + extern void guS2DEmuBgRect1Cyc(Gfx **, uObjBg *); +#endif + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif +#endif /* _GS2DEX_H_ */ + +/*======== End of gs2dex.h ========*/ diff --git a/lib/ultralib/include/PR/gt.h b/lib/ultralib/include/PR/gt.h new file mode 100644 index 0000000..09b6ba2 --- /dev/null +++ b/lib/ultralib/include/PR/gt.h @@ -0,0 +1,365 @@ + +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: gt.h + * Creator: hsa@sgi.com + * Create Date: Thu Oct 12 15:48:14 PDT 1995 + * + * This file defines the GBI for the TURBO 3D graphics microcode. + * The turbo microcode is a special FEATURE-LIMITED microcode designed + * for specific applications. It is not for general use. + * + * (see XXX for more information) + * + */ + +/************************************************************************** + * + * $Revision: 1.16 $ + * $Date: 1998/05/28 00:14:50 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gt.h,v $ + * + **************************************************************************/ + +#ifndef _GT_H_ +#define _GT_H_ + +/* this file should be #included AFTER gbi.h */ + +#include "sptask.h" + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif /* _LANGUAGE_C_PLUS_PLUS */ + +#include + +/* the following #defines seem out of order, but we need them + * for the microcode. + */ + +/* + * object state field: rendState + * + * This flag word is built up out of the bits from a + * subset of the G_SETGEOMETRYMODE flags from gbi.h. + * + * When each of these bits is '1', the comments below explain + * the effect on the triangles. + */ +#define GT_ZBUFFER G_ZBUFFER +#define GT_TEXTURE G_TEXTURE_ENABLE /* texture ON */ +#define GT_CULL_BACK G_CULL_BACK /* reject backfaces */ +#define GT_SHADING_SMOOTH G_SHADING_SMOOTH /* smooth shade ON */ + +/* + * object state field: textureState + * + * The lower 3 bits of this flag word contain the texture tile number + * to be used. All triangles of an object are rendered with the same + * texture tile. + */ + +/* + * object state field: flag + * + * This is a group of what would be pad bits. We use them for some + * flag bits. + */ +#define GT_FLAG_NOMTX 0x01 /* don't load the matrix */ +#define GT_FLAG_NO_XFM 0x02 /* load vtx, use verbatim */ +#define GT_FLAG_XFM_ONLY 0x04 /* xform vtx, write to *TriN */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* turbo 3D ucode: */ +extern long long int gspTurbo3DTextStart[], gspTurbo3DTextEnd[]; +extern long long int gspTurbo3DDataStart[], gspTurbo3DDataEnd[]; +extern long long int gspTurbo3D_dramTextStart[], gspTurbo3D_dramTextEnd[]; +extern long long int gspTurbo3D_dramDataStart[], gspTurbo3D_dramDataEnd[]; +extern long long int gspTurbo3D_fifoTextStart[], gspTurbo3D_fifoTextEnd[]; +extern long long int gspTurbo3D_fifoDataStart[], gspTurbo3D_fifoDataEnd[]; + +/* + * This is the global state structure. It's definition carefully + * matches the ucode, so if this structure changes, you must also change + * the ucode. + */ +typedef struct { + u16 perspNorm; /* persp normalization */ + u16 pad0; + u32 flag; + Gfx rdpOthermode; + u32 segBases[16]; /* table of segment base addrs (SEE NOTE!) */ + Vp viewport; /* the viewport to use */ + Gfx *rdpCmds; /* block of RDP data, process if !NULL + * block terminated by gDPEndDisplayList() + * (This is a segment address) + */ +} gtGlobState_t; + +/* NOTE: + * Although there are 16 segment table entries, the first one (segment 0) + * is reserved for physical memory mapping. You should not segment 0 + * to anything other than 0x0. + */ + +typedef union { + gtGlobState_t sp; + long long int force_structure_alignment; +} gtGlobState; + + +/* + * This is the 'state' structure associated with each object + * to be rendered. It's definition carefully matches the + * ucode, so if this structure changes, you must also change + * the gtoff.c tool and the ucode. + */ +typedef struct { + u32 renderState; /* render state */ + u32 textureState; /* texture state */ + u8 vtxCount; /* how many verts? */ + u8 vtxV0; /* where to load verts? */ + u8 triCount; /* how many tris? */ + u8 flag; + Gfx *rdpCmds; /* ptr (segment address) to RDP DL */ + Gfx rdpOthermode; + Mtx transform; /* the transform matrix to use */ +} gtState_t; + +typedef union { + gtState_t sp; + long long int force_structure_alignment; +} gtState; + +/* gtStateLite : same as gtState, but no matrix (see flags below) */ +/* this structure must be identical to gtState! (bad) */ +typedef struct { + u32 renderState; /* render state */ + u32 textureState; /* texture state */ + u8 vtxCount; /* how many verts? */ + u8 vtxV0; /* where to load verts? */ + u8 triCount; /* how many tris? */ + u8 flag; + Gfx *rdpCmds; /* ptr (segment address) to RDP DL */ + Gfx rdpOthermode; +} gtStateL_t; + +typedef union { + gtStateL_t sp; + long long int force_structure_alignment; +} gtStateL; + +/* + * The vertex list for the turbo display list uses the + * Vtx struct in gbi.h + * + */ + + +/* + * This structure represents a single triangle, part of the + * triangle list of the object to be rendered. + * + * NOTE: The triangle list MUST be aligned to an 8-byte boundary. + * Since this structure is only 4 bytes, we are REQUIRING that + * this structure only be used as an array of triangles, and we + * depend on the MIPS C compiler (which always aligns arrays to + * 8-byte boundaries). THIS IS DANGEROUS!!!! + * + */ +typedef struct { + u8 v0, v1, v2, flag; /* flag is which one for flat shade */ +} gtTriN; + + +/* + * This structure represents the transformed points. It is the format + * of the points written out when GT_FLAG_XFM_ONLY is set, as well as + * the format expected when GT_FLAG_NO_XFM is used. + * + * NOTE: The size and layout of these points is very similar to Vtx, + * except the screen coordinates overwrite the x,y,z,pad fields. + * (we could consider adding to the Vtx union, but we want to keep + * turbo stuff out of gbi.h) + * + * NOTE: The z is a special format. It can be used to compare vertices + * for sorting, but it should not be used for other purposes. If modified, + * the z-buffer hardware might not understand the data. + * + */ +typedef struct { + short int xscrn; /* x,y screen coordinates are SSSS10.2 */ + short int yscrn; + int zscrn; /* z screen is S15.16 */ + + short int s; /* transformed texture coord, S10.5 */ + short int t; + + u8 r; /* color (or normal) */ + u8 g; + u8 b; + u8 a; +} gtVtxOut_t; + +/* see "Data Structure" comment in gbi.h for information about why + * we use this union. + */ +typedef union { + gtVtxOut_t v; + long long int force_structure_alignment; +} gtVtxOut; + + + +/* + * state field: rdpOthermode + * + * This is one of the trickier state fields. The turbo interface + * requires the RDP othermode command to be cached by the host, + * therefore we provide a different interface in libultra to help cache + * this in the gt state (this word is just bits, you could pack them + * on your own). + * + * gtStateSetOthermode() accomplishs this, taking as arguments + * the state, one of the following mode enums, and a piece of data + * (othermode parameters from gbi.h). + * + * By definition, the othermode word from the gt state structure is sent + * to the RDP *before* any RDP commands from the rdpCmds[] field. The + * othermode is *always* sent. + * + * Stated another way, NONE of the gbi RDP othermode commands equivalent + * to those listed here are allowed in the rdpCmd[] field of the + * gt state structure. + * + * Notice also that many of these commands do not make sense for + * the turbo ucode (they control features not supported, like mip-mapping). + * They are only included here for completeness. + * + */ +typedef enum { + GT_CLEAR, /* special gt mode, clears othermode state */ + GT_ALPHACOMPARE, + GT_ZSRCSEL, + GT_RENDERMODE, + GT_ALPHADITHER, + GT_RGBDITHER, + GT_COMBKEY, + GT_TEXTCONV, + GT_TEXTFILT, + GT_TEXTLUT, + GT_TEXTLOD, + GT_TEXTDETAIL, + GT_TEXTPERSP, + GT_CYCLETYPE, + GT_PIPELINE +} gtStateOthermode_t; + +/* + * This call builds up an othermode command word. The 'mode' is one of + * the above modes, the 'data' field comes from gbi.h, it is the data + * field for the equivalent gbi setothermode macro. + */ +extern void gtStateSetOthermode(Gfx *om, gtStateOthermode_t mode, int data); + +/* + * This call dumps a turbo display list for use with gbi2mem and RSPSIM + */ +#define GT_DUMPTURBO_HANGAFTER 64 +#define GT_DUMPTURBO_NOTEXTURES 128 +extern void gtDumpTurbo(OSTask *tp,u8 flags); + +/* + * Special macros to init othermode words to all 0's, a good default + * value. + */ +#define gDPClearOtherMode(pkt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE, 24, 8); \ + _g->words.w1 = 0x0; \ +} + +#define gsDPClearOtherMode() \ +{ \ + _SHIFTL(G_RDPSETOTHERMODE, 24, 8), 0x0 \ +} + +/* + * Special macros to end DP blocks (see above). These commands + * generate all 0's, which the turbo ucode looks for. They *aren't* + * real DP commands! + */ +#define gDPEndDisplayList(pkt) gSPNoOp(pkt) +#define gsDPEndDisplayList() gsSPNoOp() + +/* + * This structure is a turbo 'object', the turbo display list is + * simply a list of these. + * + * NOTE: All pointers are segment addresses + * + * NOTE: If (statep->flag & GT_FLAG_XFM_ONLY), the trip field is + * interpreted as a pointer to gtVtxOut[] that can be used to store + * the transformed points. (statep->triCount should be 0, else bad + * things could happen...) + * + * NOTE: If (statep->flag & GT_FLAG_NO_XFM), the vtxp field is + * interpreted as a pointer to gtVtxOut[] that can be used to load + * pre-transformed points. + * + */ +typedef struct { + gtGlobState *gstatep; /* global state, usually NULL */ + gtState *statep; /* if this is NULL, end object processing */ + Vtx *vtxp; /* if this is NULL, use points in buffer */ + gtTriN *trip; /* if this is NULL, use tris in buffer */ +} gtGfx_t; + +typedef union { + gtGfx_t obj; + long long int force_structure_alignment; +} gtGfx; + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_ASSEMBLY +#include +#endif /* _LANGUAGE_ASSEMBLY */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif /* _LANGUAGE_C_PLUS_PLUS */ + +#ifdef _LANGUAGE_MAKEROM +#endif /* _LANGUAGE_MAKEROM */ + +#endif /* _GT_H_ */ diff --git a/lib/ultralib/include/PR/gu.h b/lib/ultralib/include/PR/gu.h new file mode 100644 index 0000000..9a2fa2b --- /dev/null +++ b/lib/ultralib/include/PR/gu.h @@ -0,0 +1,270 @@ +#ifndef _GU_H_ +#define _GU_H_ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.48 $ + * $Date: 1999/07/13 08:00:20 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gu.h,v $ + * + **************************************************************************/ + +#include +#include +#include +#include + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#define M_PI 3.14159265358979323846 +#define M_DTOR (3.14159265358979323846/180.0) + +#define FTOFIX32(x) (long)((x) * (float)0x00010000) +#define FIX32TOF(x) ((float)(x) * (1.0f / (float)0x00010000)) +#define FTOFRAC8(x) ((int) MIN(((x) * (128.0f)), 127.0f) & 0xff) + +#define FILTER_WRAP 0 +#define FILTER_CLAMP 1 + +#define RAND(x) (guRandom()%x) /* random number between 0 to x */ + +/* + * Data Structures + */ +typedef struct { + unsigned char *base; + int fmt, siz; + int xsize, ysize; + int lsize; + /* current tile info */ + int addr; + int w, h; + int s, t; +} Image; + +typedef struct { + float col[3]; + float pos[3]; + float a1, a2; /* actual color = col/(a1*dist + a2) */ +} PositionalLight; + + +/* + * Function Prototypes + */ + +extern int guLoadTextureBlockMipMap(Gfx **glist, unsigned char *tbuf, Image *im, + unsigned char startTile, unsigned char pal, unsigned char cms, + unsigned char cmt, unsigned char masks, unsigned char maskt, + unsigned char shifts, unsigned char shiftt, unsigned char cfs, + unsigned char cft); + +extern int guGetDPLoadTextureTileSz (int ult, int lrt); +extern void guDPLoadTextureTile (Gfx *glistp, void *timg, + int texl_fmt, int texl_size, + int img_width, int img_height, + int uls, int ult, int lrs, int lrt, + int palette, + int cms, int cmt, + int masks, int maskt, + int shifts, int shiftt); + + +/* + * matrix operations: + * + * The 'F' version is floating point, in case the application wants + * to do matrix manipulations and convert to fixed-point at the last + * minute. + */ +extern void guMtxIdent(Mtx *m); +extern void guMtxIdentF(float mf[4][4]); +extern void guOrtho(Mtx *m, float l, float r, float b, float t, + float n, float f, float scale); +extern void guOrthoF(float mf[4][4], float l, float r, float b, float t, + float n, float f, float scale); +extern void guFrustum(Mtx *m, float l, float r, float b, float t, + float n, float f, float scale); +extern void guFrustumF(float mf[4][4], float l, float r, float b, float t, + float n, float f, float scale); +extern void guPerspective(Mtx *m, u16 *perspNorm, float fovy, + float aspect, float near, float far, float scale); +extern void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, + float aspect, float near, float far, float scale); +extern void guLookAt(Mtx *m, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp); +extern void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp); +extern void guLookAtReflect(Mtx *m, LookAt *l, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp); +extern void guLookAtReflectF(float mf[4][4], LookAt *l, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp); +extern void guLookAtHilite(Mtx *m, LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float xl1, float yl1, float zl1, + float xl2, float yl2, float zl2, + int twidth, int theight); +extern void guLookAtHiliteF(float mf[4][4], LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float xl1, float yl1, float zl1, + float xl2, float yl2, float zl2, + int twidth, int theight); +extern void guLookAtStereo(Mtx *m, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float eyedist); +extern void guLookAtStereoF(float mf[4][4], + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float eyedist); +extern void guRotate(Mtx *m, float a, float x, float y, float z); +extern void guRotateF(float mf[4][4], float a, float x, float y, float z); +extern void guRotateRPY(Mtx *m, float r, float p, float y); +extern void guRotateRPYF(float mf[4][4], float r, float p, float h); +extern void guAlign(Mtx *m, float a, float x, float y, float z); +extern void guAlignF(float mf[4][4], float a, float x, float y, float z); +extern void guScale(Mtx *m, float x, float y, float z); +extern void guScaleF(float mf[4][4], float x, float y, float z); +extern void guTranslate(Mtx *m, float x, float y, float z); +extern void guTranslateF(float mf[4][4], float x, float y, float z); +extern void guPosition(Mtx *m, float r, float p, float h, float s, + float x, float y, float z); +extern void guPositionF(float mf[4][4], float r, float p, float h, float s, + float x, float y, float z); +extern void guMtxF2L(float mf[4][4], Mtx *m); +extern void guMtxL2F(float mf[4][4], Mtx *m); +extern void guMtxCatF(float m[4][4], float n[4][4], float r[4][4]); +extern void guMtxCatL(Mtx *m, Mtx *n, Mtx *res); +extern void guMtxXFMF(float mf[4][4], float x, float y, float z, + float *ox, float *oy, float *oz); +extern void guMtxXFML(Mtx *m, float x, float y, float z, + float *ox, float *oy, float *oz); + +/* vector utility: */ +extern void guNormalize(float *x, float *y, float *z); + +/* light utilities: */ +void guPosLight(PositionalLight *pl, Light *l, + float xOb, float yOb, float zOb); +void guPosLightHilite(PositionalLight *pl1, PositionalLight *pl2, + Light *l1, Light *l2, + LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xOb, float yOb, float zOb, + float xUp, float yUp, float zUp, + int twidth, int theight); +extern int guRandom(void); + +/* + * Math functions + */ +extern float sinf(float angle); +extern float cosf(float angle); +extern signed short sins (unsigned short angle); +extern signed short coss (unsigned short angle); +extern float sqrtf(float value); +#if defined(__sgi) && BUILD_VERSION >= VERSION_K +#pragma intrinsic(sqrtf); +#endif + +/* + * Dump routines for low-level display lists + */ +/* flag values for guParseRdpDL() */ +#define GU_PARSERDP_VERBOSE 1 +#define GU_PARSERDP_PRAREA 2 +#define GU_PARSERDP_PRHISTO 4 +#define GU_PARSERDP_DUMPONLY 32 /* doesn't need to be same as */ + /* GU_PARSEGBI_DUMPOLNY, but this */ + /* allows app to use interchangeably */ + +extern void guParseRdpDL(u64 *rdp_dl, u64 nbytes, u8 flags); +extern void guParseString(char *StringPointer, u64 nbytes); + +/* + * NO LONGER SUPPORTED, + * use guParseRdpDL with GU_PARSERDP_DUMPONLY flags + */ +/* extern void guDumpRawRdpDL(u64 *rdp_dl, u64 nbytes); */ + +/* flag values for guBlinkRdpDL() */ +#define GU_BLINKRDP_HILITE 1 +#define GU_BLINKRDP_EXTRACT 2 + +extern void +guBlinkRdpDL(u64 *rdp_dl_in, u64 nbytes_in, + u64 *rdp_dl_out, u64 *nbytes_out, + u32 x, u32 y, u32 radius, + u8 red, u8 green, u8 blue, + u8 flags); + +/* flag values for guParseGbiDL() */ +#define GU_PARSEGBI_ROWMAJOR 1 +#define GU_PARSEGBI_NONEST 2 +#define GU_PARSEGBI_FLTMTX 4 +#define GU_PARSEGBI_SHOWDMA 8 +#define GU_PARSEGBI_ALLMTX 16 +#define GU_PARSEGBI_DUMPONLY 32 +/* +#define GU_PARSEGBI_HANGAFTER 64 +#define GU_PARSEGBI_NOTEXTURES 128 +*/ +extern void guParseGbiDL(u64 *gbi_dl, u32 nbytes, u8 flags); +extern void guDumpGbiDL(OSTask *tp,u8 flags); + +#define GU_PARSE_GBI_TYPE 1 +#define GU_PARSE_RDP_TYPE 2 +#define GU_PARSE_READY 3 +#define GU_PARSE_MEM_BLOCK 4 +#define GU_PARSE_ABI_TYPE 5 +#define GU_PARSE_STRING_TYPE 6 + +typedef struct { + int dataSize; + int dlType; + int flags; + u32 paddr; +} guDLPrintCB; + +void guSprite2DInit(uSprite *SpritePointer, + void *SourceImagePointer, + void *TlutPointer, + int Stride, + int SubImageWidth, + int SubImageHeight, + int SourceImageType, + int SourceImageBitSize, + int SourceImageOffsetS, + int SourceImageOffsetT); + +#endif /* !_GU_H_ */ diff --git a/lib/ultralib/include/PR/libaudio.h b/lib/ultralib/include/PR/libaudio.h new file mode 100644 index 0000000..33017b7 --- /dev/null +++ b/lib/ultralib/include/PR/libaudio.h @@ -0,0 +1,947 @@ +/*==================================================================== + * libaudio.h + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.173 $ + * $Date: 1997/12/01 12:42:21 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/libaudio.h,v $ + * + **************************************************************************/ + +#ifndef __LIB_AUDIO__ +#define __LIB_AUDIO__ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include + +/*********************************************************************** + * misc defines + ***********************************************************************/ +#ifndef _EMULATOR +# ifdef AUD_PROFILE + +#define PROFILE_AUD(num, cnt, max, min) \ +{ \ + u32 currCnt = osGetCount(); \ + currCnt -= lastCnt[cnt_index]; \ + cnt_index--; \ + cnt += currCnt; \ + num++; \ + \ + if ( currCnt > max ) max = currCnt; \ + if ( currCnt < min ) min = currCnt; \ +} + +# endif /* AUD_PROFILE */ +#endif /* EMULATOR */ + +#ifndef NULL +#define NULL 0 +#endif + +#define AL_FX_BUFFER_SIZE 8192 +#define AL_FRAME_INIT -1 +#define AL_USEC_PER_FRAME 16000 +#define AL_MAX_PRIORITY 127 +#define AL_GAIN_CHANGE_TIME 1000 + +typedef s32 ALMicroTime; +typedef u8 ALPan; + +#define AL_PAN_CENTER 64 +#define AL_PAN_LEFT 0 +#define AL_PAN_RIGHT 127 +#define AL_VOL_FULL 127 +#define AL_KEY_MIN 0 +#define AL_KEY_MAX 127 +#define AL_DEFAULT_FXMIX 0 +#define AL_SUSTAIN 63 + +/*********************************************************************** + * Error handling + ***********************************************************************/ + +#ifdef _DEBUG +#define ALFailIf(condition, error) \ + if (condition) { \ + __osError(error, 0); \ + return; } + +#else +#define ALFailIf(condition, error) \ + if (condition) { \ + return; } +#endif + +#ifdef _DEBUG +#define ALFlagFailIf(condition, flag, error) \ + if (condition) { \ + if(flag) __osError(error, 0); \ + return; } + +#else +#define ALFlagFailIf(condition, flag, error) \ + if (condition) { \ + return; } +#endif + +/*********************************************************************** + * Audio Library global routines + ***********************************************************************/ +typedef struct ALLink_s { + struct ALLink_s *next; + struct ALLink_s *prev; +} ALLink; + +void alUnlink(ALLink *element); +void alLink(ALLink *element, ALLink *after); + +typedef s32 (*ALDMAproc)(s32 addr, s32 len, void *state); +typedef ALDMAproc (*ALDMANew)(void *state); + +void alCopy(void *src, void *dest, s32 len); + +typedef struct { + u8 *base; + u8 *cur; + s32 len; + s32 count; +} ALHeap; + +#define AL_HEAP_DEBUG 1 +#define AL_HEAP_MAGIC 0x20736a73 +#define AL_HEAP_INIT 0 + +void alHeapInit(ALHeap *hp, u8 *base, s32 len); +void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); +s32 alHeapCheck(ALHeap *hp); + +#ifdef _DEBUG +#define alHeapAlloc(hp, elem ,size) alHeapDBAlloc((u8 *) __FILE__,__LINE__,(hp),(elem),(size)) +#else +#define alHeapAlloc(hp, elem ,size) alHeapDBAlloc(0, 0,(hp),(elem),(size)) +#endif + +/*********************************************************************** + * FX Stuff + ***********************************************************************/ +#define AL_FX_NONE 0 +#define AL_FX_SMALLROOM 1 +#define AL_FX_BIGROOM 2 +#define AL_FX_CHORUS 3 +#define AL_FX_FLANGE 4 +#define AL_FX_ECHO 5 +#define AL_FX_CUSTOM 6 + +typedef u8 ALFxId; +typedef void *ALFxRef; + +/*********************************************************************** + * data structures for sound banks + ***********************************************************************/ + +#define AL_BANK_VERSION 0x4231 /* 'B1' */ + +/* Possible wavetable types */ +enum {AL_ADPCM_WAVE = 0, + AL_RAW16_WAVE}; + +typedef struct { + s32 order; + s32 npredictors; + s16 book[1]; /* Actually variable size. Must be 8-byte aligned */ +} ALADPCMBook; + +typedef struct { + u32 start; + u32 end; + u32 count; + ADPCM_STATE state; +} ALADPCMloop; + +typedef struct { + u32 start; + u32 end; + u32 count; +} ALRawLoop; + +typedef struct { + ALMicroTime attackTime; + ALMicroTime decayTime; + ALMicroTime releaseTime; + u8 attackVolume; + u8 decayVolume; +} ALEnvelope; + +typedef struct { + u8 velocityMin; + u8 velocityMax; + u8 keyMin; + u8 keyMax; + u8 keyBase; + s8 detune; +} ALKeyMap; + +typedef struct { + ALADPCMloop *loop; + ALADPCMBook *book; +} ALADPCMWaveInfo; + +typedef struct { + ALRawLoop *loop; +} ALRAWWaveInfo; + +typedef struct ALWaveTable_s { + u8 *base; /* ptr to start of wave data */ + s32 len; /* length of data in bytes */ + u8 type; /* compression type */ + u8 flags; /* offset/address flags */ + union { + ALADPCMWaveInfo adpcmWave; + ALRAWWaveInfo rawWave; + } waveInfo; +} ALWaveTable; + +typedef struct ALSound_s { + ALEnvelope *envelope; + ALKeyMap *keyMap; + ALWaveTable *wavetable; /* offset to wavetable struct */ + ALPan samplePan; + u8 sampleVolume; + u8 flags; +} ALSound; + +typedef struct { + u8 volume; /* overall volume for this instrument */ + ALPan pan; /* 0 = hard left, 127 = hard right */ + u8 priority; /* voice priority for this instrument */ + u8 flags; + u8 tremType; /* the type of tremelo osc. to use */ + u8 tremRate; /* the rate of the tremelo osc. */ + u8 tremDepth; /* the depth of the tremelo osc */ + u8 tremDelay; /* the delay for the tremelo osc */ + u8 vibType; /* the type of tremelo osc. to use */ + u8 vibRate; /* the rate of the tremelo osc. */ + u8 vibDepth; /* the depth of the tremelo osc */ + u8 vibDelay; /* the delay for the tremelo osc */ + s16 bendRange; /* pitch bend range in cents */ + s16 soundCount; /* number of sounds in this array */ + ALSound *soundArray[1]; +} ALInstrument; + +typedef struct ALBank_s { + s16 instCount; /* number of programs in this bank */ + u8 flags; + u8 pad; + s32 sampleRate; /* e.g. 44100, 22050, etc... */ + ALInstrument *percussion; /* default percussion for GM */ + ALInstrument *instArray[1]; /* ARRAY of instruments */ +} ALBank; + +typedef struct { /* Note: sizeof won't be correct */ + s16 revision; /* format revision of this file */ + s16 bankCount; /* number of banks */ + ALBank *bankArray[1]; /* ARRAY of bank offsets */ +} ALBankFile; + +void alBnkfNew(ALBankFile *f, u8 *table); + +/*********************************************************************** + * Sequence Files + ***********************************************************************/ +#define AL_SEQBANK_VERSION 'S1' + +typedef struct { + u8 *offset; + s32 len; +} ALSeqData; + +typedef struct { /* Note: sizeof won't be correct */ + s16 revision; /* format revision of this file */ + s16 seqCount; /* number of sequences */ + ALSeqData seqArray[1]; /* ARRAY of sequence info */ +} ALSeqFile; + +void alSeqFileNew(ALSeqFile *f, u8 *base); + +/*********************************************************************** + * Synthesis driver stuff + ***********************************************************************/ +typedef ALMicroTime (*ALVoiceHandler)(void *); + +typedef struct { + s32 maxVVoices; /* obsolete */ + s32 maxPVoices; + s32 maxUpdates; + s32 maxFXbusses; + void *dmaproc; + ALHeap *heap; + s32 outputRate; /* output sample rate */ + ALFxId fxType; + s32 *params; +} ALSynConfig; + +typedef struct ALPlayer_s { + struct ALPlayer_s *next; + void *clientData; /* storage for client callback */ + ALVoiceHandler handler; /* voice handler for player */ + ALMicroTime callTime; /* usec requested callback */ + s32 samplesLeft; /* usec remaining to callback */ +} ALPlayer; + +typedef struct ALVoice_s { + ALLink node; + struct PVoice_s *pvoice; + ALWaveTable *table; + void *clientPrivate; + s16 state; + s16 priority; + s16 fxBus; + s16 unityPitch; +} ALVoice; + +typedef struct ALVoiceConfig_s { + s16 priority; /* voice priority */ + s16 fxBus; /* bus assignment */ + u8 unityPitch; /* unity pitch flag */ +} ALVoiceConfig; + +typedef struct { + ALPlayer *head; /* client list head */ + ALLink pFreeList; /* list of free physical voices */ + ALLink pAllocList; /* list of allocated physical voices */ + ALLink pLameList; /* list of voices ready to be freed */ + s32 paramSamples; + s32 curSamples; /* samples from start of game */ + ALDMANew dma; + ALHeap *heap; + + struct ALParam_s *paramList; + + struct ALMainBus_s *mainBus; + struct ALAuxBus_s *auxBus; /* ptr to array of aux bus structs */ + struct ALFilter_s *outputFilter; /* last filter in the filter chain */ + + s32 numPVoices; + s32 maxAuxBusses; + s32 outputRate; /* output sample rate */ + s32 maxOutSamples; /* Maximum samples rsp can generate + at one time at output rate */ +} ALSynth; + +void alSynNew(ALSynth *s, ALSynConfig *config); +void alSynDelete(ALSynth *s); + +void alSynAddPlayer(ALSynth *s, ALPlayer *client); +void alSynRemovePlayer(ALSynth *s, ALPlayer *client); + +s32 alSynAllocVoice(ALSynth *s, ALVoice *v, ALVoiceConfig *vc); +void alSynFreeVoice(ALSynth *s, ALVoice *voice); + +void alSynStartVoice(ALSynth *s, ALVoice *voice, ALWaveTable *w); +void alSynStartVoiceParams(ALSynth *s, ALVoice *voice, ALWaveTable *w, + f32 pitch, s16 vol, ALPan pan, u8 fxmix, + ALMicroTime t); +void alSynStopVoice(ALSynth *s, ALVoice *voice); + +void alSynSetVol(ALSynth *s, ALVoice *v, s16 vol, ALMicroTime delta); +void alSynSetPitch(ALSynth *s, ALVoice *voice, f32 ratio); +void alSynSetPan(ALSynth *s, ALVoice *voice, ALPan pan); +void alSynSetFXMix(ALSynth *s, ALVoice *voice, u8 fxmix); +void alSynSetPriority(ALSynth *s, ALVoice *voice, s16 priority); +s16 alSynGetPriority(ALSynth *s, ALVoice *voice); + +ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp); +ALFxRef alSynGetFXRef(ALSynth *s, s16 bus, s16 index); +void alSynFreeFX(ALSynth *s, ALFxRef *fx); +void alSynSetFXParam(ALSynth *s, ALFxRef fx, s16 paramID, void *param); + +/*********************************************************************** + * Audio Library (AL) stuff + ***********************************************************************/ +typedef struct { + ALSynth drvr; +} ALGlobals; + +extern ALGlobals *alGlobals; + +void alInit(ALGlobals *glob, ALSynConfig *c); +void alClose(ALGlobals *glob); + +Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen); + +/*********************************************************************** + * Sequence Player stuff + ***********************************************************************/ + +/* + * Play states + */ +#define AL_STOPPED 0 +#define AL_PLAYING 1 +#define AL_STOPPING 2 + +#define AL_DEFAULT_PRIORITY 5 +#define AL_DEFAULT_VOICE 0 +#define AL_MAX_CHANNELS 16 + +/* + * Audio Library event type definitions + */ +enum ALMsg { + AL_SEQ_REF_EVT, /* Reference to a pending event in the sequence. */ + AL_SEQ_MIDI_EVT, + AL_SEQP_MIDI_EVT, + AL_TEMPO_EVT, + AL_SEQ_END_EVT, + AL_NOTE_END_EVT, + AL_SEQP_ENV_EVT, + AL_SEQP_META_EVT, + AL_SEQP_PROG_EVT, + AL_SEQP_API_EVT, + AL_SEQP_VOL_EVT, + AL_SEQP_LOOP_EVT, + AL_SEQP_PRIORITY_EVT, + AL_SEQP_SEQ_EVT, + AL_SEQP_BANK_EVT, + AL_SEQP_PLAY_EVT, + AL_SEQP_STOP_EVT, + AL_SEQP_STOPPING_EVT, + AL_TRACK_END, + AL_CSP_LOOPSTART, + AL_CSP_LOOPEND, + AL_CSP_NOTEOFF_EVT, + AL_TREM_OSC_EVT, + AL_VIB_OSC_EVT +}; + +/* + * Midi event definitions + */ +#define AL_EVTQ_END 0x7fffffff + +enum AL_MIDIstatus { + /* For distinguishing channel number from status */ + AL_MIDI_ChannelMask = 0x0F, + AL_MIDI_StatusMask = 0xF0, + + /* Channel voice messages */ + AL_MIDI_ChannelVoice = 0x80, + AL_MIDI_NoteOff = 0x80, + AL_MIDI_NoteOn = 0x90, + AL_MIDI_PolyKeyPressure = 0xA0, + AL_MIDI_ControlChange = 0xB0, + AL_MIDI_ChannelModeSelect = 0xB0, + AL_MIDI_ProgramChange = 0xC0, + AL_MIDI_ChannelPressure = 0xD0, + AL_MIDI_PitchBendChange = 0xE0, + + /* System messages */ + AL_MIDI_SysEx = 0xF0, /* System Exclusive */ + + /* System common */ + AL_MIDI_SystemCommon = 0xF1, + AL_MIDI_TimeCodeQuarterFrame = 0xF1, + AL_MIDI_SongPositionPointer = 0xF2, + AL_MIDI_SongSelect = 0xF3, + AL_MIDI_Undefined1 = 0xF4, + AL_MIDI_Undefined2 = 0xF5, + AL_MIDI_TuneRequest = 0xF6, + AL_MIDI_EOX = 0xF7, /* End of System Exclusive */ + + /* System real time */ + AL_MIDI_SystemRealTime = 0xF8, + AL_MIDI_TimingClock = 0xF8, + AL_MIDI_Undefined3 = 0xF9, + AL_MIDI_Start = 0xFA, + AL_MIDI_Continue = 0xFB, + AL_MIDI_Stop = 0xFC, + AL_MIDI_Undefined4 = 0xFD, + AL_MIDI_ActiveSensing = 0xFE, + AL_MIDI_SystemReset = 0xFF, + AL_MIDI_Meta = 0xFF /* MIDI Files only */ +}; + +enum AL_MIDIctrl { + AL_MIDI_VOLUME_CTRL = 0x07, + AL_MIDI_PAN_CTRL = 0x0A, + AL_MIDI_PRIORITY_CTRL = 0x10, /* use general purpose controller for priority */ + AL_MIDI_FX_CTRL_0 = 0x14, + AL_MIDI_FX_CTRL_1 = 0x15, + AL_MIDI_FX_CTRL_2 = 0x16, + AL_MIDI_FX_CTRL_3 = 0x17, + AL_MIDI_FX_CTRL_4 = 0x18, + AL_MIDI_FX_CTRL_5 = 0x19, + AL_MIDI_FX_CTRL_6 = 0x1A, + AL_MIDI_FX_CTRL_7 = 0x1B, + AL_MIDI_FX_CTRL_8 = 0x1C, + AL_MIDI_FX_CTRL_9 = 0x1D, + AL_MIDI_SUSTAIN_CTRL = 0x40, + AL_MIDI_FX1_CTRL = 0x5B, + AL_MIDI_FX3_CTRL = 0x5D +}; + +enum AL_MIDImeta { + AL_MIDI_META_TEMPO = 0x51, + AL_MIDI_META_EOT = 0x2f +}; + + +#define AL_CMIDI_BLOCK_CODE 0xFE +#define AL_CMIDI_LOOPSTART_CODE 0x2E +#define AL_CMIDI_LOOPEND_CODE 0x2D +#define AL_CMIDI_CNTRL_LOOPSTART 102 +#define AL_CMIDI_CNTRL_LOOPEND 103 +#define AL_CMIDI_CNTRL_LOOPCOUNT_SM 104 +#define AL_CMIDI_CNTRL_LOOPCOUNT_BIG 105 + +typedef struct { + u8 *curPtr; /* ptr to the next event */ + s32 lastTicks; /* sequence clock ticks (used by alSeqSetLoc) */ + s32 curTicks; /* sequence clock ticks of next event (used by loop end test) */ + s16 lastStatus; /* the last status msg */ +} ALSeqMarker; + +typedef struct { + s32 ticks; /* MIDI, Tempo and End events must start with ticks */ + u8 status; + u8 byte1; + u8 byte2; + u32 duration; +} ALMIDIEvent; + +typedef struct { + s32 ticks; + u8 status; + u8 type; + u8 len; + u8 byte1; + u8 byte2; + u8 byte3; +} ALTempoEvent; + +typedef struct { + s32 ticks; + u8 status; + u8 type; + u8 len; +} ALEndEvent; + +typedef struct { + struct ALVoice_s *voice; +} ALNoteEvent; + +typedef struct { + struct ALVoice_s *voice; + ALMicroTime delta; + u8 vol; +} ALVolumeEvent; + +typedef struct { + s16 vol; +} ALSeqpVolEvent; + +typedef struct { + ALSeqMarker *start; + ALSeqMarker *end; + s32 count; +} ALSeqpLoopEvent; + +typedef struct { + u8 chan; + u8 priority; +} ALSeqpPriorityEvent; + +typedef struct { + void *seq; /* pointer to a seq (could be an ALSeq or an ALCSeq). */ +} ALSeqpSeqEvent; + +typedef struct { + ALBank *bank; +} ALSeqpBankEvent; + +typedef struct { + struct ALVoiceState_s *vs; + void *oscState; + u8 chan; +} ALOscEvent; + +typedef struct { + s16 type; + union { + ALMIDIEvent midi; + ALTempoEvent tempo; + ALEndEvent end; + ALNoteEvent note; + ALVolumeEvent vol; + ALSeqpLoopEvent loop; + ALSeqpVolEvent spvol; + ALSeqpPriorityEvent sppriority; + ALSeqpSeqEvent spseq; + ALSeqpBankEvent spbank; + ALOscEvent osc; + } msg; +} ALEvent; + +typedef struct { + ALLink node; + ALMicroTime delta; + ALEvent evt; +} ALEventListItem; + +typedef struct { + ALLink freeList; + ALLink allocList; + s32 eventCount; +} ALEventQueue; + +void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, + s32 itemCount); +ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt); +void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, + ALMicroTime delta); +void alEvtqFlush(ALEventQueue *evtq); +void alEvtqFlushType(ALEventQueue *evtq, s16 type); + + +#define AL_PHASE_ATTACK 0 +#define AL_PHASE_NOTEON 0 +#define AL_PHASE_DECAY 1 +#define AL_PHASE_SUSTAIN 2 +#define AL_PHASE_RELEASE 3 +#define AL_PHASE_SUSTREL 4 + +typedef struct ALVoiceState_s { + struct ALVoiceState_s *next;/* MUST be first */ + ALVoice voice; + ALSound *sound; + ALMicroTime envEndTime; /* time of envelope segment end */ + f32 pitch; /* currect pitch ratio */ + f32 vibrato; /* current value of the vibrato */ + u8 envGain; /* current envelope gain */ + u8 channel; /* channel assignment */ + u8 key; /* note on key number */ + u8 velocity; /* note on velocity */ + u8 envPhase; /* what envelope phase */ + u8 phase; + u8 tremelo; /* current value of the tremelo */ + u8 flags; /* bit 0 tremelo flag + bit 1 vibrato flag */ +} ALVoiceState; + +typedef struct { + ALInstrument *instrument; /* instrument assigned to this chan */ + s16 bendRange; /* pitch bend range in cents */ + ALFxId fxId; /* type of fx assigned to this chan */ + ALPan pan; /* overall pan for this chan */ + u8 priority; /* priority for this chan */ + u8 vol; /* current volume for this chan */ + u8 fxmix; /* current fx mix for this chan */ + u8 sustain; /* current sustain pedal state */ + f32 pitchBend; /* current pitch bend val in cents */ +} ALChanState; + +typedef struct ALSeq_s { + u8 *base; /* ptr to start of sequence file */ + u8 *trackStart; /* ptr to first MIDI event */ + u8 *curPtr; /* ptr to next event to read */ + s32 lastTicks; /* MIDI ticks for last event */ + s32 len; /* length of sequence in bytes */ + f32 qnpt; /* qrter notes / tick (1/division) */ + s16 division; /* ticks per quarter note */ + s16 lastStatus; /* for running status */ +} ALSeq; + +typedef struct { + u32 trackOffset[16]; + u32 division; +} ALCMidiHdr; + +typedef struct ALCSeq_s { + ALCMidiHdr *base; /* ptr to start of sequence file */ + u32 validTracks; /* set of flags, showing valid tracks */ + f32 qnpt; /* qrter notes / tick (1/division) */ + u32 lastTicks; /* keep track of ticks incase app wants */ + u32 lastDeltaTicks; /* number of delta ticks of last event */ + u32 deltaFlag; /* flag: set if delta's not subtracted */ + u8 *curLoc[16]; /* ptr to current track location, */ + /* may point to next event, or may point */ + /* to a backup code */ + u8 *curBUPtr[16]; /* ptr to next event if in backup mode */ + u8 curBULen[16]; /* if > 0, then in backup mode */ + u8 lastStatus[16]; /* for running status */ + u32 evtDeltaTicks[16]; /* delta time to next event */ +} ALCSeq; + +typedef struct { + u32 validTracks; + s32 lastTicks; + u32 lastDeltaTicks; + u8 *curLoc[16]; + u8 *curBUPtr[16]; + u8 curBULen[16]; + u8 lastStatus[16]; + u32 evtDeltaTicks[16]; +} ALCSeqMarker; + +#define NO_SOUND_ERR_MASK 0x01 +#define NOTE_OFF_ERR_MASK 0x02 +#define NO_VOICE_ERR_MASK 0x04 + +typedef struct { + s32 maxVoices; /* max number of voices to alloc */ + s32 maxEvents; /* max internal events to support */ + u8 maxChannels; /* max MIDI channels to support (16)*/ + u8 debugFlags; /* control which error get reported */ + ALHeap *heap; /* ptr to initialized heap */ + void *initOsc; + void *updateOsc; + void *stopOsc; +} ALSeqpConfig; + +typedef ALMicroTime (*ALOscInit)(void **oscState,f32 *initVal, u8 oscType, + u8 oscRate, u8 oscDepth, u8 oscDelay); +typedef ALMicroTime (*ALOscUpdate)(void *oscState, f32 *updateVal); +typedef void (*ALOscStop)(void *oscState); + +typedef struct { + ALPlayer node; /* note: must be first in structure */ + ALSynth *drvr; /* reference to the client driver */ + ALSeq *target; /* current sequence */ + ALMicroTime curTime; + ALBank *bank; /* current ALBank */ + s32 uspt; /* microseconds per tick */ + s32 nextDelta; /* microseconds to next callback */ + s32 state; + u16 chanMask; /* active channels */ + s16 vol; /* overall sequence volume */ + u8 maxChannels; /* number of MIDI channels */ + u8 debugFlags; /* control which error get reported */ + ALEvent nextEvent; + ALEventQueue evtq; + ALMicroTime frameTime; + ALChanState *chanState; /* 16 channels for MIDI */ + ALVoiceState *vAllocHead; /* list head for allocated voices */ + ALVoiceState *vAllocTail; /* list tail for allocated voices */ + ALVoiceState *vFreeList; /* list of free voice state structs */ + ALOscInit initOsc; + ALOscUpdate updateOsc; + ALOscStop stopOsc; + ALSeqMarker *loopStart; + ALSeqMarker *loopEnd; + s32 loopCount; /* -1 = loop forever, 0 = no loop */ +} ALSeqPlayer; + +typedef struct { + ALPlayer node; /* note: must be first in structure */ + ALSynth *drvr; /* reference to the client driver */ + ALCSeq *target; /* current sequence */ + ALMicroTime curTime; + ALBank *bank; /* current ALBank */ + s32 uspt; /* microseconds per tick */ + s32 nextDelta; /* microseconds to next callback */ + s32 state; + u16 chanMask; /* active channels */ + s16 vol; /* overall sequence volume */ + u8 maxChannels; /* number of MIDI channels */ + u8 debugFlags; /* control which error get reported */ + ALEvent nextEvent; + ALEventQueue evtq; + ALMicroTime frameTime; + ALChanState *chanState; /* 16 channels for MIDI */ + ALVoiceState *vAllocHead; /* list head for allocated voices */ + ALVoiceState *vAllocTail; /* list tail for allocated voices */ + ALVoiceState *vFreeList; /* list of free voice state structs */ + ALOscInit initOsc; + ALOscUpdate updateOsc; + ALOscStop stopOsc; +} ALCSPlayer; + +/* + * Sequence data representation routines + */ +void alSeqNew(ALSeq *seq, u8 *ptr, s32 len); +void alSeqNextEvent(ALSeq *seq, ALEvent *event); +s32 alSeqGetTicks(ALSeq *seq); +f32 alSeqTicksToSec(ALSeq *seq, s32 ticks, u32 tempo); +u32 alSeqSecToTicks(ALSeq *seq, f32 sec, u32 tempo); +void alSeqNewMarker(ALSeq *seq, ALSeqMarker *m, u32 ticks); +void alSeqSetLoc(ALSeq *seq, ALSeqMarker *marker); +void alSeqGetLoc(ALSeq *seq, ALSeqMarker *marker); +/* + * Compact Sequence data representation routines + */ +void alCSeqNew(ALCSeq *seq, u8 *ptr); +void alCSeqNextEvent(ALCSeq *seq,ALEvent *evt); +s32 alCSeqGetTicks(ALCSeq *seq); +f32 alCSeqTicksToSec(ALCSeq *seq, s32 ticks, u32 tempo); +u32 alCSeqSecToTicks(ALCSeq *seq, f32 sec, u32 tempo); +void alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks); +void alCSeqSetLoc(ALCSeq *seq, ALCSeqMarker *marker); +void alCSeqGetLoc(ALCSeq *seq, ALCSeqMarker *marker); + +/* + * Sequence Player routines + */ +f32 alCents2Ratio(s32 cents); + +void alSeqpNew(ALSeqPlayer *seqp, ALSeqpConfig *config); +void alSeqpDelete(ALSeqPlayer *seqp); +void alSeqpSetSeq(ALSeqPlayer *seqp, ALSeq *seq); +ALSeq *alSeqpGetSeq(ALSeqPlayer *seqp); +void alSeqpPlay(ALSeqPlayer *seqp); +void alSeqpStop(ALSeqPlayer *seqp); +s32 alSeqpGetState(ALSeqPlayer *seqp); +void alSeqpSetBank(ALSeqPlayer *seqp, ALBank *b); +void alSeqpSetTempo(ALSeqPlayer *seqp, s32 tempo); +s32 alSeqpGetTempo(ALSeqPlayer *seqp); +s16 alSeqpGetVol(ALSeqPlayer *seqp); /* Master volume control */ +void alSeqpSetVol(ALSeqPlayer *seqp, s16 vol); +void alSeqpLoop(ALSeqPlayer *seqp, ALSeqMarker *start, ALSeqMarker *end, s32 count); + +void alSeqpSetChlProgram(ALSeqPlayer *seqp, u8 chan, u8 prog); +s32 alSeqpGetChlProgram(ALSeqPlayer *seqp, u8 chan); +void alSeqpSetChlFXMix(ALSeqPlayer *seqp, u8 chan, u8 fxmix); +u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan); +void alSeqpSetChlVol(ALSeqPlayer *seqp, u8 chan, u8 vol); +u8 alSeqpGetChlVol(ALSeqPlayer *seqp, u8 chan); +void alSeqpSetChlPan(ALSeqPlayer *seqp, u8 chan, ALPan pan); +ALPan alSeqpGetChlPan(ALSeqPlayer *seqp, u8 chan); +void alSeqpSetChlPriority(ALSeqPlayer *seqp, u8 chan, u8 priority); +u8 alSeqpGetChlPriority(ALSeqPlayer *seqp, u8 chan); +void alSeqpSendMidi(ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, u8 byte2); + + +/* Maintain backwards compatibility with old routine names. */ +#define alSeqpSetProgram alSeqpSetChlProgram +#define alSeqpGetProgram alSeqpGetChlProgram +#define alSeqpSetFXMix alSeqpSetChlFXMix +#define alSeqpGetFXMix alSeqpGetChlFXMix +#define alSeqpSetPan alSeqpSetChlPan +#define alSeqpGetPan alSeqpGetChlPan +#define alSeqpSetChannelPriority alSeqpSetChlPriority +#define alSeqpGetChannelPriority alSeqpGetChlPriority + + + +/* + * Compressed Sequence Player routines + */ +void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *config); +void alCSPDelete(ALCSPlayer *seqp); +void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq); +ALCSeq *alCSPGetSeq(ALCSPlayer *seqp); +void alCSPPlay(ALCSPlayer *seqp); +void alCSPStop(ALCSPlayer *seqp); +s32 alCSPGetState(ALCSPlayer *seqp); +void alCSPSetBank(ALCSPlayer *seqp, ALBank *b); +void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo); +s32 alCSPGetTempo(ALCSPlayer *seqp); +s16 alCSPGetVol(ALCSPlayer *seqp); +void alCSPSetVol(ALCSPlayer *seqp, s16 vol); + +void alCSPSetChlProgram(ALCSPlayer *seqp, u8 chan, u8 prog); +s32 alCSPGetChlProgram(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlFXMix(ALCSPlayer *seqp, u8 chan, u8 fxmix); +u8 alCSPGetChlFXMix(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan); +ALPan alCSPGetChlPan(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol); +u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlPriority(ALCSPlayer *seqp, u8 chan, u8 priority); +u8 alCSPGetChlPriority(ALCSPlayer *seqp, u8 chan); +void alCSPSendMidi(ALCSPlayer *seqp, s32 ticks, u8 status, + u8 byte1, u8 byte2); + + +/* Maintain backwards compatibility with old routine names. */ +#define alCSPSetProgram alCSPSetChlProgram +#define alCSPGetProgram alCSPGetChlProgram +#define alCSPSetFXMix alCSPSetChlFXMix +#define alCSPGetFXMix alCSPGetChlFXMix +#define alCSPSetPan alCSPSetChlPan +#define alCSPGetPan alCSPGetChlPan +#define alCSPSetChannelPriority alCSPSetChlPriority +#define alCSPGetChannelPriority alCSPGetChlPriority + + + +/*********************************************************************** + * Sound Player stuff + ***********************************************************************/ + +typedef struct { + s32 maxSounds; + s32 maxEvents; + ALHeap *heap; +} ALSndpConfig; + +typedef struct { + ALPlayer node; /* note: must be first in structure */ + ALEventQueue evtq; + ALEvent nextEvent; + ALSynth *drvr; /* reference to the client driver */ + s32 target; + void *sndState; + s32 maxSounds; + ALMicroTime frameTime; + ALMicroTime nextDelta; /* microseconds to next callback */ + ALMicroTime curTime; +} ALSndPlayer; + +typedef s16 ALSndId; + +void alSndpNew(ALSndPlayer *sndp, ALSndpConfig *c); +void alSndpDelete(ALSndPlayer *sndp); + +ALSndId alSndpAllocate(ALSndPlayer *sndp, ALSound *sound); +void alSndpDeallocate(ALSndPlayer *sndp, ALSndId id); + +void alSndpSetSound(ALSndPlayer *sndp, ALSndId id); +ALSndId alSndpGetSound(ALSndPlayer *sndp); + +void alSndpPlay(ALSndPlayer *sndp); +void alSndpPlayAt(ALSndPlayer *sndp, ALMicroTime delta); +void alSndpStop(ALSndPlayer *sndp); + +void alSndpSetVol(ALSndPlayer *sndp, s16 vol); +void alSndpSetPitch(ALSndPlayer *sndp, f32 pitch); +void alSndpSetPan(ALSndPlayer *sndp, ALPan pan); +void alSndpSetPriority(ALSndPlayer *sndp, ALSndId id, u8 priority); + +void alSndpSetFXMix(ALSndPlayer *sndp, u8 mix); +s32 alSndpGetState(ALSndPlayer *sndp); + +#ifndef _FINALROM +void alParseAbiCL(Acmd *cmdList, u32 nbytes); +#endif +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !__LIB_AUDIO__ */ + + + diff --git a/lib/ultralib/include/PR/mbi.h b/lib/ultralib/include/PR/mbi.h new file mode 100644 index 0000000..ac900a5 --- /dev/null +++ b/lib/ultralib/include/PR/mbi.h @@ -0,0 +1,100 @@ +#ifndef _MBI_H_ +#define _MBI_H_ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.136 $ + * $Date: 1999/01/05 13:04:00 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/mbi.h,v $ + * + **************************************************************************/ + +/* + * Header file for the Media Binary Interface + * + * NOTE: This file is included by the RSP microcode, so any C-specific + * constructs must be bracketed by #ifdef _LANGUAGE_C + * + */ + + +/* + * the SHIFT macros are used to build display list commands, inserting + * bit-fields into a 32-bit word. They take a value, a shift amount, + * and a width. + * + * For the left shift, the lower bits of the value are masked, + * then shifted left. + * + * For the right shift, the value is shifted right, then the lower bits + * are masked. + * + * (NOTE: _SHIFTL(v, 0, 32) won't work, just use an assignment) + * + */ +#define _SHIFTL(v, s, w) \ + ((unsigned int) (((unsigned int)(v) & ((0x01 << (w)) - 1)) << (s))) +#define _SHIFTR(v, s, w) \ + ((unsigned int)(((unsigned int)(v) >> (s)) & ((0x01 << (w)) - 1))) + +#define _SHIFT _SHIFTL /* old, for compatibility only */ + +#define G_ON (1) +#define G_OFF (0) + +/************************************************************************** + * + * Graphics Binary Interface + * + **************************************************************************/ + +#include + +/************************************************************************** + * + * Audio Binary Interface + * + **************************************************************************/ + +#include + +/************************************************************************** + * + * Task list + * + **************************************************************************/ + +#define M_GFXTASK 1 +#define M_AUDTASK 2 +#define M_VIDTASK 3 +#define M_HVQTASK 6 +#define M_HVQMTASK 7 + +/************************************************************************** + * + * Segment macros and definitions + * + **************************************************************************/ + +#define NUM_SEGMENTS (16) +#define SEGMENT_OFFSET(a) ((unsigned int)(a) & 0x00ffffff) +#define SEGMENT_NUMBER(a) (((unsigned int)(a) << 4) >> 28) +#define SEGMENT_ADDR(num, off) (((num) << 24) + (off)) + +#ifndef NULL +#define NULL 0 +#endif + +#endif /* !_MBI_H_ */ diff --git a/lib/ultralib/include/PR/os.h b/lib/ultralib/include/PR/os.h new file mode 100644 index 0000000..4b52dfb --- /dev/null +++ b/lib/ultralib/include/PR/os.h @@ -0,0 +1,108 @@ + +/*==================================================================== + * os.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os.h,v $ + $Revision: 1.168 $ + $Date: 2000/06/15 06:24:52 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_H_ +#define _OS_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Stack size for I/O device managers: PIM (PI Manager), VIM (VI Manager), + * SIM (SI Manager) + * + */ +#define OS_PIM_STACKSIZE 4096 +#define OS_VIM_STACKSIZE 4096 +#define OS_SIM_STACKSIZE 4096 + +#define OS_MIN_STACKSIZE 72 + +/* + * Leo Disk + */ + +/* transfer mode */ + +#define LEO_BLOCK_MODE 1 +#define LEO_TRACK_MODE 2 +#define LEO_SECTOR_MODE 3 + +/* + * Boot addresses + */ +#define BOOT_ADDRESS_ULTRA 0x80000400 +#define BOOT_ADDRESS_COSIM 0x80002000 +#define BOOT_ADDRESS_EMU 0x20010000 +#define BOOT_ADDRESS_INDY 0x88100000 + + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_H */ diff --git a/lib/ultralib/include/PR/os_ai.h b/lib/ultralib/include/PR/os_ai.h new file mode 100644 index 0000000..f89d87c --- /dev/null +++ b/lib/ultralib/include/PR/os_ai.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_ai.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_ai.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_AI_H_ +#define _OS_AI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Audio interface (Ai) */ +extern u32 osAiGetStatus(void); +extern u32 osAiGetLength(void); +extern s32 osAiSetFrequency(u32); +extern s32 osAiSetNextBuffer(void *, u32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_AI_H_ */ diff --git a/lib/ultralib/include/PR/os_cache.h b/lib/ultralib/include/PR/os_cache.h new file mode 100644 index 0000000..54ed923 --- /dev/null +++ b/lib/ultralib/include/PR/os_cache.h @@ -0,0 +1,96 @@ + +/*==================================================================== + * os_cache.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cache.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CACHE_H_ +#define _OS_CACHE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) +#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Cache operations and macros */ + +extern void osInvalDCache(void *, s32); +extern void osInvalICache(void *, s32); +extern void osWritebackDCache(void *, s32); +extern void osWritebackDCacheAll(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CACHE_H_ */ diff --git a/lib/ultralib/include/PR/os_cont.h b/lib/ultralib/include/PR/os_cont.h new file mode 100644 index 0000000..2b69330 --- /dev/null +++ b/lib/ultralib/include/PR/os_cont.h @@ -0,0 +1,208 @@ + +/*==================================================================== + * os_cont.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cont.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:05 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CONT_H_ +#define _OS_CONT_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for controllers + */ + +typedef struct { + u16 type; /* Controller Type */ + u8 status; /* Controller status */ + u8 errno; +}OSContStatus; + +typedef struct { + u16 button; + s8 stick_x; /* -80 <= stick_x <= 80 */ + s8 stick_y; /* -80 <= stick_y <= 80 */ + u8 errno; +} OSContPad; + +typedef struct { + void *address; /* Ram pad Address: 11 bits */ + u8 databuffer[32]; /* address of the data buffer */ + u8 addressCrc; /* CRC code for address */ + u8 dataCrc; /* CRC code for data */ + u8 errno; +} OSContRamIo; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Controllers number + */ + +#ifndef _HW_VERSION_1 +#define MAXCONTROLLERS 4 +#else +#define MAXCONTROLLERS 6 +#endif + +/* controller errors */ +#define CONT_NO_RESPONSE_ERROR 0x8 +#define CONT_OVERRUN_ERROR 0x4 +#define CONT_RANGE_ERROR -1 +#ifdef _HW_VERSION_1 +#define CONT_FRAME_ERROR 0x2 +#define CONT_COLLISION_ERROR 0x1 +#endif + +/* Controller type */ + +#define CONT_ABSOLUTE 0x0001 +#define CONT_RELATIVE 0x0002 +#define CONT_JOYPORT 0x0004 +#define CONT_EEPROM 0x8000 +#define CONT_EEP16K 0x4000 +#define CONT_TYPE_MASK 0x1f07 +#define CONT_TYPE_NORMAL 0x0005 +#define CONT_TYPE_MOUSE 0x0002 +#define CONT_TYPE_VOICE 0x0100 + +/* Controller status */ + +#define CONT_CARD_ON 0x01 +#define CONT_CARD_PULL 0x02 +#define CONT_ADDR_CRC_ER 0x04 +#define CONT_EEPROM_BUSY 0x80 + +/* Buttons */ + +#define CONT_A 0x8000 +#define CONT_B 0x4000 +#define CONT_G 0x2000 +#define CONT_START 0x1000 +#define CONT_UP 0x0800 +#define CONT_DOWN 0x0400 +#define CONT_LEFT 0x0200 +#define CONT_RIGHT 0x0100 +#define CONT_L 0x0020 +#define CONT_R 0x0010 +#define CONT_E 0x0008 +#define CONT_D 0x0004 +#define CONT_C 0x0002 +#define CONT_F 0x0001 + +/* Nintendo's official button names */ + +#define A_BUTTON CONT_A +#define B_BUTTON CONT_B +#define L_TRIG CONT_L +#define R_TRIG CONT_R +#define Z_TRIG CONT_G +#define START_BUTTON CONT_START +#define U_JPAD CONT_UP +#define L_JPAD CONT_LEFT +#define R_JPAD CONT_RIGHT +#define D_JPAD CONT_DOWN +#define U_CBUTTONS CONT_E +#define L_CBUTTONS CONT_C +#define R_CBUTTONS CONT_F +#define D_CBUTTONS CONT_D + +/* Controller error number */ + +#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ +#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ +#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ +#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ +#define CONT_ERR_NOT_READY 12 +#define CONT_ERR_VOICE_MEMORY 13 +#define CONT_ERR_VOICE_WORD 14 +#define CONT_ERR_VOICE_NO_RESPONSE 15 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Controller interface */ + +extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); +extern s32 osContReset(OSMesgQueue *, OSContStatus *); +extern s32 osContStartQuery(OSMesgQueue *); +extern s32 osContStartReadData(OSMesgQueue *); +#ifndef _HW_VERSION_1 +extern s32 osContSetCh(u8); +#endif +extern void osContGetQuery(OSContStatus *); +extern void osContGetReadData(OSContPad *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CONT_H_ */ diff --git a/lib/ultralib/include/PR/os_convert.h b/lib/ultralib/include/PR/os_convert.h new file mode 100644 index 0000000..0a5da10 --- /dev/null +++ b/lib/ultralib/include/PR/os_convert.h @@ -0,0 +1,111 @@ + +/*==================================================================== + * os_convert.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_convert.h,v $ + $Revision: 1.2 $ + $Date: 1999/04/21 02:53:11 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CONVERT_H_ +#define _OS_CONVERT_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +#define OS_CLOCK_RATE 62500000LL +#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +#define OS_NSEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625000LL))/(1000000000LL/15625000LL)) +#define OS_USEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625LL))/(1000000LL/15625LL)) +#define OS_CYCLES_TO_NSEC(c) (((u64)(c)*(1000000000LL/15625000LL))/(OS_CPU_COUNTER/15625000LL)) +#define OS_CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CPU_COUNTER/15625LL)) + +/* OS_K?_TO_PHYSICAL macro bug fix for CodeWarrior */ +#ifndef __MWERKS__ +#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000)) +#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000)) +#else +#define OS_K0_TO_PHYSICAL(x) ((char *)(x)-0x80000000) +#define OS_K1_TO_PHYSICAL(x) ((char *)(x)-0xa0000000) +#endif + +#define OS_PHYSICAL_TO_K0(x) (void *)(((u32)(x)+0x80000000)) +#define OS_PHYSICAL_TO_K1(x) (void *)(((u32)(x)+0xa0000000)) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Address translation routines and macros */ + +extern u32 osVirtualToPhysical(void *); +extern void * osPhysicalToVirtual(u32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CONVERT_H_ */ diff --git a/lib/ultralib/include/PR/os_debug.h b/lib/ultralib/include/PR/os_debug.h new file mode 100644 index 0000000..f8f5a89 --- /dev/null +++ b/lib/ultralib/include/PR/os_debug.h @@ -0,0 +1,117 @@ + +/*==================================================================== + * os_debug.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_debug.h,v $ + $Revision: 1.4 $ + $Date: 1999/06/30 03:04:08 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_DEBUG_H_ +#define _OS_DEBUG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for Profiler + */ +typedef struct { + u16 *histo_base; /* histogram base */ + u32 histo_size; /* histogram size */ + u32 *text_start; /* start of text segment */ + u32 *text_end; /* end of text segment */ +} OSProf; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Profiler constants + */ +#define PROF_MIN_INTERVAL 50 /* microseconds */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Profiler Interface */ + +extern void osProfileInit(OSProf *, u32 profcnt); +extern void osProfileStart(u32); +extern void osProfileFlush(void); +extern void osProfileStop(void); + +/* Thread Profiler Interface */ +extern void osThreadProfileClear(OSId); +extern void osThreadProfileInit(void); +extern void osThreadProfileStart(void); +extern void osThreadProfileStop(void); +extern u32 osThreadProfileReadCount(OSId); +extern u32 osThreadProfileReadCountTh(OSThread*); +extern OSTime osThreadProfileReadTime(OSId); +extern OSTime osThreadProfileReadTimeTh(OSThread*); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_DEBUG_H_ */ diff --git a/lib/ultralib/include/PR/os_eeprom.h b/lib/ultralib/include/PR/os_eeprom.h new file mode 100644 index 0000000..b3bca81 --- /dev/null +++ b/lib/ultralib/include/PR/os_eeprom.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_eeprom.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_eeprom.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EEPROM_H_ +#define _OS_EEPROM_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* EEPROM TYPE */ + +#define EEPROM_TYPE_4K 0x01 +#define EEPROM_TYPE_16K 0x02 + +/* definition for EEPROM */ + +#define EEPROM_MAXBLOCKS 64 +#define EEP16K_MAXBLOCKS 256 +#define EEPROM_BLOCK_SIZE 8 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* EEPROM interface */ + +extern s32 osEepromProbe(OSMesgQueue *); +extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); +extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); +extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); +extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EEPROM_H_ */ diff --git a/lib/ultralib/include/PR/os_error.h b/lib/ultralib/include/PR/os_error.h new file mode 100644 index 0000000..f4c3b83 --- /dev/null +++ b/lib/ultralib/include/PR/os_error.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_error.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_error.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_ERROR_H_ +#define _OS_ERROR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_ERROR_H_ */ diff --git a/lib/ultralib/include/PR/os_exception.h b/lib/ultralib/include/PR/os_exception.h new file mode 100644 index 0000000..2457bde --- /dev/null +++ b/lib/ultralib/include/PR/os_exception.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_exception.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_exception.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:07 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EXCEPTION_H_ +#define _OS_EXCEPTION_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +typedef u32 OSIntMask; +typedef u32 OSHWIntr; + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/* Flags for debugging purpose */ + +#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ +#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ + +/* Interrupt masks */ + +#define OS_IM_NONE 0x00000001 +#define OS_IM_RCP 0x00000401 +#define OS_IM_SW1 0x00000501 +#define OS_IM_SW2 0x00000601 +#define OS_IM_CART 0x00000c01 +#define OS_IM_PRENMI 0x00001401 +#define OS_IM_RDBWRITE 0x00002401 +#define OS_IM_RDBREAD 0x00004401 +#define OS_IM_COUNTER 0x00008401 +#define OS_IM_CPU 0x0000ff01 +#define OS_IM_SP 0x00010401 +#define OS_IM_SI 0x00020401 +#define OS_IM_AI 0x00040401 +#define OS_IM_VI 0x00080401 +#define OS_IM_PI 0x00100401 +#define OS_IM_DP 0x00200401 +#define OS_IM_ALL 0x003fff01 +#define RCP_IMASK 0x003f0000 +#define RCP_IMASKSHIFT 16 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Interrupt operations */ + +extern OSIntMask osGetIntMask(void); +extern OSIntMask osSetIntMask(OSIntMask); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EXCEPTION_H_ */ diff --git a/lib/ultralib/include/PR/os_flash.h b/lib/ultralib/include/PR/os_flash.h new file mode 100644 index 0000000..9eb0bf7 --- /dev/null +++ b/lib/ultralib/include/PR/os_flash.h @@ -0,0 +1,77 @@ +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_flash.h,v $ + $Revision: 1.1 $ + $Date: 2000/06/15 06:24:55 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_FLASH_H_ +#define _OS_FLASH_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" +#include "os_pi.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* + * defines for FLASH + */ +#define FLASH_START_ADDR 0x08000000 + +#define FLASH_SIZE 0x20000 + +#define FLASH_LATENCY 0x5 +#define FLASH_PULSE 0x0c +#define FLASH_PAGE_SIZE 0xf +#define FLASH_REL_DURATION 0x2 +#define DEVICE_TYPE_FLASH 8 + +#define FLASH_VERSION_MX_PROTO_A 0x00c20000 +#define FLASH_VERSION_MX_A 0x00c20001 +#define FLASH_VERSION_MX_C 0x00c2001e +#define FLASH_VERSION_MX_B_AND_D 0x00c2001d +#define FLASH_VERSION_MEI 0x003200f1 + +/* OLD_FLASH is MX_PROTO_A, MX_A and MX_C */ +#define OLD_FLASH 0 +/* NEW_FLASH is MX_B_AND_D and MATSUSHITA flash */ +#define NEW_FLASH 1 + +#define FLASH_STATUS_ERASE_BUSY 2 +#define FLASH_STATUS_ERASE_OK 0 +#define FLASH_STATUS_ERASE_ERROR -1 + +#define FLASH_STATUS_WRITE_BUSY 1 +#define FLASH_STATUS_WRITE_OK 0 +#define FLASH_STATUS_WRITE_ERROR -1 + +extern OSPiHandle *osFlashReInit(u8 latency, u8 pulse, + u8 page_size, u8 rel_duration, u32 start); +extern OSPiHandle *osFlashInit(void); +extern void osFlashReadStatus(u8 *flash_status); +extern void osFlashReadId(u32 *flash_type, u32 *flash_maker); +extern void osFlashClearStatus(void); +extern s32 osFlashAllErase(void); +extern s32 osFlashSectorErase(u32 page_num); +extern s32 osFlashWriteBuffer(OSIoMesg *mb, s32 priority, + void *dramAddr, OSMesgQueue *mq); +extern s32 osFlashWriteArray(u32 page_num); +extern s32 osFlashReadArray(OSIoMesg *mb, s32 priority, u32 page_num, + void *dramAddr, u32 n_pages, OSMesgQueue *mq); +extern void osFlashChange(u32 flash_num); +extern void osFlashAllEraseThrough(void); +extern void osFlashSectorEraseThrough(u32 page_num); +extern s32 osFlashCheckEraseEnd(void); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_FLASH_H_ */ diff --git a/lib/ultralib/include/PR/os_gbpak.h b/lib/ultralib/include/PR/os_gbpak.h new file mode 100644 index 0000000..0a99994 --- /dev/null +++ b/lib/ultralib/include/PR/os_gbpak.h @@ -0,0 +1,107 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_gbpak.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:07 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_GBPAK_H_ +#define _OS_GBPAK_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" +#include "os_pfs.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef struct { + u16 fixed1; + u16 start_address; + u8 nintendo_chr[0x30]; + u8 game_title[16]; + u16 company_code; + u8 body_code; + u8 cart_type; + u8 rom_size; + u8 ram_size; + u8 country_code; + u8 fixed2; + u8 version; + u8 isum; + u16 sum; +} OSGbpakId; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* definition for 64GB-PAK */ + +#define OS_GBPAK_POWER 0x01 +#define OS_GBPAK_RSTB_DETECTION 0x04 +#define OS_GBPAK_RSTB_STATUS 0x08 +#define OS_GBPAK_GBCART_PULL 0x40 +#define OS_GBPAK_GBCART_ON 0x80 + +#define OS_GBPAK_POWER_OFF 0x00 /* power of 64GB-PAK */ +#define OS_GBPAK_POWER_ON 0x01 + +#define OS_GBPAK_ROM_ID_SIZE 0x50 /* ID size of GB cartridge */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* 64GB-PAK */ +extern s32 osGbpakInit(OSMesgQueue *, OSPfs *, int); +extern s32 osGbpakPower(OSPfs *, s32); +extern s32 osGbpakGetStatus(OSPfs *, u8 *); +extern s32 osGbpakReadWrite(OSPfs *, u16, u16, u8 *, u16); +extern s32 osGbpakReadId(OSPfs *, OSGbpakId *, u8 *); +extern s32 osGbpakCheckConnector(OSPfs *, u8 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_GBPAK_H_ */ diff --git a/lib/ultralib/include/PR/os_gio.h b/lib/ultralib/include/PR/os_gio.h new file mode 100644 index 0000000..ad3c020 --- /dev/null +++ b/lib/ultralib/include/PR/os_gio.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_gio.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_gio.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:08 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_GIO_H_ +#define _OS_GIO_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_GIO_H_ */ diff --git a/lib/ultralib/include/PR/os_host.h b/lib/ultralib/include/PR/os_host.h new file mode 100644 index 0000000..3192f6a --- /dev/null +++ b/lib/ultralib/include/PR/os_host.h @@ -0,0 +1,166 @@ + +/*==================================================================== + * os_host.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_host.h,v $ + $Revision: 1.3 $ + $Date: 1999/06/24 09:23:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_HOST_H_ +#define _OS_HOST_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +extern void __osInitialize_common(void); + +#if defined(_FINALROM) + +#define osInitialize() __osInitialize_common() + +#else + +/* PARTNER-N64 */ +#if defined(PTN64) +extern void __osInitialize_kmc(void); +#define osReadHost osReadHost_pt +#define osWriteHost osWriteHost_pt +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_kmc(); \ +} + +/* MONEGI SMART PACK A */ +#elif defined(MWN64) +extern void __osInitialize_msp(void); +#define osReadHost osReadHost_pt +#define osWriteHost osWriteHost_pt +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_msp(); \ +} + +/* IS-Viewer(for Debugger) */ +#elif defined(ISV64) +extern void __osInitialize_isv(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_isv(); \ +} + +/* Emulation board for INDY */ +#elif defined(EMU64) +extern void __osInitialize_emu(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_emu(); \ +} + +#else +/* Default (auto detect) */ +extern void __osInitialize_autodetect(void); +extern void __osInitialize_msp(void); +extern void __osInitialize_kmc(void); +extern void __osInitialize_isv(void); +extern void __osInitialize_emu(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_autodetect(); \ +} +#endif + +#endif /* _FINAL_ROM */ + +#if BUILD_VERSION < VERSION_K +#undef osInitialize +#endif + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Game <> Host data transfer functions */ + +extern s32 osTestHost(void); +extern void osReadHost(void *, u32); +extern void osWriteHost(void *, u32); +extern void osAckRamromRead(void); +extern void osAckRamromWrite(void); + +/* RDB port operations */ + +extern void osInitRdb(u8 *sendBuf, u32 sendSize); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_HOST_H_ */ diff --git a/lib/ultralib/include/PR/os_internal.h b/lib/ultralib/include/PR/os_internal.h new file mode 100644 index 0000000..754d1ee --- /dev/null +++ b/lib/ultralib/include/PR/os_internal.h @@ -0,0 +1,49 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal.h,v $ + $Revision: 1.20 $ + $Date: 1998/10/09 08:01:09 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_H_ +#define _OS_INTERNAL_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +#include "os_internal_reg.h" +#include "os_internal_exception.h" +#include "os_internal_tlb.h" +#include "os_internal_si.h" +#include "os_internal_rsp.h" +#include "os_internal_error.h" +#include "os_internal_gio.h" +#include "os_internal_thread.h" +#include "os_internal_debug.h" +#include "os_internal_host.h" + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_H */ diff --git a/lib/ultralib/include/PR/os_internal_debug.h b/lib/ultralib/include/PR/os_internal_debug.h new file mode 100644 index 0000000..7b307d6 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_debug.h @@ -0,0 +1,43 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_debug.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:09 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_DEBUG_H_ +#define _OS_INTERNAL_DEBUG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Debug port */ +extern void __osSyncPutChars(int, int, const char *); +extern int __osAtomicDec(unsigned int *p); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_DEBUG_H */ diff --git a/lib/ultralib/include/PR/os_internal_error.h b/lib/ultralib/include/PR/os_internal_error.h new file mode 100644 index 0000000..de188d2 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_error.h @@ -0,0 +1,45 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_error.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:10 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_ERROR_H_ +#define _OS_INTERNAL_ERROR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Error handling */ + +extern void __osError(s16, s16, ...); +extern OSThread * __osGetCurrFaultedThread(void); +extern OSThread * __osGetNextFaultedThread(OSThread *); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_ERROR_H */ diff --git a/lib/ultralib/include/PR/os_internal_exception.h b/lib/ultralib/include/PR/os_internal_exception.h new file mode 100644 index 0000000..dae8a9f --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_exception.h @@ -0,0 +1,57 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_exception.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:10 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_EXCEPTION_H_ +#define _OS_INTERNAL_EXCEPTION_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "os.h" +#include "os_version.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Routine for HW interrupt "handler" */ +#if BUILD_VERSION >= VERSION_J +extern void __osSetHWIntrRoutine(OSHWIntr interrupt, + s32 (*handler)(void), void *stackEnd); +extern void __osGetHWIntrRoutine(OSHWIntr interrupt, + s32 (**handler)(void), void **stackEnd); +#else +extern void __osSetHWIntrRoutine(OSHWIntr interrupt, + s32 (*handler)(void)); +extern void __osGetHWIntrRoutine(OSHWIntr interrupt, + s32 (**handler)(void)); +#endif + +/* Routine for global interrupt mask */ +extern void __osSetGlobalIntMask(OSHWIntr); +extern void __osResetGlobalIntMask(OSHWIntr); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_EXCEPTION_H */ diff --git a/lib/ultralib/include/PR/os_internal_flash.h b/lib/ultralib/include/PR/os_internal_flash.h new file mode 100644 index 0000000..1c6f780 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_flash.h @@ -0,0 +1,40 @@ +#ifndef _OS_INTERNAL_FLASH_H_ +#define _OS_INTERNAL_FLASH_H_ + +#include "os_message.h" +#include "os_flash.h" + +#define FLASH_BLOCK_SIZE 128 + +/** + * Flash commands + */ +#define FLASH_CMD_REG 0x10000 + +/* set whole chip erase mode */ +#define FLASH_CMD_CHIP_ERASE 0x3C000000 +/* set sector erase mode */ +#define FLASH_CMD_SECTOR_ERASE 0x4B000000 +/* do erasure */ +#define FLASH_CMD_EXECUTE_ERASE 0x78000000 +/* program selected page */ +#define FLASH_CMD_PROGRAM_PAGE 0xA5000000 +/* set page program mode */ +#define FLASH_CMD_PAGE_PROGRAM 0xB4000000 +/* set status mode */ +#define FLASH_CMD_STATUS 0xD2000000 +/* set silicon id mode */ +#define FLASH_CMD_ID 0xE1000000 +/* set read mode */ +#define FLASH_CMD_READ_ARRAY 0xF0000000 + +extern OSIoMesg __osFlashMsg; +extern OSMesgQueue __osFlashMessageQ; +extern OSPiHandle __osFlashHandler; +extern OSMesg __osFlashMsgBuf[1]; +extern s32 __osFlashVersion; +extern u32 __osFlashID[4]; + +u32 __osFlashGetAddr(u32 page_num); + +#endif diff --git a/lib/ultralib/include/PR/os_internal_gio.h b/lib/ultralib/include/PR/os_internal_gio.h new file mode 100644 index 0000000..ff13385 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_gio.h @@ -0,0 +1,45 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_gio.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:11 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_GIO_H_ +#define _OS_INTERNAL_GIO_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Development board functions */ + +extern void __osGIOInit(s32); +extern void __osGIOInterrupt(s32); +extern void __osGIORawInterrupt(s32); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_GIO_H */ diff --git a/lib/ultralib/include/PR/os_internal_host.h b/lib/ultralib/include/PR/os_internal_host.h new file mode 100644 index 0000000..b6d1951 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_host.h @@ -0,0 +1,42 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_host.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:11 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_HOST_H_ +#define _OS_INTERNAL_HOST_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* routine for rdb port */ +extern u32 __osRdbSend(u8 *buf, u32 size, u32 type); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_HOST_H */ diff --git a/lib/ultralib/include/PR/os_internal_reg.h b/lib/ultralib/include/PR/os_internal_reg.h new file mode 100644 index 0000000..206b721 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_reg.h @@ -0,0 +1,57 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_reg.h,v $ + $Revision: 1.2 $ + $Date: 1999/03/10 12:19:14 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_REG_H_ +#define _OS_INTERNAL_REG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "os.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Routines to get/fetch coprocessor 0 registers */ +extern u32 __osGetCause(void); +extern void __osSetCause(u32); +extern u32 __osGetCompare(void); +extern void __osSetCompare(u32); +extern u32 __osGetConfig(void); +extern void __osSetConfig(u32); +extern void __osSetCount(u32); +extern u32 __osGetSR(void); +extern void __osSetSR(u32); +extern u32 __osDisableInt(void); +extern void __osRestoreInt(u32); +extern u32 __osGetWatchLo(void); +extern void __osSetWatchLo(u32); + +/* Routines to get/set floating-point control and status register */ +extern u32 __osSetFpcCsr(u32); +extern u32 __osGetFpcCsr(void); + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_REG_H */ diff --git a/lib/ultralib/include/PR/os_internal_rsp.h b/lib/ultralib/include/PR/os_internal_rsp.h new file mode 100644 index 0000000..646e667 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_rsp.h @@ -0,0 +1,48 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_rsp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:12 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_RSP_H_ +#define _OS_INTERNAL_RSP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Signal processor interface (Sp) */ + +extern u32 __osSpGetStatus(void); +extern void __osSpSetStatus(u32); +extern s32 __osSpSetPc(u32); +extern s32 __osSpRawWriteIo(u32, u32); +extern s32 __osSpRawReadIo(u32, u32 *); +extern s32 __osSpRawStartDma(s32, u32, void *, u32); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_RSP_H */ diff --git a/lib/ultralib/include/PR/os_internal_si.h b/lib/ultralib/include/PR/os_internal_si.h new file mode 100644 index 0000000..d0eeedc --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_si.h @@ -0,0 +1,46 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_si.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:13 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_SI_H_ +#define _OS_INTERNAL_SI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Serial interface (Si) */ + +extern u32 __osSiGetStatus(void); +extern s32 __osSiRawWriteIo(u32, u32); +extern s32 __osSiRawReadIo(u32, u32 *); +extern s32 __osSiRawStartDma(s32, void *); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_SI_H */ diff --git a/lib/ultralib/include/PR/os_internal_thread.h b/lib/ultralib/include/PR/os_internal_thread.h new file mode 100644 index 0000000..1305eb5 --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_thread.h @@ -0,0 +1,43 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_thread.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:13 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_THREAD_H_ +#define _OS_INTERNAL_THREAD_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* For debugger use */ + +extern OSThread * __osGetActiveQueue(void); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_THREAD_H */ diff --git a/lib/ultralib/include/PR/os_internal_tlb.h b/lib/ultralib/include/PR/os_internal_tlb.h new file mode 100644 index 0000000..b92918f --- /dev/null +++ b/lib/ultralib/include/PR/os_internal_tlb.h @@ -0,0 +1,47 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_tlb.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:14 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_TLB_H_ +#define _OS_INTERNAL_TLB_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Routines for fetch TLB info */ + +extern u32 __osGetTLBASID(void); +extern u32 __osGetTLBPageMask(s32); +extern u32 __osGetTLBHi(s32); +extern u32 __osGetTLBLo0(s32); +extern u32 __osGetTLBLo1(s32); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_TLB_H */ diff --git a/lib/ultralib/include/PR/os_libc.h b/lib/ultralib/include/PR/os_libc.h new file mode 100644 index 0000000..35d0e8e --- /dev/null +++ b/lib/ultralib/include/PR/os_libc.h @@ -0,0 +1,100 @@ + +/*==================================================================== + * os_libc.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_libc.h,v $ + $Revision: 1.3 $ + $Date: 1999/07/13 01:43:47 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_LIBC_H_ +#define _OS_LIBC_H_ + +#include "os_pfs.h" + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* byte string operations */ + + +extern void bcopy(const void *, void *, int); +extern int bcmp(const void *, const void *, int); +extern void bzero(void *, int); + +/* Printf */ + +extern int sprintf(char *s, const char *fmt, ...); +extern void osSyncPrintf(const char *fmt, ...); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_LIBC_H_ */ diff --git a/lib/ultralib/include/PR/os_message.h b/lib/ultralib/include/PR/os_message.h new file mode 100644 index 0000000..606c5cb --- /dev/null +++ b/lib/ultralib/include/PR/os_message.h @@ -0,0 +1,162 @@ + +/*==================================================================== + * os_message.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_message.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:15 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_MESSAGE_H_ +#define _OS_MESSAGE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" +#include "os_thread.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSEvent; + +/* + * Structure for message + */ +typedef void *OSMesg; + +/* + * Structure for message queue + */ +typedef struct OSMesgQueue_s { + OSThread *mtqueue; /* Queue to store threads blocked on empty mailboxes (receive) */ + OSThread *fullqueue; /* Queue to store threads blocked on full mailboxes (send) */ + s32 validCount; /* Contains number of valid message */ + s32 first; /* Points to first valid message */ + s32 msgCount; /* Contains total # of messages */ + OSMesg *msg; /* Points to message buffer array */ +} OSMesgQueue; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Events */ +#ifdef _FINALROM +#define OS_NUM_EVENTS 15 +#else +#define OS_NUM_EVENTS 23 +#endif + +#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ +#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ +#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ +#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ +#define OS_EVENT_SP 4 /* SP task done interrupt */ +#define OS_EVENT_SI 5 /* SI (controller) interrupt */ +#define OS_EVENT_AI 6 /* AI interrupt */ +#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ +#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ +#define OS_EVENT_DP 9 /* DP full sync interrupt */ +#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ +#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ +#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ +#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ +#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ +#ifndef _FINALROM +#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ +#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ +#define OS_EVENT_RDB_DATA_DONE 17 /* read of hostio data complete */ +#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ +#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ +#define OS_EVENT_RDB_DBG_DONE 20 +#define OS_EVENT_RDB_FLUSH_PROF 21 +#define OS_EVENT_RDB_ACK_PROF 22 +#endif + +/* Flags to turn blocking on/off when sending/receiving message */ + +#define OS_MESG_NOBLOCK 0 +#define OS_MESG_BLOCK 1 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* Get count of valid messages in queue */ +#define MQ_GET_COUNT(mq) ((mq)->validCount) + +/* Figure out if message queue is empty or full */ +#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) +#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Message operations */ + +extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32); +extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); + +/* Event operations */ + +extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_MESSAGE_H_ */ diff --git a/lib/ultralib/include/PR/os_motor.h b/lib/ultralib/include/PR/os_motor.h new file mode 100644 index 0000000..2edb8e6 --- /dev/null +++ b/lib/ultralib/include/PR/os_motor.h @@ -0,0 +1,84 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_motor.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:15 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_MOTOR_H_ +#define _OS_MOTOR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" +#include "os_pfs.h" +#include "os_version.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Rumble PAK interface */ + +extern s32 osMotorInit(OSMesgQueue *, OSPfs *, int); +#if BUILD_VERSION >= VERSION_J +#define MOTOR_START 1 +#define MOTOR_STOP 0 +#define osMotorStart(x) __osMotorAccess((x), MOTOR_START) +#define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP) +extern s32 __osMotorAccess(OSPfs *, s32); +#else +extern s32 osMotorStop(OSPfs *); +extern s32 osMotorStart(OSPfs *); +#endif + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_MOTOR_H_ */ diff --git a/lib/ultralib/include/PR/os_pfs.h b/lib/ultralib/include/PR/os_pfs.h new file mode 100644 index 0000000..9c86e23 --- /dev/null +++ b/lib/ultralib/include/PR/os_pfs.h @@ -0,0 +1,200 @@ + +/*==================================================================== + * os_pfs.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_pfs.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_PFS_H_ +#define _OS_PFS_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for file system + */ +typedef struct { + int status; + OSMesgQueue *queue; + int channel; + u8 id[32]; + u8 label[32]; + int version; + int dir_size; + int inode_table; /* block location */ + int minode_table; /* mirrioring inode_table */ + int dir_table; /* block location */ + int inode_start_page; /* page # */ + u8 banks; + u8 activebank; +} OSPfs; + +typedef struct { + u32 file_size; /* bytes */ + u32 game_code; + u16 company_code; + char ext_name[4]; + char game_name[16]; +} OSPfsState; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +/* File System size */ +#define OS_PFS_VERSION 0x0200 +#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) +#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) + +#define PFS_INODE_SIZE_PER_PAGE 128 +#define PFS_FILE_NAME_LEN 16 +#define PFS_FILE_EXT_LEN 4 +#define BLOCKSIZE 32 /* bytes */ +#define PFS_ONE_PAGE 8 /* blocks */ +#define PFS_MAX_BANKS 62 + +/* File System flag */ + +#define PFS_READ 0 +#define PFS_WRITE 1 +#define PFS_CREATE 2 + +/* File System status */ +#define PFS_INITIALIZED 0x1 +#define PFS_CORRUPTED 0x2 +#define PFS_ID_BROKEN 0x4 +#define PFS_MOTOR_INITIALIZED 0x8 +#define PFS_GBPAK_INITIALIZED 0x10 + +/* Definition for page usage */ +#define PFS_EOF 1 +#define PFS_PAGE_NOT_EXIST 2 +#define PFS_PAGE_NOT_USED 3 + +/* File System error number */ + +#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ +#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a different one */ +#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker*/ +#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR +#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ +#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ +#define PFS_DATA_FULL 7 /* no free pages on ram pack*/ +#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ +#define PFS_ERR_EXIST 9 /* file exists*/ +#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ +#define PFS_ERR_DEVICE 11 /* wrong device type*/ +#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ +#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ + +/* Definition for bank */ +#define PFS_ID_BANK_256K 0 +#define PFS_ID_BANK_1M 4 +#define PFS_BANKS_256K 1 + +#define PFS_WRITTEN 2 +#define DEF_DIR_PAGES 2 + +#define PFS_ID_0AREA 1 +#define PFS_ID_1AREA 3 +#define PFS_ID_2AREA 4 +#define PFS_ID_3AREA 6 +#define PFS_LABEL_AREA 7 +#define PFS_ID_PAGE PFS_ONE_PAGE * 0 + +#define PFS_BANK_LAPPED_BY 8 /* => u8 */ +#define PFS_SECTOR_PER_BANK 32 +#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK) +#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE/PFS_SECTOR_PER_BANK) + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* file system interface */ + +extern s32 osPfsInitPak(OSMesgQueue *, OSPfs *, int); +extern s32 osPfsRepairId(OSPfs *); +extern s32 osPfsInit(OSMesgQueue *, OSPfs *, int); +extern s32 osPfsReFormat(OSPfs *, OSMesgQueue *, int); +extern s32 osPfsChecker(OSPfs *); +extern s32 osPfsAllocateFile(OSPfs *, u16, u32, u8 *, u8 *, int, s32 *); +extern s32 osPfsFindFile(OSPfs *, u16, u32, u8 *, u8 *, s32 *); +extern s32 osPfsDeleteFile(OSPfs *, u16, u32, u8 *, u8 *); +extern s32 osPfsReadWriteFile(OSPfs *, s32, u8, int, int, u8 *); +extern s32 osPfsFileState(OSPfs *, s32, OSPfsState *); +extern s32 osPfsGetLabel(OSPfs *, u8 *, int *); +extern s32 osPfsSetLabel(OSPfs *, u8 *); +extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); +extern s32 osPfsFreeBlocks(OSPfs *, s32 *); +extern s32 osPfsNumFiles(OSPfs *, s32 *, s32 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_PFS_H_ */ diff --git a/lib/ultralib/include/PR/os_pi.h b/lib/ultralib/include/PR/os_pi.h new file mode 100644 index 0000000..f408d6c --- /dev/null +++ b/lib/ultralib/include/PR/os_pi.h @@ -0,0 +1,221 @@ + +/*==================================================================== + * os_pi.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_pi.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_PI_H_ +#define _OS_PI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" +#include "os_thread.h" +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for Enhanced PI interface + */ + +/* + * OSTranxInfo is set up for Leo Disk DMA. This info will be maintained + * by exception handler. This is how the PIMGR and the ISR communicate. + */ + +typedef struct { + u32 errStatus; /* error status */ + void *dramAddr; /* RDRAM buffer address (DMA) */ + void *C2Addr; /* C2 buffer address */ + u32 sectorSize; /* size of transfering sector */ + u32 C1ErrNum; /* total # of C1 errors */ + u32 C1ErrSector[4]; /* error sectors */ +} __OSBlockInfo; + +typedef struct { + u32 cmdType; /* for disk only */ + u16 transferMode; /* Block, Track, or sector? */ + u16 blockNum; /* which block is transfering */ + s32 sectorNum; /* which sector is transfering */ + u32 devAddr; /* Device buffer address */ + u32 bmCtlShadow; /* asic bm_ctl(510) register shadow ram */ + u32 seqCtlShadow; /* asic seq_ctl(518) register shadow ram */ + __OSBlockInfo block[2]; /* bolck transfer info */ +} __OSTranxInfo; + + +typedef struct OSPiHandle_s { + struct OSPiHandle_s *next; /* point to next handle on the table */ + u8 type; /* DEVICE_TYPE_BULK for disk */ + u8 latency; /* domain latency */ + u8 pageSize; /* domain page size */ + u8 relDuration; /* domain release duration */ + u8 pulse; /* domain pulse width */ + u8 domain; /* which domain */ + u32 baseAddress; /* Domain address */ + u32 speed; /* for roms only */ + /* The following are "private" elements" */ + __OSTranxInfo transferInfo; /* for disk only */ +} OSPiHandle; + +typedef struct { + u8 type; + u32 address; +} OSPiInfo; + +/* + * Structure for I/O message block + */ +typedef struct { + u16 type; /* Message type */ + u8 pri; /* Message priority (High or Normal) */ + u8 status; /* Return status */ + OSMesgQueue *retQueue; /* Return message queue to notify I/O completion */ +} OSIoMesgHdr; + +typedef struct { + OSIoMesgHdr hdr; /* Message header */ + void *dramAddr; /* RDRAM buffer address (DMA) */ + u32 devAddr; /* Device buffer address (DMA) */ + u32 size; /* DMA transfer size in bytes */ + OSPiHandle *piHandle; /* PI device handle */ +} OSIoMesg; + +/* + * Structure for device manager block + */ +typedef struct { + s32 active; /* Status flag */ + OSThread *thread; /* Calling thread */ + OSMesgQueue *cmdQueue; /* Command queue */ + OSMesgQueue *evtQueue; /* Event queue */ + OSMesgQueue *acsQueue; /* Access queue */ + /* Raw DMA routine */ + s32 (*dma)(s32, u32, void *, u32); + s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); +} OSDevMgr; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Flags to indicate direction of data transfer */ + +#define OS_READ 0 /* device -> RDRAM */ +#define OS_WRITE 1 /* device <- RDRAM */ +#define OS_OTHERS 2 /* for Leo disk only */ + +/* + * I/O message types + */ +#define OS_MESG_TYPE_BASE (10) +#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE + 0) +#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE + 1) +#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE + 2) +#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE + 3) +#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE + 4) +#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE + 5) +#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE + 6) + +/* + * I/O message priority + */ +#define OS_MESG_PRI_NORMAL 0 +#define OS_MESG_PRI_HIGH 1 + +/* + * PI/EPI + */ +#define PI_DOMAIN1 0 +#define PI_DOMAIN2 1 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +extern u32 osPiGetStatus(void); +extern s32 osPiGetDeviceType(void); +extern s32 osPiWriteIo(u32, u32); +extern s32 osPiReadIo(u32, u32 *); +extern s32 osPiStartDma(OSIoMesg *, s32, s32, u32, void *, u32, OSMesgQueue *); +extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32); + +/* Enhanced PI interface */ + +extern OSPiHandle *osCartRomInit(void); +extern OSPiHandle *osLeoDiskInit(void); +extern OSPiHandle *osDriveRomInit(void); + +extern s32 osEPiDeviceType(OSPiHandle *, OSPiInfo *); +extern s32 osEPiWriteIo(OSPiHandle *, u32 , u32 ); +extern s32 osEPiReadIo(OSPiHandle *, u32 , u32 *); +extern s32 osEPiStartDma(OSPiHandle *, OSIoMesg *, s32); +extern s32 osEPiLinkHandle(OSPiHandle *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_PI_H_ */ diff --git a/lib/ultralib/include/PR/os_rdp.h b/lib/ultralib/include/PR/os_rdp.h new file mode 100644 index 0000000..6b3d288 --- /dev/null +++ b/lib/ultralib/include/PR/os_rdp.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_rdp.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_rdp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_RDP_H_ +#define _OS_RDP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Display processor interface (Dp) */ +extern u32 osDpGetStatus(void); +extern void osDpSetStatus(u32); +extern void osDpGetCounters(u32 *); +extern s32 osDpSetNextBuffer(void *, u64); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_RDP_H_ */ diff --git a/lib/ultralib/include/PR/os_reg.h b/lib/ultralib/include/PR/os_reg.h new file mode 100644 index 0000000..50aa218 --- /dev/null +++ b/lib/ultralib/include/PR/os_reg.h @@ -0,0 +1,90 @@ + +/*==================================================================== + * os_reg.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_reg.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:17 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_REG_H_ +#define _OS_REG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Miscellaneous operations */ + +extern u32 osGetCount(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_REG_H_ */ diff --git a/lib/ultralib/include/PR/os_rsp.h b/lib/ultralib/include/PR/os_rsp.h new file mode 100644 index 0000000..1211605 --- /dev/null +++ b/lib/ultralib/include/PR/os_rsp.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_rsp.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_rsp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:17 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_RSP_H_ +#define _OS_RSP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_RSP_H_ */ diff --git a/lib/ultralib/include/PR/os_si.h b/lib/ultralib/include/PR/os_si.h new file mode 100644 index 0000000..23b07c0 --- /dev/null +++ b/lib/ultralib/include/PR/os_si.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_si.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_si.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:18 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_SI_H_ +#define _OS_SI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_SI_H_ */ diff --git a/lib/ultralib/include/PR/os_system.h b/lib/ultralib/include/PR/os_system.h new file mode 100644 index 0000000..1179189 --- /dev/null +++ b/lib/ultralib/include/PR/os_system.h @@ -0,0 +1,118 @@ + +/*==================================================================== + * os_system.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_system.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:18 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_SYSTEM_H_ +#define _OS_SYSTEM_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Values for osTvType + */ +#define OS_TV_PAL 0 +#define OS_TV_NTSC 1 +#define OS_TV_MPAL 2 + +/* + * Size of buffer the retains contents after NMI + */ +#define OS_APP_NMI_BUFSIZE 64 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */ +extern void *osRomBase; /* Rom base address of the game image */ +extern s32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */ +extern s32 osResetType; /* 0 = cold reset, 1 = NMI */ +extern s32 osCicId; +extern s32 osVersion; +extern u32 osMemSize; /* Memory Size */ +extern s32 osAppNMIBuffer[]; + +extern u64 osClockRate; + +extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +extern void osInitialize(void); +extern void osExit(void); +extern u32 osGetMemSize(void); + +/* pre-NMI */ +extern s32 osAfterPreNMI(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_SYSTEM_H_ */ diff --git a/lib/ultralib/include/PR/os_thread.h b/lib/ultralib/include/PR/os_thread.h new file mode 100644 index 0000000..68c8e74 --- /dev/null +++ b/lib/ultralib/include/PR/os_thread.h @@ -0,0 +1,161 @@ + +/*==================================================================== + * os_thread.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_thread.h,v $ + $Revision: 1.3 $ + $Date: 1999/06/15 12:39:40 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_THREAD_H_ +#define _OS_THREAD_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef s32 OSPri; +typedef s32 OSId; + +typedef union { + struct { + f32 f_odd; + f32 f_even; + } f; + f64 d; +} __OSfp; + +typedef struct { + u64 at, v0, v1, a0, a1, a2, a3; + u64 t0, t1, t2, t3, t4, t5, t6, t7; + u64 s0, s1, s2, s3, s4, s5, s6, s7; + u64 t8, t9; + u64 gp, sp, s8, ra; + u64 lo, hi; + u32 sr, pc, cause, badvaddr, rcp; + u32 fpcsr; + __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; + __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; +} __OSThreadContext; + +typedef struct { + u32 flag; + u32 count; + u64 time; +} __OSThreadprofile_s; + +typedef struct OSThread_s { + struct OSThread_s *next; /* run/mesg queue link */ + OSPri priority; /* run/mesg queue priority */ + struct OSThread_s **queue; /* queue thread is on */ + struct OSThread_s *tlnext; /* all threads queue link */ + u16 state; /* OS_STATE_* */ + u16 flags; /* flags for rmon */ + OSId id; /* id for debugging */ + int fp; /* thread has used fp unit */ + __OSThreadprofile_s *thprof; /* workarea for thread profiler */ + __OSThreadContext context; /* register/interrupt mask */ +} OSThread; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Thread states */ + +#define OS_STATE_STOPPED (1 << 0) +#define OS_STATE_RUNNABLE (1 << 1) +#define OS_STATE_RUNNING (1 << 2) +#define OS_STATE_WAITING (1 << 3) + +/* Recommended thread priorities for the system threads */ + +#define OS_PRIORITY_MAX 255 +#define OS_PRIORITY_VIMGR 254 +#define OS_PRIORITY_RMON 250 +#define OS_PRIORITY_RMONSPIN 200 +#define OS_PRIORITY_PIMGR 150 +#define OS_PRIORITY_SIMGR 140 +#define OS_PRIORITY_APPMAX 127 +#define OS_PRIORITY_IDLE 0 /* Must be 0 */ + +/* For thread profiler */ +#define THPROF_IDMAX 64 +#define THPROF_STACKSIZE 256 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Thread operations */ + +extern void osCreateThread(OSThread *, OSId, void (*)(void *), void *, void *, OSPri); +extern void osDestroyThread(OSThread *); +extern void osYieldThread(void); +extern void osStartThread(OSThread *); +extern void osStopThread(OSThread *); +extern OSId osGetThreadId(OSThread *); +extern void osSetThreadPri(OSThread *, OSPri); +extern OSPri osGetThreadPri(OSThread *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_THREAD_H_ */ diff --git a/lib/ultralib/include/PR/os_time.h b/lib/ultralib/include/PR/os_time.h new file mode 100644 index 0000000..deaec65 --- /dev/null +++ b/lib/ultralib/include/PR/os_time.h @@ -0,0 +1,114 @@ + +/*==================================================================== + * os_time.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_time.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:19 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_TIME_H_ +#define _OS_TIME_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for time value + */ +typedef u64 OSTime; + +/* + * Structure for interval timer + */ +typedef struct OSTimer_s { + struct OSTimer_s *next; /* point to next timer in list */ + struct OSTimer_s *prev; /* point to previous timer in list */ + OSTime interval; /* duration set by user */ + OSTime value; /* time remaining before */ + /* timer fires */ + OSMesgQueue *mq; /* Message Queue */ + OSMesg msg; /* Message to send */ +} OSTimer; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Timer interface */ + +extern OSTime osGetTime(void); +extern void osSetTime(OSTime); +extern int osSetTimer(OSTimer *, OSTime, OSTime, + OSMesgQueue *, OSMesg); +extern int osStopTimer(OSTimer *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_TIME_H_ */ diff --git a/lib/ultralib/include/PR/os_tlb.h b/lib/ultralib/include/PR/os_tlb.h new file mode 100644 index 0000000..2cdd5c9 --- /dev/null +++ b/lib/ultralib/include/PR/os_tlb.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_tlb.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_tlb.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:20 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_TLB_H_ +#define _OS_TLB_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSPageMask; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Page size argument for TLB routines + */ +#define OS_PM_4K 0x0000000 +#define OS_PM_16K 0x0006000 +#define OS_PM_64K 0x001e000 +#define OS_PM_256K 0x007e000 +#define OS_PM_1M 0x01fe000 +#define OS_PM_4M 0x07fe000 +#define OS_PM_16M 0x1ffe000 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* TLB management routines */ + +extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); +extern void osMapTLBRdb(void); +extern void osUnmapTLB(s32); +extern void osUnmapTLBAll(void); +extern void osSetTLBASID(s32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_TLB_H_ */ diff --git a/lib/ultralib/include/PR/os_version.h b/lib/ultralib/include/PR/os_version.h new file mode 100644 index 0000000..aa10d20 --- /dev/null +++ b/lib/ultralib/include/PR/os_version.h @@ -0,0 +1,26 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_version.h,v $ + $Revision: 1.2 $ + $Date: 1999/06/17 01:33:01 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VERSION_H_ +#define _OS_VERSION_H_ + +#define VERSION_D 1 +#define VERSION_E 2 +#define VERSION_F 3 +#define VERSION_G 4 +#define VERSION_H 5 +#define VERSION_I 6 +#define VERSION_J 7 +#define VERSION_K 8 +#define VERSION_L 9 + +#define OS_MAJOR_VERSION BUILD_VERSION_STRING /* major version */ +#define OS_MINOR_VERSION 0 /* patch level */ + +#endif /* !_OS_VERSION_H_ */ diff --git a/lib/ultralib/include/PR/os_vi.h b/lib/ultralib/include/PR/os_vi.h new file mode 100644 index 0000000..5a17f25 --- /dev/null +++ b/lib/ultralib/include/PR/os_vi.h @@ -0,0 +1,298 @@ + +/*==================================================================== + * os_vi.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_vi.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:20 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VI_H_ +#define _OS_VI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_thread.h" +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure to store VI register values that remain the same between 2 fields + */ +typedef struct { + u32 ctrl; + u32 width; + u32 burst; + u32 vSync; + u32 hSync; + u32 leap; + u32 hStart; + u32 xScale; + u32 vCurrent; +} OSViCommonRegs; + + +/* + * Structure to store VI register values that change between fields + */ +typedef struct { + u32 origin; + u32 yScale; + u32 vStart; + u32 vBurst; + u32 vIntr; +} OSViFieldRegs; + + +/* + * Structure for VI mode + */ +typedef struct { + u8 type; /* Mode type */ + OSViCommonRegs comRegs; /* Common registers for both fields */ + OSViFieldRegs fldRegs[2]; /* Registers for Field 1 & 2 */ +} OSViMode; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Video Interface (VI) mode type + */ +#define OS_VI_NTSC_LPN1 0 /* NTSC */ +#define OS_VI_NTSC_LPF1 1 +#define OS_VI_NTSC_LAN1 2 +#define OS_VI_NTSC_LAF1 3 +#define OS_VI_NTSC_LPN2 4 +#define OS_VI_NTSC_LPF2 5 +#define OS_VI_NTSC_LAN2 6 +#define OS_VI_NTSC_LAF2 7 +#define OS_VI_NTSC_HPN1 8 +#define OS_VI_NTSC_HPF1 9 +#define OS_VI_NTSC_HAN1 10 +#define OS_VI_NTSC_HAF1 11 +#define OS_VI_NTSC_HPN2 12 +#define OS_VI_NTSC_HPF2 13 + +#define OS_VI_PAL_LPN1 14 /* PAL */ +#define OS_VI_PAL_LPF1 15 +#define OS_VI_PAL_LAN1 16 +#define OS_VI_PAL_LAF1 17 +#define OS_VI_PAL_LPN2 18 +#define OS_VI_PAL_LPF2 19 +#define OS_VI_PAL_LAN2 20 +#define OS_VI_PAL_LAF2 21 +#define OS_VI_PAL_HPN1 22 +#define OS_VI_PAL_HPF1 23 +#define OS_VI_PAL_HAN1 24 +#define OS_VI_PAL_HAF1 25 +#define OS_VI_PAL_HPN2 26 +#define OS_VI_PAL_HPF2 27 + +#define OS_VI_MPAL_LPN1 28 /* MPAL - mainly Brazil */ +#define OS_VI_MPAL_LPF1 29 +#define OS_VI_MPAL_LAN1 30 +#define OS_VI_MPAL_LAF1 31 +#define OS_VI_MPAL_LPN2 32 +#define OS_VI_MPAL_LPF2 33 +#define OS_VI_MPAL_LAN2 34 +#define OS_VI_MPAL_LAF2 35 +#define OS_VI_MPAL_HPN1 36 +#define OS_VI_MPAL_HPF1 37 +#define OS_VI_MPAL_HAN1 38 +#define OS_VI_MPAL_HAF1 39 +#define OS_VI_MPAL_HPN2 40 +#define OS_VI_MPAL_HPF2 41 + +#define OS_VI_FPAL_LPN1 42 /* FPAL - Full screen PAL */ +#define OS_VI_FPAL_LPF1 43 +#define OS_VI_FPAL_LAN1 44 +#define OS_VI_FPAL_LAF1 45 +#define OS_VI_FPAL_LPN2 46 +#define OS_VI_FPAL_LPF2 47 +#define OS_VI_FPAL_LAN2 48 +#define OS_VI_FPAL_LAF2 49 +#define OS_VI_FPAL_HPN1 50 +#define OS_VI_FPAL_HPF1 51 +#define OS_VI_FPAL_HAN1 52 +#define OS_VI_FPAL_HAF1 53 +#define OS_VI_FPAL_HPN2 54 +#define OS_VI_FPAL_HPF2 55 + +/* + * Video Interface (VI) special features + */ +#define OS_VI_GAMMA_ON 0x0001 +#define OS_VI_GAMMA_OFF 0x0002 +#define OS_VI_GAMMA_DITHER_ON 0x0004 +#define OS_VI_GAMMA_DITHER_OFF 0x0008 +#define OS_VI_DIVOT_ON 0x0010 +#define OS_VI_DIVOT_OFF 0x0020 +#define OS_VI_DITHER_FILTER_ON 0x0040 +#define OS_VI_DITHER_FILTER_OFF 0x0080 + +/* + * Video Interface (VI) mode attribute bit + */ +#define OS_VI_BIT_NONINTERLACE 0x0001 /* lo-res */ +#define OS_VI_BIT_INTERLACE 0x0002 /* lo-res */ +#define OS_VI_BIT_NORMALINTERLACE 0x0004 /* hi-res */ +#define OS_VI_BIT_DEFLICKINTERLACE 0x0008 /* hi-res */ +#define OS_VI_BIT_ANTIALIAS 0x0010 +#define OS_VI_BIT_POINTSAMPLE 0x0020 +#define OS_VI_BIT_16PIXEL 0x0040 +#define OS_VI_BIT_32PIXEL 0x0080 +#define OS_VI_BIT_LORES 0x0100 +#define OS_VI_BIT_HIRES 0x0200 +#define OS_VI_BIT_NTSC 0x0400 +#define OS_VI_BIT_PAL 0x0800 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern OSViMode osViModeTable[]; /* Global VI mode table */ + +extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */ +extern OSViMode osViModeNtscLpf1; +extern OSViMode osViModeNtscLan1; +extern OSViMode osViModeNtscLaf1; +extern OSViMode osViModeNtscLpn2; +extern OSViMode osViModeNtscLpf2; +extern OSViMode osViModeNtscLan2; +extern OSViMode osViModeNtscLaf2; +extern OSViMode osViModeNtscHpn1; +extern OSViMode osViModeNtscHpf1; +extern OSViMode osViModeNtscHan1; +extern OSViMode osViModeNtscHaf1; +extern OSViMode osViModeNtscHpn2; +extern OSViMode osViModeNtscHpf2; + +extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */ +extern OSViMode osViModePalLpf1; +extern OSViMode osViModePalLan1; +extern OSViMode osViModePalLaf1; +extern OSViMode osViModePalLpn2; +extern OSViMode osViModePalLpf2; +extern OSViMode osViModePalLan2; +extern OSViMode osViModePalLaf2; +extern OSViMode osViModePalHpn1; +extern OSViMode osViModePalHpf1; +extern OSViMode osViModePalHan1; +extern OSViMode osViModePalHaf1; +extern OSViMode osViModePalHpn2; +extern OSViMode osViModePalHpf2; + +extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */ +extern OSViMode osViModeMpalLpf1; +extern OSViMode osViModeMpalLan1; +extern OSViMode osViModeMpalLaf1; +extern OSViMode osViModeMpalLpn2; +extern OSViMode osViModeMpalLpf2; +extern OSViMode osViModeMpalLan2; +extern OSViMode osViModeMpalLaf2; +extern OSViMode osViModeMpalHpn1; +extern OSViMode osViModeMpalHpf1; +extern OSViMode osViModeMpalHan1; +extern OSViMode osViModeMpalHaf1; +extern OSViMode osViModeMpalHpn2; +extern OSViMode osViModeMpalHpf2; + +extern OSViMode osViModeFpalLpn1; /* Individual VI FPAL modes */ +extern OSViMode osViModeFpalLpf1; +extern OSViMode osViModeFpalLan1; +extern OSViMode osViModeFpalLaf1; +extern OSViMode osViModeFpalLpn2; +extern OSViMode osViModeFpalLpf2; +extern OSViMode osViModeFpalLan2; +extern OSViMode osViModeFpalLaf2; +extern OSViMode osViModeFpalHpn1; +extern OSViMode osViModeFpalHpf1; +extern OSViMode osViModeFpalHan1; +extern OSViMode osViModeFpalHaf1; +extern OSViMode osViModeFpalHpn2; +extern OSViMode osViModeFpalHpf2; + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Video interface (Vi) */ +extern u32 osViGetStatus(void); +extern u32 osViGetCurrentMode(void); +extern u32 osViGetCurrentLine(void); +extern u32 osViGetCurrentField(void); +extern void *osViGetCurrentFramebuffer(void); +extern void *osViGetNextFramebuffer(void); +extern void osViSetXScale(f32); +extern void osViSetYScale(f32); +extern void osViExtendVStart(u32); +extern void osViSetSpecialFeatures(u32); +extern void osViSetMode(OSViMode *); +extern void osViSetEvent(OSMesgQueue *, OSMesg, u32); +extern void osViSwapBuffer(void *); +extern void osViBlack(u8); +extern void osViFade(u8, u16); +extern void osViRepeatLine(u8); +extern void osCreateViManager(OSPri); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_VI_H_ */ diff --git a/lib/ultralib/include/PR/os_voice.h b/lib/ultralib/include/PR/os_voice.h new file mode 100644 index 0000000..4e3cf6e --- /dev/null +++ b/lib/ultralib/include/PR/os_voice.h @@ -0,0 +1,108 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_voice.h,v $ + $Revision: 1.2 $ + $Date: 1999/07/13 08:36:42 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VOICE_H_ +#define _OS_VOICE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef struct { /* Voice Recognition System */ + OSMesgQueue *__mq; /* SI Message Queue */ + int __channel; /* Controller Port # */ + s32 __mode; + u8 cmd_status; /* Command Status */ +} OSVoiceHandle; + +typedef struct { /* Voice Recognition System */ + u16 warning; + u16 answer_num; /* 0...5 */ + u16 voice_level; + u16 voice_sn; + u16 voice_time; + u16 answer[5]; + u16 distance[5]; +} OSVoiceData; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* definition for Voice Recognition System */ + +#define VOICE_WARN_TOO_SMALL 0x0400 +#define VOICE_WARN_TOO_LARGE 0x0800 +#define VOICE_WARN_NOT_FIT 0x4000 +#define VOICE_WARN_TOO_NOISY 0x8000 + +#define VOICE_STATUS_READY 0 +#define VOICE_STATUS_START 1 +#define VOICE_STATUS_CANCEL 3 +#define VOICE_STATUS_BUSY 5 +#define VOICE_STATUS_END 7 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Voice Recognition System */ +extern s32 osVoiceInit(OSMesgQueue *, OSVoiceHandle *, int); +extern s32 osVoiceCheckWord(u8 *data); +extern s32 osVoiceClearDictionary(OSVoiceHandle *, u8); +extern s32 osVoiceControlGain(OSVoiceHandle *, s32, s32); +extern s32 osVoiceSetWord(OSVoiceHandle *, u8 *); +extern s32 osVoiceStartReadData(OSVoiceHandle *); +extern s32 osVoiceStopReadData(OSVoiceHandle *); +extern s32 osVoiceGetReadData(OSVoiceHandle *, OSVoiceData *); +extern s32 osVoiceMaskDictionary(OSVoiceHandle *, u8 *, int); +extern void osVoiceCountSyllables(u8 *, u32 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_VOICE_H_ */ diff --git a/lib/ultralib/include/PR/ramrom.h b/lib/ultralib/include/PR/ramrom.h new file mode 100644 index 0000000..42e5c2d --- /dev/null +++ b/lib/ultralib/include/PR/ramrom.h @@ -0,0 +1,113 @@ +#ifndef _RAMROM_H +#define _RAMROM_H + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.20 $ + * $Date: 1997/02/11 08:26:47 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ramrom.h,v $ + * + **************************************************************************/ + +/* + * Defines for the GIO card in the Nintendo Development Station + * + * The RAM on the GIO card acts as ROM for the game + * Interrupts available between the game and the Indy host + * + * The last part of the ramrom is used for communication between + * game and host. There are 6 4K buffers defined: + * log, printf, rmon to indy, rmon from indy, app to indy, app from indy + * The last 8 bytes of the buffer are used in the emulator environment + */ + +#define RAMROM_SIZE (0x1000000) + +#define RAMROM_BUF_SIZE (4096) +#define RAMROM_MSG_SIZE (RAMROM_BUF_SIZE*6) +#define RAMROM_MSG_ADDR (RAMROM_SIZE - RAMROM_MSG_SIZE) +#define RAMROM_MSG_HDR_SIZE (3*sizeof(long)) +#define RAMROM_USER_DATA_SIZE (RAMROM_MSG_SIZE-RAMROM_MSG_HDR_SIZE) + +#define RAMROM_APP_READ_ADDR (RAMROM_MSG_ADDR + (0*RAMROM_BUF_SIZE)) +#define RAMROM_APP_WRITE_ADDR (RAMROM_MSG_ADDR + (1*RAMROM_BUF_SIZE)) +#define RAMROM_RMON_READ_ADDR (RAMROM_MSG_ADDR + (2*RAMROM_BUF_SIZE)) +#define RAMROM_RMON_WRITE_ADDR (RAMROM_MSG_ADDR + (3*RAMROM_BUF_SIZE)) +#define RAMROM_PRINTF_ADDR (RAMROM_MSG_ADDR + (4*RAMROM_BUF_SIZE)) +#define RAMROM_LOG_ADDR (RAMROM_MSG_ADDR + (5*RAMROM_BUF_SIZE)) + +/*#define RAMROM_GIO_INTERRUPT (RAMROM_MSG_ADDR + RAMROM_MSG_SIZE - 4)*/ + +/* + * For the initial round of PIF bringup, we will load in a bootstrap loader + * 0x400 bytes into the ramrom, and the rom will be loaded at 0x2000 + */ +#ifndef _HW_VERSION_1 +#define RAMROM_BOOTSTRAP_OFFSET 0x40 +#define RAMROM_GAME_OFFSET 0x1000 +#define RAMROM_FONTDATA_OFFSET 0xb70 +#define RAMROM_FONTDATA_SIZE 1152 +#else +#define RAMROM_BOOTSTRAP_OFFSET 0x400 +#define RAMROM_GAME_OFFSET 0x2000 +#endif +#define RAMROM_CLOCKRATE_OFFSET 0x4 +#define RAMROM_CLOCKRATE_MASK 0xfffffff0 +#define RAMROM_BOOTADDR_OFFSET 0x8 +#define RAMROM_RELEASE_OFFSET 0xc +/* + * Second version of the PIF jumps to location 0x1000, and we'll put a jump to + * location 0x400 into the ramrom (for backwards compatibility). + */ +#define RAMROM_PIF2BOOTSTRAP_OFFSET 0x1000 + +typedef struct { + long type; + long length; /* in bytes of userdata */ + long magic; + char userdata[RAMROM_USER_DATA_SIZE]; +} RamRomBuffer; + +/* + * Interrupt values (must fit in 6 bits!) + * values are used for both request & response + * Transactions initiated by the host start with HOST + * and those initiated by the target start with GAME. + */ + +#define HOST_PIACCESS_REQ 1 +#define HOST_DBG_CMD_READY 2 +#define GAME_DBG_DATA_SEND 3 +#define HOST_DBG_DATA_ACK 4 +#define GAME_PRINTF_SEND 5 +#define HOST_PRINTF_ACK 6 +#define GAME_LOG_SEND 7 +#define HOST_LOG_ACK 8 +#define HOST_APP_CMD_READY 9 +#define GAME_APP_DATA_READY 10 +#define HOST_PROF_REQ 11 +#define GAME_PROF_SEND 12 +#define HOST_PROF_ACK 13 +#define GAME_FAULT_SEND 14 +#define HOST_FAULT_ACK 15 +#define GAME_EXIT 16 +#define HOST_DATA_ACK 17 + +#ifdef _EMULATOR +void __RamRomInit(int key, void *romaddr); +void __RamRomDestroy(int key); +#endif /* _EMULATOR */ + +#endif /* !_RAMROM_H */ diff --git a/lib/ultralib/include/PR/rcp.h b/lib/ultralib/include/PR/rcp.h new file mode 100644 index 0000000..47c4b34 --- /dev/null +++ b/lib/ultralib/include/PR/rcp.h @@ -0,0 +1,848 @@ +#ifndef _RCP_H_ +#define _RCP_H_ + +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * File: rcp.h + * + * This file contains register and bit definitions for RCP memory map. + * $Revision: 1.22 $ + * $Date: 1999/05/20 03:01:49 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rcp.h,v $ + * + **************************************************************************/ + +#include "R4300.h" +#include "ultratypes.h" + +/** + * RCP memory map overview: + * + * 0x0000_0000 .. 0x03ef_ffff RDRAM memory + * 0x03f0_0000 .. 0x03ff_ffff RDRAM registers + * + * 0x0400_0000 .. 0x0400_2000 SP memory + * 0x0404_0000 .. 0x040f_ffff SP registers + * 0x0410_0000 .. 0x041f_ffff DP command registers + * 0x0420_0000 .. 0x042f_ffff DP span registers + * 0x0430_0000 .. 0x043f_ffff MI registers + * 0x0440_0000 .. 0x044f_ffff VI registers + * 0x0450_0000 .. 0x045f_ffff AI registers + * 0x0460_0000 .. 0x046f_ffff PI registers + * 0x0470_0000 .. 0x047f_ffff RI registers + * 0x0480_0000 .. 0x048f_ffff SI registers + * 0x0490_0000 .. 0x04ff_ffff unused + * + * 0x0500_0000 .. 0x05ff_ffff cartridge domain 2 + * 0x0600_0000 .. 0x07ff_ffff cartridge domain 1 + * 0x0800_0000 .. 0x0fff_ffff cartridge domain 2 + * 0x1000_0000 .. 0x1fbf_ffff cartridge domain 1 + * + * 0x1fc0_0000 .. 0x1fc0_07bf PIF Boot Rom (1984 bytes) + * 0x1fc0_07c0 .. 0x1fc0_07ff PIF (JoyChannel) RAM (64 bytes) + * 0x1fc0_0800 .. 0x1fcf_ffff Reserved + * 0x1fd0_0000 .. 0x7fff_ffff cartridge domain 1 + * 0x8000_0000 .. 0xffff_ffff external SysAD device + */ + +/** + * RDRAM memory + */ + +#define RDRAM_0_START 0x00000000 +#define RDRAM_0_END 0x001FFFFF +#define RDRAM_1_START 0x00200000 +#define RDRAM_1_END 0x003FFFFF + +#define RDRAM_START RDRAM_0_START +#define RDRAM_END RDRAM_1_END + +/** + * RDRAM registers + */ +#define RDRAM_BASE_REG 0x03F00000 + +#define RDRAM_CONFIG_REG (RDRAM_BASE_REG + 0x00) +#define RDRAM_DEVICE_TYPE_REG (RDRAM_BASE_REG + 0x00) +#define RDRAM_DEVICE_ID_REG (RDRAM_BASE_REG + 0x04) +#define RDRAM_DELAY_REG (RDRAM_BASE_REG + 0x08) +#define RDRAM_MODE_REG (RDRAM_BASE_REG + 0x0c) +#define RDRAM_REF_INTERVAL_REG (RDRAM_BASE_REG + 0x10) +#define RDRAM_REF_ROW_REG (RDRAM_BASE_REG + 0x14) +#define RDRAM_RAS_INTERVAL_REG (RDRAM_BASE_REG + 0x18) +#define RDRAM_MIN_INTERVAL_REG (RDRAM_BASE_REG + 0x1c) +#define RDRAM_ADDR_SELECT_REG (RDRAM_BASE_REG + 0x20) +#define RDRAM_DEVICE_MANUF_REG (RDRAM_BASE_REG + 0x24) + +#define RDRAM_0_DEVICE_ID 0 +#define RDRAM_1_DEVICE_ID 1 + +#define RDRAM_RESET_MODE 0 +#define RDRAM_ACTIVE_MODE 1 +#define RDRAM_STANDBY_MODE 2 + +#define RDRAM_LENGTH (2 * 512 * 2048) +#define RDRAM_0_BASE_ADDRESS (RDRAM_0_DEVICE_ID * RDRAM_LENGTH) +#define RDRAM_1_BASE_ADDRESS (RDRAM_1_DEVICE_ID * RDRAM_LENGTH) + +#define RDRAM_0_CONFIG 0x00000 +#define RDRAM_1_CONFIG 0x00400 +#define RDRAM_GLOBAL_CONFIG 0x80000 + +/** + * PIF Physical memory map (total size = 2 KB) + * + * Size Description Mode + * 1FC007FF +-------+-----------------+-----+ + * | 64 B | JoyChannel RAM | R/W | + * 1FC007C0 +-------+-----------------+-----+ + * |1984 B | Boot ROM | * | * = Reserved + * 1FC00000 +-------+-----------------+-----+ + */ +#define PIF_ROM_START 0x1FC00000 +#define PIF_ROM_END 0x1FC007BF +#define PIF_RAM_START 0x1FC007C0 +#define PIF_RAM_END 0x1FC007FF + + +/** + * Controller channel + * Each game controller channel has 4 error bits that are defined in bit 6-7 of + * the Rx and Tx data size area bytes. Programmers need to clear these bits + * when setting the Tx/Rx size area values for a channel + */ +#define CHNL_ERR_NORESP 0x80 /* Bit 7 (Rx): No response error */ +#define CHNL_ERR_OVERRUN 0x40 /* Bit 6 (Rx): Overrun error */ +#define CHNL_ERR_FRAME 0x80 /* Bit 7 (Tx): Frame error */ +#define CHNL_ERR_COLLISION 0x40 /* Bit 6 (Tx): Collision error */ + +#define CHNL_ERR_MASK 0xC0 /* Bit 6-7: channel errors */ + + +/** + * External device info + */ +#define DEVICE_TYPE_CART 0 /* ROM cartridge */ +#define DEVICE_TYPE_BULK 1 /* ROM bulk */ +#define DEVICE_TYPE_64DD 2 /* 64 Disk Drive */ +#define DEVICE_TYPE_SRAM 3 /* SRAM */ +/* 4-6 are reserved */ +#define DEVICE_TYPE_INIT 7 /* initial value */ +/* 8-14 are reserved */ + +/** + * Signal Processor (SP) Memory + */ +#define SP_DMEM_START 0x04000000 +#define SP_DMEM_END 0x04000FFF +#define SP_IMEM_START 0x04001000 +#define SP_IMEM_END 0x04001FFF + +/** + * Signal Processor (SP) CP0 Registers + */ + +#define SP_BASE_REG 0x04040000 + +/* SP memory address (R/W): [11:0] DMEM/IMEM address, [12] 0=DMEM,1=IMEM */ +#define SP_MEM_ADDR_REG (SP_BASE_REG + 0x00) + +/* SP DRAM DMA address (R/W): [23:0] RDRAM address */ +#define SP_DRAM_ADDR_REG (SP_BASE_REG + 0x04) + +/* SP read DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip; RDRAM -> I/DMEM */ +#define SP_RD_LEN_REG (SP_BASE_REG + 0x08) + +/* SP write DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip; I/DMEM -> RDRAM */ +#define SP_WR_LEN_REG (SP_BASE_REG + 0x0C) + +/* SP status (R/W): [14:0] valid bits; see below for write/read mode */ +#define SP_STATUS_REG (SP_BASE_REG + 0x10) + +/* SP DMA full (R): [0] dma full */ +#define SP_DMA_FULL_REG (SP_BASE_REG + 0x14) + +/* SP DMA busy (R): [0] dma busy */ +#define SP_DMA_BUSY_REG (SP_BASE_REG + 0x18) + +/* SP semaphore (R/W): Read: [0] acquire semaphore; Write: [] release semaphore */ +#define SP_SEMAPHORE_REG (SP_BASE_REG + 0x1C) + +/* SP PC (R/W): [11:0] program counter */ +#define SP_PC_REG 0x04080000 + +/** + * SP_MEM_ADDR_REG: bit 12 + */ +#define SP_DMA_DMEM (0 << 12) +#define SP_DMA_IMEM (1 << 12) + +/** + * SP_STATUS_REG: write bits + */ +#define SP_CLR_HALT (1 << 0) /* clear halt */ +#define SP_SET_HALT (1 << 1) /* set halt */ +#define SP_CLR_BROKE (1 << 2) /* clear broke */ +#define SP_CLR_INTR (1 << 3) /* clear interrupt */ +#define SP_SET_INTR (1 << 4) /* set interrupt */ +#define SP_CLR_SSTEP (1 << 5) /* clear sstep */ +#define SP_SET_SSTEP (1 << 6) /* set sstep */ +#define SP_CLR_INTR_BREAK (1 << 7) /* clear interrupt on break */ +#define SP_SET_INTR_BREAK (1 << 8) /* set interrupt on break */ +#define SP_CLR_SIG0 (1 << 9) /* clear signal 0 */ +#define SP_SET_SIG0 (1 << 10) /* set signal 0 */ +#define SP_CLR_SIG1 (1 << 11) /* clear signal 1 */ +#define SP_SET_SIG1 (1 << 12) /* set signal 1 */ +#define SP_CLR_SIG2 (1 << 13) /* clear signal 2 */ +#define SP_SET_SIG2 (1 << 14) /* set signal 2 */ +#define SP_CLR_SIG3 (1 << 15) /* clear signal 3 */ +#define SP_SET_SIG3 (1 << 16) /* set signal 3 */ +#define SP_CLR_SIG4 (1 << 17) /* clear signal 4 */ +#define SP_SET_SIG4 (1 << 18) /* set signal 4 */ +#define SP_CLR_SIG5 (1 << 19) /* clear signal 5 */ +#define SP_SET_SIG5 (1 << 20) /* set signal 5 */ +#define SP_CLR_SIG6 (1 << 21) /* clear signal 6 */ +#define SP_SET_SIG6 (1 << 22) /* set signal 6 */ +#define SP_CLR_SIG7 (1 << 23) /* clear signal 7 */ +#define SP_SET_SIG7 (1 << 24) /* set signal 7 */ + +/* + * SP_STATUS_REG: read bits + */ +#define SP_STATUS_HALT (1 << 0) +#define SP_STATUS_BROKE (1 << 1) +#define SP_STATUS_DMA_BUSY (1 << 2) +#define SP_STATUS_DMA_FULL (1 << 3) +#define SP_STATUS_IO_FULL (1 << 4) +#define SP_STATUS_SSTEP (1 << 5) +#define SP_STATUS_INTR_BREAK (1 << 6) +#define SP_STATUS_SIG0 (1 << 7) +#define SP_STATUS_SIG1 (1 << 8) +#define SP_STATUS_SIG2 (1 << 9) +#define SP_STATUS_SIG3 (1 << 10) +#define SP_STATUS_SIG4 (1 << 11) +#define SP_STATUS_SIG5 (1 << 12) +#define SP_STATUS_SIG6 (1 << 13) +#define SP_STATUS_SIG7 (1 << 14) + +/* + * SP_STATUS_REG: use of SIG bits + */ +#define SP_CLR_YIELD SP_CLR_SIG0 +#define SP_SET_YIELD SP_SET_SIG0 +#define SP_STATUS_YIELD SP_STATUS_SIG0 +#define SP_CLR_YIELDED SP_CLR_SIG1 +#define SP_SET_YIELDED SP_SET_SIG1 +#define SP_STATUS_YIELDED SP_STATUS_SIG1 +#define SP_CLR_TASKDONE SP_CLR_SIG2 +#define SP_SET_TASKDONE SP_SET_SIG2 +#define SP_STATUS_TASKDONE SP_STATUS_SIG2 +#define SP_CLR_RSPSIGNAL SP_CLR_SIG3 +#define SP_SET_RSPSIGNAL SP_SET_SIG3 +#define SP_STATUS_RSPSIGNAL SP_STATUS_SIG3 +#define SP_CLR_CPUSIGNAL SP_CLR_SIG4 +#define SP_SET_CPUSIGNAL SP_SET_SIG4 +#define SP_STATUS_CPUSIGNAL SP_STATUS_SIG4 + +/* + * SP IMEM BIST REG (R/W): [6:0] BIST status bits; see below for detail + */ +#define SP_IBIST_REG 0x04080004 + +/* + * SP_IBIST_REG: write bits + */ +#define SP_IBIST_CHECK (1 << 0) /* BIST check */ +#define SP_IBIST_GO (1 << 1) /* BIST go */ +#define SP_IBIST_CLEAR (1 << 2) /* BIST clear */ + +/* + * SP_BIST_REG: read bits + * First 2 bits are same as in write mode + */ +#define SP_IBIST_DONE (1 << 2) +#define SP_IBIST_FAILED 0x78 /* bits [6:3], BIST fail */ + +/** + * Display Processor Command (DPC) Registers + */ +#define DPC_BASE_REG 0x04100000 + +/* DP CMD DMA start (R/W): [23:0] DMEM/RDRAM start address */ +#define DPC_START_REG (DPC_BASE_REG + 0x00) + +/* DP CMD DMA end (R/W): [23:0] DMEM/RDRAM end address */ +#define DPC_END_REG (DPC_BASE_REG + 0x04) + +/* DP CMD DMA end (R): [23:0] DMEM/RDRAM current address */ +#define DPC_CURRENT_REG (DPC_BASE_REG + 0x08) + +/* DP CMD status (R/W): [9:0] valid bits - see below for definitions */ +#define DPC_STATUS_REG (DPC_BASE_REG + 0x0C) + +/* DP clock counter (R): [23:0] clock counter */ +#define DPC_CLOCK_REG (DPC_BASE_REG + 0x10) + +/* DP buffer busy counter (R): [23:0] clock counter */ +#define DPC_BUFBUSY_REG (DPC_BASE_REG + 0x14) + +/* DP pipe busy counter (R): [23:0] clock counter */ +#define DPC_PIPEBUSY_REG (DPC_BASE_REG + 0x18) + +/* DP TMEM load counter (R): [23:0] clock counter */ +#define DPC_TMEM_REG (DPC_BASE_REG + 0x1C) + +/** + * DPC_STATUS_REG: write bits + */ +#define DPC_CLR_XBUS_DMEM_DMA (1 << 0) +#define DPC_SET_XBUS_DMEM_DMA (1 << 1) +#define DPC_CLR_FREEZE (1 << 2) +#define DPC_SET_FREEZE (1 << 3) +#define DPC_CLR_FLUSH (1 << 4) +#define DPC_SET_FLUSH (1 << 5) +#define DPC_CLR_TMEM_CTR (1 << 6) +#define DPC_CLR_PIPE_CTR (1 << 7) +#define DPC_CLR_CMD_CTR (1 << 8) +#define DPC_CLR_CLOCK_CTR (1 << 9) + +/** + * DPC_STATUS_REG: read bits + */ +#define DPC_STATUS_XBUS_DMEM_DMA (1 << 0) +#define DPC_STATUS_FREEZE (1 << 1) +#define DPC_STATUS_FLUSH (1 << 2) +#define DPC_STATUS_START_GCLK (1 << 3) +#define DPC_STATUS_TMEM_BUSY (1 << 4) +#define DPC_STATUS_PIPE_BUSY (1 << 5) +#define DPC_STATUS_CMD_BUSY (1 << 6) +#define DPC_STATUS_CBUF_READY (1 << 7) +#define DPC_STATUS_DMA_BUSY (1 << 8) +#define DPC_STATUS_END_VALID (1 << 9) +#define DPC_STATUS_START_VALID (1 << 10) + +/** + * Display Processor Span (DPS) Registers + */ +#define DPS_BASE_REG 0x04200000 + +/* DP tmem built-in self-test (R/W): [10:0] BIST status bits */ +#define DPS_TBIST_REG (DPS_BASE_REG + 0x00) + +/* DP span test mode (R/W): [0] Span buffer test access enable */ +#define DPS_TEST_MODE_REG (DPS_BASE_REG + 0x04) + +/* DP span buffer test address (R/W): [6:0] bits */ +#define DPS_BUFTEST_ADDR_REG (DPS_BASE_REG + 0x08) + +/* DP span buffer test data (R/W): [31:0] span buffer data */ +#define DPS_BUFTEST_DATA_REG (DPS_BASE_REG + 0x0C) + +/* + * DPS_TMEM_BIST_REG: write bits + */ +#define DPS_TBIST_CHECK (1 << 0) +#define DPS_TBIST_GO (1 << 1) +#define DPS_TBIST_CLEAR (1 << 2) + +/* + * DPS_TMEM_BIST_REG: read bits + * First 2 bits are same as in write mode + */ +#define DPS_TBIST_DONE (1 << 2) +#define DPS_TBIST_FAILED 0x7F8 /* bits [10:3], BIST fail */ + +/** + * MIPS Interface (MI) Registers + */ +#define MI_BASE_REG 0x04300000 + +/* + * MI init mode (W): [6:0] init length, [7] clear init mode, [8] set init mode + * [9/10] clear/set ebus test mode, [11] clear DP interrupt + * (R): [6:0] init length, [7] init mode, [8] ebus test mode + */ +#define MI_INIT_MODE_REG (MI_BASE_REG + 0x00) +#define MI_MODE_REG MI_INIT_MODE_REG + +/* + * MI_MODE_REG: write bits + */ +#define MI_CLR_INIT (1 << 7) /* clear init mode */ +#define MI_SET_INIT (1 << 8) /* set init mode */ +#define MI_CLR_EBUS (1 << 9) /* clear ebus test */ +#define MI_SET_EBUS (1 << 10) /* set ebus test mode */ +#define MI_CLR_DP_INTR (1 << 11) /* clear dp interrupt */ +#define MI_CLR_RDRAM (1 << 12) /* clear RDRAM reg */ +#define MI_SET_RDRAM (1 << 13) /* set RDRAM reg mode */ + +/* + * MI_MODE_REG: read bits + */ +#define MI_MODE_INIT (1 << 7) /* init mode */ +#define MI_MODE_EBUS (1 << 8) /* ebus test mode */ +#define MI_MODE_RDRAM (1 << 9) /* RDRAM reg mode */ + +/* MI version (R): [7:0] io, [15:8] rac, [23:16] rdp, [31:24] rsp */ +#define MI_VERSION_REG (MI_BASE_REG + 0x04) +#define MI_NOOP_REG MI_VERSION_REG + +/* MI interrupt (R): [5:0] valid bits - see below for bit patterns */ +#define MI_INTR_REG (MI_BASE_REG + 0x08) + +/* + * MI interrupt mask (W): [11:0] valid bits - see below for bit patterns + * (R): [5:0] valid bits - see below for bit patterns + */ +#define MI_INTR_MASK_REG (MI_BASE_REG + 0x0C) + +/* + * MI_INTR_REG: read bits + */ +#define MI_INTR_SP (1 << 0) /* SP intr */ +#define MI_INTR_SI (1 << 1) /* SI intr */ +#define MI_INTR_AI (1 << 2) /* AI intr */ +#define MI_INTR_VI (1 << 3) /* VI intr */ +#define MI_INTR_PI (1 << 4) /* PI intr */ +#define MI_INTR_DP (1 << 5) /* DP intr */ + +/* + * MI_INTR_MASK_REG: write bits + */ +#define MI_INTR_MASK_CLR_SP (1 << 0) /* clear SP mask */ +#define MI_INTR_MASK_SET_SP (1 << 1) /* set SP mask */ +#define MI_INTR_MASK_CLR_SI (1 << 2) /* clear SI mask */ +#define MI_INTR_MASK_SET_SI (1 << 3) /* set SI mask */ +#define MI_INTR_MASK_CLR_AI (1 << 4) /* clear AI mask */ +#define MI_INTR_MASK_SET_AI (1 << 5) /* set AI mask */ +#define MI_INTR_MASK_CLR_VI (1 << 6) /* clear VI mask */ +#define MI_INTR_MASK_SET_VI (1 << 7) /* set VI mask */ +#define MI_INTR_MASK_CLR_PI (1 << 8) /* clear PI mask */ +#define MI_INTR_MASK_SET_PI (1 << 9) /* set PI mask */ +#define MI_INTR_MASK_CLR_DP (1 << 10) /* clear DP mask */ +#define MI_INTR_MASK_SET_DP (1 << 11) /* set DP mask */ + +/* + * MI_INTR_MASK_REG: read bits + */ +#define MI_INTR_MASK_SP (1 << 0) /* SP intr mask */ +#define MI_INTR_MASK_SI (1 << 1) /* SI intr mask */ +#define MI_INTR_MASK_AI (1 << 2) /* AI intr mask */ +#define MI_INTR_MASK_VI (1 << 3) /* VI intr mask */ +#define MI_INTR_MASK_PI (1 << 4) /* PI intr mask */ +#define MI_INTR_MASK_DP (1 << 5) /* DP intr mask */ + +/** + * Video Interface (VI) Registers + */ +#define VI_BASE_REG 0x04400000 + +/* VI status/control (R/W): [15-0] valid bits: + * [1:0] = type[1:0] (pixel size) + * 0: blank (no data, no sync) + * 1: reserved + * 2: 5/5/5/3 ("16" bit) + * 3: 8/8/8/8 (32 bit) + * [2] = gamma_dither_enable (normally on, unless "special effect") + * [3] = gamma_enable (normally on, unless MPEG/JPEG) + * [4] = divot_enable (normally on if antialiased, unless decal lines) + * [5] = reserved - always off + * [6] = serrate (always on if interlaced, off if not) + * [7] = reserved - diagnostics only + * [9:8] = anti-alias (aa) mode[1:0] + * 0: aa & resamp (always fetch extra lines) + * 1: aa & resamp (fetch extra lines if needed) + * 2: resamp only (treat as all fully covered) + * 3: neither (replicate pixels, no interpolate) + * [11] = reserved - diagnostics only + * [15:12] = reserved + * + */ +#define VI_CONTROL_REG (VI_BASE_REG + 0x00) +#define VI_STATUS_REG VI_CONTROL_REG + +/* VI origin (R/W): [23:0] frame buffer origin in bytes */ +#define VI_ORIGIN_REG (VI_BASE_REG + 0x04) +#define VI_DRAM_ADDR_REG VI_ORIGIN_REG + +/* VI width (R/W): [11:0] frame buffer line width in pixels */ +#define VI_WIDTH_REG (VI_BASE_REG + 0x08) +#define VI_H_WIDTH_REG VI_WIDTH_REG + +/* VI vertical intr (R/W): [9:0] interrupt when current half-line = V_INTR */ +#define VI_INTR_REG (VI_BASE_REG + 0x0C) +#define VI_V_INTR_REG VI_INTR_REG + +/* + * VI current vertical line (R/W): [9:0] current half line, sampled once per + * line (the lsb of V_CURRENT is constant within a field, and in + * interlaced modes gives the field number - which is constant for non- + * interlaced modes) + * - Any write to this register will clear interrupt line + */ +#define VI_CURRENT_REG (VI_BASE_REG + 0x10) +#define VI_V_CURRENT_LINE_REG VI_CURRENT_REG + +/* + * VI video timing (R/W): [ 7: 0] horizontal sync width in pixels, + * [15: 8] color burst width in pixels, + * [19:16] vertical sync width in half lines, + * [29:20] start of color burst in pixels from h-sync + */ +#define VI_BURST_REG (VI_BASE_REG + 0x14) +#define VI_TIMING_REG VI_BURST_REG + +/* VI vertical sync (R/W): [9:0] number of half-lines per field */ +#define VI_V_SYNC_REG (VI_BASE_REG + 0x18) + +/* VI horizontal sync (R/W): [11: 0] total duration of a line in 1/4 pixel + * [20:16] a 5-bit leap pattern used for PAL only + * (h_sync_period) + */ +#define VI_H_SYNC_REG (VI_BASE_REG + 0x1C) + +/* + * VI horizontal sync leap (R/W): [11: 0] identical to h_sync_period + * [27:16] identical to h_sync_period + */ +#define VI_LEAP_REG (VI_BASE_REG + 0x20) +#define VI_H_SYNC_LEAP_REG VI_LEAP_REG + +/* + * VI horizontal video (R/W): [ 9: 0] end of active video in screen pixels + * : [25:16] start of active video in screen pixels + */ +#define VI_H_START_REG (VI_BASE_REG + 0x24) +#define VI_H_VIDEO_REG VI_H_START_REG + +/* + * VI vertical video (R/W): [ 9: 0] end of active video in screen half-lines + * : [25:16] start of active video in screen half-lines + */ +#define VI_V_START_REG (VI_BASE_REG + 0x28) +#define VI_V_VIDEO_REG VI_V_START_REG + +/* + * VI vertical burst (R/W): [ 9: 0] end of color burst enable in half-lines + * : [25:16] start of color burst enable in half-lines + */ +#define VI_V_BURST_REG (VI_BASE_REG + 0x2C) + +/* VI x-scale (R/W): [11: 0] 1/horizontal scale up factor (2.10 format) + * [27:16] horizontal subpixel offset (2.10 format) + */ +#define VI_X_SCALE_REG (VI_BASE_REG + 0x30) + +/* VI y-scale (R/W): [11: 0] 1/vertical scale up factor (2.10 format) + * [27:16] vertical subpixel offset (2.10 format) + */ +#define VI_Y_SCALE_REG (VI_BASE_REG + 0x34) + +/* + * Patterns to interpret VI_CONTROL_REG + */ +#define VI_CTRL_TYPE_16 0x00002 /* [1:0] pixel size: 16 bit */ +#define VI_CTRL_TYPE_32 0x00003 /* [1:0] pixel size: 32 bit */ +#define VI_CTRL_GAMMA_DITHER_ON 0x00004 /* 2: default = on */ +#define VI_CTRL_GAMMA_ON 0x00008 /* 3: default = on */ +#define VI_CTRL_DIVOT_ON 0x00010 /* 4: default = on */ +#define VI_CTRL_SERRATE_ON 0x00040 /* 6: on if interlaced */ +#define VI_CTRL_ANTIALIAS_MASK 0x00300 /* [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_PIXEL_ADV_MASK 0x01000 /* [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_1 0x01000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_2 0x02000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_3 0x03000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_DITHER_FILTER_ON 0x10000 /* 16: dither-filter mode */ + +/* + * Possible video clocks (NTSC or PAL) + */ +#define VI_NTSC_CLOCK 48681812 /* Hz = 48.681812 MHz */ +#define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */ +#define VI_MPAL_CLOCK 48628316 /* Hz = 48.628316 MHz */ + +/** + * The address and length registers are double buffered; that is, they + * can be written twice before becoming full. + * The address must be written before the length. + */ + +/** + * Audio Interface (AI) Registers + */ +#define AI_BASE_REG 0x04500000 + +/* AI DRAM address (W): [23:0] starting RDRAM address (8B-aligned) */ +#define AI_DRAM_ADDR_REG (AI_BASE_REG + 0x00) /* R0: DRAM address */ + +/* AI length (R/W): [14:0] transfer length (v1.0) - Bottom 3 bits are ignored */ +/* [17:0] transfer length (v2.0) - Bottom 3 bits are ignored */ +#define AI_LEN_REG (AI_BASE_REG + 0x04) /* R1: Length */ + +/* AI control (W): [0] DMA enable - if LSB == 1, DMA is enabled */ +#define AI_CONTROL_REG (AI_BASE_REG + 0x08) /* R2: DMA Control */ + +/* Value for control register */ +#define AI_CONTROL_DMA_ON 1 /* LSB = 1: DMA enable*/ +#define AI_CONTROL_DMA_OFF 0 /* LSB = 1: DMA enable*/ + +/* + * AI status (R): [31]/[0] ai_full (addr & len buffer full), [30] ai_busy + * Note that a 1->0 transition in ai_full will set interrupt + * (W): clear audio interrupt + */ +#define AI_STATUS_REG (AI_BASE_REG + 0x0C) /* R3: Status */ + +/* Value for status register */ +#define AI_STATUS_FIFO_FULL (1 << 31) +#define AI_STATUS_DMA_BUSY (1 << 30) + +/* + * AI DAC sample period register (W): [13:0] dac rate + * - vid_clock/(dperiod + 1) is the DAC sample rate + * - (dperiod + 1) >= 66 * (aclockhp + 1) must be true + */ +#define AI_DACRATE_REG (AI_BASE_REG + 0x10) /* R4: DAC rate 14-lsb*/ + +/* DAC rate = video clock / audio frequency + * - DAC rate >= (66 * Bit rate) must be true + */ +#define AI_MAX_DAC_RATE 16384 /* 14-bit+1 */ +#define AI_MIN_DAC_RATE 132 + +/* + * AI bit rate (W): [3:0] bit rate (abus clock half period register - aclockhp) + * - vid_clock/(2 * (aclockhp + 1)) is the DAC clock rate + * - The abus clock stops if aclockhp is zero + */ +#define AI_BITRATE_REG (AI_BASE_REG + 0x14) /* R5: Bit rate 4-lsb */ + +/* Bit rate <= (DAC rate / 66) */ +#define AI_MAX_BIT_RATE 16 /* 4-bit+1 */ +#define AI_MIN_BIT_RATE 2 + +/* + * Maximum and minimum values for audio frequency based on video clocks + * max frequency = (video clock / min dac rate) + * min frequency = (video clock / max dac rate) + */ +#define AI_NTSC_MAX_FREQ 368000 /* 368 KHz */ +#define AI_NTSC_MIN_FREQ 3000 /* 3 KHz ~ 2971 Hz */ + +#define AI_PAL_MAX_FREQ 376000 /* 376 KHz */ +#define AI_PAL_MIN_FREQ 3050 /* 3 KHz ~ 3031 Hz */ + +#define AI_MPAL_MAX_FREQ 368000 /* 368 KHz */ +#define AI_MPAL_MIN_FREQ 3000 /* 3 KHz ~ 2968 Hz */ + +/** + * Peripheral Interface (PI) Registers + */ +#define PI_BASE_REG 0x04600000 + +/* PI DRAM address (R/W): [23:0] starting RDRAM address */ +#define PI_DRAM_ADDR_REG (PI_BASE_REG + 0x00) /* DRAM address */ + +/* PI pbus (cartridge) address (R/W): [31:0] starting AD16 address */ +#define PI_CART_ADDR_REG (PI_BASE_REG + 0x04) + +/* PI read length (R/W): [23:0] read data length */ +#define PI_RD_LEN_REG (PI_BASE_REG + 0x08) + +/* PI write length (R/W): [23:0] write data length */ +#define PI_WR_LEN_REG (PI_BASE_REG + 0x0C) + +/* + * PI status (R): [0] DMA busy, [1] IO busy, [2], error + * (W): [0] reset controller (and abort current op), [1] clear intr + */ +#define PI_STATUS_REG (PI_BASE_REG + 0x10) + +/* PI dom1 latency (R/W): [7:0] domain 1 device latency */ +#define PI_BSD_DOM1_LAT_REG (PI_BASE_REG + 0x14) + +/* PI dom1 pulse width (R/W): [7:0] domain 1 device R/W strobe pulse width */ +#define PI_BSD_DOM1_PWD_REG (PI_BASE_REG + 0x18) + +/* PI dom1 page size (R/W): [3:0] domain 1 device page size */ +#define PI_BSD_DOM1_PGS_REG (PI_BASE_REG + 0x1C) /* page size */ + +/* PI dom1 release (R/W): [1:0] domain 1 device R/W release duration */ +#define PI_BSD_DOM1_RLS_REG (PI_BASE_REG + 0x20) + +/* PI dom2 latency (R/W): [7:0] domain 2 device latency */ +#define PI_BSD_DOM2_LAT_REG (PI_BASE_REG + 0x24) /* Domain 2 latency */ + +/* PI dom2 pulse width (R/W): [7:0] domain 2 device R/W strobe pulse width */ +#define PI_BSD_DOM2_PWD_REG (PI_BASE_REG + 0x28) /* pulse width */ + +/* PI dom2 page size (R/W): [3:0] domain 2 device page size */ +#define PI_BSD_DOM2_PGS_REG (PI_BASE_REG + 0x2C) /* page size */ + +/* PI dom2 release (R/W): [1:0] domain 2 device R/W release duration */ +#define PI_BSD_DOM2_RLS_REG (PI_BASE_REG + 0x30) /* release duration */ + +#define PI_DOMAIN1_REG PI_BSD_DOM1_LAT_REG +#define PI_DOMAIN2_REG PI_BSD_DOM2_LAT_REG + +#define PI_DOM_LAT_OFS 0x00 +#define PI_DOM_PWD_OFS 0x04 +#define PI_DOM_PGS_OFS 0x08 +#define PI_DOM_RLS_OFS 0x0C + +/* + * PI status register has 3 bits active when read from (PI_STATUS_REG - read) + * Bit 0: DMA busy - set when DMA is in progress + * Bit 1: IO busy - set when IO is in progress + * Bit 2: Error - set when CPU issues IO request while DMA is busy + */ +#define PI_STATUS_DMA_BUSY (1 << 0) +#define PI_STATUS_IO_BUSY (1 << 1) +#define PI_STATUS_ERROR (1 << 2) + +/* PI status register has 2 bits active when written to: + * Bit 0: When set, reset PIC + * Bit 1: When set, clear interrupt flag + * The values of the two bits can be ORed together to both reset PIC and + * clear interrupt at the same time. + * + * Note: + * - The PIC does generate an interrupt at the end of each DMA. CPU + * needs to clear the interrupt flag explicitly (from an interrupt + * handler) by writing into the STATUS register with bit 1 set. + * + * - When a DMA completes, the interrupt flag is set. CPU can issue + * another request even while the interrupt flag is set (as long as + * PIC is idle). However, it is the CPU's responsibility for + * maintaining accurate correspondence between DMA completions and + * interrupts. + * + * - When PIC is reset, if PIC happens to be busy, an interrupt will + * be generated as PIC returns to idle. Otherwise, no interrupt will + * be generated and PIC remains idle. + */ + +/* + * PI_STATUS_REG: write bits + */ +#define PI_STATUS_RESET (1 << 0) +#define PI_SET_RESET PI_STATUS_RESET + +#define PI_STATUS_CLR_INTR (1 << 1) +#define PI_CLR_INTR PI_STATUS_CLR_INTR + +#define PI_DMA_BUFFER_SIZE 128 + +#define PI_DOM1_ADDR1 0x06000000 /* to 0x07FFFFFF */ +#define PI_DOM1_ADDR2 0x10000000 /* to 0x1FBFFFFF */ +#define PI_DOM1_ADDR3 0x1FD00000 /* to 0x7FFFFFFF */ +#define PI_DOM2_ADDR1 0x05000000 /* to 0x05FFFFFF */ +#define PI_DOM2_ADDR2 0x08000000 /* to 0x0FFFFFFF */ + +/** + * RDRAM Interface (RI) Registers + */ +#define RI_BASE_REG 0x04700000 + +/* RI mode (R/W): [1:0] operating mode, [2] stop T active, [3] stop R active */ +#define RI_MODE_REG (RI_BASE_REG + 0x00) + +/* RI config (R/W): [5:0] current control input, [6] current control enable */ +#define RI_CONFIG_REG (RI_BASE_REG + 0x04) + +/* RI current load (W): [] any write updates current control register */ +#define RI_CURRENT_LOAD_REG (RI_BASE_REG + 0x08) + +/* RI select (R/W): [2:0] receive select, [2:0] transmit select */ +#define RI_SELECT_REG (RI_BASE_REG + 0x0C) + +/* RI refresh (R/W): [7:0] clean refresh delay, [15:8] dirty refresh delay, + * [16] refresh bank, [17] refresh enable + * [18] refresh optimize + */ +#define RI_REFRESH_REG (RI_BASE_REG + 0x10) +#define RI_COUNT_REG RI_REFRESH_REG + +/* RI latency (R/W): [3:0] DMA latency/overlap */ +#define RI_LATENCY_REG (RI_BASE_REG + 0x14) + +/* RI error (R): [0] nack error, [1] ack error */ +#define RI_RERROR_REG (RI_BASE_REG + 0x18) + +/* RI error (W): [] any write clears all error bits */ +#define RI_WERROR_REG (RI_BASE_REG + 0x1C) + +/** + * Serial Interface (SI) Registers + */ +#define SI_BASE_REG 0x04800000 + +/* SI DRAM address (R/W): [23:0] starting RDRAM address */ +#define SI_DRAM_ADDR_REG (SI_BASE_REG + 0x00) + +/* SI address read 64B (W): [] write begins a 64B DMA write PIF RAM -> RDRAM */ +#define SI_PIF_ADDR_RD64B_REG (SI_BASE_REG + 0x04) + +/* Address SI_BASE_REG + (0x08, 0x0C, 0x14) are reserved */ + +/* SI address write 64B (W): [] write begins a 64B DMA read RDRAM -> PIF RAM */ +#define SI_PIF_ADDR_WR64B_REG (SI_BASE_REG + 0x10) + +/* SI status (R/W): [] any write clears interrupt */ +#define SI_STATUS_REG (SI_BASE_REG + 0x18) + +/* + * SI_STATUS_REG: read bits + */ +#define SI_STATUS_DMA_BUSY (1 << 0) /* DMA in progress */ +#define SI_STATUS_RD_BUSY (1 << 1) /* IO access in progress */ +#define SI_STATUS_DMA_ERROR (1 << 3) /* Overlapping DMA requests */ +#define SI_STATUS_INTERRUPT (1 << 12) /* Interrupt is set */ + +/** + * Development Board GIO Control Registers + */ + +#define GIO_BASE_REG 0x18000000 + +/* Game to Host Interrupt */ +#define GIO_GIO_INTR_REG (GIO_BASE_REG+0x000) + +/* Game to Host SYNC */ +#define GIO_GIO_SYNC_REG (GIO_BASE_REG+0x400) + +/* Host to Game Interrupt */ +#define GIO_CART_INTR_REG (GIO_BASE_REG+0x800) + +/** + * Common macros + */ +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) +#define IO_READ(addr) (*(vu32*)PHYS_TO_K1(addr)) +#define IO_WRITE(addr,data) (*(vu32*)PHYS_TO_K1(addr)=(u32)(data)) +#define RCP_STAT_PRINT \ + rmonPrintf("current=%x start=%x end=%x dpstat=%x spstat=%x\n", \ + IO_READ(DPC_CURRENT_REG), \ + IO_READ(DPC_START_REG), \ + IO_READ(DPC_END_REG), \ + IO_READ(DPC_STATUS_REG), \ + IO_READ(SP_STATUS_REG)) + +#endif + +#endif /* _RCP_H_ */ diff --git a/lib/ultralib/include/PR/rdb.h b/lib/ultralib/include/PR/rdb.h new file mode 100644 index 0000000..e089749 --- /dev/null +++ b/lib/ultralib/include/PR/rdb.h @@ -0,0 +1,93 @@ + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 1997/02/11 08:29:31 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rdb.h,v $ + * + **************************************************************************/ + +#ifndef _RDB_H +#define _RDB_H + +/* U64 side address */ +#define RDB_BASE_REG 0xc0000000 +#define RDB_WRITE_INTR_REG (RDB_BASE_REG + 0x8) +#define RDB_READ_INTR_REG (RDB_BASE_REG + 0xc) +#define RDB_BASE_VIRTUAL_ADDR 0x80000000 + +/* packet type Have six bits, so can have up to 63 types */ +#define RDB_TYPE_INVALID 0 +#define RDB_TYPE_GtoH_PRINT 1 +#define RDB_TYPE_GtoH_FAULT 2 +#define RDB_TYPE_GtoH_LOG_CT 3 +#define RDB_TYPE_GtoH_LOG 4 +#define RDB_TYPE_GtoH_READY_FOR_DATA 5 +#define RDB_TYPE_GtoH_DATA_CT 6 +#define RDB_TYPE_GtoH_DATA 7 +#define RDB_TYPE_GtoH_DEBUG 8 +#define RDB_TYPE_GtoH_RAMROM 9 +#define RDB_TYPE_GtoH_DEBUG_DONE 10 +#define RDB_TYPE_GtoH_DEBUG_READY 11 +#define RDB_TYPE_GtoH_KDEBUG 12 +#define RDB_TYPE_GtoH_PROF_DATA 22 + + +#define RDB_TYPE_HtoG_LOG_DONE 13 +#define RDB_TYPE_HtoG_DEBUG 14 +#define RDB_TYPE_HtoG_DEBUG_CT 15 +#define RDB_TYPE_HtoG_DATA 16 +#define RDB_TYPE_HtoG_DATA_DONE 17 +#define RDB_TYPE_HtoG_REQ_RAMROM 18 +#define RDB_TYPE_HtoG_FREE_RAMROM 19 +#define RDB_TYPE_HtoG_KDEBUG 20 +#define RDB_TYPE_HtoG_PROF_SIGNAL 21 + + +#define RDB_PROF_ACK_SIG 1 +#define RDB_PROF_FLUSH_SIG 2 +#define PROF_BLOCK_SIZE 2048 + +#define RDB_LOG_MAX_BLOCK_SIZE 0x8000 +#define RDB_DATA_MAX_BLOCK_SIZE 0x8000 + + +/* GIO side address */ +#define GIO_RDB_BASE_REG 0xbf480000 +#define GIO_RDB_WRITE_INTR_REG (GIO_RDB_BASE_REG + 0x8) +#define GIO_RDB_READ_INTR_REG (GIO_RDB_BASE_REG + 0xc) + +/* minor device number */ +#define GIO_RDB_PRINT_MINOR 1 +#define GIO_RDB_DEBUG_MINOR 2 + +/* interrupt bit */ +#define GIO_RDB_WRITE_INTR_BIT 0x80000000 +#define GIO_RDB_READ_INTR_BIT 0x40000000 + +/* debug command */ +#define DEBUG_COMMAND_NULL 0 +#define DEBUG_COMMAND_MEMORY 1 +#define DEBUG_COMMAND_REGISTER 2 +#define DEBUG_COMMAND_INVALID 255 + +/* debug state */ +#define DEBUG_STATE_NULL 0 +#define DEBUG_STATE_RECEIVE 1 +#define DEBUG_STATE_INVALID 255 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Structure for debug port */ +typedef struct { + unsigned type : 6; /* 0: invalid, 1: print, 2: debug */ + unsigned length : 2; /* 1, 2, or 3 */ + char buf[3]; /* character buffer */ +} rdbPacket; + +extern unsigned int __osRdbWriteOK; +extern unsigned int __osRdbSendMessage; + +#endif /* _LANGUAGE_C */ + +#endif /* !_RDB_H */ diff --git a/lib/ultralib/include/PR/region.h b/lib/ultralib/include/PR/region.h new file mode 100644 index 0000000..0ac8a25 --- /dev/null +++ b/lib/ultralib/include/PR/region.h @@ -0,0 +1,123 @@ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * Module: region.h + * + * $Revision: 1.8 $ + * $Date: 1997/11/26 00:30:56 $ + * $Author: mitu $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/region.h,v $ + * + * Description: + * This file contains macros and structure definitions for the region + * library. + * + **************************************************************************/ + + +#ifndef _REGION_H_ +#define _REGION_H_ + + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + + +/*************************************** + * + * Global defines + * + */ + /* Alignment sizes */ +#define ALIGNSZ (sizeof(long long)) /* 8 bytes */ +#define ALIGNOFFST (ALIGNSZ-1) + + /* size for storing index to free buffer */ +#define BUF_CTRL_SIZE ALIGNSZ + + /* Max bufcount = 32K */ +#define MAX_BUFCOUNT 0x8000 + /* code for last free buffer */ +#define BUF_FREE_WO_NEXT 0x8000 + +/* + * Global defines for alignment size (default is 8-byte alignment) + */ +#define OS_RG_ALIGN_2B 2 /* 2 bytes = 16-bit alignment */ +#define OS_RG_ALIGN_4B 4 /* 4 bytes = 32-bit alignment */ +#define OS_RG_ALIGN_8B 8 /* 8 bytes = 64-bit alignment */ +#define OS_RG_ALIGN_16B 16 /* 16 bytes = 128-bit alignment */ + +#define OS_RG_ALIGN_DEFAULT OS_RG_ALIGN_8B + + +/*************************************** + * + * Macro definitions + * + */ + +/* Perform alignment on input 's' */ +#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1)) + + +/*************************************** + * + * Typedefs & structure definitions + * + */ +/* + * Structure for region header/control area + */ +typedef struct _Region_s { + u8 *r_startBufferAddress; /* start address to data buffer */ + u8 *r_endAddress; /* end address of region */ + s32 r_bufferSize; /* size of buffers for this region */ + s32 r_bufferCount; /* up to 32K entries; MSB is used for + setting end-of-list/used */ + u16 r_freeList; /* point to array index of first + available memory buffer */ + u16 r_alignSize; /* alignment size (# of bytes) */ +} OSRegion; + +/* + * Macro to simplify accessing region header structure + */ +#define RP(x) rp->r_##x + + +/*************************************** + * + * Function prototypes + * + */ +extern void *osCreateRegion(void *, u32, u32, u32); +extern void *osMalloc(void *); +extern void osFree(void *, void *); +extern s32 osGetRegionBufCount(void *); +extern s32 osGetRegionBufSize(void *); + + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + + +#endif /* _REGION_H_ */ + + diff --git a/lib/ultralib/include/PR/rmon.h b/lib/ultralib/include/PR/rmon.h new file mode 100644 index 0000000..199e569 --- /dev/null +++ b/lib/ultralib/include/PR/rmon.h @@ -0,0 +1,39 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 1997/02/11 08:30:08 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rmon.h,v $ + * + **************************************************************************/ + +#ifndef _RMON_H_ +#define _RMON_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#define RMON_DBG_BUF_SIZE 2048 +#define RMON_STACKSIZE 0x1000 + +extern void rmonMain( void * ); +extern void rmonPrintf( const char *, ... ); + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_H */ diff --git a/lib/ultralib/include/PR/sched.h b/lib/ultralib/include/PR/sched.h new file mode 100644 index 0000000..2d305a2 --- /dev/null +++ b/lib/ultralib/include/PR/sched.h @@ -0,0 +1,115 @@ +/*==================================================================== + * sched.h + * + * Synopsis: + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.7 $ + * $Date: 1997/02/11 08:32:02 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sched.h,v $ + * + **************************************************************************/ + +#ifndef __sched__ +#define __sched__ + +#include + +#define OS_SC_STACKSIZE 0x2000 + +#define OS_SC_RETRACE_MSG 1 +#define OS_SC_DONE_MSG 2 +#define OS_SC_RDP_DONE_MSG 3 +#define OS_SC_PRE_NMI_MSG 4 +#define OS_SC_LAST_MSG 4 /* this should have highest number */ +#define OS_SC_MAX_MESGS 8 + +typedef struct { + short type; + char misc[30]; +} OSScMsg; + +typedef struct OSScTask_s { + struct OSScTask_s *next; /* note: this must be first */ + u32 state; + u32 flags; + void *framebuffer; /* used by graphics tasks */ + + OSTask list; + OSMesgQueue *msgQ; + OSMesg msg; +#ifndef _FINALROM /* all #ifdef items should */ + OSTime startTime; /* remain at the end!!, or */ + OSTime totalTime; /* possible conflict if */ +#endif /* FINALROM library used with */ +} OSScTask; /* non FINALROM code */ + +/* + * OSScTask flags: + */ +#define OS_SC_NEEDS_RDP 0x0001 /* uses the RDP */ +#define OS_SC_NEEDS_RSP 0x0002 /* uses the RSP */ +#define OS_SC_DRAM_DLIST 0x0004 /* SP & DP communicate through DRAM */ +#define OS_SC_PARALLEL_TASK 0x0010 /* must be first gfx task on list */ +#define OS_SC_LAST_TASK 0x0020 /* last task in queue for frame */ +#define OS_SC_SWAPBUFFER 0x0040 /* swapbuffers when gfx task done */ + +#define OS_SC_RCP_MASK 0x0003 /* mask for needs bits */ +#define OS_SC_TYPE_MASK 0x0007 /* complete type mask */ +/* + * OSScClient: + * + * Data structure used by threads that wish to communicate to the + * scheduling thread + * + */ +typedef struct SCClient_s { + struct SCClient_s *next; /* next client in the list */ + OSMesgQueue *msgQ; /* where to send the frame msg */ +} OSScClient; + +typedef struct { + OSScMsg retraceMsg; + OSScMsg prenmiMsg; + OSMesgQueue interruptQ; + OSMesg intBuf[OS_SC_MAX_MESGS]; + OSMesgQueue cmdQ; + OSMesg cmdMsgBuf[OS_SC_MAX_MESGS]; + OSThread thread; + OSScClient *clientList; + OSScTask *audioListHead; + OSScTask *gfxListHead; + OSScTask *audioListTail; + OSScTask *gfxListTail; + OSScTask *curRSPTask; + OSScTask *curRDPTask; + u32 frameCount; + s32 doAudio; +} OSSched; + +void osCreateScheduler(OSSched *s, void *stack, OSPri priority, + u8 mode, u8 numFields); +void osScAddClient(OSSched *s, OSScClient *c, OSMesgQueue *msgQ); +void osScRemoveClient(OSSched *s, OSScClient *c); +OSMesgQueue *osScGetCmdQ(OSSched *s); + +#endif + diff --git a/lib/ultralib/include/PR/sp.h b/lib/ultralib/include/PR/sp.h new file mode 100644 index 0000000..8167ca2 --- /dev/null +++ b/lib/ultralib/include/PR/sp.h @@ -0,0 +1,196 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * Sprite library include file + * + * $Revision: 1.16 $ + * $Date: 1998/04/17 05:03:46 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sp.h,v $ + * + **************************************************************************/ + +#ifndef _SP_H_ +#define _SP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include + +struct bitmap { + s16 width; /* Size across to draw in texels */ + /* Done if width = 0 */ + + s16 width_img; /* Size across of bitmap in texels */ + /* Done if width = 0 */ + + s16 s; /* Horizontal offset into bitmap */ + /* if (s > width), then load only! */ + + s16 t; /* Vertical offset into base */ + + void *buf; /* Pointer to bitmap data */ + /* Don't re-load if new buf */ + /* is the same as the old one */ + /* Skip if NULL */ + + s16 actualHeight; /* True Height of this bitmap piece */ + + s16 LUToffset; /* LUT base index */ +}; + +typedef struct bitmap Bitmap; + +struct sprite { + s16 x,y; /* Target position */ + + s16 width, height; /* Target size */ + + f32 scalex, scaley; /* Texel to Pixel scale factor */ + + s16 expx, expy; /* Explosion spacing */ + + u16 attr; /* Attribute Flags */ + s16 zdepth; /* Z Depth */ + + u8 red; /* Red component */ + u8 green; /* Green component */ + u8 blue; /* Blue component */ + u8 alpha; /* Alpha component */ + + s16 startTLUT; /* Lookup Table Entry Starting index */ + s16 nTLUT; /* Total number of Lookup Table Entries */ + + int *LUT; /* Pointer to Lookup Table */ + + s16 istart; /* Starting bitmap index */ + s16 istep; /* Bitmaps index step (see SP_INCY) */ + /* if 0, then variable width bitmaps */ + + s16 nbitmaps; /* Total number of bitmaps */ + s16 ndisplist; /* Total number of display-list words */ + + s16 bmheight; /* Bitmap Texel height (Used) */ + s16 bmHreal; /* Bitmap Texel height (Real) */ + u8 bmfmt; /* Bitmap Format */ + u8 bmsiz; /* Bitmap Texel Size */ + + Bitmap *bitmap; /* Pointer to first bitmap */ + + Gfx *rsp_dl; /* Pointer to RSP display list */ + + Gfx *rsp_dl_next; /* Pointer to next RSP display entry */ + + s16 frac_s, /* Fractional Texture offsets */ + frac_t; /* These have 5 fraction bits */ +}; + +typedef struct sprite Sprite; + +/* + * DANGER! + * This is bad programming. Where the *heck* do these numbers come + * from? + * + * They are obviously 'maximums' from the sprite library, but since + * the sprite library is built on top of gbi.h, which includes macros + * that decode into multiple macros, etc., it is nearly impossible to + * know what these maximums should be. + * + * Worse, there are some gbi macros (texture alignment mostly) that + * decode into *many* macros, so if we choose that as a maximum, we + * are wasting TONS of space... + * + * These numbers work for "reasonable" sprite library usage, and + * there is an assert() in the library to detect when they aren't + * enough. (use the debug version) + */ +#define DL_BM_OVERHEAD (12) +#define DL_SPRITE_OVERHEAD (24) + +#define NUM_DL(nb) ((nb)*DL_BM_OVERHEAD +DL_SPRITE_OVERHEAD) + +/* + * Misc constants + */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +/* + * For sprite->attr + */ + +#define SP_TRANSPARENT 0x00000001 +#define SP_CUTOUT 0x00000002 +#define SP_HIDDEN 0x00000004 +#define SP_Z 0x00000008 +#define SP_SCALE 0x00000010 +#define SP_FASTCOPY 0x00000020 +#define SP_OVERLAP 0x00000040 +#define SP_TEXSHIFT 0x00000080 +#define SP_FRACPOS 0x00000100 +#define SP_TEXSHUF 0x00000200 +#define SP_EXTERN 0x00000400 + +/* + * Function wrapper + */ +#if defined(F3DEX_GBI_2) +#define spMove spX2Move +#define spSetZ spX2SetZ +#define spScissor spX2Scissor +#define spDraw spX2Draw +#define spInit spX2Init +#define spFinish spX2Finish +#elif defined(F3DEX_GBI) +#define spMove spXMove +#define spSetZ spXSetZ +#define spScissor spXScissor +#define spDraw spXDraw +#define spInit spXInit +#define spFinish spXFinish +#endif + +/* + * Function prototypes + */ + +void spSetAttribute (Sprite *sp, s32 attr); +void spClearAttribute (Sprite *sp, s32 attr); +void spMove (Sprite *sp, s32 x, s32 y); +void spScale (Sprite *sp, f32 sx, f32 sy); +void spSetZ (Sprite *sp, s32 z ); +void spColor (Sprite *sp, u8 red, u8 green, u8 blue, u8 alpha); +Gfx *spDraw (Sprite *sp); +void spInit( Gfx **glistp ); +void spScissor( s32 xmin, s32 xmax, s32 ymin, s32 ymax ); +void spFinish( Gfx **glistp ); + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* _SP_H_ */ diff --git a/lib/ultralib/include/PR/sptask.h b/lib/ultralib/include/PR/sptask.h new file mode 100644 index 0000000..960cab9 --- /dev/null +++ b/lib/ultralib/include/PR/sptask.h @@ -0,0 +1,201 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.9 $ + * $Date: 1998/03/05 06:40:29 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sptask.h,v $ + * + **************************************************************************/ + +#ifndef _SPTASK_H_ +#define _SPTASK_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Task List Structure. + * + * Things an app might pass to the SP via the task list. + * Not every task ucode would need/use every field, but + * + * - type (audio, gfx, video, ...) + * - flags + * - wait for DP to drain before running new task + * - SEE BIT DEFINITIONS UNDER "Task Flags field" + * - pointer to boot ucode + * - size of boot ucode + * - pointer to ucode + * - size of ucode + * - pointer to initial DMEM data + * - size of initial DMEM data + * - pointer to DRAM stack + * - size of DRAM stack (max) + * - pointer to output buffer + * - pointer to store output buffer length + * - generic data pointer (for display list, etc.) + * - generic data length (for display list, etc.) + * - pointer to buffer where to store saved DMEM (in yield case) + * - size of buffer to store saved DMEM. + * + * IMPORTANT!!! Watch alignment issues. + * + * IMPORTANT!!! Watch data cache issues. The RCP may write data into the + * dram_stack, output_buff, output_buff_size, and the yield_data_ptr areas. + * These buffers should be cache aligned and use the entire line (16 bytes) to + * avoid corruption by writebacks by the CPU (cache tearing). + * + * IMPORTANT!!! all addresses are virtual addresses. Library does + * any necessary translation. + * + */ +typedef struct { + u32 type; + u32 flags; + + u64 *ucode_boot; + u32 ucode_boot_size; + + u64 *ucode; + u32 ucode_size; + + u64 *ucode_data; + u32 ucode_data_size; + + u64 *dram_stack; + u32 dram_stack_size; + + u64 *output_buff; + u64 *output_buff_size; + + u64 *data_ptr; + u32 data_size; + + u64 *yield_data_ptr; + u32 yield_data_size; + +} OSTask_t; + +typedef union { + OSTask_t t; + long long int force_structure_alignment; +} OSTask; + +typedef u32 OSYieldResult; + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_ASSEMBLY + +/* + * For the RSP ucode: + * offsets into the task structure + */ + +#include + +#endif + +/* + * Task Flags field + */ +#define OS_TASK_YIELDED 0x0001 +#define OS_TASK_DP_WAIT 0x0002 +#define OS_TASK_LOADABLE 0x0004 +#define OS_TASK_SP_ONLY 0x0008 +#define OS_TASK_USR0 0x0010 +#define OS_TASK_USR1 0x0020 +#define OS_TASK_USR2 0x0040 +#define OS_TASK_USR3 0x0080 + +/* + * Size of Yield buffer. The taskHdrPtr->t.yield_data_ptr must point to a + * buffer of this size. (The size is in bytes). ONLY If the task will NEVER + * yield it may be a null pointer. The buffer must be aligned to a 64 bit + * boundary. The taskHdrPtr->t.yield_data_ptr must be set to point to the + * buffer BEFORE the task is started. + */ +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)||defined(F3DEX_GBI_2)) +#define OS_YIELD_DATA_SIZE 0xc00 +#else +#define OS_YIELD_DATA_SIZE 0x900 +#endif +#define OS_YIELD_AUDIO_SIZE 0x400 + +/************************************************************************** + * + * Global definitions + * + */ + + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* + * this macro simulates atomic action. + */ +#define osSpTaskStart(tp) \ + { \ + osSpTaskLoad((tp)); \ + osSpTaskStartGo((tp)); \ + } + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* + * break this up into two steps for debugging. + */ +extern void osSpTaskLoad(OSTask *tp); +extern void osSpTaskStartGo(OSTask *tp); + +extern void osSpTaskYield(void); +extern OSYieldResult osSpTaskYielded(OSTask *tp); + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_SPTASK_H */ diff --git a/lib/ultralib/include/PR/ucode.h b/lib/ultralib/include/PR/ucode.h new file mode 100644 index 0000000..e43f52a --- /dev/null +++ b/lib/ultralib/include/PR/ucode.h @@ -0,0 +1,192 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.15 $ + * $Date: 1998/03/31 07:58:57 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ucode.h,v $ + * + **************************************************************************/ + +#ifndef _UCODE_H_ +#define _UCODE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* + * This is the recommended size of the SP DRAM stack area, used + * by the graphics ucode. This stack is used primarily for the + * matrix stack, so it needs to be AT LEAST (10 * 64bytes) in size. + */ +#define SP_DRAM_STACK_SIZE8 (1024) +#define SP_DRAM_STACK_SIZE64 (SP_DRAM_STACK_SIZE8 >> 3) + +/* + * This is the size of the IMEM, which is also the size of the + * graphics microcode. (other ucode might be less) + * This value is used in apps to tell the OS how much ucode to + * load. + */ +#define SP_UCODE_SIZE 4096 + +/* + * This is 1/2 the size of DMEM, which is the maximum amount of + * initialized DMEM data any of the ucode tasks need to start up. + * This value is dependent on all of the task ucodes, and is therefore + * fixed per release. + */ +#define SP_UCODE_DATA_SIZE 2048 + + +/************************************************************************** + * + * Extern variables + * + */ + +/* + * Symbols generated by "rsp2elf", included by "makerom" that indicate + * the location and size of the SP microcode objects. The ucode objects + * are loaded as part of the codesegment (arbitrary, could do other + * ways) + * + */ + +/* standard boot ucode: */ +extern long long int rspbootTextStart[], rspbootTextEnd[]; + +/* standard 3D ucode: */ +extern long long int gspFast3DTextStart[], gspFast3DTextEnd[]; +extern long long int gspFast3DDataStart[], gspFast3DDataEnd[]; + +/* 3D ucode with output to DRAM: */ +extern long long int gspFast3D_dramTextStart[], gspFast3D_dramTextEnd[]; +extern long long int gspFast3D_dramDataStart[], gspFast3D_dramDataEnd[]; + +/* 3D ucode with output through DRAM FIFO to RDP: */ +extern long long int gspFast3D_fifoTextStart[], gspFast3D_fifoTextEnd[]; +extern long long int gspFast3D_fifoDataStart[], gspFast3D_fifoDataEnd[]; + +/* 3D ucode without nearclip: */ +extern long long int gspF3DNoNTextStart[], gspF3DNoNTextEnd[]; +extern long long int gspF3DNoNDataStart[], gspF3DNoNDataEnd[]; + +/* 3D ucode without nearclip with output to DRAM: */ +extern long long int gspF3DNoN_dramTextStart[]; +extern long long int gspF3DNoN_dramTextEnd[]; +extern long long int gspF3DNoN_dramDataStart[]; +extern long long int gspF3DNoN_dramDataEnd[]; + +/* 3D ucode without nearclip with output through DRAM FIFO to RDP: */ +extern long long int gspF3DNoN_fifoTextStart[]; +extern long long int gspF3DNoN_fifoTextEnd[]; +extern long long int gspF3DNoN_fifoDataStart[]; +extern long long int gspF3DNoN_fifoDataEnd[]; + +/* 3D line ucode: */ +extern long long int gspLine3DTextStart[], gspLine3DTextEnd[]; +extern long long int gspLine3DDataStart[], gspLine3DDataEnd[]; + +/* 3D line ucode with output to DRAM: */ +extern long long int gspLine3D_dramTextStart[], gspLine3D_dramTextEnd[]; +extern long long int gspLine3D_dramDataStart[], gspLine3D_dramDataEnd[]; + +/* 3D line ucode with output through DRAM FIFO to RDP: */ +extern long long int gspLine3D_fifoTextStart[], gspLine3D_fifoTextEnd[]; +extern long long int gspLine3D_fifoDataStart[], gspLine3D_fifoDataEnd[]; + +/* 2D sprite ucode: */ +extern long long int gspSprite2DTextStart[], gspSprite2DTextEnd[]; +extern long long int gspSprite2DDataStart[], gspSprite2DDataEnd[]; + +/* 2D sprite ucode with output to DRAM: */ +extern long long int gspSprite2D_dramTextStart[], gspSprite2D_dramTextEnd[]; +extern long long int gspSprite2D_dramDataStart[], gspSprite2D_dramDataEnd[]; + +/* 2D sprite ucode with output through DRAM FIFO to RDP: */ +extern long long int gspSprite2D_fifoTextStart[], gspSprite2D_fifoTextEnd[]; +extern long long int gspSprite2D_fifoDataStart[], gspSprite2D_fifoDataEnd[]; + +/* basic audio ucode: */ +extern long long int aspMainTextStart[], aspMainTextEnd[]; +extern long long int aspMainDataStart[], aspMainDataEnd[]; + +/*========== F3DEX/F3DLX/F3DLP/L3DEX ==========*/ +/* FIFO version only */ +extern long long int gspF3DEX_fifoTextStart[], gspF3DEX_fifoTextEnd[]; +extern long long int gspF3DEX_fifoDataStart[], gspF3DEX_fifoDataEnd[]; +extern long long int gspF3DEX_NoN_fifoTextStart[], gspF3DEX_NoN_fifoTextEnd[]; +extern long long int gspF3DEX_NoN_fifoDataStart[], gspF3DEX_NoN_fifoDataEnd[]; + +extern long long int gspF3DLX_fifoTextStart[], gspF3DLX_fifoTextEnd[]; +extern long long int gspF3DLX_fifoDataStart[], gspF3DLX_fifoDataEnd[]; +extern long long int gspF3DLX_NoN_fifoTextStart[], gspF3DLX_NoN_fifoTextEnd[]; +extern long long int gspF3DLX_NoN_fifoDataStart[], gspF3DLX_NoN_fifoDataEnd[]; +extern long long int gspF3DLX_Rej_fifoTextStart[], gspF3DLX_Rej_fifoTextEnd[]; +extern long long int gspF3DLX_Rej_fifoDataStart[], gspF3DLX_Rej_fifoDataEnd[]; + +extern long long int gspF3DLP_Rej_fifoTextStart[], gspF3DLP_Rej_fifoTextEnd[]; +extern long long int gspF3DLP_Rej_fifoDataStart[], gspF3DLP_Rej_fifoDataEnd[]; +extern long long int gspL3DEX_fifoTextStart[], gspL3DEX_fifoTextEnd[]; +extern long long int gspL3DEX_fifoDataStart[], gspL3DEX_fifoDataEnd[]; + +/*========== F3DEX2/F3DLX2/F3DLP2/L3DEX2 ==========*/ +/* FIFO version */ +extern long long int gspF3DEX2_fifoTextStart[], gspF3DEX2_fifoTextEnd[]; +extern long long int gspF3DEX2_fifoDataStart[], gspF3DEX2_fifoDataEnd[]; +extern long long int gspF3DEX2_NoN_fifoTextStart[],gspF3DEX2_NoN_fifoTextEnd[]; +extern long long int gspF3DEX2_NoN_fifoDataStart[],gspF3DEX2_NoN_fifoDataEnd[]; +extern long long int gspF3DEX2_Rej_fifoTextStart[],gspF3DEX2_Rej_fifoTextEnd[]; +extern long long int gspF3DEX2_Rej_fifoDataStart[],gspF3DEX2_Rej_fifoDataEnd[]; +extern long long int gspF3DLX2_Rej_fifoTextStart[],gspF3DLX2_Rej_fifoTextEnd[]; +extern long long int gspF3DLX2_Rej_fifoDataStart[],gspF3DLX2_Rej_fifoDataEnd[]; +extern long long int gspL3DEX2_fifoTextStart[], gspL3DEX2_fifoTextEnd[]; +extern long long int gspL3DEX2_fifoDataStart[], gspL3DEX2_fifoDataEnd[]; + +/* XBUS version */ +extern long long int gspF3DEX2_xbusTextStart[], gspF3DEX2_xbusTextEnd[]; +extern long long int gspF3DEX2_xbusDataStart[], gspF3DEX2_xbusDataEnd[]; +extern long long int gspF3DEX2_NoN_xbusTextStart[],gspF3DEX2_NoN_xbusTextEnd[]; +extern long long int gspF3DEX2_NoN_xbusDataStart[],gspF3DEX2_NoN_xbusDataEnd[]; +extern long long int gspF3DEX2_Rej_xbusTextStart[],gspF3DEX2_Rej_xbusTextEnd[]; +extern long long int gspF3DEX2_Rej_xbusDataStart[],gspF3DEX2_Rej_xbusDataEnd[]; +extern long long int gspF3DLX2_Rej_xbusTextStart[],gspF3DLX2_Rej_xbusTextEnd[]; +extern long long int gspF3DLX2_Rej_xbusDataStart[],gspF3DLX2_Rej_xbusDataEnd[]; +extern long long int gspL3DEX2_xbusTextStart[], gspL3DEX2_xbusTextEnd[]; +extern long long int gspL3DEX2_xbusDataStart[], gspL3DEX2_xbusDataEnd[]; + +/************************************************************************** + * + * Function prototypes + * + */ + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_UCODE_H */ diff --git a/lib/ultralib/include/PR/ultraerror.h b/lib/ultralib/include/PR/ultraerror.h new file mode 100644 index 0000000..ebaf59a --- /dev/null +++ b/lib/ultralib/include/PR/ultraerror.h @@ -0,0 +1,165 @@ +/*==================================================================== + * ultraerror.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.27 $ + * $Date: 1999/07/14 02:44:00 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultraerror.h,v $ + * + **************************************************************************/ + +#ifndef __ULTRAERROR_H__ +#define __ULTRAERROR_H__ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" + +#define OS_ERROR_FMT "/usr/lib/PR/error.fmt" +#define OS_ERROR_MAGIC 0x6b617479 + +/* OS error codes */ + +#define ERR_OSCREATETHREAD_SP 1 +#define ERR_OSCREATETHREAD_PRI 2 +#define ERR_OSSTARTTHREAD 3 +#define ERR_OSSETTHREADPRI 4 +#define ERR_OSCREATEMESGQUEUE 5 +#define ERR_OSSENDMESG 6 +#define ERR_OSJAMMESG 7 +#define ERR_OSRECVMESG 8 +#define ERR_OSSETEVENTMESG 9 +#define ERR_OSMAPTLB_INDEX 10 +#define ERR_OSMAPTLB_ASID 11 +#define ERR_OSUNMAPTLB 12 +#define ERR_OSSETTLBASID 13 +#define ERR_OSAISETFREQUENCY 14 +#define ERR_OSAISETNEXTBUFFER_ADDR 15 +#define ERR_OSAISETNEXTBUFFER_SIZE 16 +#define ERR_OSDPSETNEXTBUFFER_ADDR 17 +#define ERR_OSDPSETNEXTBUFFER_SIZE 18 +#define ERR_OSPIRAWREADIO 19 +#define ERR_OSPIRAWWRITEIO 20 +#define ERR_OSPIRAWSTARTDMA_DIR 21 +#define ERR_OSPIRAWSTARTDMA_DEVADDR 22 +#define ERR_OSPIRAWSTARTDMA_ADDR 23 +#define ERR_OSPIRAWSTARTDMA_SIZE 24 +#define ERR_OSPIRAWSTARTDMA_RANGE 25 +#define ERR_OSPIREADIO 26 +#define ERR_OSPIWRITEIO 27 +#define ERR_OSPISTARTDMA_PIMGR 28 +#define ERR_OSPISTARTDMA_PRI 29 +#define ERR_OSPISTARTDMA_DIR 30 +#define ERR_OSPISTARTDMA_DEVADDR 31 +#define ERR_OSPISTARTDMA_ADDR 32 +#define ERR_OSPISTARTDMA_SIZE 33 +#define ERR_OSPISTARTDMA_RANGE 34 +#define ERR_OSCREATEPIMANAGER 35 +#define ERR_OSVIGETCURRENTMODE 36 +#define ERR_OSVIGETCURRENTFRAMEBUFFER 37 +#define ERR_OSVIGETNEXTFRAMEBUFFER 38 +#define ERR_OSVISETXSCALE_VALUE 39 +#define ERR_OSVISETXSCALE_VIMGR 40 +#define ERR_OSVISETYSCALE_VALUE 41 +#define ERR_OSVISETYSCALE_VIMGR 42 +#define ERR_OSVISETSPECIAL_VALUE 43 +#define ERR_OSVISETSPECIAL_VIMGR 44 +#define ERR_OSVISETMODE 45 +#define ERR_OSVISETEVENT 46 +#define ERR_OSVISWAPBUFFER_ADDR 47 +#define ERR_OSVISWAPBUFFER_VIMGR 48 +#define ERR_OSCREATEVIMANAGER 49 +#define ERR_OSCREATEREGION_ALIGN 50 +#define ERR_OSCREATEREGION_SIZE 51 +#define ERR_OSMALLOC 52 +#define ERR_OSFREE_REGION 53 +#define ERR_OSFREE_ADDR 54 +#define ERR_OSGETREGIONBUFCOUNT 55 +#define ERR_OSGETREGIONBUFSIZE 56 +#define ERR_OSSPTASKLOAD_DRAM 57 +#define ERR_OSSPTASKLOAD_OUT 58 +#define ERR_OSSPTASKLOAD_OUTSIZE 59 +#define ERR_OSSPTASKLOAD_YIELD 60 +#define ERR_OSPROFILEINIT_STR 61 +#define ERR_OSPROFILEINIT_CNT 62 +#define ERR_OSPROFILEINIT_ALN 63 +#define ERR_OSPROFILEINIT_ORD 64 +#define ERR_OSPROFILEINIT_SIZ 65 +#define ERR_OSPROFILESTART_TIME 66 +#define ERR_OSPROFILESTART_FLAG 67 +#define ERR_OSPROFILESTOP_FLAG 68 +#define ERR_OSPROFILESTOP_TIMER 69 +#define ERR_OSREADHOST_ADDR 70 +#define ERR_OSREADHOST_SIZE 71 +#define ERR_OSWRITEHOST_ADDR 72 +#define ERR_OSWRITEHOST_SIZE 73 +#define ERR_OSGETTIME 74 +#define ERR_OSSETTIME 75 +#define ERR_OSSETTIMER 76 +#define ERR_OSSTOPTIMER 77 +#define ERR_ALSEQP_NO_SOUND 100 +#define ERR_ALSEQP_NO_VOICE 101 +#define ERR_ALSEQP_MAP_VOICE 102 +#define ERR_ALSEQP_OFF_VOICE 103 +#define ERR_ALSEQP_POLY_VOICE 104 +#define ERR_ALSNDP_NO_VOICE 105 +#define ERR_ALSYN_NO_UPDATE 106 +#define ERR_ALSNDPDEALLOCATE 107 +#define ERR_ALSNDPDELETE 108 +#define ERR_ALSNDPPLAY 109 +#define ERR_ALSNDPSETSOUND 110 +#define ERR_ALSNDPSETPRIORITY 111 +#define ERR_ALSNDPSETPAR 112 +#define ERR_ALBNKFNEW 113 +#define ERR_ALSEQNOTMIDI 114 +#define ERR_ALSEQNOTMIDI0 115 +#define ERR_ALSEQNUMTRACKS 116 +#define ERR_ALSEQTIME 117 +#define ERR_ALSEQTRACKHDR 118 +#define ERR_ALSEQSYSEX 119 +#define ERR_ALSEQMETA 120 +#define ERR_ALSEQPINVALIDPROG 121 +#define ERR_ALSEQPUNKNOWNMIDI 122 +#define ERR_ALSEQPUNMAP 123 +#define ERR_ALEVENTNOFREE 124 +#define ERR_ALHEAPNOFREE 125 +#define ERR_ALHEAPCORRUPT 126 +#define ERR_ALHEAPFIRSTBLOCK 127 +#define ERR_ALCSEQZEROSTATUS 128 +#define ERR_ALCSEQZEROVEL 129 +#define ERR_ALCSPVNOTFREE 130 +#define ERR_ALSEQOVERRUN 131 +#define ERR_OSAISETNEXTBUFFER_ENDADDR 132 +#define ERR_ALMODDELAYOVERFLOW 133 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) +typedef void (*OSErrorHandler)(s16, s16, ...); + +OSErrorHandler osSetErrorHandler(OSErrorHandler); +#endif + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* __ULTRAERROR_H__ */ diff --git a/lib/ultralib/include/PR/ultralog.h b/lib/ultralib/include/PR/ultralog.h new file mode 100644 index 0000000..48b84b9 --- /dev/null +++ b/lib/ultralib/include/PR/ultralog.h @@ -0,0 +1,74 @@ +/*==================================================================== + * ultralog.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 1997/02/11 08:39:05 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultralog.h,v $ + * + **************************************************************************/ + +#ifndef __log__ +#define __log__ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#define OS_LOG_MAX_ARGS 16 +#define OS_LOG_MAGIC 0x20736a73 +#define OS_LOG_FLOAT(x) (*(int *) &(x)) +#define OS_LOG_VERSION 1 + +typedef struct { + u32 magic; /* log identifier */ + u32 len; /* length of log data + log structure */ + u32 *base; /* starting addr array */ + s32 startCount; /* read offset from dataBase */ + s32 writeOffset; /* write offset from dataBase */ +} OSLog; + +typedef struct { + u32 magic; + u32 timeStamp; + u16 argCount; + u16 eventID; +} OSLogItem; + +typedef struct { + u32 magic; /* log identifier */ + u32 version; /* 1 */ +} OSLogFileHdr; + +void osCreateLog(OSLog *log, u32 *base, s32 len); +void osLogEvent(OSLog *log, s16 code, s16 numArgs, ...); +void osFlushLog(OSLog *log); +u32 osLogFloat(f32); + +extern void osDelay(int count); + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif diff --git a/lib/ultralib/include/PR/ultratypes.h b/lib/ultralib/include/PR/ultratypes.h new file mode 100644 index 0000000..235cc73 --- /dev/null +++ b/lib/ultralib/include/PR/ultratypes.h @@ -0,0 +1,85 @@ +#ifndef _ULTRATYPES_H_ +#define _ULTRATYPES_H_ + + +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + + +/************************************************************************* + * + * File: ultratypes.h + * + * This file contains various types used in Ultra64 interfaces. + * + * $Revision: 1.6 $ + * $Date: 1997/12/17 04:02:06 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultratypes.h,v $ + * + **************************************************************************/ + + + +/********************************************************************** + * General data types for R4300 + */ +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +typedef unsigned char u8; /* unsigned 8-bit */ +typedef unsigned short u16; /* unsigned 16-bit */ +typedef unsigned long u32; /* unsigned 32-bit */ +typedef unsigned long long u64; /* unsigned 64-bit */ + +typedef signed char s8; /* signed 8-bit */ +typedef short s16; /* signed 16-bit */ +typedef long s32; /* signed 32-bit */ +typedef long long s64; /* signed 64-bit */ + +typedef volatile unsigned char vu8; /* unsigned 8-bit */ +typedef volatile unsigned short vu16; /* unsigned 16-bit */ +typedef volatile unsigned long vu32; /* unsigned 32-bit */ +typedef volatile unsigned long long vu64; /* unsigned 64-bit */ + +typedef volatile signed char vs8; /* signed 8-bit */ +typedef volatile short vs16; /* signed 16-bit */ +typedef volatile long vs32; /* signed 32-bit */ +typedef volatile long long vs64; /* signed 64-bit */ + +typedef float f32; /* single prec floating point */ +typedef double f64; /* double prec floating point */ + +#if !defined(_SIZE_T) && !defined(_SIZE_T_) && !defined(_SIZE_T_DEF) +#define _SIZE_T +#define _SIZE_T_DEF /* exeGCC size_t define label */ +#if (_MIPS_SZLONG == 32) +typedef unsigned int size_t; +#endif +#if (_MIPS_SZLONG == 64) +typedef unsigned long size_t; +#endif +#endif + +#endif /* _LANGUAGE_C */ + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#endif /* _ULTRATYPES_H_ */ diff --git a/lib/ultralib/include/asm.h b/lib/ultralib/include/asm.h new file mode 100644 index 0000000..1de9f0a --- /dev/null +++ b/lib/ultralib/include/asm.h @@ -0,0 +1 @@ +#include diff --git a/lib/ultralib/include/assert.h b/lib/ultralib/include/assert.h new file mode 100644 index 0000000..bfbf255 --- /dev/null +++ b/lib/ultralib/include/assert.h @@ -0,0 +1,12 @@ +#ifndef __ASSERT_H__ +#define __ASSERT_H__ + +#ifdef NDEBUG +#undef assert +#define assert(EX) ((void)0) +#else +extern void __assert(const char *, const char *, int); +#define assert(EX) ((EX)?((void)0):__assert("EX", __FILE__, __LINE__)) +#endif /* NDEBUG */ + +#endif /* !__ASSERT_H__ */ diff --git a/lib/ultralib/include/dbgdefs.h b/lib/ultralib/include/dbgdefs.h new file mode 100644 index 0000000..f7ead71 --- /dev/null +++ b/lib/ultralib/include/dbgdefs.h @@ -0,0 +1,8 @@ +#ifndef _DBGDEFS_H__ +#define _DBGDEFS_H__ + +typedef int TVid; +typedef unsigned short TVushort; +typedef char TVuchar; + +#endif diff --git a/lib/ultralib/include/dbgproto.h b/lib/ultralib/include/dbgproto.h new file mode 100644 index 0000000..2eabf9a --- /dev/null +++ b/lib/ultralib/include/dbgproto.h @@ -0,0 +1,402 @@ +#ifndef _DBGPROTO_H__ +#define _DBGPROTO_H__ + +#include "dbgdefs.h" + +#define KK_REV 2 + +#define KK_CODE_THREAD_STATUS 4 + +#define KK_TYPE_REQUEST 0 +#define KK_TYPE_REPLY 1 +#define KK_TYPE_EXCEPTION 2 +#define KK_TYPE_THREAD_EXIT 3 +#define KK_TYPE_PROCESS_EXIT 4 +#define KK_TYPE_CONSOLE 5 + +#define TV_ERROR_NO_ERROR 0 +#define TV_ERROR_ILLEGAL_CALL -1 +#define TV_ERROR_INVALID_ID -2 +#define TV_ERROR_INVALID_TYPE -3 +#define TV_ERROR_OPERATIONS_PROTECTED -4 +#define TV_ERROR_INVALID_ADDRESS -5 +#define TV_ERROR_INVALID_PRIORITY -6 +#define TV_ERROR_INVALID_FLAGS -7 +#define TV_ERROR_INVALID_CAPABILITY -8 +#define TV_ERROR_NO_HANDLER -9 +#define TV_ERROR_NO_MORE_IDS -10 +#define TV_ERROR_NO_MORE_MESSAGES -11 +#define TV_ERROR_NO_MORE_PROCESSES -12 +#define TV_ERROR_NO_MORE_THREADS -13 +#define TV_ERROR_NO_MORE_REGIONS -14 +#define TV_ERROR_NO_MORE_TIMERS -15 +#define TV_ERROR_NO_MORE_LOCKS -16 +#define TV_ERROR_NO_MORE_QUEUES -17 +#define TV_ERROR_NO_MORE_SETS -18 +#define TV_ERROR_NO_MORE_MEMORY -19 +#define TV_ERROR_NOT_LOCKED -20 + +typedef struct __KKTimeStruct { + long seconds; + long nanoseconds; +} KKTimeStruct; + +typedef struct __KKObjsStruct { + TVushort number; + TVid objects[1]; +} KKObjs; + +typedef struct __KKFaultInfoStruct { + unsigned int addr; + short major; + short minor; +} KKFaultInfo; + +typedef struct __KKThreadStatusStruct { + int flags; + short why; + short what; + TVid tid; + TVid pid; + unsigned int instr; + KKFaultInfo info; + int priority; + int start; + int rv; + unsigned int args[6]; +} KKThreadStatus; + +#define KK_RUN_SSTEP (1 << 0) +#define KK_RUN_SETPC (1 << 1) + +typedef struct __KKRunStruct { + int flags; + unsigned int vaddr; +} KKRun; + +typedef struct __KKFaultStruct { + short majorMask; + short minorMask; +} KKFault; + +typedef struct __KKRegionStruct { + unsigned int vaddr; + unsigned int size; + short flags; + unsigned int paddr; +} KKRegion; + +typedef struct __KKGregSetStruct { + unsigned int gregs[37]; +} KKGregSet; + +typedef struct __KKFPregSetStruct { + union { + double dregs[16]; + float fregs[32]; + unsigned int regs[32]; + } fpregs; + unsigned int fpcsr; + unsigned int fppad; +} KKFPregSet; + +typedef struct __KKRegisterContextStruct { + KKGregSet gregs; + KKFPregSet fpregs; +} KKRegisterContext; + +typedef struct __KKCpScalarSetStruct { + unsigned int sregs[40]; +} KKCpScalarRegSet; + +typedef struct __KKCpVectorSetStruct { + unsigned int vregs[128]; +} KKCpVectorRegSet; + +typedef struct __KKCpRegisterContextStruct { + KKCpScalarRegSet sregs; + KKCpVectorRegSet vregs; +} KKCpRegisterContext; + +typedef struct __KKUsageStruct { + KKTimeStruct tstamp; + KKTimeStruct created; + KKTimeStruct states[10]; +} KKUsage; + +typedef struct __KKLogEventSetStruct { + int from; + int to; +} KKLogEventSet; + +typedef struct __KKLogStatusStruct { + int bufferType; + int bufferSize; + int dataSize; + int logState; + int flushLimit; +} KKLogStatus; + +typedef struct __KKProcUsageStruct { + TVid pid; + KKTimeStruct states[10]; +} KKProcUsage; + +typedef struct __KKHeaderStruct { + int length; + char code; + char type; + short error; + char rev; + char method; + short notused2; +} KKHeader; + +typedef struct __KKGetFrameRequestStruct { + KKHeader header; + int height; + int width; + int which; +} KKGetFrameRequest; + +typedef struct __KKLoadExecutableRequestStruct { + KKHeader header; + char str[1]; +} KKLoadExecutableRequest; + +typedef struct __KKObjectRequestStruct { + KKHeader header; + TVid object; +} KKObjectRequest; + +typedef struct __KKRunThreadRequestStruct { + KKHeader header; + TVid tid; + KKRun actions; +} KKRunThreadRequest; + +typedef struct __KKFaultRequestStruct { + KKHeader header; + TVid tid; + KKFault fault; + TVuchar stopAllThreads; +} KKFaultRequest; + +typedef struct __KKGRegsetRequestStruct { + KKHeader header; + TVid tid; + KKGregSet registers; +} KKGRegsetRequest; + +typedef struct __KKFPRegsetRequestStruct { + KKHeader header; + TVid tid; + KKFPregSet registers; +} KKFPRegsetRequest; + +typedef struct __KKCpScalarRegsetRequestStruct { + KKHeader header; + TVid tid; + KKCpScalarRegSet registers; +} KKCpScalarRegsetRequest; + +typedef struct __KKCpVectorRegsetRequestStruct { + KKHeader header; + TVid tid; + KKCpVectorRegSet registers; +} KKCpVectorRegsetRequest; + +typedef struct __KKReadRequestStruct { + KKHeader header; + TVid object; + unsigned int addr; + unsigned int nbytes; +} KKReadRequest; + +typedef struct __KKWriteHeaderStruct { + KKHeader header; + TVid object; + unsigned int addr; + unsigned int nbytes; +} KKWriteHeader; + +typedef struct __KKWriteRequestStruct { + KKWriteHeader writeHeader; + char buffer[1]; +} KKWriteRequest; + +typedef struct __KKSetBkptRequestStruct { + KKHeader header; + TVid object; + unsigned int addr; +} KKSetBkptRequest; + +typedef struct __KKClrBkptRequestStruct { + KKHeader header; + TVid object; + TVid bp; +} KKClrBkptRequest; + +typedef struct __KKWatchRequestStruct { + KKHeader header; + TVid object; + unsigned int number; + KKRegion wp[1]; +} KKWatchRequest; + +typedef struct __KKSetCommRequestStruct { + KKHeader header; + unsigned int how; + unsigned int addr; +} KKSetCommRequest; + +typedef struct __KKSysCallSetStruct { + unsigned int word[8]; +} KKSysCallSet; + +typedef struct __KKSysCallRequestStruct { + KKHeader header; + TVid pid; + KKSysCallSet syscallset; +} KKSysCallRequest; + +typedef struct __KKLogEventRequestStruct { + KKHeader header; + unsigned int numSet; + KKLogEventSet set[1]; +} KKLogEventRequest; + +typedef struct __KKNewLogRequestStruct { + KKHeader header; + char str[1]; +} KKNewLogRequest; + +typedef struct __KKRemoteRequestStruct { + KKHeader header; + int len; + char buf[16]; +} KKRemoteRequest; + +typedef struct __KKFlushLogRequestStruct { + KKHeader header; + int no_block; +} KKFlushLogRequest; + +typedef struct __KKLogControlRequestStruct { + KKHeader header; + int command; + int arg; +} KKLogControlRequest; + +typedef struct __KKSetTrptRequestStruct { + KKSetBkptRequest bpRequest; + unsigned short code; +} KKSetTrptRequest; + +typedef KKClrBkptRequest KKClrTrptRequest; + +typedef struct __KKObjectEventStruct { + KKHeader header; + TVid object; +} KKObjectEvent; + +typedef struct __KKObjsEventStruct { + KKHeader header; + TVid object; + KKObjs objs; +} KKObjsEvent; + +typedef struct __KKBufferEventStruct { + KKHeader header; + TVid object; + char buffer[1]; +} KKBufferEvent; + +typedef struct __KKStatusEventStruct { + KKHeader header; + KKThreadStatus status; +} KKStatusEvent; + +typedef struct __KKFaultEventStruct { + KKHeader header; + TVid tid; + KKFault fault; + TVuchar stopAllThreads; +} KKFaultEvent; + +typedef struct __KKNumberEventStruct { + KKHeader header; + TVid object; + unsigned int number; +} KKNumberEvent; + +typedef struct __KKRegionEventStruct { + KKHeader header; + TVid object; + unsigned int number; + KKRegion regions[1]; +} KKRegionEvent; + +typedef struct __KKGregEventStruct { + KKHeader header; + TVid tid; + KKGregSet registers; +} KKGregEvent; + +typedef struct __KKFPregEventStruct { + KKHeader header; + TVid tid; + KKFPregSet registers; +} KKFPregEvent; + +typedef struct __KKCpSregEventStruct { + KKHeader header; + TVid tid; + KKCpScalarRegSet registers; +} KKCpSregEvent; + +typedef struct __KKCpVregEventStruct { + KKHeader header; + TVid tid; + KKCpVectorRegSet registers; +} KKCpVregEvent; + +typedef struct __KKBkptEventStruct { + KKHeader header; + TVid object; + TVid bp; + unsigned int instruction; +} KKBkptEvent; + +typedef struct __KKUsageEventStruct { + KKHeader header; + TVid tid; + KKUsage usage; +} KKUsageEvent; + +typedef struct __KKFlushEventStruct { + KKHeader header; + int bufferType; + char buffer[1]; +} KKFlushEvent; + +typedef struct __KKLogStatusEventStruct { + KKHeader header; + KKLogStatus status; +} KKLogStatusEvent; + +typedef struct __KKSysUsageEventStruct { + KKHeader header; + KKTimeStruct tstamp; + int numProc; + KKProcUsage usage[1]; +} KKSysUsageEvent; + +typedef struct __KKStringEventStruct { + KKHeader header; + char str[1]; +} KKStringEvent; + +typedef KKSysCallRequest KKSysCallEvent; + +#endif diff --git a/lib/ultralib/include/fpregdef.h b/lib/ultralib/include/fpregdef.h new file mode 100644 index 0000000..e69de29 diff --git a/lib/ultralib/include/gcc/math.h b/lib/ultralib/include/gcc/math.h new file mode 100644 index 0000000..3e93ceb --- /dev/null +++ b/lib/ultralib/include/gcc/math.h @@ -0,0 +1 @@ +// Nothing needed here diff --git a/lib/ultralib/include/gcc/memory.h b/lib/ultralib/include/gcc/memory.h new file mode 100644 index 0000000..edfff5e --- /dev/null +++ b/lib/ultralib/include/gcc/memory.h @@ -0,0 +1,23 @@ +#ifndef _MEMORY_H +#define _MEMORY_H +/* + memory.h +*/ + +#ifndef _SIZE_T_DEF +#define _SIZE_T_DEF +typedef unsigned size_t; +#endif + +void *memccpy(void *,void *,int,size_t); +void *memchr(void *,int,size_t); +int memcmp(const void *,const void *,size_t); +void *memcpy(void *,const void *,size_t); +int memicmp(void *,void *,size_t); +void *memmove(void *,void *,size_t); +void *memset(void *,int,size_t); + +void movmem(void *,void *,unsigned); +void setmem(void *,unsigned,int); + +#endif diff --git a/lib/ultralib/include/gcc/sgidefs.h b/lib/ultralib/include/gcc/sgidefs.h new file mode 100644 index 0000000..56567e8 --- /dev/null +++ b/lib/ultralib/include/gcc/sgidefs.h @@ -0,0 +1,44 @@ +/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ralf Baechle . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _SGIDEFS_H +#define _SGIDEFS_H 1 + +/* + * Definitions for the ISA level + */ +#define _MIPS_ISA_MIPS1 1 +#define _MIPS_ISA_MIPS2 2 +#define _MIPS_ISA_MIPS3 3 +#define _MIPS_ISA_MIPS4 4 +#define _MIPS_ISA_MIPS5 5 + +/* + * Subprogram calling convention + * + * At the moment only _MIPS_SIM_ABI32 is in use. This will change rsn. + * Until GCC 2.8.0 is released don't rely on this definitions because the + * 64bit code is essentially using the 32bit interface model just with + * 64bit registers. + */ +#define _MIPS_SIM_ABI32 1 +#define _MIPS_SIM_NABI32 2 +#define _MIPS_SIM_ABI64 3 + +#endif /* sgidefs.h */ diff --git a/lib/ultralib/include/gcc/stdarg.h b/lib/ultralib/include/gcc/stdarg.h new file mode 100644 index 0000000..af337f6 --- /dev/null +++ b/lib/ultralib/include/gcc/stdarg.h @@ -0,0 +1,121 @@ +#ifndef _STDARG_H +#define _STDARG_H +/* ---------------------------------------- */ +/* VARARGS for MIPS/GNU CC */ +/* */ +/* */ +/* */ +/* */ +/* ---------------------------------------- */ + +/* These macros implement varargs for GNU C--either traditional or ANSU. */ + +/* Define __gnuc_va_list. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef char * __gnuc_va_list; +#endif /* not __GNUC_VA_LIST */ + +/* If this is for internal libc use, don't define anything but + __gnuc_va_list. */ +#if defined (_STDARG_H) || defined (_VARARGS_H) + +/* In GCC version 2, we want an ellipsis at the end of the declaration + of the argument list. GCC version 1 can't parse it. */ + +#if __GNUC__ > 1 +#define __va_ellipsis ... +#else +#define __va_ellipsis +#endif + +#if __mips>=3 +#define __va_rounded_size(__TYPE) \ + (((sizeof (__TYPE) + 8 - 1) / 8) * 8) +#else +#define __va_rounded_size(__TYPE) \ + (((sizeof (__TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) +#endif + +/* Get definitions for _MIPS_SIM_ABI64 etc. */ +#ifdef _MIPS_SIM +#include +#endif + +#ifdef _STDARG_H +#if defined(_MIPS_SIM) && (_MIPS_SIM == _MIPS_SIM_ABI64) +#define va_start(__AP, __LASTARG) \ + (__AP = __builtin_next_arg (__LASTARG) - 64 \ + + (__builtin_args_info (2) > 8 ? 64 : __builtin_args_info(2) * 8)) +#else +#define va_start(__AP, __LASTARG) \ + (__AP = (__gnuc_va_list) __builtin_next_arg (__LASTARG)) +#endif + +#else +#define va_alist __builtin_va_alist +#if __mips>=3 +/* This assumes that `long long int' is always a 64 bit type. */ +#define va_dcl long long int __builtin_va_alist; __va_ellipsis +#else +#define va_dcl int __builtin_va_alist; __va_ellipsis +#endif +/* Need alternate code for _MIPS_SIM_ABI64, but don't use that symbol + because it may not be defined. */ +#if defined(_MIPS_SIM) && (_MIPS_SIM == _MIPS_SIM_ABI64) +#define va_start(__AP) \ + (__AP = __builtin_next_arg () - 64 \ + + (__builtin_args_info (2) > 8 ? 64 : __builtin_args_info(2) * 8)) +#else +#define va_start(__AP) __AP = (char *) &__builtin_va_alist +#endif +#endif + +#ifndef va_end +void va_end (__gnuc_va_list); /* Defined in libgcc.a */ +#endif +#define va_end(__AP) ((void)0) + +/* We cast to void * and then to TYPE * because this avoids + a warning about increasing the alignment requirement. */ +/* The __mips>=3 cases are reversed from the 32 bit cases, because the standard + 32 bit calling convention left-aligns all parameters smaller than a word, + whereas the __mips>=3 calling convention does not (and hence they are + right aligned). */ +#if __mips>=3 +#ifdef __MIPSEB__ +#define va_arg(__AP, __type) \ + ((__type *) (void *) (__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \ + + __va_rounded_size (__type))))[-1] +#else +#define va_arg(__AP, __type) \ + ((__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \ + + __va_rounded_size (__type))), \ + *(__type *) (void *) (__AP - __va_rounded_size (__type))) +#endif + +#else /* not __mips>=3 */ + +#ifdef __MIPSEB__ +/* For big-endian machines. */ +#define va_arg(__AP, __type) \ + ((__AP = (char *) ((__alignof__ (__type) > 4 \ + ? ((int)__AP + 8 - 1) & -8 \ + : ((int)__AP + 4 - 1) & -4) \ + + __va_rounded_size (__type))), \ + *(__type *) (void *) (__AP - __va_rounded_size (__type))) +#else +/* For little-endian machines. */ +#define va_arg(__AP, __type) \ + ((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4 \ + ? ((int)__AP + 8 - 1) & -8 \ + : ((int)__AP + 4 - 1) & -4) \ + + __va_rounded_size(__type))))[-1] +#endif +#endif + +typedef __gnuc_va_list va_list; + +#endif /* defined (_STDARG_H) || defined (_VARARGS_H) */ +#endif diff --git a/lib/ultralib/include/gcc/stdio.h b/lib/ultralib/include/gcc/stdio.h new file mode 100644 index 0000000..3e93ceb --- /dev/null +++ b/lib/ultralib/include/gcc/stdio.h @@ -0,0 +1 @@ +// Nothing needed here diff --git a/lib/ultralib/include/gcc/stdlib.h b/lib/ultralib/include/gcc/stdlib.h new file mode 100644 index 0000000..98f8a2e --- /dev/null +++ b/lib/ultralib/include/gcc/stdlib.h @@ -0,0 +1,81 @@ +#ifndef _STDLIB_H +#define _STDLIB_H +/* + stdlib.h +*/ + +#ifndef _SIZE_T_DEF +#define _SIZE_T_DEF +typedef unsigned size_t; +#endif + +#ifndef _DIV_T_DEF +#define _DIV_T_DEF +typedef struct DIV_T { + int quot; + int rem; +} div_t; +#endif + +#ifndef _LDIV_T_DEF +#define _LDIV_T_DEF +typedef struct LDIV_T { + long quot; + long rem; +} ldiv_t; +#endif + +#ifndef _LLDIV_T_DEF +#define _LLDIV_T_DEF +typedef struct lldiv_t +{ + long long quot; + long long rem; +} lldiv_t; +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#define _max(a,b) (((a) > (b)) ? (a) : (b)) +#define _min(a,b) (((a) < (b)) ? (a) : (b)) + +#define RAND_MAX 32767 + +int rand(void); +void srand(unsigned); + +int abs(int); +long labs(long); + +div_t div(int,int); +ldiv_t ldiv(long,long); +lldiv_t lldiv(long long, long long); + +int atoi(const char *); +long atol(const char *); + +long strtol(const char *,char **,int); +unsigned long strtoul(const char *,char **,int); + +char *itoa(int,char *,int); +char *ltoa(long,char *,int); +char *ultoa(unsigned long,char *,int); + +double atof(const char *); +double strtod(const char *,char **); + +void qsort(void *,size_t,size_t,int (*)(const void *,const void *)); +void *bsearch(const void *,const void *,size_t,size_t,int (*)(const void *,const void *)); + +void *malloc(size_t); +void *calloc(size_t,size_t); +void *realloc(void *,size_t); +void free(void *); + +void exit(int); + +void abort(void); + +#endif diff --git a/lib/ultralib/include/gcc/string.h b/lib/ultralib/include/gcc/string.h new file mode 100644 index 0000000..d82e1f1 --- /dev/null +++ b/lib/ultralib/include/gcc/string.h @@ -0,0 +1,42 @@ +#ifndef _STRING_H +#define _STRING_H +/* + string.h +*/ + +#ifndef _SIZE_T_DEF +#define _SIZE_T_DEF +typedef unsigned size_t; +#endif + +#include "memory.h" + +char *stpcpy(char *,const char *); +char *strcat(char *,const char *); +char *strchr(const char *,int); +int strcmp(const char *,const char *); +char *strcpy(char *,const char *); +size_t strcspn(const char *,const char *); +char *strdup(const char *); +char *strerror(int); +int stricmp(const char *,const char *); +size_t strlen(const char *); +char *strlwr(char *); +char *strncat(char *,const char *,size_t); +int strncmp(const char *,const char *,size_t); +char *strncpy(char *,const char *,size_t); +int strnicmp(const char *,const char *,size_t); +char *strnset(char *,int,size_t); +char *strpbrk(const char *,const char *); +char *strrchr(const char *,int); +char *strrev(char *); +char *strset(char *,int); +size_t strspn(const char *,const char *); +char *strstr(const char *,const char *); +char *strtok(char *,const char *); +char *strupr(char *); + +#define strcmpi(s1,s2) stricmp(s1,s2) +#define strncmpi(s1,s2,n) strnicmp(s1,s2,n) + +#endif diff --git a/lib/ultralib/include/ido/math.h b/lib/ultralib/include/ido/math.h new file mode 100644 index 0000000..3e93ceb --- /dev/null +++ b/lib/ultralib/include/ido/math.h @@ -0,0 +1 @@ +// Nothing needed here diff --git a/lib/ultralib/include/ido/memory.h b/lib/ultralib/include/ido/memory.h new file mode 100644 index 0000000..edfff5e --- /dev/null +++ b/lib/ultralib/include/ido/memory.h @@ -0,0 +1,23 @@ +#ifndef _MEMORY_H +#define _MEMORY_H +/* + memory.h +*/ + +#ifndef _SIZE_T_DEF +#define _SIZE_T_DEF +typedef unsigned size_t; +#endif + +void *memccpy(void *,void *,int,size_t); +void *memchr(void *,int,size_t); +int memcmp(const void *,const void *,size_t); +void *memcpy(void *,const void *,size_t); +int memicmp(void *,void *,size_t); +void *memmove(void *,void *,size_t); +void *memset(void *,int,size_t); + +void movmem(void *,void *,unsigned); +void setmem(void *,unsigned,int); + +#endif diff --git a/lib/ultralib/include/ido/stdarg.h b/lib/ultralib/include/ido/stdarg.h new file mode 100644 index 0000000..62f68e0 --- /dev/null +++ b/lib/ultralib/include/ido/stdarg.h @@ -0,0 +1,33 @@ +#ifndef _STDARG_H +#define _STDARG_H + +typedef char *va_list; +#define _FP 1 +#define _INT 0 +#define _STRUCT 2 + +#define _VA_FP_SAVE_AREA 0x10 +#define _VA_ALIGN(p, a) (((unsigned int)(((char *)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) +#define va_start(vp, parmN) (vp = ((va_list)&parmN + sizeof(parmN))) + +#define __va_stack_arg(list, mode) \ + ( \ + ((list) = (char *)_VA_ALIGN(list, __builtin_alignof(mode)) + \ + _VA_ALIGN(sizeof(mode), 4)), \ + (((char *)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode)))) + +#define __va_double_arg(list, mode) \ + ( \ + (((long)list & 0x1) /* 1 byte aligned? */ \ + ? (list = (char *)((long)list + 7), (char *)((long)list - 6 - _VA_FP_SAVE_AREA)) \ + : (((long)list & 0x2) /* 2 byte aligned? */ \ + ? (list = (char *)((long)list + 10), (char *)((long)list - 24 - _VA_FP_SAVE_AREA)) \ + : __va_stack_arg(list, mode)))) + +#define va_arg(list, mode) ((mode *)(((__builtin_classof(mode) == _FP && \ + __builtin_alignof(mode) == sizeof(double)) \ + ? __va_double_arg(list, mode) \ + : __va_stack_arg(list, mode))))[-1] +#define va_end(__list) + +#endif /* STDARG_H */ diff --git a/lib/ultralib/include/ido/stdio.h b/lib/ultralib/include/ido/stdio.h new file mode 100644 index 0000000..3e93ceb --- /dev/null +++ b/lib/ultralib/include/ido/stdio.h @@ -0,0 +1 @@ +// Nothing needed here diff --git a/lib/ultralib/include/ido/stdlib.h b/lib/ultralib/include/ido/stdlib.h new file mode 100644 index 0000000..98f8a2e --- /dev/null +++ b/lib/ultralib/include/ido/stdlib.h @@ -0,0 +1,81 @@ +#ifndef _STDLIB_H +#define _STDLIB_H +/* + stdlib.h +*/ + +#ifndef _SIZE_T_DEF +#define _SIZE_T_DEF +typedef unsigned size_t; +#endif + +#ifndef _DIV_T_DEF +#define _DIV_T_DEF +typedef struct DIV_T { + int quot; + int rem; +} div_t; +#endif + +#ifndef _LDIV_T_DEF +#define _LDIV_T_DEF +typedef struct LDIV_T { + long quot; + long rem; +} ldiv_t; +#endif + +#ifndef _LLDIV_T_DEF +#define _LLDIV_T_DEF +typedef struct lldiv_t +{ + long long quot; + long long rem; +} lldiv_t; +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#define _max(a,b) (((a) > (b)) ? (a) : (b)) +#define _min(a,b) (((a) < (b)) ? (a) : (b)) + +#define RAND_MAX 32767 + +int rand(void); +void srand(unsigned); + +int abs(int); +long labs(long); + +div_t div(int,int); +ldiv_t ldiv(long,long); +lldiv_t lldiv(long long, long long); + +int atoi(const char *); +long atol(const char *); + +long strtol(const char *,char **,int); +unsigned long strtoul(const char *,char **,int); + +char *itoa(int,char *,int); +char *ltoa(long,char *,int); +char *ultoa(unsigned long,char *,int); + +double atof(const char *); +double strtod(const char *,char **); + +void qsort(void *,size_t,size_t,int (*)(const void *,const void *)); +void *bsearch(const void *,const void *,size_t,size_t,int (*)(const void *,const void *)); + +void *malloc(size_t); +void *calloc(size_t,size_t); +void *realloc(void *,size_t); +void free(void *); + +void exit(int); + +void abort(void); + +#endif diff --git a/lib/ultralib/include/ido/string.h b/lib/ultralib/include/ido/string.h new file mode 100644 index 0000000..d82e1f1 --- /dev/null +++ b/lib/ultralib/include/ido/string.h @@ -0,0 +1,42 @@ +#ifndef _STRING_H +#define _STRING_H +/* + string.h +*/ + +#ifndef _SIZE_T_DEF +#define _SIZE_T_DEF +typedef unsigned size_t; +#endif + +#include "memory.h" + +char *stpcpy(char *,const char *); +char *strcat(char *,const char *); +char *strchr(const char *,int); +int strcmp(const char *,const char *); +char *strcpy(char *,const char *); +size_t strcspn(const char *,const char *); +char *strdup(const char *); +char *strerror(int); +int stricmp(const char *,const char *); +size_t strlen(const char *); +char *strlwr(char *); +char *strncat(char *,const char *,size_t); +int strncmp(const char *,const char *,size_t); +char *strncpy(char *,const char *,size_t); +int strnicmp(const char *,const char *,size_t); +char *strnset(char *,int,size_t); +char *strpbrk(const char *,const char *); +char *strrchr(const char *,int); +char *strrev(char *); +char *strset(char *,int); +size_t strspn(const char *,const char *); +char *strstr(const char *,const char *); +char *strtok(char *,const char *); +char *strupr(char *); + +#define strcmpi(s1,s2) stricmp(s1,s2) +#define strncmpi(s1,s2,n) strnicmp(s1,s2,n) + +#endif diff --git a/lib/ultralib/include/macros.h b/lib/ultralib/include/macros.h new file mode 100644 index 0000000..3057fc8 --- /dev/null +++ b/lib/ultralib/include/macros.h @@ -0,0 +1,16 @@ +#ifndef __MACROS_H__ +#define __MACROS_H__ + +#define ALIGNED(x) __attribute__((aligned(x))) + +#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) + +#define STUBBED_PRINTF(x) ((void)(x)) + +#define UNUSED __attribute__((unused)) + +#ifndef __GNUC__ +#define __attribute__(x) +#endif + +#endif diff --git a/lib/ultralib/include/regdef.h b/lib/ultralib/include/regdef.h new file mode 100644 index 0000000..c29cc69 --- /dev/null +++ b/lib/ultralib/include/regdef.h @@ -0,0 +1,3 @@ +#include +#include +#include diff --git a/lib/ultralib/include/sgidefs.h b/lib/ultralib/include/sgidefs.h new file mode 100644 index 0000000..8d4b6e1 --- /dev/null +++ b/lib/ultralib/include/sgidefs.h @@ -0,0 +1,3 @@ +#ifdef __GNUC__ +#include "gcc/sgidefs.h" +#endif diff --git a/lib/ultralib/include/sys/asm.h b/lib/ultralib/include/sys/asm.h new file mode 100644 index 0000000..97f8fb2 --- /dev/null +++ b/lib/ultralib/include/sys/asm.h @@ -0,0 +1,116 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO Co,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/07/06 13:21:13 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#ifndef __ASM_H__ +#define __ASM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define _MIPS_ISA_MIPS1 1 /* R2/3K */ +#define _MIPS_ISA_MIPS2 2 /* R4K/6K */ +#define _MIPS_ISA_MIPS3 3 /* R4K */ +#define _MIPS_ISA_MIPS4 4 /* TFP */ + +#define _MIPS_SIM_ABI32 1 /* MIPS MSIG calling convention */ +#define _MIPS_SIM_NABI32 2 /* MIPS new 32-bit abi */ + /* NABI32 is 64bit calling convention but 32bit type sizes) */ +#define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ + + +/* libgultra doesn't match with the .type directive but iQue sdk asm.h uses it */ +#ifdef BBPLAYER +#define ASM_TYPE_FUNC(x) .type x, @function +#else +#define ASM_TYPE_FUNC(x) +#endif + +#define LEAF(x) \ + .globl x ;\ + .align 2 ;\ + ASM_TYPE_FUNC(x) ;\ + .ent x,0 ;\ + x: ;\ + .frame sp,0,ra + +#if defined(BBPLAYER) || defined(__sgi) +#define XLEAF(x) \ + .globl x ;\ + .aent x,0 ;\ + x: +#else +#define XLEAF(x) \ + .globl x +#endif + +#ifdef BBPLAYER +#define END(proc) \ + .end proc ;\ + .size proc, . - proc +#else +#define END(proc) \ + .end proc +#endif + +#define ABS(x, y) \ + .globl x ;\ + x = y + +#define EXPORT(x) \ + .globl x ;\ + x: + +#if defined(BBPLAYER) || defined(__sgi) +#define WEAK(x, y) \ + .weakext x, y +#else +#define WEAK(x, y) +#endif + + + +#define STAY1(stmnt) \ + .set noreorder ;\ + stmnt ;\ + .set reorder + +#define STAY2(stmnt, arg1) \ + .set noreorder ;\ + stmnt, arg1 ;\ + .set reorder + +#define STAY3(stmnt, arg1, arg2) \ + .set noreorder ;\ + stmnt, arg1, arg2 ;\ + .set reorder + +#define NOP \ + .set noreorder ;\ + nop ;\ + .set reorder + +#define CACHE(op, reg) \ + .set noreorder ;\ + cache op, reg ;\ + .set reorder + +#ifdef __cplusplus +} +#endif + +#endif /* !__ASM_H__ */ diff --git a/lib/ultralib/include/sys/fpregdef.h b/lib/ultralib/include/sys/fpregdef.h new file mode 100644 index 0000000..e69de29 diff --git a/lib/ultralib/include/sys/regdef.h b/lib/ultralib/include/sys/regdef.h new file mode 100644 index 0000000..ac9c109 --- /dev/null +++ b/lib/ultralib/include/sys/regdef.h @@ -0,0 +1,187 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO Co,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/07/06 13:21:13 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#ifndef __REGDEF_H__ +#define __REGDEF_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef mips + +#if (_MIPS_SIM == _MIPS_SIM_ABI32) +#define zero $0 +#define AT $at +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define t0 $8 +#define t1 $9 +#define t2 $10 +#define t3 $11 +#define t4 $12 +#define ta0 $12 +#define t5 $13 +#define ta1 $13 +#define t6 $14 +#define ta2 $14 +#define t7 $15 +#define ta3 $15 +#define s0 $16 +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 +#define t8 $24 +#define t9 $25 +#define jp $25 +#define k0 $26 +#define k1 $27 +#define gp $28 +#define sp $29 +#define fp $30 +#define s8 $30 +#define ra $31 +#endif + +#if (_MIPS_SIM == _MIPS_SIM_ABI64) +#define zero $0 +#define AT $at +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define a4 $8 +#define ta0 $8 +#define a5 $9 +#define ta1 $9 +#define a6 $10 +#define ta2 $10 +#define a7 $11 +#define ta3 $11 +#define t0 $12 +#define t1 $13 +#define t2 $14 +#define t3 $15 +#define s0 $16 +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 +#define t8 $24 +#define t9 $25 +#define jp $25 +#define k0 $26 +#define k1 $27 +#define gp $28 +#define sp $29 +#define fp $30 +#define s8 $30 +#define ra $31 +#endif + +#if (_MIPS_SIM == _MIPS_SIM_ABI32) +#define fv0 $f0 +#define fv0f $f1 +#define fv1 $f2 +#define fv1f $f3 +#define fa0 $f12 +#define fa0f $f13 +#define fa1 $f14 +#define fa1f $f15 +#define ft0 $f4 +#define ft0f $f5 +#define ft1 $f6 +#define ft1f $f7 +#define ft2 $f8 +#define ft2f $f9 +#define ft3 $f10 +#define ft3f $f11 +#define ft4 $f16 +#define ft4f $f17 +#define ft5 $f18 +#define ft5f $f19 +#define fs0 $f20 +#define fs0f $f21 +#define fs1 $f22 +#define fs1f $f23 +#define fs2 $f24 +#define fs2f $f25 +#define fs3 $f26 +#define fs3f $f27 +#define fs4 $f28 +#define fs4f $f29 +#define fs5 $f30 +#define fs5f $f31 +#endif + +#if (_MIPS_SIM == _MIPS_SIM_ABI64) +#define fv0 $f0 +#define fv1 $f2 +#define fa0 $f12 +#define fa1 $f13 +#define fa2 $f14 +#define fa3 $f15 +#define fa4 $f16 +#define fa5 $f17 +#define fa6 $f18 +#define fa7 $f19 +#define ft0 $f4 +#define ft1 $f5 +#define ft2 $f6 +#define ft3 $f7 +#define ft4 $f8 +#define ft5 $f9 +#define ft6 $f10 +#define ft7 $f11 +#define ft8 $f20 +#define ft9 $f21 +#define ft10 $f22 +#define ft11 $f23 +#define ft12 $f1 +#define ft13 $f3 +#define fs0 $f24 +#define fs1 $f25 +#define fs2 $f26 +#define fs3 $f27 +#define fs4 $f28 +#define fs5 $f29 +#define fs6 $f30 +#define fs7 $f31 +#endif + +#define fcr31 $31 + +#endif /* mips */ + +#ifdef __cplusplus +} +#endif + +#endif /* !__REGDEF_H__ */ diff --git a/lib/ultralib/include/ultra64.h b/lib/ultralib/include/ultra64.h new file mode 100644 index 0000000..053db38 --- /dev/null +++ b/lib/ultralib/include/ultra64.h @@ -0,0 +1,40 @@ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + *************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.10 $ + * $Date: 1997/02/11 08:37:33 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultra64.h,v $ + * + **************************************************************************/ + +#ifndef _ULTRA64_H_ +#define _ULTRA64_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/lib/ultralib/include/ultrahost.h b/lib/ultralib/include/ultrahost.h new file mode 100644 index 0000000..2c50b95 --- /dev/null +++ b/lib/ultralib/include/ultrahost.h @@ -0,0 +1,59 @@ +/************************************************************************** + * + * $Revision: 1.1 $ + * $Date: 1999/07/05 02:16:07 $ + * + **************************************************************************/ + +#ifndef _ULTRAHOST_H_ +#define _ULTRAHOST_H_ + +#ifdef WIN32 /* { */ + +int __stdcall uhOpenGame(char *); +int __stdcall uhCloseGame(int); +int __stdcall uhReadGame(int hfd,void *buf,int count); +int __stdcall uhWriteGame(int hfd,void *buf,int count); +int __stdcall uhReadRamrom(int hfd,void *ramrom_adr,void *buf,int count); +int __stdcall uhWriteRamrom(int hfd,void *ramrom_adr,void *buf,int count); +int __stdcall uhPartnerInit(int hfd); +int __stdcall uhPartnerCmd(int hfd,char *ptcmd); +int __stdcall uhGload(int hfd,char *loadfile); + +#else /* }{ */ +#ifdef PTN64 /* { */ + +#define execl execl_pt + +#define uhOpenGame uhOpenGame_pt +#define uhCloseGame uhCloseGame_pt + +#define uhReadGame uhReadGame_pt +#define uhWriteGame uhWriteGame_pt +#define uhReadRamrom uhReadRamrom_pt +#define uhWriteRamrom uhWriteRamrom_pt +#define uhPartnerCmd uhPartnerCmd_pt +#define uhGload uhGload_pt + +int uhPartnerCmd(int,char *); +int uhGload(int,char *); + +#endif /* } */ + +#ifdef __cplusplus +extern "C" { +#endif +int uhOpenGame(const char *); +int uhCloseGame(int); + +int uhReadGame(int, void *, int); +int uhWriteGame(int, void *, int); +int uhWriteRamrom(int, void *, void*, int); +int uhReadRamrom(int, void *, void*, int); + +#ifdef __cplusplus +} +#endif +#endif /* } */ + +#endif /* ULTRAHOST */ diff --git a/lib/ultralib/src/audio/Makefile b/lib/ultralib/src/audio/Makefile new file mode 100644 index 0000000..d8fdce4 --- /dev/null +++ b/lib/ultralib/src/audio/Makefile @@ -0,0 +1,120 @@ +#!smake +# +# Makefile for audio library subdirectory +# + +include $(ROOT)/usr/include/make/PRdefs + +# LCOPTS = -mips2 -non_shared -fullwarn -G 0 +LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include + +CFILES = \ + drvrnew.c \ + load.c \ + auxbus.c \ + bnkf.c \ + env.c \ + event.c \ + filter.c \ + mainbus.c \ + resample.c \ + reverb.c \ + save.c \ + seq.c \ + sl.c \ + heapcheck.c \ + heapinit.c \ + heapalloc.c \ + copy.c \ + seqpdelete.c \ + seqpgetfxmix.c \ + seqpgetpan.c \ + seqpgetchlvol.c \ + seqpgetpriority.c \ + seqpgetprogram.c \ + seqpgetseq.c \ + seqpgettempo.c \ + seqpgetvol.c \ + seqpgetstate.c \ + seqploop.c \ + seqpplay.c \ + seqpsendmidi.c \ + seqpsetbank.c \ + seqpsetfxmix.c \ + seqpsetpan.c \ + seqpsetchlvol.c \ + seqpsetpriority.c \ + seqpsetprogram.c \ + seqpsetseq.c \ + seqpsettempo.c \ + seqpsetvol.c \ + seqpstop.c \ + seqplayer.c \ + cseq.c \ + cspdelete.c \ + cspgetfxmix.c \ + cspgetpan.c \ + cspgetchlvol.c \ + cspgetpriority.c \ + cspgetprogram.c \ + cspgetseq.c \ + cspgettempo.c \ + cspgetvol.c \ + cspgetstate.c \ + cspplay.c \ + cspsendmidi.c \ + cspsetbank.c \ + cspsetfxmix.c \ + cspsetpan.c \ + cspsetchlvol.c \ + cspsetpriority.c \ + cspsetprogram.c \ + cspsetseq.c \ + cspsettempo.c \ + cspsetvol.c \ + cspstop.c \ + csplayer.c \ + sndplayer.c \ + sndpdelete.c \ + sndpallocate.c \ + sndpdeallocate.c \ + sndpsetsound.c \ + sndpplay.c \ + sndpplayat.c \ + sndpgetsound.c \ + sndpstop.c \ + sndpgetstate.c \ + sndpsetpitch.c \ + sndpsetpriority.c \ + sndpsetvol.c \ + sndpsetpan.c \ + sndpsetfxmix.c \ + synthesizer.c \ + syndelete.c \ + synaddplayer.c \ + synremoveplayer.c \ + synfreevoice.c \ + synallocvoice.c \ + synstopvoice.c \ + synstartvoice.c \ + synstartvoiceparam.c \ + synsetpitch.c \ + synsetvol.c \ + synsetfxmix.c \ + synsetpan.c \ + syngetpriority.c \ + synsetpriority.c \ + synallocfx.c \ + synfreefx.c \ + syngetfxref.c \ + synsetfxparam.c \ + cents2ratio.c \ + parse_abi.c + +TARGETS = $(CFILES:.c=.o) + +default : $(TARGETS) + +include $(COMMONRULES) + + diff --git a/lib/ultralib/src/audio/auxbus.c b/lib/ultralib/src/audio/auxbus.c new file mode 100644 index 0000000..471ba41 --- /dev/null +++ b/lib/ultralib/src/audio/auxbus.c @@ -0,0 +1,65 @@ +/*==================================================================== + * auxbus.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" + +Acmd *alAuxBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) +{ + Acmd *ptr = p; + ALAuxBus *m = (ALAuxBus *)filter; + ALFilter **sources = m->sources; + s32 i; + + /* + * clear the output buffers here + */ + aClearBuffer(ptr++, AL_AUX_L_OUT, outCount<<1); + aClearBuffer(ptr++, AL_AUX_R_OUT, outCount<<1); + + for (i = 0; i < m->sourceCount; i++) { + ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset, + ptr); + } + + return ptr; +} + +s32 alAuxBusParam(void *filter, s32 paramID, void *param) +{ + ALAuxBus *m = (ALAuxBus *) filter; + ALFilter **sources = m->sources; + + switch (paramID) { + + case (AL_FILTER_ADD_SOURCE): + sources[m->sourceCount++] = (ALFilter *) param; + break; + + default: + /* ??? */ + break; + } + + return 0; + +} + diff --git a/lib/ultralib/src/audio/bnkf.c b/lib/ultralib/src/audio/bnkf.c new file mode 100644 index 0000000..dfd312f --- /dev/null +++ b/lib/ultralib/src/audio/bnkf.c @@ -0,0 +1,143 @@ +/*==================================================================== + * bnkf.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include + +/* + * ### when the file format settles down a little, I'll remove these + * ### for efficiency. + */ +static void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table); +static void _bnkfPatchInst(ALInstrument *i, s32 offset, s32 table); +static void _bnkfPatchSound(ALSound *s, s32 offset, s32 table); +static void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table); + +void alSeqFileNew(ALSeqFile *file, u8 *base) +{ + s32 offset = (s32) base; + s32 i; + + /* + * patch the file so that offsets are pointers + */ + for (i = 0; i < file->seqCount; i++) { + file->seqArray[i].offset = (u8 *)((u8 *)file->seqArray[i].offset + offset); + } +} + +void alBnkfNew(ALBankFile *file, u8 *table) +{ + s32 offset = (s32) file; + s32 woffset = (s32) table; + + s32 i; + + /* + * check the file format revision in debug libraries + */ + ALFailIf(file->revision != AL_BANK_VERSION, ERR_ALBNKFNEW); + + /* + * patch the file so that offsets are pointers + */ + for (i = 0; i < file->bankCount; i++) { + file->bankArray[i] = (ALBank *)((u8 *)file->bankArray[i] + offset); + if(file->bankArray[i]) + _bnkfPatchBank(file->bankArray[i], offset, woffset); + } +} + +void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table) +{ + s32 i; + + if (bank->flags) + return; + + bank->flags = 1; + + if (bank->percussion) { + bank->percussion = (ALInstrument *)((u8 *)bank->percussion + offset); + _bnkfPatchInst(bank->percussion, offset, table); + } + + for (i = 0; i < bank->instCount; i++) { + bank->instArray[i] = (ALInstrument *)((u8 *)bank->instArray[i] + + offset); + if(bank->instArray[i]) + _bnkfPatchInst(bank->instArray[i], offset, table); + } +} + +void _bnkfPatchInst(ALInstrument *inst, s32 offset, s32 table) +{ + s32 i; + + if (inst->flags) + return; + + inst->flags = 1; + + for (i = 0; i < inst->soundCount; i++) { + inst->soundArray[i] = (ALSound *)((u8 *)inst->soundArray[i] + + offset); + _bnkfPatchSound(inst->soundArray[i], offset, table); + + } +} + +void _bnkfPatchSound(ALSound *s, s32 offset, s32 table) +{ + if (s->flags) + return; + + s->flags = 1; + + s->envelope = (ALEnvelope *)((u8 *)s->envelope + offset); + s->keyMap = (ALKeyMap *)((u8 *)s->keyMap + offset); + + s->wavetable = (ALWaveTable *)((u8 *)s->wavetable + offset); + _bnkfPatchWaveTable(s->wavetable, offset, table); +} + +void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table) +{ + if (w->flags) + return; + + w->flags = 1; + + w->base += table; + + /* sct 2/14/96 - patch wavetable loop info based on type. */ + if (w->type == AL_ADPCM_WAVE) + { + w->waveInfo.adpcmWave.book = (ALADPCMBook *)((u8 *)w->waveInfo.adpcmWave.book + offset); + if (w->waveInfo.adpcmWave.loop) + w->waveInfo.adpcmWave.loop = (ALADPCMloop *)((u8 *)w->waveInfo.adpcmWave.loop + offset); + } + else if (w->type == AL_RAW16_WAVE) + { + if (w->waveInfo.rawWave.loop) + w->waveInfo.rawWave.loop = (ALRawLoop *)((u8 *)w->waveInfo.rawWave.loop + offset); + } +} diff --git a/lib/ultralib/src/audio/cents2ratio.c b/lib/ultralib/src/audio/cents2ratio.c new file mode 100644 index 0000000..55cd2a3 --- /dev/null +++ b/lib/ultralib/src/audio/cents2ratio.c @@ -0,0 +1,33 @@ +/* + * alCents2Ratio() + * + * Calculates the pitch shift ratio from the number of cents according to + * ratio = 2^(cents/1200) + * + * This is accurate to within one cent for ratios up and octave and down + * two ocataves. + */ + +#include + +f32 alCents2Ratio(s32 cents) +{ + f32 x; + f32 ratio = 1.0f; + + if (cents >= 0) { + x = 1.00057779f; /* 2^(1/1200) */ + } else { + x = 0.9994225441f; /* 2^(-1/1200) */ + cents = -cents; + } + + while (cents) { + if (cents & 1) + ratio *= x; + x *= x; + cents >>= 1; + } + + return ratio; +} diff --git a/lib/ultralib/src/audio/copy.c b/lib/ultralib/src/audio/copy.c new file mode 100644 index 0000000..e80a8df --- /dev/null +++ b/lib/ultralib/src/audio/copy.c @@ -0,0 +1,35 @@ +/*==================================================================== + * copy.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCopy(void *src, void *dest, s32 len) +{ + s32 i; + u8 *s = (u8 *)src; + u8 *d = (u8 *)dest; + + for (i = 0; i < len; i++){ + *d++ = *s++; + } +} + diff --git a/lib/ultralib/src/audio/cseq.c b/lib/ultralib/src/audio/cseq.c new file mode 100644 index 0000000..9c4b8bd --- /dev/null +++ b/lib/ultralib/src/audio/cseq.c @@ -0,0 +1,409 @@ +/*==================================================================== + * cseq.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include +#include "cseq.h" + + +static u32 __readVarLen(ALCSeq *s,u32 track); +static u8 __getTrackByte(ALCSeq *s,u32 track); +static u32 __alCSeqGetTrackEvent(ALCSeq *seq, u32 track, ALEvent *event); + +void alCSeqNew(ALCSeq *seq, u8 *ptr) +{ + u32 i,tmpOff,flagTmp; + + /* load the seqence pointed to by ptr */ + seq->base = (ALCMidiHdr*)ptr; + seq->validTracks = 0; + seq->lastDeltaTicks = 0; + seq->lastTicks = 0; + seq->deltaFlag = 1; + + for(i = 0; i < 16; i++) + { + seq->lastStatus[i] = 0; + seq->curBUPtr[i] = 0; + seq->curBULen[i] = 0; + tmpOff = seq->base->trackOffset[i]; + if(tmpOff) /* if the track is valid */ + { + flagTmp = 1 << i; + seq->validTracks |= flagTmp; + seq->curLoc[i] = (u8*)((u32)ptr + tmpOff); + seq->evtDeltaTicks[i] = __readVarLen(seq,i); + /*__alCSeqGetTrackEvent(seq,i); prime the event buffers */ + } + else + seq->curLoc[i] = 0; + } + + seq->qnpt = 1.0/(f32)seq->base->division; +} + +void alCSeqNextEvent(ALCSeq *seq,ALEvent *evt) +{ + u32 i; + u32 firstTime = 0xFFFFFFFF; + u32 firstTrack; + u32 lastTicks = seq->lastDeltaTicks; + +#ifdef _DEBUG + /* sct 1/17/96 - Warn if we are beyond the end of sequence. */ + if (!seq->validTracks) + __osError(ERR_ALSEQOVERRUN, 0); +#endif + + + for(i = 0; i < 16 ; i++) + { + if((seq->validTracks >> i) & 1) + { + if(seq->deltaFlag) + seq->evtDeltaTicks[i] -= lastTicks; + if(seq->evtDeltaTicks[i] < firstTime) + { + firstTime = seq->evtDeltaTicks[i]; + firstTrack = i; + } + } + } + + __alCSeqGetTrackEvent(seq,firstTrack,evt); + + evt->msg.midi.ticks = firstTime; + seq->lastTicks += firstTime; + seq->lastDeltaTicks = firstTime; + if(evt->type != AL_TRACK_END) + seq->evtDeltaTicks[firstTrack] += __readVarLen(seq,firstTrack); + seq->deltaFlag = 1; + +} + + +/* + Note: If there are no valid tracks (ie. all tracks have + reached the end of their data stream), then return FALSE + to indicate that there is no next event. +*/ +char __alCSeqNextDelta(ALCSeq *seq, s32 *pDeltaTicks) +{ + u32 i; + u32 firstTime = 0xFFFFFFFF; + u32 lastTicks = seq->lastDeltaTicks; + + if (!seq->validTracks) + return FALSE; + + for(i = 0; i < 16 ; i++) + { + if((seq->validTracks >> i) & 1) + { + if(seq->deltaFlag) + seq->evtDeltaTicks[i] -= lastTicks; + + if(seq->evtDeltaTicks[i] < firstTime) + firstTime = seq->evtDeltaTicks[i]; + } + } + + seq->deltaFlag = 0; + *pDeltaTicks = firstTime; + + return TRUE; +} + +/* only call alCSeqGetTrackEvent with a valid track !! */ +static u32 __alCSeqGetTrackEvent(ALCSeq *seq, u32 track, ALEvent *event) +{ + u32 offset; + u8 status, loopCt, curLpCt, *tmpPtr; + + + status = __getTrackByte(seq,track); /* read the status byte */ + + if (status == AL_MIDI_Meta) /* running status not allowed on meta events!! */ + { + u8 type = __getTrackByte(seq,track); + + if (type == AL_MIDI_META_TEMPO) + { + event->type = AL_TEMPO_EVT; + event->msg.tempo.status = status; + event->msg.tempo.type = type; + event->msg.tempo.byte1 = __getTrackByte(seq,track); + event->msg.tempo.byte2 = __getTrackByte(seq,track); + event->msg.tempo.byte3 = __getTrackByte(seq,track); + seq->lastStatus[track] = 0; /* lastStatus not supported after meta */ + } + else if (type == AL_MIDI_META_EOT) + { + u32 flagMask; + + flagMask = 0x01 << track; + seq->validTracks = seq->validTracks ^ flagMask; + + if(seq->validTracks) /* there is music left don't end */ + event->type = AL_TRACK_END; + else /* no more music send AL_SEQ_END_EVT msg */ + event->type = AL_SEQ_END_EVT; + } + else if (type == AL_CMIDI_LOOPSTART_CODE) + { + status = __getTrackByte(seq,track); /* get next two bytes, ignore them */ + status = __getTrackByte(seq,track); + seq->lastStatus[track] = 0; + event->type = AL_CSP_LOOPSTART; + } + else if (type == AL_CMIDI_LOOPEND_CODE) + { + tmpPtr = seq->curLoc[track]; + loopCt = *tmpPtr++; + curLpCt = *tmpPtr; + if(curLpCt == 0) /* done looping */ + { + *tmpPtr = loopCt; /* reset current loop count */ + seq->curLoc[track] = tmpPtr + 5; /* move pointer to end of event */ + } + else + { + if(curLpCt != 0xFF) /* not a loop forever */ + *tmpPtr = curLpCt - 1; /* decrement current loop count */ + tmpPtr++; /* get offset from end of event */ + offset = (*tmpPtr++) << 24; + offset += (*tmpPtr++) << 16; + offset += (*tmpPtr++) << 8; + offset += *tmpPtr++; + seq->curLoc[track] = tmpPtr - offset; + } + seq->lastStatus[track] = 0; + event->type = AL_CSP_LOOPEND; + } + +#ifdef _DEBUG + else + __osError(ERR_ALSEQMETA, 1, type); +#endif + + } + else + { + event->type = AL_SEQ_MIDI_EVT; + if (status & 0x80) /* if high bit is set, then new status */ + { + event->msg.midi.status = status; + event->msg.midi.byte1 = __getTrackByte(seq,track); + seq->lastStatus[track] = status; + } + else /* running status */ + { +#ifdef _DEBUG + if(seq->lastStatus[track] == 0) + __osError(ERR_ALCSEQZEROSTATUS, 1, track); +#endif + event->msg.midi.status = seq->lastStatus[track]; + event->msg.midi.byte1 = status; + } + + if (((event->msg.midi.status & 0xf0) != AL_MIDI_ProgramChange) && + ((event->msg.midi.status & 0xf0) != AL_MIDI_ChannelPressure)) + { + event->msg.midi.byte2 = __getTrackByte(seq,track); + if((event->msg.midi.status & 0xf0) == AL_MIDI_NoteOn) + { + event->msg.midi.duration = __readVarLen(seq,track); +#ifdef _DEBUG + if(event->msg.midi.byte2 == 0) + __osError( ERR_ALCSEQZEROVEL, 1, track); +#endif + } + } + else + event->msg.midi.byte2 = 0; + } + return TRUE; +} + +f32 alCSeqTicksToSec(ALCSeq *seq, s32 ticks, u32 tempo) +{ + return ((f32) (((f32)(ticks) * (f32)(tempo)) / + ((f32)(seq->base->division) * 1000000.0))); +} + +u32 alCSeqSecToTicks(ALCSeq *seq, f32 sec, u32 tempo) +{ + return (u32)(((sec * 1000000.0) * seq->base->division) / tempo); +} + + +s32 alCSeqGetTicks(ALCSeq *seq) +{ + return seq->lastTicks; +} + + +void alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks) +{ + ALEvent evt; + ALCSeq tempSeq; + s32 i; + + + alCSeqNew(&tempSeq, (u8*)seq->base); + + do { + m->validTracks = tempSeq.validTracks; + m->lastTicks = tempSeq.lastTicks; + m->lastDeltaTicks = tempSeq.lastDeltaTicks; + + for(i=0;i<16;i++) + { + m->curLoc[i] = tempSeq.curLoc[i]; + m->curBUPtr[i] = tempSeq.curBUPtr[i]; + m->curBULen[i] = tempSeq.curBULen[i]; + m->lastStatus[i] = tempSeq.lastStatus[i]; + m->evtDeltaTicks[i] = tempSeq.evtDeltaTicks[i]; + } + + alCSeqNextEvent(&tempSeq, &evt); + + if (evt.type == AL_SEQ_END_EVT) + break; + + } while (tempSeq.lastTicks < ticks); + +} + +void alCSeqSetLoc(ALCSeq *seq, ALCSeqMarker *m) +{ + s32 i; + + seq->validTracks = m->validTracks; + seq->lastTicks = m->lastTicks; + seq->lastDeltaTicks = m->lastDeltaTicks; + + for(i=0;i<16;i++) + { + seq->curLoc[i] = m->curLoc[i]; + seq->curBUPtr[i] = m->curBUPtr[i]; + seq->curBULen[i] = m->curBULen[i]; + seq->lastStatus[i] = m->lastStatus[i]; + seq->evtDeltaTicks[i] = m->evtDeltaTicks[i]; + } +} + +void alCSeqGetLoc(ALCSeq *seq, ALCSeqMarker *m) +{ + s32 i; + + m->validTracks = seq->validTracks; + m->lastTicks = seq->lastTicks; + m->lastDeltaTicks = seq->lastDeltaTicks; + + for(i=0;i<16;i++) + { + m->curLoc[i] = seq->curLoc[i]; + m->curBUPtr[i] = seq->curBUPtr[i]; + m->curBULen[i] = seq->curBULen[i]; + m->lastStatus[i] = seq->lastStatus[i]; + m->evtDeltaTicks[i] = seq->evtDeltaTicks[i]; + } +} + +/* non-aligned byte reading routines */ +static u8 __getTrackByte(ALCSeq *seq,u32 track) +{ + u8 theByte; + + + if(seq->curBULen[track]) + { + theByte = *seq->curBUPtr[track]; + seq->curBUPtr[track]++; + seq->curBULen[track]--; + } + else /* need to handle backup mode */ + { + theByte = *seq->curLoc[track]; + seq->curLoc[track]++; + if(theByte == AL_CMIDI_BLOCK_CODE) + { + u8 loBackUp,hiBackUp,theLen,nextByte; + u32 backup; + + nextByte = *seq->curLoc[track]; + seq->curLoc[track]++; + if(nextByte != AL_CMIDI_BLOCK_CODE) + { + /* if here, then got a backup section. get the amount of + backup, and the len of the section. Subtract the amount of + backup from the curLoc ptr, and subtract four more, since + curLoc has been advanced by four while reading the codes. */ + hiBackUp = nextByte; + loBackUp = *seq->curLoc[track]; + seq->curLoc[track]++; + theLen = *seq->curLoc[track]; + seq->curLoc[track]++; + backup = (u32)hiBackUp; + backup = backup << 8; + backup += loBackUp; + seq->curBUPtr[track] = seq->curLoc[track] - (backup + 4); + seq->curBULen[track] = (u32)theLen; + + /* now get the byte */ + theByte = *seq->curBUPtr[track]; + seq->curBUPtr[track]++; + seq->curBULen[track]--; + } + } + } + + return theByte; +} + +static u32 __readVarLen(ALCSeq *seq,u32 track) +{ + u32 value; + u32 c; + + value = (u32)__getTrackByte(seq,track); + if ( value & 0x00000080 ) + { + value &= 0x7f; + do + { + c = (u32)__getTrackByte(seq,track); + value = (value << 7) + (c & 0x7f); + } while (c & 0x80); + } + return (value); +} + + + + + + + + + + diff --git a/lib/ultralib/src/audio/cseq.h b/lib/ultralib/src/audio/cseq.h new file mode 100644 index 0000000..0342398 --- /dev/null +++ b/lib/ultralib/src/audio/cseq.h @@ -0,0 +1,11 @@ + + + +#ifndef __cseq__ +#define __cseq__ + + +char __alCSeqNextDelta(ALCSeq *seq, s32 *pDeltaTicks); + + +#endif /* __cseq__ */ diff --git a/lib/ultralib/src/audio/cseqp.h b/lib/ultralib/src/audio/cseqp.h new file mode 100644 index 0000000..bb72541 --- /dev/null +++ b/lib/ultralib/src/audio/cseqp.h @@ -0,0 +1,10 @@ + + +#ifndef __cseqp__ +#define __cseqp__ + + +void __CSPPostNextSeqEvent(ALCSPlayer *seqp); + + +#endif /* __cseqp__ */ diff --git a/lib/ultralib/src/audio/cspdelete.c b/lib/ultralib/src/audio/cspdelete.c new file mode 100644 index 0000000..063c543 --- /dev/null +++ b/lib/ultralib/src/audio/cspdelete.c @@ -0,0 +1,29 @@ +/*==================================================================== + * cspdelete.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPDelete(ALCSPlayer *seqp) +{ + alSynRemovePlayer(seqp->drvr, &seqp->node); +} + diff --git a/lib/ultralib/src/audio/cspgetchlvol.c b/lib/ultralib/src/audio/cspgetchlvol.c new file mode 100644 index 0000000..23d256e --- /dev/null +++ b/lib/ultralib/src/audio/cspgetchlvol.c @@ -0,0 +1,27 @@ +/*==================================================================== + * cspgetchlvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].vol; +} + diff --git a/lib/ultralib/src/audio/cspgetfxmix.c b/lib/ultralib/src/audio/cspgetfxmix.c new file mode 100644 index 0000000..c67e033 --- /dev/null +++ b/lib/ultralib/src/audio/cspgetfxmix.c @@ -0,0 +1,27 @@ +/*==================================================================== + * cspgetfxmix.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +u8 alCSPGetChlFXMix(ALCSPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].fxmix; +} + diff --git a/lib/ultralib/src/audio/cspgetpan.c b/lib/ultralib/src/audio/cspgetpan.c new file mode 100644 index 0000000..5c0e322 --- /dev/null +++ b/lib/ultralib/src/audio/cspgetpan.c @@ -0,0 +1,27 @@ +/*==================================================================== + * cspgetpan.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +ALPan alCSPGetChlPan(ALCSPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].pan; +} + diff --git a/lib/ultralib/src/audio/cspgetpriority.c b/lib/ultralib/src/audio/cspgetpriority.c new file mode 100644 index 0000000..ac38cae --- /dev/null +++ b/lib/ultralib/src/audio/cspgetpriority.c @@ -0,0 +1,26 @@ +/*==================================================================== + * cspgetpriority.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +u8 alCSPGetChlPriority(ALCSPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].priority; +} diff --git a/lib/ultralib/src/audio/cspgetprogram.c b/lib/ultralib/src/audio/cspgetprogram.c new file mode 100644 index 0000000..382616f --- /dev/null +++ b/lib/ultralib/src/audio/cspgetprogram.c @@ -0,0 +1,42 @@ +/*==================================================================== + * cspgetprogram.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s32 alCSPGetChlProgram(ALCSPlayer *seqp, u8 chan) + +{ + s32 i; + ALBank *b = seqp->bank; + ALInstrument *inst; + ALChanState s; + + s = seqp->chanState[chan]; + for (i=0; iinstCount; i++){ + inst = b->instArray[i]; + if (inst == s.instrument) + return i; + } + return(-1); + +} + diff --git a/lib/ultralib/src/audio/cspgetseq.c b/lib/ultralib/src/audio/cspgetseq.c new file mode 100644 index 0000000..85d2545 --- /dev/null +++ b/lib/ultralib/src/audio/cspgetseq.c @@ -0,0 +1,29 @@ +/*==================================================================== + * cspgetseq.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +ALCSeq *alCSPGetSeq(ALCSPlayer *seqp) +{ + return seqp->target; +} + diff --git a/lib/ultralib/src/audio/cspgetstate.c b/lib/ultralib/src/audio/cspgetstate.c new file mode 100644 index 0000000..9be7937 --- /dev/null +++ b/lib/ultralib/src/audio/cspgetstate.c @@ -0,0 +1,29 @@ +/*==================================================================== + * cspgetstate.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s32 alCSPGetState(ALCSPlayer *seqp) +{ + return seqp->state; +} + diff --git a/lib/ultralib/src/audio/cspgettempo.c b/lib/ultralib/src/audio/cspgettempo.c new file mode 100644 index 0000000..ed3dfe2 --- /dev/null +++ b/lib/ultralib/src/audio/cspgettempo.c @@ -0,0 +1,31 @@ +/*==================================================================== + * cspgettempo.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s32 alCSPGetTempo(ALCSPlayer *seqp) +{ + /* sct 1/8/96 - If no target sequence has been set, just return zero (instead of crashing). */ + if (seqp->target == NULL) + return 0; + + return seqp->uspt/seqp->target->qnpt; +} + diff --git a/lib/ultralib/src/audio/cspgetvol.c b/lib/ultralib/src/audio/cspgetvol.c new file mode 100644 index 0000000..5353228 --- /dev/null +++ b/lib/ultralib/src/audio/cspgetvol.c @@ -0,0 +1,27 @@ +/*==================================================================== + * cspgetvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s16 alCSPGetVol(ALCSPlayer *seqp) +{ + return seqp->vol; +} + diff --git a/lib/ultralib/src/audio/csplayer.c b/lib/ultralib/src/audio/csplayer.c new file mode 100644 index 0000000..5cd3df6 --- /dev/null +++ b/lib/ultralib/src/audio/csplayer.c @@ -0,0 +1,882 @@ +/*==================================================================== + * csplayer.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/* + * Notes: + * + * Controller Numbers: + * 1 Modulation + * 7 Volume + * 10 Pan + * 11 Expression + * 64 Sustain + * 121 Reset All Controllers + * 123 All Notes Off + * + * Registered Parameters + * 0 Pitch Bend Sensitivity + * 1 Fine Tuning + * 2 Coarse Tuning + */ + +#include +#include +#include +#include +#include "seqp.h" +#include "cseqp.h" +#include "cseq.h" +// TODO: this comes from a header +#ident "$Revision: 1.17 $" +static ALMicroTime __CSPVoiceHandler(void *node); +static void __CSPHandleNextSeqEvent(ALCSPlayer *seqp); +static void __CSPHandleMIDIMsg(ALCSPlayer *seqp, ALEvent *event); +static void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event); +static void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item); +static void __setUsptFromTempo(ALCSPlayer *seqp, f32 tempo); /* sct 1/8/96 */ + + +/* + * Sequence Player public functions + */ +void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *c) +{ + s32 i; + ALEventListItem *items; + ALVoiceState *vs; + ALVoiceState *voices; + + ALHeap *hp = c->heap; + + /* + * initialize member variables + */ + seqp->bank = 0; + seqp->target = NULL; + seqp->drvr = &alGlobals->drvr; + seqp->chanMask = 0xff; + seqp->uspt = 488; + seqp->nextDelta = 0; + seqp->state = AL_STOPPED; + seqp->vol = 0x7FFF; /* full volume */ + seqp->frameTime = AL_USEC_PER_FRAME; /* should get this from driver */ + seqp->curTime = 0; + seqp->initOsc = c->initOsc; + seqp->updateOsc = c->updateOsc; + seqp->stopOsc = c->stopOsc; + + seqp->nextEvent.type = AL_SEQP_API_EVT; /* this will start the voice handler "spinning" */ + + /* + * init the channel state + */ + seqp->maxChannels = c->maxChannels; + seqp->chanState = alHeapAlloc(hp, c->maxChannels, sizeof(ALChanState) ); + __initChanState((ALSeqPlayer*)seqp); /* sct 11/6/95 */ + + /* + * init the voice state array + */ + voices = alHeapAlloc(hp, c->maxVoices, sizeof(ALVoiceState)); + seqp->vFreeList = 0; + for (i = 0; i < c->maxVoices; i++) { + vs = &voices[i]; + vs->next = seqp->vFreeList; + seqp->vFreeList = vs; + } + + seqp->vAllocHead = 0; + seqp->vAllocTail = 0; +#if BUILD_VERSION < VERSION_J +#line 109 +#endif + // init the event queue + items = alHeapAlloc(hp, c->maxEvents, sizeof(ALEventListItem)); + alEvtqNew(&seqp->evtq, items, c->maxEvents); + + /* + * add ourselves to the driver + */ + seqp->node.next = NULL; + seqp->node.handler = __CSPVoiceHandler; + seqp->node.clientData = seqp; + alSynAddPlayer(&alGlobals->drvr, &seqp->node); +} + +/************************************************************* + * private routines or driver callback routines + *************************************************************/ +static ALMicroTime __CSPVoiceHandler(void *node) +{ + ALCSPlayer *seqp = (ALCSPlayer *) node; + ALEvent evt; + ALVoice *voice; + ALMicroTime delta; + ALVoiceState *vs; + void *oscState; + f32 oscValue; + u8 chan; + + do { + switch (seqp->nextEvent.type) + { + case (AL_SEQ_REF_EVT): + __CSPHandleNextSeqEvent(seqp); + break; + + case (AL_SEQP_API_EVT): + evt.type = AL_SEQP_API_EVT; + alEvtqPostEvent(&seqp->evtq, (ALEvent *)&evt, seqp->frameTime); + break; + + case (AL_NOTE_END_EVT): + voice = seqp->nextEvent.msg.note.voice; + + alSynStopVoice(seqp->drvr, voice); + alSynFreeVoice(seqp->drvr, voice); + vs = (ALVoiceState *)voice->clientPrivate; + if(vs->flags) + __seqpStopOsc((ALSeqPlayer*)seqp,vs); + __unmapVoice((ALSeqPlayer*)seqp, voice); + break; + + case (AL_SEQP_ENV_EVT): + voice = seqp->nextEvent.msg.vol.voice; + vs = (ALVoiceState *)voice->clientPrivate; + + if(vs->envPhase == AL_PHASE_ATTACK) + vs->envPhase = AL_PHASE_DECAY; + + delta = seqp->nextEvent.msg.vol.delta; + vs->envEndTime = seqp->curTime + delta; + vs->envGain = seqp->nextEvent.msg.vol.vol; + alSynSetVol(seqp->drvr, voice, __vsVol(vs, (ALSeqPlayer*)seqp), delta); + break; + + case (AL_TREM_OSC_EVT): + vs = seqp->nextEvent.msg.osc.vs; + oscState = seqp->nextEvent.msg.osc.oscState; + delta = (*seqp->updateOsc)(oscState,&oscValue); + vs->tremelo = (u8)oscValue; + alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs,(ALSeqPlayer*)seqp), + __vsDelta(vs,seqp->curTime)); + evt.type = AL_TREM_OSC_EVT; + evt.msg.osc.vs = vs; + evt.msg.osc.oscState = oscState; + alEvtqPostEvent(&seqp->evtq, &evt, delta); + break; + + case (AL_VIB_OSC_EVT): + vs = seqp->nextEvent.msg.osc.vs; + oscState = seqp->nextEvent.msg.osc.oscState; + chan = seqp->nextEvent.msg.osc.chan; + delta = (*seqp->updateOsc)(oscState,&oscValue); + vs->vibrato = oscValue; + alSynSetPitch(seqp->drvr, &vs->voice, vs->pitch * vs->vibrato + * seqp->chanState[chan].pitchBend); + evt.type = AL_VIB_OSC_EVT; + evt.msg.osc.vs = vs; + evt.msg.osc.oscState = oscState; + evt.msg.osc.chan = chan; + alEvtqPostEvent(&seqp->evtq, &evt, delta); + break; + + case (AL_SEQP_MIDI_EVT): + case (AL_CSP_NOTEOFF_EVT): /* nextEvent is a note off midi message */ + __CSPHandleMIDIMsg(seqp, &seqp->nextEvent); + break; + + case (AL_SEQP_META_EVT): + __CSPHandleMetaMsg(seqp, &seqp->nextEvent); + break; + + case (AL_SEQP_VOL_EVT): + seqp->vol = seqp->nextEvent.msg.spvol.vol; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + alSynSetVol(seqp->drvr, &vs->voice, + __vsVol(vs, (ALSeqPlayer*)seqp), + __vsDelta(vs, seqp->curTime)); + } + break; + + case (AL_SEQP_PLAY_EVT): + if (seqp->state != AL_PLAYING) + { + seqp->state = AL_PLAYING; + __CSPPostNextSeqEvent(seqp); /* seqp must be AL_PLAYING before we call this routine. */ + } + break; + + case (AL_SEQP_STOP_EVT): + if ( seqp->state == AL_STOPPING ) + { + for (vs = seqp->vAllocHead; vs != 0; vs = seqp->vAllocHead) + { +#ifdef _DEBUG + __osError(ERR_ALCSPVNOTFREE, 2, vs->channel, vs->key); +#endif + alSynStopVoice(seqp->drvr, &vs->voice); + alSynFreeVoice(seqp->drvr, &vs->voice); + if(vs->flags) + __seqpStopOsc((ALSeqPlayer*)seqp,vs); + __unmapVoice((ALSeqPlayer*)seqp, &vs->voice); + } + seqp->state = AL_STOPPED; + + /* alEvtqFlush(&seqp->evtq); - Don't flush event queue + anymore. */ + /* sct 1/3/96 - Don't overwrite nextEvent with + AL_SEQP_API_EVT or set nextDelta to + AL_USEC_PER_FRAME since we're not stopping event + processing. */ + /* sct 1/3/96 - Don't return here since we keep + processing events as usual. */ + } + break; + + case (AL_SEQP_STOPPING_EVT): + if (seqp->state == AL_PLAYING) + { + /* sct 12/29/95 - Remove events associated with the + * stopping sequence. For compact sequence player, + * also remove all queued note off events since they + * are not contained in a compact sequence but are + * generated in response to note ons. Note that + * flushing AL_SEQP_MIDI_EVTs may flush events that + * were posted after the call to alSeqpStop, so the + * application must queue these events either when + * the player is fully stopped, or when it is + * playing. */ + alEvtqFlushType(&seqp->evtq, AL_SEQ_REF_EVT); + alEvtqFlushType(&seqp->evtq, AL_CSP_NOTEOFF_EVT); + alEvtqFlushType(&seqp->evtq, AL_SEQP_MIDI_EVT); + + /* sct 1/3/96 - Check to see which voices need to be + killed and release them. */ + /* Unkilled voices should have note end events + occurring prior to KILL_TIME. */ + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (__voiceNeedsNoteKill ((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME)) + __seqpReleaseVoice((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME); + } + + seqp->state = AL_STOPPING; + evt.type = AL_SEQP_STOP_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); + } + break; + + case (AL_SEQP_PRIORITY_EVT): + chan = seqp->nextEvent.msg.sppriority.chan; + seqp->chanState[chan].priority = seqp->nextEvent.msg.sppriority.priority; + break; + + case (AL_SEQP_SEQ_EVT): +#if BUILD_VERSION < VERSION_J +#line 294 +#endif + assert(seqp->state != AL_PLAYING); /* Must be done playing to change sequences. */ + + seqp->target = seqp->nextEvent.msg.spseq.seq; + __setUsptFromTempo (seqp, 500000.0); + if (seqp->bank) + __initFromBank((ALSeqPlayer *)seqp, seqp->bank); + break; + + case (AL_SEQP_BANK_EVT): +#if BUILD_VERSION < VERSION_J +#line 303 +#endif + assert(seqp->state == AL_STOPPED); /* Must be fully stopped to change banks. */ + + seqp->bank = seqp->nextEvent.msg.spbank.bank; + __initFromBank((ALSeqPlayer *)seqp, seqp->bank); + break; + + /* sct 11/6/95 - these events should now be handled by __CSPHandleNextSeqEvent */ + case (AL_SEQ_END_EVT): + case (AL_TEMPO_EVT): + case (AL_SEQ_MIDI_EVT): +#if BUILD_VERSION < VERSION_J +#line 313 +#endif + assert(FALSE); + + break; + } + seqp->nextDelta = alEvtqNextEvent(&seqp->evtq, &seqp->nextEvent); + + } while (seqp->nextDelta == 0); + + /* + * assume that next callback won't be more than half an + * hour away + */ + seqp->curTime += seqp->nextDelta; /* sct 11/7/95 */ + return seqp->nextDelta; +} + +/* + Calculates the delta time in ticks until the next sequence + event and posts a sequence reference event with the time in usecs. + Loops are handled automatically by the compact sequence. + + Does nothing if the sequence player is not playing or if there + is no target sequence. + + sct 11/7/95 +*/ +void __CSPPostNextSeqEvent(ALCSPlayer *seqp) +{ + ALEvent evt; + s32 deltaTicks; + + if (seqp->state != AL_PLAYING || seqp->target == NULL) + return; + + /* Get the next event time in ticks. */ + /* If false is returned, then there is no next delta (ie. end of sequence reached). */ + if (!__alCSeqNextDelta(seqp->target, &deltaTicks)) + return; + + evt.type = AL_SEQ_REF_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt); +} + + +/* + Call this routine to handle the next event in the sequence. + Assumes that the next sequence event is scheduled to be processed + immediately since it does not check the event's tick time. + + sct 11/7/95 +*/ +static void +__CSPHandleNextSeqEvent(ALCSPlayer *seqp) +{ + ALEvent evt; + + /* sct 1/5/96 - Do nothing if we don't have a target sequence. */ + if (seqp->target == NULL) + return; + + alCSeqNextEvent(seqp->target, &evt); + + switch (evt.type) + { + case AL_SEQ_MIDI_EVT: + __CSPHandleMIDIMsg(seqp, &evt); + __CSPPostNextSeqEvent(seqp); + break; + + case AL_TEMPO_EVT: + __CSPHandleMetaMsg(seqp, &evt); + __CSPPostNextSeqEvent(seqp); + break; + + case AL_SEQ_END_EVT: + seqp->state = AL_STOPPING; + evt.type = AL_SEQP_STOP_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); + break; + + case AL_TRACK_END: + case AL_CSP_LOOPSTART: + case AL_CSP_LOOPEND: + __CSPPostNextSeqEvent(seqp); + break; + + default: +#if BUILD_VERSION < VERSION_J +#line 399 +#endif + assert(FALSE); /* Sequence event type not supported. */ +#if BUILD_VERSION >= VERSION_J + break; +#endif + } +} + +static void __CSPHandleMIDIMsg(ALCSPlayer *seqp, ALEvent *event) +{ + ALVoice *voice; + ALVoiceState *vs; + s32 status; + u8 chan; + u8 key; + u8 vel; + u8 byte1; + u8 byte2; + ALMIDIEvent *midi = &event->msg.midi; + s16 vol; + ALEvent evt; + ALMicroTime deltaTime; + ALVoiceState *vstate; + ALPan pan; + ALFxRef fxref; + + + status = midi->status & AL_MIDI_StatusMask; + chan = midi->status & AL_MIDI_ChannelMask; + byte1 = key = midi->byte1; + byte2 = vel = midi->byte2; + + switch (status) + { + case (AL_MIDI_NoteOn): + + if (vel != 0) /* a real note on */ + { + ALVoiceConfig config; + ALSound *sound; + s16 cents; + f32 pitch,oscValue; + u8 fxmix; + void *oscState; + ALInstrument *inst; + + /* If we're not playing, don't process note ons. */ + if (seqp->state != AL_PLAYING) + break; + + sound = __lookupSoundQuick((ALSeqPlayer*)seqp, key, vel, chan); + ALFlagFailIf(!sound, seqp->debugFlags & NO_SOUND_ERR_MASK, + ERR_ALSEQP_NO_SOUND); + + config.priority = seqp->chanState[chan].priority; + config.fxBus = 0; + config.unityPitch = 0; + + vstate = __mapVoice((ALSeqPlayer*)seqp, key, vel, chan); + ALFlagFailIf(!vstate, seqp->debugFlags & NO_VOICE_ERR_MASK, + ERR_ALSEQP_NO_VOICE ); + + voice = &vstate->voice; + + alSynAllocVoice(seqp->drvr, voice, &config); + + /* + * set up the voice state structure + */ + vstate->sound = sound; + vstate->envPhase = AL_PHASE_ATTACK; + if (seqp->chanState[chan].sustain > AL_SUSTAIN) + vstate->phase = AL_PHASE_SUSTAIN; + else + vstate->phase = AL_PHASE_NOTEON; + + cents = (key - sound->keyMap->keyBase) * 100 + + sound->keyMap->detune; + + vstate->pitch = alCents2Ratio(cents); + vstate->envGain = sound->envelope->attackVolume; + vstate->envEndTime = seqp->curTime + + sound->envelope->attackTime; + + /* + * setup tremelo and vibrato if active + */ + vstate->flags = 0; + inst = seqp->chanState[chan].instrument; + + oscValue = (f32)AL_VOL_FULL; /* set this as a default */ + if(inst->tremType) + { + if(seqp->initOsc) + { + deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->tremType, + inst->tremRate,inst->tremDepth,inst->tremDelay); + + if(deltaTime) /* a deltaTime of zero means don't run osc */ + { + evt.type = AL_TREM_OSC_EVT; + evt.msg.osc.vs = vstate; + evt.msg.osc.oscState = oscState; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + vstate->flags |= 0x01; /* set tremelo flag bit */ + } + } + } + vstate->tremelo = (u8)oscValue; /* will default if not changed by initOsc */ + + oscValue = 1.0f; /* set this as a default */ + if(inst->vibType) + { + if(seqp->initOsc) + { + deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->vibType, + inst->vibRate,inst->vibDepth,inst->vibDelay); + + if(deltaTime) /* a deltaTime of zero means don't run osc. */ + { + evt.type = AL_VIB_OSC_EVT; + evt.msg.osc.vs = vstate; + evt.msg.osc.oscState = oscState; + evt.msg.osc.chan = chan; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + vstate->flags |= 0x02; /* set the vibrato flag bit */ + } + } + } + vstate->vibrato = oscValue; /* will default if not changed by initOsc */ + + /* + * calculate the note on parameters + */ + pitch = vstate->pitch * seqp->chanState[chan].pitchBend * + vstate->vibrato; + fxmix = seqp->chanState[chan].fxmix; + pan = __vsPan(vstate, (ALSeqPlayer*)seqp); + vol = __vsVol(vstate, (ALSeqPlayer*)seqp); + deltaTime = sound->envelope->attackTime; + + alSynStartVoiceParams(seqp->drvr, voice, sound->wavetable, + pitch, vol, pan, fxmix, deltaTime); + /* + * set up callbacks for envelope + */ + evt.type = AL_SEQP_ENV_EVT; + evt.msg.vol.voice = voice; + evt.msg.vol.vol = sound->envelope->decayVolume; + evt.msg.vol.delta = sound->envelope->decayTime; + + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + + if(midi->duration) + { + /* + * set up note off evt. if no duration don't do this + */ + evt.type = AL_CSP_NOTEOFF_EVT; + evt.msg.midi.status = chan | AL_MIDI_NoteOff; + evt.msg.midi.byte1 = key; + evt.msg.midi.byte2 = 0; /* not needed ? */ + deltaTime = seqp->uspt * midi->duration; + + /* max time would be about one hour ten minutes */ + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + } + + break; + } + + /* + * NOTE: intentional fall-through for note on with zero + * velocity (Should never happen with compact midi sequence, + * but could happen with real time midi.) + */ + + case (AL_MIDI_NoteOff): + vstate = __lookupVoice((ALSeqPlayer*)seqp, key, chan); + ALFlagFailIf(!vstate, seqp->debugFlags & NOTE_OFF_ERR_MASK, + ERR_ALSEQP_OFF_VOICE ); + + if (vstate->phase == AL_PHASE_SUSTAIN) + vstate->phase = AL_PHASE_SUSTREL; + else + { + vstate->phase = AL_PHASE_RELEASE; + __seqpReleaseVoice((ALSeqPlayer*)seqp, &vstate->voice, + vstate->sound->envelope->releaseTime); + } + + break; + + case (AL_MIDI_PolyKeyPressure): + /* + * Aftertouch per key (hardwired to volume). Note that + * aftertouch affects only notes that are already + * sounding. + */ + vstate = __lookupVoice((ALSeqPlayer*)seqp, key, chan); + ALFailIf(!vstate, ERR_ALSEQP_POLY_VOICE ); + + vstate->velocity = byte2; + alSynSetVol(seqp->drvr, &vstate->voice, + __vsVol(vstate, (ALSeqPlayer*)seqp), + __vsDelta(vstate,seqp->curTime)); + break; + + case (AL_MIDI_ChannelPressure): + /* + * Aftertouch per channel (hardwired to volume). Note that + * aftertouch affects only notes that are already + * sounding. + */ + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if (vs->channel == chan) { + vs->velocity = byte1; + alSynSetVol(seqp->drvr, &vs->voice, + __vsVol(vs, (ALSeqPlayer*)seqp), + __vsDelta(vs,seqp->curTime)); + } + } + break; + + case (AL_MIDI_ControlChange): + switch (byte1) + { + case (AL_MIDI_PAN_CTRL): + seqp->chanState[chan].pan = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (vs->channel == chan) + { + pan = __vsPan(vs, (ALSeqPlayer*)seqp); + alSynSetPan(seqp->drvr, &vs->voice, pan); + } + } + break; + case (AL_MIDI_VOLUME_CTRL): + seqp->chanState[chan].vol = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE)) + { + vol = __vsVol(vs, (ALSeqPlayer*)seqp); + alSynSetVol(seqp->drvr, &vs->voice, vol, + __vsDelta(vs,seqp->curTime)); + } + } + break; + case (AL_MIDI_PRIORITY_CTRL): + /* leave current voices where they are */ + seqp->chanState[chan].priority = byte2; + break; + case (AL_MIDI_SUSTAIN_CTRL): + seqp->chanState[chan].sustain = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if ((vs->channel == chan) && (vs->phase != AL_PHASE_RELEASE)) + { + if ( byte2 > AL_SUSTAIN ) + { + /* + * sustain pedal down + */ + if (vs->phase == AL_PHASE_NOTEON) + vs->phase = AL_PHASE_SUSTAIN; + } + else + { + /* + * sustain pedal up + */ + if (vs->phase == AL_PHASE_SUSTAIN) + vs->phase = AL_PHASE_NOTEON; + + else if(vs->phase == AL_PHASE_SUSTREL) + { + vs->phase = AL_PHASE_RELEASE; + __seqpReleaseVoice((ALSeqPlayer*)seqp, + &vs->voice, + vs->sound->envelope->releaseTime); + } + } + } + } + break; + case (AL_MIDI_FX1_CTRL): + seqp->chanState[chan].fxmix = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (vs->channel == chan) + alSynSetFXMix(seqp->drvr, &vs->voice, byte2); + } + break; +/* case (AL_MIDI_FX_CTRL_0): + case (AL_MIDI_FX_CTRL_1): + case (AL_MIDI_FX_CTRL_2): + case (AL_MIDI_FX_CTRL_3): + case (AL_MIDI_FX_CTRL_4): + case (AL_MIDI_FX_CTRL_5): + case (AL_MIDI_FX_CTRL_6): + case (AL_MIDI_FX_CTRL_7): + fxref = alSynGetFXRef(seqp->drvr, 0, 0); + if (fxref) + alSynSetFXParam(seqp->drvr, fxref, (s16)byte1, (void *)byte2); + break; + case (AL_MIDI_FX3_CTRL): */ + default: + break; + } + break; + case (AL_MIDI_ProgramChange): + /* sct 1/16/96 - We must have a valid bank in order to process the program change. */ +#if BUILD_VERSION < VERSION_J +#line 710 +#endif + assert(seqp->bank != NULL); + + if (key < seqp->bank->instCount) + { + ALInstrument *inst = seqp->bank->instArray[key]; + __setInstChanState((ALSeqPlayer*)seqp, inst, chan); /* sct 11/6/95 */ + } + else + { +#ifdef _DEBUG + __osError(ERR_ALSEQPINVALIDPROG, 2, key, seqp->bank->instCount); +#endif + } + break; + case (AL_MIDI_PitchBendChange): + { + s32 bendVal; + f32 bendRatio; + s32 cents; + + /* get 14-bit unsigned midi value */ + bendVal = ( (byte2 << 7) + byte1) - 8192; + + /* calculate pitch bend in cents */ + cents = (seqp->chanState[chan].bendRange * bendVal)/8192; + + /* calculate the corresponding ratio */ + bendRatio = alCents2Ratio(cents); + seqp->chanState[chan].pitchBend = bendRatio; + + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + if (vs->channel == chan) + alSynSetPitch(seqp->drvr, &vs->voice, + vs->pitch * bendRatio * vs->vibrato); + + } + break; + + default: +#ifdef _DEBUG + __osError(ERR_ALSEQPUNKNOWNMIDI, 1, status); +#endif + break; + } + +} + +static void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event) +{ + ALTempoEvent *tevt = &event->msg.tempo; + ALEvent evt; + s32 tempo; + s32 oldUspt; + u32 ticks; + ALMicroTime tempDelta,curDelta = 0; + ALEventListItem *thisNode,*nextNode,*firstTemp = 0; + + + if (event->msg.tempo.status == AL_MIDI_Meta) + { + if (event->msg.tempo.type == AL_MIDI_META_TEMPO) + { + oldUspt = seqp->uspt; + tempo = (tevt->byte1 << 16) | (tevt->byte2 << 8) | (tevt->byte3 << 0); + __setUsptFromTempo (seqp, (f32)tempo); /* sct 1/8/96 */ + + thisNode = (ALEventListItem*)seqp->evtq.allocList.next; + while(thisNode) + { + curDelta += thisNode->delta; + nextNode = (ALEventListItem*)thisNode->node.next; + if(thisNode->evt.type == AL_CSP_NOTEOFF_EVT) + { + alUnlink((ALLink*)thisNode); + + if(firstTemp) + alLink((ALLink*)thisNode,(ALLink*)firstTemp); + else + { + thisNode->node.next = 0; + thisNode->node.prev = 0; + firstTemp = thisNode; + } + tempDelta = curDelta; /* record the current delta */ + if(nextNode) /* don't do this if no nextNode */ + { + curDelta -= thisNode->delta; /* subtract out this delta */ + nextNode->delta += thisNode->delta; /* add it to next event */ + } + thisNode->delta = tempDelta; /* set this event delta from current */ + } + thisNode = nextNode; + } + + thisNode = firstTemp; + while(thisNode) + { + nextNode = (ALEventListItem*)thisNode->node.next; + ticks = thisNode->delta/oldUspt; + thisNode->delta = ticks * seqp->uspt; + __CSPRepostEvent(&seqp->evtq,thisNode); + thisNode = nextNode; + } + } + } +} + +static void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item) +{ + OSIntMask mask; + ALLink *node; + ALEventListItem *nextItem; + + mask = osSetIntMask(OS_IM_NONE); + + for (node = &evtq->allocList; node != 0; node = node->next) + { + if (!node->next) /* end of the list */ + { + alLink((ALLink *)item, node); + break; + } + else + { + nextItem = (ALEventListItem *)node->next; + if (item->delta < nextItem->delta) + { + nextItem->delta -= item->delta; + alLink((ALLink *)item, node); + break; + } + item->delta -= nextItem->delta; + } + } + osSetIntMask(mask); +} + + +/* + This routine safely calculates the sequence player's + uspt value based on the given tempo. It does this safely + by making sure that the player has a target sequence and + therefore a qnpt value which is needed for the calculation. + + Compact sequence player needs its own version of this routine + since the ALCSeq's qnpt field is at a different offset. +*/ +static void __setUsptFromTempo (ALCSPlayer *seqp, f32 tempo) +{ + if (seqp->target) + seqp->uspt = (s32)((f32)tempo * seqp->target->qnpt); + else + seqp->uspt = 488; /* This is the initial value set by alSeqpNew. */ +} + diff --git a/lib/ultralib/src/audio/cspplay.c b/lib/ultralib/src/audio/cspplay.c new file mode 100644 index 0000000..e34914c --- /dev/null +++ b/lib/ultralib/src/audio/cspplay.c @@ -0,0 +1,34 @@ +/*==================================================================== + * cspplay.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "cseqp.h" + +void alCSPPlay(ALCSPlayer *seqp) +{ + ALEvent evt; + + evt.type = AL_SEQP_PLAY_EVT; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsendmidi.c b/lib/ultralib/src/audio/cspsendmidi.c new file mode 100644 index 0000000..3d03c9b --- /dev/null +++ b/lib/ultralib/src/audio/cspsendmidi.c @@ -0,0 +1,40 @@ +/*==================================================================== + * cspsendmidi.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSendMidi(ALCSPlayer *seqp, s32 ticks, u8 status, u8 byte1, + u8 byte2) +{ + ALEvent evt; + ALMicroTime deltaTime; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = status; + evt.msg.midi.byte1 = byte1; + evt.msg.midi.byte2 = byte2; + evt.msg.midi.duration = 0; + + deltaTime = ticks*seqp->uspt; + + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); +} + diff --git a/lib/ultralib/src/audio/cspsetbank.c b/lib/ultralib/src/audio/cspsetbank.c new file mode 100644 index 0000000..63292b4 --- /dev/null +++ b/lib/ultralib/src/audio/cspsetbank.c @@ -0,0 +1,32 @@ +/*==================================================================== + * cspsetbank.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetBank(ALCSPlayer *seqp, ALBank *b) +{ + ALEvent evt; + + evt.type = AL_SEQP_BANK_EVT; + evt.msg.spbank.bank = b; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsetchlvol.c b/lib/ultralib/src/audio/cspsetchlvol.c new file mode 100644 index 0000000..28e62bb --- /dev/null +++ b/lib/ultralib/src/audio/cspsetchlvol.c @@ -0,0 +1,35 @@ +/*==================================================================== + * cspsetchlvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ControlChange | chan; + evt.msg.midi.byte1 = AL_MIDI_VOLUME_CTRL; + evt.msg.midi.byte2 = vol; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsetfxmix.c b/lib/ultralib/src/audio/cspsetfxmix.c new file mode 100644 index 0000000..f099297 --- /dev/null +++ b/lib/ultralib/src/audio/cspsetfxmix.c @@ -0,0 +1,35 @@ +/*==================================================================== + * cspsetfxmix.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetChlFXMix(ALCSPlayer *seqp, u8 chan, u8 fxmix) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ControlChange | chan; + evt.msg.midi.byte1 = AL_MIDI_FX1_CTRL; + evt.msg.midi.byte2 = fxmix; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsetpan.c b/lib/ultralib/src/audio/cspsetpan.c new file mode 100644 index 0000000..c0dab00 --- /dev/null +++ b/lib/ultralib/src/audio/cspsetpan.c @@ -0,0 +1,35 @@ +/*==================================================================== + * cspsetpan.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ControlChange | chan; + evt.msg.midi.byte1 = AL_MIDI_PAN_CTRL; + evt.msg.midi.byte2 = pan; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsetpriority.c b/lib/ultralib/src/audio/cspsetpriority.c new file mode 100644 index 0000000..b449b82 --- /dev/null +++ b/lib/ultralib/src/audio/cspsetpriority.c @@ -0,0 +1,32 @@ +/*==================================================================== + * cspsetpriority.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetChlPriority(ALCSPlayer *seqp, u8 chan, u8 priority) +{ + ALEvent evt; + + evt.type = AL_SEQP_PRIORITY_EVT; + evt.msg.sppriority.chan = chan; + evt.msg.sppriority.priority = priority; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} diff --git a/lib/ultralib/src/audio/cspsetprogram.c b/lib/ultralib/src/audio/cspsetprogram.c new file mode 100644 index 0000000..2b19e63 --- /dev/null +++ b/lib/ultralib/src/audio/cspsetprogram.c @@ -0,0 +1,35 @@ +/*==================================================================== + * cspsetprogram.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetChlProgram(ALCSPlayer *seqp, u8 chan, u8 prog) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ProgramChange | chan; + evt.msg.midi.byte1 = prog; + evt.msg.midi.byte2 = 0; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsetseq.c b/lib/ultralib/src/audio/cspsetseq.c new file mode 100644 index 0000000..4b6718e --- /dev/null +++ b/lib/ultralib/src/audio/cspsetseq.c @@ -0,0 +1,34 @@ +/*==================================================================== + * cspsetseq.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq) +{ + ALEvent evt; + + evt.type = AL_SEQP_SEQ_EVT; + evt.msg.spseq.seq = seq; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsettempo.c b/lib/ultralib/src/audio/cspsettempo.c new file mode 100644 index 0000000..b085b45 --- /dev/null +++ b/lib/ultralib/src/audio/cspsettempo.c @@ -0,0 +1,36 @@ +/*==================================================================== + * cspsettempo.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo) +{ + ALEvent evt; + + evt.type = AL_SEQP_META_EVT; + evt.msg.tempo.status = AL_MIDI_Meta; + evt.msg.tempo.type = AL_MIDI_META_TEMPO; + evt.msg.tempo.byte1 = (tempo & 0xff0000)>>16; + evt.msg.tempo.byte2 = (tempo & 0xff00)>>8; + evt.msg.tempo.byte3 = tempo & 0xff; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspsetvol.c b/lib/ultralib/src/audio/cspsetvol.c new file mode 100644 index 0000000..6782f33 --- /dev/null +++ b/lib/ultralib/src/audio/cspsetvol.c @@ -0,0 +1,32 @@ +/*==================================================================== + * cspsetvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPSetVol(ALCSPlayer *seqp, s16 vol) +{ + ALEvent evt; + + evt.type = AL_SEQP_VOL_EVT; + evt.msg.spvol.vol = vol; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/cspstop.c b/lib/ultralib/src/audio/cspstop.c new file mode 100644 index 0000000..9929820 --- /dev/null +++ b/lib/ultralib/src/audio/cspstop.c @@ -0,0 +1,32 @@ +/*==================================================================== + * cspstop.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCSPStop(ALCSPlayer *seqp) +{ + ALEvent evt; + + evt.type = AL_SEQP_STOPPING_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/drvrnew.c b/lib/ultralib/src/audio/drvrnew.c new file mode 100644 index 0000000..7ca2e10 --- /dev/null +++ b/lib/ultralib/src/audio/drvrnew.c @@ -0,0 +1,303 @@ +/*==================================================================== + * drvrNew.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +#include +#include "synthInternals.h" +#include +#include +#include "initfx.h" +// TODO: this comes from a header +#ident "$Revision: 1.49 $" +/* + * WARNING: THE FOLLOWING CONSTANT MUST BE KEPT IN SYNC + * WITH SCALING IN MICROCODE!!! + */ +#define SCALE 16384 + +/* + * the following arrays contain default parameters for + * a few hopefully useful effects. + */ +#define ms *(((s32)((f32)44.1))&~0x7) + + +static s32 SMALLROOM_PARAMS[26] = { + /* sections length */ + 3, 100 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 54 ms, 9830, -9830, 0, 0, 0, 0, + 19 ms, 38 ms, 3276, -3276, 0x3fff, 0, 0, 0, + 0, 60 ms, 5000, 0, 0, 0, 0, 0x5000 +}; + +static s32 BIGROOM_PARAMS[34] = { + /* sections length */ + 4, 100 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 66 ms, 9830, -9830, 0, 0, 0, 0, + 22 ms, 54 ms, 3276, -3276, 0x3fff, 0, 0, 0, + 66 ms, 91 ms, 3276, -3276, 0x3fff, 0, 0, 0, + 0, 94 ms, 8000, 0, 0, 0, 0, 0x5000 +}; + +static s32 ECHO_PARAMS[10] = { + /* sections length */ + 1, 200 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 179 ms, 12000, 0, 0x7fff, 0, 0, 0 +}; + +static s32 CHORUS_PARAMS[10] = { + /* sections length */ + 1, 20 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 5 ms, 0x4000, 0, 0x7fff, 7600, 700, 0 +}; + +static s32 FLANGE_PARAMS[10] = { + /* sections length */ + 1, 20 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 5 ms, 0, 0x5fff, 0x7fff, 380, 500, 0 +}; + +static s32 NULL_PARAMS[10] = { + 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + + +void _init_lpfilter(ALLowPass *lp) +{ + s32 i, temp; + s16 fc; + f64 ffc, fcoef; + + temp = lp->fc * SCALE; + fc = temp >> 15; + lp->fgain = SCALE - fc; + + lp->first = 1; + for (i=0; i<8; i++) + lp->fcvec.fccoef[i] = 0; + + lp->fcvec.fccoef[i++] = fc; + fcoef = ffc = (f64)fc/SCALE; + + for (; i<16; i++){ + fcoef *= ffc; + lp->fcvec.fccoef[i] = (s16)(fcoef * SCALE); + } +} + + +void alFxNew(ALFx *r, ALSynConfig *c, ALHeap *hp) +{ + u16 i, j, k; + s32 *param = 0; + ALFilter *f = (ALFilter *) r; + ALDelay *d; + + alFilterNew(f, 0, alFxParam, AL_FX); + f->handler = alFxPull; + r->paramHdl = (ALSetFXParam)alFxParamHdl; + + switch (c->fxType) { + case AL_FX_SMALLROOM: param = SMALLROOM_PARAMS; break; + case AL_FX_BIGROOM: param = BIGROOM_PARAMS; break; + case AL_FX_ECHO: param = ECHO_PARAMS; break; + case AL_FX_CHORUS: param = CHORUS_PARAMS; break; + case AL_FX_FLANGE: param = FLANGE_PARAMS; break; + case AL_FX_CUSTOM: param = c->params; break; + default: param = NULL_PARAMS; break; + } + + + j = 0; + + r->section_count = param[j++]; + r->length = param[j++]; + + r->delay = alHeapAlloc(hp, r->section_count, sizeof(ALDelay)); + r->base = alHeapAlloc(hp, r->length, sizeof(s16)); + r->input = r->base; + + for ( k=0; k < r->length; k++) + r->base[k] = 0; + + for ( i=0; isection_count; i++ ){ + d = &r->delay[i]; + d->input = param[j++]; + d->output = param[j++]; + d->fbcoef = param[j++]; + d->ffcoef = param[j++]; + d->gain = param[j++]; + + if (param[j]) { +#define RANGE 2.0 +/* d->rsinc = ((f32) param[j++])/0xffffff; */ + d->rsinc = ((((f32)param[j++])/1000) * RANGE)/c->outputRate; + + /* + * the following constant is derived from: + * + * ratio = 2^(cents/1200) + * + * and therefore for hundredths of a cent + * x + * ln(ratio) = --------------- + * (120,000)/ln(2) + * where + * 120,000/ln(2) = 173123.40... + */ +#define CONVERT 173123.404906676 +#define LENGTH (d->output - d->input) + d->rsgain = (((f32) param[j++])/CONVERT) * LENGTH; + d->rsval = 1.0; + d->rsdelta = 0.0; + d->rs = alHeapAlloc(hp, 1, sizeof(ALResampler)); + d->rs->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); + d->rs->delta = 0.0; + d->rs->first = 1; + } else { + d->rs = 0; + j++; + j++; + } + + if (param[j]) { + d->lp = alHeapAlloc(hp, 1, sizeof(ALLowPass)); + d->lp->fstate = alHeapAlloc(hp, 1, sizeof(POLEF_STATE)); + d->lp->fc = param[j++]; + _init_lpfilter(d->lp); + } else { + d->lp = 0; + j++; + } + } +} + +void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp) +{ + alFilterNew((ALFilter *) e, alEnvmixerPull, alEnvmixerParam, AL_ENVMIX); + + e->state = alHeapAlloc(hp, 1, sizeof(ENVMIX_STATE)); + + e->first = 1; + e->motion = AL_STOPPED; + e->volume = 1; + e->ltgt = 1; + e->rtgt = 1; + e->cvolL = 1; + e->cvolR = 1; + e->dryamt = 0; + e->wetamt = 0; + e->lratm = 1; + e->lratl = 0; + e->lratm = 1; + e->lratl = 0; + e->delta = 0; + e->segEnd = 0; + e->pan = 0; + e->ctrlList = 0; + e->ctrlTail = 0; + e->sources = 0; +} + +void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp) +{ + s32 + i; + + /* + * init filter superclass + */ + + alFilterNew((ALFilter *) f, alAdpcmPull, alLoadParam, AL_ADPCM); + + f->state = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); + f->lstate = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); + + f->dma = dmaNew(&f->dmaState); + + /* + * init the adpcm state + */ + f->lastsam = 0; + f->first = 1; + f->memin = 0; +} + +void alResampleNew(ALResampler *r, ALHeap *hp) +{ + alFilterNew((ALFilter *) r, alResamplePull, alResampleParam, AL_RESAMPLE); + + /* + * Init resampler state + */ + r->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); + r->delta = 0.0; + r->first = 1; + r->motion = AL_STOPPED; + r->ratio = 1.0; + r->upitch = 0; + r->ctrlList = 0; + r->ctrlTail = 0; + + /* state in the ucode is initialized by the A_INIT flag */ +} + +void alAuxBusNew(ALAuxBus *m, void *sources, s32 maxSources) +{ + alFilterNew((ALFilter *) m, alAuxBusPull, alAuxBusParam, AL_AUXBUS); + m->sourceCount = 0; + m->maxSources = maxSources; + m->sources = (ALFilter **)sources; +} + +void alMainBusNew(ALMainBus *m, void *sources, s32 maxSources) +{ + alFilterNew((ALFilter *) m, alMainBusPull, alMainBusParam, AL_MAINBUS); + m->sourceCount = 0; + m->maxSources = maxSources; + m->sources = (ALFilter **)sources; +} + +void alSaveNew(ALSave *f) +{ + /* + * init filter superclass + */ + + alFilterNew((ALFilter *) f, alSavePull, alSaveParam, AL_SAVE); + + /* + * init the save state, which is a virtual dram address + */ + + f->dramout = 0; + f->first = 1; + +} + diff --git a/lib/ultralib/src/audio/env.c b/lib/ultralib/src/audio/env.c new file mode 100644 index 0000000..fda20f4 --- /dev/null +++ b/lib/ultralib/src/audio/env.c @@ -0,0 +1,591 @@ +/*==================================================================== + * envmixer.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +#include +#include "synthInternals.h" +#include +#include +#include +#include +// TODO: these come from headers +#ident "$Revision: 1.49 $" +#ident "$Revision: 1.17 $" +#ifdef AUD_PROFILE +extern u32 cnt_index, env_num, env_cnt, env_max, env_min, lastCnt[]; +extern u32 rate_num, rate_cnt, rate_max, rate_min; +extern u32 vol_num, vol_cnt, vol_max, vol_min; +#endif +#define EQPOWER_LENGTH 128 +static s16 eqpower[ EQPOWER_LENGTH ] = { + 32767, 32764, 32757, 32744, 32727, 32704, + 32677, 32644, 32607, 32564, 32517, 32464, + 32407, 32344, 32277, 32205, 32127, 32045, + 31958, 31866, 31770, 31668, 31561, 31450, + 31334, 31213, 31087, 30957, 30822, 30682, + 30537, 30388, 30234, 30075, 29912, 29744, + 29572, 29395, 29214, 29028, 28838, 28643, + 28444, 28241, 28033, 27821, 27605, 27385, + 27160, 26931, 26698, 26461, 26220, 25975, + 25726, 25473, 25216, 24956, 24691, 24423, + 24151, 23875, 23596, 23313, 23026, 22736, + 22442, 22145, 21845, 21541, 21234, 20924, + 20610, 20294, 19974, 19651, 19325, 18997, + 18665, 18331, 17993, 17653, 17310, 16965, + 16617, 16266, 15913, 15558, 15200, 14840, + 14477, 14113, 13746, 13377, 13006, 12633, + 12258, 11881, 11503, 11122, 10740, 10357, + 9971, 9584, 9196, 8806, 8415, 8023, + 7630, 7235, 6839, 6442, 6044, 5646, + 5246, 4845, 4444, 4042, 3640, 3237, + 2833, 2429, 2025, 1620, 1216, 810, + 405, 0 +}; + +extern f64 __pow(f64, f64); + +/* + * prototypes for private enveloper functions + */ +static Acmd *_pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, + s32 sampleOffset, Acmd *p) ; +static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel); + +static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel); + +/*********************************************************************** + * Enveloper filter public interfaces + ***********************************************************************/ +Acmd *alEnvmixerPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) +{ + Acmd *ptr = p; + ALEnvMixer *e = (ALEnvMixer *)filter; + s16 inp; + s32 lastOffset; + s32 thisOffset = sampleOffset; + s32 samples; + s16 loutp = 0; + s32 fVol; + ALParam *thisParam; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + /* + * Force the input to be the resampler output + */ + inp = AL_RESAMPLER_OUT; + + while (e->ctrlList != 0) { + lastOffset = thisOffset; + thisOffset = e->ctrlList->delta; + samples = thisOffset - lastOffset; + if (samples > outCount) + break; +#if BUILD_VERSION < VERSION_J +#line 103 +#endif + assert(samples >= 0); + assert(samples <= AL_MAX_RSP_SAMPLES); + + + switch (e->ctrlList->type) { + case (AL_FILTER_START_VOICE_ALT): + { + ALStartParamAlt *param = (ALStartParamAlt *)e->ctrlList; + ALFilter *f = (ALFilter *) e; + s32 tmp; + + if (param->unity) { + (*e->filter.setParam)(&e->filter, + AL_FILTER_SET_UNITY_PITCH, 0); + } + + (*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE, + param->wave); + (*e->filter.setParam)(&e->filter, AL_FILTER_START, 0); + + e->first = 1; + + e->delta = 0; + e->segEnd = param->samples; + + tmp = ((s32)param->volume * (s32)param->volume) >> 15; + e->volume = (s16) tmp; + e->pan = param->pan; + e->dryamt = eqpower[param->fxMix]; + e->wetamt = eqpower[EQPOWER_LENGTH - param->fxMix - 1]; + + if (param->samples) { + e->cvolL = 1; + e->cvolR = 1; + } else { + /* + * Attack time is zero. Simply set the + * volume. We don't want an attack segment. + */ + e->cvolL = (e->volume * eqpower[e->pan]) >> 15; + e->cvolR = (e->volume * + eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; + } + + if (f->source) { + union { + f32 f; + s32 i; + } data; + data.f = param->pitch; + (*f->source->setParam)(f->source, AL_FILTER_SET_PITCH, + (void *)data.i); + } + + } + + break; + + case (AL_FILTER_SET_FXAMT): + case (AL_FILTER_SET_PAN): + case (AL_FILTER_SET_VOLUME): + ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); + + if (e->delta >= e->segEnd){ + /* + * We should have reached our target, calculate + * target in case e->segEnd was 0 + */ + e->ltgt = (e->volume * eqpower[e->pan]) >> 15; + e->rtgt = (e->volume * + eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; + e->delta = e->segEnd; /* To prevent overflow */ + e->cvolL = e->ltgt; + e->cvolR = e->rtgt; + } else { + /* + * Estimate the current volume + */ + e->cvolL = _getVol(e->cvolL, e->delta, e->lratm, e->lratl); + e->cvolR = _getVol(e->cvolR, e->delta, e->rratm, e->rratl); + } + + /* + * We can't have volume of zero, because the envelope + * would never go anywhere from there + */ + if( e->cvolL == 0 ) e->cvolL = 1; + if( e->cvolR == 0 ) e->cvolR = 1; + + if (e->ctrlList->type == AL_FILTER_SET_PAN) + + /* + * This should result in a change to the current + * segment rate and target + */ + e->pan = (s16) e->ctrlList->data.i; + + if (e->ctrlList->type == AL_FILTER_SET_VOLUME){ + + /* + * Switching to a new segment + */ + e->delta = 0; + + /* + * Map volume non-linearly to give something close to + * loudness + */ + fVol = (e->ctrlList->data.i); + fVol = (fVol*fVol)>>15; + e->volume = (s16) fVol; + + e->segEnd = e->ctrlList->moredata.i; + + } + + if (e->ctrlList->type == AL_FILTER_SET_FXAMT){ + e->dryamt = eqpower[e->ctrlList->data.i]; + e->wetamt = eqpower[EQPOWER_LENGTH - e->ctrlList->data.i - 1]; + } + + /* + * Force a volume update + */ + e->first = 1; + break; + + case (AL_FILTER_START_VOICE): + { + ALStartParam *p = (ALStartParam *)e->ctrlList; + + /* + * Changing to PLAYING (since the previous state was + * persumable STOPPED, we'll just bump the output + * pointer rather than pull a subframe of zeros). + */ + if (p->unity) { + (*e->filter.setParam)(&e->filter, + AL_FILTER_SET_UNITY_PITCH, 0); + } + + (*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE, + p->wave); + (*e->filter.setParam)(&e->filter, AL_FILTER_START, 0); + } + break; + + case (AL_FILTER_STOP_VOICE): + { + /* + * Changing to STOPPED and reset the filter + */ + ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); + (*e->filter.setParam)(&e->filter, AL_FILTER_RESET, 0); + } + break; + + case (AL_FILTER_FREE_VOICE): + { + ALSynth *drvr = &alGlobals->drvr; + ALFreeParam *param = (ALFreeParam *)e->ctrlList; + param->pvoice->offset = 0; + _freePVoice(drvr, (PVoice *)param->pvoice); + } + break; + + default: + /* + * Pull the reuired number of samples and then pass the message + * on down the chain + */ + ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); + (*e->filter.setParam)(&e->filter, e->ctrlList->type, + (void *) e->ctrlList->data.i); + break; + } + loutp += (samples<<1); + outCount -= samples; + + /* + * put the param record back on the free list + */ + thisParam = e->ctrlList; + e->ctrlList = e->ctrlList->next; + if (e->ctrlList == 0) + e->ctrlTail = 0; + + __freeParam(thisParam); + + } + + ptr = _pullSubFrame(e, &inp, &loutp, outCount, sampleOffset, ptr); + + /* + * Prevent overflow in e->delta + */ + if (e->delta > e->segEnd) + e->delta = e->segEnd; + +#ifdef AUD_PROFILE + PROFILE_AUD(env_num, env_cnt, env_max, env_min); +#endif + return ptr; +} + +s32 alEnvmixerParam(void *filter, s32 paramID, void *param) +{ + ALFilter *f = (ALFilter *) filter; + ALEnvMixer *e = (ALEnvMixer *) filter; + + switch (paramID) { + + case (AL_FILTER_ADD_UPDATE): + if (e->ctrlTail) { + e->ctrlTail->next = (ALParam *)param; + } else { + e->ctrlList = (ALParam *)param; + } + e->ctrlTail = (ALParam *)param; + + break; + + case (AL_FILTER_RESET): + e->first = 1; + e->motion = AL_STOPPED; + e->volume = 1; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_RESET, param); + break; + + case (AL_FILTER_START): + e->motion = AL_PLAYING; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_START, param); + break; + + case (AL_FILTER_SET_SOURCE): + f->source = (ALFilter *) param; + break; + + default: + if (f->source) + (*f->source->setParam)(f->source, paramID, param); + } + return 0; +} +#if BUILD_VERSION < VERSION_J +#line 350 +#endif +static Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, + s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + ALEnvMixer *e = (ALEnvMixer *)filter; + ALFilter *source= e->filter.source; + + /* filter must be playing and request non-zero output samples to pull. */ + if (e->motion != AL_PLAYING || !outCount) + return ptr; + + /* + * ask all filters upstream from us to build their command + * lists. + */ + + assert(source); + + + ptr = (*source->handler)(source, inp, outCount, sampleOffset, p); + + /* + * construct our portion of the command list + */ + aSetBuffer(ptr++, A_MAIN, *inp, AL_MAIN_L_OUT + *outp, outCount<<1); + aSetBuffer(ptr++, A_AUX, AL_MAIN_R_OUT + *outp, AL_AUX_L_OUT + *outp, + AL_AUX_R_OUT + *outp); + + if (e->first){ + e->first = 0; + + /* + * Calculate derived parameters + */ + e->ltgt = (e->volume * eqpower[e->pan]) >> 15; + e->lratm = _getRate((f64)e->cvolL, (f64)e->ltgt, + e->segEnd, &(e->lratl)); + e->rtgt = (e->volume * + eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; + e->rratm = _getRate((f64)e->cvolR, (f64)e->rtgt, e->segEnd, + &(e->rratl)); + + aSetVolume(ptr++, A_LEFT | A_VOL, e->cvolL, 0, 0); + aSetVolume(ptr++, A_RIGHT | A_VOL, e->cvolR, 0, 0); + aSetVolume(ptr++, A_LEFT | A_RATE, e->ltgt, e->lratm, e->lratl); + aSetVolume(ptr++, A_RIGHT | A_RATE, e->rtgt, e->rratm, e->rratl); + aSetVolume(ptr++, A_AUX, e->dryamt, 0, e->wetamt); + aEnvMixer (ptr++, A_INIT | A_AUX, osVirtualToPhysical(e->state)); + } + else + aEnvMixer(ptr++, A_CONTINUE | A_AUX, osVirtualToPhysical(e->state)); + + /* + * bump the input buffer pointer + */ + + *inp += (outCount<<1); + e->delta += outCount; + + return ptr; +} + +#define EXP_MASK 0x7f800000 +#define MANT_MASK 0x807fffff + +f64 +_frexpf(f64 value, s32 *eptr) +{ + f64 absvalue; + + *eptr = 0; + if (value == 0.0) /* nothing to do for zero */ + return (value); + absvalue = (value > 0.0) ? value : -value; + for ( ; absvalue >= 1.0; absvalue *= 0.5) + ++*eptr; + for ( ; absvalue < 0.5; absvalue += absvalue) + --*eptr; + return (value > 0.0 ? absvalue : -absvalue); +} + +f64 +_ldexpf(f64 in, s32 ex) +{ + s32 exp; + + if ( ex ) { + exp = 1 << ex; + in *= (f64)exp; + } + + return ( in ); +} + +/* + _getRate() -- This function determines how to go from the + current volume level (vol) to the target + volume level (tgt) in some number of steps + (count). Two values are returned that are + used as multipliers to incrementally scale + the volume. Some tricky math is used and + is explained below. + RWW 28jun95 +*/ + +static +s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) +{ + s16 s; + + f64 invn = 1.0/count, eps, a, fs, mant; + s32 i_invn, ex, indx; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + if (count == 0){ + if (tgt >= vol){ + *ratel = 0xffff; + return 0x7fff; + } + else{ + *ratel = 0; + return 0; + } + } + + if (tgt < 1.0) + tgt = 1.0; + if (vol <= 0) vol = 1; /* zero and neg values not allowed */ + +#define NBITS (3) +#define NPOS (1<>= 1; + } + } + + a *= (a *= (a *= a)); + s = (s16) a; + *ratel = (s16)(0xffff * (a - (f32) s)); + +#ifdef AUD_PROFILE + PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min); +#endif + return (s16)a; + +} + +static +f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel) +{ + f32 r, a; + s32 i; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + /* + * Rate values are actually rate^8 + */ + samples >>=3; + if (samples == 0){ + return ivol; + } + r = ((f32) (ratem<<16) + (f32) ratel)/65536; + + a = 1.0; + for (i=0; i<32; i++){ + if( samples & 1 ) + a *= r; + samples >>= 1; + if (samples == 0) + break; + r *= r; + } + ivol *= a; +#ifdef AUD_PROFILE + PROFILE_AUD(vol_num, vol_cnt, vol_max, vol_min); +#endif + return ivol; +} + + + + + + + diff --git a/lib/ultralib/src/audio/event.c b/lib/ultralib/src/audio/event.c new file mode 100644 index 0000000..3112c99 --- /dev/null +++ b/lib/ultralib/src/audio/event.c @@ -0,0 +1,272 @@ +/*==================================================================== + * event.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include + + +void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, s32 itemCount) +{ + s32 i; + + evtq->eventCount = 0; + evtq->allocList.next = 0; + evtq->allocList.prev = 0; + evtq->freeList.next = 0; + evtq->freeList.prev = 0; + + for (i = 0; i < itemCount; i++) { + alLink((ALLink *)&items[i], &evtq->freeList); + } +} + +ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt) +{ + ALEventListItem *item; + ALMicroTime delta; + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + item = (ALEventListItem *)evtq->allocList.next; + + if (item) + { + alUnlink((ALLink *)item); + alCopy(&item->evt, evt, sizeof(*evt)); + alLink((ALLink *)item, &evtq->freeList); + delta = item->delta; + } + else + { + /* sct 11/28/95 - If we get here, most like we overflowed the event queue */ + /* with non-self-perpetuating events. Eg. if we filled the evtq with volume */ + /* events, then when the seqp is told to play it will handle all the events */ + /* at once completely emptying out the queue. At this point this problem */ + /* must be treated as an out of resource error and the evtq should be increased. */ + evt->type = -1; + delta = 0; + } + + osSetIntMask(mask); + + return delta; +} + +void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, ALMicroTime delta) +{ + ALEventListItem *item; + ALEventListItem *nextItem; + ALLink *node; + s32 postAtEnd=0; + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + item = (ALEventListItem *)evtq->freeList.next; + if (!item) { + osSetIntMask(mask); +#ifdef _DEBUG + __osError(ERR_ALEVENTNOFREE, 0); +#endif + return; + } + + alUnlink((ALLink *)item); + alCopy(evt, &item->evt, sizeof(*evt)); + + if (delta == AL_EVTQ_END) + postAtEnd = -1; + + for (node = &evtq->allocList; node != 0; node = node->next) { + if (!node->next) { /* end of the list */ + if (postAtEnd) + item->delta = 0; + else + item->delta = delta; + alLink((ALLink *)item, node); + break; + } else { + nextItem = (ALEventListItem *)node->next; + + if (delta < nextItem->delta) { + item->delta = delta; + nextItem->delta -= delta; + + alLink((ALLink *)item, node); + break; + } + + delta -= nextItem->delta; + + } + } + + osSetIntMask(mask); + +} + +void alEvtqFlush(ALEventQueue *evtq) +{ + ALLink *thisNode; + ALLink *nextNode; + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + thisNode = evtq->allocList.next; + while( thisNode != 0 ) { + nextNode = thisNode->next; + alUnlink(thisNode); + alLink(thisNode, &evtq->freeList); + thisNode = nextNode; + } + + osSetIntMask(mask); +} + + +/* + This routine flushes events according their type. +*/ +void alEvtqFlushType(ALEventQueue *evtq, s16 type) +{ + ALLink *thisNode; + ALLink *nextNode; + ALEventListItem *thisItem, *nextItem; + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + thisNode = evtq->allocList.next; + while( thisNode != 0 ) + { + nextNode = thisNode->next; + thisItem = (ALEventListItem *)thisNode; + nextItem = (ALEventListItem *)nextNode; + if (thisItem->evt.type == type) + { + if (nextItem) + nextItem->delta += thisItem->delta; + alUnlink(thisNode); + alLink(thisNode, &evtq->freeList); + } + thisNode = nextNode; + } + + osSetIntMask(mask); +} + + +#ifdef _DEBUG_INTERNAL +void alEvtqPrintEvtQueue(ALEventQueue *evtq) +{ + s32 count1 = 0; + s32 count2 = 0; + ALLink *node; + ALEventListItem *item; + + /* count free events */ + for (node = evtq->freeList.next; node != 0; node= node->next) { + count1++; + } + + PRINTF("----- Allocated Events -----\n"); + for (node = evtq->allocList.next; node != 0; node= node->next) { + item = (ALEventListItem *)node; + + PRINTF("\tdelta: %d\ttype %d\n", item->delta, item->evt.type); + count2++; + } + PRINTF("\n"); + + PRINTF("free events\t %d\n", count1); + PRINTF("alloc events\t %d\n", count2); + PRINTF("total events\t %d\n", count1 + count2); +} + +char *MidiStatus2Str (char status, char *str); + +void +alEvtqPrintAllocEvts(ALEventQueue *evtq) +{ + ALLink *node; + ALEventListItem *item; + ALMicroTime itemTime = 0; + char str[32]; + + PRINTF("----- Allocated Events -----\n"); + for (node = evtq->allocList.next; node != 0; node= node->next) + { + item = (ALEventListItem *)node; + itemTime += item->delta; + + PRINTF("\tdelta: %d\tabs: %d\t", item->delta, itemTime); + + switch (item->evt.type) + { + case AL_NOTE_END_EVT: + PRINTF("NOTE_END\tvox: %x\n", item->evt.msg.note.voice); + break; + + case AL_SEQP_MIDI_EVT: + PRINTF("SEQP_MIDI\t%s\n", MidiStatus2Str(item->evt.msg.midi.status & AL_MIDI_StatusMask, str)); + break; + + case AL_SEQP_PRIORITY_EVT: + PRINTF("SEQP_PRIORITY\n"); + break; + + default: + PRINTF("type: %d\n", item->evt.type); + break; + } + + } + PRINTF("\n"); + +} + +char * +MidiStatus2Str (char status, char *str) +{ + switch (status) + { + case AL_MIDI_NoteOn: + sprintf(str, "note on"); + break; + + case AL_MIDI_NoteOff: + sprintf(str, "note off"); + break; + + default: + sprintf(str, "status:%d", status); + break; + } + + return str; +} + +#endif /* _DEBUG_INTERNAL */ + + + diff --git a/lib/ultralib/src/audio/filter.c b/lib/ultralib/src/audio/filter.c new file mode 100644 index 0000000..d88460b --- /dev/null +++ b/lib/ultralib/src/audio/filter.c @@ -0,0 +1,32 @@ +/*==================================================================== + * filter.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" + +void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type) +{ + f->source = 0; + f->handler = h; + f->setParam = s; + f->inp = 0; + f->outp = 0; + f->type = type; +} diff --git a/lib/ultralib/src/audio/heapalloc.c b/lib/ultralib/src/audio/heapalloc.c new file mode 100644 index 0000000..8a37808 --- /dev/null +++ b/lib/ultralib/src/audio/heapalloc.c @@ -0,0 +1,65 @@ +/*==================================================================== + * heapalloc.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include +#include + +void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size) +{ + s32 bytes; + u8 *ptr = 0; + + bytes = (num*size + AL_CACHE_ALIGN) & ~AL_CACHE_ALIGN; + +#ifdef _DEBUG + hp->count++; + bytes += sizeof(HeapInfo); +#endif + + if ((hp->cur + bytes) <= (hp->base + hp->len)) { + + ptr = hp->cur; + hp->cur += bytes; + +#ifdef _DEBUG + ((HeapInfo *)ptr)->magic = AL_HEAP_MAGIC; + ((HeapInfo *)ptr)->size = bytes; + ((HeapInfo *)ptr)->count = hp->count; + if (file) { + ((HeapInfo *)ptr)->file = file; + ((HeapInfo *)ptr)->line = line; + } else { + ((HeapInfo *)ptr)->file = (u8 *) "unknown"; + ((HeapInfo *)ptr)->line = 0; + } + + ptr += sizeof(HeapInfo); +#endif + + } else { +#ifdef _DEBUG + __osError(ERR_ALHEAPNOFREE, 1, size); +#endif + } + + return ptr; +} diff --git a/lib/ultralib/src/audio/heapcheck.c b/lib/ultralib/src/audio/heapcheck.c new file mode 100644 index 0000000..baae643 --- /dev/null +++ b/lib/ultralib/src/audio/heapcheck.c @@ -0,0 +1,71 @@ +/*==================================================================== + * heapcheck.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include +#include + +#ifdef AUD_PROFILE +#include +extern u32 cnt_index, heap_num, heap_cnt, heap_max, heap_min, lastCnt[]; +#endif + +s32 alHeapCheck(ALHeap *hp) +{ + s32 rv = 0; + HeapInfo *hi; + HeapInfo *last = 0; + u8 *ptr; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + +#ifdef _DEBUG + for (ptr = hp->base; ptr < hp->cur; ptr += hi->size){ + + hi = (HeapInfo *)ptr; + + if ( hi->magic != AL_HEAP_MAGIC) { + if (last) { + __osError(ERR_ALHEAPCORRUPT, 0); + } else { + __osError(ERR_ALHEAPFIRSTBLOCK, 0); + } + + rv = 1; +#ifdef AUD_PROFILE + PROFILE_AUD(heap_num, heap_cnt, heap_max, heap_min); +#endif + return rv; + } + + last = hi; + + } +#endif +#ifdef AUD_PROFILE + PROFILE_AUD(heap_num, heap_cnt, heap_max, heap_min); +#endif + return rv; +} + + diff --git a/lib/ultralib/src/audio/heapinit.c b/lib/ultralib/src/audio/heapinit.c new file mode 100644 index 0000000..9053375 --- /dev/null +++ b/lib/ultralib/src/audio/heapinit.c @@ -0,0 +1,37 @@ +/*==================================================================== + * heapinit.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include + +void alHeapInit(ALHeap *hp, u8 *base, s32 len) +{ + s32 extraAlign = (AL_CACHE_ALIGN+1) - ((s32) base & AL_CACHE_ALIGN); + + if (extraAlign != AL_CACHE_ALIGN+1) + hp->base = base + extraAlign; + else + hp->base = base; + + hp->len = len; + hp->cur = hp->base; + hp->count = 0; +} + diff --git a/lib/ultralib/src/audio/initfx.h b/lib/ultralib/src/audio/initfx.h new file mode 100644 index 0000000..704e1f4 --- /dev/null +++ b/lib/ultralib/src/audio/initfx.h @@ -0,0 +1,59 @@ +/*==================================================================== + * initfx.h + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#ifndef __initfx__ +#define __initfx__ + +#define MAX_L0 AL_FX_BUFFER_SIZE/4 +#define MAX_L1 AL_FX_BUFFER_SIZE/4 +#define MAX_L2 AL_FX_BUFFER_SIZE/2 + +#define L0_INC MAX_L0/128 +#define L1_INC MAX_L1/128 +#define L2_INC MAX_L2/128 + +#define SMALLROOM_SECT_CNT 3 +#define SMALLROOM_SIZE AL_FX_BUFFER_SIZE +#define SMALLROOM_L0 880 /* 22 ms */ +#define SMALLROOM_C0 9830 +#define SMALLROOM_L1 1400 /* 35 ms */ +#define SMALLROOM_C1 3276 +#define SMALLROOM_L2 2640 /* 66 ms */ +#define SMALLROOM_C2 10000 +#define SMALLROOM_FILT_CNT 1 +#define SMALLROOM_FC0 0x4000 /* .25 */ + +#define BIGROOM_SECT_CNT 3 +#define BIGROOM_SIZE AL_FX_BUFFER_SIZE +#define BIGROOM_L0 1408 /* 32 ms */ +#define BIGROOM_C0 9830 +#define BIGROOM_L1 1984 /* 45 ms */ +#define BIGROOM_C1 9830 +#define BIGROOM_L2 3792 /* 86 ms */ +#define BIGROOM_C2 12000 +#define BIGROOM_FILT_CNT 1 +#define BIGROOM_FC0 0x4000 /* .25 */ + +#define ECHO_SIZE AL_FX_BUFFER_SIZE +#define ECHO_SECT_CNT 1 +#define ECHO_L0 7936 /* 180 ms */ +#define ECHO_C0 0x6000 + +#endif diff --git a/lib/ultralib/src/audio/load.c b/lib/ultralib/src/audio/load.c new file mode 100644 index 0000000..af07075 --- /dev/null +++ b/lib/ultralib/src/audio/load.c @@ -0,0 +1,471 @@ +/*==================================================================== + * load.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" +#include +#include + +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#ifdef AUD_PROFILE +extern u32 cnt_index, adpcm_num, adpcm_cnt, adpcm_max, adpcm_min, lastCnt[]; +#endif + +#define ADPCMFBYTES 9 +#define LFSAMPLES 4 + +static +Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags); + +Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + s16 inp; + s32 tsam; + s32 nframes; + s32 nbytes; + s32 overFlow; + s32 startZero; + s32 nOver; + s32 nSam; + s32 op; + s32 nLeft; + s32 bEnd; + s32 decoded = 0; + s32 looped = 0; + + ALLoadFilter *f = (ALLoadFilter *)filter; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + if (outCount == 0) + return ptr; + + inp = AL_DECODER_IN; + aLoadADPCM(ptr++, f->bookSize, + K0_TO_PHYS(f->table->waveInfo.adpcmWave.book->book)); + + looped = (outCount + f->sample > f->loop.end) && (f->loop.count != 0); + if (looped) + nSam = f->loop.end - f->sample; + else + nSam = outCount; + + if (f->lastsam) + nLeft = ADPCMFSIZE - f->lastsam; + else + nLeft = 0; + tsam = nSam - nLeft; + if (tsam<0) tsam = 0; + + nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; + nbytes = nframes*ADPCMFBYTES; + + if (looped){ + + ptr = _decodeChunk(ptr, f, tsam, nbytes, *outp, inp, f->first); + + /* + * Fix up output pointer, which will be used as the input pointer + * by the following module. + */ + if (f->lastsam) + *outp += (f->lastsam<<1); + else + *outp += (ADPCMFSIZE<<1); + + /* + * Now fix up state info to reflect the loop start point + */ + f->lastsam = f->loop.start &0xf; + f->memin = (s32) f->table->base + ADPCMFBYTES * + ((s32) (f->loop.start>>LFSAMPLES) + 1); + f->sample = f->loop.start; + + bEnd = *outp; + while (outCount > nSam){ + + outCount -= nSam; + + /* + * Put next one after the end of the last lot - on the + * frame boundary (32 byte) after the end. + */ + op = (bEnd + ((nframes+1)<<(LFSAMPLES+1))) & ~0x1f; + + /* + * The actual end of data + */ + bEnd += (nSam<<1); + + /* + * -1 is loop forever - the loop count is not exact now + * for small loops! + */ + if ((f->loop.count != -1) && (f->loop.count != 0)) + f->loop.count--; + + /* + * What's left to compute. + */ + nSam = MIN(outCount, f->loop.end - f->loop.start); + tsam = nSam - ADPCMFSIZE + f->lastsam; + if (tsam<0) tsam = 0; + nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; + nbytes = nframes*ADPCMFBYTES; + ptr = _decodeChunk(ptr, f, tsam, nbytes, op, inp, f->first | A_LOOP); + /* + * Merge the two sections in DMEM. + */ + aDMEMMove(ptr++, op+(f->lastsam<<1), bEnd, nSam<<1); + + } + + f->lastsam = (outCount + f->lastsam) & 0xf; + f->sample += outCount; + f->memin += ADPCMFBYTES*nframes; +#ifdef AUD_PROFILE + PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); +#endif + return ptr; + } + + /* + * The unlooped case, which is executed most of the time + */ + + nSam = nframes<memin + nbytes - ((s32) f->table->base + f->table->len); + if (overFlow < 0) + overFlow = 0; + nOver = (overFlow/ADPCMFBYTES)< nSam + nLeft) + nOver = nSam + nLeft; + + nbytes -= overFlow; + + if ((nOver - (nOver & 0xf))< outCount){ + decoded = 1; + ptr = _decodeChunk(ptr, f, nSam - nOver, nbytes, *outp, inp, f->first); + + if (f->lastsam) + *outp += (f->lastsam<<1); + else + *outp += (ADPCMFSIZE<<1); + + f->lastsam = (outCount + f->lastsam) & 0xf; + f->sample += outCount; + f->memin += ADPCMFBYTES*nframes; + } else { + f->lastsam = 0; + f->memin += ADPCMFBYTES*nframes; + } + + /* + * Put zeros in if necessary + */ + if (nOver){ + f->lastsam = 0; + if (decoded) + startZero = (nLeft + nSam - nOver)<<1; + else + startZero = 0; + aClearBuffer(ptr++, startZero + *outp, nOver<<1); + } +#ifdef AUD_PROFILE + PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); +#endif + + return ptr; +} + +Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + s32 nbytes; + s32 dramLoc; + s32 dramAlign; + s32 dmemAlign; + s32 overFlow; + s32 startZero; + s32 nSam; + s32 op; + + ALLoadFilter *f = (ALLoadFilter *)filter; + ALFilter *a = (ALFilter *) filter; + + if (outCount == 0) + return ptr; + + if ((outCount + f->sample > f->loop.end) && (f->loop.count != 0)){ + + nSam = f->loop.end - f->sample; + nbytes = nSam<<1; + if (nSam > 0){ + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + } else + dramAlign = 0; + + /* + * Fix up output pointer to allow for dram alignment + */ + *outp += dramAlign; + + f->memin = (s32) f->table->base + (f->loop.start<<1); + f->sample = f->loop.start; + op = *outp; + + while (outCount > nSam){ + + op += (nSam<<1); + outCount -= nSam; + /* + * -1 is loop forever + */ + if ((f->loop.count != -1) && (f->loop.count != 0)) + f->loop.count--; + + /* + * What to compute. + */ + nSam = MIN(outCount, f->loop.end - f->loop.start); + nbytes = nSam<<1; + + /* + * Do the next section, same as last. + */ + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + if (op & 0x7) + dmemAlign = 8 - (op & 0x7); + else + dmemAlign = 0; + + aSetBuffer(ptr++, 0, op + dmemAlign, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + + /* + * Merge the two sections in DMEM. + */ + if (dramAlign || dmemAlign) + aDMEMMove(ptr++, op+dramAlign+dmemAlign, op, nSam<<1); + + } + + f->sample += outCount; + f->memin += (outCount<<1); + + return ptr; + } + + /* + * The unlooped case, which is executed most of the time + * + * overFlow is the number of bytes past the end + * of the bitstream I try to generate + */ + + nbytes = outCount<<1; + overFlow = f->memin + nbytes - ((s32) f->table->base + f->table->len); + if (overFlow < 0) + overFlow = 0; + if (overFlow > nbytes) + overFlow = nbytes; + + if (overFlow < nbytes){ + if (outCount > 0){ + nbytes -= overFlow; + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + } else + dramAlign = 0; + *outp += dramAlign; + + f->sample += outCount; + f->memin += outCount<<1; + } else { + f->memin += outCount<<1; + } + + /* + * Put zeros in if necessary + */ + if (overFlow){ + startZero = (outCount<<1) - overFlow; + if (startZero < 0) + startZero = 0; + aClearBuffer(ptr++, startZero + *outp, overFlow); + } + return ptr; +} + + +s32 +alLoadParam(void *filter, s32 paramID, void *param) +{ + ALLoadFilter *a = (ALLoadFilter *) filter; + ALFilter *f = (ALFilter *) filter; + + switch (paramID) { + case (AL_FILTER_SET_WAVETABLE): + a->table = (ALWaveTable *) param; + a->memin = (s32) a->table->base; + a->sample = 0; + switch (a->table->type){ + case (AL_ADPCM_WAVE): + + /* + * Set up the correct handler + */ + f->handler = alAdpcmPull; + + /* + * Make sure the table length is an integer number of + * frames + */ + a->table->len = ADPCMFBYTES * + ((s32) (a->table->len/ADPCMFBYTES)); + + a->bookSize = 2*a->table->waveInfo.adpcmWave.book->order* + a->table->waveInfo.adpcmWave.book->npredictors*ADPCMVSIZE; + if (a->table->waveInfo.adpcmWave.loop) { + a->loop.start = a->table->waveInfo.adpcmWave.loop->start; + a->loop.end = a->table->waveInfo.adpcmWave.loop->end; + a->loop.count = a->table->waveInfo.adpcmWave.loop->count; + alCopy(a->table->waveInfo.adpcmWave.loop->state, + a->lstate, sizeof(ADPCM_STATE)); + } else { + a->loop.start = a->loop.end = a->loop.count = 0; + } + break; + + case (AL_RAW16_WAVE): + f->handler = alRaw16Pull; + if (a->table->waveInfo.rawWave.loop) { + a->loop.start = a->table->waveInfo.rawWave.loop->start; + a->loop.end = a->table->waveInfo.rawWave.loop->end; + a->loop.count = a->table->waveInfo.rawWave.loop->count; + } else { + a->loop.start = a->loop.end = a->loop.count = 0; + } + break; + + default: + break; + + } + break; + + case (AL_FILTER_RESET): + a->lastsam = 0; + a->first = 1; + a->sample = 0; + + /* sct 2/14/96 - Check table since it is initialized to null and */ + /* Get loop info according to table type. */ + if (a->table) + { + a->memin = (s32) a->table->base; + if (a->table->type == AL_ADPCM_WAVE) + { + if (a->table->waveInfo.adpcmWave.loop) + a->loop.count = a->table->waveInfo.adpcmWave.loop->count; + } + else if (a->table->type == AL_RAW16_WAVE) + { + if (a->table->waveInfo.rawWave.loop) + a->loop.count = a->table->waveInfo.rawWave.loop->count; + } + } + + break; + + default: + break; + } +} + +Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags) + +{ + + s32 + dramAlign, + dramLoc; + + if (nbytes > 0){ + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + aSetBuffer(ptr++, 0, inp, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + } else + dramAlign = 0; + + if (flags & A_LOOP){ + aSetLoop(ptr++, K0_TO_PHYS(f->lstate)); + } + + aSetBuffer(ptr++, 0, inp + dramAlign, outp, tsam<<1); + aADPCMdec(ptr++, flags, K0_TO_PHYS(f->state)); + f->first = 0; + + return ptr; +} + + + diff --git a/lib/ultralib/src/audio/mainbus.c b/lib/ultralib/src/audio/mainbus.c new file mode 100644 index 0000000..d5c8eca --- /dev/null +++ b/lib/ultralib/src/audio/mainbus.c @@ -0,0 +1,67 @@ +/*==================================================================== + * mainbus.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" + +Acmd *alMainBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + ALMainBus *m = (ALMainBus *)filter; + ALFilter **sources = m->sources; + s32 i; + + /* + * clear the output buffers here + */ + aClearBuffer(ptr++, AL_MAIN_L_OUT, outCount<<1); + aClearBuffer(ptr++, AL_MAIN_R_OUT, outCount<<1); + + for (i = 0; i < m->sourceCount; i++) { + ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset, + ptr); + aSetBuffer(ptr++, 0, 0, 0, outCount<<1); + aMix(ptr++, 0, 0x7fff, AL_AUX_L_OUT, AL_MAIN_L_OUT); + aMix(ptr++, 0, 0x7fff, AL_AUX_R_OUT, AL_MAIN_R_OUT); + } + + return ptr; +} + +s32 alMainBusParam(void *filter, s32 paramID, void *param) +{ + ALMainBus *m = (ALMainBus *) filter; + ALFilter **sources = m->sources; + + switch (paramID) { + + case (AL_FILTER_ADD_SOURCE): + sources[m->sourceCount++] = (ALFilter *) param; + break; + + default: + /* ??? */ + break; + } + + return 0; + +} + diff --git a/lib/ultralib/src/audio/parse_abi.c b/lib/ultralib/src/audio/parse_abi.c new file mode 100644 index 0000000..f1fd37d --- /dev/null +++ b/lib/ultralib/src/audio/parse_abi.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#ifndef _FINALROM +void alParseAbiCL(Acmd *cmdList, u32 nbytes) +{ + guDLPrintCB cntlBlk; + + cntlBlk.dataSize = nbytes; + cntlBlk.flags = 0; + cntlBlk.dlType = GU_PARSE_ABI_TYPE; + cntlBlk.paddr = osVirtualToPhysical(cmdList); + + osWriteHost(&cntlBlk,sizeof(cntlBlk)); + osWriteHost(cmdList,nbytes); + +} + +#endif + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/ultralib/src/audio/resample.c b/lib/ultralib/src/audio/resample.c new file mode 100644 index 0000000..2baf26f --- /dev/null +++ b/lib/ultralib/src/audio/resample.c @@ -0,0 +1,150 @@ +/*==================================================================== + * resample.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" +#include +#include + +// TODO: this comes from a header +#ident "$Revision: 1.49 $" + +#ifdef AUD_PROFILE +extern u32 cnt_index, resampler_num, resampler_cnt, resampler_max, resampler_min, lastCnt[]; +#endif + +/*********************************************************************** + * Resampler filter public interfaces + ***********************************************************************/ +Acmd *alResamplePull(void *filter, s16 *outp, s32 outCnt, s32 sampleOffset, Acmd *p) +{ + ALResampler *f = (ALResampler *)filter; + Acmd *ptr = p; + s16 inp; + s32 inCount; + ALFilter *source = f->filter.source; + s32 incr; + f32 finCount; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + inp = AL_DECODER_OUT; + + if (!outCnt) + return ptr; + + /* + * check if resampler is required + */ + if (f->upitch) { + + ptr = (*source->handler)(source, &inp, outCnt, sampleOffset, p); + aDMEMMove(ptr++, inp, *outp, outCnt<<1); + + } else { + + /* + * clip to maximum allowable pitch + * FIXME: should we check for some minimum as well? + */ + if (f->ratio > MAX_RATIO) f->ratio = MAX_RATIO; + + /* + * quantize the pitch + */ + f->ratio = (s32)(f->ratio * UNITY_PITCH); + f->ratio = f->ratio / UNITY_PITCH; + + /* + * determine how many samples to generate + */ + finCount = f->delta + (f->ratio * (f32) outCnt); + inCount = (s32) finCount; + f->delta = finCount - (f32)inCount; + + /* + * ask all filters upstream from us to build their command + * lists. + */ + ptr = (*source->handler)(source, &inp, inCount, sampleOffset, p); + + /* + * construct our portion of the command list + */ + incr = (s32)(f->ratio * UNITY_PITCH); + aSetBuffer(ptr++, 0, inp, *outp, outCnt<<1); + aResample(ptr++, f->first, incr, osVirtualToPhysical(f->state)); + f->first = 0; + } + +#ifdef AUD_PROFILE + PROFILE_AUD(resampler_num, resampler_cnt, resampler_max, resampler_min); +#endif + return ptr; +} + +s32 alResampleParam(void *filter, s32 paramID, void *param) +{ + ALFilter *f = (ALFilter *) filter; + ALResampler *r = (ALResampler *) filter; + union { + f32 f; + s32 i; + } data; + + switch (paramID) { + + case (AL_FILTER_SET_SOURCE): + f->source = (ALFilter *) param; + break; + + case (AL_FILTER_RESET): + r->delta = 0.0; + r->first = 1; + r->motion = AL_STOPPED; + r->upitch = 0; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_RESET, 0); + break; + + case (AL_FILTER_START): + r->motion = AL_PLAYING; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_START, 0); + break; + + case (AL_FILTER_SET_PITCH): + data.i = (s32) param; + r->ratio = data.f; + break; + + case (AL_FILTER_SET_UNITY_PITCH): + r->upitch = 1; + break; + + default: + if (f->source) + (*f->source->setParam)(f->source, paramID, param); + break; + } + return 0; +} diff --git a/lib/ultralib/src/audio/reverb.c b/lib/ultralib/src/audio/reverb.c new file mode 100644 index 0000000..f5158c3 --- /dev/null +++ b/lib/ultralib/src/audio/reverb.c @@ -0,0 +1,452 @@ +/*==================================================================== + * reverb.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +#include +#include +#include "synthInternals.h" +#include +#include +#include +#include +#include "initfx.h" +// TODO: these come from headers +#ident "$Revision: 1.49 $" +#ident "$Revision: 1.17 $" +#define RANGE 2.0 +extern ALGlobals *alGlobals; + +#ifdef AUD_PROFILE +extern u32 cnt_index, reverb_num, reverb_cnt, reverb_max, reverb_min, lastCnt[]; +extern u32 load_num, load_cnt, load_max, load_min, save_num, save_cnt, save_max, save_min; +#endif + +/* + * macros + */ +#define SWAP(in, out) \ +{ \ + s16 t = out; \ + out = in; \ + in = t; \ +} + + +Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p); +Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p); +Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p); +Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p); +f32 _doModFunc(ALDelay *d, s32 count); + +static s32 L_INC[] = { L0_INC, L1_INC, L2_INC }; + +/*********************************************************************** + * Reverb filter public interfaces + ***********************************************************************/ +Acmd *alFxPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) +{ + Acmd *ptr = p; + ALFx *r = (ALFx *)filter; + ALFilter *source = r->filter.source; + s16 i, buff1, buff2, input, output; + s16 *in_ptr, *out_ptr, gain, *prev_out_ptr = 0; + ALDelay *d, *pd; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif +#if BUILD_VERSION < VERSION_J +#line 74 +#endif + assert(source); + + /* + * pull channels going into this effect first + */ + ptr = (*source->handler)(source, outp, outCount, sampleOffset, p); + + input = AL_AUX_L_OUT; + output = AL_AUX_R_OUT; + buff1 = AL_TEMP_0; + buff2 = AL_TEMP_1; + + aSetBuffer(ptr++, 0, 0, 0, outCount<<1); /* set the buffer size */ + aMix(ptr++, 0, 0xda83, AL_AUX_L_OUT, input); /* .707L = L - .293L */ + aMix(ptr++, 0, 0x5a82, AL_AUX_R_OUT, input); /* mix the AuxL and AuxR into the AuxL */ + /* and write the mixed value to the delay line at r->input */ + ptr = _saveBuffer(r, r->input, input, outCount, ptr); + + aClearBuffer(ptr++, output, outCount<<1); /* clear the AL_AUX_R_OUT */ + + for (i = 0; i < r->section_count; i++) { + d = &r->delay[i]; /* get the ALDelay structure */ + in_ptr = &r->input[-d->input]; + out_ptr = &r->input[-d->output]; + + if (in_ptr == prev_out_ptr) { + SWAP(buff1, buff2); + } else { /* load data at in_ptr into buff1 */ + ptr = _loadBuffer(r, in_ptr, buff1, outCount, ptr); + } + ptr = _loadOutputBuffer(r, d, buff2, outCount, ptr); + + if (d->ffcoef) { + aMix(ptr++, 0, (u16)d->ffcoef, buff1, buff2); + if (!d->rs && !d->lp) { + ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr); + } + } + + if (d->fbcoef) { + aMix(ptr++, 0, (u16)d->fbcoef, buff2, buff1); + ptr = _saveBuffer(r, in_ptr, buff1, outCount, ptr); + } + + if (d->lp) + ptr = _filterBuffer(d->lp, buff2, outCount, ptr); + + if (!d->rs) + ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr); + + if (d->gain) + aMix(ptr++, 0, (u16)d->gain, buff2, output); + + prev_out_ptr = &r->input[d->output]; + } + + /* + * bump the master delay line input pointer + * modulo the length + */ + r->input += outCount; + if (r->input > &r->base[r->length]) + r->input -= r->length; + + /* + * output already in AL_AUX_R_OUT + * just copy to AL_AUX_L_OUT + */ + aDMEMMove(ptr++, output, AL_AUX_L_OUT, outCount<<1); + +#ifdef AUD_PROFILE + PROFILE_AUD(reverb_num, reverb_cnt, reverb_max, reverb_min); +#endif + return ptr; +} + +s32 alFxParam(void *filter, s32 paramID, void *param) +{ + if(paramID == AL_FILTER_SET_SOURCE) + { + ALFilter *f = (ALFilter *) filter; + f->source = (ALFilter*) param; + } + return 0; +} + +/* + * This routine gets called by alSynSetFXParam. No checking takes place to + * verify the validity of the paramID or the param value. input and output + * values must be 8 byte aligned, so round down any param passed. + */ +s32 alFxParamHdl(void *filter, s32 paramID, void *param) +{ + ALFx *f = (ALFx *) filter; + s32 p = (paramID - 2) % 8; + s32 s = (paramID - 2) / 8; + s32 val = *(s32*)param; + +#define INPUT_PARAM 0 +#define OUTPUT_PARAM 1 +#define FBCOEF_PARAM 2 +#define FFCOEF_PARAM 3 +#define GAIN_PARAM 4 +#define CHORUSRATE_PARAM 5 +#define CHORUSDEPTH_PARAM 6 +#define LPFILT_PARAM 7 + + switch(p) + { + case INPUT_PARAM: + f->delay[s].input = (u32)val & 0xFFFFFFF8; + break; + case OUTPUT_PARAM: + f->delay[s].output = (u32)val & 0xFFFFFFF8; + break; + case FFCOEF_PARAM: + f->delay[s].ffcoef = (s16)val; + break; + case FBCOEF_PARAM: + f->delay[s].fbcoef = (s16)val; + break; + case GAIN_PARAM: + f->delay[s].gain = (s16)val; + break; + case CHORUSRATE_PARAM: + /* f->delay[s].rsinc = ((f32)val)/0xffffff; */ + f->delay[s].rsinc = ((((f32)val)/1000) * RANGE)/alGlobals->drvr.outputRate; + break; + +/* + * the following constant is derived from: + * + * ratio = 2^(cents/1200) + * + * and therefore for hundredths of a cent + * x + * ln(ratio) = --------------- + * (120,000)/ln(2) + * where + * 120,000/ln(2) = 173123.40... + */ +#define CONVERT 173123.404906676 +#define LENGTH (f->delay[s].output - f->delay[s].input) + + case CHORUSDEPTH_PARAM: + /*f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; */ + f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; + break; + case LPFILT_PARAM: + if(f->delay[s].lp) + { + f->delay[s].lp->fc = (s16)val; + _init_lpfilter(f->delay[s].lp); + } + break; + } + return 0; +} + +Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p) +{ + Acmd *ptr = p; + s32 ratio, count, rbuff = AL_TEMP_2; + s16 *out_ptr; + f32 fincount, fratio, delta; + s32 ramalign = 0, length; + static f32 val=0.0, lastval=-10.0; + static f32 blob=0; +/* + * The following section implements the chorus resampling. Modulate where you pull + * the samples from, since you need varying amounts of samples. + */ + if (d->rs) { + length = d->output - d->input; + delta = _doModFunc(d, incount); /* get the number of samples to modulate by */ + /* + * find ratio of delta to delay length and quantize + * to same resolution as resampler + */ + delta /= length; /* convert delta from number of samples to a pitch ratio */ + delta = (s32)(delta * UNITY_PITCH); /* quantize to value microcode will use */ + delta = delta / UNITY_PITCH; + fratio = 1.0 - delta; /* pitch ratio needs to be centered around 1, not zero */ + + /* d->rs->delta is the difference between the fractional and integer value + * of the samples needed. fratio * incount + rs->delta gives the number of samples + * needed for this frame. + */ + fincount = d->rs->delta + (fratio * (f32)incount); + count = (s32) fincount; /* quantize to s32 */ + d->rs->delta = fincount - (f32)count; /* calculate the round off and store */ + + /* + * d->rsdelta is amount the out_ptr has deviated from its starting position. + * You calc the out_ptr by taking d->output - d->rsdelta, and then using the + * negative of that as an index into the delay buffer. loadBuffer that uses this + * value then bumps it up if it is below the delay buffer. + */ + out_ptr = &r->input[-(d->output - d->rsdelta)]; + ramalign = ((s32)out_ptr & 0x7) >> 1; /* calculate the number of samples needed + to align the buffer*/ +#ifdef _DEBUG +#if 0 + if(length > 0) { + if (length - d->rsdelta > (s32)r->length) { + __osError(ERR_ALMODDELAYOVERFLOW, 1, length - d->rsdelta - r->length); + } + } + else if(length < 0) { + if ((-length) - d->rsdelta > (s32)r->length) { + __osError(ERR_ALMODDELAYOVERFLOW, 1, (-length) - d->rsdelta - r->length); + } + } +#endif +#endif + /* load the rbuff with samples, note that there will be ramalign worth of + * samples at the begining which you don't care about. */ + ptr = _loadBuffer(r, out_ptr - ramalign, rbuff, count + ramalign, ptr); + + /* convert fratio to 16 bit fraction for microcode use */ + ratio = (s32)(fratio * UNITY_PITCH); + /* set the buffers, and do the resample */ + aSetBuffer(ptr++, 0, rbuff + (ramalign<<1), buff, incount<<1); + aResample(ptr++, d->rs->first, ratio, osVirtualToPhysical(d->rs->state)); + + d->rs->first = 0; /* turn off first time flag */ + d->rsdelta += count - incount; /* add the number of samples to d->rsdelta */ + } else { + out_ptr = &r->input[-d->output]; + ptr = _loadBuffer(r, out_ptr, buff, incount, ptr); + } + + return ptr; +} +/* + * This routine is for loading data from the delay line buff. If the + * address of curr_ptr < r->base, it will force it to be within r->base + * space, If the load goes past the end of r->base it will wrap around. + * Cause count bytes of data at curr_ptr (within the delay line) to be + * loaded into buff. (Buff is a dmem buffer) + */ +Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p) +{ + Acmd *ptr = p; + s32 after_end, before_end; + s16 *updated_ptr, *delay_end; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + delay_end = &r->base[r->length]; + +#ifdef _DEBUG + if(curr_ptr > delay_end) + __osError(ERR_ALMODDELAYOVERFLOW, 1, delay_end - curr_ptr); +#endif + + if (curr_ptr < r->base) + curr_ptr += r->length; + updated_ptr = curr_ptr + count; + + if (updated_ptr > delay_end) { + after_end = updated_ptr - delay_end; + before_end = delay_end - curr_ptr; + + aSetBuffer(ptr++, 0, buff, 0, before_end<<1); + aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + aSetBuffer(ptr++, 0, buff+(before_end<<1), 0, after_end<<1); + aLoadBuffer(ptr++, osVirtualToPhysical(r->base)); + } else { + aSetBuffer(ptr++, 0, buff, 0, count<<1); + aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + } + + aSetBuffer(ptr++, 0, 0, 0, count<<1); + +#ifdef AUD_PROFILE + PROFILE_AUD(load_num, load_cnt, load_max, load_min); +#endif + return ptr; + +} + +/* + * This routine is for writing data to the delay line buff. If the + * address of curr_ptr < r->base, it will force it to be within r->base + * space. If the write goes past the end of r->base, it will wrap around + * Cause count bytes of data at buff to be written to delay line, curr_ptr. + */ +Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p) +{ + Acmd *ptr = p; + s32 after_end, before_end; + s16 *updated_ptr, *delay_end; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + delay_end = &r->base[r->length]; + if (curr_ptr < r->base) /* probably just security */ + curr_ptr += r->length; /* shouldn't occur */ + updated_ptr = curr_ptr + count; + + if (updated_ptr > delay_end) { /* if the data wraps past end of r->base */ + after_end = updated_ptr - delay_end; + before_end = delay_end - curr_ptr; + + aSetBuffer(ptr++, 0, 0, buff, before_end<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + aSetBuffer(ptr++, 0, 0, buff+(before_end<<1), after_end<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(r->base)); + aSetBuffer(ptr++, 0, 0, 0, count<<1); + } else { + aSetBuffer(ptr++, 0, 0, buff, count<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + } + +#ifdef AUD_PROFILE + PROFILE_AUD(save_num, save_cnt, save_max, save_min); +#endif + return ptr; + +} + +Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p) +{ + Acmd *ptr = p; + + aSetBuffer(ptr++, 0, buff, buff, count<<1); + aLoadADPCM(ptr++, 32, osVirtualToPhysical(lp->fcvec.fccoef)); + aPoleFilter(ptr++, lp->first, lp->fgain, osVirtualToPhysical(lp->fstate)); + lp->first = 0; + + return ptr; +} + + + +/* + * Generate a triangle wave from -1 to 1, and find the current position + * in the wave. (Rate of the wave is controlled by d->rsinc, which is chorus + * rate) Multiply the current triangle wave value by d->rsgain, (chorus depth) + * which is expressed in number of samples back from output pointer the chorus + * should go at it's full chorus. In otherwords, this function returns a number + * of samples the output pointer should modulate backwards. + */ +f32 _doModFunc(ALDelay *d, s32 count) +{ + f32 val; + + /* + * generate bipolar sawtooth + * from -RANGE to +RANGE + */ + d->rsval += d->rsinc * count; + d->rsval = (d->rsval > RANGE) ? d->rsval-(RANGE*2) : d->rsval; + + /* + * convert to monopolar triangle + * from 0 to RANGE + */ + val = d->rsval; + val = (val < 0) ? -val : val; + + /* + * convert to bipolar triangle + * from -1 to 1 + */ + val -= RANGE/2; + + return(d->rsgain * val); +} + + + diff --git a/lib/ultralib/src/audio/save.c b/lib/ultralib/src/audio/save.c new file mode 100644 index 0000000..59bd09b --- /dev/null +++ b/lib/ultralib/src/audio/save.c @@ -0,0 +1,70 @@ +/*==================================================================== + * save.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +#include +#include "synthInternals.h" +#include +#include +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +Acmd *alSavePull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) +{ + Acmd *ptr = p; + ALSave *f = (ALSave *)filter; + ALFilter *source = f->filter.source; +#if BUILD_VERSION < VERSION_J +#line 33 +#endif + assert(f->filter.source); + + + ptr = (*source->handler)(source, outp, outCount, sampleOffset, ptr); + + aSetBuffer (ptr++, 0, 0, 0, outCount<<1); + aInterleave(ptr++, AL_MAIN_L_OUT, AL_MAIN_R_OUT); + aSetBuffer (ptr++, 0, 0, 0, outCount<<2); + aSaveBuffer(ptr++, f->dramout); + return ptr; +} + +s32 alSaveParam(void *filter, s32 paramID, void *param) +{ + ALSave *a = (ALSave *) filter; + ALFilter *f = (ALFilter *) filter; + s32 pp = (s32) param; + + switch (paramID) { + case (AL_FILTER_SET_SOURCE): + f->source = (ALFilter *) param; + break; + + case (AL_FILTER_SET_DRAM): + a->dramout = pp; + break; + + default: + break; + } + return 0; + +} + + + diff --git a/lib/ultralib/src/audio/seq.c b/lib/ultralib/src/audio/seq.c new file mode 100644 index 0000000..5da5b11 --- /dev/null +++ b/lib/ultralib/src/audio/seq.c @@ -0,0 +1,343 @@ +/*==================================================================== + * seq.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include +#include "seq.h" + + +#define IFF_FILE_HDR 0x4d546864 /* 'MThd' */ +#define IFF_TRACK_HDR 0x4d54726b /* 'MTrk' */ + +static s32 readVarLen(ALSeq *s); +static u8 read8(ALSeq *s); +static s16 read16(ALSeq *s); +static s32 read32(ALSeq *s); + + +void alSeqNew(ALSeq *seq, u8 *ptr, s32 len) +{ + /* + * load the seqence pointed to by ptr + */ + seq->base = ptr; + seq->len = len; + seq->lastStatus = 0; + seq->lastTicks = 0; + seq->curPtr = ptr; + + if (read32(seq) != IFF_FILE_HDR) { +#ifdef _DEBUG + __osError(ERR_ALSEQNOTMIDI, 1, ptr); +#endif + return; + } + + read32(seq); /* skip the length field */ + + if (read16(seq) != 0) { +#ifdef _DEBUG + __osError(ERR_ALSEQNOTMIDI0, 1, ptr); +#endif + return; + } + + if (read16(seq) != 1) { +#ifdef _DEBUG + __osError(ERR_ALSEQNUMTRACKS, 1, ptr); +#endif + return; + } + + seq->division = read16(seq); + if (seq->division & 0x8000) { +#ifdef _DEBUG + __osError(ERR_ALSEQTIME, 1, ptr); +#endif + return; + } + + seq->qnpt = 1.0/(f32)seq->division; + + if (read32(seq) != IFF_TRACK_HDR) { +#ifdef _DEBUG + __osError(ERR_ALSEQTRACKHDR, 1, ptr); +#endif + return; + } + + read32(seq); /* skip the length field */ + + seq->trackStart = seq->curPtr; +} + + +void alSeqNextEvent(ALSeq *seq, ALEvent *event) +{ + u8 status; + s16 delta; + s32 len; + s32 deltaTicks; + s32 i; + +#ifdef _DEBUG + /* sct 1/17/96 - Warn if curPtr is beyond the end of sequence. */ + if (seq->curPtr >= seq->base + seq->len) + __osError(ERR_ALSEQOVERRUN, 0); +#endif + + deltaTicks = readVarLen(seq); /* read the delta time */ + seq->lastTicks += deltaTicks; + status = read8(seq); + +#if _DEBUG + /* + * System exclusives are not supported, so just skip them and read + * the next event + */ + if ((status == 0xf0) || (status == 0xf7)) { + __osError(ERR_ALSEQSYSEX, 0); + len = readVarLen(seq); + for (i = 0; i < len; i++) { + read8(seq); + } + alSeqNextEvent(seq,event); + return; + } +#endif + + if (status == AL_MIDI_Meta) { + u8 type = read8(seq); + + if (type == AL_MIDI_META_TEMPO) { + event->type = AL_TEMPO_EVT; + event->msg.tempo.ticks = deltaTicks; + event->msg.tempo.status = status; + event->msg.tempo.type = type; + event->msg.tempo.len = read8(seq); + event->msg.tempo.byte1 = read8(seq); + event->msg.tempo.byte2 = read8(seq); + event->msg.tempo.byte3 = read8(seq); + } else if (type == AL_MIDI_META_EOT) { + event->type = AL_SEQ_END_EVT; + event->msg.end.ticks = deltaTicks; + event->msg.end.status = status; + event->msg.end.type = type; + event->msg.end.len = read8(seq); + } else { +#ifdef _DEBUG + __osError(ERR_ALSEQMETA, 1, type); + len = readVarLen(seq); + for (i = 0; i < len; i++) { + read8(seq); + } + alSeqNextEvent(seq,event); + return; +#endif + } + + seq->lastStatus = 0; + + } else { + event->type = AL_SEQ_MIDI_EVT; + event->msg.midi.ticks = deltaTicks; + if (status & 0x80) { + event->msg.midi.status = status; + event->msg.midi.byte1 = read8(seq); + seq->lastStatus = status; + } else { + /* running status */ + event->msg.midi.status = seq->lastStatus; + event->msg.midi.byte1 = status; + } + + if (((event->msg.midi.status & 0xf0) != AL_MIDI_ProgramChange) && + ((event->msg.midi.status & 0xf0) != AL_MIDI_ChannelPressure)) { + event->msg.midi.byte2 = read8(seq); + } else { + event->msg.midi.byte2 = 0; + } + } +} + + +/* + Returns the delta time in ticks for the next event in the sequence. + Assumes that the sequence data pointer is pointing to the delta time. + + If the curPtr is at or beyond the end of the sequence, then return FALSE + to indicate no next event. + + sct 11/6/95 +*/ +char __alSeqNextDelta (ALSeq *seq, s32 *pDeltaTicks) +{ + u8 * savedPtr; + + /* sct 1/16/96 - Put in safety check here to make sure we don't read past sequence data. */ + if (seq->curPtr >= seq->base + seq->len) + return FALSE; + + savedPtr = seq->curPtr; + *pDeltaTicks = readVarLen(seq); /* read the delta time */ + seq->curPtr = savedPtr; + + return TRUE; +} + + +f32 alSeqTicksToSec(ALSeq *seq, s32 ticks, u32 tempo) +{ + return ((f32) (((f32)(ticks) * (f32)(tempo)) / + ((f32)(seq->division) * 1000000.0))); +} + +u32 alSeqSecToTicks(ALSeq *seq, f32 sec, u32 tempo) +{ + return (u32)(((sec * 1000000.0) * seq->division) / tempo); +} + +void alSeqNewMarker(ALSeq *seq, ALSeqMarker *m, u32 ticks) +{ + ALEvent evt; + u8 *savePtr, *lastPtr; + s32 saveTicks, lastTicks; + s16 saveStatus, lastStatus; + + /* does not check that ticks is within bounds */ + + if (ticks == 0) { /* common case */ + m->curPtr = seq->trackStart; + m->lastStatus = 0; + m->lastTicks = 0; + m->curTicks = 0; + return; + } else { + savePtr = seq->curPtr; + saveStatus = seq->lastStatus; + saveTicks = seq->lastTicks; + + seq->curPtr = seq->trackStart; + seq->lastStatus = 0; + seq->lastTicks = 0; + + do { + lastPtr = seq->curPtr; + lastStatus = seq->lastStatus; + lastTicks = seq->lastTicks; + + alSeqNextEvent(seq, &evt); + + if (evt.type == AL_SEQ_END_EVT) + { + lastPtr = seq->curPtr; + lastStatus = seq->lastStatus; + lastTicks = seq->lastTicks; + break; + } + + } while (seq->lastTicks < ticks); + + m->curPtr = lastPtr; + m->lastStatus = lastStatus; + m->lastTicks = lastTicks; + m->curTicks = seq->lastTicks; /* Used by test loop condition. */ + + seq->curPtr = savePtr; + seq->lastStatus = saveStatus; + seq->lastTicks = saveTicks; + + } +} + +s32 alSeqGetTicks(ALSeq *seq) +{ + return seq->lastTicks; +} + +void alSeqSetLoc(ALSeq *seq, ALSeqMarker *m) +{ + seq->curPtr = m->curPtr; + seq->lastStatus = m->lastStatus; + seq->lastTicks = m->lastTicks; +} + +void alSeqGetLoc(ALSeq *seq, ALSeqMarker *m) +{ + m->curPtr = seq->curPtr; + m->lastStatus = seq->lastStatus; + m->lastTicks = seq->lastTicks; +} + +/* non-aligned byte reading routines */ +static u8 read8(ALSeq *seq) +{ + return *seq->curPtr++; +} + +static s16 read16(ALSeq *seq) +{ + s16 tmp; + + tmp = *seq->curPtr++ << 8; + tmp |= *seq->curPtr++; + + return tmp; +} + +static s32 read32(ALSeq *seq) +{ + s32 tmp; + + tmp = *seq->curPtr++ << 24; + tmp |= *seq->curPtr++ << 16; + tmp |= *seq->curPtr++ << 8; + tmp |= *seq->curPtr++; + + return tmp; +} + +static s32 readVarLen(ALSeq *seq) +{ + s32 value; + s32 c; + + c = *seq->curPtr++; + value = c; + if ( c & 0x80 ) { + value &= 0x7f; + do { + c = *seq->curPtr++; + value = (value << 7) + (c & 0x7f); + } while (c & 0x80); + } + return (value); +} + + + + + + + + + + diff --git a/lib/ultralib/src/audio/seq.h b/lib/ultralib/src/audio/seq.h new file mode 100644 index 0000000..479b339 --- /dev/null +++ b/lib/ultralib/src/audio/seq.h @@ -0,0 +1,9 @@ + + +#ifndef __seq__ +#define __seq__ + +char __alSeqNextDelta (ALSeq *seq, s32 *pDeltaTicks); + + +#endif /* __seq__ */ diff --git a/lib/ultralib/src/audio/seqp.h b/lib/ultralib/src/audio/seqp.h new file mode 100644 index 0000000..c9ab02b --- /dev/null +++ b/lib/ultralib/src/audio/seqp.h @@ -0,0 +1,37 @@ + + +#define KILL_TIME 50000 /* 50 ms */ + +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +ALVoiceState *__mapVoice(ALSeqPlayer *, u8, u8, u8); +void __unmapVoice(ALSeqPlayer *seqp, ALVoice *voice); +char __voiceNeedsNoteKill(ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime killTime); /* sct 1/5/96 */ + +ALVoiceState *__lookupVoice(ALSeqPlayer *, u8, u8); +ALSound *__lookupSound(ALSeqPlayer *, u8, u8, u8); +ALSound *__lookupSoundQuick(ALSeqPlayer *, u8, u8, u8); + +s16 __vsVol(ALVoiceState *voice, ALSeqPlayer *seqp); +ALMicroTime __vsDelta(ALVoiceState *voice, ALMicroTime t); +ALPan __vsPan(ALVoiceState *voice, ALSeqPlayer *seqp); + +void __initFromBank(ALSeqPlayer *seqp, ALBank *b); +void __initChanState(ALSeqPlayer *seqp); +void __resetPerfChanState(ALSeqPlayer *seqp, s32 chan); +void __setInstChanState(ALSeqPlayer *seqp, ALInstrument *inst, s32 chan); + +void __seqpPrintVoices(ALSeqPlayer *); +void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, + ALMicroTime deltaTime); + +void __seqpStopOsc(ALSeqPlayer *seqp, ALVoiceState *vs); + +void __postNextSeqEvent(ALSeqPlayer *seqp); /* sct 11/7/95 */ + diff --git a/lib/ultralib/src/audio/seqpdelete.c b/lib/ultralib/src/audio/seqpdelete.c new file mode 100644 index 0000000..142f190 --- /dev/null +++ b/lib/ultralib/src/audio/seqpdelete.c @@ -0,0 +1,39 @@ +/*==================================================================== + * seqpdelete.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +#include +#include +#include +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void alSeqpDelete(ALSeqPlayer *seqp) +{ + /* sct 1/4/96 - If the sequence player isn't stopped, then you may end + up with stuck notes. Application should check state before calling + this routine to be sure. */ +#if BUILD_VERSION < VERSION_J +#line 31 +#endif + assert(seqp->state == AL_STOPPED); + + + alSynRemovePlayer(seqp->drvr, &seqp->node); +} + diff --git a/lib/ultralib/src/audio/seqpgetchlvol.c b/lib/ultralib/src/audio/seqpgetchlvol.c new file mode 100644 index 0000000..e205651 --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetchlvol.c @@ -0,0 +1,27 @@ +/*==================================================================== + * seqpgetchlvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +u8 alSeqpGetChlVol(ALSeqPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].vol; +} + diff --git a/lib/ultralib/src/audio/seqpgetfxmix.c b/lib/ultralib/src/audio/seqpgetfxmix.c new file mode 100644 index 0000000..5d7ee3f --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetfxmix.c @@ -0,0 +1,27 @@ +/*==================================================================== + * seqpgetfxmix.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].fxmix; +} + diff --git a/lib/ultralib/src/audio/seqpgetpan.c b/lib/ultralib/src/audio/seqpgetpan.c new file mode 100644 index 0000000..23f1067 --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetpan.c @@ -0,0 +1,27 @@ +/*==================================================================== + * seqpgetpan.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +ALPan alSeqpGetChlPan(ALSeqPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].pan; +} + diff --git a/lib/ultralib/src/audio/seqpgetpriority.c b/lib/ultralib/src/audio/seqpgetpriority.c new file mode 100644 index 0000000..e6f77a4 --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetpriority.c @@ -0,0 +1,26 @@ +/*==================================================================== + * seqpgetpriority.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +u8 alSeqpGetChlPriority(ALSeqPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].priority; +} diff --git a/lib/ultralib/src/audio/seqpgetprogram.c b/lib/ultralib/src/audio/seqpgetprogram.c new file mode 100644 index 0000000..d421cde --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetprogram.c @@ -0,0 +1,42 @@ +/*==================================================================== + * seqpgetprogram.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s32 alSeqpGetChlProgram(ALSeqPlayer *seqp, u8 chan) + +{ + s32 i; + ALBank *b = seqp->bank; + ALInstrument *inst; + ALChanState s; + + s = seqp->chanState[chan]; + for (i=0; iinstCount; i++){ + inst = b->instArray[i]; + if (inst == s.instrument) + return i; + } + return(-1); + +} + diff --git a/lib/ultralib/src/audio/seqpgetseq.c b/lib/ultralib/src/audio/seqpgetseq.c new file mode 100644 index 0000000..d35ea19 --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetseq.c @@ -0,0 +1,29 @@ +/*==================================================================== + * seqpgetseq.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +ALSeq *alSeqpGetSeq(ALSeqPlayer *seqp) +{ + return seqp->target; +} + diff --git a/lib/ultralib/src/audio/seqpgetstate.c b/lib/ultralib/src/audio/seqpgetstate.c new file mode 100644 index 0000000..8d36b49 --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetstate.c @@ -0,0 +1,29 @@ +/*==================================================================== + * seqpgetstate.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s32 alSeqpGetState(ALSeqPlayer *seqp) +{ + return seqp->state; +} + diff --git a/lib/ultralib/src/audio/seqpgettempo.c b/lib/ultralib/src/audio/seqpgettempo.c new file mode 100644 index 0000000..41cd4b4 --- /dev/null +++ b/lib/ultralib/src/audio/seqpgettempo.c @@ -0,0 +1,31 @@ +/*==================================================================== + * seqpgettempo.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s32 alSeqpGetTempo(ALSeqPlayer *seqp) +{ + /* sct 1/8/96 - If no target sequence has been set, just return zero (instead of crashing). */ + if (seqp->target == NULL) + return 0; + + return seqp->uspt/seqp->target->qnpt; +} + diff --git a/lib/ultralib/src/audio/seqpgetvol.c b/lib/ultralib/src/audio/seqpgetvol.c new file mode 100644 index 0000000..43a3bb8 --- /dev/null +++ b/lib/ultralib/src/audio/seqpgetvol.c @@ -0,0 +1,27 @@ +/*==================================================================== + * seqpgetvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +s16 alSeqpGetVol(ALSeqPlayer *seqp) +{ + return seqp->vol; +} + diff --git a/lib/ultralib/src/audio/seqplayer.c b/lib/ultralib/src/audio/seqplayer.c new file mode 100644 index 0000000..9d77a6f --- /dev/null +++ b/lib/ultralib/src/audio/seqplayer.c @@ -0,0 +1,1228 @@ +/*==================================================================== + * seqplayer.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +/* + * Notes: + * + * Controller Numbers: + * 1 Modulation + * 7 Volume + * 10 Pan + * 11 Expression + * 64 Sustain + * 121 Reset All Controllers + * 123 All Notes Off + * + * Registered Parameters + * 0 Pitch Bend Sensitivity + * 1 Fine Tuning + * 2 Coarse Tuning + */ + +#include +#include +#include +#include +#include "seqp.h" +#include "seq.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + + +static ALMicroTime __seqpVoiceHandler(void *node); +static void __handleMIDIMsg(ALSeqPlayer *seqp, ALEvent *event); +static void __handleMetaMsg(ALSeqPlayer *seqp, ALEvent *event); +static void __handleNextSeqEvent(ALSeqPlayer *seqp); +static void __setUsptFromTempo(ALSeqPlayer *seqp, f32 tempo); /* sct 1/8/96 */ + +/* + * Sequence Player public functions + */ +void alSeqpNew(ALSeqPlayer *seqp, ALSeqpConfig *c) +{ + s32 i; + ALEventListItem *items; + ALVoiceState *vs; + ALVoiceState *voices; + ALHeap *hp = c->heap; + + /* + * initialize member variables + */ + seqp->bank = 0; + seqp->target = NULL; + seqp->drvr = &alGlobals->drvr; + seqp->chanMask = 0xff; + seqp->uspt = 488; + seqp->nextDelta = 0; + seqp->state = AL_STOPPED; + seqp->vol = 0x7FFF; /* full volume */ + seqp->debugFlags = c->debugFlags; + seqp->frameTime = AL_USEC_PER_FRAME; /* should get this from driver */ + seqp->curTime = 0; + seqp->initOsc = c->initOsc; + seqp->updateOsc = c->updateOsc; + seqp->stopOsc = c->stopOsc; + seqp->loopStart = 0; + seqp->loopEnd = 0; + seqp->loopCount = 0; /* -1 = loop forever, 0 = no loop */ + + seqp->nextEvent.type = AL_SEQP_API_EVT; /* start the voice handler "spinning" */ + + /* + * init the channel state + */ + seqp->maxChannels = c->maxChannels; + seqp->chanState = alHeapAlloc(hp, c->maxChannels, sizeof(ALChanState) ); + __initChanState(seqp); /* sct 11/6/95 */ + + /* + * init the voice state array + */ + voices = alHeapAlloc(hp, c->maxVoices, sizeof(ALVoiceState)); + seqp->vFreeList = 0; + for (i = 0; i < c->maxVoices; i++) { + vs = &voices[i]; + vs->next = seqp->vFreeList; + seqp->vFreeList = vs; + } + + seqp->vAllocHead = 0; + seqp->vAllocTail = 0; + + /* + * init the event queue + */ + items = alHeapAlloc(hp, c->maxEvents, sizeof(ALEventListItem)); + alEvtqNew(&seqp->evtq, items, c->maxEvents); + + /* + * add ourselves to the driver + */ + seqp->node.next = NULL; + seqp->node.handler = __seqpVoiceHandler; + seqp->node.clientData = seqp; + alSynAddPlayer(&alGlobals->drvr, &seqp->node); +} + +/************************************************************* + * private routines or driver callback routines + *************************************************************/ +ALMicroTime __seqpVoiceHandler(void *node) +{ + ALSeqPlayer *seqp = (ALSeqPlayer *) node; + ALEvent evt; + ALVoice *voice; + ALMicroTime delta; + ALVoiceState *vs; + void *oscState; + f32 oscValue; + u8 chan; + + do { + + switch (seqp->nextEvent.type) { + + case (AL_SEQ_REF_EVT): + __handleNextSeqEvent(seqp); + break; + + case (AL_SEQP_API_EVT): + evt.type = AL_SEQP_API_EVT; + alEvtqPostEvent(&seqp->evtq, (ALEvent *)&evt, seqp->frameTime); + break; + + case (AL_NOTE_END_EVT): + voice = seqp->nextEvent.msg.note.voice; + alSynStopVoice(seqp->drvr, voice); + alSynFreeVoice(seqp->drvr, voice); + vs = (ALVoiceState *)voice->clientPrivate; + if(vs->flags) + __seqpStopOsc((ALSeqPlayer*)seqp,vs); + __unmapVoice(seqp, voice); + break; + + case (AL_SEQP_ENV_EVT): + voice = seqp->nextEvent.msg.vol.voice; + vs = (ALVoiceState *)voice->clientPrivate; + + if (vs->envPhase == AL_PHASE_ATTACK) + vs->envPhase = AL_PHASE_DECAY; + + delta = seqp->nextEvent.msg.vol.delta; + vs->envGain = seqp->nextEvent.msg.vol.vol; + vs->envEndTime = seqp->curTime + delta; + alSynSetVol(seqp->drvr, voice, __vsVol(vs, seqp), delta); + break; + + case (AL_TREM_OSC_EVT): + vs = seqp->nextEvent.msg.osc.vs; + oscState = seqp->nextEvent.msg.osc.oscState; + delta = (*seqp->updateOsc)(oscState,&oscValue); + vs->tremelo = (u8)oscValue; + alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs,seqp), + __vsDelta(vs,seqp->curTime)); + evt.type = AL_TREM_OSC_EVT; + evt.msg.osc.vs = vs; + evt.msg.osc.oscState = oscState; + alEvtqPostEvent(&seqp->evtq, &evt, delta); + break; + + case (AL_VIB_OSC_EVT): + vs = seqp->nextEvent.msg.osc.vs; + oscState = seqp->nextEvent.msg.osc.oscState; + chan = seqp->nextEvent.msg.osc.chan; + delta = (*seqp->updateOsc)(oscState,&oscValue); + vs->vibrato = oscValue; + alSynSetPitch(seqp->drvr, &vs->voice, vs->pitch * vs->vibrato + * seqp->chanState[chan].pitchBend); + evt.type = AL_VIB_OSC_EVT; + evt.msg.osc.vs = vs; + evt.msg.osc.oscState = oscState; + evt.msg.osc.chan = chan; + alEvtqPostEvent(&seqp->evtq, &evt, delta); + break; + + case (AL_SEQP_MIDI_EVT): + __handleMIDIMsg(seqp, &seqp->nextEvent); + break; + + case (AL_SEQP_META_EVT): + __handleMetaMsg(seqp, &seqp->nextEvent); + break; + + case (AL_SEQP_PLAY_EVT): + if (seqp->state != AL_PLAYING) + { + seqp->state = AL_PLAYING; + __postNextSeqEvent(seqp); /* seqp must be AL_PLAYING before we call this routine. */ + } + break; + + case (AL_SEQP_STOP_EVT): + if ( seqp->state == AL_STOPPING ) + { + for (vs = seqp->vAllocHead; vs != 0; vs = seqp->vAllocHead) + { + alSynStopVoice(seqp->drvr, &vs->voice); + alSynFreeVoice(seqp->drvr, &vs->voice); + if(vs->flags) + __seqpStopOsc((ALSeqPlayer*)seqp,vs); + __unmapVoice((ALSeqPlayer*)seqp, &vs->voice); + } + + seqp->curTime = 0; + seqp->state = AL_STOPPED; + + /* alEvtqFlush(&seqp->evtq); - Don't flush event + queue anymore. */ + /* sct 1/3/96 - Don't overwrite nextEvent with + AL_SEQP_API_EVT or set nextDelta to + AL_USEC_PER_FRAME since we're not stopping event + processing. */ + /* sct 1/3/96 - Don't return here since we keep + processing events as usual. */ + } + break; + + case (AL_SEQP_STOPPING_EVT): + if (seqp->state == AL_PLAYING) + { + /* + * sct 12/29/95 - Remove events associated with the + * stopping sequence. Note that flushing + * AL_SEQP_MIDI_EVTs may flush events that were + * posted after the call to alSeqpStop, so the + * application must queue these events either when + * the player is fully stopped, or when it is + * playing. + */ + alEvtqFlushType(&seqp->evtq, AL_SEQ_REF_EVT); + alEvtqFlushType(&seqp->evtq, AL_SEQP_MIDI_EVT); + + /* + * sct 1/3/96 - Check to see which voices need to be + * killed and release them. Unkilled voices should + * have note end events occurring prior to + * KILL_TIME. + */ + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (__voiceNeedsNoteKill (seqp, &vs->voice, KILL_TIME)) + __seqpReleaseVoice(seqp, &vs->voice, KILL_TIME); + } + + seqp->state = AL_STOPPING; + evt.type = AL_SEQP_STOP_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); + } + break; + + case (AL_SEQP_VOL_EVT): + seqp->vol = seqp->nextEvent.msg.spvol.vol; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs, seqp), + __vsDelta(vs, seqp->curTime)); + } + break; + + case (AL_SEQP_LOOP_EVT): + seqp->loopStart = seqp->nextEvent.msg.loop.start; + seqp->loopEnd = seqp->nextEvent.msg.loop.end; + seqp->loopCount = seqp->nextEvent.msg.loop.count; + break; + + case (AL_SEQP_PRIORITY_EVT): + chan = seqp->nextEvent.msg.sppriority.chan; + seqp->chanState[chan].priority = seqp->nextEvent.msg.sppriority.priority; + break; + case (AL_SEQP_SEQ_EVT): +#if BUILD_VERSION < VERSION_J // Adjust line numbers to match asserts +#line 295 +#endif + assert(seqp->state != AL_PLAYING); /* Must be done playing to change sequences. */ + + + seqp->target = seqp->nextEvent.msg.spseq.seq; + __setUsptFromTempo (seqp, 500000.0); + if (seqp->bank) + __initFromBank(seqp, seqp->bank); + break; + case (AL_SEQP_BANK_EVT): +#if BUILD_VERSION < VERSION_J +#line 304 +#endif + assert(seqp->state == AL_STOPPED); /* Must be fully stopped to change banks. */ + + seqp->bank = seqp->nextEvent.msg.spbank.bank; + __initFromBank(seqp, seqp->bank); + break; + + /* sct 11/6/95 - these events should now be handled by __handleNextSeqEvent */ + case (AL_SEQ_END_EVT): + case (AL_TEMPO_EVT): + case (AL_SEQ_MIDI_EVT): +#if BUILD_VERSION < VERSION_J +#line 314 +#endif + assert(FALSE); + + + break; + } + + seqp->nextDelta = alEvtqNextEvent (&seqp->evtq, &seqp->nextEvent); + + } while (seqp->nextDelta == 0); + + /* + * assume that next callback won't be more than half an hour away + */ + seqp->curTime += seqp->nextDelta; /* Update the player's current time. */ + return seqp->nextDelta; +} + + +/* + Calculates the delta time in ticks until the next sequence + event taking into account loop points, and posts a + sequence reference event with the time in usecs. + + Does nothing if the sequence player is not playing or there + is no target sequence. + + sct 11/7/95 +*/ +void __postNextSeqEvent(ALSeqPlayer *seqp) +{ + ALEvent evt; + s32 deltaTicks; + ALSeq *seq = seqp->target; + + /* sct 1/5/96 - Do nothing if we're not playing or don't have a target sequence. */ + if ((seqp->state != AL_PLAYING) || (seq == NULL)) + return; + + /* Get the next event time in ticks. */ + /* If false is returned, then there is no next delta (ie. end of sequence reached). */ + if (!__alSeqNextDelta(seq, &deltaTicks)) + return; + + /* Handle loops. */ + if (seqp->loopCount) + { + /* Assume that the loop end falls on a MIDI event. Delta time + will be correct even if we loop */ + if (alSeqGetTicks(seq) + deltaTicks >= seqp->loopEnd->curTicks) + { + alSeqSetLoc(seq, seqp->loopStart); + + if (seqp->loopCount != -1) + seqp->loopCount--; + } + } + + evt.type = AL_SEQ_REF_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt); +} + +/* + Call this routine to handle the next event in the sequence. + Assumes that the next sequence event is scheduled to be processed + immediately since it does not check the event's tick time. + + sct 11/7/95 +*/ +static void +__handleNextSeqEvent(ALSeqPlayer *seqp) +{ + ALEvent evt; + + /* sct 1/5/96 - Do nothing if we don't have a target sequence. */ + if (seqp->target == NULL) + return; + + alSeqNextEvent(seqp->target, &evt); + + switch (evt.type) + { + case AL_SEQ_MIDI_EVT: + __handleMIDIMsg(seqp, &evt); + __postNextSeqEvent(seqp); + break; + + case AL_TEMPO_EVT: + __handleMetaMsg(seqp, &evt); + __postNextSeqEvent(seqp); + break; + + case AL_SEQ_END_EVT: + seqp->state = AL_STOPPING; + evt.type = AL_SEQP_STOP_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); + break; + + default: +#if BUILD_VERSION < VERSION_J +#line 411 +#endif + assert(FALSE); /* Sequence event type not supported. */ +#if BUILD_VERSION >= VERSION_J + break; +#endif + } +} + +void __handleMIDIMsg(ALSeqPlayer *seqp, ALEvent *event) +{ + ALVoice *voice; + ALVoiceState *vs; + s32 status; + u8 chan; + u8 key; + u8 vel; + u8 byte1; + u8 byte2; + ALMIDIEvent *midi = &event->msg.midi; + s16 vol; + ALEvent evt; + ALMicroTime deltaTime; + ALVoiceState *vstate; + ALPan pan; + ALFxRef fxref; +#if BUILD_VERSION < VERSION_J +#line 434 +#endif + /* sct 12/15/95 - Fixed assert to also allow seqp midi event types. */ + assert(event->type == AL_SEQ_MIDI_EVT || event->type == AL_SEQP_MIDI_EVT); + + + status = midi->status & AL_MIDI_StatusMask; + chan = midi->status & AL_MIDI_ChannelMask; + byte1 = key = midi->byte1; + byte2 = vel = midi->byte2; + + switch (status) { + + case (AL_MIDI_NoteOn): + + if (vel != 0) { /* a real note on */ + ALVoiceConfig config; + ALSound *sound; + s16 cents; + f32 pitch,oscValue; + u8 fxmix; + void *oscState; + ALInstrument *inst; + + /* If we're not playing, don't process note ons. */ + if (seqp->state != AL_PLAYING) + break; + + sound = __lookupSoundQuick(seqp, key, vel, chan); + ALFlagFailIf(!sound, seqp->debugFlags & NO_SOUND_ERR_MASK, + ERR_ALSEQP_NO_SOUND); + + config.priority = seqp->chanState[chan].priority; + config.fxBus = 0; + config.unityPitch = 0; + + vstate = __mapVoice(seqp, key, vel, chan); + ALFlagFailIf(!vstate, seqp->debugFlags & NO_VOICE_ERR_MASK, + ERR_ALSEQP_NO_VOICE ); + + voice = &vstate->voice; + + alSynAllocVoice(seqp->drvr, voice, &config); + + /* + * set up the voice state structure + */ + vstate->sound = sound; + vstate->envPhase = AL_PHASE_ATTACK; + if (seqp->chanState[chan].sustain > AL_SUSTAIN) + vstate->phase = AL_PHASE_SUSTAIN; + else + vstate->phase = AL_PHASE_NOTEON; + + cents = (key - sound->keyMap->keyBase) * 100 + + sound->keyMap->detune; + + vstate->pitch = alCents2Ratio(cents); + vstate->envGain = sound->envelope->attackVolume; + vstate->envEndTime = seqp->curTime + + sound->envelope->attackTime; + + /* + * setup tremelo and vibrato if active + */ + vstate->flags = 0; + inst = seqp->chanState[chan].instrument; + + oscValue = (f32)AL_VOL_FULL; /* set this as a default */ + + if(inst->tremType) + { + if(seqp->initOsc) + { + deltaTime = (*seqp->initOsc)(&oscState,&oscValue, + inst->tremType, + inst->tremRate, + inst->tremDepth, + inst->tremDelay); + + if(deltaTime) /* if deltaTime = zero, don't run osc */ + { + evt.type = AL_TREM_OSC_EVT; + evt.msg.osc.vs = vstate; + evt.msg.osc.oscState = oscState; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + vstate->flags |= 0x01; /* set tremelo flag bit */ + } + } + } + /* will default if not changed by initOsc */ + vstate->tremelo = (u8)oscValue; + + oscValue = 1.0f; /* set this as a default */ + if(inst->vibType) + { + if(seqp->initOsc) + { + deltaTime = (*seqp->initOsc)(&oscState,&oscValue, + inst->vibType, + inst->vibRate, + inst->vibDepth, + inst->vibDelay); + + if(deltaTime) /* if deltaTime = zero,don't run osc. */ + { + evt.type = AL_VIB_OSC_EVT; + evt.msg.osc.vs = vstate; + evt.msg.osc.oscState = oscState; + evt.msg.osc.chan = chan; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + vstate->flags |= 0x02; /* set the vibrato flag bit */ + } + } + } + /* will default if not changed by initOsc */ + vstate->vibrato = oscValue; + + /* + * calculate the note on parameters + */ + pitch = vstate->pitch * seqp->chanState[chan].pitchBend * + vstate->vibrato; + fxmix = seqp->chanState[chan].fxmix; + pan = __vsPan(vstate, seqp); + vol = __vsVol(vstate, seqp); + deltaTime = sound->envelope->attackTime; + + alSynStartVoiceParams(seqp->drvr, voice, sound->wavetable, + pitch, vol, pan, fxmix, deltaTime); + /* + * set up callbacks for envelope + */ + evt.type = AL_SEQP_ENV_EVT; + evt.msg.vol.voice = voice; + evt.msg.vol.vol = sound->envelope->decayVolume; + evt.msg.vol.delta = sound->envelope->decayTime; + deltaTime = sound->envelope->attackTime; + + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + + break; + } + + /* + * NOTE: intentional fall-through for note on with zero + * velocity + */ + + case (AL_MIDI_NoteOff): + vstate = __lookupVoice(seqp, key, chan); + ALFlagFailIf(!vstate, (seqp->debugFlags & NOTE_OFF_ERR_MASK), + ERR_ALSEQP_OFF_VOICE ); + + if (vstate->phase == AL_PHASE_SUSTAIN) + vstate->phase = AL_PHASE_SUSTREL; + else { + vstate->phase = AL_PHASE_RELEASE; + __seqpReleaseVoice(seqp, &vstate->voice, + vstate->sound->envelope->releaseTime); + } + + break; + + case (AL_MIDI_PolyKeyPressure): + /* + * Aftertouch per key (hardwired to volume). Note that + * aftertouch affects only notes that are already + * sounding. + */ + vstate = __lookupVoice(seqp, key, chan); + ALFailIf(!vstate, ERR_ALSEQP_POLY_VOICE ); + + vstate->velocity = byte2; + alSynSetVol(seqp->drvr, &vstate->voice, __vsVol(vstate, seqp), + __vsDelta(vstate, seqp->curTime)); + break; + + case (AL_MIDI_ChannelPressure): + /* + * Aftertouch per channel (hardwired to volume). Note that + * aftertouch affects only notes that are already + * sounding. + */ + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if (vs->channel == chan) { + vs->velocity = byte1; + alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs, seqp), + __vsDelta(vs, seqp->curTime)); + } + } + break; + + case (AL_MIDI_ControlChange): + + switch (byte1) { + + case (AL_MIDI_PAN_CTRL): + seqp->chanState[chan].pan = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if (vs->channel == chan) { + pan = __vsPan(vs, seqp); + alSynSetPan(seqp->drvr, &vs->voice, pan); + } + } + break; + + case (AL_MIDI_VOLUME_CTRL): + seqp->chanState[chan].vol = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if ((vs->channel == chan) && + (vs->envPhase != AL_PHASE_RELEASE)) + { + vol = __vsVol(vs, seqp); + alSynSetVol(seqp->drvr, &vs->voice, vol, + __vsDelta(vs, seqp->curTime)); + } + } + break; + case (AL_MIDI_PRIORITY_CTRL): + /* leave current voices where they are */ + seqp->chanState[chan].priority = byte2; + break; + case (AL_MIDI_SUSTAIN_CTRL): + seqp->chanState[chan].sustain = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if ((vs->channel == chan) && + (vs->phase != AL_PHASE_RELEASE)) { + if ( byte2 > AL_SUSTAIN ) { + /* + * sustain pedal down + */ + if (vs->phase == AL_PHASE_NOTEON) + vs->phase = AL_PHASE_SUSTAIN; + } else { + /* + * sustain pedal up + */ + if (vs->phase == AL_PHASE_SUSTAIN) + vs->phase = AL_PHASE_NOTEON; + else if(vs->phase == AL_PHASE_SUSTREL) { + vs->phase = AL_PHASE_RELEASE; + __seqpReleaseVoice(seqp, &vs->voice, + vs->sound->envelope->releaseTime); + } + } + } + } + break; + + case (AL_MIDI_FX1_CTRL): + seqp->chanState[chan].fxmix = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if (vs->channel == chan) { + alSynSetFXMix(seqp->drvr, &vs->voice, byte2); + } + } + break; + + case (AL_MIDI_FX_CTRL_0): + case (AL_MIDI_FX_CTRL_1): + case (AL_MIDI_FX_CTRL_2): + case (AL_MIDI_FX_CTRL_3): + case (AL_MIDI_FX_CTRL_4): + case (AL_MIDI_FX_CTRL_5): + case (AL_MIDI_FX_CTRL_6): + case (AL_MIDI_FX_CTRL_7): +#if 0 /* fx control not implemented */ + fxref = alSynGetFXRef(seqp->drvr, 0, 0); + if (fxref) + alSynSetFXParam(seqp->drvr, fxref, (s16)byte1, (void *)byte2); + break; +#endif + case (AL_MIDI_FX3_CTRL): + default: + break; + } + break; + + case (AL_MIDI_ProgramChange): + /* sct 1/16/96 - We must have a valid bank in order to process the program change. */ +#if BUILD_VERSION < VERSION_J +#line 713 +#endif + assert(seqp->bank != NULL); + + + if (key < seqp->bank->instCount) { + ALInstrument *inst = seqp->bank->instArray[key]; + __setInstChanState(seqp, inst, chan); /* sct 11/6/95 */ + } +#ifdef _DEBUG + else + __osError(ERR_ALSEQPINVALIDPROG, 2, key, seqp->bank->instCount); +#endif + break; + + case (AL_MIDI_PitchBendChange): + { + s32 bendVal; + f32 bendRatio; + s32 cents; + + /* + * get 14-bit unsigned midi value + */ + bendVal = ( (byte2 << 7) + byte1) - 8192; + + /* + * calculate pitch bend in cents + */ + cents = (seqp->chanState[chan].bendRange * bendVal)/8192; + + /* + * calculate the corresponding ratio + */ + bendRatio = alCents2Ratio(cents); + seqp->chanState[chan].pitchBend = bendRatio; + + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if (vs->channel == chan) { + alSynSetPitch(seqp->drvr, &vs->voice, + vs->pitch * bendRatio * vs->vibrato); + } + } + } + break; + + default: +#ifdef _DEBUG + __osError(ERR_ALSEQPUNKNOWNMIDI, 1, status); +#endif + break; + } +} + +void __handleMetaMsg(ALSeqPlayer *seqp, ALEvent *event) +{ + ALTempoEvent *tevt = &event->msg.tempo; + ALEvent evt; + s32 tempo; + + if (event->msg.tempo.status == AL_MIDI_Meta) + { + if (event->msg.tempo.type == AL_MIDI_META_TEMPO) + { + tempo = + (tevt->byte1 << 16) | + (tevt->byte2 << 8) | + (tevt->byte3 << 0); + __setUsptFromTempo (seqp, (f32)tempo); /* sct 1/8/96 */ + } + } +} + +ALVoiceState *__mapVoice(ALSeqPlayer *seqp, u8 key, u8 vel, u8 channel) +{ + ALVoiceState *vs = seqp->vFreeList; + + if (vs) { + + seqp->vFreeList = vs->next; + + vs->next = 0; + + if (!seqp->vAllocHead) + seqp->vAllocHead = vs; + else + seqp->vAllocTail->next = vs; + + seqp->vAllocTail = vs; + + vs->channel = channel; + vs->key = key; + vs->velocity = vel; + vs->voice.clientPrivate = vs; + } + + return vs; +} + +void __unmapVoice(ALSeqPlayer *seqp, ALVoice *voice) +{ + ALVoiceState *prev = 0; + ALVoiceState *vs; + + /* + * we could use doubly linked lists here and save some code and + * execution time, but time spent here in negligible, so it won't + * make much difference. + */ + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if (&vs->voice == voice) { + + if (prev) + prev->next = vs->next; + else + seqp->vAllocHead = vs->next; + + if (vs == seqp->vAllocTail) { + seqp->vAllocTail = prev; + } + + vs->next = seqp->vFreeList; + seqp->vFreeList = vs; + return; + + } + prev = vs; + } +#ifdef _DEBUG + __osError(ERR_ALSEQPUNMAP, 1, voice); +#endif +} + +ALVoiceState *__lookupVoice(ALSeqPlayer *seqp, u8 key, u8 channel) +{ + ALVoiceState *vs; + + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if ((vs->key == key) && (vs->channel == channel) && + (vs->phase != AL_PHASE_RELEASE) && (vs->phase != AL_PHASE_SUSTREL)) + return vs; + } + + return 0; +} +#if 0 +ALSound *__lookupSound(ALSeqPlayer *seqp, u8 key, u8 vel, u8 chan) +{ + s32 i; + ALInstrument *inst = seqp->chanState[chan].instrument; + ALSound *snd = 0; + + for (i = 0; i < inst->soundCount; i++) { + ALSound *sound = inst->soundArray[i]; + ALKeyMap *keymap = sound->keyMap; + + if ((key >= keymap->keyMin) && (key <= keymap->keyMax) && + (vel >= keymap->velocityMin) && (vel <= keymap->velocityMax)) { + snd = sound; + break; + } + } + return snd; +} +#endif + +ALSound *__lookupSoundQuick(ALSeqPlayer *seqp, u8 key, u8 vel, u8 chan) +{ + ALInstrument *inst = seqp->chanState[chan].instrument; + s32 l = 1; + s32 r = inst->soundCount; + s32 i; + ALKeyMap *keymap; +#if BUILD_VERSION < VERSION_J +#line 885 +#endif + assert(inst != NULL); /* sct 10/31/95 - If inst is NULL, then the seqp probably wasn't setup correctly. */ + + + while (r >= l) { + i = (l+r)/2; + + keymap = inst->soundArray[i-1]->keyMap; + + if ((key >= keymap->keyMin) && (key <= keymap->keyMax) && + (vel >= keymap->velocityMin) && (vel <= keymap->velocityMax)) { + return inst->soundArray[i-1]; + } else if ((key < keymap->keyMin) || + ((vel < keymap->velocityMin) && (key <= keymap->keyMax))) { + r = i - 1; + } else { + l = i + 1; + } + } + + return 0; +} + + +/* + * __vsVol calculates the target volume for the voice based on the + * note on velocity, envelope, sampleVolume and controller. + */ +s16 __vsVol(ALVoiceState *vs, ALSeqPlayer *seqp) +{ + + u32 t1,t2; + + t1 = (vs->tremelo*vs->velocity*vs->envGain) >> 6; + t2 = (vs->sound->sampleVolume*seqp->vol* + seqp->chanState[vs->channel].vol) >> 14; + + t1 *= t2; + t1 >>= 15; + + return( (s16)t1 ); + +} + +ALMicroTime __vsDelta(ALVoiceState *vs, ALMicroTime t) +{ + /* + * If we are interrupting a previously set envelope segment, we + * need to recalculate the segment end time given the current + * time. Note: this routine assumes that the voice is currently + * playing. + */ + + s32 delta = vs->envEndTime - t; + + if (delta >= 0) { + return delta; + } else { + return AL_GAIN_CHANGE_TIME; + } +} + + +ALPan __vsPan(ALVoiceState *vs, ALSeqPlayer *seqp) +{ + s32 tmp; + + tmp = seqp->chanState[vs->channel].pan - AL_PAN_CENTER + + vs->sound->samplePan; + tmp = MAX(tmp, AL_PAN_LEFT); + tmp = MIN(tmp, AL_PAN_RIGHT); + + return (ALPan) tmp; +} + +#ifdef IMPLEMENTED + +s32 seqpGetVoices(SEQP *seqp); +s32 seqpSetVoices(SEQP *seqp, s32 numvoices); + +u16 seqpGetChannelMask(SEQP *seqp); +s32 seqpSetChannelMask(SEQP *seqp, u16 bitmask); + +#endif + +void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, + ALMicroTime deltaTime) +{ + ALEvent evt; + ALVoiceState *vs = (ALVoiceState *)voice->clientPrivate; + + /* + * if in attack phase, remove all pending volume + * events for this voice from the queue + */ + + if (vs->envPhase == AL_PHASE_ATTACK) { + ALLink *thisNode; + ALLink *nextNode; + ALEventListItem *thisItem, *nextItem; + + thisNode = seqp->evtq.allocList.next; + while( thisNode != 0 ) { + nextNode = thisNode->next; + thisItem = (ALEventListItem *)thisNode; + nextItem = (ALEventListItem *)nextNode; + if (thisItem->evt.type == AL_SEQP_ENV_EVT) { + if(thisItem->evt.msg.vol.voice == voice) { + if( nextItem ) + nextItem->delta += thisItem->delta; + alUnlink(thisNode); + alLink(thisNode, &seqp->evtq.freeList); + } + } + thisNode = nextNode; + } + } + + vs->velocity = 0; + vs->envPhase = AL_PHASE_RELEASE; + vs->envGain = 0; + vs->envEndTime = seqp->curTime + deltaTime; + + alSynSetPriority(seqp->drvr, voice, 0); /* make candidate for stealing */ + alSynSetVol(seqp->drvr, voice, 0, deltaTime); + evt.type = AL_NOTE_END_EVT; + evt.msg.note.voice = voice; + + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); +} + + + +/* + This special purpose routine is called only when processing + a stopping event in order to properly kill all active voices. + + The routine searches through the seqp's event queue for an + AL_NOTE_END_EVT for the given voice. If the event's execution + time is greater than kill time, it removes the event from the + event queue and returns true that it needs to kill the voice. + Otherwise, if the event's time is less than the kill time, it + returns false that the voice needs to be killed. + + sct 1/3/96 +*/ + +#define VOICENEEDSNOTEKILL_DEBUG _DEBUG_INTERNAL&&0 /* For debugging voiceNeedsNoteKill routine. */ + +char __voiceNeedsNoteKill (ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime killTime) +{ + ALLink *thisNode; + ALLink *nextNode; + ALEventListItem *thisItem; + ALMicroTime itemTime = 0; + char needsNoteKill = TRUE; + +#if VOICENEEDSNOTEKILL_DEBUG + alEvtqPrintAllocEvts (&seqp->evtq); +#endif + + thisNode = seqp->evtq.allocList.next; + while (thisNode != 0) + { + nextNode = thisNode->next; + thisItem = (ALEventListItem *)thisNode; + itemTime += thisItem->delta; + + if (thisItem->evt.type == AL_NOTE_END_EVT) + { + if (thisItem->evt.msg.note.voice == voice) + { + if (itemTime > killTime) + { + if ((ALEventListItem *)nextNode) + ((ALEventListItem *)nextNode)->delta += thisItem->delta; + alUnlink(thisNode); + alLink(thisNode, &seqp->evtq.freeList); + } + else + needsNoteKill = FALSE; + break; + } + } + thisNode = nextNode; + } + +#if VOICENEEDSNOTEKILL_DEBUG + if (thisNode) + osSyncPrintf("vox 0x%0x: end time %d kill time %d\n\n", voice, itemTime, killTime); + else + osSyncPrintf("vox 0x%0x: not found\n\n", voice); + + alEvtqPrintAllocEvts (&seqp->evtq); +#endif + + return needsNoteKill; +} + + + + +void __initFromBank(ALSeqPlayer *seqp, ALBank *b) +{ + /* + * init the chanState with the default instrument + */ + s32 i; + ALInstrument *inst = 0; + + /* set to the first available instrument. */ + for(i = 0; !inst ; i++) + inst = b->instArray[i]; + + /* sct 11/6/95 - Setup the channel state for the given instrument. */ + /* There is some wasted effort here since both calls the same state vars */ + /* but it's safer. */ + for (i = 0; i < seqp->maxChannels; i++) { + __resetPerfChanState(seqp, i); + __setInstChanState(seqp, inst, i); + } + + if (b->percussion) { + __resetPerfChanState(seqp, i); + __setInstChanState(seqp, b->percussion, 9); + } +} + + +/* + sct 11/6/95 - Call this whenever a new instrument gets assigned to a channel + such as when changing banks or in response to a MIDI program change event. + Currently also gets called when changing sequences. +*/ +void __setInstChanState(ALSeqPlayer *seqp, ALInstrument *inst, s32 chan) +{ + seqp->chanState[chan].instrument = inst; + seqp->chanState[chan].pan = inst->pan; + seqp->chanState[chan].vol = inst->volume; + seqp->chanState[chan].priority = inst->priority; + seqp->chanState[chan].bendRange = inst->bendRange; +} + + +/* + sct 11/6/95 -- Call this whenever a new sequence is to be played or when + initializing a sequence player. +*/ +void __resetPerfChanState(ALSeqPlayer *seqp, s32 chan) +{ + seqp->chanState[chan].fxId = AL_FX_NONE; + seqp->chanState[chan].fxmix = AL_DEFAULT_FXMIX; + seqp->chanState[chan].pan = AL_PAN_CENTER; + seqp->chanState[chan].vol = AL_VOL_FULL; + seqp->chanState[chan].priority = AL_DEFAULT_PRIORITY; + seqp->chanState[chan].sustain = 0; + seqp->chanState[chan].bendRange = 200; + seqp->chanState[chan].pitchBend = 1.0f; +} + + +/* + sct 11/6/95 - Called only when creating a new sequence player. +*/ +void __initChanState(ALSeqPlayer *seqp) +{ + int i; + + for (i = 0; i < seqp->maxChannels; i++) + { + seqp->chanState[i].instrument = 0; + __resetPerfChanState (seqp, i); + } +} + + +void __seqpStopOsc(ALSeqPlayer *seqp, ALVoiceState *vs) +{ + ALEventListItem *thisNode,*nextNode; + s16 evtType; + + thisNode = (ALEventListItem*)seqp->evtq.allocList.next; + while(thisNode) + { + nextNode = (ALEventListItem*)thisNode->node.next; + evtType = thisNode->evt.type; + if(evtType == AL_TREM_OSC_EVT || evtType == AL_VIB_OSC_EVT) + { + if(thisNode->evt.msg.osc.vs == vs) + { + (*seqp->stopOsc)(thisNode->evt.msg.osc.oscState); + alUnlink((ALLink*)thisNode); + if(nextNode) + nextNode->delta += thisNode->delta; + alLink((ALLink*)thisNode, &seqp->evtq.freeList); + if(evtType == AL_TREM_OSC_EVT) + vs->flags = vs->flags & 0xFE; + else /* must be a AL_VIB_OSC_EVT */ + vs->flags = vs->flags & 0xFD; + if(!vs->flags) + return; /* there should be no more events */ + } + } + + thisNode = nextNode; + } +} + + + +/* + This routine safely calculates the sequence player's + uspt value based on the given tempo. It does this safely + by making sure that the player has a target sequence and + therefore a qnpt value which is needed for the calculation. +*/ +static void __setUsptFromTempo (ALSeqPlayer *seqp, f32 tempo) +{ + if (seqp->target) + seqp->uspt = (s32)((f32)tempo * seqp->target->qnpt); + else + seqp->uspt = 488; /* This is the initial value set by alSeqpNew. */ +} diff --git a/lib/ultralib/src/audio/seqploop.c b/lib/ultralib/src/audio/seqploop.c new file mode 100644 index 0000000..9bbaf5f --- /dev/null +++ b/lib/ultralib/src/audio/seqploop.c @@ -0,0 +1,35 @@ +/*==================================================================== + * seqploop.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpLoop(ALSeqPlayer *seqp, ALSeqMarker *start, ALSeqMarker *end, + s32 count) +{ + ALEvent evt; + + evt.type = AL_SEQP_LOOP_EVT; + evt.msg.loop.start = start; + evt.msg.loop.end = end; + evt.msg.loop.count = count; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpplay.c b/lib/ultralib/src/audio/seqpplay.c new file mode 100644 index 0000000..8e65504 --- /dev/null +++ b/lib/ultralib/src/audio/seqpplay.c @@ -0,0 +1,48 @@ +/*==================================================================== + * seqpplay.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "seqp.h" + +void alSeqpPlay(ALSeqPlayer *seqp) +{ + ALEvent evt; + + evt.type = AL_SEQP_PLAY_EVT; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + + + + + + + + + + + + + + + diff --git a/lib/ultralib/src/audio/seqpsendmidi.c b/lib/ultralib/src/audio/seqpsendmidi.c new file mode 100644 index 0000000..56a9510 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsendmidi.c @@ -0,0 +1,40 @@ +/*==================================================================== + * seqpsendmidi.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSendMidi(ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, + u8 byte2) +{ + ALEvent evt; + ALMicroTime deltaTime; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = status; + evt.msg.midi.byte1 = byte1; + evt.msg.midi.byte2 = byte2; + evt.msg.midi.duration = 0; + + deltaTime = ticks*seqp->uspt; + + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); +} + diff --git a/lib/ultralib/src/audio/seqpsetbank.c b/lib/ultralib/src/audio/seqpsetbank.c new file mode 100644 index 0000000..1c00e8b --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetbank.c @@ -0,0 +1,32 @@ +/*==================================================================== + * seqpsetbank.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetBank(ALSeqPlayer *seqp, ALBank *b) +{ + ALEvent evt; + + evt.type = AL_SEQP_BANK_EVT; + evt.msg.spbank.bank = b; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpsetchlvol.c b/lib/ultralib/src/audio/seqpsetchlvol.c new file mode 100644 index 0000000..9b48803 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetchlvol.c @@ -0,0 +1,35 @@ +/*==================================================================== + * seqpsetchlvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetChlVol(ALSeqPlayer *seqp, u8 chan, u8 vol) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ControlChange | chan; + evt.msg.midi.byte1 = AL_MIDI_VOLUME_CTRL; + evt.msg.midi.byte2 = vol; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpsetfxmix.c b/lib/ultralib/src/audio/seqpsetfxmix.c new file mode 100644 index 0000000..9397963 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetfxmix.c @@ -0,0 +1,35 @@ +/*==================================================================== + * seqpsetfxmix.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetChlFXMix(ALSeqPlayer *seqp, u8 chan, u8 fxmix) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ControlChange | chan; + evt.msg.midi.byte1 = AL_MIDI_FX1_CTRL; + evt.msg.midi.byte2 = fxmix; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpsetpan.c b/lib/ultralib/src/audio/seqpsetpan.c new file mode 100644 index 0000000..85d07d9 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetpan.c @@ -0,0 +1,35 @@ +/*==================================================================== + * seqpsetpan.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetChlPan(ALSeqPlayer *seqp, u8 chan, ALPan pan) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ControlChange | chan; + evt.msg.midi.byte1 = AL_MIDI_PAN_CTRL; + evt.msg.midi.byte2 = pan; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpsetpriority.c b/lib/ultralib/src/audio/seqpsetpriority.c new file mode 100644 index 0000000..0910726 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetpriority.c @@ -0,0 +1,32 @@ +/*==================================================================== + * seqpsetpriority.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetChlPriority(ALSeqPlayer *seqp, u8 chan, u8 priority) +{ + ALEvent evt; + + evt.type = AL_SEQP_PRIORITY_EVT; + evt.msg.sppriority.chan = chan; + evt.msg.sppriority.priority = priority; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} diff --git a/lib/ultralib/src/audio/seqpsetprogram.c b/lib/ultralib/src/audio/seqpsetprogram.c new file mode 100644 index 0000000..dfd6d94 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetprogram.c @@ -0,0 +1,36 @@ +/*==================================================================== + * seqpsetprogram.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetChlProgram(ALSeqPlayer *seqp, u8 chan, u8 prog) + +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ProgramChange | chan; + evt.msg.midi.byte1 = prog; + evt.msg.midi.byte2 = 0; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpsetseq.c b/lib/ultralib/src/audio/seqpsetseq.c new file mode 100644 index 0000000..3fe8175 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetseq.c @@ -0,0 +1,34 @@ +/*==================================================================== + * seqpsetseq.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetSeq(ALSeqPlayer *seqp, ALSeq *seq) +{ + ALEvent evt; + + evt.type = AL_SEQP_SEQ_EVT; + evt.msg.spseq.seq = seq; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpsettempo.c b/lib/ultralib/src/audio/seqpsettempo.c new file mode 100644 index 0000000..592320a --- /dev/null +++ b/lib/ultralib/src/audio/seqpsettempo.c @@ -0,0 +1,36 @@ +/*==================================================================== + * seqpsettempo.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetTempo(ALSeqPlayer *seqp, s32 tempo) +{ + ALEvent evt; + + evt.type = AL_SEQP_META_EVT; + evt.msg.tempo.status = AL_MIDI_Meta; + evt.msg.tempo.type = AL_MIDI_META_TEMPO; + evt.msg.tempo.byte1 = (tempo & 0xff0000)>>16; + evt.msg.tempo.byte2 = (tempo & 0xff00)>>8; + evt.msg.tempo.byte3 = tempo & 0xff; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpsetvol.c b/lib/ultralib/src/audio/seqpsetvol.c new file mode 100644 index 0000000..b698a40 --- /dev/null +++ b/lib/ultralib/src/audio/seqpsetvol.c @@ -0,0 +1,32 @@ +/*==================================================================== + * seqpsetvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpSetVol(ALSeqPlayer *seqp, s16 vol) +{ + ALEvent evt; + + evt.type = AL_SEQP_VOL_EVT; + evt.msg.spvol.vol = vol; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/ultralib/src/audio/seqpstop.c b/lib/ultralib/src/audio/seqpstop.c new file mode 100644 index 0000000..abec781 --- /dev/null +++ b/lib/ultralib/src/audio/seqpstop.c @@ -0,0 +1,33 @@ +/*==================================================================== + * seqpstop.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSeqpStop(ALSeqPlayer *seqp) +{ + ALEvent evt; + + evt.type = AL_SEQP_STOPPING_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, 0); + +} + diff --git a/lib/ultralib/src/audio/sl.c b/lib/ultralib/src/audio/sl.c new file mode 100644 index 0000000..d184972 --- /dev/null +++ b/lib/ultralib/src/audio/sl.c @@ -0,0 +1,65 @@ +/*==================================================================== + * sl.c + * + * Synopsis: + * Sound library global routines + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +ALGlobals *alGlobals=0; + +void alInit(ALGlobals *g, ALSynConfig *c) +{ + if (!alGlobals) { /* already initialized? */ + alGlobals = g; + alSynNew(&alGlobals->drvr, c); + } +} + +void alClose(ALGlobals *glob) +{ + if (alGlobals) { + alSynDelete(&glob->drvr); + alGlobals = 0; + } +} + +/* might want to make these macros */ +void alLink(ALLink *ln, ALLink *to) +{ + ln->next = to->next; + ln->prev = to; + if (to->next) + to->next->prev = ln; + to->next = ln; +} + +void alUnlink(ALLink *ln) +{ + if (ln->next) + ln->next->prev = ln->prev; + if (ln->prev) + ln->prev->next = ln->next; +} + + + + + diff --git a/lib/ultralib/src/audio/sndp.h b/lib/ultralib/src/audio/sndp.h new file mode 100644 index 0000000..17d7015 --- /dev/null +++ b/lib/ultralib/src/audio/sndp.h @@ -0,0 +1,102 @@ +/*==================================================================== + * sndp.h + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + + +#ifndef __SNDP__ +#define __SNDP__ + +#include + +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +#define MIN_RATIO 0.0001 + +typedef enum { + AL_SNDP_PLAY_EVT, + AL_SNDP_STOP_EVT, + AL_SNDP_PAN_EVT, + AL_SNDP_VOL_EVT, + AL_SNDP_PITCH_EVT, + AL_SNDP_API_EVT, + AL_SNDP_DECAY_EVT, + AL_SNDP_END_EVT, + AL_SNDP_FX_EVT +} ALSndpMsgType; + +typedef struct { + ALVoice voice; + ALSound *sound; /* sound referenced here */ + s16 priority; + f32 pitch; /* current playback pitch */ + s32 state; /* play state for this sound */ + s16 vol; /* volume - combined with volume from bank */ + ALPan pan; /* pan - 0 = left, 127 = right */ + u8 fxMix; /* wet/dry mix - 0 = dry, 127 = wet */ +} ALSoundState; + +typedef union { + + ALEvent msg; + + struct { + s16 type; + ALSoundState *state; + } common; + + struct { + s16 type; + ALSoundState *state; + s16 vol; + } vol; + + struct { + s16 type; + ALSoundState *state; + f32 pitch; + } pitch; + + struct { + s16 type; + ALSoundState *state; + ALPan pan; + } pan; + + struct { + s16 type; + ALSoundState *state; + u8 mix; + } fx; + +} ALSndpEvent; + +static ALMicroTime _sndpVoiceHandler(void *node); +static void _handleEvent(ALSndPlayer *sndp, ALSndpEvent *event); +static void _removeEvents(ALEventQueue *evtq, ALSoundState *state); +static s32 _DivS32ByF32 (s32 i, f32 f); + +#endif diff --git a/lib/ultralib/src/audio/sndpallocate.c b/lib/ultralib/src/audio/sndpallocate.c new file mode 100644 index 0000000..0629ac7 --- /dev/null +++ b/lib/ultralib/src/audio/sndpallocate.c @@ -0,0 +1,43 @@ +/*==================================================================== + * sndpallocate.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" + +ALSndId alSndpAllocate(ALSndPlayer *sndp, ALSound *sound) +{ + ALSndId i; + ALSoundState *sState = sndp->sndState; + + for (i = 0; i < sndp->maxSounds; i++) { + if (!sState[i].sound) { + sState[i].sound = sound; + sState[i].priority = AL_DEFAULT_PRIORITY; + sState[i].state = AL_STOPPED; + sState[i].pitch = 1.0; + sState[i].pan = AL_PAN_CENTER; + sState[i].fxMix = AL_DEFAULT_FXMIX; + sState[i].vol = 32767*sound->sampleVolume/AL_VOL_FULL; + return i; + } + } + + return -1; +} + diff --git a/lib/ultralib/src/audio/sndpdeallocate.c b/lib/ultralib/src/audio/sndpdeallocate.c new file mode 100644 index 0000000..7c18b56 --- /dev/null +++ b/lib/ultralib/src/audio/sndpdeallocate.c @@ -0,0 +1,35 @@ +/*==================================================================== + * sndpdeallocate.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpDeallocate(ALSndPlayer *sndp, ALSndId id) +{ + ALSoundState *sState = sndp->sndState; + + ALFailIf((sState + id)->state != AL_STOPPED, ERR_ALSNDPDEALLOCATE); + + sState[id].sound = 0; + if (sndp->target == id) /* if we are deleting the target sound */ + sndp->target = -1; +} + diff --git a/lib/ultralib/src/audio/sndpdelete.c b/lib/ultralib/src/audio/sndpdelete.c new file mode 100644 index 0000000..5cfb4f7 --- /dev/null +++ b/lib/ultralib/src/audio/sndpdelete.c @@ -0,0 +1,44 @@ +/*==================================================================== + * sndpdelete.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpDelete(ALSndPlayer *sndp) +{ + /* + * Remove client from synthesizer. Note application is responsible + * for making sure all sounds have been stopped beforehand. + */ +#ifdef _DEBUG + { + int i, notStopped = 0; + ALSoundState *sState = sndp->sndState; + + for (i=0; imaxSounds; i++) + if ((sState + i)->state != AL_STOPPED) + notStopped = 1; + ALFailIf(notStopped, ERR_ALSNDPDELETE); + } +#endif + alSynRemovePlayer(&alGlobals->drvr, &sndp->node); +} + diff --git a/lib/ultralib/src/audio/sndpgetsound.c b/lib/ultralib/src/audio/sndpgetsound.c new file mode 100644 index 0000000..9088982 --- /dev/null +++ b/lib/ultralib/src/audio/sndpgetsound.c @@ -0,0 +1,27 @@ +/*==================================================================== + * sndpgetsound.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" + +ALSndId alSndpGetSound(ALSndPlayer *sndp) +{ + return (ALSndId) sndp->target; +} + diff --git a/lib/ultralib/src/audio/sndpgetstate.c b/lib/ultralib/src/audio/sndpgetstate.c new file mode 100644 index 0000000..882b4a3 --- /dev/null +++ b/lib/ultralib/src/audio/sndpgetstate.c @@ -0,0 +1,29 @@ +/*==================================================================== + * sndpgetstate.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" + +s32 alSndpGetState(ALSndPlayer *sndp) +{ + ALSoundState *sState = sndp->sndState; + + return (sState + sndp->target)->state; +} + diff --git a/lib/ultralib/src/audio/sndplayer.c b/lib/ultralib/src/audio/sndplayer.c new file mode 100644 index 0000000..f2d7b56 --- /dev/null +++ b/lib/ultralib/src/audio/sndplayer.c @@ -0,0 +1,297 @@ +/*==================================================================== + * Sndplayer.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include +#include + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void alSndpNew(ALSndPlayer *sndp, ALSndpConfig *c) +{ + u8 *ptr; + ALEvent evt; + ALSoundState *sState; + u32 i; + + /* + * Init member variables + */ + sndp->maxSounds = c->maxSounds; + sndp->target = -1; + sndp->frameTime = AL_USEC_PER_FRAME; /* time between API events */ + sState = (ALSoundState*)alHeapAlloc(c->heap, 1, + c->maxSounds * sizeof(ALSoundState)); + sndp->sndState = sState; + + for(i = 0; i < c->maxSounds; i++) + sState[i].sound = 0; + + /* + * init the event queue + */ + ptr = alHeapAlloc(c->heap, 1, c->maxEvents * sizeof(ALEventListItem)); + alEvtqNew(&sndp->evtq, (ALEventListItem *)ptr, c->maxEvents); + + /* + * add ourselves to the driver + */ + sndp->drvr = &alGlobals->drvr; + sndp->node.next = NULL; + sndp->node.handler = _sndpVoiceHandler; + sndp->node.clientData = sndp; + alSynAddPlayer(sndp->drvr, &sndp->node); + + /* + * Start responding to API events + */ + evt.type = AL_SNDP_API_EVT; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, sndp->frameTime); + sndp->nextDelta = alEvtqNextEvent(&sndp->evtq, &sndp->nextEvent); + +} + +/************************************************************* + * Sound Player private routines + *************************************************************/ +ALMicroTime _sndpVoiceHandler(void *node) +{ + ALSndPlayer *sndp = (ALSndPlayer *) node; + ALSndpEvent evt; + + do { + switch (sndp->nextEvent.type) { + case (AL_SNDP_API_EVT): + evt.common.type = AL_SNDP_API_EVT; +#if BUILD_VERSION >= VERSION_K + evt.common.state = (ALSoundState*)-1; +#endif + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, sndp->frameTime); + break; + + default: + _handleEvent(sndp, (ALSndpEvent *)&sndp->nextEvent); + break; + } + sndp->nextDelta = alEvtqNextEvent(&sndp->evtq, &sndp->nextEvent); + + } while (sndp->nextDelta == 0); + sndp->curTime += sndp->nextDelta; + return sndp->nextDelta; +} + +void _handleEvent(ALSndPlayer *sndp, ALSndpEvent *event) +{ + ALVoiceConfig vc; + ALSound *snd; + ALVoice *voice; + ALPan pan; + f32 pitch; + ALSndpEvent evt; + ALMicroTime delta; + + s16 vol; + s16 tmp; + s32 vtmp; + ALSoundState *state; + + state = event->common.state; + snd = state->sound; + + + switch (event->msg.type) { + case (AL_SNDP_PLAY_EVT): + if (state->state != AL_STOPPED || !snd) + return; + + vc.fxBus = 0; /* effect buss 0 */ + vc.priority = state->priority; + vc.unityPitch = 0; + + voice = &state->voice; + alSynAllocVoice(sndp->drvr, voice, &vc); + + vol = (s16) ((s32) snd->envelope->attackVolume*state->vol/AL_VOL_FULL); + tmp = state->pan - AL_PAN_CENTER + snd->samplePan; + tmp = MAX(tmp, AL_PAN_LEFT); + pan = (ALPan) MIN(tmp, AL_PAN_RIGHT); + pitch = state->pitch; + delta = snd->envelope->attackTime; + + alSynStartVoice(sndp->drvr, voice, snd->wavetable); + state->state = AL_PLAYING; + + alSynSetPan(sndp->drvr, voice, pan); + alSynSetVol(sndp->drvr, voice, vol, delta); + alSynSetPitch(sndp->drvr, voice, pitch); + alSynSetFXMix(sndp->drvr, voice, state->fxMix); + + evt.common.type = AL_SNDP_DECAY_EVT; + evt.common.state = state; + delta = (ALMicroTime) _DivS32ByF32 (snd->envelope->attackTime, state->pitch); + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); + break; + + case (AL_SNDP_STOP_EVT): + if (state->state != AL_PLAYING || !snd) + return; + + delta = (ALMicroTime) _DivS32ByF32 (snd->envelope->releaseTime, state->pitch); + alSynSetVol(sndp->drvr, &state->voice, 0, delta); + + if (delta) { + evt.common.type = AL_SNDP_END_EVT; + evt.common.state = state; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); + state->state = AL_STOPPING; + } else { + /* note: this code is repeated in AL_SNDP_END_EVT */ + alSynStopVoice(sndp->drvr, &state->voice); + alSynFreeVoice(sndp->drvr, &state->voice); + _removeEvents(&sndp->evtq, state); + state->state = AL_STOPPED; + } + break; + + case (AL_SNDP_PAN_EVT): + state->pan = event->pan.pan; + if (state->state == AL_PLAYING && snd){ + tmp = state->pan - AL_PAN_CENTER + snd->samplePan; + tmp = MAX(tmp, AL_PAN_LEFT); + pan = (ALPan) MIN(tmp, AL_PAN_RIGHT); + alSynSetPan(sndp->drvr, &state->voice, pan); + } + break; + + case (AL_SNDP_PITCH_EVT): + /* Limit the pitch to a practical value even though we only need */ + /* to limit it to a non-zero number to avoid divide by zero. */ + if ((state->pitch = event->pitch.pitch) < MIN_RATIO) + state->pitch = MIN_RATIO; + + if (state->state == AL_PLAYING){ + alSynSetPitch(sndp->drvr, &state->voice, state->pitch); + } + break; + + case (AL_SNDP_FX_EVT): + state->fxMix = event->fx.mix; + if (state->state == AL_PLAYING) + alSynSetFXMix(sndp->drvr, &state->voice, state->fxMix); + break; + + case (AL_SNDP_VOL_EVT): + state->vol = event->vol.vol; + if (state->state == AL_PLAYING && snd){ + vtmp = snd->envelope->decayVolume * state->vol/AL_VOL_FULL; + alSynSetVol(sndp->drvr, &state->voice, (s16) vtmp, 1000); + } + break; + + case (AL_SNDP_DECAY_EVT): + /* + * The voice has theoretically reached its attack velocity, + * set up callback for release envelope - except for a looped sound + */ + if (snd->envelope->decayTime != -1){ + vtmp = snd->envelope->decayVolume * state->vol/AL_VOL_FULL; + delta = (ALMicroTime) _DivS32ByF32 (snd->envelope->decayTime, state->pitch); + alSynSetVol(sndp->drvr, &state->voice, (s16) vtmp, delta); + evt.common.type = AL_SNDP_STOP_EVT; + evt.common.state = state; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); + } + break; + + case (AL_SNDP_END_EVT): + /* note: this code is repeated in AL_SNDP_STOP_EVT */ + alSynStopVoice(sndp->drvr, &state->voice); + alSynFreeVoice(sndp->drvr, &state->voice); + _removeEvents(&sndp->evtq, state); + state->state = AL_STOPPED; + break; + + default: + break; + } +} +static void _removeEvents(ALEventQueue *evtq, ALSoundState *state) +{ + ALLink *thisNode; + ALLink *nextNode; + ALEventListItem *thisItem; + ALEventListItem *nextItem; + ALSndpEvent *thisEvent; + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + thisNode = evtq->allocList.next; + while( thisNode != 0 ) { + nextNode = thisNode->next; + thisItem = (ALEventListItem *)thisNode; + nextItem = (ALEventListItem *)nextNode; + thisEvent = (ALSndpEvent *) &thisItem->evt; + if (thisEvent->common.state == state){ + if( nextItem ) + nextItem->delta += thisItem->delta; + alUnlink(thisNode); + alLink(thisNode, &evtq->freeList); + } + thisNode = nextNode; + } + + osSetIntMask(mask); +} +/* + This routine safely divides a signed 32-bit integer + by a floating point value. It avoids overflow by using + a double to store the result and then before truncating + to an integer it compares the result to the limit and + limits it on overflow. Underflow is handled automatically + by the CPU which limits the value to zero. + + Presently this routine is used to divide a time in usecs + by a pitch ratio. Since the time could be a very large number, + very small pitch ratios can cause the reult to overflow, + causing a floating point exception. +*/ +#if BUILD_VERSION == VERSION_J // Adjust line numbers to match assert +#line 277 +#elif BUILD_VERSION < VERSION_J +#line 278 +#endif +static s32 _DivS32ByF32 (s32 i, f32 f) +{ + #define INT_MAX 2147483647 /* Should be in a limits.h file. */ + f64 rd; + int ri; + + assert(f!=0); /* Caller must make sure we do not divide by zero! */ + + rd = i/f; /* Store result as a double to avoid overflow. */ + + if (rd > INT_MAX) /* Limit the value if necessary. */ + ri = INT_MAX; + else + ri = rd; + + return ri; +} diff --git a/lib/ultralib/src/audio/sndpplay.c b/lib/ultralib/src/audio/sndpplay.c new file mode 100644 index 0000000..ff5d123 --- /dev/null +++ b/lib/ultralib/src/audio/sndpplay.c @@ -0,0 +1,36 @@ +/*==================================================================== + * sndpplay.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpPlay(ALSndPlayer *sndp) +{ + ALSndpEvent evt; + ALSoundState *sState = sndp->sndState; + + ALFailIf((sState + sndp->target)->state != AL_STOPPED, ERR_ALSNDPPLAY); + + evt.common.type = AL_SNDP_PLAY_EVT; + evt.common.state = &sState[sndp->target]; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); +} + diff --git a/lib/ultralib/src/audio/sndpplayat.c b/lib/ultralib/src/audio/sndpplayat.c new file mode 100644 index 0000000..b37f796 --- /dev/null +++ b/lib/ultralib/src/audio/sndpplayat.c @@ -0,0 +1,32 @@ +/*==================================================================== + * sndpplayat.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" + +void alSndpPlayAt(ALSndPlayer *sndp, ALMicroTime delta) +{ + ALSndpEvent evt; + ALSoundState *sState = sndp->sndState; + + evt.common.type = AL_SNDP_PLAY_EVT; + evt.common.state = &sState[sndp->target]; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, delta); +} + diff --git a/lib/ultralib/src/audio/sndpsetfxmix.c b/lib/ultralib/src/audio/sndpsetfxmix.c new file mode 100644 index 0000000..147c956 --- /dev/null +++ b/lib/ultralib/src/audio/sndpsetfxmix.c @@ -0,0 +1,42 @@ +/*==================================================================== + * sndpsetfxmix.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpSetFXMix(ALSndPlayer *sndp, u8 mix) +{ + ALSndpEvent evt; + ALSoundState *sState = sndp->sndState; + +#ifdef _DEBUG + if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ + __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); + return; + } +#endif + + evt.fx.type = AL_SNDP_FX_EVT; + evt.fx.state = &sState[sndp->target]; + evt.fx.mix = mix; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); +} + diff --git a/lib/ultralib/src/audio/sndpsetpan.c b/lib/ultralib/src/audio/sndpsetpan.c new file mode 100644 index 0000000..5f98648 --- /dev/null +++ b/lib/ultralib/src/audio/sndpsetpan.c @@ -0,0 +1,42 @@ +/*==================================================================== + * sndpsetpan.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpSetPan(ALSndPlayer *sndp, ALPan pan) +{ + ALSndpEvent evt; + ALSoundState *sState = sndp->sndState; + +#ifdef _DEBUG + if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ + __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); + return; + } +#endif + + evt.pan.type = AL_SNDP_PAN_EVT; + evt.pan.pan = pan; + evt.pan.state = &sState[sndp->target]; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); +} + diff --git a/lib/ultralib/src/audio/sndpsetpitch.c b/lib/ultralib/src/audio/sndpsetpitch.c new file mode 100644 index 0000000..0ee174c --- /dev/null +++ b/lib/ultralib/src/audio/sndpsetpitch.c @@ -0,0 +1,48 @@ +/*==================================================================== + * sndpsetpitch.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpSetPitch(ALSndPlayer *sndp, f32 pitch) +{ + ALSndpEvent evt; + ALSoundState *sState = sndp->sndState; + + /* + * If this is set during playback there will be + * a the envelope lengths won't be accurate - but you can still + * do it. + */ + +#ifdef _DEBUG + if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ + __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); + return; + } +#endif + + evt.pitch.type = AL_SNDP_PITCH_EVT; + evt.pitch.state = &sState[sndp->target]; + evt.pitch.pitch = pitch; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); +} + diff --git a/lib/ultralib/src/audio/sndpsetpriority.c b/lib/ultralib/src/audio/sndpsetpriority.c new file mode 100644 index 0000000..0d0fbc0 --- /dev/null +++ b/lib/ultralib/src/audio/sndpsetpriority.c @@ -0,0 +1,38 @@ +/*==================================================================== + * sndpsetsound.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpSetPriority(ALSndPlayer *sndp, ALSndId id, u8 priority) +{ + ALSoundState *sState = sndp->sndState; + +#ifdef _DEBUG + if ((id >= sndp->maxSounds) || (id < 0)){ + __osError(ERR_ALSNDPSETPRIORITY, 2, id, sndp->maxSounds-1); + return; + } +#endif + + sState[id].priority = priority; +} + diff --git a/lib/ultralib/src/audio/sndpsetsound.c b/lib/ultralib/src/audio/sndpsetsound.c new file mode 100644 index 0000000..3d341ec --- /dev/null +++ b/lib/ultralib/src/audio/sndpsetsound.c @@ -0,0 +1,36 @@ +/*==================================================================== + * sndpsetsound.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpSetSound(ALSndPlayer *sndp, ALSndId id) +{ +#ifdef _DEBUG + if ((id >= sndp->maxSounds) || (id < 0)){ + __osError(ERR_ALSNDPSETSOUND, 2, id, sndp->maxSounds-1); + return; + } +#endif + + sndp->target = id; +} + diff --git a/lib/ultralib/src/audio/sndpsetvol.c b/lib/ultralib/src/audio/sndpsetvol.c new file mode 100644 index 0000000..ad79f5f --- /dev/null +++ b/lib/ultralib/src/audio/sndpsetvol.c @@ -0,0 +1,42 @@ +/*==================================================================== + * sndpsetvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" +#include +#include + +void alSndpSetVol(ALSndPlayer *sndp, s16 vol) +{ + ALSndpEvent evt; + ALSoundState *sState = sndp->sndState; + +#ifdef _DEBUG + if ((sndp->target >= sndp->maxSounds) || (sndp->target < 0)){ + __osError(ERR_ALSNDPSETPAR, 2, sndp->target, sndp->maxSounds-1); + return; + } +#endif + + evt.vol.type = AL_SNDP_VOL_EVT; + evt.vol.state = &sState[sndp->target]; + evt.vol.vol = vol; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); +} + diff --git a/lib/ultralib/src/audio/sndpstop.c b/lib/ultralib/src/audio/sndpstop.c new file mode 100644 index 0000000..69aead6 --- /dev/null +++ b/lib/ultralib/src/audio/sndpstop.c @@ -0,0 +1,35 @@ +/*==================================================================== + * sndpstop.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "sndp.h" + +void alSndpStop(ALSndPlayer *sndp) +{ + ALSndpEvent evt; + ALSoundState *sState = sndp->sndState; + + /* + * Go immediately into the release phase + */ + evt.common.type = AL_SNDP_STOP_EVT; + evt.common.state = &sState[sndp->target]; + alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, 0); +} + diff --git a/lib/ultralib/src/audio/synaddplayer.c b/lib/ultralib/src/audio/synaddplayer.c new file mode 100644 index 0000000..77efb29 --- /dev/null +++ b/lib/ultralib/src/audio/synaddplayer.c @@ -0,0 +1,34 @@ +/*==================================================================== + * synaddplayer.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include + +void alSynAddPlayer(ALSynth *drvr, ALPlayer *client) +{ + OSIntMask mask = osSetIntMask(OS_IM_NONE); + + client->samplesLeft = drvr->curSamples; + client->next = drvr->head; + drvr->head = client; + + osSetIntMask(mask); +} + diff --git a/lib/ultralib/src/audio/synallocfx.c b/lib/ultralib/src/audio/synallocfx.c new file mode 100644 index 0000000..e0e7f26 --- /dev/null +++ b/lib/ultralib/src/audio/synallocfx.c @@ -0,0 +1,32 @@ +/*==================================================================== + * synallocfx.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp) +{ + alFxNew(&s->auxBus[bus].fx[0], c, hp); + alFxParam(&s->auxBus[bus].fx[0], AL_FILTER_SET_SOURCE, + &s->auxBus[bus]); + alMainBusParam(s->mainBus, AL_FILTER_ADD_SOURCE,&s->auxBus[bus].fx[0]); + + return (ALFxRef)(&s->auxBus[bus].fx[0]); +} + diff --git a/lib/ultralib/src/audio/synallocvoice.c b/lib/ultralib/src/audio/synallocvoice.c new file mode 100644 index 0000000..73d608d --- /dev/null +++ b/lib/ultralib/src/audio/synallocvoice.c @@ -0,0 +1,132 @@ +/*==================================================================== + * synallocvoice.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include "synthInternals.h" + +s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority); + +s32 alSynAllocVoice(ALSynth *drvr, ALVoice *voice, ALVoiceConfig *vc) +{ + PVoice *pvoice = 0; + ALFilter *f; + ALParam *update; + s32 stolen; + +#ifdef _DEBUG + /* need two updates if voice is stolen */ + if (drvr->paramList == 0) { + __osError(ERR_ALSYN_NO_UPDATE, 0); + return 0; + } else if (drvr->paramList->next == 0) { + __osError(ERR_ALSYN_NO_UPDATE, 0); + return 0; + } +#endif + + voice->priority = vc->priority; + voice->unityPitch = vc->unityPitch; + voice->table = 0; + voice->fxBus = vc->fxBus; + voice->state = AL_STOPPED; + voice->pvoice = 0; + + stolen = _allocatePVoice(drvr, &pvoice, vc->priority); + + if (pvoice) { /* if we were able to allocate a voice */ + + f = pvoice->channelKnob; + + if (stolen) { + + pvoice->offset = 512; + pvoice->vvoice->pvoice = 0; /* zero stolen voice */ + + /* + * ramp down stolen voice + */ + update = __allocParam(); + update->delta = drvr->paramSamples; + update->type = AL_FILTER_SET_VOLUME; + update->data.i = 0; + update->moredata.i = pvoice->offset - 64; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + + /* + * stop stolen voice + */ + update = __allocParam(); + if (update) { + update->delta = drvr->paramSamples + pvoice->offset; + update->type = AL_FILTER_STOP_VOICE; + update->next = 0; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } else { +#ifdef _DEBUG + __osError(ERR_ALSYN_NO_UPDATE, 0); +#endif + } + + } else { + pvoice->offset = 0; + } + + pvoice->vvoice = voice; /* assign new voice */ + voice->pvoice = pvoice; + + } + + return (pvoice != 0); +} + +s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority) +{ + ALLink *dl; + PVoice *pv; + s32 stolen = 0; + + if ((dl = drvr->pLameList.next) != 0) { /* check the lame list first */ + *pvoice = (PVoice *) dl; + alUnlink(dl); + alLink(dl, &drvr->pAllocList); + } else if ((dl = drvr->pFreeList.next) != 0) { /* from the free list */ + *pvoice = (PVoice *) dl; + alUnlink(dl); + alLink(dl, &drvr->pAllocList); + } else { /* steal one */ + for (dl = drvr->pAllocList.next; dl != 0; dl = dl->next) { + pv = (PVoice *)dl; + + /* + * if it is lower priority and not already stolen, keep it + * as a candidate for stealing + */ + if ((pv->vvoice->priority <= priority) && (pv->offset == 0)) { + *pvoice = pv; + priority = pv->vvoice->priority; + stolen = 1; + } + } + } + + return stolen; +} + diff --git a/lib/ultralib/src/audio/syndelete.c b/lib/ultralib/src/audio/syndelete.c new file mode 100644 index 0000000..900fe76 --- /dev/null +++ b/lib/ultralib/src/audio/syndelete.c @@ -0,0 +1,27 @@ +/*==================================================================== + * syndelete.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +void alSynDelete(ALSynth *drvr) +{ + drvr->head = 0; +} + diff --git a/lib/ultralib/src/audio/synfreefx.c b/lib/ultralib/src/audio/synfreefx.c new file mode 100644 index 0000000..be436ea --- /dev/null +++ b/lib/ultralib/src/audio/synfreefx.c @@ -0,0 +1,26 @@ +/*==================================================================== + * synfreefx.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +void alSynFreeFX(ALSynth *s, ALFxRef *fx) +{ +} + diff --git a/lib/ultralib/src/audio/synfreevoice.c b/lib/ultralib/src/audio/synfreevoice.c new file mode 100644 index 0000000..eaa71ac --- /dev/null +++ b/lib/ultralib/src/audio/synfreevoice.c @@ -0,0 +1,54 @@ +/*==================================================================== + * synfreevoice.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include "synthInternals.h" + +#include + +void alSynFreeVoice(ALSynth *drvr, ALVoice *voice) +{ + ALFilter *f; + ALFreeParam *update; + + if (voice->pvoice) { + + if (voice->pvoice->offset) { /* if voice was stolen */ + update = (ALFreeParam *)__allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + /* + * set voice data + */ + update->delta = drvr->paramSamples + voice->pvoice->offset; + update->type = AL_FILTER_FREE_VOICE; + update->pvoice = voice->pvoice; + + f = voice->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } else { + _freePVoice(drvr, voice->pvoice); + } + + voice->pvoice = 0; + + } +} diff --git a/lib/ultralib/src/audio/syngetfxref.c b/lib/ultralib/src/audio/syngetfxref.c new file mode 100644 index 0000000..b0fa577 --- /dev/null +++ b/lib/ultralib/src/audio/syngetfxref.c @@ -0,0 +1,33 @@ +/*==================================================================== + * syngetfxref.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +ALFxRef alSynGetFXRef(ALSynth *s, s16 bus, s16 index) +{ + ALMainBus *m = (ALMainBus *) s->mainBus; + ALFilter **sources = m->sources; + + if (sources[0]->type == AL_FX) + return (ALFxRef)(&s->auxBus[bus].fx[index]); + else + return 0; +} + diff --git a/lib/ultralib/src/audio/syngetpriority.c b/lib/ultralib/src/audio/syngetpriority.c new file mode 100644 index 0000000..68de365 --- /dev/null +++ b/lib/ultralib/src/audio/syngetpriority.c @@ -0,0 +1,27 @@ +/*==================================================================== + * syngetpriority.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +s16 alSynGetPriority(ALSynth *s, ALVoice *voice) +{ + return voice->priority; +} + diff --git a/lib/ultralib/src/audio/synremoveplayer.c b/lib/ultralib/src/audio/synremoveplayer.c new file mode 100644 index 0000000..0248a7e --- /dev/null +++ b/lib/ultralib/src/audio/synremoveplayer.c @@ -0,0 +1,49 @@ +/*==================================================================== + * synremoveplayer.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include + +void alSynRemovePlayer(ALSynth *drvr, ALPlayer *client) +{ + ALPlayer *thing; + ALPlayer *prev = 0; + + if (drvr->head != 0) + { + OSIntMask mask = osSetIntMask(OS_IM_NONE); + + for (thing = drvr->head; thing != 0; thing = thing->next) { + if (thing == client) { + if(prev) + prev->next = thing->next; + else + drvr->head = thing->next; + + client->next = 0; + break; + } + prev = thing; + } + + osSetIntMask(mask); + } +} + diff --git a/lib/ultralib/src/audio/synsetfxmix.c b/lib/ultralib/src/audio/synsetfxmix.c new file mode 100644 index 0000000..c787103 --- /dev/null +++ b/lib/ultralib/src/audio/synsetfxmix.c @@ -0,0 +1,60 @@ +/*==================================================================== + * synsetfxmix.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include + +void alSynSetFXMix(ALSynth *synth, ALVoice *v, u8 fxmix) +{ + ALParam *update; + ALFilter *f; + + if (v->pvoice) { + /* + * get new update struct from the free list + */ + update = __allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + /* + * set offset and fxmix data + */ + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_SET_FXAMT; +#if BUILD_VERSION >= VERSION_J + if (fxmix > 127) { + fxmix = 127; + } + update->data.i = fxmix; +#else + if (fxmix < 0) { // Not possible + update->data.i = -fxmix; + } else { + update->data.i = fxmix; + } +#endif + update->next = 0; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } +} + diff --git a/lib/ultralib/src/audio/synsetfxparam.c b/lib/ultralib/src/audio/synsetfxparam.c new file mode 100644 index 0000000..b3991f6 --- /dev/null +++ b/lib/ultralib/src/audio/synsetfxparam.c @@ -0,0 +1,29 @@ +/*==================================================================== + * synsetfxparam.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +void alSynSetFXParam(ALSynth *synth, ALFxRef fx, s16 paramID, void *param) +{ + ALFx *f = (ALFx *)fx; + + (*f->paramHdl)(f, (s32)paramID, param); +} + diff --git a/lib/ultralib/src/audio/synsetpan.c b/lib/ultralib/src/audio/synsetpan.c new file mode 100644 index 0000000..0d68538 --- /dev/null +++ b/lib/ultralib/src/audio/synsetpan.c @@ -0,0 +1,50 @@ +/*==================================================================== + * synsetpan.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include + +void alSynSetPan(ALSynth *synth, ALVoice *v, u8 pan) +{ + ALParam *update; + ALFilter *f; + + if (v->pvoice) { + + /* + * get new update struct from the free list + */ + update = __allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + /* + * set offset and pan data + */ + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_SET_PAN; + update->data.i = pan; + update->next = 0; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } +} + diff --git a/lib/ultralib/src/audio/synsetpitch.c b/lib/ultralib/src/audio/synsetpitch.c new file mode 100644 index 0000000..0bfb7ba --- /dev/null +++ b/lib/ultralib/src/audio/synsetpitch.c @@ -0,0 +1,50 @@ +/*==================================================================== + * synsetpitch.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include + +void alSynSetPitch(ALSynth *synth, ALVoice *v, f32 pitch) +{ + ALParam *update; + ALFilter *f; + + if (v->pvoice) { + /* + * get new update struct from the free list + */ + + update = __allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + /* + * set offset and pitch data + */ + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_SET_PITCH; + update->data.f = pitch; + update->next = 0; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } +} + diff --git a/lib/ultralib/src/audio/synsetpriority.c b/lib/ultralib/src/audio/synsetpriority.c new file mode 100644 index 0000000..c680bcc --- /dev/null +++ b/lib/ultralib/src/audio/synsetpriority.c @@ -0,0 +1,27 @@ +/*==================================================================== + * synsetpriority.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alSynSetPriority(ALSynth *s, ALVoice *voice, s16 priority) +{ + voice->priority = priority; +} + diff --git a/lib/ultralib/src/audio/synsetvol.c b/lib/ultralib/src/audio/synsetvol.c new file mode 100644 index 0000000..181c96f --- /dev/null +++ b/lib/ultralib/src/audio/synsetvol.c @@ -0,0 +1,50 @@ +/*==================================================================== + * synsetvol.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include + +void alSynSetVol(ALSynth *synth, ALVoice *v, s16 volume, ALMicroTime t) +{ + ALParam *update; + ALFilter *f; + + if (v->pvoice) { + /* + * get new update struct from the free list + */ + update = __allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + /* + * set offset and volume data + */ + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_SET_VOLUME; + update->data.i = volume; + update->moredata.i = _timeToSamples(synth, t); + update->next = 0; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } +} + diff --git a/lib/ultralib/src/audio/synstartvoice.c b/lib/ultralib/src/audio/synstartvoice.c new file mode 100644 index 0000000..9ad1d89 --- /dev/null +++ b/lib/ultralib/src/audio/synstartvoice.c @@ -0,0 +1,48 @@ +/*==================================================================== + * synstartvoice.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include + +void alSynStartVoice(ALSynth *synth, ALVoice *v, ALWaveTable *table) +{ + ALStartParam *update; + ALFilter *f; + + if (v->pvoice) { + + update = (ALStartParam *)__allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + /* + * send the start message to the motion control filter + */ + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_START_VOICE; + update->wave = table; + update->next = 0; + update->unity = v->unityPitch; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } +} + diff --git a/lib/ultralib/src/audio/synstartvoiceparam.c b/lib/ultralib/src/audio/synstartvoiceparam.c new file mode 100644 index 0000000..8d1a54b --- /dev/null +++ b/lib/ultralib/src/audio/synstartvoiceparam.c @@ -0,0 +1,75 @@ +/*==================================================================== + * synquickstartvoice + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include +#include + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 1.17 $" +#endif + +void alSynStartVoiceParams(ALSynth *s, ALVoice *v, ALWaveTable *w, + f32 pitch, s16 vol, ALPan pan, u8 fxmix, + ALMicroTime t) +{ + ALStartParamAlt *update; + ALFilter *f; + + if (v->pvoice) { + /* + * get new update struct from the free list + */ + update = (ALStartParamAlt *)__allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + +#if BUILD_VERSION >= VERSION_J + if (fxmix > 127) { + fxmix = 127; + } +#else + if (fxmix < 0) { // Not possible + fxmix = -fxmix; + } +#endif + + /* + * set offset and fxmix data + */ + update->delta = s->paramSamples + v->pvoice->offset; + update->next = 0; + update->type = AL_FILTER_START_VOICE_ALT; + + update->unity = v->unityPitch; + update->pan = pan; + update->volume = vol; + update->fxMix = fxmix; + update->pitch = pitch; + update->samples = _timeToSamples(s, t); + update->wave = w; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } + +} + + diff --git a/lib/ultralib/src/audio/synstopvoice.c b/lib/ultralib/src/audio/synstopvoice.c new file mode 100644 index 0000000..69c09d8 --- /dev/null +++ b/lib/ultralib/src/audio/synstopvoice.c @@ -0,0 +1,44 @@ +/*==================================================================== + * synstopvoice.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include + + +void alSynStopVoice(ALSynth *synth, ALVoice *v) +{ + ALParam *update; + ALFilter *f; + + if (v->pvoice) { + + update = __allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_STOP_VOICE; + update->next = 0; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } +} + diff --git a/lib/ultralib/src/audio/synthInternals.h b/lib/ultralib/src/audio/synthInternals.h new file mode 100644 index 0000000..c6c476c --- /dev/null +++ b/lib/ultralib/src/audio/synthInternals.h @@ -0,0 +1,344 @@ +/*==================================================================== + * audioInternals.h + * + * Synopsis: + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#ifndef __audioInternals__ +#define __audioInternals__ + +#include +#include + +/* + * filter message ids + */ +enum { + AL_FILTER_FREE_VOICE, + AL_FILTER_SET_SOURCE, + AL_FILTER_ADD_SOURCE, + AL_FILTER_ADD_UPDATE, + AL_FILTER_RESET, + AL_FILTER_SET_WAVETABLE, +/* AL_FILTER_SET_DMA_PROC,*/ +/* AL_FILTER_SKIP_LOOP,*/ + AL_FILTER_SET_DRAM, + AL_FILTER_SET_PITCH, + AL_FILTER_SET_UNITY_PITCH, + AL_FILTER_START, +/* AL_FILTER_SET_DECAY,*/ +/* AL_FILTER_SET_FC,*/ + AL_FILTER_SET_STATE, + AL_FILTER_SET_VOLUME, + AL_FILTER_SET_PAN, + AL_FILTER_START_VOICE_ALT, + AL_FILTER_START_VOICE, + AL_FILTER_STOP_VOICE, + AL_FILTER_SET_FXAMT +}; + +#define AL_MAX_RSP_SAMPLES 160 + +/* + * buffer locations based on AL_MAX_RSP_SAMPLES + */ +#define AL_DECODER_IN 0 +#define AL_RESAMPLER_OUT 0 +#define AL_TEMP_0 0 +#define AL_DECODER_OUT 320 +#define AL_TEMP_1 320 +#define AL_TEMP_2 640 +#define AL_MAIN_L_OUT 1088 +#define AL_MAIN_R_OUT 1408 +#define AL_AUX_L_OUT 1728 +#define AL_AUX_R_OUT 2048 + +/* + * filter types + */ +enum { + AL_ADPCM, + AL_RESAMPLE, + AL_BUFFER, + AL_SAVE, + AL_ENVMIX, + AL_FX, + AL_AUXBUS, + AL_MAINBUS +}; + +typedef struct ALParam_s { + struct ALParam_s *next; + s32 delta; + s16 type; + union { + f32 f; + s32 i; + } data; + union { + f32 f; + s32 i; + } moredata; + union { + f32 f; + s32 i; + } stillmoredata; + union { + f32 f; + s32 i; + } yetstillmoredata; +} ALParam; + +typedef struct { + struct ALParam_s *next; + s32 delta; + s16 type; + s16 unity; /* disable resampler */ + f32 pitch; + s16 volume; + ALPan pan; + u8 fxMix; + s32 samples; + struct ALWaveTable_s *wave; +} ALStartParamAlt; + +typedef struct { + struct ALParam_s *next; + s32 delta; + s16 type; + s16 unity; /* disable resampler */ + struct ALWaveTable_s *wave; +} ALStartParam; + +typedef struct { + struct ALParam_s *next; + s32 delta; + s16 type; + struct PVoice_s *pvoice; +} ALFreeParam; + +typedef Acmd *(*ALCmdHandler)(void *, s16 *, s32, s32, Acmd *); +typedef s32 (*ALSetParam)(void *, s32, void *); + +typedef struct ALFilter_s { + struct ALFilter_s *source; + ALCmdHandler handler; + ALSetParam setParam; + s16 inp; + s16 outp; + s32 type; +} ALFilter; + +void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type); + +#define AL_MAX_ADPCM_STATES 3 /* Depends on number of subframes + * per frame and loop length + */ +typedef struct { + ALFilter filter; + ADPCM_STATE *state; + ADPCM_STATE *lstate; + ALRawLoop loop; + struct ALWaveTable_s *table; + s32 bookSize; + ALDMAproc dma; + void *dmaState; + s32 sample; + s32 lastsam; + s32 first; + s32 memin; +} ALLoadFilter; + +void alLoadNew(ALLoadFilter *f, ALDMANew dma, ALHeap *hp); +Acmd *alAdpcmPull(void *f, s16 *outp, s32 byteCount, s32 sampleOffset, Acmd *p); +Acmd *alRaw16Pull(void *f, s16 *outp, s32 byteCount, s32 sampleOffset, Acmd *p); +s32 alLoadParam(void *filter, s32 paramID, void *param); + +typedef struct ALResampler_s { + ALFilter filter; + RESAMPLE_STATE *state; + f32 ratio; + s32 upitch; + f32 delta; + s32 first; + ALParam *ctrlList; + ALParam *ctrlTail; + s32 motion; +} ALResampler; + +typedef struct { + s16 fc; + s16 fgain; + union { + s16 fccoef[16]; + s64 force_aligned; + } fcvec; + POLEF_STATE *fstate; + s32 first; +} ALLowPass; + +typedef struct { + u32 input; + u32 output; + s16 ffcoef; + s16 fbcoef; + s16 gain; + f32 rsinc; + f32 rsval; + s32 rsdelta; + f32 rsgain; + ALLowPass *lp; + ALResampler *rs; +} ALDelay; + +typedef s32 (*ALSetFXParam)(void *, s32, void *); +typedef struct { + struct ALFilter_s filter; + s16 *base; + s16 *input; + u32 length; + ALDelay *delay; + u8 section_count; + ALSetFXParam paramHdl; +} ALFx; + +void alFxNew(ALFx *r, ALSynConfig *c, ALHeap *hp); +Acmd *alFxPull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); +s32 alFxParam(void *filter, s32 paramID, void *param); +s32 alFxParamHdl(void *filter, s32 paramID, void *param); + +#define AL_MAX_MAIN_BUS_SOURCES 1 +typedef struct ALMainBus_s { + ALFilter filter; + s32 sourceCount; + s32 maxSources; + ALFilter **sources; +} ALMainBus; + +void alMainBusNew(ALMainBus *m, void *ptr, s32 len); +Acmd *alMainBusPull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); +s32 alMainBusParam(void *filter, s32 paramID, void *param); + +#define AL_MAX_AUX_BUS_SOURCES 8 +#define AL_MAX_AUX_BUS_FX 1 +typedef struct ALAuxBus_s { + ALFilter filter; + s32 sourceCount; + s32 maxSources; + ALFilter **sources; + ALFx fx[AL_MAX_AUX_BUS_FX]; +} ALAuxBus; + +void alAuxBusNew(ALAuxBus *m, void *ptr, s32 len); +Acmd *alAuxBusPull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); +s32 alAuxBusParam(void *filter, s32 paramID, void *param); + +void alResampleNew(ALResampler *r, ALHeap *hp); +Acmd *alResamplePull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); +s32 alResampleParam(void *f, s32 paramID, void *param); + +typedef struct ALSave_s { + ALFilter filter; + s32 dramout; + s32 first; +} ALSave; + +void alSaveNew(ALSave *r); +Acmd *alSavePull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); +s32 alSaveParam(void *f, s32 paramID, void *param); + +typedef struct ALEnvMixer_s { + ALFilter filter; + ENVMIX_STATE *state; + s16 pan; + s16 volume; + s16 cvolL; + s16 cvolR; + s16 dryamt; + s16 wetamt; + u16 lratl; + s16 lratm; + s16 ltgt; + u16 rratl; + s16 rratm; + s16 rtgt; + s32 delta; + s32 segEnd; + s32 first; + ALParam *ctrlList; + ALParam *ctrlTail; + ALFilter **sources; + s32 motion; +} ALEnvMixer; + +void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp); +Acmd *alEnvmixerPull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); +s32 alEnvmixerParam(void *filter, s32 paramID, void *param); + + +/* + * heap stuff + */ +typedef struct { + s32 magic; /* check structure integrety */ + s32 size; /* size of this allocated block */ + u8 *file; /* file that this alloc was called from */ + s32 line; /* line that it was called from */ + s32 count; /* heap call number */ + s32 pad0; + s32 pad1; + s32 pad2; /* Make it 32 bytes */ +} HeapInfo; + +#define AL_CACHE_ALIGN 15 + +/* + * synth stuff + */ + +typedef struct PVoice_s { + ALLink node; + struct ALVoice_s *vvoice; + ALFilter *channelKnob; + ALLoadFilter decoder; + ALResampler resampler; + ALEnvMixer envmixer; + s32 offset; +} PVoice; + +/* + * prototypes for private driver functions + */ +ALParam *__allocParam(void); +void __freeParam(ALParam *param); +void _freePVoice(ALSynth *drvr, PVoice *pvoice); +void _collectPVoices(ALSynth *drvr); + +s32 _timeToSamples(ALSynth *ALSynth, s32 micros); +ALMicroTime _samplesToTime(ALSynth *synth, s32 samples); + +// This was renamed to have a leading underscore in 2.0J +#if BUILD_VERSION < VERSION_J +#define _init_lpfilter init_lpfilter +#endif + +void _init_lpfilter(ALLowPass *lp); + +#endif + diff --git a/lib/ultralib/src/audio/synthesizer.c b/lib/ultralib/src/audio/synthesizer.c new file mode 100644 index 0000000..9123874 --- /dev/null +++ b/lib/ultralib/src/audio/synthesizer.c @@ -0,0 +1,323 @@ +/*==================================================================== + * synthesizer.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +#include "synthInternals.h" +#include +#include +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +#ifdef AUD_PROFILE +#include +extern u32 cnt_index, drvr_num, drvr_cnt, drvr_max, drvr_min, lastCnt[]; +extern u32 client_num, client_cnt, client_max, client_min; +#endif + +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client); +static s32 _timeToSamplesNoRound(ALSynth *ALSynth, s32 micros); + +/*********************************************************************** + * Synthesis driver public interfaces + ***********************************************************************/ +void alSynNew(ALSynth *drvr, ALSynConfig *c) +{ + s32 i; + ALVoice *vv; + PVoice *pv; + ALVoice *vvoices; + PVoice *pvoices; + ALHeap *hp = c->heap; + ALSave *save; + ALFilter *sources; + ALParam *params; + ALParam *paramPtr; + + drvr->head = NULL; + drvr->numPVoices = c->maxPVoices; + drvr->curSamples = 0; + drvr->paramSamples = 0; + drvr->outputRate = c->outputRate; + drvr->maxOutSamples = AL_MAX_RSP_SAMPLES; + drvr->dma = (ALDMANew) c->dmaproc; + + save = alHeapAlloc(hp, 1, sizeof(ALSave)); + alSaveNew(save); + drvr->outputFilter = (ALFilter *)save; + + /* + * allocate and initialize the auxilliary effects bus. at present + * we only support 1 effects bus. + */ + drvr->auxBus = alHeapAlloc(hp, 1, sizeof(ALAuxBus)); + drvr->maxAuxBusses = 1; + sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); + alAuxBusNew(drvr->auxBus, sources, c->maxPVoices); + + /* + * allocate and initialize the main bus. + */ + drvr->mainBus = alHeapAlloc(hp, 1, sizeof(ALMainBus)); + sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); + alMainBusNew(drvr->mainBus, sources, c->maxPVoices); + + if (c->fxType != AL_FX_NONE){ + /* + * Allocate an effect and set parameters + */ + alSynAllocFX(drvr, 0, c, hp); + } else + /* + * Connect the aux bus to the main bus + */ + alMainBusParam(drvr->mainBus, AL_FILTER_ADD_SOURCE, &drvr->auxBus[0]); + + /* + * Build the physical voice lists + */ + drvr->pFreeList.next = 0; + drvr->pFreeList.prev = 0; + drvr->pLameList.next = 0; + drvr->pLameList.prev = 0; + drvr->pAllocList.next = 0; + drvr->pAllocList.prev = 0; + + pvoices = alHeapAlloc(hp, c->maxPVoices, sizeof(PVoice)); + for (i = 0; i < c->maxPVoices; i++) { + pv = &pvoices[i]; + alLink((ALLink *)pv, &drvr->pFreeList); + pv->vvoice = 0; + + alLoadNew(&pv->decoder, drvr->dma, hp); + alLoadParam(&pv->decoder, AL_FILTER_SET_SOURCE, 0); + + alResampleNew(&pv->resampler, hp); + alResampleParam(&pv->resampler, AL_FILTER_SET_SOURCE, &pv->decoder); + + alEnvmixerNew(&pv->envmixer, hp); + alEnvmixerParam(&pv->envmixer, AL_FILTER_SET_SOURCE, &pv->resampler); + + alAuxBusParam(drvr->auxBus, AL_FILTER_ADD_SOURCE, &pv->envmixer); + + pv->channelKnob = (ALFilter *)&pv->envmixer; + } + + alSaveParam(save, AL_FILTER_SET_SOURCE, drvr->mainBus); + + /* + * build the parameter update list + */ + params = alHeapAlloc(hp, c->maxUpdates, sizeof(ALParam)); + drvr->paramList = 0; + for (i = 0; i < c->maxUpdates; i++) { + paramPtr= ¶ms[i]; + paramPtr->next = drvr->paramList; + drvr->paramList = paramPtr; + } + + drvr->heap = hp; +} + +/* + * slAudioFrame() is called every video frame, and is based on the video + * frame interrupt. It is assumed to be an accurate time source for the + * clients. + */ +Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) +{ + ALPlayer *client; + ALFilter *output; + ALSynth *drvr = &alGlobals->drvr; + s16 tmp = 0; /* Starting buffer in DMEM */ + Acmd *cmdlEnd = cmdList; + Acmd *cmdPtr; + s32 nOut; + s16 *lOutBuf = outBuf; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + if (drvr->head == 0) { + *cmdLen = 0; + return cmdList; /* nothing to do */ + } + + /* + * run down list of clients and execute callback if needed this + * subframe. Here we do all the work for the frame at the + * start. Time offsets that occur before the next frame are + * executed "early". + */ + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + /* + * paramSamples = time of next parameter change. + * curSamples = current sample time. + * so paramSamples - curSamples is the time until the next parameter change. + * if the next parameter change occurs within this frame time (outLen), + * then call back the client that contains the parameter change. + * Note, paramSamples must be rounded down to 16 sample boundary for use + * during the client handler. + */ + + for (drvr->paramSamples = __nextSampleTime(drvr, &client); + drvr->paramSamples - drvr->curSamples < outLen; + drvr->paramSamples = __nextSampleTime(drvr, &client)) + { + drvr->paramSamples &= ~0xf; + client->samplesLeft += _timeToSamplesNoRound(drvr, (*client->handler)(client)); + } + + /* for safety's sake, always store paramSamples aligned to 16 sample boundary. + * this way, if an voice handler routine gets called outside the ALVoiceHandler + * routine (alSynAllocVoice) it will get timestamped with an aligned value and + * will be processed immediately next audio frame. + */ + drvr->paramSamples &= ~0xf; + + +#ifdef AUD_PROFILE + PROFILE_AUD(client_num, client_cnt, client_max, client_min); +#endif + + /* + * Now build the command list in small chunks + */ + while (outLen > 0){ + nOut = MIN(drvr->maxOutSamples, outLen); + + /* + * construct the command list for each physical voice by calling + * the head of the filter chain. + */ + cmdPtr = cmdlEnd; + aSegment(cmdPtr++, 0, 0); + output = drvr->outputFilter; + (*output->setParam)(output, AL_FILTER_SET_DRAM, lOutBuf); + cmdlEnd = (*output->handler)(output, &tmp, nOut, drvr->curSamples, + cmdPtr); + + outLen -= nOut; + lOutBuf += nOut<<1; /* For Stereo */ + drvr->curSamples += nOut; + + } + *cmdLen = (s32) (cmdlEnd - cmdList); + + _collectPVoices(drvr); /* collect free physical voices */ + +#ifdef AUD_PROFILE + PROFILE_AUD(drvr_num, drvr_cnt, drvr_max, drvr_min); +#endif + return cmdlEnd; +} + +/*********************************************************************** + * Synthesis driver private interfaces + ***********************************************************************/ + +ALParam *__allocParam() +{ + ALParam *update = 0; + ALSynth *drvr = &alGlobals->drvr; + + if (drvr->paramList) { + update = drvr->paramList; + drvr->paramList = drvr->paramList->next; + update->next = 0; + } + return update; +} + +void __freeParam(ALParam *param) +{ + ALSynth *drvr = &alGlobals->drvr; + param->next = drvr->paramList; + drvr->paramList = param; +} + +void _collectPVoices(ALSynth *drvr) +{ + ALLink *dl; + PVoice *pv; + + while ((dl = drvr->pLameList.next) != 0) { + pv = (PVoice *)dl; + + /* ### remove from mixer */ + + alUnlink(dl); + alLink(dl, &drvr->pFreeList); + } +} + +void _freePVoice(ALSynth *drvr, PVoice *pvoice) +{ + /* + * move the voice from the allocated list to the lame list + */ + alUnlink((ALLink *)pvoice); + alLink((ALLink *)pvoice, &drvr->pLameList); +} + +/* + Add 0.5 to adjust the average affect of + the truncation error produced by casting + a float to an int. +*/ +s32 _timeToSamplesNoRound(ALSynth *synth, s32 micros) +{ + f32 tmp = ((f32)micros) * synth->outputRate / 1000000.0 + 0.5; + + return (s32)tmp; +} + +s32 _timeToSamples(ALSynth *synth, s32 micros) +{ + return _timeToSamplesNoRound(synth, micros) & ~0xf; +} + +static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client) +{ + ALMicroTime delta = 0x7fffffff; /* max delta for s32 */ + ALPlayer *cl; +#if BUILD_VERSION < VERSION_J // Adjust line numbers to match assert +#line 306 +#endif + assert(drvr->head); + + *client = 0; + + for (cl = drvr->head; cl != 0; cl = cl->next) { + if ((cl->samplesLeft - drvr->curSamples) < delta) { + *client = cl; + delta = cl->samplesLeft - drvr->curSamples; + } + } + + return (*client)->samplesLeft; +} + + + diff --git a/lib/ultralib/src/debug/assert.c b/lib/ultralib/src/debug/assert.c new file mode 100644 index 0000000..ab7e313 --- /dev/null +++ b/lib/ultralib/src/debug/assert.c @@ -0,0 +1,12 @@ +#include "os.h" +#include "../os/osint.h" +#include "osint_debug.h" + +void __assertBreak(void); + +void __assert(const char* exp, const char* filename, int line) { +#ifndef _FINALROM + osSyncPrintf("\nASSERTION FAULT: %s, %d: \"%s\"\n", filename, line, exp); + __assertBreak; // Doesn't actually do anything, but is needed for matching +#endif +} diff --git a/lib/ultralib/src/debug/assertbreak.s b/lib/ultralib/src/debug/assertbreak.s new file mode 100644 index 0000000..69de71d --- /dev/null +++ b/lib/ultralib/src/debug/assertbreak.s @@ -0,0 +1,14 @@ +#include "PR/os_version.h" + +#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J +#include "sys/asm.h" +#include "sys/regdef.h" + +.set noreorder + +LEAF(__assertBreak) + break 0 + j ra +END(__assertBreak) + +#endif diff --git a/lib/ultralib/src/debug/atomic.c b/lib/ultralib/src/debug/atomic.c new file mode 100644 index 0000000..a0bd8fe --- /dev/null +++ b/lib/ultralib/src/debug/atomic.c @@ -0,0 +1,16 @@ +#include "PR/os_internal.h" + +int __osAtomicDec(unsigned int* p) { + u32 mask; + int result; + + mask = __osDisableInt(); + if (*p) { + (*p)--; + result = 1; + } else { + result = 0; + } + __osRestoreInt(mask); + return result; +} diff --git a/lib/ultralib/src/debug/kdebugserver.c b/lib/ultralib/src/debug/kdebugserver.c new file mode 100644 index 0000000..948a460 --- /dev/null +++ b/lib/ultralib/src/debug/kdebugserver.c @@ -0,0 +1,96 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/rdb.h" + +// not included in final rom, but __osThreadSave is here for some reason +OSThread __osThreadSave; + +extern OSThread *__osRunningThread; +extern u32 __osRdb_IP6_Empty; + +#ifndef _FINALROM + +static u8 buffer[12]; +static u32 numChars = 0; + +static u32 string_to_u32(u8* s) { + u32 k; + + k = ((s[0] & 0xFF) << 0x18); + k |= ((s[1] & 0xFF) << 0x10); + k |= ((s[2] & 0xFF) << 0x8); + k |= (s[3] & 0xFF); + + return k; +} + +static void send_packet(u8* s, u32 n) { + rdbPacket packet; + u32 i; + + packet.type = 0xC; + packet.length = n; + + for (i = 0; i < n; i++) { + packet.buf[i] = s[i]; + } + *(vu32*)RDB_BASE_REG = *(u32*)&packet; +} + +static void clear_IP6(void) { + while (!(__osGetCause() & CAUSE_IP6)) { + ; + } + *(vu32*)RDB_READ_INTR_REG = 0; + + while (__osGetCause() & CAUSE_IP6) { + ; + } +} + +static void send(u8* s, u32 n) { + u32 ct; + u32 i = 0; + u32 getLastIP6; + + if (!__osRdb_IP6_Empty) { + clear_IP6(); + getLastIP6 = FALSE; + } else { + getLastIP6 = TRUE; + } + while (n != 0) { + ct = (n < 3) ? n : 3; + send_packet(s + i, ct); + n -= ct; + i += ct; + if (n != 0) { + clear_IP6(); + } + } + if (getLastIP6) { + clear_IP6(); + } +} + +void kdebugserver(rdbPacket packet) { + u32 i; + u32 length; + u8* addr; + + for (i = 0; i < 3; i++) { + buffer[numChars++] = packet.buf[i]; + } + + if (buffer[0] == 2) { + send((char*)&__osRunningThread->context, sizeof(__OSThreadContext)); + numChars = 0; + } else if (numChars >= 9 && buffer[0] == 1) { + addr = string_to_u32(&buffer[1]); + length = string_to_u32(&buffer[5]); + send(addr, length); + numChars = 0; + } +} + +#endif diff --git a/lib/ultralib/src/debug/osint_debug.h b/lib/ultralib/src/debug/osint_debug.h new file mode 100644 index 0000000..6d644f2 --- /dev/null +++ b/lib/ultralib/src/debug/osint_debug.h @@ -0,0 +1,11 @@ +#include "PR/os_internal.h" + +extern s32 __osThprofFlag; +extern void (*__osThprofFunc)(OSThread*); +extern u32 __osThprofLastTimer; +extern u32 __osThprofCount; +extern __OSThreadprofile_s thprof[]; +extern u64 __osThprofHeap[]; +extern void* __osThprofStack; + +void osThreadProfileCallback(OSThread*); diff --git a/lib/ultralib/src/debug/profile.c b/lib/ultralib/src/debug/profile.c new file mode 100644 index 0000000..47b19d8 --- /dev/null +++ b/lib/ultralib/src/debug/profile.c @@ -0,0 +1,176 @@ +#include "PR/rdb.h" +#include "PR/ultratypes.h" +#include "PR/os.h" +#include "PR/ultraerror.h" +#include "PR/ultralog.h" +#include "PR/sptask.h" +#include "../os/osint.h" +#include "macros.h" +#include "osint_debug.h" + +#ifndef _FINALROM + +OSTimer __osProfTimer; +OSMesg __osProfTimerMsg; + +OSMesgQueue __osProfFlushMQ ALIGNED(8); +OSMesg __osProfFlushMesg; + +OSMesgQueue __osProfAckMQ ALIGNED(8); +OSMesg __osProfAckMesg; + +u32 __osProfTimerPeriod; + +u32 __osProfNumSections; + +static u32 __osProfileActive = FALSE; +static u32 __osProfileIOActive = FALSE; + +unsigned char __osProfileIOStack[2400] ALIGNED(16); + +static OSThread __osProfileIOThread; + +void osProfSendWord(u32 word); + +void __osProfileIO(void* arg) { + s32 totalBytes; + u32 bytesThisBlock; + u32 ct; + u8* sendPtr; + OSProf* t; + + while (TRUE) { + osRecvMesg(&__osProfFlushMQ, NULL, OS_MESG_BLOCK); + osProfSendWord(__osProfNumSections); + osProfSendWord(__osProfTimerPeriod); + osProfSendWord(__osProfileOverflowBin); + + for (t = __osProfileList; t < __osProfileListEnd; t++) { + osProfSendWord(t->text_start); + osProfSendWord(t->histo_size); + osRecvMesg(&__osProfAckMQ, NULL, OS_MESG_BLOCK); + + totalBytes = t->histo_size * 2; + sendPtr = t->histo_base; + while (totalBytes > 0) { + bytesThisBlock = (totalBytes < 0x800U) ? totalBytes : 0x800U; + + ct = 0; + while (ct < bytesThisBlock) { + ct += __osRdbSend(sendPtr + ct, bytesThisBlock - ct, RDB_TYPE_GtoH_PROF_DATA); + } + + sendPtr += bytesThisBlock; + totalBytes -= bytesThisBlock; + osRecvMesg(&__osProfAckMQ, NULL, OS_MESG_BLOCK); + } + } + } +} + +void osProfSendWord(u32 word) { + u32 ct = 0; + u8* sendPtr = &word; + + while (ct < sizeof(word)) { + ct += __osRdbSend(sendPtr + ct, sizeof(word) - ct, RDB_TYPE_GtoH_PROF_DATA); + } +} + +void osProfileFlush(void) { + osSendMesg(&__osProfFlushMQ, NULL, OS_MESG_BLOCK); +} + +void osProfileInit(OSProf* profp, u32 profcnt) { + u32 i; + OSProf* t; + +#if !defined(NDEBUG) && BUILD_VERSION >= VERSION_K + if (__osProfileActive) { + __osError(ERR_OSPROFILEINIT_STR, 0); + return; + } + + if (profcnt == 0) { + __osError(ERR_OSPROFILEINIT_CNT, 1, profcnt); + return; + } +#endif + + for (t = profp; t < profp + profcnt; t++) { +#ifndef NDEBUG + if ((u32)t->histo_base & 1) { + __osError(ERR_OSPROFILEINIT_ALN, 1, t->histo_base); + return; + } + + if (t->text_start >= t->text_end) { + __osError(ERR_OSPROFILEINIT_ORD, 2, t->text_start, t->text_end); + return; + } + + if (((u32)(t->text_end - t->text_start) / 4) > t->histo_size) { + __osError(ERR_OSPROFILEINIT_SIZ, 1, t->histo_size); + return; + } +#endif + + for (i = 0; i < t->histo_size; i++) { + t->histo_base[i] = 0; + } + } + + __osProfileActive = FALSE; + __osProfileOverflowBin = 0; + __osProfileList = profp; + __osProfileListEnd = profp + profcnt; + __osProfNumSections = profcnt; + if (!__osProfileIOActive) { + osCreateMesgQueue(&__osProfFlushMQ, &__osProfFlushMesg, 1); + osSetEventMesg(OS_EVENT_RDB_FLUSH_PROF, &__osProfFlushMQ, 0); + osCreateMesgQueue(&__osProfAckMQ, &__osProfAckMesg, 1); + osSetEventMesg(OS_EVENT_RDB_ACK_PROF, &__osProfAckMQ, 0); + osCreateThread(&__osProfileIOThread, 0, __osProfileIO, NULL, &__osProfileIOStack[2400], 0x81); + osStartThread(&__osProfileIOThread); + __osProfileIOActive = TRUE; + } +} + +void osProfileStart(u32 microseconds) { +#ifndef NDEBUG + if (microseconds < 50) { + __osError(ERR_OSPROFILESTART_TIME, 1, microseconds); + return; + } + + if (__osProfileActive) { + __osError(ERR_OSPROFILESTART_FLAG, 0); + return; + } +#endif + + osCreateMesgQueue(&__osProfTimerQ, &__osProfTimerMsg, 1); + osSetTimer(&__osProfTimer, 0, OS_USEC_TO_CYCLES(microseconds), &__osProfTimerQ, NULL); + __osProfTimerPeriod = microseconds; + __osProfileActive = TRUE; +} + +void osProfileStop(void) { +#ifndef NDEBUG + if (!__osProfileActive) { + __osError(ERR_OSPROFILESTOP_FLAG, 0); + return; + } +#endif + + if (osStopTimer(&__osProfTimer) < 0) { +#ifndef NDEBUG + __osError(ERR_OSPROFILESTOP_TIMER, 0); + return; +#endif + } + + __osProfileActive = FALSE; +} + +#endif diff --git a/lib/ultralib/src/debug/threadprofile.c b/lib/ultralib/src/debug/threadprofile.c new file mode 100644 index 0000000..e383773 --- /dev/null +++ b/lib/ultralib/src/debug/threadprofile.c @@ -0,0 +1,22 @@ +#include "osint_debug.h" + +#include "macros.h" + +s32 __osThprofFlag = 0; +void (*__osThprofFunc)(OSThread*) = NULL; + +u32 __osThprofLastTimer; +u32 __osThprofCount; +__OSThreadprofile_s thprof[THPROF_IDMAX] ALIGNED(0x10); +u64 __osThprofHeap[THPROF_STACKSIZE] ALIGNED(0x10); +void* __osThprofStack; + +void osThreadProfileCallback(OSThread* osthread) { + register u32 now_time = osGetCount(); + __OSThreadprofile_s* thprof = osthread->thprof; + + thprof->time += now_time - __osThprofLastTimer; + thprof->count++; + __osThprofCount++; + __osThprofLastTimer = now_time; +} diff --git a/lib/ultralib/src/debug/threadprofileclear.c b/lib/ultralib/src/debug/threadprofileclear.c new file mode 100644 index 0000000..42788f8 --- /dev/null +++ b/lib/ultralib/src/debug/threadprofileclear.c @@ -0,0 +1,11 @@ +#include "osint_debug.h" + +void osThreadProfileClear(OSId id) { + register OSIntMask saveMask = __osDisableInt(); + + thprof[id].flag = 0; + thprof[id].count = 0; + thprof[id].time = 0; + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/debug/threadprofileinit.c b/lib/ultralib/src/debug/threadprofileinit.c new file mode 100644 index 0000000..7fef229 --- /dev/null +++ b/lib/ultralib/src/debug/threadprofileinit.c @@ -0,0 +1,16 @@ +#include "osint_debug.h" + +void osThreadProfileInit(void) { + register u32 saveMask = __osDisableInt(); + OSId i; + + __osThprofFunc = NULL; + __osThprofFlag = 1; + __osThprofCount = 0; + __osThprofStack = &__osThprofHeap[(THPROF_STACKSIZE - 8) / sizeof(*__osThprofHeap)]; + __osRestoreInt(saveMask); + + for (i = 0; i < THPROF_IDMAX; i++) { + osThreadProfileClear(i); + } +} diff --git a/lib/ultralib/src/debug/threadprofilereadcount.c b/lib/ultralib/src/debug/threadprofilereadcount.c new file mode 100644 index 0000000..3237987 --- /dev/null +++ b/lib/ultralib/src/debug/threadprofilereadcount.c @@ -0,0 +1,39 @@ +#include "osint_debug.h" + +u32 osThreadProfileReadCount(OSId id) { +#ifndef NDEBUG + if (!__osThprofFlag) { + __osError(139, 0); + return 0; + } +#endif + + if (id >= THPROF_IDMAX) { +#ifndef NDEBUG + __osError(143, 1, id); +#endif + return 0; + } + return thprof[id].count; +} + +u32 osThreadProfileReadCountTh(OSThread* thread) { + OSId id; + +#ifndef NDEBUG + if (!__osThprofFlag) { + __osError(141, 0); + return 0; + } +#endif + + id = osGetThreadId(thread); + + if (id >= THPROF_IDMAX) { +#ifndef NDEBUG + __osError(145, 1, id); +#endif + return 0; + } + return thprof[id].count; +} diff --git a/lib/ultralib/src/debug/threadprofilereadtime.c b/lib/ultralib/src/debug/threadprofilereadtime.c new file mode 100644 index 0000000..9930cac --- /dev/null +++ b/lib/ultralib/src/debug/threadprofilereadtime.c @@ -0,0 +1,51 @@ +#include "osint_debug.h" + +OSTime osThreadProfileReadTime(OSId id) { + OSTime adjust = 0; + u32 now_time = osGetCount(); + +#ifndef NDEBUG + if (!__osThprofFlag) { + __osError(140, 0); + return 0; + } +#endif + if (id >= THPROF_IDMAX) { +#ifndef NDEBUG + __osError(144, 1, id); +#endif + return 0; + } + + if (id == osGetThreadId(NULL) && __osThprofFunc != NULL) { + adjust = now_time - __osThprofLastTimer; + } + return thprof[id].time + adjust; +} + +OSTime osThreadProfileReadTimeTh(OSThread* thread) { + OSId id; + OSTime adjust = 0; + u32 now_time = osGetCount(); + +#ifndef NDEBUG + if (!__osThprofFlag) { + __osError(142, 0); + return 0; + } +#endif + + id = osGetThreadId(thread); + + if (id >= THPROF_IDMAX) { +#ifndef NDEBUG + __osError(146, 1, id); +#endif + return 0; + } + + if (id == osGetThreadId(NULL) && __osThprofFunc != NULL) { + adjust = now_time - __osThprofLastTimer; + } + return thprof[id].time + adjust; +} diff --git a/lib/ultralib/src/debug/threadprofilestart.c b/lib/ultralib/src/debug/threadprofilestart.c new file mode 100644 index 0000000..3ef8fa7 --- /dev/null +++ b/lib/ultralib/src/debug/threadprofilestart.c @@ -0,0 +1,22 @@ +#include "osint_debug.h" + +void osThreadProfileStart(void) { + register u32 saveMask; + +#ifndef NDEBUG + if (!__osThprofFlag) { + __osError(136, 0); + return; + } + if (__osThprofFunc != NULL) { + __osError(137, 0); + return; + } +#endif + + saveMask = __osDisableInt(); + + __osThprofLastTimer = osGetCount(); + __osThprofFunc = osThreadProfileCallback; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/debug/threadprofilestop.c b/lib/ultralib/src/debug/threadprofilestop.c new file mode 100644 index 0000000..4803620 --- /dev/null +++ b/lib/ultralib/src/debug/threadprofilestop.c @@ -0,0 +1,47 @@ +#include "osint_debug.h" + +void osThreadProfileStop(void) { + register u32 saveMask; + int i; + OSId id; + u32 now_time = osGetCount(); + + saveMask = __osDisableInt(); + +#ifndef NDEBUG + if (__osThprofFlag == 0) { +#if BUILD_VERSION >= VERSION_L + __osRestoreInt(saveMask); + __osError(138, 0); +#else + __osError(138, 0); + __osRestoreInt(saveMask); +#endif + return; + } +#endif + + if (__osThprofFunc != NULL) { + id = osGetThreadId(0); + + if (id < THPROF_IDMAX) { + thprof[id].time += now_time - __osThprofLastTimer; + } else { +#ifndef NDEBUG +#if BUILD_VERSION >= VERSION_L + __osRestoreInt(saveMask); +#endif + __osError(147, 1, id); +#if BUILD_VERSION >= VERSION_L + saveMask = __osDisableInt(); +#endif +#endif + } + } + __osThprofFunc = NULL; + + for (i = 0; i < THPROF_IDMAX; i++) { + thprof[i].flag = 0; + } + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/error/commonerror.c b/lib/ultralib/src/error/commonerror.c new file mode 100644 index 0000000..5a6f1c9 --- /dev/null +++ b/lib/ultralib/src/error/commonerror.c @@ -0,0 +1,193 @@ +#include "PR/os.h" +#include "PR/os_internal.h" +#include "PR/sptask.h" +#include "PR/ultraerror.h" +#include "PR/ultralog.h" +#include "macros.h" +#include "stdarg.h" + +#ifndef _FINALROM + +void __osSyncVPrintf(const char* fmt, va_list args); + +static u32 errorLogData[19] ALIGNED(8); +static OSLog errorLog = { + OS_ERROR_MAGIC, // magic + sizeof(errorLogData), // len + errorLogData, // base + 0, //startCount + 0, //writeOffset +}; + +static void __commonErrorHandler(s16 code, s16 numArgs, ...); +OSErrorHandler __osCommonHandler = __commonErrorHandler; + +char NULSTR[] = { '\0' }; + +const char* __os_error_message[] = { + NULSTR, + "osCreateThread: stack pointer not aligned to 8 bytes (0x%x)", + "osCreateThread: priority not in range [0-255] (%d)", + "osStartThread: thread has bad state (running/runnable/other)", + "osSetThreadPri: priority not in range [0-255] (%d)", + "osCreateMesgQueue: message count not > 0 (%d)", + "osSendMesg: flag not OS_MESG_NOBLOCK or OS_MESG_BLOCK (%d)", + "osJamMesg: flag not OS_MESG_NOBLOCK or OS_MESG_BLOCK (%d)", + "osRecvMesg: flag not OS_MESG_NOBLOCK or OS_MESG_BLOCK (%d)", + "osSetEventMesg: unknown event type (%d)", + "osMapTLB: index not in range [0-30] (%d)", + "osMapTLB: asid argument not -1 or in range [0-255] (%d)", + "osUnmapTLB: index not in range [0-30] (%d)", + "osSetTLBASID: asid not in range [0-255] (%d)", + "osAiSetFrequency: freq not in range [%d-%d] (%d)", + "osAiSetNextBuffer: address not aligned to 8 bytes (0x%x)", + "osAiSetNextBuffer: size not aligned to 8 bytes (0x%x)", + "osDpSetNextBuffer: address not aligned to 8 bytes (0x%x)", + "osDpSetNextBuffer: size not aligned to 8 bytes (0x%x)", + "osPiRawReadIo: address not aligned to 4 bytes (0x%x)", + "osPiRawWriteIo: address not aligned to 4 bytes (0x%x)", + "osPiRawStartDma: direction not OS_READ or OS_WRITE (%d)", + "osPiRawStartDma: device address not aligned to 2 bytes (0x%x)", + "osPiRawStartDma: DRAM address not aligned to 8 bytes (0x%x)", + "osPiRawStartDma: size not aligned to 2 bytes (%d)", + "osPiRawStartDma: size not in range [0,16777216] (%d)", + "osPiReadIo: address not aligned to 4 bytes (0x%x)", + "osPiWriteIo: address not aligned to 4 bytes (0x%x)", + "osPiStartDma: PI Manager not yet begun by osCreatePiManager", + "osPiStartDma: priority not OS_MESG_PRI_[NORMAL|HIGH] (%d)", + "osPiStartDma: direction not OS_READ or OS_WRITE (%d)", + "osPiStartDma: device address not aligned to 2 bytes (0x%x)", + "osPiStartDma: DRAM address not aligned to 8 bytes (0x%x)", + "osPiStartDma: size not aligned to 2 bytes (%d)", + "osPiStartDma: size not in range [0,16777216] (%d)", + "osCreatePiManager: priority not in range [0-255] (%d)", + "osViGetCurrentMode: VI Manager not yet begun", + "osViGetCurrentFramebuffer: VI Manager not yet begun", + "osViGetNextFramebuffer: VI Manager not yet begun", + "osViSetXScale: value not in range [0.25,1.0] (%f)", + "osViSetXScale: VI Manager not yet begun by osCreateViManager", + "osViSetYScale: value not in range [0.05,1.0] (%f)", + "osViSetYScale: VI Manager not yet begun by osCreateViManager", + "osViSetSpecialFeatures: not a known feature value (%d)", + "osViSetSpecialFeatures: VI Manager not yet begun", + "osViSetMode: VI Manager not yet begun by osCreateViManager", + "osViSetEvent: VI Manager not yet begun by osCreateViManager", + "osViSwapBuffer: frame buffer not aligned to 64 bytes (0x%x)", + "osViSwapBuffer: VI Manager not yet begun", + "osCreateViManager: priority not in range [0-255] (%d)", + "osCreateRegion: not a known alignment (%d)", + "osCreateRegion: length (%d) too small for buffer size (%d)", + "osMalloc: invalid or corrupt region (0x%x)", + "osFree: invalid or corrupt region (0x%x)", + "osFree: invalid address (0x%x) or\n corrupt region (0x%x)", + "osGetRegionBufCount: invalid or corrupt region (0x%x)", + "osGetRegionBufSize: invalid or corrupt region (0x%x)", + "osSpTaskLoad: dram_stack not aligned to 16 bytes (0x%x)", + "osSpTaskLoad: output_buff not aligned to 16 bytes (0x%x)", + "osSpTaskLoad: output_buff_size not aligned to 16 bytes (0x%x)", + "osSpTaskLoad: yield_data_ptr not aligned to 16 bytes (0x%x)", + "osProfileInit: profile counter is running, call osProfileStop before init", + "osProfileInit: profcnt is %d", + "osProfileInit: histo_base pointer must be 32-bit aligned (%x)", + "osProfileInit: text_start (%x) >= text_end (%x)", + "osProfileInit: histo_size is an illegal size (%d)", + "osProfileStart: microseconds is < PROF_MIN_INTERVAL (%d)", + "osProfileStart: profiling has already been started", + "osProfileStop: profiling has already been stopped", + "osProfileStop: no profile timer to stop", + "osReadHost: address not aligned to 8 bytes (0x%x)", + "osReadHost: size either 0 or not aligned to 4 bytes (0x%x)", + "osWriteHost: address not aligned to 8 bytes (0x%x)", + "osWriteHost: size either 0 or not aligned to 4 bytes (0x%x)", + "osGetTime: VI manager not yet begun by osCreateViManager", + "osSetTime: VI manager not yet begun by osCreateViManager", + "osSetTimer: VI manager not yet begun by osCreateViManager", + "osStopTimer: VI manager not yet begun by osCreateViManager", + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + NULSTR, + "_handleMIDIMsg: no sound mapped", + "_handleMIDIMsg: no free voices", + "_handleMIDIMsg: couldn't map voice", + "_handleMIDIMsg: note off - couldn't find voice", + "_handleMIDIMsg: poly pressure - couldn't find voice", + "_handleEvent: no free voices", + "Synthesizer: no free updates", + "alSndPDeallocate: attempt to deallocate a sound which is playing", + "alSndpDelete: attempt to delete player with playing sounds", + "alSndpPlay: attempt to play a sound which is playing", + "alSndpSetSound: sound id (%d) out of range (0 - %d)", + "alSndpSetPriority: sound id (%d) out of range (0 - %d)", + "alSndpSet Parameter: target (%d) out of range (0 - %d)", + "alBnkfNew: bank file out of date", + "alSeqNew: 0x%x is not a midi file", + "alSeqNew: 0x%x is not a type 0 midi file", + "alSeqNew: 0x%x has more than 1 track", + "alSeqNew: SMPTE delta times not supported", + "alSeqNew: Error parsing file 0x%x (no track header)", + "alSeqNextEvent: Unsupported system exclusive", + "alSeqNextEvent: Unsupported midi meta event 0x%x", + "_handleMIDIMsg: Invalid program change to %d, max instruments %d", + "_handleMIDIMsg: Unknown midi message 0x%x", + "_unmapVoice: Couldn't unmap voice 0x%x", + "alEvtqPostEvent: Out of free events", + "alHeapAlloc: Can't allocate %d bytes", + "alHeapCheck: Heap corrupt", + "alHeapCheck: Heap corrupt - first block is bad", + "alCSeqGetTrackEvent: Running status of zero on track %d", + "alCSeqGetTrackEvent: Note on velocity of zero on track %d", + "alCSPVoiceHandler: Stopping sequence but voice not free chan %d, key %d", + "alSeqNextEvent: Read past end of sequence", + "osAiSetNextBuffer: DMA buffer location may cause audio clicks (0x%x)", + "_loadOutputBuffer: Modulated delay greater than total delay by %d samples", + "osViExtendVStart: VI Manager not yet begun by osCreateViManager", + "osViExtendVStart: value not in range [0-48] %d", + "osThreadProfileStart: thread profiler is not initialized", + "osThreadProfileStart: profiling has already been started", + "osThreadProfileStop: thread profiler is not initialized", + "osThreadProfileReadCount: thread profiler is not initialized", + "osThreadProfileReadCountTh: thread profiler is not initialized", + "osThreadProfileReadTime: thread profiler is not initialized", + "osThreadProfileReadTimeTh: thread profiler is not initialized", + "osThreadProfileReadCount: thread ID is too large(%d)", + "osThreadProfileReadTime: thread ID is too large(%d)", + "osThreadProfileReadCountTh: thread ID is too large(%d)", + "osThreadProfileReadTimeTh: thread ID is too large(%d)", + "osThreadProfileStop: current thread ID is too large(%d)", + NULSTR, +}; + +void __commonErrorHandler(s16 code, s16 numArgs, ...) { + va_list argPtr; + const char* fmt; + + fmt = __os_error_message[code]; + va_start(argPtr, numArgs); + + osSyncPrintf("0x%08X (%04d):", osGetCount(), code); + __osSyncVPrintf(fmt, argPtr); + osSyncPrintf("\n"); + + va_end(argPtr); +} + +#endif diff --git a/lib/ultralib/src/error/error.c b/lib/ultralib/src/error/error.c new file mode 100644 index 0000000..3f9ae2d --- /dev/null +++ b/lib/ultralib/src/error/error.c @@ -0,0 +1,30 @@ +// This file was removed in 2.0J +#include "stdarg.h" +#include "PR/os_internal.h" +#include "PR/ultralog.h" +#include "PR/ultraerror.h" +#include "macros.h" + +void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr); +static void __osDefaultHandler(s16 code, s16 numArgs, ...); + +static u32 errorLogData[19] ALIGNED(8); +static OSLog errorLog ALIGNED(8) = { + OS_ERROR_MAGIC, // magic + sizeof(errorLogData), // len + errorLogData, // base + 0, //startCount + 0, //writeOffset +}; + +OSErrorHandler __osErrorHandler = __osDefaultHandler; + +static void __osDefaultHandler(s16 code, s16 numArgs, ...) { + va_list argPtr; + va_start(argPtr, numArgs); + + __osLogWrite(&errorLog, code, numArgs, argPtr); + osFlushLog(&errorLog); + + va_end(argPtr); +} diff --git a/lib/ultralib/src/error/errorasm.s b/lib/ultralib/src/error/errorasm.s new file mode 100644 index 0000000..10f3561 --- /dev/null +++ b/lib/ultralib/src/error/errorasm.s @@ -0,0 +1,33 @@ +#include "PR/os_version.h" + +#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J +#include "sys/asm.h" +#include "sys/regdef.h" +#include "PR/os_version.h" + +LEAF(__osError) +#if BUILD_VERSION < VERSION_J + lw t0,__osErrorHandler + beqz t0,1f + jr t0 +#elif BUILD_VERSION < VERSION_K + lw t0,__kmc_pt_mode + bnez t0,_kmc_mode + + lw t0,__osErrorHandler + beqz t0,1f + jr t0 +_kmc_mode: + lw t0,__kmcErrorHandler + beqz t0,1f + jr t0 +#else + lw t0,__osCommonHandler + beqz t0,1f + jr t0 +#endif +1: + j ra +END(__osError) + +#endif diff --git a/lib/ultralib/src/flash/flashallerase.c b/lib/ultralib/src/flash/flashallerase.c new file mode 100644 index 0000000..0e982a5 --- /dev/null +++ b/lib/ultralib/src/flash/flashallerase.c @@ -0,0 +1,33 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + + +s32 osFlashAllErase(void) { + u32 status; + OSTimer mytimer; + OSMesgQueue timerMesgQueue; + OSMesg dummy; + + // start chip erase operation + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_CHIP_ERASE); + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); + + // wait for completion by polling erase-busy flag + osCreateMesgQueue(&timerMesgQueue, &dummy, 1); + do { + osSetTimer(&mytimer, OS_USEC_TO_CYCLES(15000), 0, &timerMesgQueue, &dummy); + osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + } while ((status & FLASH_STATUS_ERASE_BUSY) == FLASH_STATUS_ERASE_BUSY); + + // check erase operation status, clear status + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + osFlashClearStatus(); + + // check for success + if (((status & 0xFF) == 8) || ((status & 0xFF) == 0x48) || ((status & 8) == 8)) { + return FLASH_STATUS_ERASE_OK; + } else { + return FLASH_STATUS_ERASE_ERROR; + } +} diff --git a/lib/ultralib/src/flash/flashallerasethrough.c b/lib/ultralib/src/flash/flashallerasethrough.c new file mode 100644 index 0000000..1c3c1dd --- /dev/null +++ b/lib/ultralib/src/flash/flashallerasethrough.c @@ -0,0 +1,8 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +void osFlashAllEraseThrough(void) { + // start chip erase operation, no waiting for completion + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_CHIP_ERASE); + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); +} diff --git a/lib/ultralib/src/flash/flashchange.c b/lib/ultralib/src/flash/flashchange.c new file mode 100644 index 0000000..d92ff7b --- /dev/null +++ b/lib/ultralib/src/flash/flashchange.c @@ -0,0 +1,8 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +void osFlashChange(u32 flash_num) { + __osFlashHandler.baseAddress = PHYS_TO_K1((FLASH_START_ADDR + flash_num * FLASH_SIZE)); + __osFlashHandler.type = DEVICE_TYPE_FLASH + flash_num; + return; +} diff --git a/lib/ultralib/src/flash/flashcheckeraseend.c b/lib/ultralib/src/flash/flashcheckeraseend.c new file mode 100644 index 0000000..c87876b --- /dev/null +++ b/lib/ultralib/src/flash/flashcheckeraseend.c @@ -0,0 +1,23 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +s32 osFlashCheckEraseEnd(void) { + u8 status; + + osFlashReadStatus(&status); + + if ((status & FLASH_STATUS_ERASE_BUSY) == FLASH_STATUS_ERASE_BUSY) { + return FLASH_STATUS_ERASE_BUSY; + } else { + // not busy, read and clear status + osFlashReadStatus(&status); + } + osFlashClearStatus(); + + // check for success + if (((status & 0xFF) == 8) || ((status & 0xFF) == 0x48) || ((status & 8) == 8)) { + return FLASH_STATUS_ERASE_OK; + } else { + return FLASH_STATUS_ERASE_ERROR; + } +} diff --git a/lib/ultralib/src/flash/flashclearstatus.c b/lib/ultralib/src/flash/flashclearstatus.c new file mode 100644 index 0000000..86165d6 --- /dev/null +++ b/lib/ultralib/src/flash/flashclearstatus.c @@ -0,0 +1,10 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +void osFlashClearStatus(void) { + // select status mode + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_STATUS); + // clear status + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress, 0); + return; +} diff --git a/lib/ultralib/src/flash/flashgetaddr.c b/lib/ultralib/src/flash/flashgetaddr.c new file mode 100644 index 0000000..a530947 --- /dev/null +++ b/lib/ultralib/src/flash/flashgetaddr.c @@ -0,0 +1,15 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +u32 __osFlashGetAddr(u32 page_num) { + u32 devAddr; + + if (__osFlashVersion == OLD_FLASH) { + // Account for hardware bug in old flash where the address bits are shifted 1-off where they should be + devAddr = page_num * (FLASH_BLOCK_SIZE >> 1); + } else { + devAddr = page_num * FLASH_BLOCK_SIZE; + } + + return devAddr; +} diff --git a/lib/ultralib/src/flash/flashinit.c b/lib/ultralib/src/flash/flashinit.c new file mode 100644 index 0000000..33c7dc3 --- /dev/null +++ b/lib/ultralib/src/flash/flashinit.c @@ -0,0 +1,44 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" +#include "macros.h" + +u32 __osFlashID[4] ALIGNED(8); +OSIoMesg __osFlashMsg ALIGNED(8); +OSMesgQueue __osFlashMessageQ ALIGNED(8); +OSPiHandle __osFlashHandler ALIGNED(8); +OSMesg __osFlashMsgBuf[1]; +s32 __osFlashVersion; + +OSPiHandle* osFlashInit(void) { + u32 flash_type; + u32 flash_maker; + + osCreateMesgQueue(&__osFlashMessageQ, __osFlashMsgBuf, ARRLEN(__osFlashMsgBuf)); + + if (__osFlashHandler.baseAddress == PHYS_TO_K1(FLASH_START_ADDR)) { + return &__osFlashHandler; + } + + __osFlashHandler.type = DEVICE_TYPE_FLASH; + __osFlashHandler.baseAddress = PHYS_TO_K1(FLASH_START_ADDR); + __osFlashHandler.latency = FLASH_LATENCY; + __osFlashHandler.pulse = FLASH_PULSE; + __osFlashHandler.pageSize = FLASH_PAGE_SIZE; + __osFlashHandler.relDuration = FLASH_REL_DURATION; + __osFlashHandler.domain = PI_DOMAIN2; + __osFlashHandler.speed = 0; + + bzero(&__osFlashHandler.transferInfo, sizeof(__OSTranxInfo)); + + osEPiLinkHandle(&__osFlashHandler); + osFlashReadId(&flash_type, &flash_maker); + + if (flash_maker == FLASH_VERSION_MX_C || flash_maker == FLASH_VERSION_MX_A || + flash_maker == FLASH_VERSION_MX_PROTO_A) { + __osFlashVersion = OLD_FLASH; + } else { + __osFlashVersion = NEW_FLASH; + } + + return &__osFlashHandler; +} diff --git a/lib/ultralib/src/flash/flashreadarray.c b/lib/ultralib/src/flash/flashreadarray.c new file mode 100644 index 0000000..543f236 --- /dev/null +++ b/lib/ultralib/src/flash/flashreadarray.c @@ -0,0 +1,51 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + + +s32 osFlashReadArray(OSIoMesg* mb, s32 priority, u32 page_num, void* dramAddr, u32 n_pages, OSMesgQueue* mq) { + u32 ret; + u32 tmp; + u32 end_page; + u32 one_dma_pages; + + // select read array mode + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_READ_ARRAY); + // dummy read? + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &tmp); + + // DMA requested pages + mb->hdr.pri = priority; + mb->hdr.retQueue = mq; + mb->dramAddr = dramAddr; + + end_page = page_num + n_pages - 1; + + if ((end_page & 0xF00) != (page_num & 0xF00)) { + one_dma_pages = 256 - (page_num & 0xFF); + n_pages -= one_dma_pages; + mb->size = one_dma_pages * FLASH_BLOCK_SIZE; + mb->devAddr = __osFlashGetAddr(page_num); + osEPiStartDma(&__osFlashHandler, mb, OS_READ); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + page_num = (page_num + 256) & 0xF00; + mb->dramAddr = (u32)mb->dramAddr + mb->size; + } + + while (n_pages > 256) { + one_dma_pages = 256; + n_pages -= 256; + mb->size = one_dma_pages * FLASH_BLOCK_SIZE; + mb->devAddr = __osFlashGetAddr(page_num); + osEPiStartDma(&__osFlashHandler, mb, OS_READ); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + page_num += 256; + mb->dramAddr = (u32)mb->dramAddr + mb->size; + } + + mb->size = n_pages * FLASH_BLOCK_SIZE; + mb->devAddr = __osFlashGetAddr(page_num); + + ret = osEPiStartDma(&__osFlashHandler, mb, OS_READ); + + return ret; +} diff --git a/lib/ultralib/src/flash/flashreadid.c b/lib/ultralib/src/flash/flashreadid.c new file mode 100644 index 0000000..3112d74 --- /dev/null +++ b/lib/ultralib/src/flash/flashreadid.c @@ -0,0 +1,27 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +void osFlashReadId(u32* flash_type, u32* flash_maker) { + u8 tmp; + + // why read status ? + osFlashReadStatus(&tmp); + + // select silicon id read mode + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_ID); + + // read silicon id using DMA + __osFlashMsg.hdr.pri = OS_MESG_PRI_NORMAL; + __osFlashMsg.hdr.retQueue = &__osFlashMessageQ; + __osFlashMsg.dramAddr = __osFlashID; + __osFlashMsg.devAddr = 0; + __osFlashMsg.size = 2 * sizeof(u32); + + osInvalDCache(__osFlashID, sizeof(__osFlashID)); + osEPiStartDma(&__osFlashHandler, &__osFlashMsg, OS_READ); + osRecvMesg(&__osFlashMessageQ, NULL, OS_MESG_BLOCK); + + *flash_type = __osFlashID[0]; + *flash_maker = __osFlashID[1]; + return; +} diff --git a/lib/ultralib/src/flash/flashreadstatus.c b/lib/ultralib/src/flash/flashreadstatus.c new file mode 100644 index 0000000..6ff5560 --- /dev/null +++ b/lib/ultralib/src/flash/flashreadstatus.c @@ -0,0 +1,17 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +void osFlashReadStatus(u8* flash_status) { + u32 status; + + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_STATUS); + // read status + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + + // why twice ? + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_STATUS); + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + + *flash_status = status & 0xFF; + return; +} diff --git a/lib/ultralib/src/flash/flashreinit.c b/lib/ultralib/src/flash/flashreinit.c new file mode 100644 index 0000000..b2ab93d --- /dev/null +++ b/lib/ultralib/src/flash/flashreinit.c @@ -0,0 +1,14 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +OSPiHandle* osFlashReInit(u8 latency, u8 pulse, u8 page_size, u8 rel_duration, u32 start) { + __osFlashHandler.baseAddress = PHYS_TO_K1(start); + __osFlashHandler.type++; + __osFlashHandler.latency = latency; + __osFlashHandler.pulse = pulse; + __osFlashHandler.pageSize = page_size; + __osFlashHandler.relDuration = rel_duration; + __osFlashHandler.domain = PI_DOMAIN2; + + return &__osFlashHandler; +} diff --git a/lib/ultralib/src/flash/flashsectorerase.c b/lib/ultralib/src/flash/flashsectorerase.c new file mode 100644 index 0000000..14a0583 --- /dev/null +++ b/lib/ultralib/src/flash/flashsectorerase.c @@ -0,0 +1,32 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +s32 osFlashSectorErase(u32 page_num) { + u32 status; + OSTimer mytimer; + OSMesgQueue timerMesgQueue; + OSMesg dummy; + + // start sector erase operation + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_SECTOR_ERASE | page_num); + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); + + // wait for completion by polling erase-busy flag + osCreateMesgQueue(&timerMesgQueue, &dummy, 1); + + do { + osSetTimer(&mytimer, OS_USEC_TO_CYCLES(12500), 0, &timerMesgQueue, &dummy); + osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + } while ((status & FLASH_STATUS_ERASE_BUSY) == FLASH_STATUS_ERASE_BUSY); + + // check erase operation status, clear status + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + osFlashClearStatus(); + + if (((status & 0xFF) == 8) || ((status & 0xFF) == 0x48) || ((status & 8) == 8)) { + return FLASH_STATUS_ERASE_OK; + } else { + return FLASH_STATUS_ERASE_ERROR; + } +} diff --git a/lib/ultralib/src/flash/flashsectorerasethrough.c b/lib/ultralib/src/flash/flashsectorerasethrough.c new file mode 100644 index 0000000..474ee96 --- /dev/null +++ b/lib/ultralib/src/flash/flashsectorerasethrough.c @@ -0,0 +1,8 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +void osFlashSectorEraseThrough(u32 page_num) { + // start sector erase operation + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_SECTOR_ERASE | page_num); + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_EXECUTE_ERASE); +} diff --git a/lib/ultralib/src/flash/flashwritearray.c b/lib/ultralib/src/flash/flashwritearray.c new file mode 100644 index 0000000..d5f56a0 --- /dev/null +++ b/lib/ultralib/src/flash/flashwritearray.c @@ -0,0 +1,34 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +s32 osFlashWriteArray(u32 page_num) { + u32 status; + OSTimer mytimer; + OSMesgQueue timerMesgQueue; + OSMesg dummy; + + if ((u32)__osFlashVersion == NEW_FLASH) { + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_PAGE_PROGRAM); + } + + // start program page operation + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_PROGRAM_PAGE | page_num); + + // wait for completion by polling write-busy flag + osCreateMesgQueue(&timerMesgQueue, &dummy, 1); + do { + osSetTimer(&mytimer, OS_USEC_TO_CYCLES(200), 0, &timerMesgQueue, &dummy); + osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + } while ((status & FLASH_STATUS_WRITE_BUSY) == FLASH_STATUS_WRITE_BUSY); + + // check program operation status, clear status + osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status); + osFlashClearStatus(); + + if (((status & 0xFF) == 4) || ((status & 0xFF) == 0x44) || ((status & 4) == 4)) { + return FLASH_STATUS_WRITE_OK; + } else { + return FLASH_STATUS_WRITE_ERROR; + } +} diff --git a/lib/ultralib/src/flash/flashwritebuffer.c b/lib/ultralib/src/flash/flashwritebuffer.c new file mode 100644 index 0000000..ad3f790 --- /dev/null +++ b/lib/ultralib/src/flash/flashwritebuffer.c @@ -0,0 +1,20 @@ +#include "ultra64.h" +#include "PR/os_internal_flash.h" + +s32 osFlashWriteBuffer(OSIoMesg* mb, s32 priority, void* dramAddr, OSMesgQueue* mq) { + s32 ret; + + // select page program mode + osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FLASH_CMD_REG, FLASH_CMD_PAGE_PROGRAM); + + // DMA 128-byte page + mb->hdr.pri = priority; + mb->hdr.retQueue = mq; + mb->dramAddr = dramAddr; + mb->devAddr = 0; + mb->size = FLASH_BLOCK_SIZE; + + ret = osEPiStartDma(&__osFlashHandler, mb, OS_WRITE); + + return ret; +} diff --git a/lib/ultralib/src/gio/giointerrupt.c b/lib/ultralib/src/gio/giointerrupt.c new file mode 100644 index 0000000..3abc04f --- /dev/null +++ b/lib/ultralib/src/gio/giointerrupt.c @@ -0,0 +1,8 @@ +#include "PR/os_internal.h" +#include "../io/piint.h" + +void __osGIOInterrupt(s32 value) { + __osPiGetAccess(); + __osGIORawInterrupt(value); + __osPiRelAccess(); +} diff --git a/lib/ultralib/src/gio/giorawinterrupt.c b/lib/ultralib/src/gio/giorawinterrupt.c new file mode 100644 index 0000000..2fdc909 --- /dev/null +++ b/lib/ultralib/src/gio/giorawinterrupt.c @@ -0,0 +1,13 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "../io/piint.h" + +void __osGIORawInterrupt(s32 value) { + register u32 stat; + + WAIT_ON_IOBUSY(stat); + + IO_WRITE(GIO_GIO_INTR_REG, value); + + WAIT_ON_IOBUSY(stat); +} diff --git a/lib/ultralib/src/gt/Makefile b/lib/ultralib/src/gt/Makefile new file mode 100644 index 0000000..b0868fd --- /dev/null +++ b/lib/ultralib/src/gt/Makefile @@ -0,0 +1,19 @@ +#!smake +# +# Makefile for the gt subdirectory +# + +include $(ROOT)/usr/include/make/PRdefs + + +# LCOPTS = -mips2 -non_shared -fullwarn -G 0 + +LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include + +CFILES = dumpturbo.c gt.c + +OBJECTS = $(CFILES:.c=.o) + +default: $(OBJECTS) + +include $(COMMONRULES) diff --git a/lib/ultralib/src/gt/dumpturbo.c b/lib/ultralib/src/gt/dumpturbo.c new file mode 100644 index 0000000..02c0e63 --- /dev/null +++ b/lib/ultralib/src/gt/dumpturbo.c @@ -0,0 +1,260 @@ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + *************************************************************************/ + +/* + * Interpret & dump a turbo display list for RSPSIM debugging + * + */ + +#include +#include +#include "macros.h" + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 1.4 $" +#endif + +#undef PRINTF +#define PRINTF rmonPrintf + + +#define TX_MAX 100 +static u32 textures[TX_MAX] ALIGNED(8); +static u32 numtextures; + +#define UNSEG_ADDR(sa) ((u32 *) (((globp)? \ + (((int)(sa) & 0x00ffffff) + \ + globp->sp.segBases[(int)(sa)>>24]) \ + : (int)(sa)) | 0x80000000)) +#define PHYS(a) ((int) ((int)(a) & 0x7fffffff)) +#define UNPHYS(a) ((u32 *) ((int)(a) | 0x80000000)) + +#define DOPRINT(a,r) \ +rmonPrintf("UNSEG: %x ->(seg%x = %06x)-> %08x\n",(int)(a),(int)(a)>>24,((globp)?(globp->sp.segBases[(int)(a)>>24]):0), (int)(r)) + + + +#define UCODE_SIZE_MAX (4096*1) +void +gtDumpTurbo(OSTask *tp,u8 flags) +{ + int i; + gtGfx *gtlistp; + gtGlobState *globp=0; + gtState *statep; + u32 dat,*datp,*addr; + + + PRINTF("\nGBI_DUMP_START:\n"); + PRINTF("$ %08x\n",PHYS(tp)); + + for (i=(int)tp; i<(int)tp+sizeof(OSTask); i+=4) { + PRINTF("<%08x\n",(int) *((u32 *) i)); + } + +#if 1 + PRINTF("? %08x\n",PHYS(tp->t.ucode_boot)); + for (i=(int)tp->t.ucode_boot; + i<(int)tp->t.ucode_boot+tp->t.ucode_boot_size; i+=4) { + PRINTF("|%08x\n",(int) *((u32 *) i)); + } + + PRINTF("? %08x\n",PHYS(tp->t.ucode)); + for (i=(int)tp->t.ucode; i<(int)tp->t.ucode+UCODE_SIZE_MAX; i+=4) { + PRINTF("|%08x\n",(int) *((u32 *) i)); + } + + PRINTF("? %08x\n",PHYS(tp->t.ucode_data)); + for (i=(int)tp->t.ucode_data; + i<(int)tp->t.ucode_data+tp->t.ucode_data_size; i+=4) { + PRINTF("|%08x\n",(int) *((u32 *) i)); + } + +#endif + + + + gtlistp = (gtGfx *) tp->t.data_ptr; + PRINTF("@ %08x\n",PHYS(gtlistp)); + +/* + * Dump turbo display list + */ + while (gtlistp->obj.statep) { + PRINTF(">%08x\n",(int) gtlistp->obj.gstatep); + PRINTF("-%08x\n",(int) gtlistp->obj.statep); + PRINTF("-%08x\n",(int) gtlistp->obj.vtxp); + PRINTF("-%08x\n",(int) gtlistp->obj.trip); + gtlistp++; + } + PRINTF(">%08x\n",(int) gtlistp->obj.gstatep); + PRINTF("-%08x\n",(int) gtlistp->obj.statep); + PRINTF("-%08x\n",(int) gtlistp->obj.vtxp); + PRINTF("-%08x\n",(int) gtlistp->obj.trip); + +/* + * Dump infor pointed to by DL + */ + gtlistp = (gtGfx *) tp->t.data_ptr; + while (gtlistp->obj.statep) { +/*rmonPrintf("=============== DUMP A DL ENTRY (%x)\n",(int)gtlistp);*/ + +/* + * Dump global state + */ + if (gtlistp->obj.gstatep) { + addr = UNSEG_ADDR(gtlistp->obj.gstatep); + globp = (gtGlobState *) addr; +/*rmonPrintf("======= DUMP GlobalState (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = addr; + (u8 *) datp < (u8 *) addr + sizeof(gtGlobState); + datp++) { + PRINTF("+%08x\n",*datp); + } + if (globp->sp.rdpCmds) { + addr = UNSEG_ADDR(globp->sp.rdpCmds); +/*rmonPrintf("GlobalState RDP cmds (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = addr; + *datp || *(datp+1); + datp+=2) { + PRINTF("+%08x\n",*datp); + PRINTF("+%08x\n",*(datp+1)); + } + PRINTF("+%08x\n",*datp); + PRINTF("+%08x\n",*(datp+1)); + } + } + +/* + * Dump state + */ + addr = UNSEG_ADDR(gtlistp->obj.statep); + statep = (gtState *) addr; +/*rmonPrintf("======= DUMP State (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = addr; + (u8 *) datp < (u8 *) addr + sizeof(gtState); + datp++) { + PRINTF("+%08x\n",*datp); + } + if (statep->sp.rdpCmds) { + addr = UNSEG_ADDR(statep->sp.rdpCmds); +/*rmonPrintf("DUMP State RDP cmds (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = addr; + *datp || *(datp+1); + datp+=2) { + PRINTF("+%08x\n",*datp); + PRINTF("+%08x\n",*(datp+1)); + } + PRINTF("+%08x\n",*datp); + PRINTF("+%08x\n",*(datp+1)); + } + +/* + * Dump vertices + */ + if (gtlistp->obj.vtxp) { + addr = UNSEG_ADDR(gtlistp->obj.vtxp); +/*rmonPrintf("======= DUMP VTX (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = (u32 *) addr; + (u8 *) datp < (u8 *) addr + + (statep->sp.vtxCount * sizeof(Vtx)); + datp++) { + PRINTF("+%08x\n",*datp); + } + } + +/* + * Dump triangles + */ + if (gtlistp->obj.trip) { + addr = UNSEG_ADDR(gtlistp->obj.trip); +/*rmonPrintf("======= DUMP TRI (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = (u32 *) addr; + (u8 *) datp < (u8 *) addr + + (statep->sp.triCount * sizeof(gtTriN)); + datp++) { + PRINTF("+%08x\n",*datp); + } + } + + + + gtlistp++; + } + + +/* + * Dump Last global state + */ + if (gtlistp->obj.gstatep) { + addr = UNSEG_ADDR(gtlistp->obj.gstatep); + globp = (gtGlobState *) addr; +/*rmonPrintf("======= DUMP GlobalState (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = addr; + (u8 *) datp < (u8 *) addr + sizeof(gtGlobState); + datp++) { + PRINTF("+%08x\n",*datp); + } + if (globp->sp.rdpCmds) { + addr = UNSEG_ADDR(globp->sp.rdpCmds); +/*rmonPrintf("GlobalState RDP cmds (%x)\n",(int)addr);*/ + PRINTF("& %08x\n",PHYS(addr)); + for (datp = addr; + *datp || *(datp+1); + datp+=2) { + PRINTF("+%08x\n",*datp); + PRINTF("+%08x\n",*(datp+1)); + } + PRINTF("+%08x\n",*datp); + PRINTF("+%08x\n",*(datp+1)); + } + } + + PRINTF("^\nGBI_DUMP_END:\n"); + + + if (flags & GT_DUMPTURBO_HANGAFTER) { + for (i=0; i<1000;i++) + rmonPrintf("=======================================\n"); + while(1); + } + + +/* + * Dumps stuff + * each line is either an address for data to follow or data itself + * 1st char on line indicates what it is: + * + * $ task header address + * @ display list address + * & dma data address + * % texture address + * ? code/code data address + * + * < task header data + * > 1st half of display list command + * - 2nd half of display list command + * + dma data + * * texture data + * | code/code data + * + */ + +} diff --git a/lib/ultralib/src/gt/gt.c b/lib/ultralib/src/gt/gt.c new file mode 100644 index 0000000..bf99e85 --- /dev/null +++ b/lib/ultralib/src/gt/gt.c @@ -0,0 +1,155 @@ + +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: gt.c + * Creator: hsa@sgi.com + * Create Date: Fri Oct 13 14:23:48 PDT 1995 + * + */ + + +#include "gtint.h" + + +/* + * Set the cached RDP othermode word in the gt state structure. + */ +void +gtStateSetOthermode(Gfx *om, gtStateOthermode_t mode, int data) +{ + int shift, length; + u32 mask; + + if (mode == GT_CLEAR) { /* special case */ + om->words.w0 = (G_RDPSETOTHERMODE << 24); + om->words.w1 = 0x0; + } + + if (mode <= GT_RENDERMODE) { + /* these are OTHERMODE_L */ + switch (mode) { + + case GT_ALPHACOMPARE: + shift = G_MDSFT_ALPHACOMPARE; + length = 2; + break; + + case GT_ZSRCSEL: + shift = G_MDSFT_ZSRCSEL; + length = 1; + break; + + case GT_RENDERMODE: + shift = G_MDSFT_RENDERMODE; + length = 29; + break; + + default: + break; + } + + mask = (0x01 << length); + mask = mask - 1; + mask = (mask << shift); + mask = mask ^ 0xffffffff; + om->words.w1 &= mask; + om->words.w1 |= data; + + } else { + /* these are OTHERMODE_H */ + switch (mode) { + case GT_ALPHADITHER: + shift = G_MDSFT_ALPHADITHER; + length = 2; + break; + + case GT_RGBDITHER: + shift = G_MDSFT_RGBDITHER; + length = 2; + break; + + case GT_COMBKEY: + shift = G_MDSFT_COMBKEY; + length = 1; + break; + + case GT_TEXTCONV: + shift = G_MDSFT_TEXTCONV; + length = 3; + break; + + case GT_TEXTFILT: + shift = G_MDSFT_TEXTFILT; + length = 2; + break; + + case GT_TEXTLUT: + shift = G_MDSFT_TEXTLUT; + length = 2; + break; + + case GT_TEXTLOD: + shift = G_MDSFT_TEXTLOD; + length = 1; + break; + + case GT_TEXTDETAIL: + shift = G_MDSFT_TEXTDETAIL; + length = 2; + break; + + case GT_TEXTPERSP: + shift = G_MDSFT_TEXTPERSP; + length = 1; + break; + + case GT_CYCLETYPE: + shift = G_MDSFT_CYCLETYPE; + length = 2; + break; + + case GT_PIPELINE: + shift = G_MDSFT_PIPELINE; + length = 1; + break; + + default: + break; + } + + mask = (0x01 << length); + mask = mask - 1; + mask = (mask << shift); + mask = mask ^ 0xffffffff; + om->words.w0 &= mask; + om->words.w0 |= data; + } + + /* force cached othermode word to have proper command id: */ + om->words.w0 &= 0x00ffffff; + om->words.w0 |= (G_RDPSETOTHERMODE << 24); +} + diff --git a/lib/ultralib/src/gt/gtint.h b/lib/ultralib/src/gt/gtint.h new file mode 100644 index 0000000..31ddd7c --- /dev/null +++ b/lib/ultralib/src/gt/gtint.h @@ -0,0 +1,36 @@ + +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: gtint.h + * Creator: hsa@sgi.com + * Create Date: Fri Oct 13 14:24:36 PDT 1995 + * + */ + +#include "mbi.h" +#include "gu.h" +#include "gt.h" + diff --git a/lib/ultralib/src/gu/Makefile b/lib/ultralib/src/gu/Makefile new file mode 100644 index 0000000..ad6e2fa --- /dev/null +++ b/lib/ultralib/src/gu/Makefile @@ -0,0 +1,52 @@ +#!smake +# +# Makefile for the gu subdirectory +# + +include $(ROOT)/usr/include/make/PRdefs + + +# LCOPTS = -mips2 -non_shared -fullwarn -G 0 +LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include +LCOPTS = -G 0 -g -O + +CFILES = \ + align.c \ + cosf.c \ + coss.c \ + frustum.c \ + guloadtile_bug.c \ + loadtextureblockmipmap.c\ + lookat.c \ + lookathil.c \ + lookatref.c \ + lookatstereo.c \ + mtxcatf.c \ + mtxcatl.c \ + mtxutil.c \ + normalize.c \ + ortho.c \ + perspective.c \ + position.c \ + poslight.c \ + poslighthil.c \ + random.c \ + rotate.c \ + rotaterpy.c \ + scale.c \ + sinf.c \ + sins.c \ + translate.c \ + us2dex.c \ + us2dex_emu.c \ + us2dex2_emu.c \ + usprite.c + +ASFILES = \ + libm_vals.s \ + sqrtf.s +OBJECTS = $(CFILES:.c=.o) + +default: $(OBJECTS) + +include $(COMMONRULES) diff --git a/lib/ultralib/src/gu/align.c b/lib/ultralib/src/gu/align.c new file mode 100644 index 0000000..9be7b4a --- /dev/null +++ b/lib/ultralib/src/gu/align.c @@ -0,0 +1,75 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* + * S = sin (a) + * C = cos (a) + * H = sqrt (X*X + Z*Z) + * + * [ v ] [ C S ] [ 1 ] [ -Z/H X/H ] + * [ -S C ] [ H Y ] [ 1 ] + * [ 1 ] [ -Y H ] [ -X/H -Z/H ] + * [ 1 ] [ 1 ] [ 1 ] + * + */ + +void guAlignF(float mf[4][4], float a, float x, float y, float z) +{ + static float dtor = 3.1415926 / 180.0; + float s, c, h, hinv; + + guNormalize(&x, &y, &z); + + a *= dtor; + s = sinf (a); + c = cosf (a); + h = sqrtf (x*x + z*z); + + guMtxIdentF(mf); + + if (h != 0) { + hinv = 1 / h; + + mf[0][0] = (-z*c - s*y*x) * hinv; + mf[1][0] = (z*s - c*y*x) * hinv; + mf[2][0] = -x; + mf[3][0] = 0; + + mf[0][1] = s*h; + mf[1][1] = c*h; + mf[2][1] = -y; + mf[3][1] = 0; + + mf[0][2] = (c*x - s*y*z) * hinv; + mf[1][2] = (-s*x - c*y*z) * hinv; + mf[2][2] = -z; + mf[3][2] = 0; + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; + } else { + /* XXX: should do this right */ + } +} + +void guAlign(Mtx *m, float a, float x, float y, float z) +{ + Matrix mf; + + guAlignF(mf, a, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/cosf.c b/lib/ultralib/src/gu/cosf.c new file mode 100644 index 0000000..5a66c1b --- /dev/null +++ b/lib/ultralib/src/gu/cosf.c @@ -0,0 +1,137 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* ==================================================================== + * ==================================================================== + * + * Module: fcos.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:10:53 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/cosf.c,v $ + * + * Revision history: + * 09-Jun-93 - Original Version + * + * Description: source code for fcos function + * + * ==================================================================== + * ==================================================================== + */ + +#pragma weak fcos = __cosf +#pragma weak cosf = __cosf +#define fcos __cosf + +/* coefficients for polynomial approximation of cos on +/- pi/2 */ + +static const du P[] = +{ +{0x3ff00000, 0x00000000}, +{0xbfc55554, 0xbc83656d}, +{0x3f8110ed, 0x3804c2a0}, +{0xbf29f6ff, 0xeea56814}, +{0x3ec5dbdf, 0x0e314bfe}, +}; + +static const du rpi = +{0x3fd45f30, 0x6dc9c883}; + +static const du pihi = +{0x400921fb, 0x50000000}; + +static const du pilo = +{0x3e6110b4, 0x611a6263}; + +static const fu zero = {0x00000000}; + + +/* ==================================================================== + * + * FunctionName fcos + * + * Description computes cosine of arg + * + * ==================================================================== + */ + +float +fcos( float x ) +{ +float absx; +double dx, xsq, poly; +double dn; +int n; +double result; +int ix, xpt; + + + ix = *(int *)&x; + xpt = (ix >> 22); + xpt &= 0x1ff; + + /* xpt is exponent(x) + 1 bit of mantissa */ + + + if ( xpt < 0x136 ) + { + /* |x| < 2^28 */ + + /* use the standard algorithm from Cody and Waite, doing + the computations in double precision + */ + + absx = ABS(x); + + dx = absx; + + dn = dx*rpi.d + 0.5; + n = ROUND(dn); + dn = n; + + dn -= 0.5; + + dx = dx - dn*pihi.d; + dx = dx - dn*pilo.d; /* dx = x - (n - 0.5)*pi */ + + xsq = dx*dx; + + poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; + + result = dx + (dx*xsq)*poly; + + /* negate result if n is odd */ + + if ( (n & 1) == 0 ) + return ( (float)result ); + + return ( -(float)result ); + } + + if ( x != x ) + { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return ( __libm_qnan_f ); + } + + /* just give up and return 0.0 */ + + return ( zero.f ); +} diff --git a/lib/ultralib/src/gu/coss.c b/lib/ultralib/src/gu/coss.c new file mode 100644 index 0000000..0d95530 --- /dev/null +++ b/lib/ultralib/src/gu/coss.c @@ -0,0 +1,45 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* ==================================================================== + * ==================================================================== + * + * Module: coss.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:11:01 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/coss.c,v $ + * + * ==================================================================== + * ==================================================================== + */ + +/* coefficients for polynomial approximation of sin on +/- pi/2 */ + +/* ==================================================================== + * + * FunctionName coss + * + * Description computes cosine of arg + * + * ==================================================================== + */ + +signed short +coss( unsigned short x ) +{ + /* 0 <= x < 0x10000 ==> 0 <= x < 2PI */ + + return sins ((unsigned short) (x + 0x4000)); +} diff --git a/lib/ultralib/src/gu/dump_gbi.c b/lib/ultralib/src/gu/dump_gbi.c new file mode 100644 index 0000000..a5e5e12 --- /dev/null +++ b/lib/ultralib/src/gu/dump_gbi.c @@ -0,0 +1,274 @@ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + *************************************************************************/ + +/* + * Interpret Task with GBI display list and dump it for debugging. + */ + + +/************************************************** + * + * guDumpGbiDL no longer supported + * applications should use guParseGbiDL with the + * GU_PARSEGBI_DUMPONLY flag set. + * + **************************************************/ + + +#if 0 + + +#include "ultra64.h" +#include "bstring.h" + +#undef PRINTF +#define PRINTF osSyncPrintf + +#define DL_STACKSIZE 11 +static u32 *Gp[DL_STACKSIZE]; + +#define TX_MAX 100 +static u32 textures[TX_MAX]; +static u32 numtextures; + +static u32 segment_base[16]; +static u32 dotextures = TRUE; +static int dl_depth = 0; + + +/* + * dump a DMA-type display list command. + */ +static void +dump_dma(u32 *bufp) +{ + u32 addr, + *data; + u8 seg_id; + u16 len; + char op, + b0; + + op = ((*bufp & 0xff000000) >> 24); + + /* + * DMA op addressing is all the same: + */ + seg_id = (u8) ((bufp[1] & 0x0f000000) >> 24); + addr = segment_base[seg_id] + (bufp[1] & 0x00ffffff); + + + addr = (u32) osPhysicalToVirtual(addr); + + len = (u16) (bufp[0] & 0x0000ffff); + + PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); + if (op == (char) G_DL) { + b0 = (char) ((bufp[0] & 0x00ff0000) >> 16); + ++dl_depth; + if (dl_depth > (DL_STACKSIZE - 1)) { + PRINTF("***** Error, max levels of display lists exceeded\n"); + return; + } + Gp[dl_depth] = (u32 *) addr; + PRINTF("@ %08x\n",(int)Gp[dl_depth]&0x7fffffff); + } else { + PRINTF("& %08x\n", (int)addr&0x7fffffff); + data = (u32 *) addr; + while(len>0) { + PRINTF("+%08x\n", *data); + data++; + len -= 4; + } + PRINTF("@ %08x\n",(int)(Gp[dl_depth] + (sizeof(Gfx) >> 2))&0x7fffffff); + } +} + +/* + * dump a IMM-type display list command. + */ +static void +dump_imm(u32 *bufp) +{ + char op, + b0; + + op = ((*bufp & 0xff000000) >> 24); + + PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); + if (op == (char) G_ENDDL) { + dl_depth--; + if (dl_depth >= 0) { + PRINTF("@ %08x\n",(int)(Gp[dl_depth] + (sizeof(Gfx) >> 2))&0x7fffffff); + } + } + if (op == (char) G_MOVEWORD) { + if (((bufp[0] ) & 0xff) == G_MW_SEGMENT) { + b0 = (char) ((bufp[0] & 0xff00)>>10); + segment_base[b0] = bufp[1] & 0x00ffffff; + } + } +} + +/* + * dump a RDP-type display list command. + */ +static void +dump_rdp(u32 *bufp) +{ + u8 seg_id; + u32 addr; + int i0, + i1; + char op; + + op = ((*bufp & 0xff000000) >> 24); + + PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); + if (op == (char) G_SETTIMG && dotextures) { + if (numtextures>=TX_MAX) { + PRINTF("GBI DUMP ERROR: too many textures (max=%d)\n",TX_MAX); + return; + } + seg_id = (u8) ((bufp[1] & 0x0f000000) >> 24); + addr = segment_base[seg_id] + (bufp[1] & 0x00ffffff); + addr = (u32) osPhysicalToVirtual(addr); + i1=1; + for (i0=0;i0= 0) && (dl_depth < (DL_STACKSIZE - 1))) { + + op = (u8) ((*Gp[dl_depth] & 0xff000000) >> 24); + bcopy((char *) Gp[dl_depth], (char *) &(readBuf[0]), sizeof(Gfx)); + + switch (op & 0xc0) { + + case (u8) 0x00: + dump_dma(readBuf); + break; + + case (u8) 0x80: + dump_imm(readBuf); + break; + + case (u8) 0xc0: + dump_rdp(readBuf); + break; + + default: + PRINTF("ERROR : display list is lost, op = %02x\n", op); + break; + + } + + if (op != (u8) G_DL) { + Gp[dl_depth] += (sizeof(Gfx) >> 2); + } + } + if (dotextures) { + u32 i,j; + for (i=0; it.ucode_boot & 0x7fffffff); + for (i=(int)tp->t.ucode_boot; i<(int)tp->t.ucode_boot+tp->t.ucode_boot_size; i+=4) { + PRINTF("|%08x\n",(int) *((u32 *) i)); + } + + PRINTF("? %08x\n",(int) tp->t.ucode& 0x7fffffff); + for (i=(int)tp->t.ucode; i<(int)tp->t.ucode+UCODE_SIZE_MAX; i+=4) { + PRINTF("|%08x\n",(int) *((u32 *) i)); + } + + PRINTF("? %08x\n",(int) tp->t.ucode_data & 0x7fffffff); + for (i=(int)tp->t.ucode_data; i<(int)tp->t.ucode_data+tp->t.ucode_data_size; i+=4) { + PRINTF("|%08x\n",(int) *((u32 *) i)); + } + + + guDumpGbi((u32 *) tp->t.data_ptr); + + + PRINTF("^\nGBI_DUMP_END:\n"); + + if (flags & GU_PARSEGBI_HANGAFTER) { + int i; + for (i=0; i<1000;i++) + PRINTF("=============================================================\n"); + while(1); + } + + +/* + * Dumps stuff + * each line is either an address for data to follow or data itself + * 1st char on line indicates what it is: + * + * $ task header address + * @ display list address + * & dma data address + * % texture address + * ? code/code data address + * + * < task header data + * > 1st half of display list command + * - 2nd half of display list command + * + dma data + * * texture data + * | code/code data + * + */ + +} + +#endif diff --git a/lib/ultralib/src/gu/frustum.c b/lib/ultralib/src/gu/frustum.c new file mode 100644 index 0000000..4af9c5d --- /dev/null +++ b/lib/ultralib/src/gu/frustum.c @@ -0,0 +1,42 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guFrustumF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale) +{ + int i, j; + + guMtxIdentF(mf); + + mf[0][0] = 2*n/(r-l); + mf[1][1] = 2*n/(t-b); + mf[2][0] = (r+l)/(r-l); + mf[2][1] = (t+b)/(t-b); + mf[2][2] = -(f+n)/(f-n); + mf[2][3] = -1; + mf[3][2] = -2*f*n/(f-n); + mf[3][3] = 0; + + for (i=0; i<4; i++) + for (j=0; j<4; j++) + mf[i][j] *= scale; +} + +void guFrustum(Mtx *m, float l, float r, float b, float t, float n, float f, float scale) +{ + Matrix mf; + + guFrustumF(mf, l, r, b, t, n, f, scale); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/guint.h b/lib/ultralib/src/gu/guint.h new file mode 100644 index 0000000..c3206dd --- /dev/null +++ b/lib/ultralib/src/gu/guint.h @@ -0,0 +1,42 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "mbi.h" +#include "gu.h" + +typedef union +{ + struct + { + unsigned int hi; + unsigned int lo; + } word; + + double d; +} du; + +typedef union +{ + unsigned int i; + float f; +} fu; + +#ifndef __GL_GL_H__ + +typedef float Matrix[4][4]; + +#endif + +#define ROUND(d) (int)(((d) >= 0.0) ? ((d) + 0.5) : ((d) - 0.5)) +#define ABS(d) ((d) > 0) ? (d) : -(d) + +extern float __libm_qnan_f; diff --git a/lib/ultralib/src/gu/guloadtile_bug.c b/lib/ultralib/src/gu/guloadtile_bug.c new file mode 100644 index 0000000..e16e250 --- /dev/null +++ b/lib/ultralib/src/gu/guloadtile_bug.c @@ -0,0 +1,235 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "ultra64.h" + +/* + * Inidicates how many words will be added to display list + * by guDPLoadTextureTile function. + */ +int +guGetDPLoadTextureTileSz(int ult, int lrt) +{ + return (((lrt - ult + 1) / 2) * 4 + 3); +} + +/* + * Workaround for load_tile bug on tapeout one hardware. Uses + * load blocks for each line. ~25% more dma traffic + memory for + * extra commands. + */ +void +guDPLoadTextureTile(Gfx * temp, void *timg, + int texl_fmt, int texl_size, + int img_width, int img_height, + int uls, int ult, int lrs, int lrt, + int palette, + int cms, int cmt, + int masks, int maskt, + int shifts, int shiftt) +{ + int line; + int tile_width, + tile_height; /* + + * in texels + */ + int dxt; + int sizeb; + int lineb; + int line_size; /* + + * in 64-bit words + */ + int texel_num_pad; /* + + * in texels, pad to 64-bit word size + */ + int count; + int tmem; + int tile; + int s, + t; + + tile_width = lrs - uls + 1; + tile_height = lrt - ult + 1; + + switch (texl_size) { + case G_IM_SIZ_8b: + sizeb = G_IM_SIZ_8b_BYTES; + lineb = G_IM_SIZ_8b_LINE_BYTES; + break; + case G_IM_SIZ_16b: + sizeb = G_IM_SIZ_16b_BYTES; + lineb = G_IM_SIZ_16b_LINE_BYTES; + break; + case G_IM_SIZ_32b: + sizeb = G_IM_SIZ_32b_BYTES; + lineb = G_IM_SIZ_32b_LINE_BYTES; + break; + } + + dxt = CALC_DXT(tile_width, sizeb); + line_size = ((tile_width * lineb) + 7) >> 3; + /* + * pad line to word boundary + */ + texel_num_pad = ((((tile_width * sizeb) + 7) >> 3) * 8) / sizeb; + + gDPSetTextureImage(temp++, texl_fmt, texl_size, img_width, timg); + + for (line = 0; line < tile_height; line += 2) { + t = (ult + line) & ~1; /* + * load from even line + */ + tmem = line * line_size; + + /* + * set for both loads, avoid sync by alternating tiles + */ + tile = (line % 4) ? 1 : 0; + + gDPSetTile(temp++, texl_fmt, texl_size, 0, tmem, G_TX_LOADTILE - tile, 0, + cmt, maskt, shiftt, + cms, masks, shifts); + + /* + * do odd line first + */ + s = uls + img_width - texel_num_pad; + count = (texel_num_pad * 2) - 1; + + gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); + + /* + * do even line + */ + s = uls; + count = tile_width - 1; + + gDPLoadSync(temp++); + gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); + + } + + /* + * set final tile + */ + gDPSetTile(temp++, texl_fmt, texl_size, line_size, 0, G_TX_RENDERTILE, 0, + cmt, maskt, shiftt, + cms, masks, shifts); + + gDPSetTileSize(temp++, G_TX_RENDERTILE, + (uls) << G_TEXTURE_IMAGE_FRAC, + (ult) << G_TEXTURE_IMAGE_FRAC, + (lrs) << G_TEXTURE_IMAGE_FRAC, + (lrt) << G_TEXTURE_IMAGE_FRAC); +} + +/* + * 4-BIT VERSION + */ + +/* + * Inidicates how many words will be added to display list + * by guDPLoadTextureTile function. + */ +int +guGetDPLoadTextureTile_4bSz(int ult, int lrt) +{ + return (((lrt - ult + 1) / 2) * 4 + 3); +} + +/* + * Workaround for load_tile bug on version 1.0 hardware. Uses + * load blocks for each line. ~25% more dma traffic + memory for + * extra commands. + */ +void +guDPLoadTextureTile_4b(Gfx * temp, void *timg, + int texl_fmt, + int img_width, int img_height, + int uls, int ult, int lrs, int lrt, + int palette, + int cms, int cmt, + int masks, int maskt, + int shifts, int shiftt) +{ + int line; + int tile_width, + tile_height; + int dxt; + int sizeb; + int lineb; + int line_size; + int count; + int tmem; + int tile; + int s, + t; + + tile_width = (lrs - uls + 1) >> 1; + tile_height = lrt - ult + 1; + sizeb = G_IM_SIZ_8b_BYTES; + lineb = G_IM_SIZ_8b_LINE_BYTES; + line_size = ((tile_width * lineb) + 7) >> 3; + dxt = CALC_DXT_4b(tile_width); + + gDPSetTextureImage(temp++, texl_fmt, G_IM_SIZ_8b, ((img_width) >> 1), timg); + + for (line = 0; line < tile_height; line += 2) { + t = (ult + line) & ~1; /* + * load from even line + */ + tmem = line * line_size; + + /* + * set for both loads, avoid sync by alternating tiles + */ + tile = (line % 4) ? 1 : 0; + + gDPSetTile(temp++, texl_fmt, G_IM_SIZ_8b, 0, tmem, G_TX_LOADTILE - tile, 0, + cmt, maskt, shiftt, + cms, masks, shifts); + + /* + * do odd line first + */ + s = uls + img_width - line_size * 8; + count = (line_size * 8 * 2) - 1; + + gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); + + /* + * do even line + */ + s = uls; + count = tile_width - 1; + + gDPLoadSync(temp++); + gDPLoadBlock(temp++, G_TX_LOADTILE - tile, s, t, s + count, dxt); + + } + + /* + * set final tile + */ + gDPSetTile(temp++, texl_fmt, G_IM_SIZ_4b, line_size, 0, G_TX_RENDERTILE, 0, + cmt, maskt, shiftt, + cms, masks, shifts); + + gDPSetTileSize(temp++, G_TX_RENDERTILE, + (uls) << G_TEXTURE_IMAGE_FRAC, + (ult) << G_TEXTURE_IMAGE_FRAC, + (lrs) << G_TEXTURE_IMAGE_FRAC, + (lrt) << G_TEXTURE_IMAGE_FRAC); +} diff --git a/lib/ultralib/src/gu/libm_vals.s b/lib/ultralib/src/gu/libm_vals.s new file mode 100644 index 0000000..b88ad98 --- /dev/null +++ b/lib/ultralib/src/gu/libm_vals.s @@ -0,0 +1,5 @@ + .rdata + .align 4 + .globl __libm_qnan_f +__libm_qnan_f: + .word 0x7F810000 diff --git a/lib/ultralib/src/gu/loadtextureblockmipmap.c b/lib/ultralib/src/gu/loadtextureblockmipmap.c new file mode 100644 index 0000000..30ffc65 --- /dev/null +++ b/lib/ultralib/src/gu/loadtextureblockmipmap.c @@ -0,0 +1,717 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/**************************************************************************** + * NOTE: To view this file correctly, set tabstop=3 +*****************************************************************************/ +#include "guint.h" +#include +#include "ultra64.h" +#include "macros.h" + +// TODO: this comes from a header +#ident "$Revision: 1.49 $" + +#define TRAM_SIZE 4096 /* in bytes */ +#define TRAM_WSIZE 8 /* TRAM word size in bytes */ +#define TRAM_LSIZE 8 /* TRAM load word size in bytes */ +#define MM_MAX_LEVEL 7 /* number of mipmap levels 0 to MM_MAX_LEVEL */ +#define MM_MIN_SIZE 1 /* smallest mipmap tile */ + +struct texelSizeParams +{ + unsigned char gran; + unsigned char shift; + unsigned char tsize; + unsigned char shiftr; +}; + +/* texture ram tile */ +struct Tile +{ + int w; /* width of tile in texels, padded to tram line sz */ + int s, t; /* size of tile in texels */ + int addr; /* address in tram of tile */ +}; + +/* tram mipmaps */ +static struct Tile mipmap[MM_MAX_LEVEL+1] ALIGNED(8); +static struct texelSizeParams sizeParams[4] = + { 16, 3, 1, 0, + 8, 2, 2, 1, + 4, 1, 4, 2, + 2, 0, 8, 3 + }; + + +static int max_mipmap; +static unsigned char *tram; +static int txlsize; +static int errNo = 0; +static int NA = 0; /* Not applicable */ +static unsigned int length; /* total texels in mipmap */ +static int level; /* total levels in mipmap */ + +static void get3x3(struct Tile *tile, int *s, int *t, int *texel, int shift, int size); +static void stuffDisplayList(Gfx **glistp, Image *im, char *tbuf, unsigned char startTile, + unsigned char pal, unsigned char cms, unsigned char cmt, + unsigned char masks, unsigned char maskt, unsigned char shifts, + unsigned char shiftt); +static void kernel(int i, int r1, int g1, int b1, int a1, float *r2, float *g2, + float *b2, float *a2); + +#define unpack_ia16(c,i,a) \ + i = (c & 0xff00) >> 8, a = (c & 0xff) +#define pack_ia16(i,a) \ + (i << 8) | a + +#define unpack_ia8(c,i,a) \ + i = ((c & 0xf0) >> 4), a = (c & 0xf) +#define pack_ia8(i,a) \ + (a & 0xf) | ((i & 0xf) << 4) + +#define unpack_ia4(c,i,a) \ + i = ((c & 0xe) >> 1), a = (c & 0x1) +#define pack_ia4(i,a) \ + ((i & 0x7) << 1) | ((a & 0x1)) + +#define unpack_i4(c,i) \ + i = (c & 0xf) +#define pack_i4(i) \ + (i) + +#define unpack_i8(c,i) \ + i = (c & 0xff) +#define pack_i8(i) \ + (i) + +#define unpack_ci8(c,ci) unpack_i8(c,ci) +#define pack_ci8(ci) pack_i8(ci) + +#define unpack_ci4(c,ci) unpack_i4(c,ci) +#define pack_ci4(ci) pack_i4(ci) + +#define unpack_rgba(c,r,g,b,a) \ + (r = (c & 0xf800) >> 11), g = ((c & 0x07c0) >> 6), b = ((c & 0x003e) >> 1), \ + a = (c & 0x1) + +#define pack_rgba( r, g, b, a) ((r&0x1f) << 11) | (g&0x1f) << 6 | \ + ((b&0x1f) << 1) | (a) + +/************************************************************************* + * Generates all levels of a power-of-two mipmap from an input array. * + * Also stuffs display list with entries for loading and rendering the * + * texture. Filtering Color-Index maps makes sense only if the lookup * + * is a linear ramp. Billboards and trees cutout using alpha will change * + * shape as the level changes due to change in map resolution. Texel * + * formats with only one bit of alpha will not be filtered very well. * + ************************************************************************* + * ErrNo value error description * + *-----------------------------------------------------------------------* + * 1 Mipmap too big to load into tmem. Not Fatal, * + * will load as many levels as there is space for. * + * * + * 2 Texel format not supported, Fatal error * + ************************************************************************/ + +int guLoadTextureBlockMipMap(Gfx **glistp, unsigned char *tbuf, Image *im, + unsigned char startTile, unsigned char pal, unsigned char cms, unsigned char cmt, + unsigned char masks, unsigned char maskt, unsigned char shifts, unsigned char shiftt, + unsigned char cfs, unsigned char cft) +{ + + unsigned char *iaddr, *taddr; + int im_bytes, tr_bytes; + int h, b; + int flip; + char startUnAligned; + char endUnAligned; + + txlsize = sizeParams[im->siz].tsize; /* texel size in nibbles */ + /* to next line size */ + + /* + * Do top level map, swizzle bytes on odd t's * + */ + /* base char address of tile to be loaded */ + iaddr = ((im->t * im->lsize)+((im->s * txlsize) >> 1) + im->base); + + /*check tile line starting and ending alignments along 4bit bndries */ + startUnAligned = ((im->s & 0x1) && (im->siz == G_IM_SIZ_4b)); + endUnAligned = (((im->s + im->w) & 0x1) && (im->siz == G_IM_SIZ_4b)); + + im_bytes = ((im->w * txlsize + 1) >> 1); /* siz of 1 tile line in bytes */ + tr_bytes = im_bytes / TRAM_LSIZE; /* no of tram lines per tile line */ + tr_bytes = tr_bytes * TRAM_LSIZE; /* tile line size in bytes */ + if (im_bytes > tr_bytes) tr_bytes += TRAM_LSIZE; + + taddr = &tbuf[im->addr]; /* why ? make this zero?*/ + + if (startUnAligned) + { + for (h=0; hh; h++) + { + flip = (h & 1) << 2; /*shift does not depend on txlsize*/ + for (b=0; b> 4); + } + /* add last aligned nibble */ + if (!endUnAligned) *(taddr+((b-1)^flip)) &= (0xf0); + /* pickup trailing bytes */ + for (b=im_bytes; blsize; + taddr += tr_bytes; + } + } + else /* if start aligned */ + { + for (h=0; hh; h++) + { + flip = (h & 1) << 2; /*shift does not depend on txlsize*/ + for (b=0; blsize; + taddr += tr_bytes; + } + } + + tram = tbuf; + + /* save tile attributes in top mipmap */ + mipmap[0].s = im->w; /* tile width */ + mipmap[0].t = im->h; /* tile height */ + /* guaranteed no remainder ? */ + mipmap[0].w = ((tr_bytes / txlsize) << 1); /* tile line width in texels*/ + mipmap[0].addr = im->addr; + max_mipmap = MM_MAX_LEVEL; + length = mipmap[0].w*mipmap[0].t; /* total texels in level 0 */ +/** + rmonPrintf("level0 w,t,l = %d %d %d\n",mipmap[0].w, mipmap[0].t,length); +***/ + +/****************************************************************************** + Generate other levels of mipmap using a box filter +******************************************************************************/ + +{/* generate mip map for this tile */ + unsigned char *taddr, *saddr; + int shift = (int) sizeParams[im->siz].shift; + int s, t, si, ti, sii, tii; + int s4[9]; + int t4[9]; + int tex4[9]; + int r0, g0, b0, a0, r1, g1, b1, a1; + float r2 ,g2, b2, a2; + float dummy; + int i0, ci0, ia0, i1, ci1, ia1; + float i2, ci2, ia2; + int texel; + int i,trip; + unsigned int tempaddr; + int ntexels = ((TRAM_LSIZE/txlsize) << 1); /* texels per line */ + + level = 0; /* need to check for memory overflow */ + while ((mipmap[level].s > 1) || (mipmap[level].t > 1)) + { + level++; + /* + * set new mipmap level address in bytes + */ + mipmap[level].addr = mipmap[level-1].addr + + (mipmap[level-1].w * txlsize * mipmap[level-1].t >> 1); + + /* + * grab location in tram pointing to the current level address + */ + taddr = &(tram[ mipmap[level].addr ]); + + /* + * downfilter by 2X, bump odd size + * compute parameters for new mipmap level + */ + mipmap[level].s = (mipmap[0].s) >> level; + mipmap[level].t = (mipmap[0].t) >> level; + + if (mipmap[level].s == 0) mipmap[level].s = 1; + if (mipmap[level].t == 0) mipmap[level].t = 1; + + /* + * width must be a multiple of 8 bytes (padding for tram line size) + */ + mipmap[level].w = + ((mipmap[level].s + (ntexels -1)) >> (shift +1) << (shift +1)); + + /* + * compute total no of texels to be loaded + */ + length += mipmap[level].w*mipmap[level].t; +/** + rmonPrintf("level, w,t,l = %d %d %d %d\n", level, mipmap[level].w, mipmap[level].t,length); +**/ + if ((length*txlsize >> 1) >= TRAM_SIZE) + { + errNo = 1; + length -= mipmap[level].w*mipmap[level].t; + break; + } + + /* + * for each scanline + */ + for (t=0; t= mipmap[level-1].t) ti = t; + if (tii < 0) tii = t; + } else { + if (ti >= mipmap[level-1].t) ti = 0; + if (tii < 0) tii = mipmap[level-1].t - 1; + } + + tempaddr = 0; + + for (s=0; s= mipmap[level-1].s) si = s; + if (sii < 0) sii = s; + } else { + if (si >= mipmap[level-1].s) si = 0; + if (sii < 0) sii = mipmap[level-1].s - 1; + } + +/*** + if (level == 6) + rmonPrintf("sts = %d %d %d %d %d %d\n", + s, si, sii, t, ti, tii); +***/ + + /* + * grab the nine neighbours to apply kernel function + */ + s4[0] = s; t4[0] = tii; + s4[1] = si; t4[1] = tii; + s4[2] = si; t4[2] = t; + s4[3] = si; t4[3] = ti; + s4[4] = s; t4[4] = ti; + s4[5] = sii; t4[5] = ti; + s4[6] = sii; t4[6] = t; + s4[7] = sii; t4[7] = tii; + s4[8] = s; t4[8] = t; + + get3x3( &mipmap[level-1], s4, t4, tex4, shift, im->siz); + + saddr = taddr + ((tempaddr >> 1)^trip); + r1 = g1 = b1 = a1 = ci1 = i1 = 0; + r2 = g2 = b2 = a2 = ci2 = i2 = 0; + + /* + * Extract R,G and B components of the 9 texels and + * apply the filter kernel + */ + switch (im->fmt) + { + case (G_IM_FMT_RGBA): + if (im->siz == G_IM_SIZ_16b) + { + for (i=0; i< 9; i++) + { + unpack_rgba(tex4[i], r0, g0, b0, a0); + kernel(i, r0, g0, b0, a0, &r2, &g2, &b2, &a2); +/*** + if (level == 6) + rmonPrintf("r0, g0, b0, a0 = %d %d %d %d\n", + r0, g0, b0, a0); +**/ + } + r1 = (int)(r2/16.0 + 0.5); + g1 = (int)(g2/16.0 + 0.5); + b1 = (int)(b2/16.0 + 0.5); + a1 = (int)(a2/16.0 + 0.5); + } + else + { + /* + * RGBA32 is not supported + */ + errNo = 2; + return errNo; + } + break; + + case (G_IM_FMT_YUV): + errNo = 2; + return errNo; + break; + + case (G_IM_FMT_CI): + if (im->siz == G_IM_SIZ_4b) + { + for (i=0; i<9; i++) + { + unpack_ci4(tex4[i],ci0); + kernel(i, ci0, 0, 0, 0, &ci2, &dummy, &dummy, + &dummy); + } + ci1 = (int)(ci2/16.0 + 0.5); + } + else + if (im->siz == G_IM_SIZ_8b) + { + for (i=0; i<9; i++) + { + unpack_ci8(tex4[i],ci0); + kernel(i, ci0, 0, 0, 0, &ci2, &dummy, + &dummy, &dummy); + } + ci1 = (int)(ci2/16.0 + 0.5); + } + else + { + errNo=2; + return errNo; + } + break; + + case (G_IM_FMT_IA): + if (im->siz == G_IM_SIZ_4b) + { + for (i=0; i<9; i++) + { + unpack_ia4(tex4[i],i0,a0); + kernel(i, i0, a0, 0, 0, &i2, &a2, &dummy, + &dummy); + } + i1 = (int)(i2/16.0 +0.5); + a1 = (int)(a2/16.0 +0.5); + } + else if (im->siz == G_IM_SIZ_8b) + { + for (i=0; i<9; i++) + { + unpack_ia8(tex4[i],i0,a0); + kernel(i, i0, a0, 0, 0, &i2, &a2, &dummy, + &dummy); + } + i1 = (int)(i2/16.0 +0.5); + a1 = (int)(a2/16.0 +0.5); + } + else + if (im->siz == G_IM_SIZ_16b) + { + for (i=0; i<9; i++) + { + unpack_ia16(tex4[i],i0,a0); + kernel(i, i0, a0, 0, 0, &i2, &a2, &dummy, + &dummy); + } + i1 = (int)(i2/16.0 +0.5); + a1 = (int)(a2/16.0 +0.5); + } + else + { + errNo = 2; + return errNo; + } + break; + + case (G_IM_FMT_I): + if (im->siz == G_IM_SIZ_4b) + { + for (i=0; i<9; i++) + { + unpack_i4(tex4[i],i0); + kernel(i, i0, 0, 0, 0, &i2, &dummy, &dummy, + &dummy); + } + i1 = (int)(i2/16.0 + 0.5); + } + else + if (im->siz == G_IM_SIZ_8b) + { + for (i=0; i<9; i++) + { + unpack_i8(tex4[i],i0); + kernel(i, i0, 0, 0, 0, &i2, &dummy, &dummy, + &dummy); + } + i1 = (int)(i2/16.0 +0.5); + } + else + { + errNo = 2; + return errNo; + } + + default: + break; + } + + /* + * Pack fields into destination texel + */ + switch (im->fmt) + { + + case (G_IM_FMT_RGBA): + texel = pack_rgba(r1,g1,b1,a1); + *(short *)((int)saddr^flip) = texel; + break; + + case (G_IM_FMT_YUV): + break; + + case (G_IM_FMT_CI): + + if (im->siz == G_IM_SIZ_4b) + { + texel = pack_ci4(ci1); + *(char *)((int)saddr^flip) |= (s & 0x2)? + (texel): (texel << 4); + } + else + if (im->siz == G_IM_SIZ_8b) + { + texel = pack_ci8(ci1); + *(char *)((int)saddr^flip) = texel; + } + break; + + case (G_IM_FMT_IA): + if (im->siz == G_IM_SIZ_4b) + { + texel = pack_ia4(i1,a1); + *(char *)((int)saddr^flip) |= (s & 0x2)? + (texel): (texel << 4); + } + else + if (im->siz == G_IM_SIZ_8b) + { + texel = pack_ia8(i1,a1); + *(char *)((int)saddr^flip) = texel; + } + else + if (im->siz == G_IM_SIZ_16b) + { + texel = pack_ia16(i1,a1); + *(short *)((int)saddr^flip) = texel; + } + break; + + case (G_IM_FMT_I): + if (im->siz == G_IM_SIZ_4b) + { + texel = pack_i4(i1); + *(char *)((int)saddr^flip) |= (s & 0x2)? + (texel): (texel << 4); + } + else + if (im->siz == G_IM_SIZ_8b) + { + texel = pack_i8(i1); + *(char *)((int)saddr^flip) = texel; + } + break; + } + + tempaddr += txlsize; + + } /* end s */ + + taddr += ((mipmap[level].w * txlsize) >> 1); + + } /* end t */ + + if (mipmap[level].s <= MM_MIN_SIZE && + mipmap[level].t <= MM_MIN_SIZE) + { + max_mipmap = level; + break; + } + } /* end level */ + +}/* end generate mipmap */ +/* + * Add entries for texture loading and rendering in DL + */ +stuffDisplayList(glistp, im, tbuf, startTile, pal, cms, cmt, masks, maskt, shifts, shiftt); + +return errNo; +} /* end guLoadTextureBlockMipMap */ + +/****************************************************************************** + * + * Apply Kernel : + * 1 2 1 + * 2 4 1 + * 1 2 1 + ******************************************************************************/ +static void kernel(int i, int r0, int g0, int b0, int a0, float *r2, float *g2, float *b2, float *a2) +{ + if (i == 8) + { + *r2 += r0*4; *g2 += g0*4; *b2 += b0*4; *a2 += a0*4; + } else + if (i%2 == 0) + { + *r2 += r0*2; + *g2 += g0*2; + *b2 += b0*2; + *a2 += a0*2; + } else + { + *r2 += r0; + *g2 += g0; + *b2 += b0; + *a2 += a0; + } +} + +/******************************************************************** + Add entries for loading and rendering textures into the display list +*********************************************************************/ +static void stuffDisplayList(Gfx **glistp, Image *im, char *tbuf, unsigned char startTile, + unsigned char pal, unsigned char cms, unsigned char cmt, + unsigned char masks, unsigned char maskt, unsigned char shifts, + unsigned char shiftt) +{ + int tile; + int Smask, Tmask; + int Sshift, Tshift; + + /* + * set LOADTILE for loading texture + * 4-bit textures are loaded in 8-bit chunks + */ + if (im->siz == G_IM_SIZ_4b) { + gDPSetTextureImage((*glistp)++, im->fmt, G_IM_SIZ_8b, 1, + osVirtualToPhysical((unsigned short *)tbuf)); + gDPSetTile((*glistp)++, im->fmt, G_IM_SIZ_8b, NA, 0, G_TX_LOADTILE, NA, + NA, NA, NA, NA, NA, NA); + /* Wait until all primitives are done */ + gDPLoadSync((*glistp)++); + gDPLoadBlock((*glistp)++, G_TX_LOADTILE, 0, 0, length/2, 0x0); + } else { + gDPSetTextureImage((*glistp)++, im->fmt, im->siz, 1, + osVirtualToPhysical((unsigned short *)tbuf)); + gDPSetTile((*glistp)++, im->fmt, im->siz, NA, 0, G_TX_LOADTILE, NA, + NA, NA, NA, NA, NA, NA); + /* Wait until all primitives are done */ + gDPLoadSync((*glistp)++); + gDPLoadBlock((*glistp)++, G_TX_LOADTILE, 0, 0, length, 0x0); + } + + for (tile = 0; tile <= level; tile ++) + { + Tmask = maskt-tile; + if (Tmask < 0){ + Tmask = 0; + } else { + Tshift = tile; + } + + Smask = masks-tile; + if (Smask < 0){ + Smask = 0; + } else { + Sshift = tile; + } + +/*** + rmonPrintf("tile, Tmask, Tshift, Smask, Sshift %d %d %d %d %d\n", + tile, Tmask, Tshift, Smask, Sshift); + rmonPrintf("%d\n",startTile); +***/ + + + gDPSetTile((*glistp)++,im->fmt, im->siz, (mipmap[tile].w*txlsize >> 4), + (mipmap[tile].addr >> 3), tile+startTile, pal, cmt, Tmask, Tshift, cms, + Smask, Sshift); + + gDPSetTileSize((*glistp)++,tile+startTile, (0 <> (shift-1)) ^ ((tt & 0x1) << 1)) << 1; + row = (((tt * tile->w + ss) * txlsize) >> 1) / TRAM_LSIZE; + addr = tile->addr + row * TRAM_WSIZE + bank; + + overlap = (i == 0) ? bank : overlap ^ bank; + + switch (size) + { + case G_IM_SIZ_4b: + texel[i] = (tram[addr + ((ss & 0x2) >> 1)] + & (0xf0 >> ((ss & 0x1) << 2))); + if (!(ss & 0x1)) texel[i] = texel[i] >> 4; + break; + + case G_IM_SIZ_8b: + texel[i] = tram[addr + (ss & 0x1)]; + break; + + case G_IM_SIZ_16b: + texel[i] = (tram[addr] << 8) | tram[addr+1]; + break; + + case G_IM_SIZ_32b: + errNo = 2; /* Format not supported */ + break; + + default: + break; + } + + } +} diff --git a/lib/ultralib/src/gu/lookat.c b/lib/ultralib/src/gu/lookat.c new file mode 100644 index 0000000..1fadc17 --- /dev/null +++ b/lib/ultralib/src/gu/lookat.c @@ -0,0 +1,83 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp) +{ + float len, xLook, yLook, zLook, xRight, yRight, zRight; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Up = Look x Right */ + + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} + +void guLookAt (Mtx *m, float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp) +{ + Matrix mf; + + guLookAtF(mf, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/lookathil.c b/lib/ultralib/src/gu/lookathil.c new file mode 100644 index 0000000..a848688 --- /dev/null +++ b/lib/ultralib/src/gu/lookathil.c @@ -0,0 +1,185 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + + +void guLookAtHiliteF(float mf[4][4], LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float xl1, float yl1, float zl1, /* light 1 direction */ + float xl2, float yl2, float zl2, /* light 2 direction */ + int twidth, int theight) /* highlight txtr size*/ +{ + float len, xLook, yLook, zLook, xRight, yRight, zRight; + float xHilite, yHilite, zHilite; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Up = Look x Right */ + + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + /* hilite vectors */ + + len = 1.0 / sqrtf (xl1*xl1 + yl1*yl1 + zl1*zl1); + xl1 *= len; + yl1 *= len; + zl1 *= len; + +#define THRESH2 0.1 + xHilite = xl1 + xLook; + yHilite = yl1 + yLook; + zHilite = zl1 + zLook; + + len = sqrtf (xHilite*xHilite + yHilite*yHilite + zHilite*zHilite); + + if (len>THRESH2) + { + len = 1.0 / len; + xHilite *= len; + yHilite *= len; + zHilite *= len; + + h->h.x1 = + twidth*4 + (xHilite*xRight + + yHilite*yRight + + zHilite*zRight)*twidth*2; + + h->h.y1 = + theight*4 + (xHilite*xUp + + yHilite*yUp + + zHilite*zUp)*theight*2; + } + else + { + h->h.x1 = twidth*2; + h->h.y1 = theight*2; + } + + len = 1.0 / sqrtf (xl2*xl2 + yl2*yl2 + zl2*zl2); + xl2 *= len; + yl2 *= len; + zl2 *= len; + + xHilite = xl2 + xLook; + yHilite = yl2 + yLook; + zHilite = zl2 + zLook; + len = sqrtf (xHilite*xHilite + yHilite*yHilite + zHilite*zHilite); + if (len>THRESH2) + { + len = 1.0 / len; + xHilite *= len; + yHilite *= len; + zHilite *= len; + + h->h.x2 = twidth*4 + + (xHilite*xRight + yHilite*yRight + zHilite*zRight)*twidth*2; + + h->h.y2 = theight*4 + + (xHilite*xUp + yHilite*yUp + zHilite*zUp)*theight*2; + } + else + { + h->h.x2 = twidth*2; + h->h.y2 = theight*2; + } + + /* reflectance vectors = Up and Right */ + + l->l[0].l.dir[0] = FTOFRAC8(xRight); + l->l[0].l.dir[1] = FTOFRAC8(yRight); + l->l[0].l.dir[2] = FTOFRAC8(zRight); + l->l[1].l.dir[0] = FTOFRAC8(xUp); + l->l[1].l.dir[1] = FTOFRAC8(yUp); + l->l[1].l.dir[2] = FTOFRAC8(zUp); + l->l[0].l.col[0] = 0x00; + l->l[0].l.col[1] = 0x00; + l->l[0].l.col[2] = 0x00; + l->l[0].l.pad1 = 0x00; + l->l[0].l.colc[0] = 0x00; + l->l[0].l.colc[1] = 0x00; + l->l[0].l.colc[2] = 0x00; + l->l[0].l.pad2 = 0x00; + l->l[1].l.col[0] = 0x00; + l->l[1].l.col[1] = 0x80; + l->l[1].l.col[2] = 0x00; + l->l[1].l.pad1 = 0x00; + l->l[1].l.colc[0] = 0x00; + l->l[1].l.colc[1] = 0x80; + l->l[1].l.colc[2] = 0x00; + l->l[1].l.pad2 = 0x00; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} + +void guLookAtHilite (Mtx *m, LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float xl1, float yl1, float zl1, /* light 1 direction */ + float xl2, float yl2, float zl2, /* light 2 direction */ + int twidth, int theight) /* highlight txtr size*/ +{ + Matrix mf; + + guLookAtHiliteF(mf, l, h, xEye, yEye, zEye, xAt, yAt, zAt, + xUp, yUp, zUp, xl1, yl1, zl1, xl2, yl2, zl2, + twidth, theight); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/lookatref.c b/lib/ultralib/src/gu/lookatref.c new file mode 100644 index 0000000..3cd3b65 --- /dev/null +++ b/lib/ultralib/src/gu/lookatref.c @@ -0,0 +1,111 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + + +void guLookAtReflectF(float mf[4][4], LookAt *l, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp) +{ + float len, xLook, yLook, zLook, xRight, yRight, zRight; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Up = Look x Right */ + + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + /* reflectance vectors = Up and Right */ + + l->l[0].l.dir[0] = FTOFRAC8(xRight); + l->l[0].l.dir[1] = FTOFRAC8(yRight); + l->l[0].l.dir[2] = FTOFRAC8(zRight); + l->l[1].l.dir[0] = FTOFRAC8(xUp); + l->l[1].l.dir[1] = FTOFRAC8(yUp); + l->l[1].l.dir[2] = FTOFRAC8(zUp); + l->l[0].l.col[0] = 0x00; + l->l[0].l.col[1] = 0x00; + l->l[0].l.col[2] = 0x00; + l->l[0].l.pad1 = 0x00; + l->l[0].l.colc[0] = 0x00; + l->l[0].l.colc[1] = 0x00; + l->l[0].l.colc[2] = 0x00; + l->l[0].l.pad2 = 0x00; + l->l[1].l.col[0] = 0x00; + l->l[1].l.col[1] = 0x80; + l->l[1].l.col[2] = 0x00; + l->l[1].l.pad1 = 0x00; + l->l[1].l.colc[0] = 0x00; + l->l[1].l.colc[1] = 0x80; + l->l[1].l.colc[2] = 0x00; + l->l[1].l.pad2 = 0x00; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} + +void guLookAtReflect (Mtx *m, LookAt *l, float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp) +{ + float mf[4][4]; + + guLookAtReflectF(mf, l, xEye, yEye, zEye, xAt, yAt, zAt, + xUp, yUp, zUp); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/lookatstereo.c b/lib/ultralib/src/gu/lookatstereo.c new file mode 100644 index 0000000..b60ca08 --- /dev/null +++ b/lib/ultralib/src/gu/lookatstereo.c @@ -0,0 +1,111 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guLookAtStereoF(float mf[4][4], float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, float eyedist) +{ + float len, xLook, yLook, zLook, xRight, yRight, zRight; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Move eye for stereo */ + xEye += eyedist*xRight; + yEye += eyedist*yRight; + zEye += eyedist*zRight; + + /* recalculate using new eye */ + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + + /* Up = Look x Right */ + + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} + +void guLookAtStereo (Mtx *m, float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, float eyedist) +{ + Matrix mf; + + guLookAtStereoF(mf, xEye, yEye, zEye, xAt, yAt, zAt, + xUp, yUp, zUp, eyedist); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/mtxcatf.c b/lib/ultralib/src/gu/mtxcatf.c new file mode 100644 index 0000000..6572e0f --- /dev/null +++ b/lib/ultralib/src/gu/mtxcatf.c @@ -0,0 +1,63 @@ + +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: mtxcatf.c + * Creator: hsa@sgi.com + * Create Date: Thu Nov 2 13:03:02 PST 1995 + * + */ + +#include "guint.h" + +void guMtxCatF(float mf[4][4], float nf[4][4], float res[4][4]) +{ + int i, j, k; + float temp[4][4]; + + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + temp[i][j] = 0.0; + for (k=0; k<4; k++) { + temp[i][j] += mf[i][k] * nf[k][j]; + } + } + } + + /* make sure we handle case where result is an input */ + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + res[i][j] = temp[i][j]; + } + } +} + +void guMtxXFMF(float mf[4][4], float x, float y, float z, float *ox, float *oy, float *oz) +{ + *ox = mf[0][0]*x + mf[1][0]*y + mf[2][0]*z + mf[3][0]; + *oy = mf[0][1]*x + mf[1][1]*y + mf[2][1]*z + mf[3][1]; + *oz = mf[0][2]*x + mf[1][2]*y + mf[2][2]*z + mf[3][2]; +} + diff --git a/lib/ultralib/src/gu/mtxcatl.c b/lib/ultralib/src/gu/mtxcatl.c new file mode 100644 index 0000000..3f165bb --- /dev/null +++ b/lib/ultralib/src/gu/mtxcatl.c @@ -0,0 +1,57 @@ + +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: mtxcatl.c + * Creator: hsa@sgi.com + * Create Date: Thu Nov 2 13:03:02 PST 1995 + * + */ + +#include "guint.h" +#include "os_version.h" + +void guMtxCatL(Mtx *m, Mtx *n, Mtx *res) +{ + float mf[4][4], nf[4][4], resf[4][4]; + + guMtxL2F(mf, m); + guMtxL2F(nf, n); + + guMtxCatF(mf, nf, resf); + + guMtxF2L(resf, res); +} + +#if BUILD_VERSION < VERSION_K +void guMtxXFML(Mtx *m, float x, float y, float z, float *ox, float *oy, float *oz) +{ + float mf[4][4]; + + guMtxL2F(mf, m); + + guMtxXFMF(mf, x, y, z, ox, oy, oz); +} +#endif diff --git a/lib/ultralib/src/gu/mtxutil.c b/lib/ultralib/src/gu/mtxutil.c new file mode 100644 index 0000000..2510558 --- /dev/null +++ b/lib/ultralib/src/gu/mtxutil.c @@ -0,0 +1,73 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guMtxF2L(float mf[4][4], Mtx *m) +{ + int i, j; + int e1,e2; + int *ai,*af; + + + ai=(int *) &m->m[0][0]; + af=(int *) &m->m[2][0]; + + for (i=0; i<4; i++) + for (j=0; j<2; j++) { + e1=FTOFIX32(mf[i][j*2]); + e2=FTOFIX32(mf[i][j*2+1]); + *(ai++) = ( e1 & 0xffff0000 ) | ((e2 >> 16)&0xffff); + *(af++) = ((e1 << 16) & 0xffff0000) | (e2 & 0xffff); + } +} + +void guMtxL2F(float mf[4][4], Mtx *m) +{ + int i, j; + unsigned int e1,e2; + unsigned int *ai,*af; + int q1,q2; + + ai=(unsigned int *) &m->m[0][0]; + af=(unsigned int *) &m->m[2][0]; + + for (i=0; i<4; i++) + for (j=0; j<2; j++) { + e1 = (*ai & 0xffff0000) | ((*af >> 16) & 0xffff); + e2 = ((*(ai++) << 16) & 0xffff0000) | (*(af++) & 0xffff); + q1 = *((int *)&e1); + q2 = *((int *)&e2); + + mf[i][j*2] = FIX32TOF(q1); + mf[i][j*2+1] = FIX32TOF(q2); + } +} + +void guMtxIdentF(float mf[4][4]) +{ + int i, j; + + for (i=0; i<4; i++) + for (j=0; j<4; j++) + if (i == j) mf[i][j] = 1.0; + else mf[i][j] = 0.0; +} + +void guMtxIdent(Mtx *m) +{ + float mf[4][4]; + + guMtxIdentF(mf); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/normalize.c b/lib/ultralib/src/gu/normalize.c new file mode 100644 index 0000000..6884b29 --- /dev/null +++ b/lib/ultralib/src/gu/normalize.c @@ -0,0 +1,23 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guNormalize(float *x, float *y, float *z) +{ + float m; + + m = 1/sqrtf((*x)*(*x) + (*y)*(*y) + (*z)*(*z)); + *x *= m; + *y *= m; + *z *= m; +} diff --git a/lib/ultralib/src/gu/ortho.c b/lib/ultralib/src/gu/ortho.c new file mode 100644 index 0000000..9e52cb3 --- /dev/null +++ b/lib/ultralib/src/gu/ortho.c @@ -0,0 +1,41 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guOrthoF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale) +{ + int i, j; + + guMtxIdentF(mf); + + mf[0][0] = 2/(r-l); + mf[1][1] = 2/(t-b); + mf[2][2] = -2/(f-n); + mf[3][0] = -(r+l)/(r-l); + mf[3][1] = -(t+b)/(t-b); + mf[3][2] = -(f+n)/(f-n); + mf[3][3] = 1; + + for (i=0; i<4; i++) + for (j=0; j<4; j++) + mf[i][j] *= scale; +} + +void guOrtho(Mtx *m, float l, float r, float b, float t, float n, float f, float scale) +{ + Matrix mf; + + guOrthoF(mf, l, r, b, t, n, f, scale); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/parse_gbi.c b/lib/ultralib/src/gu/parse_gbi.c new file mode 100644 index 0000000..d736d4a --- /dev/null +++ b/lib/ultralib/src/gu/parse_gbi.c @@ -0,0 +1,139 @@ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + *************************************************************************/ +#include +#include +#include + +#ifndef _FINALROM + +/* + * guParseGbiDL works in conjunction with the dlprint tool. dlprint must be + * running on the host Indy. guParseGbiDL, sends a bunch of blocks of data, + * with a minimum of one display list, but typically, the principle display + * list with a bunch of branched or nested display lists, as well as all the + * vertex and matrix data that will be used. After all the blocks of data + * are sent, a GU_PARSE_READY command is sent, and dlprint parses out the + * data printing it to stdout. + * + * In order to know what data to send, guParseGbiDL must step through the + * display list, find all the gSPDisplayList and gSPBranchList calls, go + * to those lists, and also find and send info for all the matrix and vertex + * calls. + */ +void guParseGbiDL(u64 *gbi_dl, u32 nbytes, u8 flags) +{ + guDLPrintCB cntlBlk; + Gfx* dlStk[11]; + s32 dlcount = 0; + Gfx *curGfx,*dlPtr,*vaddr; + s8 op; + u32 *word0; + u32 *word1; + u32 segments[16]; + u32 param, seg; + u32 paddr,len; + + + cntlBlk.dataSize = nbytes; + cntlBlk.flags = flags; + cntlBlk.dlType = GU_PARSE_GBI_TYPE; + cntlBlk.paddr = osVirtualToPhysical(gbi_dl); + + osWriteHost(&cntlBlk,sizeof(cntlBlk)); + osWriteHost(gbi_dl,nbytes); + + dlStk[0] = (Gfx*)gbi_dl; + while((dlcount >= 0) && (dlcount <= 10)) + { + curGfx = dlStk[dlcount]; /* get the current graphics display list */ + op = *((s8*)curGfx); /* get the first byte */ + dlStk[dlcount]++; /* increment to next gfx command */ + switch(op) + { + case G_MOVEWORD: + word0 = (u32*)curGfx; /* get ptr to first word */ + if(((*word0) & 0x000000ff) == G_MW_SEGMENT) + { + u32 seg; + seg = (((*word0) & 0x00ffff00) >> 8) >> 2; + word1 = word0 + 1; + segments[seg] = *word1; + } + break; + case G_ENDDL: + dlcount--; + break; + case G_DL: + word0 = (u32*)curGfx; /* get ptr to first word */ + param = ((*word0) & 0x00ff0000) >> 16; /* get param */ + word1 = word0 + 1; /* get pointer to second word */ +#if BUILD_VERSION >= VERSION_J + seg = ((*word1) & 0x0f000000) >> 24; /* get the segment */ +#else + seg = ((*word1) & 0xff000000) >> 24; /* get the segment */ +#endif + paddr = segments[seg] + ((*word1) & 0x00ffffff); + vaddr = (Gfx*)osPhysicalToVirtual(paddr); + len = 1; + dlPtr = vaddr; + while((*(s8*)dlPtr) != G_ENDDL) + { + len++; + dlPtr++; + } + len *= sizeof(Gfx); + + cntlBlk.dataSize = len; + cntlBlk.dlType = GU_PARSE_GBI_TYPE; + cntlBlk.paddr = paddr; + + osWriteHost(&cntlBlk,sizeof(cntlBlk)); + osWriteHost((u8*)vaddr,len); + if(param == G_DL_PUSH) + { + if(dlcount < 10) + dlcount++; + else + osSyncPrintf("Display lists nested too deep!!!\n"); + } + dlStk[dlcount] = (Gfx*)vaddr; + break; + case G_VTX: + case G_MOVEMEM: + case G_MTX: + word0 = (u32*)curGfx; /* get ptr to first word */ + word1 = word0 + 1; /* get pointer to second word */ +#if BUILD_VERSION >= VERSION_J + seg = ((*word1) & 0x0f000000) >> 24; /* get the segment */ +#else + seg = ((*word1) & 0xff000000) >> 24; /* get the segment */ +#endif + paddr = segments[seg] + ((*word1) & 0x00ffffff); + vaddr = (Gfx*)osPhysicalToVirtual(paddr); + len = (*word0) & 0x0000ffff; + cntlBlk.dataSize = len; /* always send 32 bytes, the most used */ + cntlBlk.dlType = GU_PARSE_MEM_BLOCK; + cntlBlk.paddr = paddr; + osWriteHost(&cntlBlk,sizeof(cntlBlk)); + osWriteHost((u8*)vaddr,len); + break; + + } + } + + cntlBlk.dlType = GU_PARSE_READY; + osWriteHost(&cntlBlk,sizeof(cntlBlk)); +} + +#endif + diff --git a/lib/ultralib/src/gu/parse_rdp.c b/lib/ultralib/src/gu/parse_rdp.c new file mode 100644 index 0000000..c17c978 --- /dev/null +++ b/lib/ultralib/src/gu/parse_rdp.c @@ -0,0 +1,36 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + *************************************************************************/ +#include +#include +#include + +/* guParseRdpDL works in conjunction with dlprint which must be running on + * the host Indy. guParseRdpDL simple uses the hostio routines to send the + * display list to the Indy, and dlprint does all the parsing. + */ + +#ifndef _FINALROM +void guParseRdpDL(u64 *rdp_dl, u64 nbytes, u8 flags) +{ + guDLPrintCB cntlBlk; + + cntlBlk.dataSize = nbytes; + cntlBlk.flags = flags; + cntlBlk.dlType = GU_PARSE_RDP_TYPE; + cntlBlk.paddr = osVirtualToPhysical(rdp_dl); + + osWriteHost(&cntlBlk,sizeof(cntlBlk)); + osWriteHost(rdp_dl,nbytes); + +} + +#endif diff --git a/lib/ultralib/src/gu/parse_string.c b/lib/ultralib/src/gu/parse_string.c new file mode 100644 index 0000000..71a58a8 --- /dev/null +++ b/lib/ultralib/src/gu/parse_string.c @@ -0,0 +1,35 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + *************************************************************************/ +#include +#include +#include + +/* guParseString works in conjunction with dlprint which must be running on + * the host Indy. guParseString simply uses the hostio routines to send the + * string to the Indy, and dlprint does all the parsing. + */ + +#ifndef _FINALROM +void guParseString(char *StringPointer, u64 nbytes) +{ + guDLPrintCB cntlBlk; + + cntlBlk.dataSize = nbytes /* /8 + ((nbytes%8) != 0) */; + cntlBlk.dlType = GU_PARSE_STRING_TYPE; + cntlBlk.paddr = osVirtualToPhysical((u64 *) StringPointer); + + osWriteHost(&cntlBlk,sizeof(cntlBlk)); + osWriteHost((u64 *) StringPointer,nbytes); + +} + +#endif diff --git a/lib/ultralib/src/gu/perspective.c b/lib/ultralib/src/gu/perspective.c new file mode 100644 index 0000000..be571d4 --- /dev/null +++ b/lib/ultralib/src/gu/perspective.c @@ -0,0 +1,58 @@ + +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" +#include + +void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) +{ + float cot; + int i, j; + + guMtxIdentF(mf); + + fovy *= 3.1415926 / 180.0; + cot = cosf (fovy/2) / sinf (fovy/2); + + mf[0][0] = cot / aspect; + mf[1][1] = cot; + mf[2][2] = (near + far) / (near - far); + mf[2][3] = -1; + mf[3][2] = (2 * near * far) / (near - far); + mf[3][3] = 0; + + for (i=0; i<4; i++) + for (j=0; j<4; j++) + mf[i][j] *= scale; + + if (perspNorm != (u16 *) NULL) { + if (near+far<=2.0) { + *perspNorm = (u16) 0xFFFF; + } else { + *perspNorm = (u16) ((2.0*65536.0)/(near+far)); + if (*perspNorm<=0) + *perspNorm = (u16) 0x0001; + } + } +} + +void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) +{ + Matrix mf; + + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + + guMtxF2L(mf, m); +} + + diff --git a/lib/ultralib/src/gu/position.c b/lib/ultralib/src/gu/position.c new file mode 100644 index 0000000..52cdd96 --- /dev/null +++ b/lib/ultralib/src/gu/position.c @@ -0,0 +1,73 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* + * Return position matrix given roll, pitch, and yaw in degrees + * plus scale and position. + * + * r = roll (degrees) + * p = pitch (degrees) + * h = yaw (degrees) + * s = scale + * x,y,z = position (world coordinates) + * + */ + +void guPositionF(float mf[4][4], float r, float p, float h, float s, + float x, float y, float z) +{ + static float dtor = 3.1415926 / 180.0; + float sinr, sinp, sinh; + float cosr, cosp, cosh; + + r *= dtor; + p *= dtor; + h *= dtor; + sinr = sinf(r); + cosr = cosf(r); + sinp = sinf(p); + cosp = cosf(p); + sinh = sinf(h); + cosh = cosf(h); + + mf[0][0] = (cosp*cosh) * s; + mf[0][1] = (cosp*sinh) * s; + mf[0][2] = (-sinp) * s; + mf[0][3] = 0.0; + + mf[1][0] = (sinr*sinp*cosh - cosr*sinh) * s; + mf[1][1] = (sinr*sinp*sinh + cosr*cosh) * s; + mf[1][2] = (sinr*cosp) * s; + mf[1][3] = 0.0; + + mf[2][0] = (cosr*sinp*cosh + sinr*sinh) * s; + mf[2][1] = (cosr*sinp*sinh - sinr*cosh) * s; + mf[2][2] = (cosr*cosp) * s; + mf[2][3] = 0.0; + + mf[3][0] = x; + mf[3][1] = y; + mf[3][2] = z; + mf[3][3] = 1.0; +} + +void guPosition(Mtx *m, float r, float p, float h, float s, + float x, float y, float z) +{ + float mf[4][4]; + + guPositionF(mf, r, p, h, s, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/poslight.c b/lib/ultralib/src/gu/poslight.c new file mode 100644 index 0000000..389a04d --- /dev/null +++ b/lib/ultralib/src/gu/poslight.c @@ -0,0 +1,69 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + + +/* + * define a positional light. + * this function must be called anytime the light or object moves. + * + * pl = (input) positional light description. + * l = (output) directiona light description for gSPLight or gSPSetLightsN. + * *Ob = position of (center of) object to be lit. + * + */ +#define THRESH1 0.01 +#define THRESH2 0.1 +void guPosLight(PositionalLight *pl, Light *l, + float xOb, float yOb, float zOb) +{ + float x,y,z,d,a; + + + x = pl->pos[0]-xOb; + y = pl->pos[1]-yOb; + z = pl->pos[2]-zOb; + d = sqrtf(x*x + y*y + z*z); + + a = d*pl->a1 + pl->a2; + if (al.dir[0] = 0; + l->l.dir[1] = 0; + l->l.dir[2] = -120; + + l->l.col[0] = 0; + l->l.col[1] = 0; + l->l.col[2] = 0; + l->l.colc[0] = 0; + l->l.colc[1] = 0; + l->l.colc[2] = 0; + } else { + d = 1/d; + l->l.dir[0] = 120.0*x*d; + l->l.dir[1] = 120.0*y*d; + l->l.dir[2] = 120.0*z*d; + + l->l.col[0] = pl->col[0]*a; + l->l.col[1] = pl->col[1]*a; + l->l.col[2] = pl->col[2]*a; + l->l.colc[0] = pl->col[0]*a; + l->l.colc[1] = pl->col[1]*a; + l->l.colc[2] = pl->col[2]*a; + } + +} diff --git a/lib/ultralib/src/gu/poslighthil.c b/lib/ultralib/src/gu/poslighthil.c new file mode 100644 index 0000000..259fe8c --- /dev/null +++ b/lib/ultralib/src/gu/poslighthil.c @@ -0,0 +1,168 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + + +/* + * define 2 positional lights with highlights. + * this function must be called anytime the viewpoint, light or object moves. + * + * pl1 = (input) positional light#1 description. + * pl2 = (input) positional light#2 description. + * l1 = (output) directional light desc. #1 for gSPLight or gSPSetLightsN. + * l2 = (output) directional light desc. #2 for gSPLight or gSPSetLightsN. + * *Eye = position of eye (viewpoint). (usually same as in LookAt command.) + * *Ob = position of (center of) object to be lit. + * *Ob = up vector (usually same as in LookAt command). + * twidth = width of texture map used for highlight. + * theight = height of texture map used for highlight. + * + */ +#define THRESH2 0.01 +#define THRESH3 0.1 +void guPosLightHilite(PositionalLight *pl1, PositionalLight *pl2, + Light *l1, Light *l2, + LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xOb, float yOb, float zOb, + float xUp, float yUp, float zUp, + int twidth, int theight) /* hilite txtr size*/ +{ + float x,y,z,d,a; + Mtx m; + + +/* + * light 1, diffuse + */ + x = pl1->pos[0]-xOb; + y = pl1->pos[1]-yOb; + z = pl1->pos[2]-zOb; + d = sqrtf(x*x + y*y + z*z); + + a=d*pl1->a1 + pl1->a2; + if (al.dir[0] = 0; + l1->l.dir[1] = 0; + l1->l.dir[2] = -120; + + l1->l.col[0] = 0; + l1->l.col[1] = 0; + l1->l.col[2] = 0; + l1->l.colc[0] = 0; + l1->l.colc[1] = 0; + l1->l.colc[2] = 0; + } else { + d = 1/d; + l1->l.dir[0] = 120.0*x*d; + l1->l.dir[1] = 120.0*y*d; + l1->l.dir[2] = 120.0*z*d; + + l1->l.col[0] = pl1->col[0]*a; + l1->l.col[1] = pl1->col[1]*a; + l1->l.col[2] = pl1->col[2]*a; + l1->l.colc[0] = pl1->col[0]*a; + l1->l.colc[1] = pl1->col[1]*a; + l1->l.colc[2] = pl1->col[2]*a; + } + + +/* + * light 2, diffuse + */ + x = pl2->pos[0]-xOb; + y = pl2->pos[1]-yOb; + z = pl2->pos[2]-zOb; + d = sqrtf(x*x + y*y + z*z); + + a = d*pl2->a1 + pl2->a2; + if (al.dir[0] = 0; + l2->l.dir[1] = 0; + l2->l.dir[2] = -120; + + l2->l.col[0] = 0; + l2->l.col[1] = 0; + l2->l.col[2] = 0; + l2->l.colc[0] = 0; + l2->l.colc[1] = 0; + l2->l.colc[2] = 0; + } else { + d = 1/d; + l2->l.dir[0] = 120.0*x*d; + l2->l.dir[1] = 120.0*y*d; + l2->l.dir[2] = 120.0*z*d; + + l2->l.col[0] = pl2->col[0]*a; + l2->l.col[1] = pl2->col[1]*a; + l2->l.col[2] = pl2->col[2]*a; + l2->l.colc[0] = pl2->col[0]*a; + l2->l.colc[1] = pl2->col[1]*a; + l2->l.colc[2] = pl2->col[2]*a; + } + + +/* + * Hilight factors + */ + x = xOb-xEye; + y = yOb-yEye; + z = zOb-zEye; + if (sqrtf(x*x + y*y + z*z)h.x1 = twidth*2; + h->h.y1 = twidth*2; + h->h.x2 = twidth*2; + h->h.y2 = twidth*2; + l->l[0].l.dir[0] = 0; + l->l[0].l.dir[1] = 0; + l->l[0].l.dir[2] = 0; + l->l[1].l.dir[0] = 0; + l->l[1].l.dir[1] = 0; + l->l[1].l.dir[2] = 0; + l->l[0].l.col[0] = 0x00; + l->l[0].l.col[1] = 0x00; + l->l[0].l.col[2] = 0x00; + l->l[0].l.pad1 = 0x00; + l->l[0].l.colc[0] = 0x00; + l->l[0].l.colc[1] = 0x00; + l->l[0].l.colc[2] = 0x00; + l->l[0].l.pad2 = 0x00; + l->l[1].l.col[0] = 0x00; + l->l[1].l.col[1] = 0x80; + l->l[1].l.col[2] = 0x00; + l->l[1].l.pad1 = 0x00; + l->l[1].l.colc[0] = 0x00; + l->l[1].l.colc[1] = 0x80; + l->l[1].l.colc[2] = 0x00; + l->l[1].l.pad2 = 0x00; + } else { + guLookAtHilite(&m, l, h, + xEye, yEye, zEye, + xOb, yOb, zOb, + xUp, yUp, zUp, + l1->l.dir[0], l1->l.dir[1], l1->l.dir[2], + l2->l.dir[0], l2->l.dir[1], l2->l.dir[2], + twidth, theight); + } +} + diff --git a/lib/ultralib/src/gu/random.c b/lib/ultralib/src/gu/random.c new file mode 100644 index 0000000..32cfde3 --- /dev/null +++ b/lib/ultralib/src/gu/random.c @@ -0,0 +1,33 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* + * Return a pseudorandom 32 bit number + * try the RAND macro too + * + */ +int guRandom(void) +{ + static unsigned int xseed = 174823885; + unsigned int x; + + x = (xseed<<2) + 2; + + x *= (x+1); + x = x >> 2; + + xseed = x; + + return( x ); +} diff --git a/lib/ultralib/src/gu/readme.txt b/lib/ultralib/src/gu/readme.txt new file mode 100644 index 0000000..114174e --- /dev/null +++ b/lib/ultralib/src/gu/readme.txt @@ -0,0 +1,17 @@ +Among the gu Functions, the following were replaced with the newly +created high speed versions. With the current version OS they are +not being used. + +guMtxIdent +guMtxIdentF +guScale +guScaleF +guNormalize +guTranslate +guTranslateF +guMtxF2L +guRotateF +guMtxL2F +guMtxCatF + +The newly created functions are installed in the mgu directory. diff --git a/lib/ultralib/src/gu/rotate.c b/lib/ultralib/src/gu/rotate.c new file mode 100644 index 0000000..c843d9f --- /dev/null +++ b/lib/ultralib/src/gu/rotate.c @@ -0,0 +1,72 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" +#include "os_version.h" + +void guRotateF(float mf[4][4], float a, float x, float y, float z) +{ + static float dtor = 3.1415926 / 180.0; + float sine; + float cosine; + float ab, bc, ca, t; +#if BUILD_VERSION >= VERSION_K + float xxsine; + float yxsine; + float zxsine; +#endif + + guNormalize(&x, &y, &z); + a *= dtor; + sine = sinf(a); + cosine = cosf(a); + t = (1-cosine); + ab = x*y*t; + bc = y*z*t; + ca = z*x*t; + + guMtxIdentF(mf); + +#if BUILD_VERSION >= VERSION_K + xxsine = x * sine; + yxsine = y * sine; + zxsine = z * sine; +#else + #define xxsine (x * sine) + #define yxsine (y * sine) + #define zxsine (z * sine) +#endif + + t = x*x; + mf[0][0] = t+cosine*(1-t); + mf[2][1] = bc-xxsine; + mf[1][2] = bc+xxsine; + + t = y*y; + mf[1][1] = t+cosine*(1-t); + mf[2][0] = ca+yxsine; + mf[0][2] = ca-yxsine; + + t = z*z; + mf[2][2] = t+cosine*(1-t); + mf[1][0] = ab-zxsine; + mf[0][1] = ab+zxsine; +} + +void guRotate(Mtx *m, float a, float x, float y, float z) +{ + Matrix mf; + + guRotateF(mf, a, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/rotaterpy.c b/lib/ultralib/src/gu/rotaterpy.c new file mode 100644 index 0000000..c239d21 --- /dev/null +++ b/lib/ultralib/src/gu/rotaterpy.c @@ -0,0 +1,58 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* + * Return rotation matrix given roll, pitch, and yaw in degrees + * + */ + +void guRotateRPYF(float mf[4][4], float r, float p, float h) +{ + static float dtor = 3.1415926 / 180.0; + float sinr, sinp, sinh; + float cosr, cosp, cosh; + + r *= dtor; + p *= dtor; + h *= dtor; + sinr = sinf(r); + cosr = cosf(r); + sinp = sinf(p); + cosp = cosf(p); + sinh = sinf(h); + cosh = cosf(h); + + guMtxIdentF(mf); + + mf[0][0] = cosp*cosh; + mf[0][1] = cosp*sinh; + mf[0][2] = -sinp; + + mf[1][0] = sinr*sinp*cosh - cosr*sinh; + mf[1][1] = sinr*sinp*sinh + cosr*cosh; + mf[1][2] = sinr*cosp; + + mf[2][0] = cosr*sinp*cosh + sinr*sinh; + mf[2][1] = cosr*sinp*sinh - sinr*cosh; + mf[2][2] = cosr*cosp; +} + +void guRotateRPY(Mtx *m, float r, float p, float h) +{ + Matrix mf; + + guRotateRPYF(mf, r, p, h); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/scale.c b/lib/ultralib/src/gu/scale.c new file mode 100644 index 0000000..1523cd0 --- /dev/null +++ b/lib/ultralib/src/gu/scale.c @@ -0,0 +1,32 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guScaleF(float mf[4][4], float x, float y, float z) +{ + guMtxIdentF(mf); + + mf[0][0] = x; + mf[1][1] = y; + mf[2][2] = z; + mf[3][3] = 1; +} + +void guScale(Mtx *m, float x, float y, float z) +{ + Matrix mf; + + guScaleF(mf, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/sinf.c b/lib/ultralib/src/gu/sinf.c new file mode 100644 index 0000000..f4bb1ad --- /dev/null +++ b/lib/ultralib/src/gu/sinf.c @@ -0,0 +1,157 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* ==================================================================== + * ==================================================================== + * + * Module: fsin.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:14:51 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/sinf.c,v $ + * + * Revision history: + * 09-Jun-93 - Original Version + * + * Description: source code for fsin function + * + * ==================================================================== + * ==================================================================== + */ + +#pragma weak fsin = __sinf +#pragma weak sinf = __sinf +#define fsin __sinf + +/* coefficients for polynomial approximation of sin on +/- pi/2 */ + +static const du P[] = +{ +{0x3ff00000, 0x00000000}, +{0xbfc55554, 0xbc83656d}, +{0x3f8110ed, 0x3804c2a0}, +{0xbf29f6ff, 0xeea56814}, +{0x3ec5dbdf, 0x0e314bfe}, +}; + +static const du rpi = +{0x3fd45f30, 0x6dc9c883}; + +static const du pihi = +{0x400921fb, 0x50000000}; + +static const du pilo = +{0x3e6110b4, 0x611a6263}; + +static const fu zero = {0x00000000}; + + +/* ==================================================================== + * + * FunctionName fsin + * + * Description computes sine of arg + * + * ==================================================================== + */ + +float +fsin( float x ) +{ +double dx, xsq, poly; +double dn; +int n; +double result; +int ix, xpt; + + + ix = *(int *)&x; + xpt = (ix >> 22); + xpt &= 0x1ff; + + /* xpt is exponent(x) + 1 bit of mantissa */ + + if ( xpt < 0xff ) + { + /* |x| < 1.5 */ + + dx = x; + + if ( xpt >= 0xe6 ) + { + /* |x| >= 2^(-12) */ + + /* compute sin(x) with a standard polynomial approximation */ + + xsq = dx*dx; + + poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; + + result = dx + (dx*xsq)*poly; + + return ( (float)result ); + } + + return ( x ); + } + + if ( xpt < 0x136 ) + { + /* |x| < 2^28 */ + + dx = x; + + /* reduce argument to +/- pi/2 */ + + dn = dx*rpi.d; + + n = ROUND(dn); + dn = n; + + dx = dx - dn*pihi.d; + dx = dx - dn*pilo.d; /* dx = x - n*pi */ + + /* compute sin(dx) as before, negating result if n is odd + */ + + xsq = dx*dx; + + poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; + + result = dx + (dx*xsq)*poly; + + + if ( (n & 1) == 0 ) + return ( (float)result ); + + return ( -(float)result ); + } + + if ( x != x ) + { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return ( __libm_qnan_f ); + } + + /* just give up and return 0.0 */ + + return ( zero.f ); +} + diff --git a/lib/ultralib/src/gu/sins.c b/lib/ultralib/src/gu/sins.c new file mode 100644 index 0000000..b24851f --- /dev/null +++ b/lib/ultralib/src/gu/sins.c @@ -0,0 +1,61 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* ==================================================================== + * ==================================================================== + * + * Module: sins.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:15:00 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/sins.c,v $ + * + * ==================================================================== + * ==================================================================== + */ + +/* coefficients for polynomial approximation of sin on +/- pi/2 */ + +/* ==================================================================== + * + * FunctionName sins + * + * Description computes sine of arg + * + * ==================================================================== + */ + +#include "sintable.h" + +signed short +sins( unsigned short x ) +{ + /* 0 <= x < 0x10000 ==> 0 <= x < 2PI */ + + signed short val; + + x >>= 4; /* Now range 0 <= x < 0x1000 */ + + if (x & 0x400) { + val = sintable[0x3ff - (x & 0x3ff)]; + } else { + val = sintable[x & 0x3ff]; + } + + if (x & 0x800) { + return -val; + } else { + return val; + } +} diff --git a/lib/ultralib/src/gu/sintable.h b/lib/ultralib/src/gu/sintable.h new file mode 100644 index 0000000..b5e1a45 --- /dev/null +++ b/lib/ultralib/src/gu/sintable.h @@ -0,0 +1,1031 @@ + +/* + * Do not edit this file -- it was generated by "maketable". + */ + +static signed short sintable[0x400] = { + 0x0000, + 0x0032, + 0x0064, + 0x0096, + 0x00c9, + 0x00fb, + 0x012d, + 0x0160, + 0x0192, + 0x01c4, + 0x01f7, + 0x0229, + 0x025b, + 0x028e, + 0x02c0, + 0x02f2, + 0x0324, + 0x0357, + 0x0389, + 0x03bb, + 0x03ee, + 0x0420, + 0x0452, + 0x0484, + 0x04b7, + 0x04e9, + 0x051b, + 0x054e, + 0x0580, + 0x05b2, + 0x05e4, + 0x0617, + 0x0649, + 0x067b, + 0x06ad, + 0x06e0, + 0x0712, + 0x0744, + 0x0776, + 0x07a9, + 0x07db, + 0x080d, + 0x083f, + 0x0871, + 0x08a4, + 0x08d6, + 0x0908, + 0x093a, + 0x096c, + 0x099f, + 0x09d1, + 0x0a03, + 0x0a35, + 0x0a67, + 0x0a99, + 0x0acb, + 0x0afe, + 0x0b30, + 0x0b62, + 0x0b94, + 0x0bc6, + 0x0bf8, + 0x0c2a, + 0x0c5c, + 0x0c8e, + 0x0cc0, + 0x0cf2, + 0x0d25, + 0x0d57, + 0x0d89, + 0x0dbb, + 0x0ded, + 0x0e1f, + 0x0e51, + 0x0e83, + 0x0eb5, + 0x0ee7, + 0x0f19, + 0x0f4b, + 0x0f7c, + 0x0fae, + 0x0fe0, + 0x1012, + 0x1044, + 0x1076, + 0x10a8, + 0x10da, + 0x110c, + 0x113e, + 0x116f, + 0x11a1, + 0x11d3, + 0x1205, + 0x1237, + 0x1269, + 0x129a, + 0x12cc, + 0x12fe, + 0x1330, + 0x1361, + 0x1393, + 0x13c5, + 0x13f6, + 0x1428, + 0x145a, + 0x148c, + 0x14bd, + 0x14ef, + 0x1520, + 0x1552, + 0x1584, + 0x15b5, + 0x15e7, + 0x1618, + 0x164a, + 0x167b, + 0x16ad, + 0x16df, + 0x1710, + 0x1741, + 0x1773, + 0x17a4, + 0x17d6, + 0x1807, + 0x1839, + 0x186a, + 0x189b, + 0x18cd, + 0x18fe, + 0x1930, + 0x1961, + 0x1992, + 0x19c3, + 0x19f5, + 0x1a26, + 0x1a57, + 0x1a88, + 0x1aba, + 0x1aeb, + 0x1b1c, + 0x1b4d, + 0x1b7e, + 0x1baf, + 0x1be1, + 0x1c12, + 0x1c43, + 0x1c74, + 0x1ca5, + 0x1cd6, + 0x1d07, + 0x1d38, + 0x1d69, + 0x1d9a, + 0x1dcb, + 0x1dfc, + 0x1e2d, + 0x1e5d, + 0x1e8e, + 0x1ebf, + 0x1ef0, + 0x1f21, + 0x1f52, + 0x1f82, + 0x1fb3, + 0x1fe4, + 0x2015, + 0x2045, + 0x2076, + 0x20a7, + 0x20d7, + 0x2108, + 0x2139, + 0x2169, + 0x219a, + 0x21ca, + 0x21fb, + 0x222b, + 0x225c, + 0x228c, + 0x22bd, + 0x22ed, + 0x231d, + 0x234e, + 0x237e, + 0x23ae, + 0x23df, + 0x240f, + 0x243f, + 0x2470, + 0x24a0, + 0x24d0, + 0x2500, + 0x2530, + 0x2560, + 0x2591, + 0x25c1, + 0x25f1, + 0x2621, + 0x2651, + 0x2681, + 0x26b1, + 0x26e1, + 0x2711, + 0x2740, + 0x2770, + 0x27a0, + 0x27d0, + 0x2800, + 0x2830, + 0x285f, + 0x288f, + 0x28bf, + 0x28ee, + 0x291e, + 0x294e, + 0x297d, + 0x29ad, + 0x29dd, + 0x2a0c, + 0x2a3c, + 0x2a6b, + 0x2a9b, + 0x2aca, + 0x2af9, + 0x2b29, + 0x2b58, + 0x2b87, + 0x2bb7, + 0x2be6, + 0x2c15, + 0x2c44, + 0x2c74, + 0x2ca3, + 0x2cd2, + 0x2d01, + 0x2d30, + 0x2d5f, + 0x2d8e, + 0x2dbd, + 0x2dec, + 0x2e1b, + 0x2e4a, + 0x2e79, + 0x2ea8, + 0x2ed7, + 0x2f06, + 0x2f34, + 0x2f63, + 0x2f92, + 0x2fc0, + 0x2fef, + 0x301e, + 0x304c, + 0x307b, + 0x30a9, + 0x30d8, + 0x3107, + 0x3135, + 0x3163, + 0x3192, + 0x31c0, + 0x31ef, + 0x321d, + 0x324b, + 0x3279, + 0x32a8, + 0x32d6, + 0x3304, + 0x3332, + 0x3360, + 0x338e, + 0x33bc, + 0x33ea, + 0x3418, + 0x3446, + 0x3474, + 0x34a2, + 0x34d0, + 0x34fe, + 0x352b, + 0x3559, + 0x3587, + 0x35b5, + 0x35e2, + 0x3610, + 0x363d, + 0x366b, + 0x3698, + 0x36c6, + 0x36f3, + 0x3721, + 0x374e, + 0x377c, + 0x37a9, + 0x37d6, + 0x3803, + 0x3831, + 0x385e, + 0x388b, + 0x38b8, + 0x38e5, + 0x3912, + 0x393f, + 0x396c, + 0x3999, + 0x39c6, + 0x39f3, + 0x3a20, + 0x3a4d, + 0x3a79, + 0x3aa6, + 0x3ad3, + 0x3b00, + 0x3b2c, + 0x3b59, + 0x3b85, + 0x3bb2, + 0x3bde, + 0x3c0b, + 0x3c37, + 0x3c64, + 0x3c90, + 0x3cbc, + 0x3ce9, + 0x3d15, + 0x3d41, + 0x3d6d, + 0x3d99, + 0x3dc5, + 0x3df1, + 0x3e1d, + 0x3e49, + 0x3e75, + 0x3ea1, + 0x3ecd, + 0x3ef9, + 0x3f25, + 0x3f50, + 0x3f7c, + 0x3fa8, + 0x3fd3, + 0x3fff, + 0x402b, + 0x4056, + 0x4082, + 0x40ad, + 0x40d8, + 0x4104, + 0x412f, + 0x415a, + 0x4186, + 0x41b1, + 0x41dc, + 0x4207, + 0x4232, + 0x425d, + 0x4288, + 0x42b3, + 0x42de, + 0x4309, + 0x4334, + 0x435f, + 0x4389, + 0x43b4, + 0x43df, + 0x4409, + 0x4434, + 0x445f, + 0x4489, + 0x44b4, + 0x44de, + 0x4508, + 0x4533, + 0x455d, + 0x4587, + 0x45b1, + 0x45dc, + 0x4606, + 0x4630, + 0x465a, + 0x4684, + 0x46ae, + 0x46d8, + 0x4702, + 0x472c, + 0x4755, + 0x477f, + 0x47a9, + 0x47d2, + 0x47fc, + 0x4826, + 0x484f, + 0x4879, + 0x48a2, + 0x48cc, + 0x48f5, + 0x491e, + 0x4948, + 0x4971, + 0x499a, + 0x49c3, + 0x49ec, + 0x4a15, + 0x4a3e, + 0x4a67, + 0x4a90, + 0x4ab9, + 0x4ae2, + 0x4b0b, + 0x4b33, + 0x4b5c, + 0x4b85, + 0x4bad, + 0x4bd6, + 0x4bfe, + 0x4c27, + 0x4c4f, + 0x4c78, + 0x4ca0, + 0x4cc8, + 0x4cf0, + 0x4d19, + 0x4d41, + 0x4d69, + 0x4d91, + 0x4db9, + 0x4de1, + 0x4e09, + 0x4e31, + 0x4e58, + 0x4e80, + 0x4ea8, + 0x4ed0, + 0x4ef7, + 0x4f1f, + 0x4f46, + 0x4f6e, + 0x4f95, + 0x4fbd, + 0x4fe4, + 0x500b, + 0x5032, + 0x505a, + 0x5081, + 0x50a8, + 0x50cf, + 0x50f6, + 0x511d, + 0x5144, + 0x516b, + 0x5191, + 0x51b8, + 0x51df, + 0x5205, + 0x522c, + 0x5253, + 0x5279, + 0x52a0, + 0x52c6, + 0x52ec, + 0x5313, + 0x5339, + 0x535f, + 0x5385, + 0x53ab, + 0x53d1, + 0x53f7, + 0x541d, + 0x5443, + 0x5469, + 0x548f, + 0x54b5, + 0x54da, + 0x5500, + 0x5525, + 0x554b, + 0x5571, + 0x5596, + 0x55bb, + 0x55e1, + 0x5606, + 0x562b, + 0x5650, + 0x5675, + 0x569b, + 0x56c0, + 0x56e5, + 0x5709, + 0x572e, + 0x5753, + 0x5778, + 0x579d, + 0x57c1, + 0x57e6, + 0x580a, + 0x582f, + 0x5853, + 0x5878, + 0x589c, + 0x58c0, + 0x58e5, + 0x5909, + 0x592d, + 0x5951, + 0x5975, + 0x5999, + 0x59bd, + 0x59e1, + 0x5a04, + 0x5a28, + 0x5a4c, + 0x5a6f, + 0x5a93, + 0x5ab7, + 0x5ada, + 0x5afd, + 0x5b21, + 0x5b44, + 0x5b67, + 0x5b8b, + 0x5bae, + 0x5bd1, + 0x5bf4, + 0x5c17, + 0x5c3a, + 0x5c5d, + 0x5c7f, + 0x5ca2, + 0x5cc5, + 0x5ce7, + 0x5d0a, + 0x5d2d, + 0x5d4f, + 0x5d71, + 0x5d94, + 0x5db6, + 0x5dd8, + 0x5dfa, + 0x5e1d, + 0x5e3f, + 0x5e61, + 0x5e83, + 0x5ea5, + 0x5ec6, + 0x5ee8, + 0x5f0a, + 0x5f2c, + 0x5f4d, + 0x5f6f, + 0x5f90, + 0x5fb2, + 0x5fd3, + 0x5ff4, + 0x6016, + 0x6037, + 0x6058, + 0x6079, + 0x609a, + 0x60bb, + 0x60dc, + 0x60fd, + 0x611e, + 0x613e, + 0x615f, + 0x6180, + 0x61a0, + 0x61c1, + 0x61e1, + 0x6202, + 0x6222, + 0x6242, + 0x6263, + 0x6283, + 0x62a3, + 0x62c3, + 0x62e3, + 0x6303, + 0x6323, + 0x6342, + 0x6362, + 0x6382, + 0x63a1, + 0x63c1, + 0x63e0, + 0x6400, + 0x641f, + 0x643f, + 0x645e, + 0x647d, + 0x649c, + 0x64bb, + 0x64da, + 0x64f9, + 0x6518, + 0x6537, + 0x6556, + 0x6574, + 0x6593, + 0x65b2, + 0x65d0, + 0x65ef, + 0x660d, + 0x662b, + 0x664a, + 0x6668, + 0x6686, + 0x66a4, + 0x66c2, + 0x66e0, + 0x66fe, + 0x671c, + 0x673a, + 0x6757, + 0x6775, + 0x6792, + 0x67b0, + 0x67cd, + 0x67eb, + 0x6808, + 0x6825, + 0x6843, + 0x6860, + 0x687d, + 0x689a, + 0x68b7, + 0x68d4, + 0x68f1, + 0x690d, + 0x692a, + 0x6947, + 0x6963, + 0x6980, + 0x699c, + 0x69b9, + 0x69d5, + 0x69f1, + 0x6a0e, + 0x6a2a, + 0x6a46, + 0x6a62, + 0x6a7e, + 0x6a9a, + 0x6ab5, + 0x6ad1, + 0x6aed, + 0x6b08, + 0x6b24, + 0x6b40, + 0x6b5b, + 0x6b76, + 0x6b92, + 0x6bad, + 0x6bc8, + 0x6be3, + 0x6bfe, + 0x6c19, + 0x6c34, + 0x6c4f, + 0x6c6a, + 0x6c84, + 0x6c9f, + 0x6cba, + 0x6cd4, + 0x6cef, + 0x6d09, + 0x6d23, + 0x6d3e, + 0x6d58, + 0x6d72, + 0x6d8c, + 0x6da6, + 0x6dc0, + 0x6dda, + 0x6df3, + 0x6e0d, + 0x6e27, + 0x6e40, + 0x6e5a, + 0x6e73, + 0x6e8d, + 0x6ea6, + 0x6ebf, + 0x6ed9, + 0x6ef2, + 0x6f0b, + 0x6f24, + 0x6f3d, + 0x6f55, + 0x6f6e, + 0x6f87, + 0x6fa0, + 0x6fb8, + 0x6fd1, + 0x6fe9, + 0x7002, + 0x701a, + 0x7032, + 0x704a, + 0x7062, + 0x707a, + 0x7092, + 0x70aa, + 0x70c2, + 0x70da, + 0x70f2, + 0x7109, + 0x7121, + 0x7138, + 0x7150, + 0x7167, + 0x717e, + 0x7196, + 0x71ad, + 0x71c4, + 0x71db, + 0x71f2, + 0x7209, + 0x7220, + 0x7236, + 0x724d, + 0x7264, + 0x727a, + 0x7291, + 0x72a7, + 0x72bd, + 0x72d4, + 0x72ea, + 0x7300, + 0x7316, + 0x732c, + 0x7342, + 0x7358, + 0x736e, + 0x7383, + 0x7399, + 0x73ae, + 0x73c4, + 0x73d9, + 0x73ef, + 0x7404, + 0x7419, + 0x742e, + 0x7443, + 0x7458, + 0x746d, + 0x7482, + 0x7497, + 0x74ac, + 0x74c0, + 0x74d5, + 0x74ea, + 0x74fe, + 0x7512, + 0x7527, + 0x753b, + 0x754f, + 0x7563, + 0x7577, + 0x758b, + 0x759f, + 0x75b3, + 0x75c7, + 0x75da, + 0x75ee, + 0x7601, + 0x7615, + 0x7628, + 0x763b, + 0x764f, + 0x7662, + 0x7675, + 0x7688, + 0x769b, + 0x76ae, + 0x76c1, + 0x76d3, + 0x76e6, + 0x76f9, + 0x770b, + 0x771e, + 0x7730, + 0x7742, + 0x7754, + 0x7767, + 0x7779, + 0x778b, + 0x779d, + 0x77af, + 0x77c0, + 0x77d2, + 0x77e4, + 0x77f5, + 0x7807, + 0x7818, + 0x782a, + 0x783b, + 0x784c, + 0x785d, + 0x786e, + 0x787f, + 0x7890, + 0x78a1, + 0x78b2, + 0x78c3, + 0x78d3, + 0x78e4, + 0x78f4, + 0x7905, + 0x7915, + 0x7925, + 0x7936, + 0x7946, + 0x7956, + 0x7966, + 0x7976, + 0x7985, + 0x7995, + 0x79a5, + 0x79b5, + 0x79c4, + 0x79d4, + 0x79e3, + 0x79f2, + 0x7a02, + 0x7a11, + 0x7a20, + 0x7a2f, + 0x7a3e, + 0x7a4d, + 0x7a5b, + 0x7a6a, + 0x7a79, + 0x7a87, + 0x7a96, + 0x7aa4, + 0x7ab3, + 0x7ac1, + 0x7acf, + 0x7add, + 0x7aeb, + 0x7af9, + 0x7b07, + 0x7b15, + 0x7b23, + 0x7b31, + 0x7b3e, + 0x7b4c, + 0x7b59, + 0x7b67, + 0x7b74, + 0x7b81, + 0x7b8e, + 0x7b9b, + 0x7ba8, + 0x7bb5, + 0x7bc2, + 0x7bcf, + 0x7bdc, + 0x7be8, + 0x7bf5, + 0x7c02, + 0x7c0e, + 0x7c1a, + 0x7c27, + 0x7c33, + 0x7c3f, + 0x7c4b, + 0x7c57, + 0x7c63, + 0x7c6f, + 0x7c7a, + 0x7c86, + 0x7c92, + 0x7c9d, + 0x7ca9, + 0x7cb4, + 0x7cbf, + 0x7ccb, + 0x7cd6, + 0x7ce1, + 0x7cec, + 0x7cf7, + 0x7d02, + 0x7d0c, + 0x7d17, + 0x7d22, + 0x7d2c, + 0x7d37, + 0x7d41, + 0x7d4b, + 0x7d56, + 0x7d60, + 0x7d6a, + 0x7d74, + 0x7d7e, + 0x7d88, + 0x7d91, + 0x7d9b, + 0x7da5, + 0x7dae, + 0x7db8, + 0x7dc1, + 0x7dcb, + 0x7dd4, + 0x7ddd, + 0x7de6, + 0x7def, + 0x7df8, + 0x7e01, + 0x7e0a, + 0x7e13, + 0x7e1b, + 0x7e24, + 0x7e2c, + 0x7e35, + 0x7e3d, + 0x7e45, + 0x7e4d, + 0x7e56, + 0x7e5e, + 0x7e66, + 0x7e6d, + 0x7e75, + 0x7e7d, + 0x7e85, + 0x7e8c, + 0x7e94, + 0x7e9b, + 0x7ea3, + 0x7eaa, + 0x7eb1, + 0x7eb8, + 0x7ebf, + 0x7ec6, + 0x7ecd, + 0x7ed4, + 0x7edb, + 0x7ee1, + 0x7ee8, + 0x7eee, + 0x7ef5, + 0x7efb, + 0x7f01, + 0x7f08, + 0x7f0e, + 0x7f14, + 0x7f1a, + 0x7f20, + 0x7f25, + 0x7f2b, + 0x7f31, + 0x7f36, + 0x7f3c, + 0x7f41, + 0x7f47, + 0x7f4c, + 0x7f51, + 0x7f56, + 0x7f5b, + 0x7f60, + 0x7f65, + 0x7f6a, + 0x7f6f, + 0x7f74, + 0x7f78, + 0x7f7d, + 0x7f81, + 0x7f85, + 0x7f8a, + 0x7f8e, + 0x7f92, + 0x7f96, + 0x7f9a, + 0x7f9e, + 0x7fa2, + 0x7fa6, + 0x7fa9, + 0x7fad, + 0x7fb0, + 0x7fb4, + 0x7fb7, + 0x7fba, + 0x7fbe, + 0x7fc1, + 0x7fc4, + 0x7fc7, + 0x7fca, + 0x7fcc, + 0x7fcf, + 0x7fd2, + 0x7fd4, + 0x7fd7, + 0x7fd9, + 0x7fdc, + 0x7fde, + 0x7fe0, + 0x7fe2, + 0x7fe4, + 0x7fe6, + 0x7fe8, + 0x7fea, + 0x7fec, + 0x7fed, + 0x7fef, + 0x7ff1, + 0x7ff2, + 0x7ff3, + 0x7ff5, + 0x7ff6, + 0x7ff7, + 0x7ff8, + 0x7ff9, + 0x7ffa, + 0x7ffb, + 0x7ffb, + 0x7ffc, + 0x7ffd, + 0x7ffd, + 0x7ffe, + 0x7ffe, + 0x7ffe, + 0x7ffe, + 0x7ffe, + 0x7fff, +}; diff --git a/lib/ultralib/src/gu/sqrtf.s b/lib/ultralib/src/gu/sqrtf.s new file mode 100644 index 0000000..475a827 --- /dev/null +++ b/lib/ultralib/src/gu/sqrtf.s @@ -0,0 +1,25 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/* + * Due to compiler bug, it won't insert a sqrt.s opcode in the stream so we + * make a function and call it for now. When compiler fixed, also remove the + * seperate Makefile rules + */ + +#include "sys/asm.h" +#include "sys/regdef.h" + +LEAF(sqrtf) + sqrt.s fv0, fa0 + j ra +END(sqrtf) diff --git a/lib/ultralib/src/gu/translate.c b/lib/ultralib/src/gu/translate.c new file mode 100644 index 0000000..f086f39 --- /dev/null +++ b/lib/ultralib/src/gu/translate.c @@ -0,0 +1,31 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guTranslateF(float mf[4][4], float x, float y, float z) +{ + guMtxIdentF(mf); + + mf[3][0] = x; + mf[3][1] = y; + mf[3][2] = z; +} + +void guTranslate(Mtx *m, float x, float y, float z) +{ + Matrix mf; + + guTranslateF(mf, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/gu/us2dex.c b/lib/ultralib/src/gu/us2dex.c new file mode 100644 index 0000000..92f42bb --- /dev/null +++ b/lib/ultralib/src/gu/us2dex.c @@ -0,0 +1,73 @@ +/*--------------------------------------------------------------------- + $Id: us2dex.c,v 1.4 1998/10/09 06:15:30 has Exp $ + + File : us2dex.c + + Coded by Yoshitaka Yasumoto. Mar 19, 1997. + Copyright by Nintendo, Co., Ltd. 1997. + ---------------------------------------------------------------------*/ +#include +#include + +/* + * Routines that support processing of S2DEX microcode + */ + +/* + * guS2DInitBG + * Set BG screen draw parameters + * + * If called at time of initialization, then it only needs to be + * called again when changes made to imageFmt, imageSiz, imageLoad, * imageW, frameW. However, if imageLoad == G_BGLT_LOADBLOCK and * only frameW is changed, another call is unnecessary. + */ +void guS2DInitBg(uObjBg *bg) +{ + u16 tmemUse; + u16 shift; +#if BUILD_VERSION >= VERSION_J + u32 tsize; +#endif + + /* + * Get the useable volume for TMEM + * If imageFmt is CI then TLUT will use half. + */ + tmemUse = (bg->b.imageFmt == G_IM_FMT_CI) ? 256 : 512; + + /* + * Get shift volume for conversion to TMEM word. + */ + shift = 6 - bg->b.imageSiz; + + /* + * Set other parameters for Load Mode. + */ + if (bg->b.imageLoad == G_BGLT_LOADBLOCK){ + bg->b.tmemW = bg->b.imageW >> shift; + bg->b.tmemH = (tmemUse / bg->b.tmemW) << 2; + bg->b.tmemSizeW = bg->b.tmemW << 1; + bg->b.tmemSize = bg->b.tmemH * bg->b.tmemSizeW; + bg->b.tmemLoadSH = (bg->b.tmemSize>>1) - 1; + bg->b.tmemLoadTH = GS_CALC_DXT(bg->b.tmemW); + } else { +#if BUILD_VERSION >= VERSION_J + bg->b.tmemW = (bg->b.frameW >> shift) + 3; + bg->b.tmemH = (tmemUse / bg->b.tmemW) << 2; + bg->b.tmemSizeW = (bg->b.imageW >> shift) * 2; + tsize = bg->b.tmemH * bg->b.tmemSizeW; + bg->b.tmemSize = tsize >> 16; + bg->b.tmemLoadSH = tsize & 0xffff; + bg->b.tmemLoadTH = bg->b.tmemH - 1; +#else + bg->b.tmemW = (bg->b.frameW >> shift) + 1; + bg->b.tmemH = (tmemUse / bg->b.tmemW) << 2; + bg->b.tmemSizeW = (bg->b.imageW >> shift) * 2; + bg->b.tmemSize = bg->b.tmemH * bg->b.tmemSizeW; + bg->b.tmemLoadSH = (bg->b.tmemW<<4) - 1; + bg->b.tmemLoadTH = bg->b.tmemH - 1; +#endif + } + return; +} + +/*======== End of us2dex.c ========*/ diff --git a/lib/ultralib/src/gu/us2dex2_emu.c b/lib/ultralib/src/gu/us2dex2_emu.c new file mode 100644 index 0000000..cc32179 --- /dev/null +++ b/lib/ultralib/src/gu/us2dex2_emu.c @@ -0,0 +1,12 @@ +/*---------------------------------------------------------------------* + Copyright (C) 1998, Nintendo. + + File us2dex2_emu.c + Coded by Yoshitaka Yasumoto. Apr 10, 1998. + + $Id: us2dex2_emu.c,v 1.3 1998/10/09 06:15:40 has Exp $ + *---------------------------------------------------------------------*/ +#define F3DEX_GBI_2 +#include "us2dex_emu.c" + +/*======== End of us2dex2_emu.c ========*/ diff --git a/lib/ultralib/src/gu/us2dex_emu.c b/lib/ultralib/src/gu/us2dex_emu.c new file mode 100644 index 0000000..c0a9e30 --- /dev/null +++ b/lib/ultralib/src/gu/us2dex_emu.c @@ -0,0 +1,521 @@ +/*---------------------------------------------------------------------* + Copyright (C) 1998, Nintendo. + + File us2dex_emu.c + Coded by Yoshitaka Yasumoto. Apr 9, 1998. + + $Id: us2dex_emu.c,v 1.9 1999/07/08 05:02:04 yurugi Exp $ + *---------------------------------------------------------------------*/ +#define F3DEX_GBI +#include +#include + +#define RSP_DEBUG + +static u16 scissorX0 = 0; /* (s13.2) */ +static u16 scissorY0 = 0; /* (s13.2) */ +static u16 scissorX1 = 320<<2; /* (s13.2) */ +static u16 scissorY1 = 240<<2; /* (s13.2) */ +static u8 flagBilerp = 0; + +static u32 rdpSetTimg_w0, rdpSetTile_w0; +static u16 tmemSliceWmax; +static u16 imageSrcWsize; +static s16 flagSplit; +static u16 imagePtrX0; +static u32 imageTop; +static s16 tmemSrcLines; + +/* Addition 99/05/31(Y) */ +#if BUILD_VERSION >= VERSION_K +static s8 bgflg; +#endif + +/*----------------------------------------------------------------------------* + * Set scissoring parameters + * *---------------------------------------------------------------------------*/ +void guS2DEmuSetScissor(u32 ulx, u32 uly, u32 lrx, u32 lry, u8 flag) +{ + scissorX0 = (u16)ulx << 2; + scissorY0 = (u16)uly << 2; + scissorX1 = (u16)lrx << 2; + scissorY1 = (u16)lry << 2; + flagBilerp = (flag) ? 1 : 0; +} + +/*---------------------------------------------------------------------------* + * Create texture load RDP commands + *---------------------------------------------------------------------------*/ +static void tmemLoad_B(Gfx **pkt, u32 imagePtr, s16 loadLines, s16 tmemSH) +{ + /* + * Load 16-bit texture of tmemSH word width starting from imagePtr + * into the loadLines amount of lines of tmem. + */ + + /* [SetTImg] CMD=0x3d FMT=RGBA(0) SIZ=16b(2) */ + (*pkt)->words.w0 = rdpSetTimg_w0; + (*pkt)->words.w1 = imagePtr; + (*pkt) ++; + + /* [LoadSync] Wait for completion of preceding primitive draw */ + (*pkt)->words.w0 = (G_RDPLOADSYNC<<24); + (*pkt) ++; + + /* [LoadTile] CMD=0x34 TILE=7 SH=TMEMW*16-1 TMEMH*4-1 */ + (*pkt)->words.w0 = (G_LOADTILE<<24)|0x000000; +/* addition 99/5/31(Y) */ +#if BUILD_VERSION >= VERSION_K + if(bgflg==3) (*pkt)->words.w1 = 0x07000000 | (tmemSH-1)<<16; + else (*pkt)->words.w1 = 0x07000000 | (tmemSH-1)<<16 | (loadLines<<2)-1; +#else + (*pkt)->words.w1 = 0x07000000 | (tmemSH-1)<<16 | (loadLines<<2)-1; +#endif + (*pkt) ++; +} + +static void tmemLoad_A(Gfx **pkt, u32 imagePtr, + s16 loadLines, s16 tmemAdrs, s16 tmemSH) +{ + /* + * Load 16-bit texture of tmemSH word width starting from imagePtr into + * the loadLines amount of lines of the tmemAdrs of tmem. + */ + + /* [TileSync] Wait for completion of Tile access of preceding command */ + (*pkt)->words.w0 = 0xe8000000; + (*pkt) ++; + + /* [SetTile] */ + (*pkt)->words.w0 = rdpSetTile_w0|tmemAdrs; + (*pkt)->words.w1 = 0x07000000; + (*pkt) ++; + + tmemLoad_B(pkt, imagePtr, loadLines, tmemSH); +} + +static void tmemLoad(Gfx **pkt, u32 *imagePtr, + s16 *imageRemain, s16 drawLines, s16 flagBilerp) +{ + s16 loadLines = drawLines + flagBilerp; + s16 iLoadable = (*imageRemain) - flagSplit; + + if (iLoadable >= loadLines){ /* If load can be done all at once */ + tmemLoad_B(pkt, *imagePtr, loadLines, tmemSliceWmax); + (*imagePtr) += imageSrcWsize * drawLines; + (*imageRemain) -= drawLines; + + } else { /* If load is to be partitioned */ + s16 SubSliceL2, SubSliceD2, SubSliceY2; + u32 imageTopSeg = imageTop & 0xff000000; + + SubSliceY2 = *imageRemain; + SubSliceL2 = loadLines - SubSliceY2; + SubSliceD2 = drawLines - SubSliceY2; + + if (SubSliceL2 > 0){ + u32 imagePtr2; + + imagePtr2 = imageTop + imagePtrX0; + if (SubSliceY2 & 1){ + imagePtr2 -= imageSrcWsize; + imagePtr2 = imageTopSeg | (imagePtr2 & 0x00ffffff); /*Segment counterm */ + SubSliceY2 --; + SubSliceL2 ++; + } + tmemLoad_A(pkt, imagePtr2, + SubSliceL2, SubSliceY2 * tmemSliceWmax, tmemSliceWmax); + } + if (flagSplit){ + u32 imagePtr1A, imagePtr1B; + s16 SubSliceY1, SubSliceL1; + s16 tmemSH_A, tmemSH_B; + + imagePtr1A = (*imagePtr) + iLoadable * imageSrcWsize; + imagePtr1B = imageTop; + SubSliceY1 = iLoadable; + if (SubSliceL1 = iLoadable & 1){ + imagePtr1A -= imageSrcWsize; + imagePtr1B -= imageSrcWsize; + imagePtr1B = imageTopSeg | (imagePtr1B & 0x00ffffff); /*Segment countermeasure */ + SubSliceY1 --; + } + SubSliceL1 ++; + tmemSH_A = (imageSrcWsize - imagePtrX0) >> 3; + tmemSH_B = tmemSliceWmax - tmemSH_A; + tmemLoad_A(pkt, imagePtr1B, + SubSliceL1, SubSliceY1 * tmemSliceWmax + tmemSH_A, tmemSH_B); + tmemLoad_A(pkt, imagePtr1A, + SubSliceL1, SubSliceY1 * tmemSliceWmax, tmemSH_A); + } + if (iLoadable > 0){ + + tmemLoad_A(pkt, *imagePtr, iLoadable, 0, tmemSliceWmax); + + } else { + + /* [SetTile] */ + (*pkt)->words.w0 = rdpSetTile_w0; + (*pkt)->words.w1 = 0x07000000; + (*pkt) ++; + } + + (*imageRemain) -= drawLines; + if ((*imageRemain) > 0){ + (*imagePtr) += imageSrcWsize * drawLines; + } else { + (*imageRemain) = tmemSrcLines - SubSliceD2; + (*imagePtr) = imageTop + SubSliceD2 * imageSrcWsize + imagePtrX0; + } + + } +} + +/*---------------------------------------------------------------------------* + * Scalable BG serface draw process + *---------------------------------------------------------------------------*/ +void guS2DEmuBgRect1Cyc(Gfx **pkt, uObjBg *bg) +{ + s16 frameX0, frameX1, framePtrY0, frameRemain; + s16 imageX0, imageY0, imageSliceW, imageW; + s32 imageYorig; + s16 scaleW, scaleH; + + s16 imageSrcW, imageSrcH; + s16 tmemSliceLines, imageSliceLines; + s32 frameSliceLines, frameSliceCount; + u16 imageS, imageT; + u32 imagePtr; + + s16 imageISliceL0, imageIY0; + s32 frameLSliceL0; + + scaleW = bg->s.scaleW; + scaleH = bg->s.scaleH; + +/* addition 99/05/31(Y) */ +#if BUILD_VERSION >= VERSION_K + bgflg=bg->s.imageSiz; + if(scaleW==0) scaleW=1; + if(scaleH==0) scaleH=1; +#endif + + +{ + /*-------------------------------------------------* + Scissoring process + *-------------------------------------------------*/ + /* + / frameX0, frameX1, framePtrY0, frameRemain + / imageX0, imageY0, tmemSliceW + / imageSrcW, imageSrcH + */ + s16 pixX0, pixY0, pixX1, pixY1; /* (s13.2) */ + s16 frameY0, frameW, frameH; + s32 frameWmax, frameHmax; + + /* Determine maximum frame size from image and enlargement ratio */ + frameWmax = ((((s32)bg->s.imageW << 10) / scaleW)-1) & ~3; + frameHmax = ((((s32)bg->s.imageH << 10) / scaleH)-1) & ~3; + + /* Clamp the frame size */ + frameW = bg->s.frameW; + frameH = bg->s.frameH; + frameX0 = bg->s.frameX; + frameY0 = bg->s.frameY; + if ((frameWmax = bg->s.frameW - frameWmax) < 0) frameWmax = 0; + if ((frameHmax = bg->s.frameH - frameHmax) < 0) frameHmax = 0; + frameW -= frameWmax; + frameH -= frameHmax; + if (bg->s.imageFlip & G_BG_FLAG_FLIPS){ + frameX0 += frameWmax; + } + + /* Caluculate amount of projection from screen */ + pixX0 = scissorX0 - frameX0; /* (s13.2) */ + pixY0 = scissorY0 - frameY0; /* (s13.2) */ + pixX1 = frameW - scissorX1 + frameX0; /* (s13.2) */ + pixY1 = frameH - scissorY1 + frameY0; /* (s13.2) */ + + /* Clamp if no projection */ + if (pixX0 < 0) pixX0 = 0; + if (pixY0 < 0) pixY0 = 0; + if (pixX1 < 0) pixX1 = 0; + if (pixY1 < 0) pixY1 = 0; + + /* Cut the part that is projecting */ + frameW = frameW - (pixX0 + pixX1); /* (s13.2) */ + frameH = frameH - (pixY0 + pixY1); /* (s13.2) */ + frameX0 = frameX0 + pixX0; /* (s13.2) */ + frameY0 = frameY0 + pixY0; /* (s13.2) */ + + /* Terminate if no draw range remains */ + if (frameW <= 0 || frameH <= 0) return; + + /* Caluculate frame */ + frameX1 = frameX0 + frameW; /* (s13.2) */ + framePtrY0 = frameY0 >> 2; /* (s15.0) */ + frameRemain = frameH >> 2; /* (s15.0) */ + + /* Join image columns */ + imageSrcW = bg->s.imageW << 3; /* (u11.5) */ + imageSrcH = bg->s.imageH << 3; /* (u11.5) */ + + /* Get image range (u14.2)*(u6.10)=(u20.12)->(u11.5) */ + imageSliceW = (imageW = frameW * scaleW >> 7) + flagBilerp * 32; + if (bg->s.imageFlip & G_BG_FLAG_FLIPS){ + imageX0 = bg->s.imageX + (pixX1 * scaleW >> 7); /* (s10.5) */ + } else { + imageX0 = bg->s.imageX + (pixX0 * scaleW >> 7); /* (s10.5) */ + } + imageY0 = bg->s.imageY + (pixY0 * scaleH >> 7); /* (s10.5) */ + imageYorig = bg->s.imageYorig; + + /* Loop one step down when left end of image area is greater than right end of image source */ + while (imageX0 >= imageSrcW){ + imageX0 -= imageSrcW; + imageY0 += 32; + imageYorig += 32; /* Add 1 to carrier */ + } + + /* Loop when top end of image area is greater than bottom end of image source */ + while (imageY0 >= imageSrcH){ + imageY0 -= imageSrcH; + imageYorig -= imageSrcH; + } +} + +{ + /*-------------------------------------------------* + Check process connecting top and bottom of image + *-------------------------------------------------*/ + /* + // flagSplit + // tmemSrcLines + // imageSrcLines + */ + /* Top/bottom connection process necessary when image range straddles right +end */ + flagSplit = (imageX0 + imageSliceW >= imageSrcW); + + /* Number of image lines that can be loaded at once */ + tmemSrcLines = imageSrcH >> 5; +} + +{ + /*-------------------------------------------------* + Get load data for TMEM + *-------------------------------------------------*/ + /* + //Calculate number of lines that can be loaded into TMEM. + // If the slice width changes due to scissoring and the linked + // load line number is changed, then the frame division line will + // change and the result will be the generation of unnatural wrinkles. + // To prevent this, the division region is set such that scissoring + // does not occur. + // + */ + s16 tmemSize, tmemMask, tmemShift; + s32 imageNumSlice; + s32 imageSliceWmax; + s32 imageLYoffset, frameLYoffset; + s32 imageLHidden, frameLHidden; + s32 frameLYslice; + + static s16 TMEMSIZE[] = { 512, 512, 256, 512, 512 }; + static s16 TMEMMASK[] = { 0x1ff, 0xff, 0x7f, 0x3f }; + static s16 TMEMSHIFT[] = { 0x200, 0x100, 0x80, 0x40 }; + tmemSize = TMEMSIZE[bg->s.imageFmt]; /* (s15.0) */ + tmemMask = TMEMMASK[bg->s.imageSiz]; /* (s10.5) */ + tmemShift = TMEMSHIFT[bg->s.imageSiz]; /* (s10.5)->(s15.0) */ + + /* Calculate tmem width to accommodate the slice image width */ + /* o Extra is needed at Bilerp time. + // o Clamp slice image width based on image source width. + // o Cut image width end number at TMEM Word boundary. + // o tmem width + 1 when start position not in agreement with Word boundary */ +/* addition 99/05/31(Y) */ +#if BUILD_VERSION >= VERSION_K + if(bgflg==3){ + tmemSize=480; + imageSliceWmax = 0x2800; + } + else{ + imageSliceWmax = (((s32)bg->s.frameW * (s32)scaleW)>>7) + (flagBilerp<<5); + if (imageSliceWmax > imageSrcW) imageSliceWmax = imageSrcW; + } +#else + imageSliceWmax = (((s32)bg->s.frameW * (s32)scaleW)>>7) + (flagBilerp<<5); + if (imageSliceWmax > imageSrcW) imageSliceWmax = imageSrcW; +#endif + + tmemSliceWmax = (imageSliceWmax + tmemMask) / tmemShift + 1; + + /* Get TMEM/image/frame line number that can be loaded at once */ + tmemSliceLines = tmemSize / tmemSliceWmax; /* (s15.0) */ + imageSliceLines = tmemSliceLines - flagBilerp; /* (s15.0) */ + frameSliceLines = (imageSliceLines << 20) / scaleH; /* (s21.10) */ + + /* Line up image Y coordinate offset value with frame image */ + imageLYoffset = ((s32)imageY0 - imageYorig) << 5; + if (imageLYoffset < 0) imageLYoffset -= (scaleH - 1); + frameLYoffset = imageLYoffset / scaleH; + frameLYoffset <<= 10; + + /* Get slice number corresponding to image Y */ + if (frameLYoffset >= 0){ + imageNumSlice = frameLYoffset / frameSliceLines; + } else { + imageNumSlice = (frameLYoffset - frameSliceLines + 1) / frameSliceLines; + } + + /* Calculate extent to which first draw slice is hidden at top of frame */ + frameLYslice = (frameLSliceL0 = frameSliceLines * imageNumSlice) & ~1023; + frameLHidden = frameLYoffset - frameLYslice; + imageLHidden = (frameLHidden >> 10) * scaleH; + + /* Calculate fram size of first draw slice */ + frameLSliceL0 = (frameLSliceL0 & 1023) + frameSliceLines - frameLHidden; + + /* Calculate image parameters for draw in midst of slice */ + imageT = (imageLHidden >> 5) & 31; + imageLHidden >>= 10; + imageISliceL0 = imageSliceLines - imageLHidden; + imageIY0 = + imageSliceLines * imageNumSlice + (imageYorig & ~31) / 32 + imageLHidden; + if (imageIY0 < 0) imageIY0 += (bg->s.imageH >> 2); + if (imageIY0 >= (bg->s.imageH >> 2)) imageIY0 -= (bg->s.imageH >> 2); + imageTop = (u32)bg->s.imagePtr; /* (u32.0) */ + imageSrcWsize = (imageSrcW / tmemShift) << 3; /* (u16.0) */ + imagePtrX0 = (imageX0 / tmemShift) << 3; /* (u16.0) */ + imagePtr = imageTop + imageSrcWsize * imageIY0 + imagePtrX0; + + /* S invert process */ + imageS = imageX0 & tmemMask; /* (u10.5) */ + if (bg->s.imageFlip & G_BG_FLAG_FLIPS){ + imageS = - (imageS + imageW); + } +} + +{ + /*-------------------------------------------------* + Creating RDP command constant values + *-------------------------------------------------*/ + /* u32 rdpSetTimg_w0; + u32 rdpSetTile_w0; */ +/* Addition 99/05/31(Y) */ +#if BUILD_VERSION >= VERSION_K + if(bgflg==3){ + rdpSetTimg_w0 = (G_SETTIMG<<24)+0x180000+(imageSrcWsize>>1)-1; + rdpSetTile_w0 = (G_SETTILE<<24)+0x180000+(tmemSliceWmax<<9); + } + else{ + rdpSetTimg_w0 = (G_SETTIMG<<24)+0x100000+(imageSrcWsize>>1)-1; + rdpSetTile_w0 = (G_SETTILE<<24)+0x100000+(tmemSliceWmax<<9); + } +#else + rdpSetTimg_w0 = (G_SETTIMG<<24)+0x100000+(imageSrcWsize>>1)-1; + rdpSetTile_w0 = (G_SETTILE<<24)+0x100000+(tmemSliceWmax<<9); +#endif + /* [SetTile:7] */ + (*pkt)->words.w0 = rdpSetTile_w0; + (*pkt)->words.w1 = 0x07000000; + (*pkt)++; + /* [SetTile:0] */ + (*pkt)->words.w0 = rdpSetTile_w0; + ((u8 *)&((*pkt)->words.w0))[1] = (bg->s.imageFmt<<5)|(bg->s.imageSiz<<3); + (*pkt)->words.w1 = 0x0007c1f0 | (bg->s.imagePal<<20); + (*pkt)++; + /* [SetTileSize:7] */ + (*pkt)->words.w0 = (G_SETTILESIZE<<24)|0x000000; + (*pkt)->words.w1 = 0x00000000; + (*pkt)++; +} + +{ + s16 imageRemain; + s16 imageSliceH, frameSliceH; + + imageRemain = tmemSrcLines - imageIY0; + imageSliceH = imageISliceL0; + frameSliceCount = frameLSliceL0; + + while(1){ + + /* Calculate draw line number and determine whether to perform a draw */ + frameSliceH = frameSliceCount >> 10; + if (frameSliceH <= 0){ + /* If no draw to be performed */ + imageRemain -= imageSliceH; + if (imageRemain > 0){ + imagePtr += imageSrcWsize * imageSliceH; + } else { + imagePtr = imageTop - (imageRemain * imageSrcWsize) + imagePtrX0; + imageRemain += tmemSrcLines; + } + + } else { + /* If draw to be performed */ + s16 framePtrY1; + + frameSliceCount &= 1023; + if ((frameRemain -= frameSliceH) < 0){ + /* Determine final slice */ + frameSliceH += frameRemain; + imageSliceH += ((frameRemain * scaleH) >> 10) + 1; + if (imageSliceH > imageSliceLines) imageSliceH = imageSliceLines; + } + tmemLoad(pkt, &imagePtr, &imageRemain, imageSliceH, flagBilerp); + + /* Get draw frame range */ + framePtrY1 = framePtrY0 + frameSliceH; /* (s15.0) */ + + /* [PipeSync] Wait for end of preceding LOADTILE command */ + (*pkt)->words.w0 = (G_RDPPIPESYNC<<24); + (*pkt) ++; + + /* Rectangle draw */ + /* Here an RSP command is created. With ucode an RDP command is created */ +#if 1 + { + /* [TextureRectangle] */ + (*pkt)->words.w0 = (G_TEXRECT<<24)|(frameX1<<12)|(framePtrY1<<2); + (*pkt)->words.w1 = (frameX0<<12)|(framePtrY0<<2); + (*pkt) ++; +#else + /* Code for checking slice division line */ + if (frameSliceH > 1){ + (*pkt)->words.w0 = (G_TEXRECT<<24)|(frameX1<<12)|(framePtrY1<<2)-4; + (*pkt)->words.w1 = (frameX0<<12)|(framePtrY0<<2); + (*pkt) ++; +#endif + +#if 0 /* At RDP command creation time */ + (*pkt)->words.w0 = (imageS<<16) | imageT; + (*pkt)->words.w1 = (scaleW<<16) | scaleH; +#else /* At RSP command creation time */ + (*pkt)->words.w0 = (G_RDPHALF_1<<24); + (*pkt)->words.w1 = (imageS<<16) | imageT; + (*pkt) ++; + (*pkt)->words.w0 = (G_RDPHALF_2<<24); + (*pkt)->words.w1 = (scaleW<<16) | scaleH; +#endif + (*pkt) ++; + } + + /* Update region */ + framePtrY0 = framePtrY1; + + /* End if no more undrawn line numbers for frame */ + if (frameRemain <= 0){ + return; + } + } + frameSliceCount += frameSliceLines; + imageSliceH = imageSliceLines; + imageT = 0; + } +} +} + +/*======== End of us2dex_emu.c ========*/ diff --git a/lib/ultralib/src/gu/usprite.c b/lib/ultralib/src/gu/usprite.c new file mode 100644 index 0000000..a10ed34 --- /dev/null +++ b/lib/ultralib/src/gu/usprite.c @@ -0,0 +1,39 @@ + +/************************************************************************** + * * + * Copyright (C) 1996, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "gbi.h" + +void guSprite2DInit(uSprite *SpritePointer, + void *SourceImagePointer, + void *TlutPointer, + short Stride, + short SubImageWidth, + short SubImageHeight, + char SourceImageType, + char SourceImageBitSize, + short SourceImageOffsetS, + short SourceImageOffsetT) +{ + SpritePointer->s.SourceImagePointer = SourceImagePointer; + SpritePointer->s.TlutPointer = TlutPointer; + SpritePointer->s.Stride = Stride; + SpritePointer->s.SubImageWidth = SubImageWidth; + SpritePointer->s.SubImageHeight = SubImageHeight; + SpritePointer->s.SourceImageType = SourceImageType; + SpritePointer->s.SourceImageBitSize = SourceImageBitSize; + SpritePointer->s.SourceImageOffsetS = SourceImageOffsetS; + SpritePointer->s.SourceImageOffsetT = SourceImageOffsetT; +} + + + diff --git a/lib/ultralib/src/host/host_ptn64.c b/lib/ultralib/src/host/host_ptn64.c new file mode 100644 index 0000000..54e5e9e --- /dev/null +++ b/lib/ultralib/src/host/host_ptn64.c @@ -0,0 +1,209 @@ +#include "PR/os_internal.h" +#include "PR/os_version.h" +#include "PR/rcp.h" +#include "memory.h" + +#include "macros.h" + +#if BUILD_VERSION >= VERSION_J || !defined(_FINALROM) + +static volatile unsigned int* ptwtmode = (unsigned*)0xbff08014; +static volatile unsigned int* ptstat = (unsigned*)0xbff08004; +static volatile unsigned int* ptport = (unsigned*)0xbff08000; +static volatile unsigned int* n64piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); + +static OSMesgQueue waitPtQueue ALIGNED(8); +static OSMesg waitPtQueueBuf; +static u32 isWaitPtQueueCreated = FALSE; + +void __osPiRelAccess(void); +void __osPiGetAccess(void); + +static void createWaitPtQueue(void) { + osCreateMesgQueue(&waitPtQueue, &waitPtQueueBuf, 1); + isWaitPtQueueCreated = TRUE; +} + +static u32 getPT_wait(void) { + OSTimer waitTimer; + u32 status UNUSED; + + for (;;) { + while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + ; + } + + if (*ptstat & 2) { + return *ptport; + } + __osPiRelAccess(); + + osRecvMesg(&waitPtQueue, NULL, OS_MESG_NOBLOCK); + osSetTimer(&waitTimer, OS_USEC_TO_CYCLES(1000), 0, &waitPtQueue, NULL); + osRecvMesg(&waitPtQueue, NULL, OS_MESG_BLOCK); + + __osPiGetAccess(); + } +} + +static void putPT(u32 c) { + while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + ; + } + while (!(*ptstat & 4)) { + ; + } + *ptport = c; +} + +static u32 getPT(void) { + while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + ; + } + while (!(*ptstat & 2)) { + ; + } + return *ptport; +} + +void osReadHost_pt(void* dramAddr, u32 nbytes) { + u8* tPtr; + u32 buf[256]; + u32* bp; + u32 data; + u32 ct; + u32 ct1; + u32 ct1_bak; + u32 shift; + u32 cmd; + u32 size; + + if (nbytes == 0) { + return; + } + + if (!isWaitPtQueueCreated) { + createWaitPtQueue(); + } + + __osPiGetAccess(); + + putPT(0x82U); + + cmd = getPT_wait(); + + size = getPT(); + + if (cmd != 2) { + nbytes = -1U; + } + + putPT(nbytes); + + if (size != nbytes) { + goto osReadHost_ret; + } + + tPtr = dramAddr; + ct = nbytes / 4; + + while (ct != 0) { + if (ct > 0x100) { + ct1_bak = ct1 = 0x100; + ct -= 0x100; + } else { + ct1_bak = ct1 = ct; + ct = 0; + } + bp = (u32*)&buf; + + while (ct1 != 0) { + *(bp++) = getPT(); + ct1--; + } + + memcpy(tPtr, &buf, ct1_bak * 4); + tPtr += ct1_bak * 4; + } + + nbytes &= 3; + + if (nbytes != 0) { + data = getPT(); + shift = 0x18; + + do { + *(tPtr++) = (data >> shift); + nbytes--; + shift -= 8; + } while (nbytes != 0); + } + +osReadHost_ret: + __osPiRelAccess(); + return; +} + +void osWriteHost_pt(void* dramAddr, u32 nbytes) { + u8* tPtr; + u32 buf[256]; + u32* bp; + u32 ct; + u32 ct1; + u32 ct1_bak; + u32 cmd; + u32 size; + + if (nbytes == 0) { + return; + } + + if (!isWaitPtQueueCreated) { + createWaitPtQueue(); + } + + __osPiGetAccess(); + putPT(0x82); + + cmd = getPT_wait(); + + size = getPT(); + + if (cmd != 3) { + nbytes = -1; + } + + putPT(nbytes); + + if (size != nbytes) { + goto osWriteHost_ret; + } + + tPtr = dramAddr; + ct = (nbytes + 3) >> 2; + + while (ct != 0) { + if (ct > 0x100) { + ct1_bak = ct1 = 0x100; + ct -= 0x100; + } else { + ct1_bak = ct1 = ct; + ct = 0; + } + + memcpy(bp = buf, tPtr, ct1_bak * 4); + + while (ct1 != 0) { + putPT(*(bp++)); + ct1--; + } + + tPtr += ct1_bak * 4; + } + +osWriteHost_ret: + __osPiRelAccess(); + return; +} + +#endif diff --git a/lib/ultralib/src/host/readhost.c b/lib/ultralib/src/host/readhost.c new file mode 100644 index 0000000..ed6402d --- /dev/null +++ b/lib/ultralib/src/host/readhost.c @@ -0,0 +1,36 @@ +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "PR/rdb.h" + +#include "macros.h" + +static int readHostInitialized = FALSE; +static OSMesgQueue readHostMesgQueue ALIGNED(8); +static OSMesg readHostMesgBuf[1]; + +u32 __osRdb_Read_Data_Buf; +u32 __osRdb_Read_Data_Ct; + +void osReadHost(void* dramAddr, u32 nbytes) { + char tstr[4]; + u32 sent = 0; + + if (!readHostInitialized) { + osCreateMesgQueue(&readHostMesgQueue, readHostMesgBuf, ARRLEN(readHostMesgBuf)); + osSetEventMesg(OS_EVENT_RDB_READ_DONE, &readHostMesgQueue, NULL); + readHostInitialized = TRUE; + } + + __osRdb_Read_Data_Buf = dramAddr; + __osRdb_Read_Data_Ct = nbytes; + + while (sent == 0) { + sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_READY_FOR_DATA); + } + + osRecvMesg(&readHostMesgQueue, NULL, OS_MESG_BLOCK); + return; +} + +#endif diff --git a/lib/ultralib/src/host/writehost.c b/lib/ultralib/src/host/writehost.c new file mode 100644 index 0000000..c7477e6 --- /dev/null +++ b/lib/ultralib/src/host/writehost.c @@ -0,0 +1,57 @@ +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "PR/rdb.h" +#include "PR/ultraerror.h" + +#include "macros.h" + +static int writeHostInitialized = FALSE; +static OSMesgQueue writeHostMesgQueue ALIGNED(8); +static OSMesg writeHostMesgBuf[1]; + +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +void osWriteHost(void* dramAddr, u32 nbytes) { + u8* tPtr = dramAddr; + u32 sent; + u8 dCount[3]; + u32 count; + +#ifndef NDEBUG + if (nbytes == 0) { + __osError(ERR_OSWRITEHOST_SIZE, 1, nbytes); + return; + } +#endif + + if (writeHostInitialized == FALSE) { + osCreateMesgQueue(&writeHostMesgQueue, writeHostMesgBuf, ARRLEN(writeHostMesgBuf)); + osSetEventMesg(OS_EVENT_RDB_DATA_DONE, &writeHostMesgQueue, NULL); + writeHostInitialized = TRUE; + } + + while (nbytes != 0) { + count = MIN(nbytes, 0x8000); + + dCount[0] = (count & 0xFF0000) >> 0x10; + dCount[1] = (count & 0xFF00) >> 8; + dCount[2] = count & 0xFF; + + sent = 0; + while (sent < ARRLEN(dCount)) { + sent += __osRdbSend(dCount + sent, ARRLEN(dCount) - sent, RDB_TYPE_GtoH_DATA_CT); + } + + sent = 0; + while (sent < count) { + sent += __osRdbSend(tPtr + sent, count - sent, RDB_TYPE_GtoH_DATA); + } + + nbytes -= count; + tPtr += count; + osRecvMesg(&writeHostMesgQueue, NULL, OS_MESG_BLOCK); + } +} + +#endif diff --git a/lib/ultralib/src/io/ai.c b/lib/ultralib/src/io/ai.c new file mode 100644 index 0000000..4ece0f1 --- /dev/null +++ b/lib/ultralib/src/io/ai.c @@ -0,0 +1,15 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osAiDeviceBusy(void) { + register s32 status = IO_READ(AI_STATUS_REG); + + if (status & AI_STATUS_FIFO_FULL) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/ultralib/src/io/aigetlen.c b/lib/ultralib/src/io/aigetlen.c new file mode 100644 index 0000000..6b83682 --- /dev/null +++ b/lib/ultralib/src/io/aigetlen.c @@ -0,0 +1,8 @@ +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osAiGetLength(void) { + return IO_READ(AI_LEN_REG); +} diff --git a/lib/ultralib/src/io/aigetstat.c b/lib/ultralib/src/io/aigetstat.c new file mode 100644 index 0000000..c7a3cf7 --- /dev/null +++ b/lib/ultralib/src/io/aigetstat.c @@ -0,0 +1,8 @@ +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osAiGetStatus() { + return IO_READ(AI_STATUS_REG); +} diff --git a/lib/ultralib/src/io/aisetfreq.c b/lib/ultralib/src/io/aisetfreq.c new file mode 100644 index 0000000..e41d6fa --- /dev/null +++ b/lib/ultralib/src/io/aisetfreq.c @@ -0,0 +1,53 @@ +#include "PR/rcp.h" +#include "PR/ultraerror.h" +#include "../os/osint.h" +// TODO: not sure if this should be here +extern s32 osViClock; + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osAiSetFrequency(u32 frequency) { + register unsigned int dacRate; + register unsigned char bitRate; + register float f; + +#ifdef _DEBUG + if (osViClock == VI_PAL_CLOCK) { + if (frequency < AI_PAL_MIN_FREQ || frequency > AI_PAL_MAX_FREQ) { + __osError(ERR_OSAISETFREQUENCY, 3, AI_PAL_MIN_FREQ, AI_PAL_MAX_FREQ, frequency); + return -1; + } + } else if (osViClock == VI_MPAL_CLOCK) { + if (frequency < AI_MPAL_MIN_FREQ || frequency > AI_MPAL_MAX_FREQ) { + __osError(ERR_OSAISETFREQUENCY, 3, AI_MPAL_MIN_FREQ, AI_MPAL_MAX_FREQ, frequency); + return -1; + } + } else { + if (frequency < AI_NTSC_MIN_FREQ || frequency > AI_NTSC_MAX_FREQ) { + __osError(ERR_OSAISETFREQUENCY, 3, AI_NTSC_MIN_FREQ, AI_NTSC_MAX_FREQ, frequency); + return -1; + } + } +#endif + + f = osViClock / (float)frequency + .5f; + dacRate = f; + + if (dacRate < AI_MIN_DAC_RATE) { + return -1; + } + + bitRate = dacRate / 66; + + if (bitRate > AI_MAX_BIT_RATE) { + bitRate = AI_MAX_BIT_RATE; + } + + IO_WRITE(AI_DACRATE_REG, dacRate - 1); + IO_WRITE(AI_BITRATE_REG, bitRate - 1); +#if BUILD_VERSION < VERSION_J + IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); +#endif + return osViClock / (s32)dacRate; +} diff --git a/lib/ultralib/src/io/aisetnextbuf.c b/lib/ultralib/src/io/aisetnextbuf.c new file mode 100644 index 0000000..041b61d --- /dev/null +++ b/lib/ultralib/src/io/aisetnextbuf.c @@ -0,0 +1,52 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "../os/osint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osAiSetNextBuffer(void* bufPtr, u32 size) { + static u8 hdwrBugFlag = FALSE; + char* bptr; + +#if BUILD_VERSION >= VERSION_J + if (__osAiDeviceBusy()) { + return -1; + } +#endif + +#ifdef _DEBUG + if ((u32)bufPtr & (8 - 1)) { + __osError(ERR_OSAISETNEXTBUFFER_ADDR, 1, bufPtr); + return -1; + } + + if ((u32)size & (8 - 1)) { + __osError(ERR_OSAISETNEXTBUFFER_SIZE, 1, size); + return -1; + } +#endif + + bptr = bufPtr; + + if (hdwrBugFlag) { + bptr = (u8*)bufPtr - 0x2000; + } + + if ((((u32)bufPtr + size) & 0x1fff) == 0) { + hdwrBugFlag = TRUE; + } else { + hdwrBugFlag = FALSE; + } + +#if BUILD_VERSION < VERSION_J + if (__osAiDeviceBusy()) { + return -1; + } +#endif + + IO_WRITE(AI_DRAM_ADDR_REG, osVirtualToPhysical(bptr)); + IO_WRITE(AI_LEN_REG, size); + return 0; +} diff --git a/lib/ultralib/src/io/cartrominit.c b/lib/ultralib/src/io/cartrominit.c new file mode 100644 index 0000000..87aa8bb --- /dev/null +++ b/lib/ultralib/src/io/cartrominit.c @@ -0,0 +1,95 @@ +#include "macros.h" +#include "PR/os_version.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/rcp.h" +#include "piint.h" + +#if BUILD_VERSION >= VERSION_J +OSPiHandle __CartRomHandle ALIGNED(8); +OSPiHandle* osCartRomInit(void) { + u32 value = 0; + u32 saveMask; + static int first = 1; + register u32 stat; + u32 latency; + u32 pulse; + u32 pageSize; + u32 relDuration; + + __osPiGetAccess(); + + if (!first) { + __osPiRelAccess(); + return &__CartRomHandle; + } + + first = 0; + __CartRomHandle.type = DEVICE_TYPE_CART; + __CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); + __CartRomHandle.domain = PI_DOMAIN1; + __CartRomHandle.speed = 0; + + bzero(&__CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); + + WAIT_ON_IOBUSY(stat); + + latency = IO_READ(PI_BSD_DOM1_LAT_REG); + pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + + IO_WRITE(PI_BSD_DOM1_LAT_REG, 0xFF); + IO_WRITE(PI_BSD_DOM1_PGS_REG, 0); + IO_WRITE(PI_BSD_DOM1_RLS_REG, 3); + IO_WRITE(PI_BSD_DOM1_PWD_REG, 0xFF); + + value = IO_READ(__CartRomHandle.baseAddress); + __CartRomHandle.latency = value & 0xFF; + __CartRomHandle.pageSize = (value >> 0x10) & 0xF; + __CartRomHandle.relDuration = (value >> 0x14) & 0xF; + __CartRomHandle.pulse = (value >> 8) & 0xFF; + + IO_WRITE(PI_BSD_DOM1_LAT_REG, latency); + IO_WRITE(PI_BSD_DOM1_PGS_REG, pageSize); + IO_WRITE(PI_BSD_DOM1_RLS_REG, relDuration); + IO_WRITE(PI_BSD_DOM1_PWD_REG, pulse); + + saveMask = __osDisableInt(); + __CartRomHandle.next = __osPiTable; + __osPiTable = &__CartRomHandle; + __osRestoreInt(saveMask); + __osPiRelAccess(); + + return &__CartRomHandle; +} +#else + +OSPiHandle CartRomHandle ALIGNED(8); +OSPiHandle* osCartRomInit(void) { + u32 domain = 0; + u32 saveMask; + + if (CartRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR2)) + return &CartRomHandle; + + CartRomHandle.type = DEVICE_TYPE_CART; + CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); + osPiRawReadIo(NULL, &domain); + CartRomHandle.latency = domain & 0xff; + CartRomHandle.pulse = (domain >> 8) & 0xff; + CartRomHandle.pageSize = (domain >> 0x10) & 0xf; + CartRomHandle.relDuration = (domain >> 0x14) & 0xf; + CartRomHandle.domain = PI_DOMAIN1; + CartRomHandle.speed = 0; + + bzero(&CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); + + saveMask = __osDisableInt(); + CartRomHandle.next = __osPiTable; + __osPiTable = &CartRomHandle; + __osRestoreInt(saveMask); + + return &CartRomHandle; +} +#endif diff --git a/lib/ultralib/src/io/contchannelreset.c b/lib/ultralib/src/io/contchannelreset.c new file mode 100644 index 0000000..f6ed8a2 --- /dev/null +++ b/lib/ultralib/src/io/contchannelreset.c @@ -0,0 +1,28 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +s32 __osContChannelReset(OSMesgQueue* mq, int channel) { + s32 i; + s32 ret; + u8* ptr = (u8*)&__osPfsPifRam; + + __osSiGetAccess(); + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + + *ptr++ = CONT_CMD_CHANNEL_RESET; + *ptr = CONT_CMD_END; + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + __osSiRelAccess(); + return ret; +} diff --git a/lib/ultralib/src/io/conteeplongread.c b/lib/ultralib/src/io/conteeplongread.c new file mode 100644 index 0000000..d8d59f6 --- /dev/null +++ b/lib/ultralib/src/io/conteeplongread.c @@ -0,0 +1,15 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osEepromLongRead(OSMesgQueue* mq, u8 address, u8* buffer, int length) { + s32 ret = 0; + + while (length > 0) { + ERRCK(osEepromRead(mq, address, buffer)); + length -= EEPROM_BLOCK_SIZE; + address++; + buffer += EEPROM_BLOCK_SIZE; + } + + return ret; +} diff --git a/lib/ultralib/src/io/conteeplongwrite.c b/lib/ultralib/src/io/conteeplongwrite.c new file mode 100644 index 0000000..c5668e1 --- /dev/null +++ b/lib/ultralib/src/io/conteeplongwrite.c @@ -0,0 +1,17 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osEepromLongWrite(OSMesgQueue* mq, u8 address, u8* buffer, int length) { + s32 ret = 0; + + while (length > 0) { + ERRCK(osEepromWrite(mq, address, buffer)); + length -= EEPROM_BLOCK_SIZE; + address++; + buffer += EEPROM_BLOCK_SIZE; + osSetTimer(&__osEepromTimer, OS_USEC_TO_CYCLES(12000), 0, &__osEepromTimerQ, &__osEepromTimerMsg); + osRecvMesg(&__osEepromTimerQ, NULL, OS_MESG_BLOCK); + } + + return ret; +} diff --git a/lib/ultralib/src/io/conteepprobe.c b/lib/ultralib/src/io/conteepprobe.c new file mode 100644 index 0000000..b19dc49 --- /dev/null +++ b/lib/ultralib/src/io/conteepprobe.c @@ -0,0 +1,34 @@ +#include "controller.h" +#include "siint.h" + +s32 osEepromProbe(OSMesgQueue* mq) { + s32 ret = 0; + u16 type; + OSContStatus sdata; + + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); + type = sdata.type & (CONT_EEPROM | CONT_EEP16K); + + if (ret != 0) { + ret = 0; + } else { + switch (type) { + case CONT_EEPROM: + ret = EEPROM_TYPE_4K; + break; + case CONT_EEPROM | CONT_EEP16K: + ret = EEPROM_TYPE_16K; + break; + default: + ret = 0; + break; + } + } + +#if BUILD_VERSION >= VERSION_L + __osEepromRead16K = 0; +#endif + __osSiRelAccess(); + return ret; +} diff --git a/lib/ultralib/src/io/conteepread.c b/lib/ultralib/src/io/conteepread.c new file mode 100644 index 0000000..2d334fa --- /dev/null +++ b/lib/ultralib/src/io/conteepread.c @@ -0,0 +1,139 @@ +#include "macros.h" +#include "PR/rcp.h" +#include "controller.h" +#include "siint.h" + +OSPifRam __osEepPifRam ALIGNED(16); +#if BUILD_VERSION >= VERSION_L +s32 __osEepromRead16K; +#endif +static void __osPackEepReadData(u8 address); + +s32 osEepromRead(OSMesgQueue* mq, u8 address, u8* buffer) { + s32 ret = 0; + int i = 0; + u16 type; + u8* ptr; + OSContStatus sdata; + __OSContEepromFormat eepromformat; + + ptr = (u8*)&__osEepPifRam.ramarray; + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); + type = sdata.type & (CONT_EEPROM | CONT_EEP16K); + +#if BUILD_VERSION >= VERSION_J + if (ret == 0) { + switch (type) { + case CONT_EEPROM: + if (address >= EEPROM_MAXBLOCKS) { + ret = CONT_RANGE_ERROR; + } + break; + case CONT_EEPROM | CONT_EEP16K: + if (address >= EEP16K_MAXBLOCKS) { + // not technically possible + ret = CONT_RANGE_ERROR; + } +#if BUILD_VERSION >= VERSION_L + else { + __osEepromRead16K = 1; + } +#endif + break; + default: + ret = CONT_NO_RESPONSE_ERROR; + } + } + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } +#else + if (ret != 0) + { + __osSiRelAccess(); + return CONT_NO_RESPONSE_ERROR; + } else { + switch (type) { + case CONT_EEPROM: + if (address > EEPROM_MAXBLOCKS) { + __osSiRelAccess(); + return CONT_RANGE_ERROR; + } + break; + case CONT_EEPROM | CONT_EEP16K: + if (address > EEP16K_MAXBLOCKS) { + // not technically possible + __osSiRelAccess(); + return CONT_RANGE_ERROR; + } + break; + default: + __osSiRelAccess(); + return CONT_NO_RESPONSE_ERROR; + } + } +#endif + + while (sdata.status & CONT_EEPROM_BUSY) { + __osEepStatus(mq, &sdata); + } + + __osPackEepReadData(address); + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); // send command to pif + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); // recv response + __osContLastCmd = CONT_CMD_READ_EEPROM; + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + for (i = 0; i < MAXCONTROLLERS; i++) { + // skip the first 4 bytes + ptr++; + } + + eepromformat = *(__OSContEepromFormat*)ptr; + ret = CHNL_ERR(eepromformat); + + if (ret == 0) { + for (i = 0; i < ARRLEN(eepromformat.data); i++) { + *buffer++ = eepromformat.data[i]; + } + } + __osSiRelAccess(); + return ret; +} + +static void __osPackEepReadData(u8 address) { + u8* ptr = (u8*)&__osEepPifRam.ramarray; + __OSContEepromFormat eepromformat; + int i; + +#if BUILD_VERSION < VERSION_J + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray); i++) { + __osEepPifRam.ramarray[i] = CONT_CMD_NOP; + } +#endif + + __osEepPifRam.pifstatus = CONT_CMD_EXE; + + eepromformat.txsize = CONT_CMD_READ_EEPROM_TX; + eepromformat.rxsize = CONT_CMD_READ_EEPROM_RX; + eepromformat.cmd = CONT_CMD_READ_EEPROM; + eepromformat.address = address; + +#if BUILD_VERSION < VERSION_J + for (i = 0; i < ARRLEN(eepromformat.data); i++) { + eepromformat.data[i] = 0; + } +#endif + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = 0; + } + + *(__OSContEepromFormat*)(ptr) = eepromformat; + ptr += sizeof(__OSContEepromFormat); + ptr[0] = CONT_CMD_END; +} diff --git a/lib/ultralib/src/io/conteepwrite.c b/lib/ultralib/src/io/conteepwrite.c new file mode 100644 index 0000000..7352430 --- /dev/null +++ b/lib/ultralib/src/io/conteepwrite.c @@ -0,0 +1,203 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "controller.h" +#include "siint.h" + +static void __osPackEepWriteData(u8 address, u8* buffer); +s32 osEepromWrite(OSMesgQueue* mq, u8 address, u8* buffer) { + s32 ret = 0; +#if BUILD_VERSION < VERSION_J + int i; +#endif + u16 type; + u8* ptr = (u8*)&__osEepPifRam.ramarray; + __OSContEepromFormat eepromformat; + OSContStatus sdata; +#if BUILD_VERSION >= VERSION_L + u8 temp[8]; +#endif + + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); +#if BUILD_VERSION < VERSION_J + ret = __osEepStatus(mq, &sdata); // Duplicate that was removed in 2.0J +#endif + + type = sdata.type & (CONT_EEPROM | CONT_EEP16K); + +#if BUILD_VERSION >= VERSION_J + if (ret == 0) { + switch (type) { + case CONT_EEPROM: + if (address >= EEPROM_MAXBLOCKS) { + ret = CONT_RANGE_ERROR; + } + break; + case CONT_EEPROM | CONT_EEP16K: + if (address >= EEP16K_MAXBLOCKS) { + // not technically possible + ret = CONT_RANGE_ERROR; + } +#if BUILD_VERSION >= VERSION_L + else if (__osEepromRead16K) { + __osEepromRead16K = 0; + __osSiRelAccess(); + osEepromRead(mq, (address ^ 1), temp); + __osSiGetAccess(); + } +#endif + break; + default: + ret = CONT_NO_RESPONSE_ERROR; + } + } + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } +#else + if (ret != 0) { + __osSiRelAccess(); + return CONT_NO_RESPONSE_ERROR; + } else { + switch (type) { + case CONT_EEPROM: + if (address > EEPROM_MAXBLOCKS) { + __osSiRelAccess(); + return -1; + } + + break; + case CONT_EEPROM | CONT_EEP16K: + if (address > EEP16K_MAXBLOCKS) { + // not technically possible + __osSiRelAccess(); + return -1; + } + break; + default: + __osSiRelAccess(); + return CONT_NO_RESPONSE_ERROR; + } + } +#endif + + while (sdata.status & CONT_EEPROM_BUSY) { + __osEepStatus(mq, &sdata); + } + + __osPackEepWriteData(address, buffer); + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); // send command to pif + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); // recv response + __osContLastCmd = CONT_CMD_WRITE_EEPROM; + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + // skip the first 4 bytes +#if BUILD_VERSION >= VERSION_J + ptr += 4; +#else + for (i = 0; i < 4; i++) { + ptr++; + } +#endif + + eepromformat = *(__OSContEepromFormat*)ptr; + + ret = CHNL_ERR(eepromformat); + + __osSiRelAccess(); + return ret; +} + +static void __osPackEepWriteData(u8 address, u8* buffer) { + u8* ptr = (u8*)&__osEepPifRam.ramarray; + __OSContEepromFormat eepromformat; + int i; + +#if BUILD_VERSION < VERSION_J + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray); i++) { + __osEepPifRam.ramarray[i] = CONT_CMD_NOP; + } +#endif + __osEepPifRam.pifstatus = CONT_CMD_EXE; + + eepromformat.txsize = CONT_CMD_WRITE_EEPROM_TX; + eepromformat.rxsize = CONT_CMD_WRITE_EEPROM_RX; + eepromformat.cmd = CONT_CMD_WRITE_EEPROM; + eepromformat.address = address; + + for (i = 0; i < ARRLEN(eepromformat.data); i++) { + eepromformat.data[i] = *buffer++; + } + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = 0; + } + + *(__OSContEepromFormat*)(ptr) = eepromformat; + ptr += sizeof(__OSContEepromFormat); + ptr[0] = CONT_CMD_END; +} + +s32 __osEepStatus(OSMesgQueue* mq, OSContStatus* data) { + s32 ret = 0; + int i; + u8* ptr = (u8*)__osEepPifRam.ramarray; + __OSContRequesFormat requestformat; + + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { + __osEepPifRam.ramarray[i] = 0; + } + + __osEepPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8*)__osEepPifRam.ramarray; + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + + requestformat.dummy = CONT_CMD_NOP; + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = CONT_CMD_REQUEST_STATUS; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + requestformat.dummy1 = CONT_CMD_NOP; + *(__OSContRequesFormat*)ptr = requestformat; + ptr += sizeof(__OSContRequesFormat); + *ptr = CONT_CMD_END; + + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); +#if BUILD_VERSION >= VERSION_J + __osContLastCmd = CONT_CMD_END; +#else + __osContLastCmd = CONT_CMD_REQUEST_STATUS; +#endif + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + if (ret != 0) { + return ret; + } + + ptr = (u8*)&__osEepPifRam; + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = 0; + } + + requestformat = *(__OSContRequesFormat*)ptr; + data->errno = CHNL_ERR(requestformat); + data->type = (requestformat.typel << 8) | requestformat.typeh; + data->status = requestformat.status; + + if (data->errno != 0) { + return data->errno; + } + + return 0; +} diff --git a/lib/ultralib/src/io/contpfs.c b/lib/ultralib/src/io/contpfs.c new file mode 100644 index 0000000..c845a7d --- /dev/null +++ b/lib/ultralib/src/io/contpfs.c @@ -0,0 +1,393 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/os_version.h" +#include "controller.h" +#include "PR/rmon.h" + +#if BUILD_VERSION >= VERSION_J +__OSInode __osPfsInodeCache ALIGNED(8); +s32 __osPfsInodeCacheChannel = -1; +u8 __osPfsInodeCacheBank = 250; +#endif + +u16 __osSumcalc(u8* ptr, int length) { + int i; + u32 sum = 0; + u8* tmp = ptr; + + for (i = 0; i < length; i++) { + sum += *tmp++; +#if BUILD_VERSION < VERSION_J + sum = sum & 0xFFFF; +#endif + } + +#if BUILD_VERSION >= VERSION_J + return sum & 0xFFFF; +#else + return sum; +#endif +} + +s32 __osIdCheckSum(u16* ptr, u16* csum, u16* icsum) { + u16 data = 0; + u32 j; + + *csum = *icsum = 0; + + for (j = 0; j < ((sizeof(__OSPackId) - sizeof(u32)) / sizeof(u8)); j += 2) { + data = *(u16*)((u32)ptr + j); + *csum += data; + *icsum += ~data; + } + + return 0; +} + +s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) { + s32 ret = 0; + u8 temp[BLOCKSIZE]; + u8 comp[BLOCKSIZE]; + u8 mask = 0; + int i; + int j; + u16 index[4]; + +#if BUILD_VERSION >= VERSION_J + j = 0; +#else + SET_ACTIVEBANK_TO_ZERO(); +#endif + + newid->repaired = -1; + newid->random = osGetCount(); + newid->serial_mid = badid->serial_mid; + newid->serial_low = badid->serial_low; + +#if BUILD_VERSION >= VERSION_J + SET_ACTIVEBANK_TO_ZERO(); +#else + j = 0; +#endif + do { + ERRCK(SELECT_BANK(pfs, j)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, temp)); + + temp[0] = j | 0x80; + + for (i = 1; i < BLOCKSIZE; i++) { + temp[i] = ~temp[i]; + } + + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, 0, temp, FALSE)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, comp)); + + for (i = 0; i < BLOCKSIZE; i++) { + if (comp[i] != temp[i]) { + break; + } + } + + if (i != BLOCKSIZE) { + break; + } + + if (j > 0) { + ERRCK(SELECT_BANK(pfs, 0)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)temp)); + + if (temp[0] != 0x80) { + break; + } + } + + j++; + } while (j < PFS_MAX_BANKS); + +#if BUILD_VERSION >= VERSION_J + SET_ACTIVEBANK_TO_ZERO(); +#else + ERRCK(SELECT_BANK(pfs, 0)); +#endif + + mask = (j > 0) ? 1 : 0; + + newid->deviceid = (badid->deviceid & (u16)~1) | mask; + newid->banks = j; + newid->version = badid->version; + __osIdCheckSum((u16*)newid, &newid->checksum, &newid->inverted_checksum); + index[0] = PFS_ID_0AREA; + index[1] = PFS_ID_1AREA; + index[2] = PFS_ID_2AREA; + index[3] = PFS_ID_3AREA; + + for (i = 0; i < ARRLEN(index); i++) { + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[i], (u8*)newid, TRUE)); + } + + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); + + for (i = 0; i < BLOCKSIZE; i++) { + if (temp[i] != ((u8*)newid)[i]) { +#if BUILD_VERSION >= VERSION_J + return PFS_ERR_DEVICE; +#else + return PFS_ERR_ID_FATAL; +#endif + } + } + return 0; +} + +s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp) { + u16 index[4]; + s32 ret = 0; + u16 sum; + u16 isum; + int i; + int j; + + SET_ACTIVEBANK_TO_ZERO(); + index[0] = PFS_ID_0AREA; + index[1] = PFS_ID_1AREA; + index[2] = PFS_ID_2AREA; + index[3] = PFS_ID_3AREA; + for (i = 1; i < ARRLEN(index); i++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, index[i], (u8*)temp)); + __osIdCheckSum((u16*)temp, &sum, &isum); + if (temp->checksum == sum && temp->inverted_checksum == isum) { + break; + } + } + + if (i == ARRLEN(index)) { + return PFS_ERR_ID_FATAL; + } + + for (j = 0; j < ARRLEN(index); j++) { + if (j != i) { + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[j], (u8*)temp, TRUE)); + } + } + + return 0; +} + +s32 __osGetId(OSPfs* pfs) { +#if BUILD_VERSION < VERSION_J + int k; +#endif + u16 sum; + u16 isum; + u8 temp[BLOCKSIZE]; + __OSPackId newid; + s32 ret; + __OSPackId* id; + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); + __osIdCheckSum((u16*)temp, &sum, &isum); + id = (__OSPackId*)temp; + + if (id->checksum != sum || id->inverted_checksum != isum) { + ret = __osCheckPackId(pfs, id); + + if (ret == PFS_ERR_ID_FATAL) { + ERRCK(__osRepairPackId(pfs, id, &newid)); + id = &newid; + } else if (ret != 0) { + return ret; + } + } + + if ((id->deviceid & 1) == 0) { + ERRCK(__osRepairPackId(pfs, id, &newid)); + id = &newid; + + if ((id->deviceid & 1) == 0) { + return PFS_ERR_DEVICE; + } + } + +#if BUILD_VERSION >= VERSION_J + bcopy(id, pfs->id, BLOCKSIZE); +#else + for (k = 0; k < ARRLEN(pfs->id); k++) { + pfs->id[k] = ((u8 *)id)[k]; + } +#endif + pfs->version = id->version; + pfs->banks = id->banks; + pfs->inode_start_page = 1 + DEF_DIR_PAGES + (2 * pfs->banks); + pfs->dir_size = 16; + pfs->inode_table = PFS_ONE_PAGE; + pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; + pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label)); + return 0; +} + +s32 __osCheckId(OSPfs* pfs) { +#if BUILD_VERSION < VERSION_J + int k; +#endif + u8 temp[BLOCKSIZE]; + s32 ret; + +#if BUILD_VERSION >= VERSION_J + if (pfs->activebank != 0) { + ret = __osPfsSelectBank(pfs, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osPfsSelectBank(pfs, 0); + } + + if (ret != 0) { + return ret; + } + } +#else + SET_ACTIVEBANK_TO_ZERO(); +#endif + + ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp); + + if (ret != 0) { + if (ret != PFS_ERR_NEW_PACK) { + return ret; + } + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); + } + +#if BUILD_VERSION >= VERSION_J + if (bcmp(pfs->id, temp, BLOCKSIZE) != 0) { + return PFS_ERR_NEW_PACK; + } +#else + for (k = 0; k < ARRLEN(temp); k++) { + if (pfs->id[k] != temp[k]) + return PFS_ERR_NEW_PACK; + } +#endif + + return 0; +} + +s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) { + u8 sum; + int j; + s32 ret; + int offset; + u8* addr; + +#if BUILD_VERSION >= VERSION_J + if (flag == PFS_READ && bank == __osPfsInodeCacheBank && (pfs->channel == __osPfsInodeCacheChannel)) { + bcopy(&__osPfsInodeCache, inode, sizeof(__OSInode)); + return 0; + } +#endif + + SET_ACTIVEBANK_TO_ZERO(); + + offset = (bank > 0) ? 1 : pfs->inode_start_page; + + if (flag == PFS_WRITE) { + inode->inode_page[0].inode_t.page = + __osSumcalc((u8*)&inode->inode_page[offset], (PFS_INODE_SIZE_PER_PAGE - offset) * 2); + } + + for (j = 0; j < PFS_ONE_PAGE; j++) { + addr = ((u8*)inode->inode_page + j * BLOCKSIZE); + + if (flag == PFS_WRITE) { + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); + } else { + ret = __osContRamRead(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr); + } + + if (ret != 0) { + return ret; + } + } + + if (flag == PFS_READ) { + sum = __osSumcalc((u8*)&inode->inode_page[offset], (PFS_INODE_SIZE_PER_PAGE - offset) * 2); + if (sum != inode->inode_page[0].inode_t.page) { + for (j = 0; j < PFS_ONE_PAGE; j++) { + addr = ((u8*)inode->inode_page + j * BLOCKSIZE); + ret = __osContRamRead(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr); + } + +#if BUILD_VERSION >= VERSION_J + sum = __osSumcalc((u8*)&inode->inode_page[offset], (PFS_INODE_SIZE_PER_PAGE - offset) * 2); +#endif + + if (sum != inode->inode_page[0].inode_t.page) { + return PFS_ERR_INCONSISTENT; + } + + for (j = 0; j < PFS_ONE_PAGE; j++) { + addr = ((u8*)inode->inode_page + j * BLOCKSIZE); + ret = + __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); + } + } +#if BUILD_VERSION < VERSION_J + else + { + for (j = 0; j < PFS_ONE_PAGE; j++) + { + addr = ((u8 *)inode->inode_page + j * 32); + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); + } + } +#endif + } + +#if BUILD_VERSION >= VERSION_J + __osPfsInodeCacheBank = bank; + bcopy(inode, &__osPfsInodeCache, sizeof(__OSInode)); + __osPfsInodeCacheChannel = pfs->channel; +#endif + + return 0; +} + +// This was moved into it's own file in 2.0J +#if BUILD_VERSION < VERSION_J +s32 __osPfsSelectBank(OSPfs* pfs) { + u8 temp[BLOCKSIZE]; + int i; + s32 ret = 0; + + for (i = 0; i < BLOCKSIZE; i++) { + temp[i] = pfs->activebank; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_DETECT, temp, FALSE); + return ret; +} +#endif + +#ifdef _DEBUG +s32 __osDumpId(OSPfs* pfs) { + u8 id[BLOCKSIZE]; + __OSPackId* temp; + s32 ret; + + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, id)); + + temp = (__OSPackId*)id; + rmonPrintf("repaired %x\n", temp->repaired); + rmonPrintf("random %x\n", temp->random); + rmonPrintf("serial_mid %llu\n", temp->serial_mid); + rmonPrintf("serial_low %llu\n", temp->serial_low); + rmonPrintf("deviceid %x\n", temp->deviceid); + rmonPrintf("banks %x\n", temp->banks); + rmonPrintf("version %x\n", temp->version); + rmonPrintf("checksum %x\n", temp->checksum); + rmonPrintf("inverted_checksum %x\n", temp->inverted_checksum); + return 0; +} +#endif diff --git a/lib/ultralib/src/io/contquery.c b/lib/ultralib/src/io/contquery.c new file mode 100644 index 0000000..df038ce --- /dev/null +++ b/lib/ultralib/src/io/contquery.c @@ -0,0 +1,25 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +s32 osContStartQuery(OSMesgQueue* mq) { + s32 ret = 0; + + __osSiGetAccess(); + + if (__osContLastCmd != CONT_CMD_REQUEST_STATUS) { + __osPackRequestData(CONT_CMD_REQUEST_STATUS); + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + } + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + __osContLastCmd = CONT_CMD_REQUEST_STATUS; + __osSiRelAccess(); + return ret; +} + +void osContGetQuery(OSContStatus* data) { + u8 pattern; + __osContGetInitData(&pattern, data); +} diff --git a/lib/ultralib/src/io/contramread.c b/lib/ultralib/src/io/contramread.c new file mode 100644 index 0000000..9c399ee --- /dev/null +++ b/lib/ultralib/src/io/contramread.c @@ -0,0 +1,163 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "controller.h" +#include "siint.h" + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +#if BUILD_VERSION >= VERSION_J +s32 __osPfsLastChannel = -1; + +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + s32 i; + u8* ptr; + s32 retry = 2; + + __osSiGetAccess(); + + do { + ptr = (u8*)&__osPfsPifRam; + + if (__osContLastCmd != CONT_CMD_READ_PAK || (u32)__osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_READ_PAK; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + READFORMAT(ptr)->dummy = CONT_CMD_NOP; + READFORMAT(ptr)->txsize = CONT_CMD_READ_PAK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_READ_PAK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_READ_PAK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + +#if BUILD_VERSION >= VERSION_J + READFORMAT(ptr)->addrh = address >> 3; + READFORMAT(ptr)->addrl = (u8)((address << 5) | __osContAddressCrc(address)); +#else + READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); +#endif + + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*READFORMAT(ptr)); + + if (!ret) { + if (__osContDataCrc(READFORMAT(ptr)->data) != READFORMAT(ptr)->datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret) { + break; + } else { + ret = PFS_ERR_CONTRFAIL; + } + } else { + bcopy(READFORMAT(ptr)->data, buffer, BLOCKSIZE); + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); + __osSiRelAccess(); + return ret; +} +#else + +static void __osPackRamReadData(int channel, u16 address); + +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + int i; + u8* ptr = (u8*)&__osPfsPifRam; + __OSContRamReadFormat ramreadformat; + int retry = 2; + + __osSiGetAccess(); + __osContLastCmd = CONT_CMD_READ_PAK; + __osPackRamReadData(channel, address); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + do { + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ptr = (u8*)&__osPfsPifRam; + + if (channel != 0) { + for (i = 0; i < channel; i++) { + ptr++; + } + } + + ramreadformat = *READFORMAT(ptr); + + ret = CHNL_ERR(ramreadformat); + if (ret == 0) { + u8 c = __osContDataCrc((u8*)&ramreadformat.data); + if (c != ramreadformat.datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + ret = PFS_ERR_CONTRFAIL; + } else { + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + *buffer++ = ramreadformat.data[i]; + } + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); + + __osSiRelAccess(); + + return ret; +} + +static void __osPackRamReadData(int channel, u16 address) { + u8 *ptr; + __OSContRamReadFormat ramreadformat; + int i; + + ptr = (u8 *)__osPfsPifRam.ramarray; + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_READ_PAK_TX; + ramreadformat.rxsize = CONT_CMD_READ_PAK_RX; + ramreadformat.cmd = CONT_CMD_READ_PAK; + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = CONT_CMD_NOP; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + } + + *(__OSContRamReadFormat *)ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +#endif + diff --git a/lib/ultralib/src/io/contramwrite.c b/lib/ultralib/src/io/contramwrite.c new file mode 100644 index 0000000..a213049 --- /dev/null +++ b/lib/ultralib/src/io/contramwrite.c @@ -0,0 +1,165 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "controller.h" +#include "siint.h" + +extern s32 __osPfsLastChannel; + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +#if BUILD_VERSION >= VERSION_J +s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { + s32 ret = 0; + s32 i; + u8* ptr; + s32 retry = 2; + u8 crc; + + if ((force != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { + return 0; + } + + __osSiGetAccess(); + + do { + ptr = (u8*)__osPfsPifRam.ramarray; + + if (__osContLastCmd != CONT_CMD_WRITE_PAK || (u32)__osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + READFORMAT(ptr)->dummy = CONT_CMD_NOP; + READFORMAT(ptr)->txsize = CONT_CMD_WRITE_PAK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_WRITE_PAK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_WRITE_PAK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + +#if BUILD_VERSION >= VERSION_J + READFORMAT(ptr)->addrh = address >> 3; + READFORMAT(ptr)->addrl = ((address << 5) | __osContAddressCrc(address)); +#else + READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); +#endif + + bcopy(buffer, READFORMAT(ptr)->data, BLOCKSIZE); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + crc = __osContDataCrc(buffer); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*READFORMAT(ptr)); + + if (!ret) { + if (crc != READFORMAT(ptr)->datacrc) { + if ((ret = __osPfsGetStatus(mq, channel))) { + break; + } else { + ret = PFS_ERR_CONTRFAIL; + } + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} +#else + +static void __osPackRamWriteData(int channel, u16 address, u8 *buffer); + +s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { + s32 ret = 0; + s32 i; + u8* ptr = (u8*)&__osPfsPifRam; + __OSContRamReadFormat ramreadformat; + s32 retry = 2; + u8 crc; + + if ((force != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { + return 0; + } + + __osSiGetAccess(); + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osPackRamWriteData(channel, address, buffer); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + do { + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ptr = (u8*)&__osPfsPifRam; + + if (channel != 0) { + for (i = 0; i < channel; i++) { + ptr++; + } + } + + ramreadformat = *READFORMAT(ptr); + + ret = CHNL_ERR(ramreadformat); + if (ret == 0) { + if (__osContDataCrc(buffer) != ramreadformat.datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + ret = PFS_ERR_CONTRFAIL; + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); + + __osSiRelAccess(); + + return ret; +} + +static void __osPackRamWriteData(int channel, u16 address, u8 *buffer) { + u8 *ptr; + __OSContRamReadFormat ramreadformat; + int i; + + ptr = (u8 *)__osPfsPifRam.ramarray; + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; + ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; + ramreadformat.cmd = CONT_CMD_WRITE_PAK; + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = *buffer++; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + } + + *(__OSContRamReadFormat *)ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +#endif diff --git a/lib/ultralib/src/io/contreaddata.c b/lib/ultralib/src/io/contreaddata.c new file mode 100644 index 0000000..da0cac3 --- /dev/null +++ b/lib/ultralib/src/io/contreaddata.c @@ -0,0 +1,68 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +static void __osPackReadData(void); + +s32 osContStartReadData(OSMesgQueue* mq) { + s32 ret = 0; + + __osSiGetAccess(); + + if (__osContLastCmd != CONT_CMD_READ_BUTTON) { + __osPackReadData(); + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + } + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + __osContLastCmd = CONT_CMD_READ_BUTTON; + __osSiRelAccess(); + + return ret; +} + +void osContGetReadData(OSContPad* data) { + u8* ptr = (u8*)__osContPifRam.ramarray; + __OSContReadFormat readformat; + int i; + + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++) { + readformat = *(__OSContReadFormat*)ptr; + data->errno = CHNL_ERR(readformat); + + if (data->errno != 0) { + continue; + } + + data->button = readformat.button; + data->stick_x = readformat.stick_x; + data->stick_y = readformat.stick_y; + } +} + +static void __osPackReadData(void) { + u8* ptr = (u8*)__osContPifRam.ramarray; + __OSContReadFormat readformat; + int i; + + for (i = 0; i < ARRLEN(__osContPifRam.ramarray); i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = CONT_CMD_EXE; + readformat.dummy = CONT_CMD_NOP; + readformat.txsize = CONT_CMD_READ_BUTTON_TX; + readformat.rxsize = CONT_CMD_READ_BUTTON_RX; + readformat.cmd = CONT_CMD_READ_BUTTON; + readformat.button = 0xFFFF; + readformat.stick_x = -1; + readformat.stick_y = -1; + + for (i = 0; i < __osMaxControllers; i++) { + *(__OSContReadFormat*)ptr = readformat; + ptr += sizeof(__OSContReadFormat); + } + + *ptr = CONT_CMD_END; +} diff --git a/lib/ultralib/src/io/contreset.c b/lib/ultralib/src/io/contreset.c new file mode 100644 index 0000000..140088a --- /dev/null +++ b/lib/ultralib/src/io/contreset.c @@ -0,0 +1,51 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +void __osPackResetData(void); + +s32 osContReset(OSMesgQueue* mq, OSContStatus* data) { + u8 pattern; + s32 ret; + + __osSiGetAccess(); + + if (__osContLastCmd != CONT_CMD_RESET) { + __osPackResetData(); + + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + __osPackRequestData(CONT_CMD_RESET); + + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + __osContLastCmd = CONT_CMD_RESET; + } + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + __osContGetInitData(&pattern, data); + __osSiRelAccess(); + + return ret; +} + +void __osPackResetData(void) { + u8* ptr; + int i; + + __osContPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8*)__osContPifRam.ramarray; + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = CONT_CMD_CHANNEL_RESET; + } + + *ptr = CONT_CMD_END; +} diff --git a/lib/ultralib/src/io/controller.c b/lib/ultralib/src/io/controller.c new file mode 100644 index 0000000..728c207 --- /dev/null +++ b/lib/ultralib/src/io/controller.c @@ -0,0 +1,101 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +OSPifRam __osContPifRam ALIGNED(16); +u8 __osContLastCmd; +u8 __osMaxControllers; + +OSTimer __osEepromTimer; +OSMesgQueue __osEepromTimerQ ALIGNED(8); +OSMesg __osEepromTimerMsg; + +s32 __osContinitialized = 0; + +s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { + OSMesg dummy; + s32 ret = 0; + OSTime t; + OSTimer mytimer; + OSMesgQueue timerMesgQueue; + + if (__osContinitialized != 0) { + return 0; + } + + __osContinitialized = 1; + + t = osGetTime(); + if (t < OS_USEC_TO_CYCLES(500000)) { + osCreateMesgQueue(&timerMesgQueue, &dummy, 1); + osSetTimer(&mytimer, OS_USEC_TO_CYCLES(500000) - t, 0, &timerMesgQueue, &dummy); + osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); + } + + __osMaxControllers = 4; + + __osPackRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, &dummy, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + osRecvMesg(mq, &dummy, OS_MESG_BLOCK); + + __osContGetInitData(bitpattern, data); + __osContLastCmd = CONT_CMD_REQUEST_STATUS; + __osSiCreateAccessQueue(); + osCreateMesgQueue(&__osEepromTimerQ, &__osEepromTimerMsg, 1); + + return ret; +} + +void __osContGetInitData(u8* pattern, OSContStatus* data) { + u8* ptr; + __OSContRequesFormat requestHeader; + int i; + u8 bits = 0; + + ptr = (u8*)__osContPifRam.ramarray; + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestHeader), data++) { + requestHeader = *(__OSContRequesFormat*)ptr; + data->errno = CHNL_ERR(requestHeader); + + if (data->errno != 0) { + continue; + } + + data->type = requestHeader.typel << 8 | requestHeader.typeh; + data->status = requestHeader.status; + bits |= 1 << i; + } + *pattern = bits; +} + +void __osPackRequestData(u8 cmd) { + u8* ptr; + __OSContRequesFormat requestHeader; + s32 i; + + for (i = 0; i < ARRLEN(__osContPifRam.ramarray); i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8*)__osContPifRam.ramarray; + requestHeader.dummy = CONT_CMD_NOP; + requestHeader.txsize = CONT_CMD_RESET_TX; + requestHeader.rxsize = CONT_CMD_RESET_RX; + requestHeader.cmd = cmd; + requestHeader.typeh = CONT_CMD_NOP; + requestHeader.typel = CONT_CMD_NOP; + requestHeader.status = CONT_CMD_NOP; + requestHeader.dummy1 = CONT_CMD_NOP; + + for (i = 0; i < __osMaxControllers; i++) { + *(__OSContRequesFormat*)ptr = requestHeader; + ptr += sizeof(requestHeader); + } + *ptr = CONT_CMD_END; +} diff --git a/lib/ultralib/src/io/controller.h b/lib/ultralib/src/io/controller.h new file mode 100644 index 0000000..5dac7f5 --- /dev/null +++ b/lib/ultralib/src/io/controller.h @@ -0,0 +1,289 @@ +#ifndef _CONTROLLER_H +#define _CONTROLLER_H + +#include "PR/os_internal.h" +#include "PR/os_version.h" +#include "PR/rcp.h" + +//should go somewhere else but +#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) +#define CHNL_ERR(format) (((format).rxsize & CHNL_ERR_MASK) >> 4) + +typedef struct +{ + /* 0x0 */ u32 ramarray[15]; + /* 0x3C */ u32 pifstatus; +} OSPifRam; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u16 button; + /* 0x6 */ s8 stick_x; + /* 0x7 */ s8 stick_y; +} __OSContReadFormat; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 typeh; + /* 0x5 */ u8 typel; + /* 0x6 */ u8 status; + /* 0x7 */ u8 dummy1; +} __OSContRequesFormat; + +typedef struct +{ + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 typeh; + /* 0x4 */ u8 typel; + /* 0x5 */ u8 status; +} __OSContRequesFormatShort; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; +#if BUILD_VERSION >= VERSION_J + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; +#else + /* 0x4 */ u16 address; +#endif + /* 0x6 */ u8 data[BLOCKSIZE]; + /* 0x26 */ u8 datacrc; +} __OSContRamReadFormat; + +typedef union { + /* 0x0 */ struct + { + /* 0x0 */ u8 bank; + /* 0x1 */ u8 page; + } inode_t; + /* 0x0 */ u16 ipage; +} __OSInodeUnit; + +typedef struct +{ + /* 0x0 */ u32 game_code; + /* 0x4 */ u16 company_code; + /* 0x6 */ __OSInodeUnit start_page; + /* 0x8 */ u8 status; + /* 0x9 */ s8 reserved; + /* 0xA */ u16 data_sum; + /* 0xC */ u8 ext_name[PFS_FILE_EXT_LEN]; + /* 0x10 */ u8 game_name[PFS_FILE_NAME_LEN]; +} __OSDir; + +typedef struct +{ + /* 0x0 */ __OSInodeUnit inode_page[128]; +} __OSInode; + +typedef struct +{ + /* 0x0 */ u32 repaired; + /* 0x4 */ u32 random; + /* 0x8 */ u64 serial_mid; + /* 0x10 */ u64 serial_low; + /* 0x18 */ u16 deviceid; + /* 0x1A */ u8 banks; + /* 0x1B */ u8 version; + /* 0x1C */ u16 checksum; + /* 0x1E */ u16 inverted_checksum; +} __OSPackId; + +typedef struct +{ + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 address; + /* 0x4 */ u8 data[EEPROM_BLOCK_SIZE]; +} __OSContEepromFormat; + +// Joybus commands +//from: http://en64.shoutwiki.com/wiki/SI_Registers_Detailed#CONT_CMD_Usage +#define CONT_CMD_REQUEST_STATUS 0 +#define CONT_CMD_READ_BUTTON 1 +#define CONT_CMD_READ_PAK 2 +#define CONT_CMD_WRITE_PAK 3 +#define CONT_CMD_READ_EEPROM 4 +#define CONT_CMD_WRITE_EEPROM 5 +#define CONT_CMD_READ36_VOICE 9 +#define CONT_CMD_WRITE20_VOICE 10 +#define CONT_CMD_READ2_VOICE 11 +#define CONT_CMD_WRITE4_VOICE 12 +#define CONT_CMD_SWRITE_VOICE 13 +#define CONT_CMD_CHANNEL_RESET 0xFD +#define CONT_CMD_RESET 0xFF + +// Bytes transmitted for each joybus command +#define CONT_CMD_REQUEST_STATUS_TX 1 +#define CONT_CMD_READ_BUTTON_TX 1 +#define CONT_CMD_READ_PAK_TX 3 +#define CONT_CMD_WRITE_PAK_TX 35 +#define CONT_CMD_READ_EEPROM_TX 2 +#define CONT_CMD_WRITE_EEPROM_TX 10 +#define CONT_CMD_READ36_VOICE_TX 3 +#define CONT_CMD_WRITE20_VOICE_TX 23 +#define CONT_CMD_READ2_VOICE_TX 3 +#define CONT_CMD_WRITE4_VOICE_TX 7 +#define CONT_CMD_SWRITE_VOICE_TX 3 +#define CONT_CMD_RESET_TX 1 + +// Bytes received for each joybus command +#define CONT_CMD_REQUEST_STATUS_RX 3 +#define CONT_CMD_READ_BUTTON_RX 4 +#define CONT_CMD_READ_PAK_RX 33 +#define CONT_CMD_WRITE_PAK_RX 1 +#define CONT_CMD_READ_EEPROM_RX 8 +#define CONT_CMD_WRITE_EEPROM_RX 1 +#define CONT_CMD_READ36_VOICE_RX 37 +#define CONT_CMD_WRITE20_VOICE_RX 1 +#define CONT_CMD_READ2_VOICE_RX 3 +#define CONT_CMD_WRITE4_VOICE_RX 1 +#define CONT_CMD_SWRITE_VOICE_RX 1 +#define CONT_CMD_RESET_RX 3 + +#define CONT_CMD_NOP 0xff +#define CONT_CMD_END 0xfe //indicates end of a command +#define CONT_CMD_EXE 1 //set pif ram status byte to this to do a command + +#define DIR_STATUS_EMPTY 0 +#define DIR_STATUS_UNKNOWN 1 +#define DIR_STATUS_OCCUPIED 2 + +// Controller accessory addresses +// https://github.com/joeldipops/TransferBoy/blob/master/docs/TransferPakReference.md + +// Accesory detection +#define CONT_ADDR_DETECT 0x8000 +// Rumble +#define CONT_ADDR_RUMBLE 0xC000 +// Controller Pak +// Transfer Pak +#define CONT_ADDR_GB_POWER 0x8000 // Same as the detection address, but semantically different +#define CONT_ADDR_GB_BANK 0xA000 +#define CONT_ADDR_GB_STATUS 0xB000 + +// Addresses sent to controller accessories are in blocks, not bytes +#define CONT_BLOCKS(x) ((x) / BLOCKSIZE) + +// Block addresses of the above +#define CONT_BLOCK_DETECT CONT_BLOCKS(CONT_ADDR_DETECT) +#define CONT_BLOCK_RUMBLE CONT_BLOCKS(CONT_ADDR_RUMBLE) +#define CONT_BLOCK_GB_POWER CONT_BLOCKS(CONT_ADDR_GB_POWER) +#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK) +#define CONT_BLOCK_GB_STATUS CONT_BLOCKS(CONT_ADDR_GB_STATUS) + + +// Transfer pak + +#define GB_POWER_ON 0x84 +#define GB_POWER_OFF 0xFE + + +typedef struct +{ + /* 0x0 */ __OSInode inode; + /* 0x100 */ u8 bank; + /* 0x101 */ u8 map[PFS_INODE_DIST_MAP]; +} __OSInodeCache; + +extern s32 __osEepStatus(OSMesgQueue *, OSContStatus *); +u16 __osSumcalc(u8 *ptr, int length); +s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum); +s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid); +s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp); +s32 __osGetId(OSPfs *pfs); +s32 __osCheckId(OSPfs *pfs); +s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank); +#if BUILD_VERSION >= VERSION_J +s32 __osPfsSelectBank(OSPfs *pfs, u8 bank); +#else +s32 __osPfsSelectBank(OSPfs *pfs); +#endif +s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page); +#if BUILD_VERSION >= VERSION_J +s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u8 bank, __OSInodeUnit *last_page); +#else +s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag); +#endif +s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank); +s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer); +s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force); +void __osContGetInitData(u8 *pattern, OSContStatus *data); +void __osPackRequestData(u8 cmd); +void __osPfsRequestData(u8 cmd); +void __osPfsGetInitData(u8* pattern, OSContStatus* data); +u8 __osContAddressCrc(u16 addr); +u8 __osContDataCrc(u8 *data); +s32 __osPfsGetStatus(OSMesgQueue *queue, int channel); + +extern u8 __osContLastCmd; +extern OSTimer __osEepromTimer; +extern OSMesg __osEepromTimerMsg; +extern OSMesgQueue __osEepromTimerQ; +extern OSPifRam __osEepPifRam; +extern OSPifRam __osContPifRam; +extern OSPifRam __osPfsPifRam; +extern u8 __osMaxControllers; + +//some version of this almost certainly existed since there's plenty of times where it's used right before a return 0 +#define ERRCK(fn) \ + ret = fn; \ + if (ret != 0) \ + return ret + +#if BUILD_VERSION >= VERSION_J + +#define SELECT_BANK(pfs, bank) \ + __osPfsSelectBank((pfs), (bank)) + +#define SET_ACTIVEBANK_TO_ZERO() \ + if (pfs->activebank != 0) \ + { \ + ERRCK(__osPfsSelectBank(pfs, 0)); \ + } (void)0 + +#else + +#define SELECT_BANK(pfs, bank) \ + (pfs->activebank = (bank), __osPfsSelectBank((pfs))) + +#define SET_ACTIVEBANK_TO_ZERO() \ + if (pfs->activebank != 0) \ + { \ + pfs->activebank = 0; \ + ERRCK(__osPfsSelectBank(pfs)); \ + } (void)0 + +#endif + +#define PFS_CHECK_ID() \ + if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \ + return PFS_ERR_NEW_PACK + +#define PFS_CHECK_STATUS() \ + if ((pfs->status & PFS_INITIALIZED) == 0) \ + return PFS_ERR_INVALID + +#define PFS_GET_STATUS() \ + __osSiGetAccess(); \ + ret = __osPfsGetStatus(queue, channel); \ + __osSiRelAccess(); \ + if (ret != 0) \ + return ret + +#endif diff --git a/lib/ultralib/src/io/controller_gbpak.h b/lib/ultralib/src/io/controller_gbpak.h new file mode 100644 index 0000000..db98bd4 --- /dev/null +++ b/lib/ultralib/src/io/controller_gbpak.h @@ -0,0 +1,8 @@ +#ifndef _CONTROLLER_GBPAK_H +#define _CONTROLLER_GBPAK_H + +extern OSTimer __osGbpakTimer; +extern OSMesg __osGbpakTimerMsg; +extern OSMesgQueue __osGbpakTimerQ; + +#endif diff --git a/lib/ultralib/src/io/controller_voice.h b/lib/ultralib/src/io/controller_voice.h new file mode 100644 index 0000000..1b9dee6 --- /dev/null +++ b/lib/ultralib/src/io/controller_voice.h @@ -0,0 +1,59 @@ +#ifndef CONTROLLER_VOICE_H +#define CONTROLLER_VOICE_H + +#include "PR/ultratypes.h" + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[2]; + /* 0x8 */ u8 datacrc; +} __OSVoiceRead2Format; + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[36]; + /* 0x2A */ u8 datacrc; +} __OSVoiceRead36Format; + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[4]; + /* 0xA */ u8 datacrc; +} __OSVoiceWrite4Format; + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[20]; + /* 0x1A */ u8 datacrc; +} __OSVoiceWrite20Format; + +typedef struct { + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 data; + /* 0x4 */ u8 scrc; + /* 0x5 */ u8 datacrc; +} __OSVoiceSWriteFormat; + +#endif // CONTROLLER_VOICE_H diff --git a/lib/ultralib/src/io/contsetch.c b/lib/ultralib/src/io/contsetch.c new file mode 100644 index 0000000..0cababd --- /dev/null +++ b/lib/ultralib/src/io/contsetch.c @@ -0,0 +1,19 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +s32 osContSetCh(u8 ch) { + s32 ret = 0; + + __osSiGetAccess(); + + if (ch > MAXCONTROLLERS) { + __osMaxControllers = MAXCONTROLLERS; + } else { + __osMaxControllers = ch; + } + + __osContLastCmd = CONT_CMD_END; + __osSiRelAccess(); + return ret; +} diff --git a/lib/ultralib/src/io/crc.c b/lib/ultralib/src/io/crc.c new file mode 100644 index 0000000..3293b2d --- /dev/null +++ b/lib/ultralib/src/io/crc.c @@ -0,0 +1,114 @@ +#include "PR/os_internal.h" + +#if BUILD_VERSION >= VERSION_J + +u8 __osContAddressCrc(u16 addr) { + u32 temp = 0; + u32 i = 0x400; + + do { + temp <<= 1; + + if ((u32)addr & i) { + if (temp & 0x20) { + temp ^= 0x14; + } else { + ++temp; + } + } else if (temp & 0x20) { + temp ^= 0x15; + } + + i >>= 1; + } while (i != 0); + + i = 5; + + do { + temp <<= 1; + if (temp & 0x20) { + temp ^= 0x15; + } + } while (--i != 0); + + return temp & 0x1F; +} + +u8 __osContDataCrc(u8* data) { + u32 temp = 0; + u32 i; + u32 j; + + for (i = 0x20; i; --i) { + for (j = 0x80; j; j >>= 1) { + temp <<= 1; + + if ((*data & j) != 0) { + if ((temp & 0x100) != 0) { + temp ^= 0x84; + } else { + ++temp; + } + } else if (temp & 0x100) { + temp ^= 0x85; + } + } + + data++; + } + do { + temp <<= 1; + + if (temp & 0x100) { + temp ^= 0x85; + } + } while (++i < 8U); + + return temp; +} + +#else + +u8 __osContAddressCrc(u16 addr) { + u8 temp = 0; + u8 temp2; + int i; + + for (i = 0; i < 16; i++) { + temp2 = (temp & 0x10) ? 0x15 : 0; + + temp <<= 1; + temp |= (u8)((addr & 0x400) ? 1 : 0); + addr <<= 1; + temp ^= temp2; + } + + return temp & 0x1f; +} + +u8 __osContDataCrc(u8 *data) { + u8 temp = 0; + u8 temp2; + int i; + int j; + + for (i = 0; i <= 32; i++) { + for (j = 7; j > -1; j--) { + temp2 = (temp & 0x80) ? 0x85 : 0; + + temp <<= 1; + + if (i == 32) { + temp &= -1; + } else { + temp |= ((*data & (1 << j)) ? 1 : 0); + } + + temp ^= temp2; + } + data++; + } + return temp; +} + +#endif diff --git a/lib/ultralib/src/io/devmgr.c b/lib/ultralib/src/io/devmgr.c new file mode 100644 index 0000000..616dee5 --- /dev/null +++ b/lib/ultralib/src/io/devmgr.c @@ -0,0 +1,108 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "piint.h" + +void __osDevMgrMain(void* args) { + OSIoMesg* mb; + OSMesg em; + OSMesg dummy; + s32 ret; + OSDevMgr* dm; + s32 messageSend = 0; + + dm = (OSDevMgr*)args; + mb = NULL; + ret = 0; + + while (TRUE) { + osRecvMesg(dm->cmdQueue, (OSMesg)&mb, OS_MESG_BLOCK); + + if (mb->piHandle != NULL && mb->piHandle->type == DEVICE_TYPE_64DD && + (mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0 || + mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_1)) { + __OSBlockInfo* blockInfo; + __OSTranxInfo* info; + info = &mb->piHandle->transferInfo; + blockInfo = &info->block[info->blockNum]; + info->sectorNum = -1; + + if (info->transferMode != LEO_SECTOR_MODE) { + blockInfo->dramAddr = (void*)((u32)blockInfo->dramAddr - blockInfo->sectorSize); + } + + if (info->transferMode == LEO_TRACK_MODE && mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0) { + messageSend = 1; + } else { + messageSend = 0; + } + + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + __osResetGlobalIntMask(OS_IM_PI); + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, (info->bmCtlShadow | 0x80000000)); + + readblock1: + osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); + info = &mb->piHandle->transferInfo; + blockInfo = &info->block[info->blockNum]; + + if (blockInfo->errStatus == LEO_ERROR_29) { + u32 stat; + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow); + __osEPiRawReadIo(mb->piHandle, LEO_STATUS, &stat); + + if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); + } + + blockInfo->errStatus = LEO_ERROR_4; + IO_WRITE(PI_STATUS_REG, PI_CLR_INTR); + __osSetGlobalIntMask(OS_IM_PI | SR_IBIT4); + } + + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + + if (messageSend == 1 && mb->piHandle->transferInfo.block[0].errStatus == LEO_ERROR_GOOD) { + messageSend = 0; + goto readblock1; + } + + osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); + if (mb->piHandle->transferInfo.blockNum == 1) { + osYieldThread(); + } + } else { + switch (mb->hdr.type) { + case OS_MESG_TYPE_DMAREAD: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->dma(OS_READ, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_DMAWRITE: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->dma(OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_EDMAREAD: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->edma(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_EDMAWRITE: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->edma(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_LOOPBACK: + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + ret = -1; + break; + default: + ret = -1; + break; + } + + if (ret == 0) { + osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); + } + } + } +} diff --git a/lib/ultralib/src/io/dp.c b/lib/ultralib/src/io/dp.c new file mode 100644 index 0000000..e636217 --- /dev/null +++ b/lib/ultralib/src/io/dp.c @@ -0,0 +1,15 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osDpDeviceBusy(void) { + register u32 stat = IO_READ(DPC_STATUS_REG); + + if (stat & DPC_STATUS_DMA_BUSY) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/ultralib/src/io/dpctr.c b/lib/ultralib/src/io/dpctr.c new file mode 100644 index 0000000..a53b030 --- /dev/null +++ b/lib/ultralib/src/io/dpctr.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +void osDpGetCounters(u32* array) { + *array++ = IO_READ(DPC_CLOCK_REG); + *array++ = IO_READ(DPC_BUFBUSY_REG); + *array++ = IO_READ(DPC_PIPEBUSY_REG); + *array++ = IO_READ(DPC_TMEM_REG); +} diff --git a/lib/ultralib/src/io/dpgetstat.c b/lib/ultralib/src/io/dpgetstat.c new file mode 100644 index 0000000..af3ccee --- /dev/null +++ b/lib/ultralib/src/io/dpgetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osDpGetStatus() { + return IO_READ(DPC_STATUS_REG); +} diff --git a/lib/ultralib/src/io/dpsetnextbuf.c b/lib/ultralib/src/io/dpsetnextbuf.c new file mode 100644 index 0000000..6314472 --- /dev/null +++ b/lib/ultralib/src/io/dpsetnextbuf.c @@ -0,0 +1,39 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "../os/osint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osDpSetNextBuffer(void* bufPtr, u64 size) { + register u32 stat; + +#ifdef _DEBUG + if ((u32)bufPtr & 0x7) { + __osError(ERR_OSDPSETNEXTBUFFER_ADDR, 1, bufPtr); + return -1; + } + if (size & 0x7) { + __osError(ERR_OSDPSETNEXTBUFFER_SIZE, 1, size); + return -1; + } +#endif + + if (__osDpDeviceBusy()) { + return -1; + } + + IO_WRITE(DPC_STATUS_REG, DPC_CLR_XBUS_DMEM_DMA); + + while (TRUE) { + stat = IO_READ(DPC_STATUS_REG); + if ((stat & DPC_STATUS_XBUS_DMEM_DMA) == 0) { + break; + } + } + + IO_WRITE(DPC_START_REG, osVirtualToPhysical(bufPtr)); + IO_WRITE(DPC_END_REG, osVirtualToPhysical(bufPtr) + size); + return 0; +} diff --git a/lib/ultralib/src/io/dpsetstat.c b/lib/ultralib/src/io/dpsetstat.c new file mode 100644 index 0000000..5b53867 --- /dev/null +++ b/lib/ultralib/src/io/dpsetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osDpSetStatus(u32 data) { + IO_WRITE(DPC_STATUS_REG, data); +} diff --git a/lib/ultralib/src/io/driverominit.c b/lib/ultralib/src/io/driverominit.c new file mode 100644 index 0000000..d73d349 --- /dev/null +++ b/lib/ultralib/src/io/driverominit.c @@ -0,0 +1,31 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "macros.h" + +OSPiHandle DriveRomHandle ALIGNED(8); + +OSPiHandle *osDriveRomInit() { + u32 saveMask; + + if (DriveRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR1)) { + return &DriveRomHandle; + } + + DriveRomHandle.type = DEVICE_TYPE_BULK; + DriveRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR1); + DriveRomHandle.latency = 64; + DriveRomHandle.pulse = 7; + DriveRomHandle.pageSize = 7; + DriveRomHandle.relDuration = 2; + DriveRomHandle.domain = PI_DOMAIN1; + DriveRomHandle.speed = 0; + + bzero(&DriveRomHandle.transferInfo, sizeof(__OSTranxInfo)); + + saveMask = __osDisableInt(); + DriveRomHandle.next = __osPiTable; + __osPiTable = &DriveRomHandle; + __osRestoreInt(saveMask); + + return &DriveRomHandle; +} diff --git a/lib/ultralib/src/io/epidma.c b/lib/ultralib/src/io/epidma.c new file mode 100644 index 0000000..06a9f69 --- /dev/null +++ b/lib/ultralib/src/io/epidma.c @@ -0,0 +1,61 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { + register s32 ret; + + if (!__osPiDevMgr.active) { +#ifdef _DEBUG + __osError(ERR_OSPISTARTDMA_PIMGR, 0); +#endif + return -1; + } + +#ifdef _DEBUG + if ((mb->hdr.pri != OS_MESG_PRI_NORMAL) && (mb->hdr.pri != OS_MESG_PRI_HIGH)) { + __osError(ERR_OSPISTARTDMA_PRI, 1, mb->hdr.pri); + return -1; + } + + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPISTARTDMA_DIR, 1, direction); + return -1; + } + + if (mb->devAddr & 0x1) { + __osError(ERR_OSPISTARTDMA_DEVADDR, 1, mb->devAddr); + return -1; + } + + if ((u32)mb->dramAddr & 0x7) { + __osError(ERR_OSPISTARTDMA_ADDR, 1, mb->dramAddr); + return -1; + } + + if (mb->size & 0x1) { + __osError(ERR_OSPISTARTDMA_SIZE, 1, mb->size); + return -1; + } + + if ((mb->size == 0) || (mb->size > (16 * 1024 * 1024))) { + __osError(ERR_OSPISTARTDMA_RANGE, 1, mb->size); + return -1; + } +#endif + + mb->piHandle = pihandle; + + if (direction == OS_READ) { + mb->hdr.type = OS_MESG_TYPE_EDMAREAD; + } else { + mb->hdr.type = OS_MESG_TYPE_EDMAWRITE; + } + + if (mb->hdr.pri == OS_MESG_PRI_HIGH) { + ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); + } else { + ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); + } + + return ret; +} diff --git a/lib/ultralib/src/io/epigettype.c b/lib/ultralib/src/io/epigettype.c new file mode 100644 index 0000000..c94012c --- /dev/null +++ b/lib/ultralib/src/io/epigettype.c @@ -0,0 +1,7 @@ +#include "piint.h" + +s32 osEPiGetDeviceType(OSPiHandle* pihandle, OSPiInfo* info) { + info->type = pihandle->type; + info->address = pihandle->baseAddress; + return 0; +} diff --git a/lib/ultralib/src/io/epilinkhandle.c b/lib/ultralib/src/io/epilinkhandle.c new file mode 100644 index 0000000..5f51854 --- /dev/null +++ b/lib/ultralib/src/io/epilinkhandle.c @@ -0,0 +1,11 @@ +#include "piint.h" + +s32 osEPiLinkHandle(OSPiHandle* EPiHandle) { + u32 saveMask = __osDisableInt(); + + EPiHandle->next = __osPiTable; + __osPiTable = EPiHandle; + + __osRestoreInt(saveMask); + return 0; +} diff --git a/lib/ultralib/src/io/epirawdma.c b/lib/ultralib/src/io/epirawdma.c new file mode 100644 index 0000000..69a404d --- /dev/null +++ b/lib/ultralib/src/io/epirawdma.c @@ -0,0 +1,53 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawStartDma(OSPiHandle* pihandle, s32 direction, u32 devAddr, void* dramAddr, u32 size) { + u32 stat; + u32 domain; + +#ifdef _DEBUG + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32)dramAddr & 0x7) { + __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + EPI_SYNC(pihandle, stat, domain); + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(pihandle->baseAddress | devAddr)); + + switch (direction) { + case OS_READ: + IO_WRITE(PI_WR_LEN_REG, size - 1); + break; + case OS_WRITE: + IO_WRITE(PI_RD_LEN_REG, size - 1); + break; + default: + return -1; + } + return 0; +} diff --git a/lib/ultralib/src/io/epirawread.c b/lib/ultralib/src/io/epirawread.c new file mode 100644 index 0000000..500a2ce --- /dev/null +++ b/lib/ultralib/src/io/epirawread.c @@ -0,0 +1,48 @@ +#include "piint.h" +#include "PR/ultraerror.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 28 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data) { + register u32 stat; + register u32 domain; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWREADIO, 1, devAddr); + return -1; + } +#endif + assert(data != NULL); + + EPI_SYNC(pihandle, stat, domain); + *data = IO_READ(pihandle->baseAddress | devAddr); + + return 0; +} diff --git a/lib/ultralib/src/io/epirawwrite.c b/lib/ultralib/src/io/epirawwrite.c new file mode 100644 index 0000000..79fba31 --- /dev/null +++ b/lib/ultralib/src/io/epirawwrite.c @@ -0,0 +1,22 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data) { + register u32 stat; + register u32 domain; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWWRITEIO, 1, devAddr); + return -1; + } +#endif + + EPI_SYNC(pihandle, stat, domain); + IO_WRITE(pihandle->baseAddress | devAddr, data); + + return 0; +} diff --git a/lib/ultralib/src/io/epiread.c b/lib/ultralib/src/io/epiread.c new file mode 100644 index 0000000..08cd0be --- /dev/null +++ b/lib/ultralib/src/io/epiread.c @@ -0,0 +1,19 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +s32 osEPiReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data) { + register s32 ret; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIREADIO, 1, devAddr); + return -1; + } +#endif + + __osPiGetAccess(); + ret = __osEPiRawReadIo(pihandle, devAddr, data); + __osPiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/io/epiwrite.c b/lib/ultralib/src/io/epiwrite.c new file mode 100644 index 0000000..42a239e --- /dev/null +++ b/lib/ultralib/src/io/epiwrite.c @@ -0,0 +1,19 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +s32 osEPiWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data) { + register s32 ret; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIWRITEIO, 1, devAddr); + return -1; + } +#endif + + __osPiGetAccess(); + ret = __osEPiRawWriteIo(pihandle, devAddr, data); + __osPiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/io/gbpakcheckconnector.c b/lib/ultralib/src/io/gbpakcheckconnector.c new file mode 100644 index 0000000..8eb3298 --- /dev/null +++ b/lib/ultralib/src/io/gbpakcheckconnector.c @@ -0,0 +1,131 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "controller.h" + +s32 osGbpakCheckConnector(OSPfs* pfs, u8* status) { + s32 ret; + s32 bufn = 1; + s32 oldbufn = 0; + u16 address = 0; + u16 oldaddr = 0; + u16 daddr = 0; + u16 num; + u8 buf[3][4][BLOCKSIZE]; + u8 buf_status[3][4]; + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = osGbpakGetStatus(pfs, status); + } + + if (ret == PFS_ERR_NEW_GBCART) { + return PFS_ERR_CONTRFAIL; + } else if (ret == 0) { + if (!(*status & OS_GBPAK_POWER)) { + ERRCK(osGbpakPower(pfs, OS_GBPAK_POWER_ON)); + } + + bzero(buf_status, sizeof(buf_status)); + + for (address = 0x80; address <= 0x4000; address <<= 1) { + num = 0; + daddr = 0; + + do { + ERRCK(osGbpakReadWrite(pfs, OS_READ, address + daddr, buf[bufn][num], BLOCKSIZE)); + buf_status[bufn][num] = 1; + + if (buf_status[oldbufn][num] == 0) { + ret = osGbpakReadWrite(pfs, OS_READ, oldaddr + daddr, buf[oldbufn][num], BLOCKSIZE); + + if (ret != 0) { + return ret; + } else { + buf_status[oldbufn][num] = 1; + } + } + + if (bcmp(buf[bufn][num], buf[oldbufn][num], BLOCKSIZE) != 0) { + num = 0; + break; + } + + daddr += BLOCKSIZE; + } while (num++ < ARRLEN(buf[0]) - 1); + + if (num != 0) { + return PFS_ERR_CONTRFAIL; + } + + if (oldbufn != 0) { + num = 0; + daddr = 0; + + do { + if (buf_status[bufn][num] == 0) { + ERRCK(osGbpakReadWrite(pfs, OS_READ, address + daddr, buf[bufn][num], BLOCKSIZE)); + buf_status[bufn][num] = 1; + } + + if (buf_status[0][num] == 0) { + ret = osGbpakReadWrite(pfs, OS_READ, daddr, buf[0][num], BLOCKSIZE); + if (ret != 0) { + return ret; + } else { + buf_status[0][num] = 1; + } + } + + if (bcmp(buf[bufn][num], buf[0][num], BLOCKSIZE)) { + num = 0; + break; + } + + daddr += BLOCKSIZE; + } while (num++ < ARRLEN(buf_status[0]) - 1); + } + + if (num != 0) { + return PFS_ERR_CONTRFAIL; + } + + if (oldbufn != 0) { + bzero(buf_status[oldbufn], ARRLEN(buf_status[oldbufn])); + } + + oldaddr = address; + oldbufn = bufn; + bufn ^= 3; + } + + if ((pfs->dir_size >= 2) || (pfs->version == 2)) { + num = 0; + daddr = 0; + + do { + ERRCK(osGbpakReadWrite(pfs, OS_READ, daddr + 0xA000, buf[bufn][num], BLOCKSIZE)); + ERRCK(osGbpakReadWrite(pfs, OS_READ, daddr + 0x2000, buf[oldbufn][num], BLOCKSIZE)); + + if (bcmp(buf[bufn][num], buf[oldbufn][num], BLOCKSIZE)) { + num = 0; + break; + } + + daddr += BLOCKSIZE; + } while (num++ < ARRLEN(buf[0]) - 1); + + if (num != 0) { + return PFS_ERR_CONTRFAIL; + } + } + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = PFS_ERR_CONTRFAIL; + } + } + + return ret; +} diff --git a/lib/ultralib/src/io/gbpakgetbank.c b/lib/ultralib/src/io/gbpakgetbank.c new file mode 100644 index 0000000..a2e5f38 --- /dev/null +++ b/lib/ultralib/src/io/gbpakgetbank.c @@ -0,0 +1,28 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 __osGbpakGetBank(OSPfs* pfs, u8* bank) { + s32 ret; + u32 temp[BLOCKSIZE / sizeof(u32)]; + + ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, (u8*)temp); + + if (ret == PFS_ERR_NEW_PACK) { + ret = osGbpakInit(pfs->queue, pfs, pfs->channel); + + if (ret == 0) { + ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, (u8*)temp); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + } + } + + if (ret == 0) { + *bank = ((u8*)temp)[0]; + pfs->banks = *bank; + } + + return ret; +} diff --git a/lib/ultralib/src/io/gbpakgetstatus.c b/lib/ultralib/src/io/gbpakgetstatus.c new file mode 100644 index 0000000..d17d15c --- /dev/null +++ b/lib/ultralib/src/io/gbpakgetstatus.c @@ -0,0 +1,39 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osGbpakGetStatus(OSPfs* pfs, u8* status) { + s32 ret; + s32 i; + u32 temp[BLOCKSIZE / sizeof(u32)]; + + ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_POWER, (u8*)temp); + + if ((ret == PFS_ERR_NEW_PACK) || (((u8*)temp)[BLOCKSIZE - 1] != GB_POWER_ON)) { + ERRCK(osGbpakInit(pfs->queue, pfs, pfs->channel)); + } + + ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_STATUS, (u8*)temp); + + if (ret == 0) { + ERRCK(__osPfsGetStatus(pfs->queue, pfs->channel)); + + *status = ((u8*)temp)[0]; + + for (i = 1; i < BLOCKSIZE; i++) { + *status |= ((u8*)temp)[i]; + } + + *status &= (OS_GBPAK_GBCART_PULL | OS_GBPAK_RSTB_DETECTION); + *status |= ((u8*)temp)[BLOCKSIZE - 1]; + + if (!(*status & OS_GBPAK_GBCART_ON)) { + ret = PFS_ERR_NO_GBCART; + } else if (*status & OS_GBPAK_GBCART_PULL) { + ret = PFS_ERR_NEW_GBCART; + } + } else if (ret == 2) { + ret = PFS_ERR_CONTRFAIL; + } + + return ret; +} diff --git a/lib/ultralib/src/io/gbpakinit.c b/lib/ultralib/src/io/gbpakinit.c new file mode 100644 index 0000000..102d962 --- /dev/null +++ b/lib/ultralib/src/io/gbpakinit.c @@ -0,0 +1,90 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "controller.h" +#include "controller_gbpak.h" + +OSTimer __osGbpakTimer; +OSMesgQueue __osGbpakTimerQ ALIGNED(8); +OSMesg __osGbpakTimerMsg; + +s32 osGbpakInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { + int i; + s32 ret; + u8 temp[BLOCKSIZE]; + + pfs->status = 0; + + // Turn off the transfer pak + for (i = 0; i < BLOCKSIZE; temp[i++] = GB_POWER_OFF) { + ; + } + + ret = __osContRamWrite(mq, channel, CONT_BLOCK_GB_POWER, temp, FALSE); + if (ret == PFS_ERR_NEW_PACK) { + ret = __osContRamWrite(mq, channel, CONT_BLOCK_GB_POWER, temp, FALSE); + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_GB_POWER, temp); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } else { + // Check if the power is still off as set earlier + if (temp[BLOCKSIZE - 1] == GB_POWER_OFF) { + return PFS_ERR_DEVICE; + } + } + + // Turn on the transfer pak + for (i = 0; i < BLOCKSIZE; temp[i++] = GB_POWER_ON) { + ; + } + + ret = __osContRamWrite(mq, channel, CONT_BLOCK_GB_POWER, temp, FALSE); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_GB_POWER, temp); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } else { + // Check if the power is still on as set earlier + if (temp[BLOCKSIZE - 1] != GB_POWER_ON) { + return PFS_ERR_DEVICE; + } + } + + ERRCK(__osPfsGetStatus(mq, channel)); + + osCreateMesgQueue(&__osGbpakTimerQ, &__osGbpakTimerMsg, 1); + osSetTimer(&__osGbpakTimer, OS_USEC_TO_CYCLES(192000), 0, &__osGbpakTimerQ, &__osGbpakTimerMsg); + osRecvMesg(&__osGbpakTimerQ, NULL, OS_MESG_BLOCK); + pfs->queue = mq; + pfs->status = PFS_GBPAK_INITIALIZED; + pfs->channel = channel; + pfs->activebank = 0x84; + pfs->banks = 0xFF; + pfs->version = 0xFF; + pfs->dir_size = 0xFF; + + return 0; +} diff --git a/lib/ultralib/src/io/gbpakpower.c b/lib/ultralib/src/io/gbpakpower.c new file mode 100644 index 0000000..3d4a8f4 --- /dev/null +++ b/lib/ultralib/src/io/gbpakpower.c @@ -0,0 +1,34 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "controller_gbpak.h" + +s32 osGbpakPower(OSPfs* pfs, s32 flag) { + s32 i; + s32 ret; + u8 temp[BLOCKSIZE]; + + for (i = 0; i < BLOCKSIZE; temp[i++] = (u8)flag) { + ; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_STATUS, temp, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = osGbpakInit(pfs->queue, pfs, pfs->channel); + + if (ret == 0) { + ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_STATUS, temp, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + } + } + + if (flag != OS_GBPAK_POWER_OFF) { + osSetTimer(&__osGbpakTimer, OS_USEC_TO_CYCLES(120000), 0, &__osGbpakTimerQ, &__osGbpakTimerMsg); + osRecvMesg(&__osGbpakTimerQ, NULL, OS_MESG_BLOCK); + } + + return ret; +} diff --git a/lib/ultralib/src/io/gbpakreadid.c b/lib/ultralib/src/io/gbpakreadid.c new file mode 100644 index 0000000..3e2fa19 --- /dev/null +++ b/lib/ultralib/src/io/gbpakreadid.c @@ -0,0 +1,97 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "controller.h" +#include "os_version.h" + +s32 osGbpakReadId(OSPfs* pfs, OSGbpakId* id, u8* status) { + s32 i; + s32 ret; + u8 isum; + u8 buf[96]; +#if BUILD_VERSION >= VERSION_K + u8 temp[32]; +#endif + static u8 nintendo[] = { 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83, + 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E, + 0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDD, 0xD9, 0x99, 0xBB, 0xBB, 0x67, 0x63, + 0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E }; + static u8 mmc_type[] = { 0x00, 0x01, 0x01, 0x01, 0xFF, 0x02, 0x02, 0xFF, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03 }; + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = osGbpakGetStatus(pfs, status); + } + + if (ret == PFS_ERR_NEW_GBCART) { + return PFS_ERR_CONTRFAIL; + } else if (ret == 0) { + if (!(*status & OS_GBPAK_POWER)) { + ERRCK(osGbpakPower(pfs, OS_GBPAK_POWER_ON)); + } + + ERRCK(osGbpakReadWrite(pfs, OS_READ, 0x100U, buf, ARRLEN(buf))); + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + if (!(*status & OS_GBPAK_RSTB_STATUS)) { + return PFS_ERR_CONTRFAIL; + } + +#if BUILD_VERSION >= VERSION_K + if (bcmp(nintendo, buf + 4, ARRLEN(nintendo))) { + for (i = 0; i < ARRLEN(temp); temp[i++] = 0) { + ; + } + + ERRCK(osGbpakReadWrite(pfs, OS_WRITE, 0x6000U, temp, ARRLEN(temp))); + ret = osGbpakReadWrite(pfs, OS_READ, 0x100U, buf, ARRLEN(buf)); + ERRCK(osGbpakReadWrite(pfs, OS_READ, 0x100U, buf, ARRLEN(buf))); + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + if (bcmp(nintendo, buf + 4, ARRLEN(nintendo))) { + return 4; + } + } +#else + if (bcmp(nintendo, buf + 4, ARRLEN(nintendo))) { + return 4; + } +#endif + for (i = 0x34, isum = 0; i < 0x4E; i++) { + isum += buf[i]; + } + + if ((isum + 0x19) & 0xFF) { + return 4; + } + + bcopy(buf, id, 0x50); + + if (id->cart_type < 0x14) { + pfs->version = (int)mmc_type[id->cart_type]; + } + + pfs->dir_size = (int)id->ram_size; + } + + return ret; +} diff --git a/lib/ultralib/src/io/gbpakreadwrite.c b/lib/ultralib/src/io/gbpakreadwrite.c new file mode 100644 index 0000000..a6d4b02 --- /dev/null +++ b/lib/ultralib/src/io/gbpakreadwrite.c @@ -0,0 +1,74 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "os_version.h" + +s32 __osGbpakSetBank(OSPfs* pfs, u8 bank); + +s32 osGbpakReadWrite(OSPfs* pfs, u16 flag, u16 address, u8* buffer, u16 size) { + s32 i; + s32 ret; + u8 bank; + + bank = (u8)(address >> 0xE); + + if (bank != pfs->banks) { + ret = __osGbpakSetBank(pfs, bank); + + if (ret != 0) { + return ret; + } + } + +#if BUILD_VERSION >= VERSION_K + if (size == 0) { + return 0; + } +#endif + + size = (u16)(size >> 5); + address = (u16)((address | 0xC000) >> 5); + + if (flag == 1) { + for (i = 0; i < (s32)size; i++, buffer += BLOCKSIZE) { + ret = __osContRamWrite(pfs->queue, pfs->channel, address, buffer, 0); + + if (ret != 0) { + break; + } + + if ((++address >= 0x800) && (i < (s32)(size - 1))) { + ret = __osGbpakSetBank(pfs, ++bank); + + if (ret != 0) { + break; + } + + address = 0x600U; + } + } + } else { + for (i = 0; i < (s32)size; i++, buffer += BLOCKSIZE) { + ret = __osContRamRead(pfs->queue, pfs->channel, address, buffer); + + if (ret != 0) { + break; + } + + if (++address >= 0x800 && (i < (s32)(size - 1))) { + ret = __osGbpakSetBank(pfs, ++bank); + + if (ret != 0) { + break; + } + + address = 0x600U; + } + } + } + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + return ret; +} diff --git a/lib/ultralib/src/io/gbpaksetbank.c b/lib/ultralib/src/io/gbpaksetbank.c new file mode 100644 index 0000000..7a08646 --- /dev/null +++ b/lib/ultralib/src/io/gbpaksetbank.c @@ -0,0 +1,35 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 __osGbpakSetBank(OSPfs* pfs, u8 bank) { + int i; + s32 ret; + u8 temp[BLOCKSIZE]; + + if (bank > 2) { + return PFS_ERR_INVALID; + } + + for (i = 0; i < BLOCKSIZE; temp[i++] = bank) { + ; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, temp, FALSE); + + if (ret == PFS_ERR_NEW_PACK) { + ret = osGbpakInit(pfs->queue, pfs, pfs->channel); + + if (ret == 0) { + ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_GB_BANK, temp, FALSE); + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + } + } + + if (ret == 0) { + pfs->banks = bank; + } + + return ret; +} diff --git a/lib/ultralib/src/io/leodiskinit.c b/lib/ultralib/src/io/leodiskinit.c new file mode 100644 index 0000000..e9f140b --- /dev/null +++ b/lib/ultralib/src/io/leodiskinit.c @@ -0,0 +1,36 @@ +// This file was removed in 2.0J +#include "PR/os_internal.h" +#include "PR/os_libc.h" +#include "PR/rcp.h" +#include "macros.h" + +OSPiHandle LeoDiskHandle ALIGNED(8); +OSPiHandle *__osDiskHandle; + +OSPiHandle *osLeoDiskInit() { + u32 saveMask; + + LeoDiskHandle.type = DEVICE_TYPE_64DD; + LeoDiskHandle.baseAddress = PHYS_TO_K1(PI_DOM2_ADDR1); + LeoDiskHandle.latency = 3; + LeoDiskHandle.pulse = 6; + LeoDiskHandle.pageSize = 6; + LeoDiskHandle.relDuration = 2; + LeoDiskHandle.domain = PI_DOMAIN2; + + IO_WRITE(PI_BSD_DOM2_LAT_REG, LeoDiskHandle.latency); + IO_WRITE(PI_BSD_DOM2_PWD_REG, LeoDiskHandle.pulse); + IO_WRITE(PI_BSD_DOM2_PGS_REG, LeoDiskHandle.pageSize); + IO_WRITE(PI_BSD_DOM2_RLS_REG, LeoDiskHandle.relDuration); + LeoDiskHandle.speed = 0; + + bzero(&LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo)); + + saveMask = __osDisableInt(); + LeoDiskHandle.next = __osPiTable; + __osPiTable = &LeoDiskHandle; + __osDiskHandle = &LeoDiskHandle; + __osRestoreInt(saveMask); + + return &LeoDiskHandle; +} diff --git a/lib/ultralib/src/io/leointerrupt.c b/lib/ultralib/src/io/leointerrupt.c new file mode 100644 index 0000000..ad34e45 --- /dev/null +++ b/lib/ultralib/src/io/leointerrupt.c @@ -0,0 +1,194 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "../os/osint.h" +#include "piint.h" +#include "macros.h" + +extern OSPiHandle *__osDiskHandle; + +u8 leoDiskStack[OS_PIM_STACKSIZE] ALIGNED(16); + +static void __osLeoAbnormalResume(void); +static void __osLeoResume(void); + +s32 __osLeoInterrupt() { + u32 stat = 0; + volatile u32 pi_stat; + u32 bm_stat; + __OSTranxInfo *info = &__osDiskHandle->transferInfo; + __OSBlockInfo *blockInfo = &info->block[info->blockNum]; + + pi_stat = IO_READ(PI_STATUS_REG); + if (pi_stat & PI_STATUS_DMA_BUSY) { + __OSGlobalIntMask = __OSGlobalIntMask & ~SR_IBIT4; //cart interrupt + blockInfo->errStatus = LEO_ERROR_29; + __osLeoResume(); + return 1; + } + + WAIT_ON_IOBUSY(pi_stat); + stat = IO_READ(LEO_STATUS); + if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); + blockInfo->errStatus = LEO_ERROR_GOOD; + return 0; + } + + if (info->cmdType == LEO_CMD_TYPE_2) { + return 1; + } + + if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR) { + WAIT_ON_IOBUSY(pi_stat); + stat = IO_READ(LEO_STATUS); + blockInfo->errStatus = LEO_ERROR_22; + __osLeoResume(); + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + return 1; + } + + if (info->cmdType == LEO_CMD_TYPE_1) { + if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { + if (info->sectorNum + 1 != info->transferMode * 85) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + blockInfo->errStatus = LEO_ERROR_GOOD; + __osLeoResume(); + return 1; + } else { + blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr + blockInfo->sectorSize); + info->sectorNum++; + __osEPiRawStartDma(__osDiskHandle, OS_WRITE, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); + return 1; + } + } else if (info->cmdType == LEO_CMD_TYPE_0) { + if (info->transferMode == LEO_SECTOR_MODE) { + if (info->sectorNum > (s32)blockInfo->C1ErrNum + 17) { + blockInfo->errStatus = LEO_ERROR_GOOD; + __osLeoAbnormalResume(); + return 1; + } + + if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { + blockInfo->errStatus = LEO_ERROR_23; + __osLeoAbnormalResume(); + return 1; + } + } else { + blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr + blockInfo->sectorSize); + } + + bm_stat = IO_READ(LEO_BM_STATUS); + if ((bm_stat & LEO_BM_STATUS_C1SINGLE && bm_stat & LEO_BM_STATUS_C1DOUBLE) || bm_stat & LEO_BM_STATUS_MICRO) { + if (blockInfo->C1ErrNum > 3) { + if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52) { + blockInfo->errStatus = LEO_ERROR_23; + __osLeoAbnormalResume(); + return 1; + } + } else { + int errNum = blockInfo->C1ErrNum; + blockInfo->C1ErrSector[errNum] = info->sectorNum + 1; + } + + blockInfo->C1ErrNum++; + } + + if (stat & LEO_STATUS_C2_TRANSFER) { + if (info->sectorNum + 1 != 88) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + } + + if (info->transferMode == LEO_TRACK_MODE && info->blockNum == 0) { + info->blockNum = 1; + info->sectorNum = -1; + info->block[1].dramAddr = (void *)((u32)info->block[1].dramAddr - info->block[1].sectorSize); + + blockInfo->errStatus = LEO_ERROR_22; + } else { + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + info->cmdType = LEO_CMD_TYPE_2; + blockInfo->errStatus = LEO_ERROR_GOOD; + } + + __osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4); + return 1; + } + + if (info->sectorNum == -1 && info->transferMode == LEO_TRACK_MODE && info->blockNum == 1) { + __OSBlockInfo *bptr = &info->block[0]; + if (bptr->C1ErrNum == 0) { + if (((u32 *)bptr->C2Addr)[0] | ((u32 *)bptr->C2Addr)[1] | ((u32 *)bptr->C2Addr)[2] | ((u32 *)bptr->C2Addr)[3]) { + bptr->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + } + + bptr->errStatus = 0; + __osLeoResume(); + } + info->sectorNum++; + if (stat & LEO_STATUS_DATA_REQUEST) { + if (info->sectorNum > 0x54) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + __osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); + blockInfo->errStatus = LEO_ERROR_GOOD; + return 1; + } else if (info->sectorNum <= 0x54) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + return 1; + } else { + blockInfo->errStatus = LEO_ERROR_4; + __osLeoAbnormalResume(); + return 1; + } +} + +static void __osLeoAbnormalResume(void) { + __OSTranxInfo *info = &__osDiskHandle->transferInfo; + u32 pi_stat; + + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow); + __osLeoResume(); + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; +} + +static void __osLeoResume(void) { + __OSEventState *es = &__osEventStateTab[OS_EVENT_PI]; + OSMesgQueue *mq = es->messageQueue; + s32 last; + + if (mq == NULL || MQ_IS_FULL(mq)) { + return; + } + + last = (mq->first + mq->validCount) % mq->msgCount; + mq->msg[last] = es->message; + mq->validCount++; + + if (mq->mtqueue->next != NULL) { + __osEnqueueThread(&__osRunQueue, __osPopThread(&mq->mtqueue)); + } +} diff --git a/lib/ultralib/src/io/motor.c b/lib/ultralib/src/io/motor.c new file mode 100644 index 0000000..8028d69 --- /dev/null +++ b/lib/ultralib/src/io/motor.c @@ -0,0 +1,332 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/os_version.h" +#include "controller.h" +#include "siint.h" + +#if BUILD_VERSION >= VERSION_J +static OSPifRam __MotorDataBuf[MAXCONTROLLERS] ALIGNED(8); + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +s32 __osMotorAccess(OSPfs* pfs, s32 flag) { + int i; + s32 ret; + u8* ptr = (u8*)&__MotorDataBuf[pfs->channel]; + + if (!(pfs->status & PFS_MOTOR_INITIALIZED)) { + return 5; + } + + __osSiGetAccess(); + __MotorDataBuf[pfs->channel].pifstatus = CONT_CMD_EXE; + ptr += pfs->channel; + + for (i = 0; i < BLOCKSIZE; i++) { + READFORMAT(ptr)->data[i] = flag; + } + + __osContLastCmd = CONT_CMD_END; + __osSiRawStartDma(OS_WRITE, &__MotorDataBuf[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__MotorDataBuf[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + + ret = READFORMAT(ptr)->rxsize & CHNL_ERR_MASK; + if (!ret) { + if (!flag) { + if (READFORMAT(ptr)->datacrc != 0) { + ret = PFS_ERR_CONTRFAIL; + } + } else { + if (READFORMAT(ptr)->datacrc != 0xEB) { + ret = PFS_ERR_CONTRFAIL; + } + } + } + + __osSiRelAccess(); + + return ret; +} + +static void __osMakeMotorData(int channel, OSPifRam* mdata) { + u8* ptr = (u8*)mdata->ramarray; + __OSContRamReadFormat ramreadformat; + int i; + + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; + ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; + ramreadformat.cmd = CONT_CMD_WRITE_PAK; + ramreadformat.addrh = CONT_BLOCK_RUMBLE >> 3; + ramreadformat.addrl = (u8)(__osContAddressCrc(CONT_BLOCK_RUMBLE) | (CONT_BLOCK_RUMBLE << 5)); + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + } + + *READFORMAT(ptr) = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +s32 osMotorInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { + s32 ret; + u8 temp[32]; + + pfs->queue = mq; + pfs->channel = channel; + pfs->activebank = 0xFF; + pfs->status = 0; + + ret = SELECT_BANK(pfs, 0xFE); + + if (ret == PFS_ERR_NEW_PACK) { + ret = SELECT_BANK(pfs, 0x80); + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } else if (temp[31] == 254) { + return PFS_ERR_DEVICE; + } + + ret = SELECT_BANK(pfs, 0x80); + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } else if (temp[31] != 0x80) { + return PFS_ERR_DEVICE; + } + + if (!(pfs->status & PFS_MOTOR_INITIALIZED)) { + __osMakeMotorData(channel, &__MotorDataBuf[channel]); + } + + pfs->status = PFS_MOTOR_INITIALIZED; + return 0; +} + +#else + +OSPifRam _MotorStopData[MAXCONTROLLERS] ALIGNED(8); +OSPifRam _MotorStartData[MAXCONTROLLERS] ALIGNED(8); +u8 _motorstopbuf[32] ALIGNED(8); +u8 _motorstartbuf[32] ALIGNED(8); +u32 __osMotorinitialized[MAXCONTROLLERS] = {0, 0, 0, 0}; + +s32 osMotorStop(OSPfs *pfs) { + int i; + s32 ret; + u8 *ptr; + __OSContRamReadFormat ramreadformat; + + ptr = (u8 *)&__osPfsPifRam; + + if (!__osMotorinitialized[pfs->channel]) { + return PFS_ERR_INVALID; + } + + __osSiGetAccess(); + + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osSiRawStartDma(OS_WRITE, &_MotorStopData[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ptr = (u8 *)&__osPfsPifRam; + + if (pfs->channel != 0) { + for (i = 0; i < pfs->channel; i++) { + ptr++; + } + } + + ramreadformat = *(__OSContRamReadFormat *)ptr; + ret = CHNL_ERR(ramreadformat); + + if (ret == 0 && __osContDataCrc((u8*)&_motorstopbuf) != ramreadformat.datacrc) { + ret = PFS_ERR_CONTRFAIL; + } + + __osSiRelAccess(); + return ret; +} + +s32 osMotorStart(OSPfs *pfs) { + + int i; + s32 ret; + u8 *ptr; + __OSContRamReadFormat ramreadformat; + + ptr = (u8 *)&__osPfsPifRam; + + if (!__osMotorinitialized[pfs->channel]) { + return PFS_ERR_INVALID; + } + + __osSiGetAccess(); + + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osSiRawStartDma(OS_WRITE, &_MotorStartData[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ptr = (u8 *)&__osPfsPifRam; + + if (pfs->channel != 0) { + for (i = 0; i < pfs->channel; i++) { + ptr++; + } + } + + ramreadformat = *(__OSContRamReadFormat *)ptr; + ret = CHNL_ERR(ramreadformat); + + if (ret == 0 && __osContDataCrc((u8*)&_motorstartbuf) != ramreadformat.datacrc) { + ret = PFS_ERR_CONTRFAIL; + } + + __osSiRelAccess(); + return ret; +} + +static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata) +{ + u8 *ptr = (u8 *)mdata->ramarray; + __OSContRamReadFormat ramreadformat; + int i; + + for (i = 0; i < ARRLEN(mdata->ramarray); i++) { + mdata->ramarray[i] = 0; + } + + mdata->pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; + ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; + ramreadformat.cmd = CONT_CMD_WRITE_PAK; + + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = *buffer++; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = 0; + } + } + + *(__OSContRamReadFormat *)ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +s32 osMotorInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { + int i; + s32 ret; + u8 temp[32]; + + pfs->queue = mq; + pfs->channel = channel; + pfs->status = 0; + pfs->activebank = 128; + + for (i = 0; i < ARRLEN(temp); i++) { + temp[i] = 254; + } + + ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + if (temp[31] == 254) { + return PFS_ERR_DEVICE; + } + + for (i = 0; i < ARRLEN(temp); i++) { + temp[i] = 128; + } + + ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + if (temp[31] != 0x80) { + return PFS_ERR_DEVICE; + } + + if (!__osMotorinitialized[channel]) { + for (i = 0; i < ARRLEN(_motorstartbuf); i++) { + _motorstartbuf[i] = 1; + _motorstopbuf[i] = 0; + } + _MakeMotorData(channel, CONT_BLOCK_RUMBLE, _motorstartbuf, &_MotorStartData[channel]); + _MakeMotorData(channel, CONT_BLOCK_RUMBLE, _motorstopbuf, &_MotorStopData[channel]); + __osMotorinitialized[channel] = 1; + } + + return 0; +} + +#endif diff --git a/lib/ultralib/src/io/pfsallocatefile.c b/lib/ultralib/src/io/pfsallocatefile.c new file mode 100644 index 0000000..24f6fe7 --- /dev/null +++ b/lib/ultralib/src/io/pfsallocatefile.c @@ -0,0 +1,371 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "PR/rmon.h" + +#define ROUND_UP_DIVIDE(numerator, denominator) (((numerator) + (denominator)-1) / (denominator)) + +#if BUILD_VERSION >= VERSION_J + +s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, + s32* file_no) { + int start_page; + int decleared; + int last_page; + int old_last_page = 0; + s32 ret = 0; + int file_size_in_pages; + __OSInode inode; + __OSInode backup_inode; + __OSDir dir; + u8 bank; + u8 old_bank = 0; + int firsttime = 0; + s32 bytes; + __OSInodeUnit fpage; + + if (company_code == 0 || game_code == 0) { + return PFS_ERR_INVALID; + } + + file_size_in_pages = ROUND_UP_DIVIDE(file_size_in_bytes, BLOCKSIZE * PFS_ONE_PAGE); + + if (((ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no)) != 0) && + ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no != -1) { + return PFS_ERR_EXIST; + } + + ret = osPfsFreeBlocks(pfs, &bytes); + + if (file_size_in_bytes > bytes) { + return PFS_DATA_FULL; + } + + if (file_size_in_pages == 0) { + return PFS_ERR_INVALID; + } + + if (((ret = osPfsFindFile(pfs, 0, 0, NULL, NULL, file_no)) != 0) && ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no == -1) { + return PFS_DIR_FULL; + } + + for (bank = 0; bank < pfs->banks; bank++) { + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + ERRCK(__osPfsDeclearPage(pfs, &inode, file_size_in_pages, &start_page, bank, &decleared, &last_page)); + + if (start_page != -1) { + if (firsttime == 0) { + fpage.inode_t.page = start_page; + fpage.inode_t.bank = bank; + } else { + backup_inode.inode_page[old_last_page].inode_t.bank = bank; + backup_inode.inode_page[old_last_page].inode_t.page = start_page; + ERRCK(__osPfsRWInode(pfs, &backup_inode, PFS_WRITE, old_bank)); + } + + if (file_size_in_pages > decleared) { + bcopy(&inode, &backup_inode, sizeof(__OSInode)); + old_last_page = last_page; + old_bank = bank; + file_size_in_pages -= decleared; + firsttime++; + } else { + file_size_in_pages = 0; + ERRCK(__osPfsRWInode(pfs, &inode, PFS_WRITE, bank)); + break; + } + } + } + + if (file_size_in_pages > 0 || start_page == -1) { + return PFS_ERR_INCONSISTENT; + } + + dir.start_page = fpage; + dir.company_code = company_code; + dir.game_code = game_code; + dir.data_sum = 0; + + bcopy(game_name, dir.game_name, PFS_FILE_NAME_LEN); + bcopy(ext_name, dir.ext_name, PFS_FILE_EXT_LEN); + + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *file_no, (u8*)&dir, FALSE); + return ret; +} + +s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, int file_size_in_pages, int* first_page, u8 bank, int* decleared, + int* last_page) { + int j; + int spage; + int old_page; + s32 ret = 0; + int offset = bank > 0 ? 1 : pfs->inode_start_page; + + for (j = offset; j < ARRLEN(inode->inode_page); j++) { + if (inode->inode_page[j].ipage == 3) { + break; + } + } + + if (j == ARRLEN(inode->inode_page)) { + *first_page = -1; + return ret; + } + + spage = j; + *decleared = 1; + old_page = j; + j++; + + while (file_size_in_pages > *decleared && j < ARRLEN(inode->inode_page)) { + if (inode->inode_page[j].ipage == 3) { + inode->inode_page[old_page].inode_t.bank = bank; + inode->inode_page[old_page].inode_t.page = j; + old_page = j; + (*decleared)++; + } + j++; + } + + *first_page = spage; + + if (j == ARRLEN(inode->inode_page) && file_size_in_pages > *decleared) { + *last_page = old_page; + } else { + inode->inode_page[old_page].ipage = 1; + *last_page = 0; + } + + return ret; +} + +#else + +static s32 __osClearPage(OSPfs *pfs, int page_num, u8 *data, u8 bank); + +s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, + s32* file_no) { + int start_page; + int decleared; + int last_page; + int old_last_page = 0; + int j; + s32 ret = 0; + int file_size_in_pages; + __OSInode inode; + __OSInode backup_inode; + __OSDir dir; + u8 bank; + u8 old_bank = 0; + int firsttime = 0; + s32 bytes; + __OSInodeUnit fpage; + + if (company_code == 0 || game_code == 0) { + return PFS_ERR_INVALID; + } + + file_size_in_pages = ROUND_UP_DIVIDE(file_size_in_bytes, BLOCKSIZE * PFS_ONE_PAGE); + + if ((pfs->status & PFS_INITIALIZED) == FALSE) { + return PFS_ERR_INVALID; + } + + PFS_CHECK_ID(); + + if (((ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no)) != 0) && + ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no != -1) { + return PFS_ERR_EXIST; + } + + ret = osPfsFreeBlocks(pfs, &bytes); + + if (file_size_in_bytes > bytes) { + return PFS_DATA_FULL; + } + + if (file_size_in_pages != 0) { + + if (((ret = osPfsFindFile(pfs, 0, 0, NULL, NULL, file_no)) != 0) && ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no == -1) { + return PFS_DIR_FULL; + } + + for (bank = 0; bank < pfs->banks; bank++) { + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + ERRCK(__osPfsDeclearPage(pfs, &inode, file_size_in_pages, &start_page, bank, &decleared, &last_page)); + + if (start_page != -1) { + if (firsttime == 0) { + fpage.inode_t.page = start_page; + fpage.inode_t.bank = bank; + } else { + backup_inode.inode_page[old_last_page].inode_t.bank = bank; + backup_inode.inode_page[old_last_page].inode_t.page = start_page; + ERRCK(__osPfsRWInode(pfs, &backup_inode, PFS_WRITE, old_bank)); + } + + for (j = 0; j < ARRLEN(inode.inode_page); j++) { + backup_inode.inode_page[j].ipage = inode.inode_page[j].ipage; + } + old_last_page = last_page; + old_bank = bank; + firsttime++; + if (file_size_in_pages > decleared) { + file_size_in_pages = file_size_in_pages - decleared; + } else { + file_size_in_pages = 0; + break; + } + } + } + + if (file_size_in_pages > 0 || start_page == -1) { + return PFS_ERR_INCONSISTENT; + } + + backup_inode.inode_page[old_last_page].inode_t.bank = bank; + backup_inode.inode_page[old_last_page].inode_t.page = start_page; + ERRCK(__osPfsRWInode(pfs, &backup_inode, OS_WRITE, old_bank)); + + dir.start_page = fpage; + dir.company_code = company_code; + dir.game_code = game_code; + dir.data_sum = 0; + + for (j = 0; j < ARRLEN(dir.game_name); j++) + dir.game_name[j] = *game_name++; + for (j = 0; j < ARRLEN(dir.ext_name); j++) + dir.ext_name[j] = *ext_name++; + + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *file_no, (u8*)&dir, FALSE)); + return ret; + } else { + return PFS_ERR_INVALID; + } +} + +s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, int file_size_in_pages, int* first_page, u8 bank, int* decleared, + int* last_page) { + int j; + int spage; + int old_page; + u8 tmp_data[BLOCKSIZE]; + int i; + s32 ret = 0; + int offset = bank > 0 ? 1 : pfs->inode_start_page; + + for (j = offset; j < ARRLEN(inode->inode_page); j++) { + if (inode->inode_page[j].ipage == 3) { + break; + } + } + + if (j == ARRLEN(inode->inode_page)) { + *first_page = -1; + return ret; + } + + for (i = 0; i < ARRLEN(tmp_data); i++) { + tmp_data[i] = 0; + } + + spage = j; + *decleared = 1; + old_page = j; + j++; + + while (file_size_in_pages > *decleared && j < ARRLEN(inode->inode_page)) { + if (inode->inode_page[j].ipage == 3) { + inode->inode_page[old_page].inode_t.bank = bank; + inode->inode_page[old_page].inode_t.page = j; + ERRCK(__osClearPage(pfs, old_page, (u8*)tmp_data, bank)); + old_page = j; + (*decleared)++; + } + j++; + } + + *first_page = spage; + + if (j == ARRLEN(inode->inode_page) && file_size_in_pages > *decleared) { + *last_page = old_page; + return ret; + } else { + inode->inode_page[old_page].ipage = 1; + ret = __osClearPage(pfs, old_page, (u8*)tmp_data, bank); + *last_page = 0; + return ret; + } +} + +static s32 __osClearPage(OSPfs *pfs, int page_no, u8 *data, u8 bank) +{ + int i; + s32 ret; + ret = 0; + pfs->activebank = bank; + ERRCK(__osPfsSelectBank(pfs)); + for (i = 0; i < PFS_ONE_PAGE; i++) { + ret = __osContRamWrite(pfs->queue, pfs->channel, page_no * PFS_ONE_PAGE + i, data, FALSE); + if (ret != 0) { + break; + } + } + pfs->activebank = 0; + ret = __osPfsSelectBank(pfs); + return ret; +} + +#endif + +#ifdef _DEBUG +s32 __osDumpInode(OSPfs* pfs) { + int j; + __OSInode inode; + s32 ret = 0; + __OSDir dir; + u8 bank; +#if BUILD_VERSION >= VERSION_J + u8 startbank = PFS_ID_BANK_256K; +#endif + + rmonPrintf("INODE:\n"); + +#if BUILD_VERSION >= VERSION_J + for (bank = startbank; bank < pfs->banks; bank++) { +#else + for (bank = 0; bank < pfs->banks; bank++) { +#endif + rmonPrintf("\nBank %d:\n", bank); + ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank); + for (j = 0; j < PFS_INODE_SIZE_PER_PAGE; j++) { + rmonPrintf("%x ", inode.inode_page[j].ipage); + } + } + + rmonPrintf("dir_size %d %d\n", pfs->dir_size, pfs->inode_start_page); + + for (j = 0; j < pfs->dir_size; j++) { + __osContRamRead(pfs->queue, pfs->channel, (u16)(pfs->dir_table + (int)j), (u8*)&dir); + rmonPrintf("file %d game_code %d page %x c_code %d sum %d\n", j, dir.game_code, dir.start_page.ipage, + dir.company_code, dir.data_sum); + } + rmonPrintf("End of Dump\n"); + return ret; +} +#endif diff --git a/lib/ultralib/src/io/pfschecker.c b/lib/ultralib/src/io/pfschecker.c new file mode 100644 index 0000000..b736200 --- /dev/null +++ b/lib/ultralib/src/io/pfschecker.c @@ -0,0 +1,258 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache); +s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache); + +#define CHECK_IPAGE(p) \ + (((p).ipage >= pfs->inode_start_page) && ((p).inode_t.bank < pfs->banks) && ((p).inode_t.page >= 0x01) && \ + ((p).inode_t.page < 0x80)) + +s32 osPfsChecker(OSPfs* pfs) { + int j; + s32 ret; + __OSInodeUnit next_page; + __OSInode checked_inode; + __OSInode tmp_inode; + __OSDir tmp_dir; + __OSInodeUnit file_next_node[16]; + __OSInodeCache cache; + int fixed = 0; + u8 bank; +#if BUILD_VERSION >= VERSION_J + u8 oldbank = 254; +#endif + s32 cc; + s32 cl; + int offset; + + ret = __osCheckId(pfs); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osGetId(pfs); + } + + if (ret != 0) { + return ret; + } + + ERRCK(corrupted_init(pfs, &cache)); + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); + +#if BUILD_VERSION >= VERSION_J + if (tmp_dir.company_code != 0 || tmp_dir.game_code != 0) { + if (tmp_dir.company_code == 0 || tmp_dir.game_code == 0) { + cc = -1; + } else { + next_page = tmp_dir.start_page; + cl = cc = 0; + bank = 255; + + while (CHECK_IPAGE(next_page)) { + if (bank != next_page.inode_t.bank) { + bank = next_page.inode_t.bank; + + if (oldbank != bank) { + ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); + oldbank = bank; + } + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + } + + if ((cc = corrupted(pfs, next_page, &cache) - cl) != 0) { + break; + } + + cl = 1; + next_page = tmp_inode.inode_page[next_page.inode_t.page]; + } + } + + if (cc != 0 || next_page.ipage != PFS_EOF) { + bzero(&tmp_dir, sizeof(__OSDir)); + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); + fixed++; + } + } +#else + if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0) { + next_page = tmp_dir.start_page; + cl = cc = 0; + bank = 255; + + while (CHECK_IPAGE(next_page)) { + if (bank != next_page.inode_t.bank) { + bank = next_page.inode_t.bank; + ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + } + + if ((cc = corrupted(pfs, next_page, &cache) - cl) != 0) { + break; + } + + cl = 1; + next_page = tmp_inode.inode_page[next_page.inode_t.page]; + } + + if (cc != 0 || next_page.ipage != PFS_EOF) { + tmp_dir.company_code = 0; + tmp_dir.game_code = 0; + tmp_dir.start_page.ipage = 0; + tmp_dir.status = DIR_STATUS_EMPTY; + tmp_dir.data_sum = 0; + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); + fixed++; + } + } else { + if (tmp_dir.company_code != 0 || tmp_dir.game_code != 0) { + tmp_dir.company_code = 0; + tmp_dir.game_code = 0; + tmp_dir.start_page.ipage = 0; + tmp_dir.status = DIR_STATUS_EMPTY; + tmp_dir.data_sum = 0; + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); + fixed++; + } + } +#endif + } + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); + + if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0 && + tmp_dir.start_page.ipage >= (u16)pfs->inode_start_page) { + file_next_node[j].ipage = tmp_dir.start_page.ipage; + } else { + file_next_node[j].ipage = 0; + } + } + + for (bank = 0; bank < pfs->banks; bank++) { + ret = __osPfsRWInode(pfs, &tmp_inode, 0, bank); + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + + offset = (bank > 0) ? 1 : pfs->inode_start_page; + + for (j = 0; j < offset; j++) { + checked_inode.inode_page[j].ipage = tmp_inode.inode_page[j].ipage; + } + + for (; j < 128; j++) { + checked_inode.inode_page[j].ipage = PFS_PAGE_NOT_USED; + } + + for (j = 0; j < pfs->dir_size; j++) { + while (file_next_node[j].inode_t.bank == bank && file_next_node[j].ipage >= (u16)pfs->inode_start_page) { + u8 pp = file_next_node[j].inode_t.page; + file_next_node[j] = checked_inode.inode_page[pp] = tmp_inode.inode_page[pp]; + } + } + ERRCK(__osPfsRWInode(pfs, &checked_inode, OS_WRITE, bank)); + } + + if (fixed) { + pfs->status |= PFS_CORRUPTED; + } else { + pfs->status &= ~PFS_CORRUPTED; + } + + return 0; +} + +s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache) { + int i; + int n; + int offset; + u8 bank; + __OSInodeUnit tpage; + __OSInode tmp_inode; + s32 ret; + + for (i = 0; i < PFS_INODE_DIST_MAP; i++) { + cache->map[i] = 0; + } + + cache->bank = -1; + for (bank = 0; bank < pfs->banks; bank++) { + offset = bank > 0 ? 1 : pfs->inode_start_page; + + ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + + for (i = offset; i < ARRLEN(tmp_inode.inode_page); i++) { + tpage = tmp_inode.inode_page[i]; + + if (tpage.ipage >= pfs->inode_start_page && tpage.inode_t.bank != bank) { +#if BUILD_VERSION >= VERSION_J + n = ((tpage.inode_t.page & 0x7F) / PFS_SECTOR_SIZE) + + ((tpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE); +#else + n = ((tpage.inode_t.page) / PFS_SECTOR_SIZE) + + ((tpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE); +#endif + cache->map[n] |= 1 << (bank % PFS_BANK_LAPPED_BY); + } + } + } + return 0; +} + +s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache) { + int j; + int n; + int hit; + u8 bank; + int offset; + s32 ret; + + hit = 0; + ret = 0; + n = (fpage.inode_t.page / PFS_SECTOR_SIZE) + (fpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE; + + for (bank = 0; bank < pfs->banks; bank++) { + offset = bank > 0 ? 1 : pfs->inode_start_page; + + if (bank == fpage.inode_t.bank || cache->map[n] & (1 << (bank % PFS_BANK_LAPPED_BY))) { + if (bank != cache->bank) { + ret = __osPfsRWInode(pfs, &cache->inode, 0, bank); + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + + cache->bank = bank; + } + + for (j = offset; hit < 2 && (j < ARRLEN(cache->inode.inode_page)); j++) { + if (cache->inode.inode_page[j].ipage == fpage.ipage) { + hit++; + } + } + + if (hit >= 2) { + return PFS_ERR_NEW_PACK; + } + } + } + return hit; +} diff --git a/lib/ultralib/src/io/pfsdeletefile.c b/lib/ultralib/src/io/pfsdeletefile.c new file mode 100644 index 0000000..e013211 --- /dev/null +++ b/lib/ultralib/src/io/pfsdeletefile.c @@ -0,0 +1,180 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osPfsDeleteFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name) { + s32 file_no; +#if BUILD_VERSION < VERSION_J + int k; +#endif + s32 ret; + __OSInode inode; + __OSDir dir; +#if BUILD_VERSION < VERSION_J + u16 sum = 0; +#endif + __OSInodeUnit last_page; + u8 startpage; + u8 bank; + + if (company_code == 0 || game_code == 0) { + return PFS_ERR_INVALID; + } + +#if BUILD_VERSION >= VERSION_J + ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no)); + SET_ACTIVEBANK_TO_ZERO(); +#else + PFS_CHECK_STATUS(); + PFS_CHECK_ID(); + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no)); + + if (file_no == -1) { + return PFS_ERR_INVALID; + } +#endif + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); + + startpage = dir.start_page.inode_t.page; + + for (bank = dir.start_page.inode_t.bank; bank < pfs->banks;) { + ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osPfsReleasePages(pfs, &inode, startpage, bank, &last_page)); +#else + ERRCK(__osPfsReleasePages(pfs, &inode, startpage, &sum, bank, &last_page, TRUE)); +#endif + ERRCK(__osPfsRWInode(pfs, &inode, OS_WRITE, bank)); + + if (last_page.ipage == PFS_EOF) { + break; + } + + bank = last_page.inode_t.bank; + startpage = last_page.inode_t.page; + } + + if (bank >= pfs->banks) { + return PFS_ERR_INCONSISTENT; + } + +#if BUILD_VERSION >= VERSION_J + bzero(&dir, sizeof(__OSDir)); +#else + dir.game_code = 0; + dir.company_code = 0; + dir.start_page.ipage = 0; + dir.data_sum = 0; + for (k = 0; k < ARRLEN(dir.game_name); k++) + { + dir.game_name[k] = 0; + } + for (k = 0; k < ARRLEN(dir.ext_name); k++) + { + dir.ext_name[k] = 0; + } + dir.status = DIR_STATUS_EMPTY; +#endif + + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir, FALSE); + + return ret; +} + +#if BUILD_VERSION >= VERSION_J + +s32 __osPfsReleasePages(OSPfs* pfs, __OSInode* inode, u8 start_page, u8 bank, __OSInodeUnit* last_page) { + __OSInodeUnit next_page; + __OSInodeUnit old_page; + s32 ret = 0; + + next_page.ipage = (bank << 8) + start_page; + + do { + old_page = next_page; + next_page = inode->inode_page[next_page.inode_t.page]; + inode->inode_page[old_page.inode_t.page].ipage = PFS_PAGE_NOT_USED; + } while (next_page.ipage >= pfs->inode_start_page && next_page.inode_t.bank == bank); + + *last_page = next_page; + + return ret; +} + +#else + +s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag) +{ + __OSInodeUnit next_page; + __OSInodeUnit old_page; + s32 ret; + int offset; + ret = 0; + next_page = inode->inode_page[start_page]; + + if (next_page.ipage != 1) { + offset = (next_page.inode_t.bank > 0) ? 1 : pfs->inode_start_page; + } else { + offset = (bank > 0) ? 1 : pfs->inode_start_page; + } + + if (next_page.inode_t.page < offset && next_page.ipage != 1) { + return PFS_ERR_INCONSISTENT; + } + + *last_page = next_page; + + if (flag == TRUE) { + inode->inode_page[start_page].ipage = 3; + } + + ERRCK(__osBlockSum(pfs, start_page, sum, bank)); + + if (next_page.ipage == 1) { + return 0; + } + + while (next_page.ipage >= pfs->inode_start_page) { + old_page = next_page; + next_page = inode->inode_page[next_page.inode_t.page]; + inode->inode_page[old_page.inode_t.page].ipage = 3; + + ERRCK(__osBlockSum(pfs, old_page.inode_t.page, sum, bank)); + + if (next_page.inode_t.bank != bank) { + break; + } + } + + if (next_page.ipage >= pfs->inode_start_page && next_page.inode_t.bank == bank) { + inode->inode_page[next_page.inode_t.page].ipage = 3; + } + + *last_page = next_page; + return 0; +} +s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank) +{ + int i; + s32 ret; + u8 data[32]; + ret = 0; + pfs->activebank = bank; + ERRCK(__osPfsSelectBank(pfs)); + for (i = 0; i < PFS_ONE_PAGE; i++) + { + ret = __osContRamRead(pfs->queue, pfs->channel, page_no * PFS_ONE_PAGE + i, data); + if (ret != 0) + { + pfs->activebank = 0; + __osPfsSelectBank(pfs); + return ret; + } + *sum = *sum + __osSumcalc(data, sizeof(data)); + } + pfs->activebank = 0; + ret = __osPfsSelectBank(pfs); + return ret; +} + +#endif diff --git a/lib/ultralib/src/io/pfsfilestate.c b/lib/ultralib/src/io/pfsfilestate.c new file mode 100644 index 0000000..4f80020 --- /dev/null +++ b/lib/ultralib/src/io/pfsfilestate.c @@ -0,0 +1,112 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osPfsFileState(OSPfs* pfs, s32 file_no, OSPfsState* state) { + s32 ret; + int pages; + __OSInode inode; + __OSDir dir; + __OSInodeUnit next_page; +#if BUILD_VERSION < VERSION_J + int j; +#endif + u8 bank; +#if BUILD_VERSION < VERSION_J + u8 start_page; +#endif + + if (file_no >= pfs->dir_size || file_no < 0) { + return PFS_ERR_INVALID; + } + + PFS_CHECK_STATUS(); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + SET_ACTIVEBANK_TO_ZERO(); + + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); + + if (dir.company_code == 0 || dir.game_code == 0) { + return PFS_ERR_INVALID; + } + +#if BUILD_VERSION >= VERSION_J + pages = 0; + next_page = dir.start_page; + bank = 0xFF; + + while (TRUE) { + if (next_page.ipage < pfs->inode_start_page) { + break; + } else if (next_page.inode_t.bank != bank) { + bank = next_page.inode_t.bank; + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + } + + pages++; + next_page = inode.inode_page[next_page.inode_t.page]; + } + + if (next_page.ipage != PFS_EOF) { + return PFS_ERR_INCONSISTENT; + } + + state->file_size = pages * (PFS_ONE_PAGE * BLOCKSIZE); + state->company_code = dir.company_code; + state->game_code = dir.game_code; + bcopy(&dir.game_name, state->game_name, PFS_FILE_NAME_LEN); + bcopy(&dir.ext_name, state->ext_name, PFS_FILE_EXT_LEN); + + ret = __osPfsGetStatus(pfs->queue, pfs->channel); + return ret; +#else + if (dir.start_page.ipage < pfs->inode_start_page) { + return PFS_ERR_INCONSISTENT; + } + + pages = 0; + start_page = dir.start_page.inode_t.page; + bank = dir.start_page.inode_t.bank; + + while (bank < pfs->banks) { + ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); + next_page = inode.inode_page[start_page]; + pages++; + + while (next_page.ipage >= pfs->inode_start_page) { + pages++; + next_page = inode.inode_page[next_page.inode_t.page]; + if (next_page.inode_t.bank != bank) { + bank = next_page.inode_t.bank; + start_page = next_page.inode_t.page; + break; + } + } + + if (next_page.ipage == PFS_EOF) { + break; + } + } + + if (next_page.ipage != PFS_EOF) { + return PFS_ERR_INCONSISTENT; + } + + state->file_size = pages * (PFS_ONE_PAGE * BLOCKSIZE); + state->company_code = dir.company_code; + state->game_code = dir.game_code; + + for (j = 0; j < ARRLEN(state->game_name); j++) { + state->game_name[j] = dir.game_name[j]; + } + + for (j = 0; j < ARRLEN(state->ext_name); j++) { + state->ext_name[j] = dir.ext_name[j]; + } + + return 0; +#endif +} diff --git a/lib/ultralib/src/io/pfsfreeblocks.c b/lib/ultralib/src/io/pfsfreeblocks.c new file mode 100644 index 0000000..68a54c6 --- /dev/null +++ b/lib/ultralib/src/io/pfsfreeblocks.c @@ -0,0 +1,31 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osPfsFreeBlocks(OSPfs* pfs, s32* bytes_not_used) { + int j; + int pages = 0; + __OSInode inode; + s32 ret = 0; + u8 bank; + int offset; + + PFS_CHECK_STATUS(); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + for (bank = 0; bank < pfs->banks; bank++) { + ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); + offset = ((bank > 0) ? 1 : pfs->inode_start_page); + + for (j = offset; j < ARRLEN(inode.inode_page); j++) { + if (inode.inode_page[j].ipage == PFS_PAGE_NOT_USED) { + pages++; + } + } + } + + *bytes_not_used = pages * PFS_ONE_PAGE * BLOCKSIZE; + return 0; +} diff --git a/lib/ultralib/src/io/pfsgetlabel.c b/lib/ultralib/src/io/pfsgetlabel.c new file mode 100644 index 0000000..0e4de49 --- /dev/null +++ b/lib/ultralib/src/io/pfsgetlabel.c @@ -0,0 +1,25 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osPfsGetLabel(OSPfs* pfs, u8* label, int* len) { + int i; + + if (label == NULL) { + return PFS_ERR_INVALID; + } + + if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) { + return PFS_ERR_NEW_PACK; + } + + for (i = 0; i < ARRLEN(pfs->label); i++) { + if (*(u8*)(u32)(i + pfs->label) == 0) { + break; + } + + *label++ = *(u8*)(u32)(i + pfs->label); + } + + *len = i; + return 0; +} diff --git a/lib/ultralib/src/io/pfsgetstatus.c b/lib/ultralib/src/io/pfsgetstatus.c new file mode 100644 index 0000000..955412b --- /dev/null +++ b/lib/ultralib/src/io/pfsgetstatus.c @@ -0,0 +1,100 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +#if BUILD_VERSION >= VERSION_J +void __osPfsRequestOneChannel(int channel, u8 cmd); +#else +void __osPfsRequestOneChannel(int channel); +#endif +void __osPfsGetOneChannelData(int channel, OSContStatus* data); + +s32 __osPfsGetStatus(OSMesgQueue* queue, int channel) { + s32 ret = 0; + OSMesg dummy; + OSContStatus data; + +#if BUILD_VERSION >= VERSION_J + __osPfsInodeCacheBank = 250; + + __osPfsRequestOneChannel(channel, CONT_CMD_REQUEST_STATUS); +#else + __osPfsRequestOneChannel(channel); +#endif + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(queue, &dummy, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(queue, &dummy, OS_MESG_BLOCK); + + __osPfsGetOneChannelData(channel, &data); + + if (((data.status & CONT_CARD_ON) != 0) && ((data.status & CONT_CARD_PULL) != 0)) { + return PFS_ERR_NEW_PACK; + } else if ((data.errno != 0) || ((data.status & CONT_CARD_ON) == 0)) { + return PFS_ERR_NOPACK; + } else if ((data.status & CONT_ADDR_CRC_ER) != 0) { + return PFS_ERR_CONTRFAIL; + } + + return ret; +} + +#if BUILD_VERSION >= VERSION_J +void __osPfsRequestOneChannel(int channel, u8 cmd) { +#else +void __osPfsRequestOneChannel(int channel) { +#endif + u8* ptr; + __OSContRequesFormatShort requestformat; + int i; + +#if BUILD_VERSION >= VERSION_J + __osContLastCmd = CONT_CMD_END; +#else + __osContLastCmd = CONT_CMD_REQUEST_STATUS; +#endif + __osPfsPifRam.pifstatus = CONT_CMD_READ_BUTTON; + + ptr = (u8*)&__osPfsPifRam; + + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; +#if BUILD_VERSION >= VERSION_J + requestformat.cmd = cmd; +#else + requestformat.cmd = CONT_CMD_REQUEST_STATUS; +#endif + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + + *(__OSContRequesFormatShort*)ptr = requestformat; + ptr += sizeof(__OSContRequesFormatShort); + *ptr = CONT_CMD_END; +} + +void __osPfsGetOneChannelData(int channel, OSContStatus* data) { + u8* ptr = (u8*)&__osPfsPifRam; + __OSContRequesFormatShort requestformat; + int i; + + for (i = 0; i < channel; i++) { + ptr++; + } + + requestformat = *(__OSContRequesFormatShort*)ptr; + data->errno = CHNL_ERR(requestformat); + + if (data->errno != 0) { + return; + } + + data->type = (requestformat.typel << 8) | (requestformat.typeh); + data->status = requestformat.status; +} diff --git a/lib/ultralib/src/io/pfsinit.c b/lib/ultralib/src/io/pfsinit.c new file mode 100644 index 0000000..5633c78 --- /dev/null +++ b/lib/ultralib/src/io/pfsinit.c @@ -0,0 +1,25 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +s32 osPfsInit(OSMesgQueue* queue, OSPfs* pfs, int channel) { + s32 ret = 0; + + __osSiGetAccess(); + ret = __osPfsGetStatus(queue, channel); + __osSiRelAccess(); + + if (ret != 0) { + return ret; + } + + pfs->queue = queue; + pfs->channel = channel; + pfs->status = 0; + pfs->activebank = -1; + ERRCK(__osGetId(pfs)); + + ret = osPfsChecker(pfs); + pfs->status |= PFS_INITIALIZED; + return ret; +} diff --git a/lib/ultralib/src/io/pfsinitpak.c b/lib/ultralib/src/io/pfsinitpak.c new file mode 100644 index 0000000..d3fde1f --- /dev/null +++ b/lib/ultralib/src/io/pfsinitpak.c @@ -0,0 +1,129 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +#if BUILD_VERSION >= VERSION_J +static s32 __osPfsCheckRamArea(OSPfs* pfs); +#endif + +s32 osPfsInitPak(OSMesgQueue* queue, OSPfs* pfs, int channel) { +#if BUILD_VERSION < VERSION_J + int k; +#endif + s32 ret = 0; + u16 sum; + u16 isum; + u8 temp[BLOCKSIZE]; + __OSPackId* id; + __OSPackId newid; + + __osSiGetAccess(); + + ret = __osPfsGetStatus(queue, channel); + + __osSiRelAccess(); + + if (ret != 0) { + return ret; + } + + pfs->queue = queue; + pfs->channel = channel; + pfs->status = 0; + +#if BUILD_VERSION >= VERSION_J + ERRCK(__osPfsCheckRamArea(pfs)); +#endif + ERRCK(SELECT_BANK(pfs, 0)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)); + + __osIdCheckSum((u16*)temp, &sum, &isum); + id = (__OSPackId*)temp; + + if ((id->checksum != sum) || (id->inverted_checksum != isum)) { + ret = __osCheckPackId(pfs, id); + + if (ret != 0) { +#if BUILD_VERSION >= VERSION_J + pfs->status |= PFS_ID_BROKEN; +#endif + return ret; + } + +#if BUILD_VERSION < VERSION_J + // Duplicated check + else if (ret != 0) { + return ret; + } +#endif + } + + if (!(id->deviceid & 1)) { + ret = __osRepairPackId(pfs, id, &newid); + + if (ret != 0) { +#if BUILD_VERSION >= VERSION_J + if (ret == PFS_ERR_ID_FATAL) { + pfs->status |= PFS_ID_BROKEN; + } +#endif + return ret; + } + + id = &newid; + + if (!(id->deviceid & 1)) { + return PFS_ERR_DEVICE; + } + } + +#if BUILD_VERSION >= VERSION_J + bcopy(id, pfs->id, BLOCKSIZE); +#else + for (k = 0; k < ARRLEN(pfs->id); k++) { + pfs->id[k] = ((u8 *)id)[k]; + } +#endif + + pfs->version = id->version; + pfs->banks = id->banks; + pfs->inode_start_page = 1 + DEF_DIR_PAGES + (2 * pfs->banks); + pfs->dir_size = DEF_DIR_PAGES * PFS_ONE_PAGE; + pfs->inode_table = 1 * PFS_ONE_PAGE; + pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; + pfs->dir_table = pfs->minode_table + (pfs->banks * PFS_ONE_PAGE); + + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label)); + + ret = osPfsChecker(pfs); + pfs->status |= PFS_INITIALIZED; + + return ret; +} + +#if BUILD_VERSION >= VERSION_J +static s32 __osPfsCheckRamArea(OSPfs* pfs) { + s32 i; + s32 ret = 0; + u8 temp1[BLOCKSIZE]; + u8 temp2[BLOCKSIZE]; + u8 save[BLOCKSIZE]; + + ERRCK(SELECT_BANK(pfs, PFS_ID_BANK_256K)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, save)); + + for (i = 0; i < BLOCKSIZE; i++) { + temp1[i] = i; + } + + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, 0, temp1, FALSE)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, temp2)); + + if (bcmp(temp1, temp2, BLOCKSIZE) != 0) { + return PFS_ERR_DEVICE; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, 0, save, FALSE); + return ret; +} +#endif diff --git a/lib/ultralib/src/io/pfsisplug.c b/lib/ultralib/src/io/pfsisplug.c new file mode 100644 index 0000000..9607907 --- /dev/null +++ b/lib/ultralib/src/io/pfsisplug.c @@ -0,0 +1,97 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +OSPifRam __osPfsPifRam ALIGNED(16); + +s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { + s32 ret = 0; + OSMesg msg; + u8 bitpattern; + OSContStatus contData[MAXCONTROLLERS]; + s32 channel; + u8 bits = 0; + s32 crcErrorCount = 3; + + __osSiGetAccess(); + + do { + __osPfsRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + __osPfsGetInitData(&bitpattern, &contData[0]); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].status & CONT_ADDR_CRC_ER) == 0) { + crcErrorCount--; + break; + } + } + + if (channel == __osMaxControllers) { + crcErrorCount = 0; + } + } while (crcErrorCount > 0); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].errno == 0) && ((contData[channel].status & CONT_CARD_ON) != 0)) { + bits |= (1 << channel); + } + } + __osSiRelAccess(); + *pattern = bits; + return ret; +} + +void __osPfsRequestData(u8 cmd) { + u8* ptr = (u8*)&__osPfsPifRam; + __OSContRequesFormat requestformat; + int i; + + __osContLastCmd = cmd; + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + requestformat.dummy = CONT_CMD_NOP; + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = cmd; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + requestformat.dummy1 = CONT_CMD_NOP; + + for (i = 0; i < __osMaxControllers; i++) { + *((__OSContRequesFormat*)ptr) = requestformat; + ptr += sizeof(__OSContRequesFormat); + } + + *ptr = CONT_CMD_END; +} + +void __osPfsGetInitData(u8* pattern, OSContStatus* data) { + u8* ptr; + __OSContRequesFormat requestformat; + int i; + u8 bits = 0; + + ptr = (u8*)&__osPfsPifRam; + + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestformat), data++) { + requestformat = *((__OSContRequesFormat*)ptr); + data->errno = CHNL_ERR(requestformat); + + if (data->errno != 0) { + continue; + } + + data->type = ((requestformat.typel << 8) | requestformat.typeh); + data->status = requestformat.status; + bits |= (1 << i); + } + *pattern = bits; +} diff --git a/lib/ultralib/src/io/pfsnumfiles.c b/lib/ultralib/src/io/pfsnumfiles.c new file mode 100644 index 0000000..7fa352e --- /dev/null +++ b/lib/ultralib/src/io/pfsnumfiles.c @@ -0,0 +1,34 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osPfsNumFiles(OSPfs* pfs, s32* max_files, s32* files_used) { + int j; + s32 ret; + __OSDir dir; + int files = 0; + + PFS_CHECK_STATUS(); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + SET_ACTIVEBANK_TO_ZERO(); + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); + + if (dir.company_code != 0 && dir.game_code != 0) { + files++; + } + } + *files_used = files; + *max_files = pfs->dir_size; + +#if BUILD_VERSION >= VERSION_J + ret = __osPfsGetStatus(pfs->queue, pfs->channel); + return ret; +#else + return 0; +#endif +} diff --git a/lib/ultralib/src/io/pfsreadwritefile.c b/lib/ultralib/src/io/pfsreadwritefile.c new file mode 100644 index 0000000..17afe54 --- /dev/null +++ b/lib/ultralib/src/io/pfsreadwritefile.c @@ -0,0 +1,124 @@ +#include "PR/os_internal.h" +#include "controller.h" + +static s32 __osPfsGetNextPage(OSPfs* pfs, u8* bank, __OSInode* inode, __OSInodeUnit* page) { + s32 ret; + + if (page->inode_t.bank != *bank) { + *bank = page->inode_t.bank; + ERRCK(__osPfsRWInode(pfs, inode, 0, *bank)); + } + + *page = inode->inode_page[page->inode_t.page]; + + if (page->ipage < pfs->inode_start_page || page->inode_t.bank >= pfs->banks || page->inode_t.page <= 0 || + page->inode_t.page >= ARRLEN(inode->inode_page)) { + + if (page->ipage == 1) { + return PFS_ERR_INVALID; + } + + return PFS_ERR_INCONSISTENT; + } + return 0; +} +s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8* data_buffer) { + s32 ret; + __OSDir dir; + __OSInode inode; + __OSInodeUnit cur_page; + int cur_block; + int siz_block; + u8* buffer; + u8 bank; + u16 blockno; + + if ((file_no >= (s32)pfs->dir_size) || (file_no < 0)) { + return PFS_ERR_INVALID; + } + + if ((size_in_bytes <= 0) || ((size_in_bytes % BLOCKSIZE) != 0)) { + return PFS_ERR_INVALID; + } + + if ((offset < 0) || ((offset % BLOCKSIZE) != 0)) { + return PFS_ERR_INVALID; + } + + PFS_CHECK_STATUS(); + PFS_CHECK_ID(); + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); + + if (dir.company_code == 0 || dir.game_code == 0) { + return PFS_ERR_INVALID; + } + + if (dir.start_page.ipage < pfs->inode_start_page || dir.start_page.inode_t.bank >= pfs->banks || + dir.start_page.inode_t.page <= 0 || dir.start_page.inode_t.page >= ARRLEN(inode.inode_page)) { + if ((dir.start_page.ipage == 1)) { + return PFS_ERR_INVALID; + } + + return PFS_ERR_INCONSISTENT; + } + + if (flag == PFS_READ && (dir.status & DIR_STATUS_OCCUPIED) == 0) { + return PFS_ERR_BAD_DATA; + } + + bank = -1; + cur_block = offset / BLOCKSIZE; + cur_page = dir.start_page; + + while (cur_block >= PFS_ONE_PAGE) { + ERRCK(__osPfsGetNextPage(pfs, &bank, &inode, &cur_page)); + cur_block -= PFS_ONE_PAGE; + } + + siz_block = size_in_bytes / BLOCKSIZE; + buffer = data_buffer; + + while (siz_block > 0) { + if (cur_block == PFS_ONE_PAGE) { + ERRCK(__osPfsGetNextPage(pfs, &bank, &inode, &cur_page)); + cur_block = 0; + } + + if (pfs->activebank != cur_page.inode_t.bank) { + ERRCK(SELECT_BANK(pfs, cur_page.inode_t.bank)); + } + + blockno = cur_page.inode_t.page * PFS_ONE_PAGE + cur_block; + + if (flag == OS_READ) { + ret = __osContRamRead(pfs->queue, pfs->channel, blockno, buffer); + } else { + ret = __osContRamWrite(pfs->queue, pfs->channel, blockno, buffer, FALSE); + } + + if (ret != 0) { + return ret; + } + buffer += BLOCKSIZE; + cur_block++; + siz_block--; + } + + if (flag == PFS_WRITE && (dir.status & DIR_STATUS_OCCUPIED) == 0) { + dir.status |= DIR_STATUS_OCCUPIED; +#if BUILD_VERSION >= VERSION_J + SET_ACTIVEBANK_TO_ZERO(); +#else + ERRCK(SELECT_BANK(pfs, 0)); +#endif + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir, FALSE)); + } + +#if BUILD_VERSION >= VERSION_J + ret = __osPfsGetStatus(pfs->queue, pfs->channel); + return ret; +#else + return 0; +#endif +} diff --git a/lib/ultralib/src/io/pfsreformat.c b/lib/ultralib/src/io/pfsreformat.c new file mode 100644 index 0000000..687b456 --- /dev/null +++ b/lib/ultralib/src/io/pfsreformat.c @@ -0,0 +1,71 @@ +#include "PR/os_internal.h" +#include "controller.h" +#include "siint.h" + +s32 osPfsReFormat(OSPfs* pfs, OSMesgQueue* queue, int channel) { + int j; + int i; + __OSInode inode; + u8 tmp_data[32]; + u8* ptr; + s32 ret; + __osSiGetAccess(); + ret = __osPfsGetStatus(queue, channel); + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + pfs->status ^= PFS_INITIALIZED; + pfs->queue = queue; + pfs->channel = channel; + __osSiRelAccess(); + ERRCK(__osGetId(pfs)); + + SET_ACTIVEBANK_TO_ZERO(); + + for (j = 0; j < ARRLEN(tmp_data); j++) { + tmp_data[j] = 0; + } + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamWrite(queue, channel, pfs->dir_table + j, tmp_data, FALSE)); + } + + for (j = 0; j < pfs->inode_start_page; j++) { + inode.inode_page[j].ipage = 0; + } + + for (j = pfs->inode_start_page; j < ARRLEN(inode.inode_page); j++) { + inode.inode_page[j].ipage = 3; + } + + inode.inode_page[0].ipage = __osSumcalc((u8*)(inode.inode_page + pfs->inode_start_page), + (ARRLEN(inode.inode_page) - pfs->inode_start_page) * sizeof(__OSInodeUnit)); + ptr = (u8*)&inode; + + for (j = 0; j < PFS_ONE_PAGE; j++) { + ERRCK(__osContRamWrite(queue, channel, pfs->inode_table + j, ptr + j * BLOCKSIZE, FALSE)); + ERRCK(__osContRamWrite(queue, channel, pfs->minode_table + j, ptr + j * BLOCKSIZE, FALSE)); + } + + for (i = 1; i < pfs->banks; i++) { + for (j = 1; j < ARRLEN(inode.inode_page); j++) { + inode.inode_page[j].ipage = 3; + } + + inode.inode_page[0].ipage = + __osSumcalc((u8*)(inode.inode_page + 1), (ARRLEN(inode.inode_page) - 1) * sizeof(__OSInodeUnit)); + ptr = (u8*)&inode; + + for (j = 0; j < PFS_ONE_PAGE; j++) { + ERRCK( + __osContRamWrite(queue, channel, pfs->inode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); + ERRCK( + __osContRamWrite(queue, channel, pfs->minode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); + } + } + + return 0; +} diff --git a/lib/ultralib/src/io/pfsrepairid.c b/lib/ultralib/src/io/pfsrepairid.c new file mode 100644 index 0000000..348f8b2 --- /dev/null +++ b/lib/ultralib/src/io/pfsrepairid.c @@ -0,0 +1,73 @@ +#include "PR/os_internal.h" +#include "controller.h" + +#if BUILD_VERSION >= VERSION_J + +s32 osPfsRepairId(OSPfs* pfs) { + s32 ret = 0; + + if ((pfs->status & (PFS_INITIALIZED | PFS_ID_BROKEN))) { + ret = __osGetId(pfs); + + if (ret == 0) { + pfs->status &= ~(PFS_ID_BROKEN); + } + } else { + ret = PFS_ERR_INVALID; + } + + return ret; +} + +#else + +s32 osPfsRepairId(OSPfs *pfs) { + int k; + u16 sum; + u16 isum; + u8 temp[32]; + __OSPackId newid; + s32 ret; + __OSPackId *id; + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)&temp)); + __osIdCheckSum((u16*)&temp, &sum, &isum); + id = (__OSPackId*)&temp; + + if (id->checksum != sum || id->inverted_checksum != isum) { + ret = __osCheckPackId(pfs, id); + + if (ret == 10) { + ERRCK(__osRepairPackId(pfs, id, &newid)); + id = &newid; + } else if (ret != 0) { + return ret; + } + } + + if ((id->deviceid & 1) == 0) { + ERRCK(__osRepairPackId(pfs, id, &newid)); + id = &newid; + + if ((id->deviceid & 1) == 0) { + return PFS_ERR_DEVICE; + } + } + + for (k = 0; k < ARRLEN(pfs->id); k++) { + pfs->id[k] = ((u8*)id)[k]; + } + + pfs->version = id->version; + pfs->banks = id->banks; + pfs->inode_start_page = pfs->banks * 2 + 3; + pfs->dir_size = 16; + pfs->inode_table = 8; + pfs->minode_table = (pfs->banks + 1) * PFS_ONE_PAGE; + pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 7, pfs->label)); + return 0; +} + +#endif diff --git a/lib/ultralib/src/io/pfssearchfile.c b/lib/ultralib/src/io/pfssearchfile.c new file mode 100644 index 0000000..4fa3c57 --- /dev/null +++ b/lib/ultralib/src/io/pfssearchfile.c @@ -0,0 +1,56 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osPfsFindFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, s32* file_no) { + s32 j; + int i; + __OSDir dir; + s32 ret = 0; + int fail; + +#if BUILD_VERSION >= VERSION_J + if (!(pfs->status & PFS_INITIALIZED)) { + return PFS_ERR_INVALID; + } + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osPfsGetStatus(pfs->queue, pfs->channel)); +#endif + + if ((dir.company_code == company_code) && dir.game_code == game_code) { + fail = FALSE; + + if (game_name != NULL) { + for (i = 0; i < ARRLEN(dir.game_name); i++) { + if (dir.game_name[i] != game_name[i]) { + fail = TRUE; + break; + } + } + } + + if (ext_name != NULL && !fail) { + for (i = 0; i < ARRLEN(dir.ext_name); i++) { + if (dir.ext_name[i] != ext_name[i]) { + fail = TRUE; + break; + } + } + } + + if (!fail) { + *file_no = j; + return ret; + } + } + } + + *file_no = -1; + return PFS_ERR_INVALID; +} diff --git a/lib/ultralib/src/io/pfsselectbank.c b/lib/ultralib/src/io/pfsselectbank.c new file mode 100644 index 0000000..7e33b2d --- /dev/null +++ b/lib/ultralib/src/io/pfsselectbank.c @@ -0,0 +1,22 @@ +#include "PR/os_internal.h" +#include "controller.h" + +#if BUILD_VERSION >= VERSION_J +s32 __osPfsSelectBank(OSPfs* pfs, u8 bank) { + u8 temp[BLOCKSIZE]; + int i; + s32 ret = 0; + + for (i = 0; i < BLOCKSIZE; i++) { + temp[i] = bank; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_DETECT, temp, FALSE); + + if (ret == 0) { + pfs->activebank = bank; + } + + return ret; +} +#endif diff --git a/lib/ultralib/src/io/pfssetlabel.c b/lib/ultralib/src/io/pfssetlabel.c new file mode 100644 index 0000000..43308c7 --- /dev/null +++ b/lib/ultralib/src/io/pfssetlabel.c @@ -0,0 +1,41 @@ +#include "PR/os_internal.h" +#include "controller.h" + +s32 osPfsSetLabel(OSPfs* pfs, u8* label) { + int i; + s32 ret; + +#if BUILD_VERSION >= VERSION_J + if (!(pfs->status & PFS_INITIALIZED)) { + return PFS_ERR_INVALID; + } + + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + + if (label != NULL) { + for (i = 0; i < ARRLEN(pfs->label); i++) { + if (*label == 0) { + break; + } + + *(pfs->label + i) = *label++; + } + } + +#if BUILD_VERSION >= VERSION_J + if (pfs->activebank != 0) { + ret = SELECT_BANK(pfs, 0); + if (ret == 0) { + ret = (__osContRamWrite(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label, FALSE)); + } + } + return ret; +#else + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label, FALSE)); + return 0; +#endif +} diff --git a/lib/ultralib/src/io/pi.c b/lib/ultralib/src/io/pi.c new file mode 100644 index 0000000..3e67ddb --- /dev/null +++ b/lib/ultralib/src/io/pi.c @@ -0,0 +1,15 @@ + +#include "PR/os_internal.h" +#include "piint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osPiDeviceBusy() { + register u32 stat = IO_READ(PI_STATUS_REG); + if (stat & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/ultralib/src/io/piacs.c b/lib/ultralib/src/io/piacs.c new file mode 100644 index 0000000..c95147f --- /dev/null +++ b/lib/ultralib/src/io/piacs.c @@ -0,0 +1,25 @@ +#include "macros.h" +#include "PR/os_internal.h" + +#define PI_Q_BUF_LEN 1 +u32 __osPiAccessQueueEnabled = 0; +static OSMesg piAccessBuf[PI_Q_BUF_LEN]; +OSMesgQueue __osPiAccessQueue ALIGNED(8); + +void __osPiCreateAccessQueue(void) { + __osPiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, PI_Q_BUF_LEN); + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} + +void __osPiGetAccess(void) { + OSMesg dummyMesg; + if (!__osPiAccessQueueEnabled) { + __osPiCreateAccessQueue(); + } + osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK); +} + +void __osPiRelAccess(void) { + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} diff --git a/lib/ultralib/src/io/pidma.c b/lib/ultralib/src/io/pidma.c new file mode 100644 index 0000000..0584e12 --- /dev/null +++ b/lib/ultralib/src/io/pidma.c @@ -0,0 +1,66 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "piint.h" + +s32 osPiStartDma(OSIoMesg* mb, s32 priority, s32 direction, u32 devAddr, void* dramAddr, u32 size, OSMesgQueue* mq) { + register s32 ret; + if (!__osPiDevMgr.active) { +#ifdef _DEBUG + __osError(ERR_OSPISTARTDMA_PIMGR, 0); +#endif + return -1; + } + +#ifdef _DEBUG + if ((priority != OS_MESG_PRI_NORMAL) && (priority != OS_MESG_PRI_HIGH)) { + __osError(ERR_OSPISTARTDMA_PRI, 1, priority); + return -1; + } + + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPISTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPISTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32)dramAddr & 0x7) { + __osError(ERR_OSPISTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPISTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPISTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + if (direction == OS_READ) { + mb->hdr.type = OS_MESG_TYPE_DMAREAD; + } else { + mb->hdr.type = OS_MESG_TYPE_DMAWRITE; + } + + mb->hdr.pri = priority; + mb->hdr.retQueue = mq; + mb->dramAddr = dramAddr; + mb->devAddr = devAddr; + mb->size = size; + mb->piHandle = NULL; + + if (priority == OS_MESG_PRI_HIGH) { + ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); + } else { + ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); + } + + return ret; +} diff --git a/lib/ultralib/src/io/pigetcmdq.c b/lib/ultralib/src/io/pigetcmdq.c new file mode 100644 index 0000000..4724301 --- /dev/null +++ b/lib/ultralib/src/io/pigetcmdq.c @@ -0,0 +1,10 @@ +#include "PR/os_internal.h" +#include "piint.h" + +OSMesgQueue* osPiGetCmdQueue(void) { + if (!__osPiDevMgr.active) { + return NULL; + } else { + return __osPiDevMgr.cmdQueue; + } +} diff --git a/lib/ultralib/src/io/pigetstat.c b/lib/ultralib/src/io/pigetstat.c new file mode 100644 index 0000000..43e9a27 --- /dev/null +++ b/lib/ultralib/src/io/pigetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "piint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osPiGetStatus() { + return IO_READ(PI_STATUS_REG); +} diff --git a/lib/ultralib/src/io/pigettype.c b/lib/ultralib/src/io/pigettype.c new file mode 100644 index 0000000..f918306 --- /dev/null +++ b/lib/ultralib/src/io/pigettype.c @@ -0,0 +1,8 @@ +#include "PR/os_internal.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osPiGetDeviceType() { + return osRomType; +} diff --git a/lib/ultralib/src/io/piint.h b/lib/ultralib/src/io/piint.h new file mode 100644 index 0000000..50a0858 --- /dev/null +++ b/lib/ultralib/src/io/piint.h @@ -0,0 +1,197 @@ +#ifndef _PIINT_H_ +#define _PIINT_H_ + +#include "PR/os_internal.h" +#include "PR/rcp.h" + +//https://github.com/LuigiBlood/64dd/wiki/Memory-Map + +#define LEO_BASE_REG 0x05000000 + +#define LEO_CMD (LEO_BASE_REG + 0x508) +#define LEO_STATUS (LEO_BASE_REG + 0x508) + +#define LEO_BM_CTL (LEO_BASE_REG + 0x510) +#define LEO_BM_STATUS (LEO_BASE_REG + 0x510) + +#define LEO_SEQ_CTL (LEO_BASE_REG + 0x518) +#define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518) + +#define LEO_C2_BUFF (LEO_BASE_REG + 0x000) //C2 Sector Buffer +#define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400) //Data Sector Buffer +#define LEO_DATA (LEO_BASE_REG + 0x500) //Data +#define LEO_MISC_REG (LEO_BASE_REG + 0x504) //Misc Register +#define LEO_CUR_TK (LEO_BASE_REG + 0x50C) //Current Track +#define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514) //Sector Error Status +#define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C) //Current Sector +#define LEO_HARD_RESET (LEO_BASE_REG + 0x520) //Hard Reset +#define LEO_C1_S0 (LEO_BASE_REG + 0x524) //C1 +#define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) //Sector Size (in bytes) +#define LEO_C1_S2 (LEO_BASE_REG + 0x52C) //C1 +#define LEO_SEC_BYTE (LEO_BASE_REG + 0x530) //Sectors per Block, Full Size +#define LEO_C1_S4 (LEO_BASE_REG + 0x534) //C1 +#define LEO_C1_S6 (LEO_BASE_REG + 0x538) //C1 +#define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C) //Current Address? +#define LEO_ID_REG (LEO_BASE_REG + 0x540) //ID +#define LEO_TEST_REG (LEO_BASE_REG + 0x544) //Test Read +#define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) //Test Write +#define LEO_RAM_ADDR (LEO_BASE_REG + 0x580) //Microsequencer RAM + +#define LEO_STATUS_PRESENCE_MASK 0xFFFF + +#define LEO_STATUS_DATA_REQUEST 0x40000000 +#define LEO_STATUS_C2_TRANSFER 0x10000000 +#define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000 +#define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000 +#define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000 +#define LEO_STATUS_DISK_PRESENT 0x01000000 +#define LEO_STATUS_BUSY_STATE 0x00800000 +#define LEO_STATUS_RESET_STATE 0x00400000 +#define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000 +#define LEO_STATUS_HEAD_RETRACTED 0x00080000 +#define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000 +#define LEO_STATUS_MECHANIC_ERROR 0x00020000 +#define LEO_STATUS_DISK_CHANGE 0x00010000 + +#define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_ACTIVE 0 + +#define LEO_CUR_TK_INDEX_LOCK 0x60000000 + +#define LEO_BM_STATUS_RUNNING 0x80000000 //Running +#define LEO_BM_STATUS_ERROR 0x04000000 //Error +#define LEO_BM_STATUS_MICRO 0x02000000 //Micro Status? +#define LEO_BM_STATUS_BLOCK 0x01000000 //Block Transfer +#define LEO_BM_STATUS_C1CORRECTION 0x00800000 //C1 Correction +#define LEO_BM_STATUS_C1DOUBLE 0x00400000 //C1 Double +#define LEO_BM_STATUS_C1SINGLE 0x00200000 //C1 Single +#define LEO_BM_STATUS_C1ERROR 0x00010000 //C1 Error + +#define LEO_BM_CTL_START 0x80000000 //Start Buffer Manager +#define LEO_BM_CTL_MODE 0x40000000 //Buffer Manager Mode +#define LEO_BM_CTL_IMASK 0x20000000 //BM Interrupt Mask +#define LEO_BM_CTL_RESET 0x10000000 //Buffer Manager Reset +#define LEO_BM_CTL_DISABLE_OR 0x08000000 //Disable OR Check? +#define LEO_BM_CTL_DISABLE_C1 0x04000000 //Disable C1 Correction +#define LEO_BM_CTL_BLOCK 0x02000000 //Block Transfer +#define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 //Mechanic Interrupt Reset + +#define LEO_BM_CTL_CONTROL_MASK 0xFF000000 +#define LEO_BM_CTL_SECTOR_MASK 0x00FF0000 +#define LEO_BM_CTL_SECTOR_SHIFT 16 + +#define LEO_CMD_TYPE_0 0 //TODO: name +#define LEO_CMD_TYPE_1 1 //TODO: name +#define LEO_CMD_TYPE_2 2 //TODO: name + +#define LEO_ERROR_GOOD 0 +#define LEO_ERROR_4 4 //maybe busy? +#define LEO_ERROR_22 22 // +#define LEO_ERROR_23 23 //unrecovered read error? +#define LEO_ERROR_24 24 //no reference position found? +#define LEO_ERROR_29 29 // + +extern OSDevMgr __osPiDevMgr; +extern OSPiHandle *__osCurrentHandle[]; +extern OSPiHandle CartRomHandle; +extern OSPiHandle LeoDiskHandle; +extern OSMesgQueue __osPiAccessQueue; +extern u32 __osPiAccessQueueEnabled; + +// These symbols were all renamed in 2.0J. +#if BUILD_VERSION < VERSION_J +#define __osEPiRawStartDma osEPiRawStartDma +#define __osEPiRawReadIo osEPiRawReadIo +#define __osEPiRawWriteIo osEPiRawWriteIo +#define __osPiRawStartDma osPiRawStartDma +#define __osPiRawWriteIo osPiRawWriteIo +#define __osPiRawReadIo osPiRawReadIo +#endif + +int __osPiDeviceBusy(void); +void __osDevMgrMain(void *); +void __osPiCreateAccessQueue(void); +void __osPiRelAccess(void); +void __osPiGetAccess(void); +s32 __osPiRawStartDma(s32, u32 , void *, u32 ); +s32 __osPiRawWriteIo(u32, u32); +s32 __osPiRawReadIo(u32, u32 *); +s32 __osEPiRawWriteIo(OSPiHandle *, u32 , u32); +s32 __osEPiRawReadIo(OSPiHandle *, u32 , u32 *); +s32 __osEPiRawStartDma(OSPiHandle *, s32 , u32 , void *, u32 ); +OSMesgQueue *osPiGetCmdQueue(void); + +#define WAIT_ON_IOBUSY(stat) \ + { \ + stat = IO_READ(PI_STATUS_REG); \ + while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \ + stat = IO_READ(PI_STATUS_REG); \ + } (void)0 + +#define UPDATE_REG(pihandle, reg, var) \ + if (cHandle->var != pihandle->var) \ + IO_WRITE(reg, pihandle->var) + +#if BUILD_VERSION >= VERSION_J + +#define EPI_SYNC(pihandle, stat, domain) \ + \ + WAIT_ON_IOBUSY(stat); \ + \ + domain = pihandle->domain; \ + if (__osCurrentHandle[domain]->type != pihandle->type) \ + { \ + OSPiHandle *cHandle = __osCurrentHandle[domain]; \ + if (domain == PI_DOMAIN1) \ + { \ + UPDATE_REG(pihandle, PI_BSD_DOM1_LAT_REG, latency); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_PGS_REG, pageSize); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_RLS_REG, relDuration); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_PWD_REG, pulse); \ + } \ + else \ + { \ + UPDATE_REG(pihandle, PI_BSD_DOM2_LAT_REG, latency); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_PGS_REG, pageSize); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_RLS_REG, relDuration); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_PWD_REG, pulse); \ + } \ + cHandle->type = pihandle->type; \ + cHandle->latency = pihandle->latency; \ + cHandle->pageSize = pihandle->pageSize; \ + cHandle->relDuration = pihandle->relDuration; \ + cHandle->pulse = pihandle->pulse; \ + }(void)0 + +#else + +#define EPI_SYNC(pihandle, stat, domain) \ + \ + WAIT_ON_IOBUSY(stat); \ + \ + domain = pihandle->domain; \ + if (__osCurrentHandle[domain] != pihandle) \ + { \ + OSPiHandle *cHandle = __osCurrentHandle[domain]; \ + if (domain == PI_DOMAIN1) \ + { \ + UPDATE_REG(pihandle, PI_BSD_DOM1_LAT_REG, latency); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_PGS_REG, pageSize); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_RLS_REG, relDuration); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_PWD_REG, pulse); \ + } \ + else \ + { \ + UPDATE_REG(pihandle, PI_BSD_DOM2_LAT_REG, latency); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_PGS_REG, pageSize); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_RLS_REG, relDuration); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_PWD_REG, pulse); \ + } \ + __osCurrentHandle[domain] = pihandle; \ + }(void)0 + +#endif + +#endif diff --git a/lib/ultralib/src/io/pimgr.c b/lib/ultralib/src/io/pimgr.c new file mode 100644 index 0000000..d98c6ad --- /dev/null +++ b/lib/ultralib/src/io/pimgr.c @@ -0,0 +1,114 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "piint.h" +#include "PR/rdb.h" + +static OSThread piThread ALIGNED(8); +static char piThreadStack[OS_PIM_STACKSIZE] ALIGNED(16); + +#ifndef _FINALROM +static OSThread ramromThread ALIGNED(8); +static char ramromThreadStack[1024] ALIGNED(16); +static OSMesgQueue getRamromQ ALIGNED(8); +static OSMesg getRamromBuf[1]; +static OSMesgQueue freeRamromQ ALIGNED(8); +static OSMesg freeRamromBuf[1]; +static void ramromMain(void*); +#endif + +static OSMesgQueue piEventQueue ALIGNED(8); +static OSMesg piEventBuf[1]; + +OSDevMgr __osPiDevMgr = { 0 }; +OSPiHandle* __osPiTable = NULL; +#if BUILD_VERSION >= VERSION_J +OSPiHandle __Dom1SpeedParam ALIGNED(8); +OSPiHandle __Dom2SpeedParam ALIGNED(8); +OSPiHandle* __osCurrentHandle[2] ALIGNED(8) = { &__Dom1SpeedParam, &__Dom2SpeedParam }; +#else +extern OSPiHandle CartRomHandle; +extern OSPiHandle LeoDiskHandle; +OSPiHandle* __osCurrentHandle[2] ALIGNED(8) = { &CartRomHandle, &LeoDiskHandle }; +#endif + +void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { + u32 savedMask; + OSPri oldPri; + OSPri myPri; + +#ifdef _DEBUG + if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { + __osError(ERR_OSCREATEPIMANAGER, 1, pri); + return; + } +#endif + + if (__osPiDevMgr.active) { + return; + } + osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt); + osCreateMesgQueue(&piEventQueue, (OSMesg*)piEventBuf, 1); + + if (!__osPiAccessQueueEnabled) { + __osPiCreateAccessQueue(); + } + + osSetEventMesg(OS_EVENT_PI, &piEventQueue, (OSMesg)0x22222222); + oldPri = -1; + myPri = osGetThreadPri(NULL); + + if (myPri < pri) { + oldPri = myPri; + osSetThreadPri(NULL, pri); + } + + savedMask = __osDisableInt(); + __osPiDevMgr.active = 1; + __osPiDevMgr.thread = &piThread; + __osPiDevMgr.cmdQueue = cmdQ; + __osPiDevMgr.evtQueue = &piEventQueue; + __osPiDevMgr.acsQueue = &__osPiAccessQueue; + __osPiDevMgr.dma = __osPiRawStartDma; + __osPiDevMgr.edma = __osEPiRawStartDma; + osCreateThread(&piThread, 0, __osDevMgrMain, &__osPiDevMgr, &piThreadStack[OS_PIM_STACKSIZE], pri); + osStartThread(&piThread); + +#ifndef _FINALROM + osCreateThread(&ramromThread, 0, ramromMain, NULL, ramromThreadStack + 1024, (OSPri)pri - 1); + osStartThread(&ramromThread); +#endif + __osRestoreInt(savedMask); + + if (oldPri != -1) { + osSetThreadPri(NULL, oldPri); + } +} + +#ifndef _FINALROM +static void ramromMain(void* arg) { + u32 sent; + u8 tmp[3]; + + osCreateMesgQueue(&getRamromQ, getRamromBuf, 1); + osCreateMesgQueue(&freeRamromQ, freeRamromBuf, 1); + osSetEventMesg(OS_EVENT_RDB_REQ_RAMROM, &getRamromQ, NULL); + osSetEventMesg(OS_EVENT_RDB_FREE_RAMROM, &freeRamromQ, NULL); + + while (TRUE) { + osRecvMesg(&getRamromQ, NULL, OS_MESG_BLOCK); + + __osPiGetAccess(); + + sent = 0; + + while (sent < 1) { + sent += __osRdbSend(tmp, 1, RDB_TYPE_GtoH_RAMROM); + } + + osRecvMesg(&freeRamromQ, NULL, OS_MESG_BLOCK); + + __osPiRelAccess(); + } +} +#endif diff --git a/lib/ultralib/src/io/pirawdma.c b/lib/ultralib/src/io/pirawdma.c new file mode 100644 index 0000000..d5ea8c3 --- /dev/null +++ b/lib/ultralib/src/io/pirawdma.c @@ -0,0 +1,53 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osPiRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { + register u32 stat; + +#ifdef _DEBUG + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32)dramAddr & 0x7) { + __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + WAIT_ON_IOBUSY(stat); + + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS((u32)osRomBase | devAddr)); + + switch (direction) { + case OS_READ: + IO_WRITE(PI_WR_LEN_REG, size - 1); + break; + case OS_WRITE: + IO_WRITE(PI_RD_LEN_REG, size - 1); + break; + default: + return -1; + } + return 0; +} diff --git a/lib/ultralib/src/io/pirawread.c b/lib/ultralib/src/io/pirawread.c new file mode 100644 index 0000000..95d7082 --- /dev/null +++ b/lib/ultralib/src/io/pirawread.c @@ -0,0 +1,66 @@ +#include "piint.h" +#include "assert.h" +#include "PR/ultraerror.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 46 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osPiRawReadIo(u32 devAddr, u32* data) { + register u32 stat; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWREADIO, 1, devAddr); + return -1; + } +#endif + + assert(data != NULL); + + WAIT_ON_IOBUSY(stat); + *data = IO_READ((u32)osRomBase | devAddr); + + return 0; +} diff --git a/lib/ultralib/src/io/pirawwrite.c b/lib/ultralib/src/io/pirawwrite.c new file mode 100644 index 0000000..92eba84 --- /dev/null +++ b/lib/ultralib/src/io/pirawwrite.c @@ -0,0 +1,21 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osPiRawWriteIo(u32 devAddr, u32 data) { + register u32 stat; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWWRITEIO, 1, devAddr); + return -1; + } +#endif + + WAIT_ON_IOBUSY(stat); + IO_WRITE((u32)osRomBase | devAddr, data); + + return 0; +} diff --git a/lib/ultralib/src/io/piread.c b/lib/ultralib/src/io/piread.c new file mode 100644 index 0000000..42bcf3e --- /dev/null +++ b/lib/ultralib/src/io/piread.c @@ -0,0 +1,19 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +s32 osPiReadIo(u32 devAddr, u32* data) { + register s32 ret; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIREADIO, 1, devAddr); + return -1; + } +#endif + + __osPiGetAccess(); + ret = __osPiRawReadIo(devAddr, data); + __osPiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/io/piwrite.c b/lib/ultralib/src/io/piwrite.c new file mode 100644 index 0000000..75c00d1 --- /dev/null +++ b/lib/ultralib/src/io/piwrite.c @@ -0,0 +1,19 @@ +#include "piint.h" +#include "PR/ultraerror.h" + +s32 osPiWriteIo(u32 devAddr, u32 data) { + register s32 ret; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIWRITEIO, 1, devAddr); + return -1; + } +#endif + + __osPiGetAccess(); + ret = __osPiRawWriteIo(devAddr, data); + __osPiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/io/si.c b/lib/ultralib/src/io/si.c new file mode 100644 index 0000000..0188927 --- /dev/null +++ b/lib/ultralib/src/io/si.c @@ -0,0 +1,15 @@ +#include "PR/os_internal.h" +#include "siint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osSiDeviceBusy() { + register u32 stat = IO_READ(SI_STATUS_REG); + + if (stat & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/ultralib/src/io/siacs.c b/lib/ultralib/src/io/siacs.c new file mode 100644 index 0000000..8ef5b3f --- /dev/null +++ b/lib/ultralib/src/io/siacs.c @@ -0,0 +1,25 @@ +#include "macros.h" +#include "PR/os_internal.h" + +#define SI_Q_BUF_LEN 1 +static OSMesg siAccessBuf[SI_Q_BUF_LEN] ALIGNED(8); +OSMesgQueue __osSiAccessQueue ALIGNED(8); +u32 __osSiAccessQueueEnabled = 0; + +void __osSiCreateAccessQueue(void) { + __osSiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, SI_Q_BUF_LEN); + osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); +} + +void __osSiGetAccess(void) { + OSMesg dummyMesg; + if (!__osSiAccessQueueEnabled) { + __osSiCreateAccessQueue(); + } + osRecvMesg(&__osSiAccessQueue, &dummyMesg, OS_MESG_BLOCK); +} + +void __osSiRelAccess(void) { + osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); +} diff --git a/lib/ultralib/src/io/sigetstat.c b/lib/ultralib/src/io/sigetstat.c new file mode 100644 index 0000000..0225445 --- /dev/null +++ b/lib/ultralib/src/io/sigetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "siint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 __osSiGetStatus() { + return IO_READ(SI_STATUS_REG); +} diff --git a/lib/ultralib/src/io/siint.h b/lib/ultralib/src/io/siint.h new file mode 100644 index 0000000..636a87f --- /dev/null +++ b/lib/ultralib/src/io/siint.h @@ -0,0 +1,15 @@ +#ifndef _SIINT_H +#define _SIINT_H + +#include "PR/os_internal.h" +#include "PR/rcp.h" + +extern s32 __osEepromRead16K; +extern u8 __osPfsInodeCacheBank; + +void __osSiGetAccess(void); +void __osSiRelAccess(void); +int __osSiDeviceBusy(void); +void __osSiCreateAccessQueue(void); + +#endif diff --git a/lib/ultralib/src/io/sirawdma.c b/lib/ultralib/src/io/sirawdma.c new file mode 100644 index 0000000..5fb5f8a --- /dev/null +++ b/lib/ultralib/src/io/sirawdma.c @@ -0,0 +1,85 @@ +#include "PR/os_internal.h" +#include "assert.h" +#include "siint.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 49 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawStartDma(s32 direction, void* dramAddr) { + assert(((u32)dramAddr & 0x3) == 0); + +#if BUILD_VERSION >= VERSION_J + if (IO_READ(SI_STATUS_REG) & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { + return -1; + } +#else + if (__osSiDeviceBusy()) { + return -1; + } +#endif + + if (direction == OS_WRITE) { + osWritebackDCache(dramAddr, 64); + } + + IO_WRITE(SI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + + if (direction == OS_READ) { + IO_WRITE(SI_PIF_ADDR_RD64B_REG, PIF_RAM_START); + } else { + IO_WRITE(SI_PIF_ADDR_WR64B_REG, PIF_RAM_START); + } + + if (direction == OS_READ) { + osInvalDCache(dramAddr, 64); + } + + return 0; +} diff --git a/lib/ultralib/src/io/sirawread.c b/lib/ultralib/src/io/sirawread.c new file mode 100644 index 0000000..4ce8330 --- /dev/null +++ b/lib/ultralib/src/io/sirawread.c @@ -0,0 +1,62 @@ +#include "PR/os_internal.h" +#include "assert.h" +#include "siint.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 45 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawReadIo(u32 devAddr, u32* data) { + assert((devAddr & 0x3) == 0); + assert(data != NULL); + + if (__osSiDeviceBusy()) { + return -1; + } + + *data = IO_READ(devAddr); + return 0; +} diff --git a/lib/ultralib/src/io/sirawwrite.c b/lib/ultralib/src/io/sirawwrite.c new file mode 100644 index 0000000..795d38a --- /dev/null +++ b/lib/ultralib/src/io/sirawwrite.c @@ -0,0 +1,61 @@ +#include "PR/os_internal.h" +#include "siint.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 46 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawWriteIo(u32 devAddr, u32 data) { + assert((devAddr & 0x3) == 0); + + if (__osSiDeviceBusy()) { + return -1; + } + + IO_WRITE(devAddr, data); + return 0; +} diff --git a/lib/ultralib/src/io/sp.c b/lib/ultralib/src/io/sp.c new file mode 100644 index 0000000..3ad9076 --- /dev/null +++ b/lib/ultralib/src/io/sp.c @@ -0,0 +1,17 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "../os/osint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osSpDeviceBusy() { + register u32 stat = IO_READ(SP_STATUS_REG); + + if (stat & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/ultralib/src/io/spgetstat.c b/lib/ultralib/src/io/spgetstat.c new file mode 100644 index 0000000..0cdfda6 --- /dev/null +++ b/lib/ultralib/src/io/spgetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 __osSpGetStatus() { + return IO_READ(SP_STATUS_REG); +} diff --git a/lib/ultralib/src/io/sprawdma.c b/lib/ultralib/src/io/sprawdma.c new file mode 100644 index 0000000..6d95a49 --- /dev/null +++ b/lib/ultralib/src/io/sprawdma.c @@ -0,0 +1,77 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "../os/osint.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 52 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { + assert(((u32)devAddr & 0x7) == 0); + assert(((u32)dramAddr & 0x7) == 0); + assert(((u32)size & 0x7) == 0); + + if (__osSpDeviceBusy()) { + return -1; + } + + IO_WRITE(SP_MEM_ADDR_REG, devAddr); + IO_WRITE(SP_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + + if (direction == OS_READ) { + IO_WRITE(SP_WR_LEN_REG, size - 1); + } else { + IO_WRITE(SP_RD_LEN_REG, size - 1); + } + + return 0; +} diff --git a/lib/ultralib/src/io/sprawread.c b/lib/ultralib/src/io/sprawread.c new file mode 100644 index 0000000..5910a9e --- /dev/null +++ b/lib/ultralib/src/io/sprawread.c @@ -0,0 +1,61 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "../os/osint.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 45 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpRawReadIo(u32 devAddr, u32* data) { + assert((devAddr & 0x3) == 0); + assert(data != NULL); + + if (__osSpDeviceBusy()) { + return -1; + } + + *data = IO_READ(devAddr); + return 0; +} diff --git a/lib/ultralib/src/io/sprawwrite.c b/lib/ultralib/src/io/sprawwrite.c new file mode 100644 index 0000000..9ce3ebf --- /dev/null +++ b/lib/ultralib/src/io/sprawwrite.c @@ -0,0 +1,61 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "../os/osint.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 45 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpRawWriteIo(u32 devAddr, u32 data) { + assert((devAddr & 0x3) == 0); + + if (__osSpDeviceBusy()) { + return -1; + } + + IO_WRITE(devAddr, data); + return 0; +} diff --git a/lib/ultralib/src/io/spsetpc.c b/lib/ultralib/src/io/spsetpc.c new file mode 100644 index 0000000..dce0b5d --- /dev/null +++ b/lib/ultralib/src/io/spsetpc.c @@ -0,0 +1,15 @@ +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpSetPc(u32 pc) { + register u32 status = IO_READ(SP_STATUS_REG); + + if (!(status & SP_STATUS_HALT)) { + return -1; + } + IO_WRITE(SP_PC_REG, pc); + + return 0; +} diff --git a/lib/ultralib/src/io/spsetstat.c b/lib/ultralib/src/io/spsetstat.c new file mode 100644 index 0000000..2ab47e0 --- /dev/null +++ b/lib/ultralib/src/io/spsetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void __osSpSetStatus(u32 data) { + IO_WRITE(SP_STATUS_REG, data); +} diff --git a/lib/ultralib/src/io/sptask.c b/lib/ultralib/src/io/sptask.c new file mode 100644 index 0000000..8fbfeb2 --- /dev/null +++ b/lib/ultralib/src/io/sptask.c @@ -0,0 +1,82 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/sptask.h" +#include "PR/rcp.h" +#include "../os/osint.h" + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 1.4 $" +#endif + +#define _osVirtualToPhysical(ptr) \ + if (ptr != NULL) { \ + ptr = (void*)osVirtualToPhysical(ptr); \ + } + +static OSTask tmp_task; + +static OSTask* _VirtualToPhysicalTask(OSTask* intp) { + OSTask* tp; + tp = &tmp_task; + bcopy(intp, tp, sizeof(OSTask)); + + _osVirtualToPhysical(tp->t.ucode); + _osVirtualToPhysical(tp->t.ucode_data); + _osVirtualToPhysical(tp->t.dram_stack); + _osVirtualToPhysical(tp->t.output_buff); + _osVirtualToPhysical(tp->t.output_buff_size); + _osVirtualToPhysical(tp->t.data_ptr); + _osVirtualToPhysical(tp->t.yield_data_ptr); + return tp; +} + +void osSpTaskLoad(OSTask* intp) { + OSTask* tp; + +#ifdef _DEBUG + if ((intp->t.dram_stack != 0x0) && ((u32)intp->t.dram_stack & 0xf)) { + __osError(ERR_OSSPTASKLOAD_DRAM, 1, intp->t.dram_stack); + return; + } + if ((intp->t.output_buff != 0x0) && ((u32)intp->t.output_buff & 0xf)) { + __osError(ERR_OSSPTASKLOAD_OUT, 1, intp->t.output_buff); + return; + } + if ((intp->t.output_buff_size != 0x0) && ((u32)intp->t.output_buff_size & 0xf)) { + __osError(ERR_OSSPTASKLOAD_OUTSIZE, 1, intp->t.output_buff_size); + return; + } + if ((intp->t.yield_data_ptr != 0x0) && ((u32)intp->t.yield_data_ptr & 0xf)) { + __osError(ERR_OSSPTASKLOAD_YIELD, 1, intp->t.yield_data_ptr); + return; + } +#endif + + tp = _VirtualToPhysicalTask(intp); + + if (tp->t.flags & OS_TASK_YIELDED) { + tp->t.ucode_data = tp->t.yield_data_ptr; + tp->t.ucode_data_size = tp->t.yield_data_size; + intp->t.flags &= ~OS_TASK_YIELDED; + if (tp->t.flags & OS_TASK_LOADABLE) { + tp->t.ucode = (u64*)IO_READ((u32)intp->t.yield_data_ptr + OS_YIELD_DATA_SIZE - 4); + } + } + + osWritebackDCache(tp, sizeof(OSTask)); + __osSpSetStatus(SP_CLR_YIELD | SP_CLR_YIELDED | SP_CLR_TASKDONE | SP_SET_INTR_BREAK); + + while (__osSpSetPc(SP_IMEM_START) == -1) {} + + while (__osSpRawStartDma(1, (SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) {} + + while (__osSpDeviceBusy()) {} + + while (__osSpRawStartDma(1, SP_IMEM_START, tp->t.ucode_boot, tp->t.ucode_boot_size) == -1) {} +} + +void osSpTaskStartGo(OSTask* tp) { + while (__osSpDeviceBusy()) {} + + __osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT); +} diff --git a/lib/ultralib/src/io/sptaskyield.c b/lib/ultralib/src/io/sptaskyield.c new file mode 100644 index 0000000..78bacae --- /dev/null +++ b/lib/ultralib/src/io/sptaskyield.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +void osSpTaskYield(void) { + __osSpSetStatus(SP_SET_YIELD); +} diff --git a/lib/ultralib/src/io/sptaskyielded.c b/lib/ultralib/src/io/sptaskyielded.c new file mode 100644 index 0000000..3ecab55 --- /dev/null +++ b/lib/ultralib/src/io/sptaskyielded.c @@ -0,0 +1,18 @@ +#include "PR/os_internal.h" +#include "PR/sptask.h" +#include "PR/rcp.h" + +OSYieldResult osSpTaskYielded(OSTask* tp) { + u32 status; + OSYieldResult result; + + status = __osSpGetStatus(); + result = (status & SP_STATUS_YIELDED) ? OS_TASK_YIELDED : 0; + + if (status & SP_STATUS_YIELD) { + tp->t.flags |= result; + tp->t.flags &= ~(OS_TASK_DP_WAIT); + } + + return result; +} diff --git a/lib/ultralib/src/io/vi.c b/lib/ultralib/src/io/vi.c new file mode 100644 index 0000000..246f01f --- /dev/null +++ b/lib/ultralib/src/io/vi.c @@ -0,0 +1,39 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/rcp.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +static __OSViContext vi[2] ALIGNED(8) = { 0 }; +__OSViContext* __osViCurr = &vi[0]; +__OSViContext* __osViNext = &vi[1]; + +void __osViInit(void) { + bzero(vi, sizeof(vi)); + __osViCurr = &vi[0]; + __osViNext = &vi[1]; + __osViNext->retraceCount = 1; + __osViCurr->retraceCount = 1; + __osViNext->framep = (void*)K0BASE; + __osViCurr->framep = (void*)K0BASE; + + if (osTvType == OS_TV_TYPE_PAL) { + __osViNext->modep = &osViModePalLan1; + } else if (osTvType == OS_TV_TYPE_MPAL) { + __osViNext->modep = &osViModeMpalLan1; + } else { + __osViNext->modep = &osViModeNtscLan1; + } + + __osViNext->state = VI_STATE_BLACK; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + + while (IO_READ(VI_CURRENT_REG) > 10) { // wait for vsync? + } + + IO_WRITE(VI_CONTROL_REG, 0); // pixel size blank (no data, no sync) + __osViSwapContext(); +} diff --git a/lib/ultralib/src/io/viblack.c b/lib/ultralib/src/io/viblack.c new file mode 100644 index 0000000..30dd85c --- /dev/null +++ b/lib/ultralib/src/io/viblack.c @@ -0,0 +1,17 @@ +#include "PR/os_internal.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViBlack(u8 active) { + register u32 saveMask = __osDisableInt(); + + if (active) { + __osViNext->state |= VI_STATE_BLACK; + } else { + __osViNext->state &= ~VI_STATE_BLACK; + } + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/viextendvstart.c b/lib/ultralib/src/io/viextendvstart.c new file mode 100644 index 0000000..7ee06d3 --- /dev/null +++ b/lib/ultralib/src/io/viextendvstart.c @@ -0,0 +1,19 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "viint.h" + +void osViExtendVStart(u32 value) { +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(134, 0); + return; + } + + if (value > 48) { + __osError(135, 1, value); + return; + } +#endif + __additional_scanline = value; + return; +} diff --git a/lib/ultralib/src/io/vifade.c b/lib/ultralib/src/io/vifade.c new file mode 100644 index 0000000..6766871 --- /dev/null +++ b/lib/ultralib/src/io/vifade.c @@ -0,0 +1,18 @@ +#include "PR/os_internal.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViFade(u8 active, u16 factor) { + register u32 saveMask = __osDisableInt(); + + if (active) { + __osViNext->y.offset = factor & VI_2_10_FPART_MASK; + __osViNext->state |= VI_STATE_FADE; + } else { + __osViNext->state &= ~VI_STATE_FADE; + } + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/vigetcurrcontext.c b/lib/ultralib/src/io/vigetcurrcontext.c new file mode 100644 index 0000000..7b1df9b --- /dev/null +++ b/lib/ultralib/src/io/vigetcurrcontext.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +__OSViContext* __osViGetCurrentContext(void) { + return __osViCurr; +} diff --git a/lib/ultralib/src/io/vigetcurrframebuf.c b/lib/ultralib/src/io/vigetcurrframebuf.c new file mode 100644 index 0000000..de36712 --- /dev/null +++ b/lib/ultralib/src/io/vigetcurrframebuf.c @@ -0,0 +1,20 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "viint.h" + +void* osViGetCurrentFramebuffer(void) { + register u32 saveMask; + void* framep; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVIGETCURRENTFRAMEBUFFER, 0); + return NULL; + } +#endif + + saveMask = __osDisableInt(); + framep = __osViCurr->framep; + __osRestoreInt(saveMask); + return framep; +} diff --git a/lib/ultralib/src/io/vigetfield.c b/lib/ultralib/src/io/vigetfield.c new file mode 100644 index 0000000..9dcb7fc --- /dev/null +++ b/lib/ultralib/src/io/vigetfield.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +u32 osViGetCurrentField(void) { + return IO_READ(VI_CURRENT_REG) & 1; +} diff --git a/lib/ultralib/src/io/vigetline.c b/lib/ultralib/src/io/vigetline.c new file mode 100644 index 0000000..5667d61 --- /dev/null +++ b/lib/ultralib/src/io/vigetline.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +u32 osViGetCurrentLine(void) { + return IO_READ(VI_CURRENT_REG); +} diff --git a/lib/ultralib/src/io/vigetmode.c b/lib/ultralib/src/io/vigetmode.c new file mode 100644 index 0000000..2507372 --- /dev/null +++ b/lib/ultralib/src/io/vigetmode.c @@ -0,0 +1,21 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "viint.h" + +u32 osViGetCurrentMode(void) { + register u32 saveMask; + register u32 modeType; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVIGETCURRENTMODE, 0); + return -1; + } +#endif + + saveMask = __osDisableInt(); + modeType = (u32)__osViCurr->modep->type; + + __osRestoreInt(saveMask); + return modeType; +} diff --git a/lib/ultralib/src/io/vigetnextcontext.c b/lib/ultralib/src/io/vigetnextcontext.c new file mode 100644 index 0000000..bb6012a --- /dev/null +++ b/lib/ultralib/src/io/vigetnextcontext.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "viint.h" + +__OSViContext* __osViGetNextContext(void) { + return __osViNext; +} diff --git a/lib/ultralib/src/io/vigetnextframebuf.c b/lib/ultralib/src/io/vigetnextframebuf.c new file mode 100644 index 0000000..2985358 --- /dev/null +++ b/lib/ultralib/src/io/vigetnextframebuf.c @@ -0,0 +1,20 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "viint.h" + +void* osViGetNextFramebuffer(void) { + register u32 saveMask; + void* framep; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVIGETNEXTFRAMEBUFFER, 0); + return NULL; + } +#endif + + saveMask = __osDisableInt(); + framep = __osViNext->framep; + __osRestoreInt(saveMask); + return framep; +} diff --git a/lib/ultralib/src/io/vigetstat.c b/lib/ultralib/src/io/vigetstat.c new file mode 100644 index 0000000..8fc6f38 --- /dev/null +++ b/lib/ultralib/src/io/vigetstat.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +u32 osViGetStatus(void) { + return IO_READ(VI_STATUS_REG); +} diff --git a/lib/ultralib/src/io/viint.h b/lib/ultralib/src/io/viint.h new file mode 100644 index 0000000..ffe0927 --- /dev/null +++ b/lib/ultralib/src/io/viint.h @@ -0,0 +1,71 @@ +#ifndef _VIINT_H +#define _VIINT_H +#include "PR/os_internal.h" + +#define OS_TV_TYPE_PAL 0 +#define OS_TV_TYPE_NTSC 1 +#define OS_TV_TYPE_MPAL 2 + +#define VI_STATE_MODE_UPDATED 0x01 +#define VI_STATE_XSCALE_UPDATED 0x02 +#define VI_STATE_YSCALE_UPDATED 0x04 +#define VI_STATE_CTRL_UPDATED 0x08 // related to control regs changing +#define VI_STATE_BUFFER_UPDATED 0x10 // swap buffer +#define VI_STATE_BLACK 0x20 // probably related to a black screen +#define VI_STATE_REPEATLINE 0x40 // repeat line? +#define VI_STATE_FADE 0x80 // fade + +#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ + +#define VI_SCALE_MASK 0xfff //see rcp scale_x/scale_y +#define VI_2_10_FPART_MASK 0x3ff +#define VI_SUBPIXEL_SH 0x10 + +#define BURST(hsync_width, color_width, vsync_width, color_start) \ + (((u32)(hsync_width) & 0xFF) | (((u32)(color_width) & 0xFF) << 8) | (((u32)(vsync_width) & 0xF) << 16) | (((u32)(color_start) & 0xFFFF) << 20)) +#define WIDTH(v) (v) +#define VSYNC(v) (v) +#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration) & 0xFFFF)) +#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower) & 0xFFFF)) +#define START(start, end) (((u32)(start) << 16) | ((u32)(end) & 0xFFFF)) + +#define FTOFIX(val, i, f) ((u32)((val) * (f32)(1 << (f))) & ((1 << ((i) + (f))) - 1)) + +#define F210(val) FTOFIX(val, 2, 10) +#define SCALE(scaleup, off) (F210((1.0f / (f32)(scaleup))) | (F210((f32)(off)) << 16)) + +#define VCURRENT(v) v //seemingly unused +#define ORIGIN(v) v +#define VINTR(v) v +#define HSTART START + +typedef struct +{ + /* 0x0 */ f32 factor; + /* 0x4 */ u16 offset; + /* 0x8 */ u32 scale; +} __OSViScale; + +typedef struct +{ + /* 0x0 */ u16 state; + /* 0x2 */ u16 retraceCount; + /* 0x4 */ void *framep; + /* 0x8 */ OSViMode *modep; + /* 0xC */ u32 control; + /* 0x10 */ OSMesgQueue *msgq; + /* 0x14 */ OSMesg msg; + /* 0x18 */ __OSViScale x; + /* 0x24 */ __OSViScale y; +} __OSViContext; // 0x30 bytes + +void __osViSwapContext(void); +extern __OSViContext *__osViCurr; +extern __OSViContext *__osViNext; +extern u32 __additional_scanline; +__OSViContext *__osViGetCurrentContext(void); +void __osViInit(void); +extern OSDevMgr __osViDevMgr; +#endif diff --git a/lib/ultralib/src/io/vimgr.c b/lib/ultralib/src/io/vimgr.c new file mode 100644 index 0000000..0fe51d5 --- /dev/null +++ b/lib/ultralib/src/io/vimgr.c @@ -0,0 +1,126 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "viint.h" +#include "../os/osint.h" + +OSDevMgr __osViDevMgr = { 0 }; +#if BUILD_VERSION >= VERSION_J +u32 __additional_scanline = 0; +#endif +static OSThread viThread; +static unsigned char viThreadStack[OS_VIM_STACKSIZE] ALIGNED(16); +static OSMesgQueue viEventQueue ALIGNED(8); +static OSMesg viEventBuf[5] ALIGNED(8); +static OSIoMesg viRetraceMsg ALIGNED(8); +static OSIoMesg viCounterMsg ALIGNED(8); + +static void viMgrMain(void* arg); +void osCreateViManager(OSPri pri) { + u32 savedMask; + OSPri oldPri; + OSPri myPri; + +#ifdef _DEBUG + if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { + __osError(ERR_OSCREATEVIMANAGER, 1, pri); + return; + } +#endif + + if (__osViDevMgr.active) { + return; + } + __osTimerServicesInit(); +#if BUILD_VERSION >= VERSION_J + __additional_scanline = 0; +#endif + osCreateMesgQueue(&viEventQueue, viEventBuf, ARRLEN(viEventBuf)); + viRetraceMsg.hdr.type = OS_MESG_TYPE_VRETRACE; + viRetraceMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viRetraceMsg.hdr.retQueue = NULL; + viCounterMsg.hdr.type = OS_MESG_TYPE_COUNTER; + viCounterMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viCounterMsg.hdr.retQueue = NULL; + osSetEventMesg(OS_EVENT_VI, &viEventQueue, &viRetraceMsg); + osSetEventMesg(OS_EVENT_COUNTER, &viEventQueue, &viCounterMsg); + oldPri = -1; + myPri = osGetThreadPri(NULL); + + if (myPri < pri) { + oldPri = myPri; + osSetThreadPri(NULL, pri); + } + + savedMask = __osDisableInt(); + __osViDevMgr.active = TRUE; + __osViDevMgr.thread = &viThread; + __osViDevMgr.cmdQueue = &viEventQueue; + __osViDevMgr.evtQueue = &viEventQueue; + __osViDevMgr.acsQueue = NULL; + __osViDevMgr.dma = NULL; + __osViDevMgr.edma = NULL; + osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &viThreadStack[OS_VIM_STACKSIZE], pri); + __osViInit(); + osStartThread(&viThread); + __osRestoreInt(savedMask); + + if (oldPri != -1) { + osSetThreadPri(NULL, oldPri); + } +} + +static void viMgrMain(void* arg) { + __OSViContext* vc; + OSDevMgr* dm; + OSIoMesg* mb; + static u16 retrace; + s32 first; + u32 count; + + mb = NULL; + first = 0; + vc = __osViGetCurrentContext(); + retrace = vc->retraceCount; + if (retrace == 0) { + retrace = 1; + } + dm = (OSDevMgr*)arg; + + while (TRUE) { + osRecvMesg(dm->evtQueue, (OSMesg)&mb, OS_MESG_BLOCK); + switch (mb->hdr.type) { + case OS_MESG_TYPE_VRETRACE: + __osViSwapContext(); + retrace--; + + if (retrace == 0) { + vc = __osViGetCurrentContext(); + if (vc->msgq != NULL) { + osSendMesg(vc->msgq, vc->msg, OS_MESG_NOBLOCK); + } + retrace = vc->retraceCount; + } + + __osViIntrCount++; + + if (first) { + count = osGetCount(); + __osCurrentTime = count; + first = 0; + } + + count = __osBaseCounter; + __osBaseCounter = osGetCount(); + count = __osBaseCounter - count; + __osCurrentTime = __osCurrentTime + count; + break; + case OS_MESG_TYPE_COUNTER: + __osTimerInterrupt(); + break; + default: + break; + } + } +} diff --git a/lib/ultralib/src/io/virepeatline.c b/lib/ultralib/src/io/virepeatline.c new file mode 100644 index 0000000..1bc4984 --- /dev/null +++ b/lib/ultralib/src/io/virepeatline.c @@ -0,0 +1,17 @@ +#include "PR/os_internal.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViRepeatLine(u8 active) { + register u32 saveMask = __osDisableInt(); + + if (active) { + __osViNext->state |= VI_STATE_REPEATLINE; + } else { + __osViNext->state &= ~VI_STATE_REPEATLINE; + } + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/visetevent.c b/lib/ultralib/src/io/visetevent.c new file mode 100644 index 0000000..f741a0e --- /dev/null +++ b/lib/ultralib/src/io/visetevent.c @@ -0,0 +1,70 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "assert.h" +#include "viint.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETEVENT, 0); + return; + } + + assert(mq != NULL); +#endif + + saveMask = __osDisableInt(); + + __osViNext->msgq = mq; + __osViNext->msg = m; + __osViNext->retraceCount = retraceCount; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/visetmode.c b/lib/ultralib/src/io/visetmode.c new file mode 100644 index 0000000..5ab2094 --- /dev/null +++ b/lib/ultralib/src/io/visetmode.c @@ -0,0 +1,67 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "assert.h" +#include "viint.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetMode(OSViMode* modep) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETMODE, 0); + return; + } + + assert(modep != NULL); +#endif + + saveMask = __osDisableInt(); + + __osViNext->modep = modep; + __osViNext->state = VI_STATE_MODE_UPDATED; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/visetspecial.c b/lib/ultralib/src/io/visetspecial.c new file mode 100644 index 0000000..0a288e5 --- /dev/null +++ b/lib/ultralib/src/io/visetspecial.c @@ -0,0 +1,72 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +// This value was incorrectly calculated until being fixed in 2.0J +#if BUILD_VERSION >= VERSION_J +#define OS_VI_SPECIAL_MAX \ + (OS_VI_GAMMA_ON | OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_ON | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | \ + OS_VI_DIVOT_OFF | OS_VI_DITHER_FILTER_ON | OS_VI_DITHER_FILTER_OFF) +#else +#define OS_VI_SPECIAL_MAX OS_VI_DITHER_FILTER_OFF +#endif + +void osViSetSpecialFeatures(u32 func) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETSPECIAL_VIMGR, 0); + return; + } + + if ((func < OS_VI_GAMMA_ON) || (func > OS_VI_SPECIAL_MAX)) { + __osError(ERR_OSVISETSPECIAL_VALUE, 1, func); + return; + } +#endif + + saveMask = __osDisableInt(); + + if ((func & OS_VI_GAMMA_ON) != 0) { + __osViNext->control |= VI_CTRL_GAMMA_ON; + } + + if ((func & OS_VI_GAMMA_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_GAMMA_ON; + } + + if ((func & OS_VI_GAMMA_DITHER_ON) != 0) { + __osViNext->control |= VI_CTRL_GAMMA_DITHER_ON; + } + + if ((func & OS_VI_GAMMA_DITHER_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_GAMMA_DITHER_ON; + } + + if ((func & OS_VI_DIVOT_ON) != 0) { + __osViNext->control |= VI_CTRL_DIVOT_ON; + } + + if ((func & OS_VI_DIVOT_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_DIVOT_ON; + } + + if ((func & OS_VI_DITHER_FILTER_ON) != 0) { + __osViNext->control |= VI_CTRL_DITHER_FILTER_ON; + __osViNext->control &= ~VI_CTRL_ANTIALIAS_MASK; + } + + if ((func & OS_VI_DITHER_FILTER_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_DITHER_FILTER_ON; + __osViNext->control |= __osViNext->modep->comRegs.ctrl & VI_CTRL_ANTIALIAS_MASK; + } + + __osViNext->state |= VI_STATE_CTRL_UPDATED; + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/visetxscale.c b/lib/ultralib/src/io/visetxscale.c new file mode 100644 index 0000000..6af6535 --- /dev/null +++ b/lib/ultralib/src/io/visetxscale.c @@ -0,0 +1,37 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/ultralog.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetXScale(f32 value) { + register u32 nomValue; + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETXSCALE_VIMGR, 0); + return; + } + + if ((value < 0.25f) || (value > 1.0f)) { + __osError(ERR_OSVISETXSCALE_VALUE, 1, OS_LOG_FLOAT(value)); + + if (value < 0.25f) { + value = 0.25f; + } else { + value = 1.0f; + } + } +#endif + + saveMask = __osDisableInt(); + + __osViNext->x.factor = value; + __osViNext->state |= VI_STATE_XSCALE_UPDATED; + nomValue = __osViNext->modep->comRegs.xScale & VI_SCALE_MASK; + __osViNext->x.scale = (u32)(__osViNext->x.factor * nomValue) & VI_SCALE_MASK; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/visetyscale.c b/lib/ultralib/src/io/visetyscale.c new file mode 100644 index 0000000..c1c96f4 --- /dev/null +++ b/lib/ultralib/src/io/visetyscale.c @@ -0,0 +1,34 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/ultralog.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetYScale(f32 value) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETYSCALE_VIMGR, 0); + return; + } + + if ((value < 0.05f) || (value > 1.0f)) { + __osError(ERR_OSVISETYSCALE_VALUE, 1, OS_LOG_FLOAT(value)); + + if (value < 0.05f) { + value = 0.05f; + } else { + value = 1.0f; + } + } +#endif + + saveMask = __osDisableInt(); + + __osViNext->y.factor = value; + __osViNext->state |= VI_STATE_YSCALE_UPDATED; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/viswapbuf.c b/lib/ultralib/src/io/viswapbuf.c new file mode 100644 index 0000000..aa077cd --- /dev/null +++ b/lib/ultralib/src/io/viswapbuf.c @@ -0,0 +1,75 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "assert.h" +#include "viint.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSwapBuffer(void* frameBufPtr) { + u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISWAPBUFFER_VIMGR, 0); + return; + } + + assert(frameBufPtr != NULL); + + if ((u32)frameBufPtr & 0x3f) { + __osError(ERR_OSVISWAPBUFFER_ADDR, 1, frameBufPtr); + return; + } +#endif + + saveMask = __osDisableInt(); + + __osViNext->framep = frameBufPtr; + __osViNext->state |= VI_STATE_BUFFER_UPDATED; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/io/viswapcontext.c b/lib/ultralib/src/io/viswapcontext.c new file mode 100644 index 0000000..2f6d2c6 --- /dev/null +++ b/lib/ultralib/src/io/viswapcontext.c @@ -0,0 +1,80 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void __osViSwapContext() { + register OSViMode* vm; + register __OSViContext* vc; + u32 origin; + u32 hStart; +#if BUILD_VERSION >= VERSION_J + u32 vStart; +#endif + u32 nomValue; + u32 field; + + field = 0; + vc = __osViNext; + vm = vc->modep; + + field = IO_READ(VI_CURRENT_REG) & 1; // field num + + origin = osVirtualToPhysical(vc->framep) + (vm->fldRegs[field].origin); + if (vc->state & VI_STATE_XSCALE_UPDATED) { + vc->x.scale |= (vm->comRegs.xScale & ~VI_SCALE_MASK); + } else { + vc->x.scale = vm->comRegs.xScale; + } + + if (vc->state & VI_STATE_YSCALE_UPDATED) { + nomValue = vm->fldRegs[field].yScale & VI_SCALE_MASK; + vc->y.scale = vc->y.factor * nomValue; + vc->y.scale |= vm->fldRegs[field].yScale & ~VI_SCALE_MASK; + } else { + vc->y.scale = vm->fldRegs[field].yScale; + } + +#if BUILD_VERSION >= VERSION_J + vStart = (vm->fldRegs[field].vStart - (__additional_scanline << 0x10)) + __additional_scanline; +#endif + hStart = vm->comRegs.hStart; + + if (vc->state & VI_STATE_BLACK) { + hStart = 0; + } + + if (vc->state & VI_STATE_REPEATLINE) { + vc->y.scale = 0; + origin = osVirtualToPhysical(vc->framep); + } + + if (vc->state & VI_STATE_FADE) { + vc->y.scale = (vc->y.offset << VI_SUBPIXEL_SH) & (VI_2_10_FPART_MASK << VI_SUBPIXEL_SH); + origin = osVirtualToPhysical(vc->framep); + } + + IO_WRITE(VI_ORIGIN_REG, origin); + IO_WRITE(VI_WIDTH_REG, vm->comRegs.width); + IO_WRITE(VI_BURST_REG, vm->comRegs.burst); + IO_WRITE(VI_V_SYNC_REG, vm->comRegs.vSync); + IO_WRITE(VI_H_SYNC_REG, vm->comRegs.hSync); + IO_WRITE(VI_LEAP_REG, vm->comRegs.leap); + IO_WRITE(VI_H_START_REG, hStart); +#if BUILD_VERSION >= VERSION_J + IO_WRITE(VI_V_START_REG, vStart); +#else + IO_WRITE(VI_V_START_REG, vm->fldRegs[field].vStart); +#endif + IO_WRITE(VI_V_BURST_REG, vm->fldRegs[field].vBurst); + IO_WRITE(VI_INTR_REG, vm->fldRegs[field].vIntr); + IO_WRITE(VI_X_SCALE_REG, vc->x.scale); + IO_WRITE(VI_Y_SCALE_REG, vc->y.scale); + IO_WRITE(VI_CONTROL_REG, vc->control); + + __osViNext = __osViCurr; + __osViCurr = vc; + *__osViNext = *__osViCurr; +} diff --git a/lib/ultralib/src/io/vitbl.c b/lib/ultralib/src/io/vitbl.c new file mode 100644 index 0000000..476036e --- /dev/null +++ b/lib/ultralib/src/io/vitbl.c @@ -0,0 +1,1740 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeTable[] = { + { OS_VI_NTSC_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_NTSC_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_PAL_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + //[0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + //[1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_MPAL_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } } }, +#if BUILD_VERSION >= VERSION_J + { OS_VI_FPAL_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } }, + { OS_VI_FPAL_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } } } +#endif +}; diff --git a/lib/ultralib/src/libc/bcmp.s b/lib/ultralib/src/libc/bcmp.s new file mode 100644 index 0000000..11db46d --- /dev/null +++ b/lib/ultralib/src/libc/bcmp.s @@ -0,0 +1,96 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +#ifdef __sgi +WEAK(bcmp, _bcmp) +#else +#define _bcmp bcmp +#endif +LEAF(_bcmp) + xor v0, a0, a1 + blt a2, 16, bytecmp + + andi v0, v0, 0x3 + negu t8, a0 + bnez v0, unalgncmp + + andi t8, t8, 0x3 + subu a2, a2, t8 + beqz t8, wordcmp + + move v0, v1 + lwl v0, 0(a0) + lwl v1, 0(a1) + addu a0, a0, t8 + addu a1, a1, t8 + bne v0, v1, cmpne + +wordcmp: + and a3, a2, ~3 + subu a2, a2, a3 + beqz a3, bytecmp + + addu a3, a3, a0 +1: + lw v0, 0(a0) + lw v1, 0(a1) + addiu a0, a0, 4 + addiu a1, a1, 4 + bne v0, v1, cmpne + bne a0, a3, 1b + + b bytecmp +unalgncmp: + negu a3, a1 + andi a3, a3, 0x3 + subu a2, a2, a3 + beqz a3, partaligncmp + + addu a3, a3, a0 + +1: + lbu v0, 0(a0) + lbu v1, 0(a1) + addiu a0, a0, 1 + addiu a1, a1, 1 + bne v0, v1, cmpne + bne a0, a3, 1b + +partaligncmp: + and a3, a2, ~3 + subu a2, a2, a3 + beqz a3, bytecmp + + addu a3, a3, a0 + +1: + lwl v0, 0(a0) + lwr v0, 3(a0) + lw v1, 0(a1) + addiu a0, a0, 4 + addiu a1, a1, 4 + bne v0, v1, cmpne + bne a0, a3, 1b + +bytecmp: + addu a3, a2, a0 + blez a2, cmpdone + +1: + lbu v0, 0(a0) + lbu v1, 0(a1) + addiu a0, a0, 1 + addiu a1, a1, 1 + bne v0, v1, cmpne + bne a0, a3, 1b + +cmpdone: + move v0, zero + jr ra +cmpne: + li v0, 1 + jr ra + +.end _bcmp diff --git a/lib/ultralib/src/libc/bcopy.s b/lib/ultralib/src/libc/bcopy.s new file mode 100644 index 0000000..216c378 --- /dev/null +++ b/lib/ultralib/src/libc/bcopy.s @@ -0,0 +1,220 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +#ifdef __sgi +WEAK(bcopy, _bcopy) +#else +#define _bcopy bcopy +#endif +LEAF(_bcopy) + move a3, a1 + beqz a2, ret + beq a0, a1, ret + blt a1, a0, goforwards + + add v0, a0, a2 + bge a1, v0, goforwards + b gobackwards + +goforwards: + + blt a2, 16, forwards_bytecopy + + andi v0, a0, 0x3 + andi v1, a1, 0x3 + beq v0, v1,forwalignable + + +forwards_bytecopy: + beqz a2, ret + addu v1, a0, a2 +99: + lb v0, 0(a0) + addiu a0, a0, 1 + sb v0, 0(a1) + addiu a1, a1, 1 + bne a0, v1, 99b +ret: + move v0, a3 + jr ra + +forwalignable: + beqz v0, forwards + beq v0, 1, forw_copy3 + beq v0, 2, forw_copy2 + + lb v0, 0(a0) + addiu a0, a0, 1 + sb v0, 0(a1) + addiu a1, a1, 1 + addiu a2, a2, -1 + b forwards + +forw_copy2: + lh v0, 0(a0) + addiu a0, a0, 2 + sh v0, 0(a1) + addiu a1, a1, 2 + addiu a2, a2, -2 + b forwards + +forw_copy3: + lb v0, 0(a0) + lh v1, 1(a0) + addiu a0, a0, 3 + sb v0, 0(a1) + sh v1, 1(a1) + addiu a1, a1, 3 + addiu a2, a2, -3 + +forwards: +forwards_32: + blt a2, 32, forwards_16 + lw v0, 0(a0) + lw v1, 4(a0) + lw t0, 8(a0) + lw t1, 12(a0) + lw t2, 16(a0) + lw t3, 20(a0) + lw ta0, 24(a0) + lw ta1, 28(a0) + addiu a0, a0, 32 + sw v0, 0(a1) + sw v1, 4(a1) + sw t0, 8(a1) + sw t1, 12(a1) + sw t2, 16(a1) + sw t3, 20(a1) + sw ta0, 24(a1) + sw ta1, 28(a1) + addiu a1, a1, 32 + addiu a2, a2, -32 + b forwards_32 + +forwards_16: + blt a2, 16, forwards_4 + lw v0, 0(a0) + lw v1, 4(a0) + lw t0, 8(a0) + lw t1, 12(a0) + addiu a0, a0, 16 + sw v0, 0(a1) + sw v1, 4(a1) + sw t0, 8(a1) + sw t1, 12(a1) + addiu a1, a1, 16 + addiu a2, a2, -16 + b forwards_16 + +forwards_4: + blt a2, 4, forwards_bytecopy + + lw v0, 0(a0) + addiu a0, a0, 4 + sw v0, 0(a1) + addiu a1, a1, 4 + addiu a2, a2, -4 + b forwards_4 + +gobackwards: + add a0, a0,a2 + add a1, a1,a2 + blt a2, 16, backwards_bytecopy + + andi v0, a0, 0x3 + andi v1, a1, 0x3 + beq v0, v1,backalignable + +backwards_bytecopy: + beqz a2, ret + addiu a0, a0, -1 + addiu a1, a1, -1 + subu v1, a0,a2 +99: + lb v0, 0(a0) + addiu a0, a0, -1 + sb v0, 0(a1) + addiu a1, a1, -1 + bne a0, v1,99b + + move v0, a3 + jr ra +backalignable: + beqz v0, backwards + beq v0, 3, back_copy3 + beq v0, 2, back_copy2 + lb v0, -1(a0) + addiu a0, a0, -1 + sb v0, -1(a1) + addiu a1, a1, -1 + addiu a2, a2, -1 + b backwards + +back_copy2: + lh v0, -2(a0) + addiu a0, a0, -2 + sh v0, -2(a1) + addiu a1, a1, -2 + addiu a2, a2, -2 + b backwards + +back_copy3: + lb v0, -1(a0) + lh v1, -3(a0) + addiu a0, a0, -3 + sb v0, -1(a1) + sh v1, -3(a1) + addiu a1, a1, -3 + addiu a2, a2, -3 + +backwards: +backwards_32: + blt a2, 32, backwards_16 + lw v0, -4(a0) + lw v1, -8(a0) + lw t0, -12(a0) + lw t1, -16(a0) + lw t2, -20(a0) + lw t3, -24(a0) + lw ta0, -28(a0) + lw ta1, -32(a0) + addiu a0, a0, -32 + sw v0, -4(a1) + sw v1, -8(a1) + sw t0, -12(a1) + sw t1, -16(a1) + sw t2, -20(a1) + sw t3, -24(a1) + sw ta0, -28(a1) + sw ta1, -32(a1) + addiu a1, a1, -32 + addiu a2, a2, -32 + b backwards_32 + +backwards_16: + blt a2, 16, backwards_4 + lw v0, -4(a0) + lw v1, -8(a0) + lw t0, -12(a0) + lw t1, -16(a0) + addiu a0, a0, -16 + sw v0, -4(a1) + sw v1, -8(a1) + sw t0, -12(a1) + sw t1, -16(a1) + addiu a1, a1, -16 + addiu a2, a2, -16 + b backwards_16 + +backwards_4: + blt a2, 4, backwards_bytecopy + lw v0, -4(a0) + addiu a0, a0, -4 + sw v0, -4(a1) + addiu a1, a1, -4 + addiu a2, a2, -4 + b backwards_4 + +.end _bcopy diff --git a/lib/ultralib/src/libc/bzero.s b/lib/ultralib/src/libc/bzero.s new file mode 100644 index 0000000..894c186 --- /dev/null +++ b/lib/ultralib/src/libc/bzero.s @@ -0,0 +1,64 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +#ifdef __sgi +WEAK(bzero, _bzero) +WEAK(blkclr, _blkclr) +#else +#define _bzero bzero +#define _blkclr blkclr +#endif +LEAF(_bzero) +XLEAF(_blkclr) + negu v1, a0 + blt a1, 12, bytezero + + andi v1, v1, 0x3 + subu a1, a1, v1 + + beqz v1, blkzero + swl zero, 0(a0) + addu a0, a0, v1 +blkzero: + and a3, a1, ~31 + subu a1, a1, a3 + beqz a3, wordzero + + addu a3, a3, a0 +1: + sw zero, 0(a0) + sw zero, 4(a0) + sw zero, 8(a0) + sw zero, 12(a0) + addiu a0, a0, 32 + sw zero, -16(a0) + sw zero, -12(a0) + sw zero, -8(a0) + sw zero, -4(a0) + bne a0, a3, 1b + +wordzero: + and a3, a1, ~3 + subu a1, a1, a3 + beqz a3, bytezero + + addu a3, a3, a0 +1: + addiu a0, a0, 4 + sw zero, -4(a0) + bne a0, a3, 1b + +bytezero: + blez a1, zerodone + #nop + addu a1, a1, a0 +1: + addiu a0, a0, 1 + sb zero, -1(a0) + bne a0, a1, 1b +zerodone: + jr ra + +.end _bzero diff --git a/lib/ultralib/src/libc/ldiv.c b/lib/ultralib/src/libc/ldiv.c new file mode 100644 index 0000000..92388d3 --- /dev/null +++ b/lib/ultralib/src/libc/ldiv.c @@ -0,0 +1,34 @@ +#include "os_version.h" +#include "stdlib.h" + +// TODO: these come from headers +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" + +ldiv_t ldiv(long num, long denom) { + ldiv_t ret; + + ret.quot = num / denom; + ret.rem = num - denom * ret.quot; + + if (ret.quot < 0 && ret.rem > 0) { + ret.quot += 1; + ret.rem -= denom; + } + + return ret; +} + +lldiv_t lldiv(long long num, long long denom) { + lldiv_t ret; + + ret.quot = num / denom; + ret.rem = num - denom * ret.quot; + + if (ret.quot < 0 && ret.rem > 0) { + ret.quot += 1; + ret.rem -= denom; + } + + return ret; +} diff --git a/lib/ultralib/src/libc/ll.c b/lib/ultralib/src/libc/ll.c new file mode 100644 index 0000000..4334b03 --- /dev/null +++ b/lib/ultralib/src/libc/ll.c @@ -0,0 +1,48 @@ +#include "PR/os.h" + +unsigned long long __ull_rshift(unsigned long long a0, unsigned long long a1) { + return a0 >> a1; +} + +unsigned long long __ull_rem(unsigned long long a0, unsigned long long a1) { + return a0 % a1; +} + +unsigned long long __ull_div(unsigned long long a0, unsigned long long a1) { + return a0 / a1; +} + +unsigned long long __ll_lshift(unsigned long long a0, unsigned long long a1) { + return a0 << a1; +} + +long long __ll_rem(unsigned long long a0, long long a1) { + return a0 % a1; +} + +long long __ll_div(long long a0, long long a1) { + return a0 / a1; +} + +unsigned long long __ll_mul(unsigned long long a0, unsigned long long a1) { + return a0 * a1; +} + +void __ull_divremi(unsigned long long* div, unsigned long long* rem, unsigned long long a2, unsigned short a3) { + *div = a2 / a3; + *rem = a2 % a3; +} + +long long __ll_mod(long long a0, long long a1) { + long long tmp = a0 % a1; + + if ((tmp < 0 && a1 > 0) || (tmp > 0 && a1 < 0)) { + tmp += a1; + } + + return tmp; +} + +long long __ll_rshift(long long a0, long long a1) { + return a0 >> a1; +} diff --git a/lib/ultralib/src/libc/llbit.c b/lib/ultralib/src/libc/llbit.c new file mode 100644 index 0000000..0680726 --- /dev/null +++ b/lib/ultralib/src/libc/llbit.c @@ -0,0 +1,52 @@ +#include "PR/os.h" +#include "PR/ultratypes.h" + +s64 __ll_bit_extract(u64* addr, unsigned int start_bit, unsigned int length) { + unsigned int words; + unsigned int lbits; + unsigned int rbits; + u64 mask; + + words = start_bit / 64; + lbits = start_bit & (64 - 1); + rbits = 64 - (lbits + length); + + addr += words; + mask = ((u64)1 << length) - 1; + mask = mask << rbits; + return (s64)((*addr & mask) >> rbits); +} + +u64 __ull_bit_extract(u64* addr, unsigned int start_bit, unsigned int length) { + unsigned int words; + unsigned int lbits; + unsigned int rbits; + u64 mask; + + words = start_bit / 64; + lbits = start_bit & (64 - 1); + rbits = 64 - (lbits + length); + addr += words; + mask = ((u64)1 << length) - 1; + mask = mask << rbits; + return (u64)((*addr & mask) >> rbits); +} + +u64 __ll_bit_insert(u64* addr, unsigned int start_bit, unsigned int length, u64 val) { + unsigned int words; + unsigned int lbits; + unsigned int rbits; + unsigned long long llval; + unsigned long long mask; + + words = start_bit / 64; + lbits = start_bit & 0x3f; + rbits = 64 - (lbits + length); + addr += words; + mask = ((u64)1 << length) - 1; + mask <<= rbits; + llval = (val << (64 - length)) >> lbits; + *addr = (*addr & ~mask) | llval; + llval = llval >> rbits; + return llval; +} diff --git a/lib/ultralib/src/libc/llcvt.c b/lib/ultralib/src/libc/llcvt.c new file mode 100644 index 0000000..74d244b --- /dev/null +++ b/lib/ultralib/src/libc/llcvt.c @@ -0,0 +1,31 @@ +long long __d_to_ll(double d) { + return d; +} + +long long __f_to_ll(float f) { + return f; +} + +unsigned long long __d_to_ull(double d) { + return d; +} + +unsigned long long __f_to_ull(float f) { + return f; +} + +double __ll_to_d(long long s) { + return s; +} + +float __ll_to_f(long long s) { + return s; +} + +double __ull_to_d(unsigned long long u) { + return u; +} + +float __ull_to_f(unsigned long long u) { + return u; +} diff --git a/lib/ultralib/src/libc/sprintf.c b/lib/ultralib/src/libc/sprintf.c new file mode 100644 index 0000000..fd95523 --- /dev/null +++ b/lib/ultralib/src/libc/sprintf.c @@ -0,0 +1,22 @@ +#include "xstdio.h" +#include "string.h" +#include "os.h" + +// TODO: this comes from a header +#ident "$Revision: 1.23 $" + +static char* proutSprintf(char* dst, const char* src, size_t count); + +int sprintf(char* dst, const char* fmt, ...) { + s32 ans; + va_list ap; + va_start(ap, fmt); + ans = _Printf(proutSprintf, dst, fmt, ap); + if (ans >= 0) { + dst[ans] = 0; + } + return ans; +} +static char* proutSprintf(char* dst, const char* src, size_t count) { + return (char*)memcpy((u8*)dst, (u8*)src, count) + count; +} diff --git a/lib/ultralib/src/libc/string.c b/lib/ultralib/src/libc/string.c new file mode 100644 index 0000000..0f01d1f --- /dev/null +++ b/lib/ultralib/src/libc/string.c @@ -0,0 +1,36 @@ +#include "PR/ultratypes.h" +#include "string.h" + +// TODO: this comes from a header +#ident "$Revision: 1.23 $" + +char* strchr(const char* s, int c) { + const char ch = c; + while (*s != ch) { + if (*s == 0) { + return NULL; + } + s++; + } + return (char*)s; +} + +size_t strlen(const char* s) { + const char* sc = s; + while (*sc != 0) { + sc++; + } + return sc - s; +} + +void* memcpy(void* s1, const void* s2, size_t n) { + char* su1 = (char*)s1; + const char* su2 = (const char*)s2; + while (n > 0) { + *su1 = *su2; + su1++; + su2++; + n--; + } + return (void*)s1; +} diff --git a/lib/ultralib/src/libc/syncprintf.c b/lib/ultralib/src/libc/syncprintf.c new file mode 100644 index 0000000..572ac73 --- /dev/null +++ b/lib/ultralib/src/libc/syncprintf.c @@ -0,0 +1,154 @@ +#include "stdarg.h" +#include "PR/os.h" +#include "PR/rdb.h" +#include "xstdio.h" +#include "PR/rcp.h" + +extern void* __printfunc; + +#if BUILD_VERSION <= VERSION_J + +#ifndef _FINALROM +extern u32 __kmc_pt_mode; + +static void* proutSyncPrintf(void* str, const char* buf, size_t n) { + size_t sent = 0; + + while (sent < n) { + sent += __osRdbSend(buf + sent, n - sent, RDB_TYPE_GtoH_PRINT); + } + return 1; +} + +static volatile unsigned int* stat = (unsigned*)0xbff08004; +static volatile unsigned int* wport = (unsigned*)0xbff08000; +static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); + +static void rmonPutchar(char c) { + u32 data; + + while (*piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + } + + while (!(*stat & 4)) { + } + + *wport = c; +} + +static void* kmc_proutSyncPrintf(void* str, const char* buf, int n) { + int i; + char c; + char* p; + char* q; + char xbuf[128]; + static int column = 0; + + p = &xbuf; + + for (i = 0; i < n; i++) { + c = *buf++; + + switch (c) { + case '\n': + *p++ = '\n'; + column = 0; + break; + case '\t': + do { + *p++ = ' '; + } while (++column % 8); + break; + default: + column++; + *p++ = c; + break; + } + + if (c == '\n' || (p - xbuf) > 100) { + rmonPutchar((p - xbuf) - 1); + + q = xbuf; + while (q != p) { + rmonPutchar(*q++); + } + p = xbuf; + } + } + if (p != xbuf) { + rmonPutchar((p - xbuf) - 1); + + q = xbuf; + while (q != p) { + rmonPutchar(*q++); + } + } + return (void*)1; +} +#endif + +void osSyncPrintf(const char* fmt, ...) { + int ans; + va_list ap; + +#ifndef _FINALROM + va_start(ap, fmt); + if (__kmc_pt_mode) { + ans = _Printf(kmc_proutSyncPrintf, NULL, fmt, ap); + } else { + ans = _Printf(proutSyncPrintf, NULL, fmt, ap); + } + va_end(ap); +#endif +} + +void rmonPrintf(const char* fmt, ...) { + int ans; + va_list ap; + +#ifndef _FINALROM + va_start(ap, fmt); + if (__kmc_pt_mode) { + ans = _Printf(kmc_proutSyncPrintf, NULL, fmt, ap); + } + va_end(ap); +#endif +} + +#else + +void __osSyncVPrintf(const char* fmt, va_list args) { + + int ans; +#ifndef _FINALROM + if (__printfunc != NULL) { + ans = _Printf(__printfunc, NULL, fmt, args); + } +#endif +} + +void osSyncPrintf(const char* fmt, ...) { + int ans; + va_list ap; + +#ifndef _FINALROM + va_start(ap, fmt); + __osSyncVPrintf(fmt, ap); + va_end(ap); +#endif +} + +void rmonPrintf(const char* fmt, ...) { + int ans; + va_list ap; + +#ifndef _FINALROM + va_start(ap, fmt); + if (__printfunc != NULL) { + ans = _Printf(__printfunc, NULL, fmt, ap); + } + va_end(ap); +#endif +} + +#endif diff --git a/lib/ultralib/src/libc/xldtob.c b/lib/ultralib/src/libc/xldtob.c new file mode 100644 index 0000000..1dc1434 --- /dev/null +++ b/lib/ultralib/src/libc/xldtob.c @@ -0,0 +1,309 @@ +#include "stdlib.h" +#include "string.h" +#include "xstdio.h" + +// TODO: these come from headers +#ident "$Revision: 1.23 $" +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" + +#define BUFF_LEN 0x20 + +static s16 _Ldunscale(s16* pex, _Pft* px); +static void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp); + +static const double pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L}; + +// float properties +#define _D0 0 +#define _DBIAS 0x3ff +#define _DLONG 1 +#define _DOFF 4 +#define _FBIAS 0x7e +#define _FOFF 7 +#define _FRND 1 +#define _LBIAS 0x3ffe +#define _LOFF 15 +// integer properties +#define _C2 1 +#define _CSIGN 1 +#define _ILONG 0 +#define _MBMAX 8 +#define NAN 2 +#define INF 1 +#define FINITE -1 +#define _DFRAC ((1 << _DOFF) - 1) +#define _DMASK (0x7fff & ~_DFRAC) +#define _DMAX ((1 << (15 - _DOFF)) - 1) +#define _DNAN (0x8000 | _DMAX << _DOFF | 1 << (_DOFF - 1)) +#define _DSIGN 0x8000 +#define _D1 1 // big-endian order +#define _D2 2 +#define _D3 3 + +#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1)) + +void _Ldtob(_Pft* px, char code) { + char buff[BUFF_LEN]; + char *p; + f64 ldval; + s16 err; + s16 nsig; + s16 xexp; + + // char unused[0x4]; + p = buff; + ldval = px->v.ld; + + if (px->prec < 0) { + px->prec = 6; + } else if (px->prec == 0 && (code == 'g' || code == 'G')) { + px->prec = 1; + } + + err = _Ldunscale(&xexp, px); + if (err > 0) { + memcpy(px->s, err == 2 ? "NaN" : "Inf", px->n1 = 3); + return; + } else if (err == 0) { + nsig = 0; + xexp = 0; + } else { + { + int i; + int n; + + if (ldval < 0) { + ldval = -ldval; + } + + // what + if ((xexp = xexp * 30103 / 100000 - 4) < 0) { + n = ALIGN(-xexp, 4), xexp = -n; + + for (i = 0; n > 0; n >>= 1, i++) { + if (n & 1) { + ldval *= pows[i]; + } + } + } else if (xexp > 0) { + f64 factor = 1; + + xexp &= ~3; + + for (n = xexp, i = 0; n > 0; n >>= 1, i++) { + if (n & 1) { + factor *= pows[i]; + } + } + + ldval /= factor; + } + } + { + int gen = px->prec + ((code == 'f') ? 10 + xexp : 6); + + if (gen > 0x13) { + gen = 0x13; + } + + for (*p++ = '0'; gen > 0 && 0 < ldval; p += 8) { + int j; + long lo = ldval; + + if ((gen -= 8) > 0) { + ldval = (ldval - lo) * 1e8; + } + + for (p += 8, j = 8; lo > 0 && --j >= 0;) { + ldiv_t qr; + qr = ldiv(lo, 10); + *--p = qr.rem + '0', lo = qr.quot; + } + + while (--j >= 0) { + *--p = '0'; + } + } + + gen = p - &buff[1]; + + for (p = &buff[1], xexp += 7; *p == '0'; p++) { + --gen, --xexp; + } + + nsig = px->prec + ((code == 'f') ? xexp + 1 : ((code == 'e' || code == 'E') ? 1 : 0)); + + if (gen < nsig) { + nsig = gen; + } + + if (nsig > 0) { + const char drop = nsig < gen && '5' <= p[nsig] ? '9' : '0'; + int n; + + for (n = nsig; p[--n] == drop;) { + --nsig; + } + + if (drop == '9') { + ++p[n]; + } + + if (n < 0) { + --p, ++nsig, ++xexp; + } + } + } + } + + _Genld(px, code, p, nsig, xexp); +} + +s16 _Ldunscale(s16* pex, _Pft* px) { + u16* ps = (u16*)px; + s16 xchar = (ps[_D0] & _DMASK) >> _DOFF; + + + if (xchar == _DMAX) { + *pex = 0; + + return (ps[_D0] & _DFRAC) || ps[_D1] || ps[_D2] || ps[_D3] ? 2 : 1; + } else if (xchar > 0) { + ps[_D0] = (ps[_D0] & ~_DMASK) | 0x3FF0; + *pex = xchar - 0x3FE; + return -1; + } else if (xchar < 0) { + return 2; + } else { + *pex = 0; + return 0; + } +} + +void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp) { + const unsigned char point = '.'; + + if (nsig <= 0) { + nsig = 1, p = "0"; + } + + if (code == 'f' || (code == 'g' || code == 'G') && xexp >= -4 && xexp < px->prec) { + xexp++; + if (code != 'f') { + if (((px->flags & 8) == 0) && nsig < px->prec) { + px->prec = nsig; + } + + if ((px->prec -= xexp) < 0) { + px->prec = 0; + } + } + + if (xexp <= 0) { + px->s[px->n1++] = '0'; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec < -xexp) { + xexp = -px->prec; + } + + px->nz1 = -xexp; + px->prec += xexp; + + if (px->prec < nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], p, px->n2 = nsig); + px->nz2 = px->prec - nsig; + } else if (nsig < xexp) { + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = xexp - nsig; + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1] = point; + px->n2++; + } + + px->nz2 = px->prec; + } else { + memcpy(&px->s[px->n1], p, xexp); + px->n1 += xexp; + nsig -= xexp; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec < nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], &p[xexp], nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + } else { + if (code == 'g' || code == 'G') { + if (nsig < px->prec) { + px->prec = nsig; + } + + if (--px->prec < 0) { + px->prec = 0; + } + + code = (code == 'g') ? 'e' : 'E'; + } + + px->s[px->n1++] = *p++; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec > 0) { + if (px->prec < --nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + + p = &px->s[px->n1]; + *p++ = code; + + if (xexp >= 0) { + *p++ = '+'; + } else { + *p++ = '-'; + xexp = -xexp; + } + + if (xexp >= 100) { + if (xexp >= 1000) { + *p++ = (xexp / 1000) + '0', xexp %= 1000; + } + *p++ = (xexp / 100) + '0', xexp %= 100; + } + *p++ = (xexp / 10) + '0', xexp %= 10; + + *p++ = xexp + '0'; + px->n2 = (size_t)p - ((size_t)px->s + px->n1); + } + + if ((px->flags & 0x14) == 0x10) { + s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2; + + if (n < px->width) { + px->nz0 = px->width - n; + } + } +} + diff --git a/lib/ultralib/src/libc/xlitob.c b/lib/ultralib/src/libc/xlitob.c new file mode 100644 index 0000000..2b27b3a --- /dev/null +++ b/lib/ultralib/src/libc/xlitob.c @@ -0,0 +1,58 @@ +#include "stdlib.h" +#include "string.h" +#include "xstdio.h" + +// TODO: these come from headers +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.23 $" + +#define BUFF_LEN 0x18 + +static char ldigs[] = "0123456789abcdef"; +static char udigs[] = "0123456789ABCDEF"; + +void _Litob(_Pft *args, char type) { + char buff[BUFF_LEN]; + const char *digs; + s32 base; + s32 i; + unsigned long long ullval; + + digs = (type == 'X') ? udigs : ldigs; + + base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16); + i = BUFF_LEN; + ullval = args->v.ll; + + if ((type == 'd' || type == 'i') && args->v.ll < 0) { + ullval = -ullval; + } + + if (ullval != 0 || args->prec != 0) { + buff[--i] = digs[ullval % base]; + } + + args->v.ll = ullval / base; + + while (args->v.ll > 0 && i > 0) { + lldiv_t qr = lldiv(args->v.ll, base); + + args->v.ll = qr.quot; + buff[--i] = digs[qr.rem]; + } + + args->n1 = BUFF_LEN - i; + + memcpy(args->s, buff + i, args->n1); + + if (args->n1 < args->prec) { + args->nz0 = args->prec - args->n1; + } + + if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { + if ((i = args->width - args->n0 - args->nz0 - args->n1) > 0) { + args->nz0 += i; + } + } +} diff --git a/lib/ultralib/src/libc/xprintf.c b/lib/ultralib/src/libc/xprintf.c new file mode 100644 index 0000000..788f42c --- /dev/null +++ b/lib/ultralib/src/libc/xprintf.c @@ -0,0 +1,257 @@ +#include "macros.h" +#include "string.h" +#include "stdarg.h" +#include "xstdio.h" + +// TODO: these come from headers +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.23 $" + +#define isdigit(x) ((x >= '0' && x <= '9')) +#define LDSIGN(x) (((unsigned short *)&(x))[0] & 0x8000) + +#define ATOI(dst, src) \ + for (dst = 0; isdigit(*src); ++src) \ + { \ + if (dst < 999) \ + dst = dst * 10 + *src - '0'; \ + } + +#define MAX_PAD ((sizeof(spaces) - 1)) +#define PAD(s, n) \ + if (0 < (n)) \ + { \ + int i, j = (n); \ + for (; 0 < j; j -= i) \ + { \ + i = MAX_PAD < (unsigned int)j ? (int)MAX_PAD : j; \ + PUT(s, i); \ + } \ + } +#define PUT(s, n) \ + if (0 < (n)) \ + { \ + if ((arg = (*prout)(arg, s, n)) != NULL) \ + x.nchar += (n); \ + else \ + return x.nchar; \ + } +static char spaces[] = " "; +static char zeroes[] = "00000000000000000000000000000000"; + +static void _Putfld(_Pft *pf, va_list *pap, char code, char *ac); + +int _Printf(outfun prout, char *arg, const char *fmt, va_list args) { + _Pft x; + + x.nchar = 0; + + while (TRUE) { + const char *s; + char c; + const char *t; + static const char fchar[] = {' ', '+', '-', '#', '0', '\0'}; + static const int fbit[] = {FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0}; + char ac[32]; + s = fmt; + + for (c = *s; c != 0 && c != '%';) { + c = *++s; + } + + PUT(fmt, s - fmt); + + if (c == 0) { + return x.nchar; + } + + fmt = ++s; + + for (x.flags = 0; (t = strchr(fchar, *s)) != NULL; s++) { + x.flags |= fbit[t - fchar]; + } + + if (*s == '*') { + x.width = va_arg(args, int); + + if (x.width < 0) { + x.width = -x.width; + x.flags |= FLAGS_MINUS; + } + s++; + } else + ATOI(x.width, s); + + + if (*s != '.') { + x.prec = -1; + } else if (*++s == '*') { + x.prec = va_arg(args, int); + ++s; + } else + for (x.prec = 0; isdigit(*s); s++) { + if (x.prec < 999) + x.prec = x.prec * 10 + *s - '0'; + } + + + x.qual = strchr("hlL", *s) ? *s++ : '\0'; + + if (x.qual == 'l' && *s == 'l') { + x.qual = 'L'; + ++s; + } + + _Putfld(&x, &args, *s, ac); + x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2; + + { + + if (!(x.flags & FLAGS_MINUS)) { + int i, j; + if (0 < (x.width)) + { + i, j = x.width; + for (; 0 < j; j -= i) + { + i = MAX_PAD < (unsigned int)j ? (int)MAX_PAD : j; + PUT(spaces, i); + } + } + } + + PUT(ac, x.n0); + PAD(zeroes, x.nz0) + + PUT(x.s, x.n1); + PAD(zeroes, x.nz1); + + PUT(x.s + x.n1, x.n2); + PAD(zeroes, x.nz2); + + if (x.flags & FLAGS_MINUS) { + PAD(spaces, x.width); + } + } + fmt = s + 1; + } + return 0; +} + +static void _Putfld(_Pft *x, va_list *args, char type, char *buff) { + x->n0 = x->nz0 = x->n1 = x->nz1 = x->n2 = + x->nz2 = 0; + + switch (type) { + case 'c': + buff[x->n0++] = va_arg(*args, int); + break; + case 'd': + case 'i': + if (x->qual == 'l') { + x->v.ll = va_arg(*args, int); + } else if (x->qual == 'L') { + x->v.ll = va_arg(*args, s64); + } else { + x->v.ll = va_arg(*args, int); + } + + if (x->qual == 'h') { + x->v.ll = (s16)x->v.ll; + } + + if (x->v.ll < 0) { + buff[x->n0++] = '-'; + } else if (x->flags & FLAGS_PLUS) { + buff[x->n0++] = '+'; + } else if (x->flags & FLAGS_SPACE) { + buff[x->n0++] = ' '; + } + + x->s = (char *)&buff[x->n0]; + + _Litob(x, type); + break; + case 'x': + case 'X': + case 'u': + case 'o': + if (x->qual == 'l') { + x->v.ll = va_arg(*args, int); + } else if (x->qual == 'L') { + x->v.ll = va_arg(*args, s64); + } else { + x->v.ll = va_arg(*args, int); + } + + if (x->qual == 'h') { + x->v.ll = (u16)x->v.ll; + } else if (x->qual == 0) { + x->v.ll = (unsigned int)x->v.ll; + } + + if (x->flags & FLAGS_HASH) { + buff[x->n0++] = '0'; + + if (type == 'x' || type == 'X') { + buff[x->n0++] = type; + } + } + + x->s = (char *)&buff[x->n0]; + _Litob(x, type); + break; + case 'e': + case 'f': + case 'g': + case 'E': + case 'G': + //... okay? + x->v.ld = x->qual == 'L' ? va_arg(*args, f64) : va_arg(*args, f64); + + if (LDSIGN(x->v.ld)) + buff[x->n0++] = '-'; + else if (x->flags & FLAGS_PLUS) + buff[x->n0++] = '+'; + else if (x->flags & FLAGS_SPACE) + buff[x->n0++] = ' '; + + x->s = (char *)&buff[x->n0]; + _Ldtob(x, type); + break; + + case 'n': + if (x->qual == 'h') { + *(va_arg(*args, u16 *)) = x->nchar; + } else if (x->qual == 'l') { + *va_arg(*args, unsigned int *) = x->nchar; + } else if (x->qual == 'L') { + *va_arg(*args, u64 *) = x->nchar; + } else { + *va_arg(*args, unsigned int *) = x->nchar; + } + + break; + case 'p': + x->v.ll = (long)va_arg(*args, void *); + x->s = (char *)&buff[x->n0]; + _Litob(x, 'x'); + break; + case 's': + x->s = va_arg(*args, char *); + x->n1 = strlen(x->s); + + if (x->prec >= 0 && x->prec < x->n1) { + x->n1 = x->prec; + } + + break; + case '%': + buff[x->n0++] = '%'; + break; + default: + buff[x->n0++] = type; + break; + } +} diff --git a/lib/ultralib/src/libc/xstdio.h b/lib/ultralib/src/libc/xstdio.h new file mode 100644 index 0000000..bd70de8 --- /dev/null +++ b/lib/ultralib/src/libc/xstdio.h @@ -0,0 +1,37 @@ +#ifndef _XSTDIO_H +#define _XSTDIO_H +#include "PR/ultratypes.h" +#include "stdlib.h" +#include "stdarg.h" + +typedef struct { + /* 0x0 */ union { + /* 0x0 */ long long ll; + /* 0x0 */ double ld; + } v; + /* 0x8 */ unsigned char* s; + /* 0xC */ int n0; + /* 0x10 */ int nz0; + /* 0x14 */ int n1; + /* 0x18 */ int nz1; + /* 0x1C */ int n2; + /* 0x20 */ int nz2; + /* 0x24 */ int prec; + /* 0x28 */ int width; + /* 0x2C */ size_t nchar; + /* 0x30 */ unsigned int flags; + /* 0x34 */ char qual; +} _Pft; + +#define FLAGS_SPACE 1 +#define FLAGS_PLUS 2 +#define FLAGS_MINUS 4 +#define FLAGS_HASH 8 +#define FLAGS_ZERO 16 +typedef char *outfun(char*,const char*,size_t); + +int _Printf(outfun prout, char *arg, const char *fmt, va_list args); +void _Litob(_Pft *args, char type); +void _Ldtob(_Pft* args, char type); + +#endif diff --git a/lib/ultralib/src/log/delay.s b/lib/ultralib/src/log/delay.s new file mode 100644 index 0000000..631781a --- /dev/null +++ b/lib/ultralib/src/log/delay.s @@ -0,0 +1,24 @@ +#include "PR/os_version.h" + +#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J +#include "sys/asm.h" +#include "sys/regdef.h" + +LEAF(osDelay) + sll t0,a0,2 + addu t0,a0 + sll t0,t0,2 + beqz a0,2f + +1: + subu t0,1 + NOP + NOP + bnez t0,1b + +2: + j ra + +END(osDelay) + +#endif diff --git a/lib/ultralib/src/log/log.c b/lib/ultralib/src/log/log.c new file mode 100644 index 0000000..85129d2 --- /dev/null +++ b/lib/ultralib/src/log/log.c @@ -0,0 +1,124 @@ +#include "stdarg.h" +#include "PR/rdb.h" +#include "PR/os.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/ultralog.h" +#include "macros.h" + +#ifndef _FINALROM + +static u32 __osLogOKtoWrite = TRUE; +static u32 __osLogInitialized = FALSE; + +static OSMesgQueue __osLogDoneMsgQ ALIGNED(8); +static OSMesg __osLogMsgBuf; + +void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr); + +void osCreateLog(OSLog* log, u32* base, s32 byteLen) { + log->magic = OS_LOG_MAGIC; + log->base = base; + log->len = byteLen; + log->startCount = osGetCount(); + log->writeOffset = 0; +} + +void osLogEvent(OSLog* log, s16 code, s16 numArgs, ...) { + va_list argPtr; + + if (numArgs > 16) { + return; + } + + va_start(argPtr, numArgs); + __osLogWrite(log, code, numArgs, argPtr); + va_end(argPtr); +} + +void osFlushLog(OSLog* log) { + s32 mask; + u32 sent; + u32 count; + u32 subcount; + u8* base; + u8 dCount[3]; + + if (!__osLogInitialized) { + osCreateMesgQueue(&__osLogDoneMsgQ, &__osLogMsgBuf, 1); + osSetEventMesg(OS_EVENT_RDB_LOG_DONE, &__osLogDoneMsgQ, 0); + __osLogInitialized = 1; + } + + mask = __osDisableInt(); + __osLogOKtoWrite = 0; + base = log->base; + count = log->writeOffset * 4; + __osRestoreInt(mask); + + while (count != 0) { + subcount = (count < 0x8000) ? count : 0x8000; + dCount[0] = (subcount & 0xFF0000) >> 0x10; + dCount[1] = (subcount & 0xFF00) >> 8; + dCount[2] = subcount & 0xFF; + + sent = 0; + while (sent < 3) { + sent += __osRdbSend(dCount + sent, 3 - sent, RDB_TYPE_GtoH_LOG_CT); + } + + sent = 0; + while (sent < subcount) { + sent += __osRdbSend(base + sent, subcount - sent, RDB_TYPE_GtoH_LOG); + } + + count -= subcount; + base += subcount; + osRecvMesg(&__osLogDoneMsgQ, NULL, OS_MESG_BLOCK); + } + mask = __osDisableInt(); + log->writeOffset = 0; + __osLogOKtoWrite = 1; + __osRestoreInt(mask); +} + +void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr) { + int i; + u32 saveEnable; + u32 buf[19]; + u32* bufp; + OSLogItem* hdr; + s32* args; + s32* dest; + int numLongs; + + bufp = buf; + hdr = buf; + args = buf + 3; + numLongs = numArgs + 3; + saveEnable = __osDisableInt(); + + hdr->magic = log->magic; + hdr->timeStamp = osGetCount() - log->startCount; + hdr->argCount = numArgs; + hdr->eventID = code; + + for (i = 0; i < numArgs; i++) { + *args++ = va_arg(argPtr, int); + } + + if (__osLogOKtoWrite) { + if ((log->writeOffset + numLongs) < (log->len >> 2)) { + dest = log->base + log->writeOffset; + for (i = 0; i < numLongs; i++) { + *dest++ = *bufp++; + } + log->writeOffset += numLongs; + } else { + __osLogOKtoWrite = FALSE; + } + } + __osRestoreInt(saveEnable); +} + +#endif diff --git a/lib/ultralib/src/log/logfloat.c b/lib/ultralib/src/log/logfloat.c new file mode 100644 index 0000000..17db739 --- /dev/null +++ b/lib/ultralib/src/log/logfloat.c @@ -0,0 +1,11 @@ +#include "os_version.h" + +#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J + +#include "ultralog.h" + +u32 osLogFloat(f32 f) { + return OS_LOG_FLOAT(f); +} + +#endif diff --git a/lib/ultralib/src/mgu/Makefile b/lib/ultralib/src/mgu/Makefile new file mode 100644 index 0000000..52c29f6 --- /dev/null +++ b/lib/ultralib/src/mgu/Makefile @@ -0,0 +1,36 @@ +# +# Makefile for the gu subdirectory +# + +include $(ROOT)/usr/include/make/PRdefs + +LCINCS = -I. -I../gu -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include +LASINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/include +LCOPTS = -G 0 -g -O + +CFILES = mtxcatl.c \ + mtxxfml.c \ + mtxxfmf.c \ + rotate.c + +ASFILES = mtxident.s \ + mtxidentf.s \ + mtxf2l.s \ + mtxl2f.s \ + mtxcatf.s \ + scale.s \ + scalef.s \ + normalize.s \ + translate.s \ + translatef.s + +OBJECTS = $(CFILES:.c=.o) $(ASFILES:.s=.o) + +default: $(OBJECTS) + +include $(COMMONRULES) + +.s.o: + cpp $(F_ROM) -DLANG_JAPANESE -E -DMIPSEB -DLANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64 -I. -I$(LIBDEPTH)\include $*.s $*.ss2 + as -mips3 -G0 -o $*.o $*.ss2 + del $*.ss? diff --git a/lib/ultralib/src/mgu/asm.h b/lib/ultralib/src/mgu/asm.h new file mode 100644 index 0000000..0c417fa --- /dev/null +++ b/lib/ultralib/src/mgu/asm.h @@ -0,0 +1,49 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO Co,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/07/06 13:21:13 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#ifndef __ASM_H__ +#define __ASM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define _MIPS_ISA_MIPS1 1 /* R2/3K */ +#define _MIPS_ISA_MIPS2 2 /* R4K/6K */ +#define _MIPS_ISA_MIPS3 3 /* R4K */ +#define _MIPS_ISA_MIPS4 4 /* TFP */ + +#define _MIPS_SIM_ABI32 1 /* MIPS MSIG calling convention */ +#define _MIPS_SIM_NABI32 2 /* MIPS new 32-bit abi */ + /* NABI32 is 64bit calling convention but 32bit type sizes) */ +#define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ + +#define LEAF(x) \ + .globl x; \ + .ent x,0; \ +x:; \ + .frame sp,0,ra + +#define END(proc) \ + .end proc + + +#ifdef __cplusplus +} +#endif + +#endif /* !__ASM_H__ */ diff --git a/lib/ultralib/src/mgu/mtxcatf.s b/lib/ultralib/src/mgu/mtxcatf.s new file mode 100644 index 0000000..4b96124 --- /dev/null +++ b/lib/ultralib/src/mgu/mtxcatf.s @@ -0,0 +1,103 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:37 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#include +#include + +/* + * void guMtxCatF(float mf[4][4], float nf[4][4], float res[4][4]) + * res = mf * nf + */ +#define FRAME_SIZE 64 + .text + .align 5 + .globl guMtxCatF + .ent guMtxCatF, 0 +guMtxCatF: + .set reorder + subu sp, FRAME_SIZE + .frame sp, FRAME_SIZE, ra + + addu v0, a0, 64 + addu v1, a1, 16 + move t2, sp +label_loop_i: + move a3, a1 +label_loop_j: + l.s ft0, 0(a0) /* mf[i][0] * nf[0][j] */ + l.s ft1, 0(a3) + mul.s ft2, ft0, ft1 + l.s ft3, 4(a0) /* + mf[i][1] * nf[1][j] */ + l.s ft4, 16(a3) + mul.s ft5, ft3, ft4 + add.s ft2, ft2, ft5 + l.s ft0, 8(a0) /* + mf[i][2] * nf[2][j] */ + l.s ft1, 32(a3) + mul.s ft5, ft0, ft1 + add.s ft2, ft2, ft5 + l.s ft3, 12(a0) /* + mf[i][3] * nf[3][j] */ + l.s ft4, 48(a3) + mul.s ft5, ft3, ft4 + add.s ft2, ft2, ft5 + + s.s ft2, 0(t2) + addu a3, a3, 4 + addu t2, t2, 4 + bne a3, v1, label_loop_j +/* loop_j_end */ + addu a0, a0, 16 + bne a0, v0, label_loop_i +/* loop_i_end */ + s.s ft2, 60(a2) + lw t0, 0(sp) + lw t1, 4(sp) + lw t2, 8(sp) + lw t3, 12(sp) + lw ta0, 16(sp) + lw ta1, 20(sp) + lw ta2, 24(sp) + lw ta3, 28(sp) + lw t8, 32(sp) + lw t9, 36(sp) + lw v0, 40(sp) + lw v1, 44(sp) + lw a0, 48(sp) + lw a1, 52(sp) + lw a3, 56(sp) + + sw t0, 0(a2) + sw t1, 4(a2) + sw t2, 8(a2) + sw t3, 12(a2) + sw ta0, 16(a2) + sw ta1, 20(a2) + sw ta2, 24(a2) + sw ta3, 28(a2) + sw t8, 32(a2) + sw t9, 36(a2) + sw v0, 40(a2) + sw v1, 44(a2) + sw a0, 48(a2) + sw a1, 52(a2) + sw a3, 56(a2) + + addu sp , FRAME_SIZE + j ra + + .end guMtxCatF + +/* end of file */ diff --git a/lib/ultralib/src/mgu/mtxcatl.c b/lib/ultralib/src/mgu/mtxcatl.c new file mode 100644 index 0000000..6054972 --- /dev/null +++ b/lib/ultralib/src/mgu/mtxcatl.c @@ -0,0 +1,44 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:37 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#include +#include "../gu/guint.h" +#include "gu.h" + +void guMtxCatL(Mtx *m, Mtx *n, Mtx *res) +{ + float mf[4][4], nf[4][4], resf[4][4]; + + guMtxL2F(mf, m); + guMtxL2F(nf, n); + + guMtxCatF(mf, nf, resf); + + guMtxF2L(resf, res); +} + +#if BUILD_VERSION < VERSION_K +void guMtxXFML(Mtx *m, float x, float y, float z, float *ox, float *oy, float *oz) +{ + float mf[4][4]; + + guMtxL2F(mf, m); + + guMtxXFMF(mf, x, y, z, ox, oy, oz); +} +#endif +/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxf2l.s b/lib/ultralib/src/mgu/mtxf2l.s new file mode 100644 index 0000000..43bbe7e --- /dev/null +++ b/lib/ultralib/src/mgu/mtxf2l.s @@ -0,0 +1,80 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:38 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#include +#include + +/* + * void guMtxF2L(float mf[4][4], Mtx *m) + * + * Input + * float mf[4][4] + * Output + * Mtx *m + */ + +#define HALF_SIZE_MTX 32 +#define MASK_LOW 0x0000FFFF +#define MASK_HIGH 0xFFFF0000 +#define MAGNIFICANT 65536.0 /* = 0x10000 */ + +#define ptr_fl a0 /* argument */ +#define ptr_mtx a1 /* argument */ +#define end_mtx t8 +#define mask_hi t9 +#define magni fv0 + + .text + .align 5 +LEAF( guMtxF2L ) + .set reorder + + li.s magni, MAGNIFICANT + li mask_hi, MASK_HIGH + addu end_mtx, ptr_mtx, HALF_SIZE_MTX +label_loop: + l.s ft0, 0(ptr_fl) /* FTOFIX32( ) */ + mul.s ft1, ft0, magni + trunc.w.s ft2, ft1 + + l.s ft3, 4(ptr_fl) /* FTOFIX32( ) */ + mul.s ft4, ft3, magni + trunc.w.s ft5, ft4 + + mfc1 t0, ft2 /* t0 <- FIXED */ + mfc1 t1, ft5 /* t1 <- FIXED */ + + and t2, t0, mask_hi /* integral part */ + srl t3, t1, 16 + or ta0, t2, t3 + sw ta0, 0(ptr_mtx) + + sll ta1, t0, 16 /* decimal part */ + and ta2, t1, MASK_LOW + or ta3, ta1, ta2 + sw ta3, HALF_SIZE_MTX(ptr_mtx) + + addu ptr_mtx, ptr_mtx, 4 + addu ptr_fl, ptr_fl, 8 + + bne ptr_mtx, end_mtx, label_loop +/* loop-end */ + + j ra + END( guMtxF2L ) + +/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxident.s b/lib/ultralib/src/mgu/mtxident.s new file mode 100644 index 0000000..a9ec491 --- /dev/null +++ b/lib/ultralib/src/mgu/mtxident.s @@ -0,0 +1,60 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:38 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ +#include +#include + +/* + * void guMtxIdent( Mtx * matrix ) + * Substitute unit matrix for matrix + * Correspond only when alignment is 4 byte boundary + * Input + * a0 = matrix + * Output + * *matrix unit matrix + */ + +#define SIZE_OF_MTX 64 /* sizeof( Mtx ) */ + .text + .align 5 +LEAF(guMtxIdent) + .set reorder + + addi t0, zero, 1 /* t0 = 0x00000001 */ + sll t1, t0, 16 /* t1 = 0x00010000 */ + + sw t1, 0(a0) /* Substitution of integers */ + sw zero, 4(a0) + sw t0, 8(a0) + sw zero, 12(a0) + sw zero, 16(a0) + sw t1, 20(a0) + sw zero, 24(a0) + sw t0, 28(a0) + + sw zero, 32(a0) /* Substitution of fractions */ + sw zero, 36(a0) + sw zero, 40(a0) + sw zero, 44(a0) + sw zero, 48(a0) + sw zero, 52(a0) + sw zero, 56(a0) + sw zero, 60(a0) + j ra + + END(guMtxIdent) + +/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxidentf.s b/lib/ultralib/src/mgu/mtxidentf.s new file mode 100644 index 0000000..a6aa779 --- /dev/null +++ b/lib/ultralib/src/mgu/mtxidentf.s @@ -0,0 +1,60 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:38 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ +#include +#include + +/* + * guMtxIdentF( float matrix[4][4] ) + * substitute unit matrix for floating point matrix + * correspond only when alignment is four byte boundary + * Input + * a0 = matrix + * Output + * *matrix unti matix + */ + .text + .align 5 +LEAF( guMtxIdentF ) + .set reorder + + li t0, 0x3f800000 /* t0 = 1.0 */ + + sw t0, 0(a0) + sw zero, 4(a0) /* line 1 */ + sw zero, 8(a0) + sw zero, 12(a0) + + sw zero, 16(a0) /* line 2 */ + sw t0, 20(a0) + sw zero, 24(a0) + sw zero, 28(a0) + + sw zero, 32(a0) /* line 3 */ + sw zero, 36(a0) + sw t0, 40(a0) + sw zero, 44(a0) + + sw zero, 48(a0) /* line 4 */ + sw zero, 52(a0) + sw zero, 56(a0) + sw t0, 60(a0) + + j ra + + END( guMtxIdentF ) + +/* End of file */ \ No newline at end of file diff --git a/lib/ultralib/src/mgu/mtxl2f.s b/lib/ultralib/src/mgu/mtxl2f.s new file mode 100644 index 0000000..897acfb --- /dev/null +++ b/lib/ultralib/src/mgu/mtxl2f.s @@ -0,0 +1,80 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:38 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#include +#include + +/* + * void guMtxF2L(float mf[4][4], Mtx *m) + * + * Input + * float mf[4][4] + * Output + * Mtx *m + */ + +#define HALF_SIZE_MTX 32 +#define MASK_LOW 0x0000FFFF +#define MASK_HIGH 0xFFFF0000 +#define MAGNIFICANT 1.5258789062500000e-05 /* ~ 1 / 0x10000 */ + +#define ptr_fl a0 /* argument */ +#define ptr_mtx a1 /* argument */ +#define end_mtx t8 +#define mask_hi t9 +#define magni fv0 + + .text + .align 5 +LEAF( guMtxL2F ) + .set reorder + li.s magni, MAGNIFICANT + li mask_hi, MASK_HIGH + addu end_mtx, ptr_mtx, HALF_SIZE_MTX +label_loop: + lw t0, 0(ptr_mtx) + lw t1, 32(ptr_mtx) + + and t2, t0, mask_hi + srl t3, t1, 16 + or ta0, t2, t3 + + sll ta1, t0, 16 + and ta2, t1, MASK_LOW + or ta3, ta1, ta2 + + mtc1 ta0, ft0 /* FIX32TOF( ) */ + cvt.s.w ft1, ft0 + mul.s ft2, ft1, magni + + mtc1 ta3, ft3 /* FIX32TOF( ) */ + cvt.s.w ft4, ft3 + mul.s ft5, ft4, magni + + s.s ft2, 0(ptr_fl) + s.s ft5, 4(ptr_fl) + + addu ptr_mtx, ptr_mtx, 4 + addu ptr_fl, ptr_fl, 8 + + bne ptr_mtx, end_mtx, label_loop +/* loop-end */ + + j ra + END( guMtxL2F ) + +/* End of file */ diff --git a/lib/ultralib/src/mgu/mtxxfmf.c b/lib/ultralib/src/mgu/mtxxfmf.c new file mode 100644 index 0000000..58c6772 --- /dev/null +++ b/lib/ultralib/src/mgu/mtxxfmf.c @@ -0,0 +1,40 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: mtxcatf.c + * Creator: hsa@sgi.com + * Create Date: Thu Nov 2 13:03:02 PST 1995 + * + */ + +#include "../gu/guint.h" + +void guMtxXFMF(float mf[4][4], float x, float y, float z, float *ox, float *oy, float *oz) +{ + *ox = mf[0][0]*x + mf[1][0]*y + mf[2][0]*z + mf[3][0]; + *oy = mf[0][1]*x + mf[1][1]*y + mf[2][1]*z + mf[3][1]; + *oz = mf[0][2]*x + mf[1][2]*y + mf[2][2]*z + mf[3][2]; +} + diff --git a/lib/ultralib/src/mgu/mtxxfml.c b/lib/ultralib/src/mgu/mtxxfml.c new file mode 100644 index 0000000..1dfa871 --- /dev/null +++ b/lib/ultralib/src/mgu/mtxxfml.c @@ -0,0 +1,41 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: mtxcatl.c + * Creator: hsa@sgi.com + * Create Date: Thu Nov 2 13:03:02 PST 1995 + * + */ + +#include "../gu/guint.h" + +void guMtxXFML(Mtx *m, float x, float y, float z, float *ox, float *oy, float *oz) +{ + float mf[4][4]; + + guMtxL2F(mf, m); + + guMtxXFMF(mf, x, y, z, ox, oy, oz); +} diff --git a/lib/ultralib/src/mgu/normalize.s b/lib/ultralib/src/mgu/normalize.s new file mode 100644 index 0000000..58b9093 --- /dev/null +++ b/lib/ultralib/src/mgu/normalize.s @@ -0,0 +1,56 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:39 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ +#include +#include + +/* + * void guNormalize(float *x, float *y, float *z) + */ + .text + .align 5 +LEAF( guNormalize ) + .set noreorder + + l.s ft0, 0(a0) /* ft0 = x */ + l.s ft1, 0(a1) /* ft1 = y */ + l.s ft2, 0(a2) /* ft2 = z */ + + mul.s ft3, ft0, ft0 /* ft3 = x*x */ + lui t0, 0x3f80 /* t0 = 1.0f */ + mul.s ft4, ft1, ft1 /* ft4 = y*y */ + add.s ft5, ft3, ft4 + mul.s ft4, ft2, ft2 /* ft4 = z*z */ + + add.s ft3, ft4, ft5 /* ft3 = x*x + y*y + z*z */ + mtc1 t0, ft5 + sqrt.s ft4, ft3 /* ft4 = sqrt(x*x + y*y + z*z) */ + + div.s ft3, ft5, ft4 /* ft3 = 1/sqrt(x*x + y*y + z*z) */ + + mul.s ft4, ft0, ft3 /* ft4 = x * 1/sqrt(x*x + y*y + z*z) */ + nop + mul.s ft5, ft1, ft3 /* ft5 = y * 1/sqrt(x*x + y*y + z*z) */ + nop + mul.s ft0, ft2, ft3 /* ft0 = z * 1/sqrt(x*x + y*y + z*z) */ + + s.s ft4, 0(a0) /* x = ft4 */ + s.s ft5, 0(a1) /* y = ft5 */ + j ra + s.s ft0, 0(a2) /* z = ft0 */ /* Use delayed slot */ + + END( guNormalize ) +/* end of file */ diff --git a/lib/ultralib/src/mgu/regdef.h b/lib/ultralib/src/mgu/regdef.h new file mode 100644 index 0000000..ac9c109 --- /dev/null +++ b/lib/ultralib/src/mgu/regdef.h @@ -0,0 +1,187 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO Co,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO Co,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/07/06 13:21:13 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ + +#ifndef __REGDEF_H__ +#define __REGDEF_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef mips + +#if (_MIPS_SIM == _MIPS_SIM_ABI32) +#define zero $0 +#define AT $at +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define t0 $8 +#define t1 $9 +#define t2 $10 +#define t3 $11 +#define t4 $12 +#define ta0 $12 +#define t5 $13 +#define ta1 $13 +#define t6 $14 +#define ta2 $14 +#define t7 $15 +#define ta3 $15 +#define s0 $16 +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 +#define t8 $24 +#define t9 $25 +#define jp $25 +#define k0 $26 +#define k1 $27 +#define gp $28 +#define sp $29 +#define fp $30 +#define s8 $30 +#define ra $31 +#endif + +#if (_MIPS_SIM == _MIPS_SIM_ABI64) +#define zero $0 +#define AT $at +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define a4 $8 +#define ta0 $8 +#define a5 $9 +#define ta1 $9 +#define a6 $10 +#define ta2 $10 +#define a7 $11 +#define ta3 $11 +#define t0 $12 +#define t1 $13 +#define t2 $14 +#define t3 $15 +#define s0 $16 +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 +#define t8 $24 +#define t9 $25 +#define jp $25 +#define k0 $26 +#define k1 $27 +#define gp $28 +#define sp $29 +#define fp $30 +#define s8 $30 +#define ra $31 +#endif + +#if (_MIPS_SIM == _MIPS_SIM_ABI32) +#define fv0 $f0 +#define fv0f $f1 +#define fv1 $f2 +#define fv1f $f3 +#define fa0 $f12 +#define fa0f $f13 +#define fa1 $f14 +#define fa1f $f15 +#define ft0 $f4 +#define ft0f $f5 +#define ft1 $f6 +#define ft1f $f7 +#define ft2 $f8 +#define ft2f $f9 +#define ft3 $f10 +#define ft3f $f11 +#define ft4 $f16 +#define ft4f $f17 +#define ft5 $f18 +#define ft5f $f19 +#define fs0 $f20 +#define fs0f $f21 +#define fs1 $f22 +#define fs1f $f23 +#define fs2 $f24 +#define fs2f $f25 +#define fs3 $f26 +#define fs3f $f27 +#define fs4 $f28 +#define fs4f $f29 +#define fs5 $f30 +#define fs5f $f31 +#endif + +#if (_MIPS_SIM == _MIPS_SIM_ABI64) +#define fv0 $f0 +#define fv1 $f2 +#define fa0 $f12 +#define fa1 $f13 +#define fa2 $f14 +#define fa3 $f15 +#define fa4 $f16 +#define fa5 $f17 +#define fa6 $f18 +#define fa7 $f19 +#define ft0 $f4 +#define ft1 $f5 +#define ft2 $f6 +#define ft3 $f7 +#define ft4 $f8 +#define ft5 $f9 +#define ft6 $f10 +#define ft7 $f11 +#define ft8 $f20 +#define ft9 $f21 +#define ft10 $f22 +#define ft11 $f23 +#define ft12 $f1 +#define ft13 $f3 +#define fs0 $f24 +#define fs1 $f25 +#define fs2 $f26 +#define fs3 $f27 +#define fs4 $f28 +#define fs5 $f29 +#define fs6 $f30 +#define fs7 $f31 +#endif + +#define fcr31 $31 + +#endif /* mips */ + +#ifdef __cplusplus +} +#endif + +#endif /* !__REGDEF_H__ */ diff --git a/lib/ultralib/src/mgu/rotate.c b/lib/ultralib/src/mgu/rotate.c new file mode 100644 index 0000000..1c09bd8 --- /dev/null +++ b/lib/ultralib/src/mgu/rotate.c @@ -0,0 +1,73 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "../gu/guint.h" +#include "gu.h" +#include "os_version.h" + +void guRotateF(float mf[4][4], float a, float x, float y, float z) +{ + static float dtor = 3.1415926 / 180.0; + float sine; + float cosine; + float ab, bc, ca, t; +#if BUILD_VERSION >= VERSION_K + float xxsine; + float yxsine; + float zxsine; +#endif + + guNormalize(&x, &y, &z); + a *= dtor; + sine = sinf(a); + cosine = cosf(a); + t = (1-cosine); + ab = x*y*t; + bc = y*z*t; + ca = z*x*t; + + guMtxIdentF(mf); + +#if BUILD_VERSION >= VERSION_K + xxsine = x * sine; + yxsine = y * sine; + zxsine = z * sine; +#else + #define xxsine (x * sine) + #define yxsine (y * sine) + #define zxsine (z * sine) +#endif + + t = x*x; + mf[0][0] = t+cosine*(1-t); + mf[2][1] = bc-xxsine; + mf[1][2] = bc+xxsine; + + t = y*y; + mf[1][1] = t+cosine*(1-t); + mf[2][0] = ca+yxsine; + mf[0][2] = ca-yxsine; + + t = z*z; + mf[2][2] = t+cosine*(1-t); + mf[1][0] = ab-zxsine; + mf[0][1] = ab+zxsine; +} + +void guRotate(Mtx *m, float a, float x, float y, float z) +{ + Matrix mf; + + guRotateF(mf, a, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/lib/ultralib/src/mgu/scale.s b/lib/ultralib/src/mgu/scale.s new file mode 100644 index 0000000..01bc290 --- /dev/null +++ b/lib/ultralib/src/mgu/scale.s @@ -0,0 +1,85 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:40 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ +#include +#include + +/* + * FTOFIX32 (float to fix32) + * a: input + * t: output + * ft0 : (float)0x00010000 + * ft1, ft2, ft3, t0 : work reg + */ +#define FTOFIX32(a, t) \ + mtc1 a, ft1 ; \ + mul.s ft2, ft1, ft0 ; \ + trunc.w.s ft3, ft2, t0 ; \ + mfc1 t, ft3 ; + +/* + void guScale(Mtx *m, float x, float y, float z) + m: a0 + x: a1 + y: a2 + z a3 + */ +#define SIZE_OF_MTX 64 /* sizeof( Mtx ) */ +#define FLOAT_0x10000 6.5536e+04 /* (float)0x00010000) */ + + .text + .align 5 +LEAF( guScale ) + .set reorder + + li.s ft0, FLOAT_0x10000 /* (float)0x00010000 */ + + FTOFIX32(a1, t1) /* t1 = FTOFIX32(x) */ + srl t2, t1, 16 + sll t0, t2, 16 + sw t0, 0(a0) /* t0 = x integral part */ + sll t2, t1, 16 + sw t2, 32(a0) /* t2 = x decimal part */ + + FTOFIX32(a2, t1) /* t1 = FTOFIX32(y) */ + srl t0, t1, 16 + sw t0, 8(a0) /* t0 = y integral part */ + andi t2, t1, 0xffff + sw t2, 40(a0) /* t2 = y decimal part */ + + FTOFIX32(a3, t1) /* t1 = FTOFIX32(z) */ + srl t2, t1, 16 + sll t0, t2, 16 + sw t0, 20(a0) /* t0 = z integral part */ + sll t2, t1, 16 + sw t2, 52(a0) /* t2 = z decimal part */ + + li t0, 1 /* t0 = 1.0 integral part */ + sw t0, 28(a0) + + sw zero, 4(a0) + sw zero, 12(a0) + sw zero, 16(a0) + sw zero, 24(a0) + sw zero, 36(a0) + sw zero, 44(a0) + sw zero, 48(a0) + sw zero, 56(a0) + sw zero, 60(a0) + j ra + + END( guScale ) +/* end of file */ diff --git a/lib/ultralib/src/mgu/scalef.s b/lib/ultralib/src/mgu/scalef.s new file mode 100644 index 0000000..b27d1e3 --- /dev/null +++ b/lib/ultralib/src/mgu/scalef.s @@ -0,0 +1,57 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:40 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ +#include +#include + +/* + * void guScaleF(float m[4][4], float x, float y, float z) + * m: a0 + * x: a1 + * y: a2 + * z: a3 + */ + .text + .align 5 +LEAF( guScaleF ) + .set reorder + + sw a1, 0(a0) + sw zero, 4(a0) /* line 1 */ + sw zero, 8(a0) + sw zero, 12(a0) + + sw zero, 16(a0) /* line 2 */ + sw a2, 20(a0) + sw zero, 24(a0) + sw zero, 28(a0) + + sw zero, 32(a0) /* line 3 */ + sw zero, 36(a0) + sw a3, 40(a0) + sw zero, 44(a0) + + li t0, 0x3f800000 /* t0 = 1.0 */ + sw zero, 48(a0) /* line 4 */ + sw zero, 52(a0) + sw zero, 56(a0) + sw t0, 60(a0) + + j ra + + END( guScaleF ) + +/* End of file */ diff --git a/lib/ultralib/src/mgu/translate.s b/lib/ultralib/src/mgu/translate.s new file mode 100644 index 0000000..472fd8c --- /dev/null +++ b/lib/ultralib/src/mgu/translate.s @@ -0,0 +1,101 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:40 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ +#include +#include + +/* + void guTranslate(Mtx *m, float x, float y, float z) + m: a0 + x: a1 + y: a2 + z a3 + */ + +#define SIZE_OF_MTX 64 /* sizeof( Mtx ) */ +#define FLOAT_0x10000 6.5536e+04 /* (float)0x00010000) */ + + .text + .align 5 +LEAF( guTranslate ) + .set reorder + + li.s ft0, FLOAT_0x10000 /* (float)0x00010000 */ + + mtc1 a1, ft1 + mul.s ft2, ft1, ft0 + trunc.w.s ft3, ft2 + mfc1 t1, ft3 /* t1 = FTOFIX32(x) */ + + mtc1 a2, ft1 + mul.s ft2, ft1, ft0 + trunc.w.s ft3, ft2 + mfc1 t3, ft3 /* t3 = FTOFIX32(y) */ + + /* Save t1 and t3 values until fraction process is finished! */ + + srl t2, t1, 16 /* x integeral part for t0 interger */ + sll t0, t2, 16 + srl t2, t3, 16 /* y integral part for t2 fraction */ + or t0, t0, t2 /* Compose in t0 */ + sw t0, 24(a0) + + sll t0,t1,16 /* x fraction part for t0 interger */ + sll t2,t3,16 + srl t2,t2,16 /* y fraction part for t2 fraction */ + or t0,t0,t2 /* Compose in t0 */ + sw t0,24+32(a0) + + + mtc1 a3, ft1 + mul.s ft2, ft1, ft0 + trunc.w.s ft3, ft2 + mfc1 t1, ft3 /* t1 = FTOFIX32(z) */ + + srl t2,t1,16 + sll t0,t2,16 /* z integral part for t0 integer */ + addiu t0,t0,1 /* enter 0x0001 in t0 fraction */ + sw t0,28(a0) + + sll t2,t1,16 /* z fraction part for t2 integer */ + sw t2,28+32(a0) + + sw zero, 0(a0) + sw zero, 4(a0) + sw zero, 8(a0) + sw zero, 12(a0) + sw zero, 16(a0) + sw zero, 20(a0) + sw zero, 0+32(a0) + sw zero, 4+32(a0) + sw zero, 8+32(a0) + sw zero, 12+32(a0) + sw zero, 16+32(a0) + sw zero, 20+32(a0) + + lui t0,0x0001 + ori t0,0x0000 + sw t0,0(a0) + sw t0,20(a0) + + lui t0,0x0000 + ori t0,0x0001 + sw t0,8(a0) + + j ra + + END( guTranslate ) +/* end of file */ diff --git a/lib/ultralib/src/mgu/translatef.s b/lib/ultralib/src/mgu/translatef.s new file mode 100644 index 0000000..47d14bd --- /dev/null +++ b/lib/ultralib/src/mgu/translatef.s @@ -0,0 +1,58 @@ +/************************************************************************ + Copyright (C) 1998,1999 NINTENDO CO,Ltd, + Copyright (C) 1998,1999 MONEGI CORPORATION, + All Rights Reserved +This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. +and it is not to be reproduced, published, disclosed to others, copied, +adapted, distributed, or displayed without the prior authorization of +NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed +this Notice on all copies of the program, including partial copies or +modified versions thereof. +*************************************************************************/ +/************************************************************************ + $Date: 1999/06/16 09:15:41 $ + $Revision: 1.1 $ + $Author: doseki $ +************************************************************************/ +#include +#include + +/* + * void guTranslateF(float m[4][4], float x, float y, float z) + * m: a0 + * x: a1 + * y: a2 + * z: a3 + */ + .text + .align 5 +LEAF( guTranslateF ) + .set reorder + + li t0,0x3f800000 /* t0 = 1.0 */ + + sw t0, 0(a0) + sw zero, 4(a0) /* line 1 */ + sw zero, 8(a0) + sw zero, 12(a0) + + sw zero, 16(a0) /* line 2 */ + sw t0, 20(a0) + sw zero, 24(a0) + sw zero, 28(a0) + + sw zero, 32(a0) /* line 3 */ + sw zero, 36(a0) + sw t0, 40(a0) + sw zero, 44(a0) + + sw a1, 48(a0) /* line 4 */ + sw a2, 52(a0) + sw a3, 56(a0) + sw t0, 60(a0) + + j ra + + END( guTranslateF ) + +/* End of file */ diff --git a/lib/ultralib/src/monutil.s b/lib/ultralib/src/monutil.s new file mode 100644 index 0000000..e5974bd --- /dev/null +++ b/lib/ultralib/src/monutil.s @@ -0,0 +1,188 @@ +#ifndef _FINALROM +#include "asm.h" +#include "sgidefs.h" +#include "regdef.h" +#include "sgidefs.h" +#include "PR/R4300.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#define EXC(code) (EXC_##code >> CAUSE_EXCSHIFT) + +.text + +LEAF(__isExpJP); .set noreorder + j __isExp + nop + sw k0, -0x10(sp) + la k0, __isExp + jr k0 + nop +.set reorder +END(__isExpJP) + +LEAF(__isExp); .set noreorder + sw k0, -0x10(sp) + sw k1, -8(sp) + + mfc0 k0, C0_CAUSE + nop + andi k0, k0, CAUSE_EXCMASK + bnez k0, non_stop + + nop + mfc0 k0, C0_CAUSE + nop + andi k0, k0, CAUSE_IP7 + beqz k0, throw_os_exception + nop + j go_monitor + nop +non_stop: + sra k0, k0, CAUSE_EXCSHIFT + li k1, EXC(BREAK) + bne k0, k1, non_bp + nop + j go_monitor + nop + +non_bp: + li k1, EXC(RADE) + bne k0, k1, non_adrs_store_exp + nop + j go_monitor + nop +non_adrs_store_exp: + li k1, EXC(WADE) + bne k0, k1, non_adrs_load_exp + nop + j go_monitor + nop +non_adrs_load_exp: + li k1, EXC(IBE) + bne k0, k1, non_bus_code_exp + nop + j go_monitor + nop +non_bus_code_exp: + li k1, EXC(DBE) + bne k0, k1, non_bus_data_exp + nop + j go_monitor + nop +non_bus_data_exp: + li k1, EXC(MOD) + bne k0, k1, non_tlb_mod + nop + j go_monitor + nop +non_tlb_mod: + li k1, EXC(RMISS) + bne k0, k1, non_tlb_load + nop + j go_monitor + nop +non_tlb_load: + li k1, EXC(WMISS) + bne k0, k1, non_tlb_store + nop + j go_monitor + nop +non_tlb_store: + li k1, EXC(II) + bne k0, k1, non_resv + nop + j go_monitor + nop + +non_resv: + lw k1, -8(sp) + +throw_os_exception: + j ramOldVector + nop + + + + + + + + + +go_monitor: + move k0, sp + addiu sp, sp, -0x200 + sw k0, 0x78(sp) + lw k1, -8(k0) + sw k1, 0x70(sp) + lw k1, -0x10(k0) + sw k1, 0x6c(sp) + nop +w: + lui k0, (0xA4600010 >> 16) + lw k0, (0xA4600010 & 0xFFFF)(k0) /* PI_STATUS_REG */ + nop + andi k0, k0, 3 /* (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY) */ + bnez k0, w + nop + la k0, 0xBFF00050 + jr k0 + nop +.set reorder +END(__isExp) + + +LEAF(MonitorInitBreak); .set noreorder + nop + nop +INIT_BREAK_POSITION: + break 4 + nop + nop + nop + jr ra + nop +.set reorder +END(MonitorInitBreak) + +#endif diff --git a/lib/ultralib/src/os/ackramromread.c b/lib/ultralib/src/os/ackramromread.c new file mode 100644 index 0000000..3de1f6f --- /dev/null +++ b/lib/ultralib/src/os/ackramromread.c @@ -0,0 +1,16 @@ +#include "PR/os_internal.h" +#include "PR/os_version.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +void osAckRamromRead() { +} diff --git a/lib/ultralib/src/os/ackramromwrite.c b/lib/ultralib/src/os/ackramromwrite.c new file mode 100644 index 0000000..a99e951 --- /dev/null +++ b/lib/ultralib/src/os/ackramromwrite.c @@ -0,0 +1,15 @@ +#include "PR/os_internal.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +void osAckRamromWrite() { +} diff --git a/lib/ultralib/src/os/afterprenmi.c b/lib/ultralib/src/os/afterprenmi.c new file mode 100644 index 0000000..03b5b24 --- /dev/null +++ b/lib/ultralib/src/os/afterprenmi.c @@ -0,0 +1,5 @@ +#include "PR/os_internal.h" + +s32 osAfterPreNMI() { + return __osSpSetPc(0); +} diff --git a/lib/ultralib/src/os/atomic.c b/lib/ultralib/src/os/atomic.c new file mode 100644 index 0000000..a0bd8fe --- /dev/null +++ b/lib/ultralib/src/os/atomic.c @@ -0,0 +1,16 @@ +#include "PR/os_internal.h" + +int __osAtomicDec(unsigned int* p) { + u32 mask; + int result; + + mask = __osDisableInt(); + if (*p) { + (*p)--; + result = 1; + } else { + result = 0; + } + __osRestoreInt(mask); + return result; +} diff --git a/lib/ultralib/src/os/createmesgqueue.c b/lib/ultralib/src/os/createmesgqueue.c new file mode 100644 index 0000000..5c92f04 --- /dev/null +++ b/lib/ultralib/src/os/createmesgqueue.c @@ -0,0 +1,20 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" + +void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 msgCount) { + +#ifdef _DEBUG + if (msgCount <= 0) { + __osError(ERR_OSCREATEMESGQUEUE, 1, msgCount); + return; + } +#endif + + mq->mtqueue = (OSThread*)&__osThreadTail.next; + mq->fullqueue = (OSThread*)&__osThreadTail.next; + mq->validCount = 0; + mq->first = 0; + mq->msgCount = msgCount; + mq->msg = msg; +} diff --git a/lib/ultralib/src/os/createthread.c b/lib/ultralib/src/os/createthread.c new file mode 100644 index 0000000..7c17834 --- /dev/null +++ b/lib/ultralib/src/os/createthread.c @@ -0,0 +1,54 @@ +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/ultraerror.h" +#include "osint.h" + +extern __OSThreadprofile_s thprof[]; + +void osCreateThread(OSThread* t, OSId id, void (*entry)(void*), void* arg, void* sp, OSPri p) { + register u32 saveMask; + OSIntMask mask; + +#ifdef _DEBUG + if ((u32)sp & 0x7) { + __osError(ERR_OSCREATETHREAD_SP, 1, sp); + return; + } + + if ((p < OS_PRIORITY_IDLE) || (p > OS_PRIORITY_MAX)) { + __osError(ERR_OSCREATETHREAD_PRI, 1, p); + return; + } +#endif + + t->id = id; + t->priority = p; + t->next = NULL; + t->queue = NULL; + t->context.pc = (u32)entry; + t->context.a0 = (s64)(s32)arg; // Double cast gets rid of compiler warning + t->context.sp = (s64)(s32)sp - 16; + t->context.ra = (u64)__osCleanupThread; + mask = OS_IM_ALL; + t->context.sr = (mask & (SR_IMASK | SR_IE)) | SR_EXL; + t->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT; + t->context.fpcsr = (u32)(FPCSR_FS | FPCSR_EV); + t->fp = 0; + t->state = OS_STATE_STOPPED; + t->flags = 0; + +#if BUILD_VERSION >= VERSION_K +#ifndef _FINALROM + if (id < THPROF_IDMAX) { + t->thprof = &thprof[id]; + } else { + t->thprof = &thprof[THPROF_IDMAX - 1]; + } +#endif +#endif + + saveMask = __osDisableInt(); + t->tlnext = __osActiveQueue; + __osActiveQueue = t; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/destroythread.c b/lib/ultralib/src/os/destroythread.c new file mode 100644 index 0000000..c668869 --- /dev/null +++ b/lib/ultralib/src/os/destroythread.c @@ -0,0 +1,49 @@ +#include "PR/os_internal.h" +#include "osint.h" + +void osDestroyThread(OSThread* t) { + register u32 saveMask; + register OSThread* pred; + register OSThread* succ; + + saveMask = __osDisableInt(); + + if (t == NULL) { + t = __osRunningThread; + } else if (t->state != OS_STATE_STOPPED) { + __osDequeueThread(t->queue, t); + } + + if (__osActiveQueue == t) { + __osActiveQueue = __osActiveQueue->tlnext; + } else { +#if BUILD_VERSION >= VERSION_J || !defined(__GNUC__) + pred = __osActiveQueue; + while (pred->priority != -1) { + succ = pred->tlnext; + if (succ == t) { + pred->tlnext = t->tlnext; + break; + } + pred = succ; + } +#else + pred = __osActiveQueue; + succ = pred->tlnext; + while (succ != NULL) { + if (succ == t) { + pred->tlnext = t->tlnext; + break; + } + pred = succ; + succ = pred->tlnext; + } +#endif + } + + if (t == __osRunningThread) { + __osDispatchThread(); + } + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/exceptasm.h b/lib/ultralib/src/os/exceptasm.h new file mode 100644 index 0000000..0d7def5 --- /dev/null +++ b/lib/ultralib/src/os/exceptasm.h @@ -0,0 +1,29 @@ +#ifndef _EXCEPTASM_H +#define _EXCEPTASM_H + +#include "PR/os_version.h" + +#define MESG(type) (type << 3) + +#define MQ_MTQUEUE 0 +#define MQ_FULLQUEUE 4 +#define MQ_VALIDCOUNT 8 +#define MQ_FIRST 12 +#define MQ_MSGCOUNT 16 +#define MQ_MSG 20 + +#define OS_EVENTSTATE_MESSAGE_QUEUE 0 +#define OS_EVENTSTATE_MESSAGE 4 + +/* __osHwInt struct member offsets */ +#define HWINTR_CALLBACK 0x00 +#define HWINTR_SP 0x04 + +/* __osHwInt struct size */ +#if BUILD_VERSION >= VERSION_J +#define HWINTR_SIZE 0x8 +#else +#define HWINTR_SIZE 0x4 +#endif + +#endif diff --git a/lib/ultralib/src/os/exceptasm.s b/lib/ultralib/src/os/exceptasm.s new file mode 100644 index 0000000..b7699a8 --- /dev/null +++ b/lib/ultralib/src/os/exceptasm.s @@ -0,0 +1,1069 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" +#include "PR/os.h" +#include "PR/rcp.h" +#include "PR/rdb.h" +#include "exceptasm.h" +#include "threadasm.h" +#include "PR/os_version.h" +#define KMC_CODE_ENTRY 0xBFF00014 +#define KMC_WPORT 0xBFF08000 +#define KMC_STAT 0xBFF08004 + +.rdata + +#define REDISPATCH 0x00 +#define SW1 0x04 +#define SW2 0x08 +#define RCP 0x0c +#define CART 0x10 +#define PRENMI 0x14 +#define IP6_HDLR 0x18 +#define IP7_HDLR 0x1c +#define COUNTER 0x20 + +__osIntOffTable: + .byte REDISPATCH + .byte PRENMI + .byte IP6_HDLR + .byte IP6_HDLR + .byte IP7_HDLR + .byte IP7_HDLR + .byte IP7_HDLR + .byte IP7_HDLR + .byte COUNTER + .byte COUNTER + .byte COUNTER + .byte COUNTER + .byte COUNTER + .byte COUNTER + .byte COUNTER + .byte COUNTER + .byte REDISPATCH + .byte SW1 + .byte SW2 + .byte SW2 + .byte RCP + .byte RCP + .byte RCP + .byte RCP + .byte CART + .byte CART + .byte CART + .byte CART + .byte CART + .byte CART + .byte CART + .byte CART + +__osIntTable: + .word redispatch, sw1, sw2, rcp, cart, prenmi, IP6_Hdlr, IP7_Hdlr, counter + +#ifndef _FINALROM +EXPORT(__osCauseTable_pt) + .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 + .byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 +#endif + +.data + +#if BUILD_VERSION >= VERSION_J +EXPORT(__osHwIntTable) + .word 0, 0 + .word 0, 0 + .word 0, 0 + .word 0, 0 + .word 0, 0 + +EXPORT(__osPiIntTable) + .word 0, 0 +#else +EXPORT(__osHwIntTable) + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 +#endif + +#ifndef _FINALROM +__osRdb_DbgRead_Ct: + .word 0 + +__osRdb_Mesg: + .word 0 + +__os_Kdebug_Pkt: + .word 0 + +#if BUILD_VERSION >= VERSION_K +__osPreviousThread: + .word 0 +#endif +#endif + +.text + +LEAF(__osExceptionPreamble) + la k0, __osException + jr k0 +END(__osExceptionPreamble) + +#ifndef _FINALROM +LEAF(__ptExceptionPreamble) +.set noreorder + sw k0, -0x10(sp) + b pt_next + lui k0, %hi(__ptException) + nop + nop +pt_next: + addiu k0, k0, %lo(__ptException) + jr k0 + nop +.set reorder +END(__ptExceptionPreamble) + +LEAF(__ptException) +.set noreorder + mfc0 k0, C0_CAUSE + andi k0, k0, 0x7c + bnez k0, pt_not_Int + srl k0, k0, 2 + mfc0 k0, C0_CAUSE + nop + andi k0, k0, CAUSE_IP7 + beqz k0, __osException + nop + j pt_break + nop +pt_not_Int: + sw k1, -8(sp) + /* determine if the pt exception handler should deal with this cause */ + la k1, __osCauseTable_pt + add k1, k1, k0 + lbu k0, (k1) + beqz k0, __osException + nop +pt_break: +pi_ok_loop: + lw k0, PHYS_TO_K1(PI_STATUS_REG) + nop + andi k0, k0, (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY) + bnez k0, pi_ok_loop + nop + lw k0, KMC_STAT + nop + andi k0, k0, 8 + bnez k0, pt_prof + li k0, KMC_CODE_ENTRY + lw k1, -8(sp) + jr k0 + addiu sp, sp, -0x60 +pt_prof: + mfc0 k0, C0_EPC + /* the following two ways is a (necessarily) messy way to write "sw k0, KMC_WPORT" without using at */ + lui k1, (KMC_WPORT >> 16 + 1) + sw k0, -(KMC_WPORT & 0xFFFF)(k1) + lw k1, -8(sp) + lw k0, -0x10(sp) + eret + nop +.set reorder +END(__ptException) +#endif + +LEAF(__osException) + la k0, __osThreadSave + /* save AT */ +.set noat + sd $1, THREAD_GP1(k0); +.set at + /* save sr */ +STAY2(mfc0 k1, C0_SR) + sw k1, THREAD_SR(k0) + /* clear interrupts */ + and k1, k1, -4 +STAY2(mtc0 k1, C0_SR) + /* save other regs */ + sd $8, THREAD_GP8(k0) + sd $9, THREAD_GP9(k0) + sd $10, THREAD_GP10(k0) + /* say fp has not been used */ + sw zero, THREAD_FP(k0) + /* this instruction is useless, leftover because of bad placement of an ifdef for the debug version */ +STAY2(mfc0 t0, C0_CAUSE) +#ifndef _FINALROM + lw t2, __kmc_pt_mode + bnez t2, skip_kmc_mode + andi t1, t0, 0x7c + li t2, 0 + bne t1, t2, savecontext + and t1, k1, t0 + andi t2, t1, CAUSE_IP7 + beqz t2, notIP7 + /* clear rdb write interrupt */ + la t1, RDB_WRITE_INTR_REG + sw zero, (t1) +IP7check: +STAY2(mfc0 t0, C0_CAUSE) + andi t0, t0, CAUSE_IP7 + bne zero, t0, IP7check + la t2, RDB_BASE_REG + lw t0, (t2) + srl t1, t0, 0x1a + andi t1, t1, 0x3f + li t2, RDB_TYPE_HtoG_DATA + beq t1, t2, HandData + li t2, RDB_TYPE_HtoG_DEBUG + beq t1, t2, HandDbg + li t2, RDB_TYPE_HtoG_KDEBUG + beq t1, t2, HandKDebug + li t2, RDB_TYPE_HtoG_DEBUG_CT + beq t1, t2, DbgCnt + li t2, RDB_TYPE_HtoG_DATA_DONE + beq t1, t2, DataRead + li t2, RDB_TYPE_HtoG_LOG_DONE + beq t1, t2, LogRead + li t2, RDB_TYPE_HtoG_REQ_RAMROM + beq t1, t2, ReqRamrom + li t2, RDB_TYPE_HtoG_FREE_RAMROM + beq t1, t2, FreeRamrom + li t2, RDB_TYPE_HtoG_PROF_SIGNAL + beq t1, t2, SignalProf + b rdbout +SignalProf: + li t2, 1 + srl t1, t0, 0x10 + andi t1, t1, 0xff + beq t1, t2, AckProf + li t2, 0xa8 + sw t2, __osRdb_Mesg + b savecontext +AckProf: + li t2, 0xb0 + sw t2, __osRdb_Mesg + b savecontext +HandKDebug: + sw t0, __os_Kdebug_Pkt + b savecontext +DbgCnt: + li t2, 0xffffff + and t1, t0, t2 + sw t1, __osRdb_DbgRead_Ct + b rdbout +DataRead: + li t2, 0x88 + sw t2, __osRdb_Mesg + b savecontext +LogRead: + li t2, 0x80 + sw t2, __osRdb_Mesg + b savecontext +ReqRamrom: + li t2, 0x90 + sw t2, __osRdb_Mesg + b savecontext +FreeRamrom: + li t2, 0x98 + sw t2, __osRdb_Mesg + b savecontext +HandData: + srl t1, t0, 0x18 + andi t1, t1, 3 + beq zero, t1, rdbout + lw t2, __osRdb_Read_Data_Ct + subu t2, t2, t1 + sw t2, __osRdb_Read_Data_Ct + sd t3, THREAD_GP11(k0) + lw t3, __osRdb_Read_Data_Buf + srl t2, t0, 0x10 + andi t2, t2, 0xff + sb t2, (t3) + addi t3, t3, 1 + addi t1, t1, -1 + beq zero, t1, doneData + srl t2, t0, 8 + andi t2, t2, 0xff + sb t2, (t3) + addi t3, t3, 1 + addi t1, t1, -1 + beq zero, t1, doneData + andi t0, t0, 0xff + sb t0, (t3) + addi t3, t3, 1 +doneData: + sw t3, __osRdb_Read_Data_Buf + ld t3, THREAD_GP11(k0) + lw t2, __osRdb_Read_Data_Ct + bne zero, t2, rdbout + li t2, 0x78 + sw t2, __osRdb_Mesg + b savecontext +HandDbg: + srl t1, t0, 0x18 + andi t1, t1, 3 + beq zero, t1, rdbout + lw t2, __osRdb_DbgRead_Ct + subu t2, t2, t1 + sw t2, __osRdb_DbgRead_Ct + sd t3, THREAD_GP11(k0) + lw t3, __osRdb_DbgRead_Buf + bne zero, t3, 1f + ld t3, THREAD_GP11(k0) + b rdbout +1: + srl t2, t0, 0x10 + andi t2, t2, 0xff + sb t2, (t3) + addi t3, t3, 1 + addi t1, t1, -1 + beq zero, t1, doneDbg + srl t2, t0, 8 + andi t2, t2, 0xff + sb t2, (t3) + addi t3, t3, 1 + addi t1, t1, -1 + beq zero, t1, doneDbg + andi t0, t0, 0xff + sb t0, (t3) + addi t3, t3, 1 +doneDbg: + sw t3, __osRdb_DbgRead_Buf + ld t3, THREAD_GP11(k0) + lw t2, __osRdb_DbgRead_Ct + bne zero, t2, rdbout + li t2, 0xa0 + sw t2, __osRdb_Mesg + b savecontext +notIP7: + andi t2, t1, CAUSE_IP6 + beqz t2, savecontext + /* clear rdb read interrupt */ + la t1, RDB_READ_INTR_REG + sw zero, (t1) + lw t2, __osRdb_IP6_Ct + bnez t2, 2f + li t2, 1 + sw t2, __osRdb_IP6_Empty + b rdbout +2: + addi t2, t2, -1 + sw t2, __osRdb_IP6_Ct + lw t0, __osRdb_IP6_Data + lw t1, __osRdb_IP6_CurSend + sll t2, t1, 2 + add t0, t2, t0 + lw t2, (t0) + addi t1, t1, 1 + lw t0, __osRdb_IP6_Size + sub t0, t0, t1 + bgtz t0, 5f + li t1, 0 +5: + sw t1, __osRdb_IP6_CurSend +checkIP6: +STAY2(mfc0 t0, C0_CAUSE) + andi t0, t0, CAUSE_IP6 + bne zero, t0, checkIP6 + la t0, RDB_BASE_REG + sw t2, (t0) +rdbout: + ld t0, THREAD_GP8(k0) + ld t1, THREAD_GP9(k0) + ld t2, THREAD_GP10(k0) +.set noat + ld $1, THREAD_GP1(k0) +.set at + lw k1, THREAD_SR(k0) +STAY2(mtc0 k1, C0_SR) +.set noreorder + nop + nop + nop + nop + eret +.set reorder + +skip_kmc_mode: +#endif + +savecontext: + move t0, k0 + lw k0, __osRunningThread +#if !defined(_FINALROM) && BUILD_VERSION >= VERSION_K + sw k0, __osPreviousThread +#endif + ld t1, THREAD_GP1(t0) + sd t1, THREAD_GP1(k0) + ld t1, THREAD_SR(t0) + sd t1, THREAD_SR(k0) + ld t1, THREAD_GP8(t0) + sd t1, THREAD_GP8(k0) + ld t1, THREAD_GP9(t0) + sd t1, THREAD_GP9(k0) + ld t1, THREAD_GP10(t0) + sd t1, THREAD_GP10(k0) +3: + sd $2, THREAD_GP2(k0) + sd $3, THREAD_GP3(k0) + sd $4, THREAD_GP4(k0) + sd $5, THREAD_GP5(k0) + sd $6, THREAD_GP6(k0) + sd $7, THREAD_GP7(k0) + sd $11, THREAD_GP11(k0) + sd $12, THREAD_GP12(k0) + sd $13, THREAD_GP13(k0) + sd $14, THREAD_GP14(k0) + sd $15, THREAD_GP15(k0) + sd $16, THREAD_GP16(k0) + sd $17, THREAD_GP17(k0) + sd $18, THREAD_GP18(k0) + sd $19, THREAD_GP19(k0) + sd $20, THREAD_GP20(k0) + sd $21, THREAD_GP21(k0) + sd $22, THREAD_GP22(k0) + sd $23, THREAD_GP23(k0) + sd $24, THREAD_GP24(k0) + sd $25, THREAD_GP25(k0) + sd $28, THREAD_GP28(k0) + sd $29, THREAD_GP29(k0) + sd $30, THREAD_GP30(k0) + sd $31, THREAD_GP31(k0) + + mflo t0 + sd t0, THREAD_LO(k0) + mfhi t0 + sd t0, THREAD_HI(k0) + + lw k1, THREAD_SR(k0) + andi t1, k1, SR_IMASK + beqz t1, savercp + +/*if any interrupts are enabled*/ + la t0, __OSGlobalIntMask + lw t0, 0(t0) + xor t2, t0, ~0 /* not except not using not */ + andi t2, t2, SR_IMASK + or ta0, t1, t2 + and t3, k1, ~SR_IMASK + or t3, t3, ta0 + sw t3, THREAD_SR(k0) + andi t0, t0, SR_IMASK + and t1, t1, t0 + and k1, k1, ~SR_IMASK + or k1, k1, t1 +savercp: + + lw t1, PHYS_TO_K1(MI_INTR_MASK_REG) + beqz t1, endrcp + + la t0, __OSGlobalIntMask + lw t0, 0(t0) + + srl t0, t0, 0x10 + xor t0, t0, ~0 + andi t0, t0, 0x3f + lw ta0, THREAD_RCP(k0) + and t0, t0, ta0 + or t1, t1, t0 +endrcp: + sw t1, THREAD_RCP(k0) +STAY2(mfc0 t0, C0_EPC) + sw t0, THREAD_PC(k0) + lw t0, THREAD_FP(k0) + beqz t0, 1f +STAY2(cfc1 t0, fcr31) + NOP + sw t0, THREAD_FPCSR(k0) + sdc1 $f0, THREAD_FP0(k0) + sdc1 $f2, THREAD_FP2(k0) + sdc1 $f4, THREAD_FP4(k0) + sdc1 $f6, THREAD_FP6(k0) + sdc1 $f8, THREAD_FP8(k0) + sdc1 $f10, THREAD_FP10(k0) + sdc1 $f12, THREAD_FP12(k0) + sdc1 $f14, THREAD_FP14(k0) + sdc1 $f16, THREAD_FP16(k0) + sdc1 $f18, THREAD_FP18(k0) + sdc1 $f20, THREAD_FP20(k0) + sdc1 $f22, THREAD_FP22(k0) + sdc1 $f24, THREAD_FP24(k0) + sdc1 $f26, THREAD_FP26(k0) + sdc1 $f28, THREAD_FP28(k0) + sdc1 $f30, THREAD_FP30(k0) +1: +STAY2(mfc0 t0, C0_CAUSE) + sw t0, THREAD_CAUSE(k0) + +.set noreorder + li t1, OS_STATE_RUNNABLE + sh t1, THREAD_STATE(k0) +.set reorder + +#ifndef _FINALROM + lw a0, __os_Kdebug_Pkt + beqz a0, no_kdebug + sw zero, __os_Kdebug_Pkt + jal kdebugserver + b __osDispatchThreadSave +no_kdebug: + lw a0, __osRdb_Mesg + beqz a0, no_rdb_mesg + sw zero, __osRdb_Mesg + jal send_mesg + lw t0, 0x120(k0) +no_rdb_mesg: +#endif + + andi t1, t0, CAUSE_EXCMASK + li t2, EXC_BREAK + beq t1, t2, handle_break + + li t2, EXC_CPU + beq t1, t2, handle_CpU + + li t2, EXC_INT + bne t1, t2, panic +handle_interrupt: + and s0, k1, t0 +next_interrupt: + andi t1, s0, SR_IMASK + srl t2, t1, 0xc + bnez t2, 1f + + srl t2, t1, SR_IMASKSHIFT + addi t2, t2, 16 +1: + + lbu t2, __osIntOffTable(t2) + + lw t2, __osIntTable(t2) + jr t2 + +IP6_Hdlr: + and s0, s0, ~CAUSE_IP6 + b next_interrupt + +IP7_Hdlr: + and s0, s0, ~CAUSE_IP7 + b next_interrupt + +counter: +STAY2(mfc0 t1, C0_COMPARE) +STAY2(mtc0 t1, C0_COMPARE) + li a0, MESG(OS_EVENT_COUNTER) + jal send_mesg + and s0, s0, ~CAUSE_IP8 + b next_interrupt + +cart: +#if BUILD_VERSION >= VERSION_J + and s0, s0, ~CAUSE_IP4 + la t1, __osHwIntTable + add t1, HWINTR_SIZE + lw t2, HWINTR_CALLBACK(t1) + + beqz t2, 1f + + lw sp, HWINTR_SP(t1) + jalr t2 + + beqz v0, 1f + b redispatch + +1: + li a0, MESG(OS_EVENT_CART) + jal send_mesg + b next_interrupt +#else + li a0, MESG(OS_EVENT_CART) + and s0, s0, ~CAUSE_IP4 + la sp, leoDiskStack + addiu sp, 0x1000 - 0x10 # Stack size minus initial frame + li t2, HWINTR_SIZE + lw t2, __osHwIntTable(t2) + + beqz t2, 1f + + jalr t2 + li a0, MESG(OS_EVENT_CART) + + beqz v0, 1f + b redispatch + +1: + jal send_mesg + b next_interrupt +#endif + +rcp: + lw s1, PHYS_TO_K1(MI_INTR_REG) + la t0, __OSGlobalIntMask + lw t0, (t0) + + srl t0, t0, 0x10 + and s1, s1, t0 + andi t1, s1, MI_INTR_SP + beqz t1, vi + + andi s1, s1, 0x3e + lw ta0, PHYS_TO_K1(SP_STATUS_REG) + li t1, (SP_CLR_INTR | SP_CLR_SIG3) + + sw t1, PHYS_TO_K1(SP_STATUS_REG) + andi ta0, ta0, 0x300 + beqz ta0, sp_other_break + + li a0, MESG(OS_EVENT_SP) + jal send_mesg + + beqz s1, NoMoreRcpInts + + b vi + +sp_other_break: + li a0, MESG(OS_EVENT_SP_BREAK) + jal send_mesg + + beqz s1, NoMoreRcpInts + +vi: + andi t1, s1, 0x8 + beqz t1, ai + + andi s1, s1, 0x37 + + sw zero, PHYS_TO_K1(VI_CURRENT_REG) + li a0, MESG(OS_EVENT_VI) + jal send_mesg + beqz s1, NoMoreRcpInts + +ai: + andi t1, s1, 0x4 + beqz t1, si + + andi s1, s1, 0x3b + + li t1, 1 + sw t1, PHYS_TO_K1(AI_STATUS_REG) + + li a0, MESG(OS_EVENT_AI) + jal send_mesg + beqz s1, NoMoreRcpInts + +si: + andi t1, s1, 0x2 + beqz t1, pi + + andi s1, s1, 0x3d + /* any write clears interrupts */ + sw zero, PHYS_TO_K1(SI_STATUS_REG) + li a0, MESG(OS_EVENT_SI) + jal send_mesg + beqz s1, NoMoreRcpInts + +pi: + andi t1, s1, 0x10 + beqz t1, dp + + andi s1, s1, 0x2f + + li t1, PI_STATUS_CLR_INTR + sw t1, PHYS_TO_K1(PI_STATUS_REG) + +#if BUILD_VERSION >= VERSION_J + la t1, __osPiIntTable + lw t2, (t1) + beqz t2, 1f + + lw sp, 4(t1) + move a0, v0 + jalr t2 + + bnez v0, 2f +1: +#endif + li a0, MESG(OS_EVENT_PI) + jal send_mesg +#if BUILD_VERSION >= VERSION_J +2: +#endif + beqz s1, NoMoreRcpInts + +dp: + andi t1, s1, 0x20 + beqz t1, NoMoreRcpInts + + andi s1, s1, 0x1f + + li t1, MI_CLR_DP_INTR + sw t1, PHYS_TO_K1(MI_INIT_MODE_REG) + + li a0, MESG(OS_EVENT_DP) + jal send_mesg + +NoMoreRcpInts: + and s0, s0, ~CAUSE_IP3 + b next_interrupt + +prenmi: + lw k1, THREAD_SR(k0) + + and k1, k1, ~CAUSE_IP5 + sw k1, THREAD_SR(k0) + la t1, __osShutdown + lw t2, 0(t1) + beqz t2, firstnmi + + and s0, s0, ~CAUSE_IP5 + b redispatch + +firstnmi: + li t2, 1 + sw t2, 0(t1) /* __osShutdown */ + li a0, MESG(OS_EVENT_PRENMI) + jal send_mesg + + and s0, s0, ~CAUSE_IP5 + lw t2, __osRunQueue + lw k1, THREAD_SR(t2) + and k1, k1, ~CAUSE_IP5 + sw k1, THREAD_SR(t2) + b redispatch + +sw2: + and t0, t0, ~CAUSE_SW2 +STAY2(mtc0 t0, C0_CAUSE) + + li a0, MESG(OS_EVENT_SW2) + jal send_mesg + + and s0, s0, ~CAUSE_SW2 + b next_interrupt + +sw1: + and t0, t0, ~CAUSE_SW1 +STAY2(mtc0 t0, C0_CAUSE) + + li a0, MESG(OS_EVENT_SW1) + jal send_mesg + + and s0, s0, ~CAUSE_SW1 + b next_interrupt + +handle_break: + li t1, OS_FLAG_CPU_BREAK + sh t1, THREAD_FLAGS(k0) + li a0, MESG(OS_EVENT_CPU_BREAK) + jal send_mesg + b redispatch + +redispatch: + lw t1, THREAD_PRI(k0) + lw t2, __osRunQueue + lw t3, THREAD_PRI(t2) + + bge t1, t3, enqueueRunning + + move a1, k0 + la a0, __osRunQueue + + jal __osEnqueueThread + + j __osDispatchThread + +enqueueRunning: + la t1, __osRunQueue + lw t2, MQ_MTQUEUE(t1) + sw t2, THREAD_NEXT(k0) + sw k0, MQ_MTQUEUE(t1) + j __osDispatchThread +panic: + sw k0, __osFaultedThread + li t1, OS_STATE_STOPPED + sh t1, THREAD_STATE(k0) + li t1, OS_FLAG_FAULT + sh t1, THREAD_FLAGS(k0) + +STAY2(mfc0 t2, C0_BADVADDR) + + sw t2, THREAD_BADVADDR(k0) + + li a0, MESG(OS_EVENT_FAULT) + jal send_mesg + j __osDispatchThread +END(__osException) + +LEAF(send_mesg) + move s2, ra + la t2, __osEventStateTab + addu t2, t2, a0 + lw t1, OS_EVENTSTATE_MESSAGE_QUEUE(t2) + beqz t1, send_done + + lw t3, MQ_VALIDCOUNT(t1) + lw ta0, MQ_MSGCOUNT(t1) + + bge t3, ta0, send_done + + lw ta1, MQ_FIRST(t1) + addu ta1, ta1, t3 + + rem ta1, ta1, ta0 + lw ta0, MQ_MSG(t1) + mul ta1, ta1, 4 + addu ta0, ta0, ta1 + lw ta1, OS_EVENTSTATE_MESSAGE(t2) + sw ta1, 0(ta0) /* msg[ta1] = */ + addiu t2, t3, 1 + sw t2, MQ_VALIDCOUNT(t1) + lw t2, MQ_MTQUEUE(t1) + lw t3, THREAD_NEXT(t2) + beqz t3, send_done + + move a0, t1 + jal __osPopThread + + move t2, v0 + + move a1, t2 + la a0, __osRunQueue + jal __osEnqueueThread +send_done: + jr s2 +END(send_mesg) + +LEAF(handle_CpU) /* coprocessor error */ + and t1, t0, CAUSE_CEMASK + srl t1, t1, CAUSE_CESHIFT + li t2, 1 /* cp1 error */ + bne t1, t2, panic + + /* enable cp1 (fpu) for this thread */ + li t1, 1 + sw t1, THREAD_FP(k0) + lw k1, THREAD_SR(k0) + or k1, k1, SR_CU1 + sw k1, THREAD_SR(k0) + b enqueueRunning +END(handle_CpU) + +LEAF(__osEnqueueAndYield) + lw a1, __osRunningThread +#if !defined(_FINALROM) && BUILD_VERSION >= VERSION_K + sw a1, __osPreviousThread +#endif +STAY2(mfc0 t0, C0_SR) + ori t0, t0, SR_EXL + sw t0, THREAD_SR(a1) + sd s0, THREAD_GP16(a1) + sd s1, THREAD_GP17(a1) + sd s2, THREAD_GP18(a1) + sd s3, THREAD_GP19(a1) + sd s4, THREAD_GP20(a1) + sd s5, THREAD_GP21(a1) + sd s6, THREAD_GP22(a1) + sd s7, THREAD_GP23(a1) + sd gp, THREAD_GP28(a1) + sd sp, THREAD_GP29(a1) + sd s8, THREAD_GP30(a1) + sd ra, THREAD_GP31(a1) + sw ra, THREAD_PC(a1) + lw k1, THREAD_FP(a1) + beqz k1, 1f + cfc1 k1, fcr31 + sw k1, THREAD_FPCSR(a1) + sdc1 $f20, THREAD_FP20(a1) + sdc1 $f22, THREAD_FP22(a1) + sdc1 $f24, THREAD_FP24(a1) + sdc1 $f26, THREAD_FP26(a1) + sdc1 $f28, THREAD_FP28(a1) + sdc1 $f30, THREAD_FP30(a1) +1: + lw k1, THREAD_SR(a1) + andi t1, k1, SR_IMASK + beqz t1, 2f + + la t0, __OSGlobalIntMask + lw t0, 0(t0) + xor t0, t0, ~0 + andi t0, t0, SR_IMASK + or t1, t1, t0 + and k1, k1, ~SR_IMASK + or k1, k1, t1 + sw k1, THREAD_SR(a1) +2: + lw k1, PHYS_TO_K1(MI_INTR_MASK_REG) + beqz k1, 3f + + la k0, __OSGlobalIntMask + lw k0, 0(k0) + + srl k0, k0, 0x10 + xor k0, k0, ~0 + andi k0, k0, 0x3f + lw t0, THREAD_RCP(a1) + and k0, k0, t0 + or k1, k1, k0 +3: + sw k1, THREAD_RCP(a1) + beqz a0, noEnqueue + jal __osEnqueueThread +noEnqueue: + j __osDispatchThread +END(__osEnqueueAndYield) + +/*__osEnqueueThread(OSThread **, OSThread *)*/ +LEAF(__osEnqueueThread) + move t9, a0 + lw t8, 0(a0) + lw ta3, THREAD_PRI(a1) + lw ta2, THREAD_PRI(t8) + blt ta2, ta3, 2f +1: + move t9, t8 + lw t8, THREAD_NEXT(t8) + lw ta2, THREAD_PRI(t8) + bge ta2, ta3, 1b +2: + lw t8, THREAD_NEXT(t9) + sw t8, THREAD_NEXT(a1) + sw a1, THREAD_NEXT(t9) + sw a0, THREAD_QUEUE(a1) + jr ra +END(__osEnqueueThread) + +LEAF(__osPopThread) + lw v0, 0(a0) /* a0 is OSThread** */ + lw t9, THREAD_NEXT(v0) + sw t9, 0(a0) + jr ra +END(__osPopThread) +#if BUILD_VERSION >= VERSION_K +LEAF(__osNop) + jr ra +END(__osNop) +#endif +LEAF(__osDispatchThread) + la a0, __osRunQueue + jal __osPopThread + sw v0, __osRunningThread + li t0, OS_STATE_RUNNING + sh t0, THREAD_STATE(v0) + move k0, v0 + +#if !defined(_FINALROM) && BUILD_VERSION >= VERSION_K + la t0, __osThprofFunc + lw t0, (t0) + beqz t0, __osDispatchThreadSave +1: + lw a0, __osPreviousThread + lw sp, __osThprofStack + jalr t0 +#endif + +/* There's another 1: label somewhere around here in version J and below */ +#if BUILD_VERSION < VERSION_K +1: +#endif + +__osDispatchThreadSave: + lw k1, THREAD_SR(k0) + la t0, __OSGlobalIntMask + lw t0, 0(t0) + andi t0, t0, SR_IMASK + andi t1, k1, SR_IMASK + and t1, t1, t0 + and k1, k1, ~SR_IMASK + or k1, k1, t1 +STAY2(mtc0 k1, C0_SR) +.set noat + ld $1, THREAD_GP1(k0) +.set at + ld $2, THREAD_GP2(k0) + ld $3, THREAD_GP3(k0) + ld $4, THREAD_GP4(k0) + ld $5, THREAD_GP5(k0) + ld $6, THREAD_GP6(k0) + ld $7, THREAD_GP7(k0) + ld $8, THREAD_GP8(k0) + ld $9, THREAD_GP9(k0) + ld $10, THREAD_GP10(k0) + ld $11, THREAD_GP11(k0) + ld $12, THREAD_GP12(k0) + ld $13, THREAD_GP13(k0) + ld $14, THREAD_GP14(k0) + ld $15, THREAD_GP15(k0) + ld $16, THREAD_GP16(k0) + ld $17, THREAD_GP17(k0) + ld $18, THREAD_GP18(k0) + ld $19, THREAD_GP19(k0) + ld $20, THREAD_GP20(k0) + ld $21, THREAD_GP21(k0) + ld $22, THREAD_GP22(k0) + ld $23, THREAD_GP23(k0) + ld $24, THREAD_GP24(k0) + ld $25, THREAD_GP25(k0) + ld $28, THREAD_GP28(k0) + ld $29, THREAD_GP29(k0) + ld $30, THREAD_GP30(k0) + ld $31, THREAD_GP31(k0) + ld k1, THREAD_LO(k0) + mtlo k1 + ld k1, THREAD_HI(k0) + mthi k1 + lw k1, THREAD_PC(k0) +STAY2(mtc0 k1, C0_EPC) + lw k1, THREAD_FP(k0) + beqz k1, 1f + + lw k1, THREAD_FPCSR(k0) +STAY2(ctc1 k1, fcr31) + ldc1 $f0, THREAD_FP0(k0) + ldc1 $f2, THREAD_FP2(k0) + ldc1 $f4, THREAD_FP4(k0) + ldc1 $f6, THREAD_FP6(k0) + ldc1 $f8, THREAD_FP8(k0) + ldc1 $f10, THREAD_FP10(k0) + ldc1 $f12, THREAD_FP12(k0) + ldc1 $f14, THREAD_FP14(k0) + ldc1 $f16, THREAD_FP16(k0) + ldc1 $f18, THREAD_FP18(k0) + ldc1 $f20, THREAD_FP20(k0) + ldc1 $f22, THREAD_FP22(k0) + ldc1 $f24, THREAD_FP24(k0) + ldc1 $f26, THREAD_FP26(k0) + ldc1 $f28, THREAD_FP28(k0) + ldc1 $f30, THREAD_FP30(k0) + +1: +.set noreorder + lw k1, THREAD_RCP(k0) + la k0, __OSGlobalIntMask + lw k0, 0(k0) + srl k0, k0, 0x10 + and k1, k1, k0 + sll k1, k1, 0x1 + la k0, __osRcpImTable + addu k1, k1, k0 + lhu k1, 0(k1) + la k0, PHYS_TO_K1(MI_INTR_MASK_REG) + sw k1, 0(k0) + + nop + nop + nop + nop + eret +.set reorder +END(__osDispatchThread) + +LEAF(__osCleanupThread) + move a0, zero +#if !defined(BBPLAYER) && !defined(__sgi) + nop +#endif + jal osDestroyThread +END(__osCleanupThread) diff --git a/lib/ultralib/src/os/exit.c b/lib/ultralib/src/os/exit.c new file mode 100644 index 0000000..24a873f --- /dev/null +++ b/lib/ultralib/src/os/exit.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" + +void osExit() { + __osGIOInterrupt(16); + + for (;;) { + ; + } +} diff --git a/lib/ultralib/src/os/getactivequeue.c b/lib/ultralib/src/os/getactivequeue.c new file mode 100644 index 0000000..1fefc88 --- /dev/null +++ b/lib/ultralib/src/os/getactivequeue.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "osint.h" + +OSThread* __osGetActiveQueue(void) { + return __osActiveQueue; +} diff --git a/lib/ultralib/src/os/getcause.s b/lib/ultralib/src/os/getcause.s new file mode 100644 index 0000000..873464f --- /dev/null +++ b/lib/ultralib/src/os/getcause.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osGetCause) + STAY2(mfc0 v0, C0_CAUSE) + jr ra +END(__osGetCause) diff --git a/lib/ultralib/src/os/getcompare.s b/lib/ultralib/src/os/getcompare.s new file mode 100644 index 0000000..99c1758 --- /dev/null +++ b/lib/ultralib/src/os/getcompare.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osGetCompare) + STAY2(mfc0 v0, C0_COMPARE) + jr ra +END(__osGetCompare) diff --git a/lib/ultralib/src/os/getconfig.s b/lib/ultralib/src/os/getconfig.s new file mode 100644 index 0000000..8165178 --- /dev/null +++ b/lib/ultralib/src/os/getconfig.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osGetConfig) + STAY2(mfc0 v0, C0_CONFIG) + jr ra +END(__osGetConfig) diff --git a/lib/ultralib/src/os/getcount.s b/lib/ultralib/src/os/getcount.s new file mode 100644 index 0000000..28d5a79 --- /dev/null +++ b/lib/ultralib/src/os/getcount.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(osGetCount) + STAY2(mfc0 v0, C0_COUNT) + jr ra +END(osGetCount) diff --git a/lib/ultralib/src/os/getcurrfaultthread.c b/lib/ultralib/src/os/getcurrfaultthread.c new file mode 100644 index 0000000..d7668c2 --- /dev/null +++ b/lib/ultralib/src/os/getcurrfaultthread.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "osint.h" + +OSThread* __osGetCurrFaultedThread() { + return __osFaultedThread; +} diff --git a/lib/ultralib/src/os/getfpccsr.s b/lib/ultralib/src/os/getfpccsr.s new file mode 100644 index 0000000..56837a5 --- /dev/null +++ b/lib/ultralib/src/os/getfpccsr.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osGetFpcCsr) + STAY2(cfc1 v0, fcr31) + jr ra +END(__osGetSR) # @bug: Should be __osGetFpcCsr diff --git a/lib/ultralib/src/os/gethwinterrupt.c b/lib/ultralib/src/os/gethwinterrupt.c new file mode 100644 index 0000000..46dc366 --- /dev/null +++ b/lib/ultralib/src/os/gethwinterrupt.c @@ -0,0 +1,21 @@ +#include "PR/os_internal.h" + +struct __osHwInt { + s32 (*handler)(void); +#if BUILD_VERSION >= VERSION_J + void* stackEnd; +#endif +}; + +extern struct __osHwInt __osHwIntTable[]; + +#if BUILD_VERSION >= VERSION_J +void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void), void** stackEnd) { +#else +void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void)) { +#endif + *handler = __osHwIntTable[interrupt].handler; +#if BUILD_VERSION >= VERSION_J + *stackEnd = __osHwIntTable[interrupt].stackEnd; +#endif +} diff --git a/lib/ultralib/src/os/getintmask.s b/lib/ultralib/src/os/getintmask.s new file mode 100644 index 0000000..573eed1 --- /dev/null +++ b/lib/ultralib/src/os/getintmask.s @@ -0,0 +1,33 @@ +#include "PR/R4300.h" +#include "PR/rcp.h" +#include "PR/os.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +.set noreorder +LEAF(osGetIntMask) + mfc0 v0, C0_SR + andi v0, v0, OS_IM_CPU + la t0, __OSGlobalIntMask + lw t1, 0(t0) + xor t0, t1, -1 + andi t0, t0, SR_IMASK + or v0, v0, t0 + + lw t1, PHYS_TO_K1(MI_INTR_MASK_REG) + beqz t1, 1f + + la t0, __OSGlobalIntMask # this is intentionally a macro in the branch delay slot + + lw t0, 0(t0) + srl t0, t0, 0x10 + xor t0, t0, -1 + andi t0, t0, 0x3f + or t1, t1, t0 +1: + sll t2, t1, 0x10 + or v0, v0, t2 + jr ra + nop +END(osGetIntMask) diff --git a/lib/ultralib/src/os/getmemsize.c b/lib/ultralib/src/os/getmemsize.c new file mode 100644 index 0000000..814443d --- /dev/null +++ b/lib/ultralib/src/os/getmemsize.c @@ -0,0 +1,53 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/R4300.h" + +#define STEP 0x100000 +#define SIZE_4MB 0x400000 +#define SIZE_8MB 0x800000 + +#if BUILD_VERSION >= VERSION_J + +u32 osGetMemSize(void) { + vu32* ptr; + u32 size = SIZE_4MB; + u32 data0; + u32 data1; + + while (size < SIZE_8MB) { + ptr = (vu32*)(K1BASE + size); + + data0 = *ptr; + data1 = ptr[STEP / 4 - 1]; + + *ptr ^= ~0; + ptr[STEP / 4 - 1] ^= ~0; + + if ((*ptr != (data0 ^ ~0)) || (ptr[STEP / 4 - 1] != (data1 ^ ~0))) { + return size; + } + + *ptr = data0; + ptr[STEP / 4 - 1] = data1; + + size += STEP; + } + + return size; +} + +#else + +u32 osGetMemSize(void) { + u32* memory; + u32 memsize = SIZE_4MB - STEP; + do { + memsize += STEP; + memory = (u32*)(memsize + K1BASE); + memory[0] = 0x12345678; + memory[STEP / 4 - 1] = 0x87654321; + } while (memory[0] == 0x12345678 && memory[STEP / 4 - 1] == 0x87654321); + return memsize; +} + +#endif diff --git a/lib/ultralib/src/os/getnextfaultthread.c b/lib/ultralib/src/os/getnextfaultthread.c new file mode 100644 index 0000000..44d723a --- /dev/null +++ b/lib/ultralib/src/os/getnextfaultthread.c @@ -0,0 +1,23 @@ +#include "PR/os_internal.h" +#include "osint.h" + +OSThread* __osGetNextFaultedThread(OSThread* lastFault) { + register int saveMask = __osDisableInt(); + register OSThread* fault; + + fault = lastFault == NULL ? __osActiveQueue : lastFault; + + while (fault->priority != -1) { + if ((fault->flags & OS_FLAG_FAULT) != 0 && fault != lastFault) { + break; + } + fault = fault->tlnext; + } + + if (fault->priority == -1) { + fault = NULL; + } + + __osRestoreInt(saveMask); + return fault; +} diff --git a/lib/ultralib/src/os/getsr.s b/lib/ultralib/src/os/getsr.s new file mode 100644 index 0000000..bc9c767 --- /dev/null +++ b/lib/ultralib/src/os/getsr.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osGetSR) + STAY2(mfc0 v0, C0_SR) + jr ra +END(__osGetSR) diff --git a/lib/ultralib/src/os/getthreadid.c b/lib/ultralib/src/os/getthreadid.c new file mode 100644 index 0000000..8bbc9f6 --- /dev/null +++ b/lib/ultralib/src/os/getthreadid.c @@ -0,0 +1,10 @@ +#include "PR/os_internal.h" +#include "osint.h" + +OSId osGetThreadId(OSThread* thread) { + if (thread == NULL) { + thread = __osRunningThread; + } + + return thread->id; +} diff --git a/lib/ultralib/src/os/getthreadpri.c b/lib/ultralib/src/os/getthreadpri.c new file mode 100644 index 0000000..149f3f7 --- /dev/null +++ b/lib/ultralib/src/os/getthreadpri.c @@ -0,0 +1,10 @@ +#include "PR/os_internal.h" +#include "osint.h" + +OSPri osGetThreadPri(OSThread* thread) { + if (thread == NULL) { + thread = __osRunningThread; + } + + return thread->priority; +} diff --git a/lib/ultralib/src/os/gettime.c b/lib/ultralib/src/os/gettime.c new file mode 100644 index 0000000..aab4133 --- /dev/null +++ b/lib/ultralib/src/os/gettime.c @@ -0,0 +1,25 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" +#include "../io/viint.h" + +OSTime osGetTime() { + u32 tmptime; + u32 elapseCount; + OSTime currentCount; + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSGETTIME, 0); + return 0; + } +#endif + + saveMask = __osDisableInt(); + tmptime = osGetCount(); + elapseCount = tmptime - __osBaseCounter; + currentCount = __osCurrentTime; + __osRestoreInt(saveMask); + return currentCount + elapseCount; +} diff --git a/lib/ultralib/src/os/gettlbasid.s b/lib/ultralib/src/os/gettlbasid.s new file mode 100644 index 0000000..a0702ea --- /dev/null +++ b/lib/ultralib/src/os/gettlbasid.s @@ -0,0 +1,11 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.set noreorder +.text +LEAF(__osGetTLBASID) + mfc0 v0, C0_ENTRYHI + jr ra + nop +END(__osGetTLBASID) diff --git a/lib/ultralib/src/os/gettlbhi.s b/lib/ultralib/src/os/gettlbhi.s new file mode 100644 index 0000000..04c03e9 --- /dev/null +++ b/lib/ultralib/src/os/gettlbhi.s @@ -0,0 +1,17 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.set noreorder +.text +LEAF(__osGetTLBHi) + mtc0 a0, C0_INX + nop + tlbr + nop + nop + nop + mfc0 v0, C0_ENTRYHI + jr ra + nop +END(__osGetTLBHi) diff --git a/lib/ultralib/src/os/gettlblo0.s b/lib/ultralib/src/os/gettlblo0.s new file mode 100644 index 0000000..3b2c2ec --- /dev/null +++ b/lib/ultralib/src/os/gettlblo0.s @@ -0,0 +1,17 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.set noreorder +.text +LEAF(__osGetTLBLo0) + mtc0 a0, C0_INX + nop + tlbr + nop + nop + nop + mfc0 v0, C0_ENTRYLO0 + jr ra + nop +END(__osGetTLBLo0) diff --git a/lib/ultralib/src/os/gettlblo1.s b/lib/ultralib/src/os/gettlblo1.s new file mode 100644 index 0000000..a24baef --- /dev/null +++ b/lib/ultralib/src/os/gettlblo1.s @@ -0,0 +1,17 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.set noreorder +.text +LEAF(__osGetTLBLo1) + mtc0 a0, C0_INX + nop + tlbr + nop + nop + nop + mfc0 v0, C0_ENTRYLO1 + jr ra + nop +END(__osGetTLBLo1) diff --git a/lib/ultralib/src/os/gettlbpagemask.s b/lib/ultralib/src/os/gettlbpagemask.s new file mode 100644 index 0000000..de9954a --- /dev/null +++ b/lib/ultralib/src/os/gettlbpagemask.s @@ -0,0 +1,17 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.set noreorder +.text +LEAF(__osGetTLBPageMask) + mtc0 a0, C0_INX + nop + tlbr + nop + nop + nop + mfc0 v0, C0_PAGEMASK + jr ra + nop +END(__osGetTLBPageMask) diff --git a/lib/ultralib/src/os/getwatchlo.s b/lib/ultralib/src/os/getwatchlo.s new file mode 100644 index 0000000..4eee9ee --- /dev/null +++ b/lib/ultralib/src/os/getwatchlo.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osGetWatchLo) + STAY2(mfc0 v0, C0_WATCHLO) + jr ra +END(__osGetWatchLo) diff --git a/lib/ultralib/src/os/initialize.c b/lib/ultralib/src/os/initialize.c new file mode 100644 index 0000000..89f4b02 --- /dev/null +++ b/lib/ultralib/src/os/initialize.c @@ -0,0 +1,224 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/os_version.h" +#include "../io/piint.h" + +typedef struct { + /* 0x0 */ unsigned int inst1; + /* 0x4 */ unsigned int inst2; + /* 0x8 */ unsigned int inst3; + /* 0xC */ unsigned int inst4; +} __osExceptionVector; +extern __osExceptionVector __osExceptionPreamble[]; + +extern OSPiHandle __Dom1SpeedParam; +extern OSPiHandle __Dom2SpeedParam; + +OSTime osClockRate = OS_CLOCK_RATE; +s32 osViClock = VI_NTSC_CLOCK; +u32 __osShutdown = 0; +u32 __OSGlobalIntMask = OS_IM_ALL; +#ifdef _FINALROM +u32 __osFinalrom; +#else +u32 __kmc_pt_mode; +#if BUILD_VERSION >= VERSION_K +void* __printfunc = NULL; +#endif +#endif + +#if BUILD_VERSION >= VERSION_K + +#define INITIALIZE_FUNC __osInitialize_common +#define SPEED_PARAM_FUNC __createSpeedParam +#else + +#define INITIALIZE_FUNC osInitialize +#define SPEED_PARAM_FUNC createSpeedParam +#if BUILD_VERSION >= VERSION_J +static void ptstart(void); +static void SPEED_PARAM_FUNC(void); +#endif +extern __osExceptionVector __ptExceptionPreamble[]; + +#endif + +#if BUILD_VERSION >= VERSION_K +void SPEED_PARAM_FUNC(void) { + __Dom1SpeedParam.type = DEVICE_TYPE_INIT; + __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); + __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + + __Dom2SpeedParam.type = DEVICE_TYPE_INIT; + __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); + __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); + __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); + __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); +} +#endif + +void INITIALIZE_FUNC() { + u32 pifdata; +#if BUILD_VERSION < VERSION_K + u32 clock = 0; +#endif + +#ifdef _FINALROM + __osFinalrom = TRUE; +#endif + + __osSetSR(__osGetSR() | SR_CU1); // enable fpu + __osSetFpcCsr(FPCSR_FS | FPCSR_EV); // flush denorm to zero, enable invalid operation +#if BUILD_VERSION >= VERSION_K + __osSetWatchLo(0x4900000); +#endif + + while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)) { // last byte of joychannel ram + ; + } + while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)) { + ; // todo: magic contant + } + *(__osExceptionVector*)UT_VEC = *__osExceptionPreamble; + *(__osExceptionVector*)XUT_VEC = *__osExceptionPreamble; + *(__osExceptionVector*)ECC_VEC = *__osExceptionPreamble; + *(__osExceptionVector*)E_VEC = *__osExceptionPreamble; + osWritebackDCache((void*)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); + osInvalICache((void*)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); +#if BUILD_VERSION >= VERSION_J + SPEED_PARAM_FUNC(); + osUnmapTLBAll(); + osMapTLBRdb(); +#else + osMapTLBRdb(); + osPiRawReadIo(4, &clock); // Read clock rate from the ROM header + clock &= ~0xf; + if (clock != 0) + { + osClockRate = clock; + } +#endif + osClockRate = osClockRate * 3 / 4; + + if (osResetType == 0) { // cold reset + bzero(osAppNMIBuffer, OS_APP_NMI_BUFSIZE); + } + + if (osTvType == OS_TV_PAL) { + osViClock = VI_PAL_CLOCK; + } else if (osTvType == OS_TV_MPAL) { + osViClock = VI_MPAL_CLOCK; + } else { + osViClock = VI_NTSC_CLOCK; + } + +#if BUILD_VERSION >= VERSION_J + // Wait until there are no RCP interrupts + if (__osGetCause() & CAUSE_IP5) { + while (TRUE) { + ; + } + } + + IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); + IO_WRITE(AI_DACRATE_REG, AI_MAX_DAC_RATE - 1); + IO_WRITE(AI_BITRATE_REG, AI_MAX_BIT_RATE - 1); +#endif + +#if BUILD_VERSION < VERSION_K && !defined(_FINALROM) + if (!__kmc_pt_mode) { + int (*fnc)(); +#if BUILD_VERSION < VERSION_J + unsigned int c; + unsigned int c1; +#endif + unsigned int* src; + unsigned int* dst; + unsigned int monadr; + volatile unsigned int* mon; + volatile unsigned int* stat; + + stat = (unsigned*)0xbff08004; + mon = (unsigned*)0xBFF00000; + if (*mon != 0x4B4D4300) { + return; + } + + src = (unsigned*)__ptExceptionPreamble; + dst = (unsigned*)E_VEC; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + src += 2; + dst += 2; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + + osWritebackDCache(E_VEC, 0x24); + osInvalICache(E_VEC, 0x24); + + __kmc_pt_mode = TRUE; + + if ((*stat & 0x10) == 0) { + monadr = *(mon + 1); + if (monadr != 0xBFF00000) { + unsigned int* src; + unsigned int* dst = monadr | 0x20000000; + unsigned int ct = 0x2000 / 4; + + src = 0xBFF00000; + + while (ct != 0) { + *dst++ = *src++; + ct--; + } + } + fnc = monadr + 8; + fnc(0x4B4D4300, 0); + } + } +#endif +} + +#if !defined(_FINALROM) && BUILD_VERSION < VERSION_J +void ptstart() { + +} +#elif !defined(_FINALROM) && BUILD_VERSION < VERSION_K +static void ptstart() { + +} +#endif + +#if BUILD_VERSION >= VERSION_K +void __osInitialize_autodetect() { +#ifndef _FINALROM + if (__checkHardware_msp()) { + __osInitialize_msp(); + } else if (__checkHardware_kmc()) { + __osInitialize_kmc(); + } else if (__checkHardware_isv()) { + __osInitialize_isv(); + } else { + __osInitialize_emu(); + } +#endif +} +#elif BUILD_VERSION == VERSION_J +static void SPEED_PARAM_FUNC(void) { + __Dom1SpeedParam.type = DEVICE_TYPE_INIT; + __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); + __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + + __Dom2SpeedParam.type = DEVICE_TYPE_INIT; + __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); + __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); + __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); + __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); +} +#endif diff --git a/lib/ultralib/src/os/initialize_emu.c b/lib/ultralib/src/os/initialize_emu.c new file mode 100644 index 0000000..7f7dd85 --- /dev/null +++ b/lib/ultralib/src/os/initialize_emu.c @@ -0,0 +1,27 @@ +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "PR/rdb.h" +#include "osint.h" + +typedef struct { + /* 0x0 */ unsigned int inst1; + /* 0x4 */ unsigned int inst2; + /* 0x8 */ unsigned int inst3; + /* 0xC */ unsigned int inst4; +} __osExceptionVector; + +static void* proutSyncPrintf(void* str, const char* buf, size_t n) { + size_t sent = 0; + + while (sent < n) { + sent += __osRdbSend(buf + sent, n - sent, RDB_TYPE_GtoH_PRINT); + } + return 1; +} + +void __osInitialize_emu(void) { + __printfunc = proutSyncPrintf; +} + +#endif diff --git a/lib/ultralib/src/os/initialize_isv.c b/lib/ultralib/src/os/initialize_isv.c new file mode 100644 index 0000000..50f6379 --- /dev/null +++ b/lib/ultralib/src/os/initialize_isv.c @@ -0,0 +1,175 @@ +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "osint.h" + +#include "macros.h" + +typedef struct { + /* 0x0 */ unsigned int inst1; + /* 0x4 */ unsigned int inst2; + /* 0x8 */ unsigned int inst3; + /* 0xC */ unsigned int inst4; +} __osExceptionVector; + +extern __osExceptionVector __isExpJP; + +void MonitorInitBreak(void); + +#define ISV_BASE gISVDbgPrnAdrs +#define ISV_MAGIC_ADDR (ISV_BASE + 0x00) +#define ISV_GET_ADDR (ISV_BASE + 0x04) +#define ISV_PUT_ADDR (ISV_BASE + 0x14) +#define ISV_BUFFER (ISV_BASE + 0x20) + +#define ISV_BUFFER_LEN (0x10000 - 0x20) + +#define IS64_MAGIC 'IS64' + +__osExceptionVector ramOldVector ALIGNED(8); +u32 gISVFlag; +u16 gISVChk; +u32 gISVDbgPrnAdrs; +u32 leoComuBuffAdd; + +static OSPiHandle* is_Handle; + +void isPrintfInit(void) { + is_Handle = osCartRomInit(); + + osEPiWriteIo(is_Handle, ISV_PUT_ADDR, 0); + osEPiWriteIo(is_Handle, ISV_GET_ADDR, 0); + osEPiWriteIo(is_Handle, ISV_MAGIC_ADDR, IS64_MAGIC); +} + +static void* is_proutSyncPrintf(void* arg, const u8* str, u32 count) { + u32 data; + s32 p; + s32 start; + s32 end; + + if (gISVDbgPrnAdrs == 0) { + return 0; + } + + osEPiReadIo(is_Handle, ISV_MAGIC_ADDR, &data); + if (data != IS64_MAGIC) { + return 1; + } + osEPiReadIo(is_Handle, ISV_GET_ADDR, &data); + p = data; + osEPiReadIo(is_Handle, ISV_PUT_ADDR, &data); + + start = data; + end = start + count; + + if (end >= ISV_BUFFER_LEN) { + end -= ISV_BUFFER_LEN; + if (p < end || start < p) { + return 1; + } + } else { + if (start < p && p < end) { + return 1; + } + } + while (count) { + if (*str != '\0') { + s32 shift = start & 3; + u32 addr = ISV_BUFFER + (start & 0xFFFFFFC); + + shift = (3 - shift) * 8; + + osEPiReadIo(is_Handle, addr, &data); + osEPiWriteIo(is_Handle, addr, (data & ~(0xff << shift)) | (*str << shift)); + + start++; + if (start >= ISV_BUFFER_LEN) { + start -= ISV_BUFFER_LEN; + } + } + count--; + str++; + } + osEPiWriteIo(is_Handle, ISV_PUT_ADDR, start); + + return 1; +} + +int __checkHardware_isv(void) { + u32 i = 0; + u32 data; + u32 save[4]; + OSPiHandle* hnd = osCartRomInit(); + + gISVDbgPrnAdrs = 0; + leoComuBuffAdd = 0; + gISVFlag = IS64_MAGIC; + gISVChk = 0; + + for (i = 0; i < 4; i++) { + osEPiReadIo(hnd, 0xB0000100 + i * 4, &save[i]); + } + +#ifndef __GNU__ // BUG: data is used uninitialized for GCC + data = 0; +#endif + osEPiWriteIo(hnd, 0xB000010C, data); + data = IS64_MAGIC; + osEPiWriteIo(hnd, 0xB0000100, IS64_MAGIC); + + for (i = 0; i < 0x20000; i++) { + osEPiReadIo(hnd, 0xB000010C, &data); + if (data == IS64_MAGIC) { + data = 0; + osEPiWriteIo(hnd, 0xB0000100, data); + gISVChk |= 1; + osEPiReadIo(hnd, 0xB0000104, &gISVDbgPrnAdrs); + osEPiReadIo(hnd, 0xB0000108, &leoComuBuffAdd); + break; + } + } + + for (i = 0; i < 4; i++) { + osEPiWriteIo(hnd, 0xB0000100 + i * 4, save[i]); + } + + osEPiReadIo(hnd, 0xBFF00000, &data); + + gISVChk |= ((data == IS64_MAGIC) ? 2 : 0); + + return (gISVChk != 0) ? TRUE : FALSE; +} + +void __osInitialize_isv(void) { + void (*fn)(void); + OSPiHandle* hnd; + s32 pad; + s32 pad2; + + if (gISVFlag == IS64_MAGIC || __checkHardware_isv()) { + if (gISVDbgPrnAdrs != 0) { + __printfunc = is_proutSyncPrintf; + isPrintfInit(); + } + if (gISVChk & 2) { + hnd = osCartRomInit(); + + ramOldVector = *(__osExceptionVector*)E_VEC; + *(__osExceptionVector*)E_VEC = __isExpJP; + + osWritebackDCache(&ramOldVector, 0x10); + osInvalICache(&ramOldVector, 0x10); + osWritebackDCache(0x80000000, 0x190); + osInvalICache(0x80000000, 0x190); + osEPiReadIo(hnd, 0xBFF00010, (u32*)&fn); + fn(); + } + if (gISVChk & 2) { + MonitorInitBreak(); + } + } +} + +#endif diff --git a/lib/ultralib/src/os/initialize_kmc.c b/lib/ultralib/src/os/initialize_kmc.c new file mode 100644 index 0000000..4952a0d --- /dev/null +++ b/lib/ultralib/src/os/initialize_kmc.c @@ -0,0 +1,152 @@ +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "osint.h" + +typedef struct { + /* 0x0 */ unsigned int inst1; + /* 0x4 */ unsigned int inst2; + /* 0x8 */ unsigned int inst3; + /* 0xC */ unsigned int inst4; +} __osExceptionVector; + +extern __osExceptionVector __ptExceptionPreamble[]; + +static volatile unsigned int* stat = (unsigned*)0xbff08004; +static volatile unsigned int* wport = (unsigned*)0xbff08000; +static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); + +static void rmonPutchar(char c) { + u32 data; + + while (TRUE) { + osPiReadIo(stat, &data); + if (data & 4) { + osPiWriteIo(wport, c); + break; + } + } +} + +static void* kmc_proutSyncPrintf(void* str, const char* buf, int n) { + int i; + char c; + char* p; + char* q; + char xbuf[128]; + static int column = 0; + + p = &xbuf; + + for (i = 0; i < n; i++) { + c = *buf++; + + switch (c) { + case '\n': + *p++ = '\n'; + column = 0; + break; + case '\t': + do { + *p++ = ' '; + } while (++column % 8); + break; + default: + column++; + *p++ = c; + break; + } + + if (c == '\n' || (p - xbuf) > 100) { + rmonPutchar((p - xbuf) - 1); + + q = xbuf; + while (q != p) { + rmonPutchar(*q++); + } + p = xbuf; + } + } + if (p != xbuf) { + rmonPutchar((p - xbuf) - 1); + + q = xbuf; + while (q != p) { + rmonPutchar(*q++); + } + } + return (void*)1; +} + +extern u32 __kmc_pt_mode; + +void __osInitialize_kmc(void) { + if (!__kmc_pt_mode) { + int (*fnc)(); + unsigned int* src; + unsigned int* dst; + unsigned int monadr; + volatile unsigned int* mon; + volatile unsigned int* stat; + + stat = (unsigned*)0xbff08004; + mon = (unsigned*)0xBFF00000; + if (*mon != 0x4B4D4300) { + return; + } + + src = (unsigned*)__ptExceptionPreamble; + dst = (unsigned*)E_VEC; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + src += 2; + dst += 2; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + + osWritebackDCache(E_VEC, 0x24); + osInvalICache(E_VEC, 0x24); + + __kmc_pt_mode = TRUE; + + if ((*stat & 0x10) == 0) { + monadr = *(mon + 1); + if (monadr != 0xBFF00000) { + unsigned int* src; + unsigned int* dst = monadr | 0x20000000; + unsigned int ct = 0x2000 / 4; + + src = 0xBFF00000; + + while (ct != 0) { + *dst++ = *src++; + ct--; + } + } + fnc = monadr + 8; + fnc(0x4B4D4300, 0); + } + __printfunc = kmc_proutSyncPrintf; + } +} + +int __checkHardware_kmc(void) { + volatile unsigned int* mon = (unsigned*)0xBFF00000; + + if (*mon == 0x4B4D4300) { + mon = (unsigned*)0xBFF00010; + + if (*mon == 0xB0FFB000) { + return TRUE; + } else { + return FALSE; + } + } else { + return FALSE; + } +} + +#endif diff --git a/lib/ultralib/src/os/initialize_msp.c b/lib/ultralib/src/os/initialize_msp.c new file mode 100644 index 0000000..1f120e1 --- /dev/null +++ b/lib/ultralib/src/os/initialize_msp.c @@ -0,0 +1,152 @@ +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "osint.h" + +typedef struct { + /* 0x0 */ unsigned int inst1; + /* 0x4 */ unsigned int inst2; + /* 0x8 */ unsigned int inst3; + /* 0xC */ unsigned int inst4; +} __osExceptionVector; + +extern __osExceptionVector __ptExceptionPreamble[]; + +static volatile unsigned int* stat = (unsigned*)0xbff08004; +static volatile unsigned int* wport = (unsigned*)0xbff08000; +static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); + +static void rmonPutchar(char c) { + u32 data; + + while (TRUE) { + osPiReadIo(stat, &data); + if (data & 4) { + osPiWriteIo(wport, c); + break; + } + } +} + +static void* msp_proutSyncPrintf(void* str, const char* buf, int n) { + int i; + char c; + char* p; + char* q; + char xbuf[128]; + static int column = 0; + + p = &xbuf; + + for (i = 0; i < n; i++) { + c = *buf++; + + switch (c) { + case '\n': + *p++ = '\n'; + column = 0; + break; + case '\t': + do { + *p++ = ' '; + } while (++column % 8); + break; + default: + column++; + *p++ = c; + break; + } + + if (c == '\n' || (p - xbuf) > 100) { + rmonPutchar((p - xbuf) - 1); + + q = xbuf; + while (q != p) { + rmonPutchar(*q++); + } + p = xbuf; + } + } + if (p != xbuf) { + rmonPutchar((p - xbuf) - 1); + + q = xbuf; + while (q != p) { + rmonPutchar(*q++); + } + } + return (void*)1; +} + +extern u32 __kmc_pt_mode; + +void __osInitialize_msp(void) { + if (!__kmc_pt_mode) { + int (*fnc)(); + unsigned int* src; + unsigned int* dst; + unsigned int monadr; + volatile unsigned int* mon; + volatile unsigned int* stat; + + stat = (unsigned*)0xbff08004; + mon = (unsigned*)0xBFF00000; + if (*mon != 0x4B4D4300) { + return; + } + + src = (unsigned*)__ptExceptionPreamble; + dst = (unsigned*)E_VEC; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + src += 2; + dst += 2; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + + osWritebackDCache(E_VEC, 0x24); + osInvalICache(E_VEC, 0x24); + + __kmc_pt_mode = TRUE; + + if ((*stat & 0x10) == 0) { + monadr = *(mon + 1); + if (monadr != 0xBFF00000) { + unsigned int* src; + unsigned int* dst = monadr | 0x20000000; + unsigned int ct = 0x2000 / 4; + + src = 0xBFF00000; + + while (ct != 0) { + *dst++ = *src++; + ct--; + } + } + fnc = monadr + 8; + fnc(0x4B4D4300, 0); + } + __printfunc = msp_proutSyncPrintf; + } +} + +int __checkHardware_msp(void) { + volatile unsigned int* mon = (unsigned*)0xBFF00000; + + if (*mon == 0x4B4D4300) { + mon = (unsigned*)0xBFF00010; + + if (*mon == 0) { + return TRUE; + } else { + return FALSE; + } + } else { + return FALSE; + } +} + +#endif diff --git a/lib/ultralib/src/os/initrdb.c b/lib/ultralib/src/os/initrdb.c new file mode 100644 index 0000000..5537eb1 --- /dev/null +++ b/lib/ultralib/src/os/initrdb.c @@ -0,0 +1,31 @@ +#ifndef _FINALROM +#include "PR/rdb.h" +#include "PR/os_internal.h" + +rdbPacket* __osRdb_IP6_Data; +u32 __osRdb_IP6_Size; +u32 __osRdb_IP6_Ct; +u32 __osRdb_IP6_CurWrite; +u32 __osRdb_IP6_CurSend; + +void osInitRdb(u8* sendBuf, u32 sendSize) { + u32 mask; + + sendSize /= 4; + + if (((u32)sendBuf & 3) != 0) { + sendBuf = ((u32)sendBuf & 3) + 4; + sendSize--; + } + mask = __osDisableInt(); + + __osRdb_IP6_Data = sendBuf; + __osRdb_IP6_Size = sendSize; + __osRdb_IP6_Ct = 0; + __osRdb_IP6_CurWrite = 0; + __osRdb_IP6_CurSend = 0; + + __osRestoreInt(mask); +} + +#endif diff --git a/lib/ultralib/src/os/interrupt.s b/lib/ultralib/src/os/interrupt.s new file mode 100644 index 0000000..01efe1a --- /dev/null +++ b/lib/ultralib/src/os/interrupt.s @@ -0,0 +1,52 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" +#include "PR/os_version.h" + +.text +.set noreorder +LEAF(__osDisableInt) +#if BUILD_VERSION >= VERSION_J + la t2, __OSGlobalIntMask + lw t3, (t2) + andi t3, 0xFF00 + mfc0 t0, C0_SR + and t1, t0, ~SR_IE + mtc0 t1, C0_SR + andi v0, t0, SR_IE + lw t0, (t2) + andi t0, 0xFF00 + beq t0, t3, No_Change_Global_Int + la t2, __osRunningThread # this is intentionally a macro in the branch delay slot + lw t1, 280(t2) + andi t2, t1, 0xFF00 + and t2, t0 + and t1, 0xFFFF00FF + or t1, t2 + and t1, -2 + mtc0 t1, $12 + nop + nop +No_Change_Global_Int: + jr ra + nop +#else + mfc0 t0, C0_SR + and t1, t0, ~SR_IE + mtc0 t1, C0_SR + andi v0, t0, SR_IE + nop + jr ra + nop +#endif +END(__osDisableInt) + +LEAF(__osRestoreInt) + mfc0 t0, C0_SR + or t0, t0, a0 + mtc0 t0, C0_SR + nop + nop + jr ra + nop +END(__osRestoreInt) diff --git a/lib/ultralib/src/os/invaldcache.s b/lib/ultralib/src/os/invaldcache.s new file mode 100644 index 0000000..ea6a657 --- /dev/null +++ b/lib/ultralib/src/os/invaldcache.s @@ -0,0 +1,58 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(osInvalDCache) + blez a1, 3f + li t3, DCACHE_SIZE + bgeu a1, t3, 4f + + + move t0, a0 + addu t1, a0, a1 + bgeu t0, t1, 3f + + + addiu t1, t1, -DCACHE_LINESIZE + andi t2, t0, DCACHE_LINEMASK + beqz t2, 1f + + + subu t0, t0, t2 + CACHE((C_HWBINV|CACH_PD), (t0)) + bgeu t0, t1, 3f + + + addiu t0, t0, DCACHE_LINESIZE +1: + andi t2, t1, DCACHE_LINEMASK + beqz t2, 2f + + subu t1, t1, t2 + CACHE((C_HWBINV|CACH_PD), 0x10(t1)) + bltu t1, t0, 3f + +2: + CACHE((C_HINV|CACH_PD), (t0)) + .set noreorder + bltu t0, t1, 2b + addiu t0, t0, DCACHE_LINESIZE + .set reorder +3: + jr ra + +4: + li t0, KUSIZE + addu t1, t0, t3 + addiu t1, t1, -DCACHE_LINESIZE +5: + CACHE((C_IINV|CACH_PD), (t0)) + .set noreorder + bltu t0, t1, 5b + addiu t0, t0, DCACHE_LINESIZE + .set reorder + + jr ra + +END(osInvalDCache) diff --git a/lib/ultralib/src/os/invalicache.s b/lib/ultralib/src/os/invalicache.s new file mode 100644 index 0000000..f5ceb58 --- /dev/null +++ b/lib/ultralib/src/os/invalicache.s @@ -0,0 +1,41 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(osInvalICache) + blez a1, 2f + + li t3, ICACHE_SIZE + bgeu a1, t3, 3f + + move t0, a0 + addu t1, a0, a1 + bgeu t0, t1, 2f + + addiu t1, t1, -ICACHE_LINESIZE + andi t2, t0, ICACHE_LINEMASK + subu t0, t0, t2 +1: + CACHE((C_HINV|CACH_PI), (t0)) + .set noreorder + bltu t0, t1, 1b + addiu t0, t0, ICACHE_LINESIZE + .set reorder +2: + jr ra + +3: + li t0, KUSIZE + addu t1, t0, t3 + addiu t1, t1, -ICACHE_LINESIZE +4: + CACHE((C_IINV|CACH_PI), (t0)) + .set noreorder + bltu t0, t1, 4b + addiu t0, t0, ICACHE_LINESIZE + .set reorder + + jr ra + +END(osInvalICache) diff --git a/lib/ultralib/src/os/jammesg.c b/lib/ultralib/src/os/jammesg.c new file mode 100644 index 0000000..cef68da --- /dev/null +++ b/lib/ultralib/src/os/jammesg.c @@ -0,0 +1,37 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" + +s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) { + register u32 saveMask; + +#ifdef _DEBUG + if ((flag != OS_MESG_NOBLOCK) && (flag != OS_MESG_BLOCK)) { + __osError(ERR_OSJAMMESG, 1, flag); + return -1; + } +#endif + + saveMask = __osDisableInt(); + + while (mq->validCount >= mq->msgCount) { + if (flag == OS_MESG_BLOCK) { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } else { + __osRestoreInt(saveMask); + return -1; + } + } + + mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount; + mq->msg[mq->first] = msg; + mq->validCount++; + + if (mq->mtqueue->next != NULL) { + osStartThread(__osPopThread(&mq->mtqueue)); + } + + __osRestoreInt(saveMask); + return 0; +} diff --git a/lib/ultralib/src/os/maptlb.s b/lib/ultralib/src/os/maptlb.s new file mode 100644 index 0000000..20125b6 --- /dev/null +++ b/lib/ultralib/src/os/maptlb.s @@ -0,0 +1,111 @@ +#include "PR/ultraerror.h" +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +#define index a0 +#define pm a1 +#define vaddr a2 +#define evenpaddr a3 +#define oddpaddr 16(sp) +#define asid 20(sp) +.text +.set noreorder +LEAF(osMapTLB) +#if defined (_DEBUG) && defined (__sgi) + bgez index, 1f + nop + b 2f + nop +1: + li t0, 0x1F +.set noat + slt AT, index, t0 + bnez AT, 3f + nop +.set at +2: + move a2, a0 + li a0, ERR_OSMAPTLB_INDEX + li a1, 1 + j __osError + nop + +3: + lw t0, asid + li t1, -1 +.set noat + slt AT, t0, t1 + beqz AT, 4f + nop +.set at + b 5f + nop +4: + li t1, 0xFF +.set noat + slt AT, t1, t0 + beqz AT, 6f + nop +.set at +5: + move a2, t0 + li a0, ERR_OSMAPTLB_ASID + li a1, 1 + j __osError + nop +6: +.set reorder +#endif + STAY2(mfc0 t0, C0_ENTRYHI) + STAY2(mtc0 index, C0_INX) + STAY2(mtc0 pm, C0_PAGEMASK) +.set noreorder + lw t1, asid + beq t1, -1, 7f + li ta0, TLBLO_G + li t2, TLBLO_NONCOHRNT | TLBLO_D | TLBLO_V + b 8f + or vaddr, vaddr, t1 +.set reorder + +7: + li t2, TLBLO_NONCOHRNT | TLBLO_D | TLBLO_V | TLBLO_G +8: + STAY2(mtc0 vaddr, C0_ENTRYHI) + beq evenpaddr, -1, 9f + #nop + srl t3, evenpaddr, TLBLO_PFNSHIFT + or t3, t3, t2 + STAY2(mtc0 t3, C0_ENTRYLO0) + b 10f + #nop +9: + STAY2(mtc0 ta0, C0_ENTRYLO0) +10: + lw t3, oddpaddr + beq t3, -1, 11f + #nop + srl t3, t3, TLBLO_PFNSHIFT + or t3, t3, t2 + STAY2(mtc0 t3, C0_ENTRYLO1) + b 12f + #nop +11: + STAY2(mtc0 ta0, C0_ENTRYLO1) + bne evenpaddr, -1, 12f + #nop + li t3, K0BASE + STAY2(mtc0 t3, C0_ENTRYHI) +12: + .set noreorder + nop + tlbwi + nop + nop + nop + nop + STAY2(mtc0 t0, C0_ENTRYHI) + jr ra + #nop +END(osMapTLB) diff --git a/lib/ultralib/src/os/maptlbrdb.s b/lib/ultralib/src/os/maptlbrdb.s new file mode 100644 index 0000000..c004362 --- /dev/null +++ b/lib/ultralib/src/os/maptlbrdb.s @@ -0,0 +1,30 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +.set noreorder +LEAF(osMapTLBRdb) + mfc0 t0, C0_ENTRYHI + li t1, 31 + mtc0 t1, C0_INX + mtc0 zero, C0_PAGEMASK /*4k*/ + li t2, TLBLO_UNCACHED | TLBLO_D | TLBLO_V | TLBLO_G + li t1, K2BASE + mtc0 t1, C0_ENTRYHI + li t1, KUSIZE + srl t3, t1,TLBLO_PFNSHIFT + or t3, t3,t2 + mtc0 t3, C0_ENTRYLO0 + li t1, TLBLO_G + mtc0 t1, C0_ENTRYLO1 + nop + tlbwi + nop + nop + nop + nop + mtc0 t0, C0_ENTRYHI + jr ra + nop +END(osMapTLBRdb) diff --git a/lib/ultralib/src/os/osint.h b/lib/ultralib/src/os/osint.h new file mode 100644 index 0000000..b73b609 --- /dev/null +++ b/lib/ultralib/src/os/osint.h @@ -0,0 +1,58 @@ +#ifndef _OSINT_H +#define _OSINT_H +#include "PR/os_internal.h" +typedef struct __OSEventState +{ + OSMesgQueue *messageQueue; + OSMesg message; +} __OSEventState; +extern struct __osThreadTail +{ + OSThread *next; + OSPri priority; +} __osThreadTail; + +//maybe should be in exceptasm.h? +extern void __osEnqueueAndYield(OSThread **); +extern void __osDequeueThread(OSThread **, OSThread *); +extern void __osEnqueueThread(OSThread **, OSThread *); +extern OSThread *__osPopThread(OSThread **); +extern void __osDispatchThread(void); +extern void __osCleanupThread(void); + +extern void __osSetTimerIntr(OSTime); +extern OSTime __osInsertTimer(OSTimer *); +extern void __osTimerInterrupt(void); +extern u32 __osProbeTLB(void *); +extern int __osSpDeviceBusy(void); + +extern OSThread *__osRunningThread; +extern OSThread *__osActiveQueue; +extern OSThread *__osFaultedThread; +extern OSThread *__osRunQueue; + +extern OSTimer *__osTimerList; +extern OSTimer __osBaseTimer; +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; +extern u32 __osViIntrCount; +extern u32 __osTimerCounter; +extern u32 __osShutdown; + +extern OSMesgQueue __osProfTimerQ; +extern OSProf *__osProfileList; +extern OSProf *__osProfileListEnd; +extern u32 __osProfileOverflowBin; + +extern __OSEventState __osEventStateTab[]; + + +extern void __osTimerServicesInit(void); +extern s32 __osAiDeviceBusy(void); +extern int __osDpDeviceBusy(void); + +#ifndef _FINALROM +extern void* __printfunc; +#endif + +#endif diff --git a/lib/ultralib/src/os/parameters.s b/lib/ultralib/src/os/parameters.s new file mode 100644 index 0000000..450af31 --- /dev/null +++ b/lib/ultralib/src/os/parameters.s @@ -0,0 +1,17 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +ABS(leoBootID, 0x800001a0) +ABS(osTvType, 0x80000300) +ABS(osRomType, 0x80000304) +ABS(osRomBase, 0x80000308) +ABS(osResetType, 0x8000030c) +ABS(osCicId, 0x80000310) +ABS(osVersion, 0x80000314) +ABS(osMemSize, 0x80000318) +ABS(osAppNMIBuffer, 0x8000031c) + +.space 0x60 +/* padded to 0x60 in the object file */ diff --git a/lib/ultralib/src/os/physicaltovirtual.c b/lib/ultralib/src/os/physicaltovirtual.c new file mode 100644 index 0000000..6fbb9c3 --- /dev/null +++ b/lib/ultralib/src/os/physicaltovirtual.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "PR/R4300.h" + +void* osPhysicalToVirtual(u32 addr) { + return (void*)PHYS_TO_K0(addr); +} diff --git a/lib/ultralib/src/os/probetlb.s b/lib/ultralib/src/os/probetlb.s new file mode 100644 index 0000000..237db23 --- /dev/null +++ b/lib/ultralib/src/os/probetlb.s @@ -0,0 +1,54 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +.set noreorder +LEAF(__osProbeTLB) + mfc0 t0, C0_ENTRYHI + andi t1, t0, TLBHI_PIDMASK + and t2, a0, -8192 # This also works: (TLBHI_VPN2MASK << 32) >> 32 + or t1, t1, t2 + mtc0 t1, C0_ENTRYHI + nop + nop + nop + tlbp + nop + nop + mfc0 t3, C0_INX + and t3, t3, TLBINX_PROBE + bnez t3, 3f + nop + tlbr + nop + nop + nop + mfc0 t3, C0_PAGEMASK + addi t3, t3, DCACHE_SIZE + srl t3, t3, 0x1 + and ta0, t3, a0 + bnez ta0, 1f + addi t3, t3,-1 + mfc0 v0, C0_ENTRYLO0 + b 2f + nop +1: + mfc0 v0, C0_ENTRYLO1 +2: + andi ta1, v0,TLBLO_V + beqz ta1, 3f + nop + and v0, v0, TLBLO_PFNMASK + sll v0, v0, TLBLO_PFNSHIFT + and ta1, a0, t3 + add v0, v0, ta1 + b 4f + nop +3: + li v0, -1 +4: + mtc0 t0, C0_ENTRYHI + jr ra + nop +END(__osProbeTLB) diff --git a/lib/ultralib/src/os/rdbsend.c b/lib/ultralib/src/os/rdbsend.c new file mode 100644 index 0000000..0dc111e --- /dev/null +++ b/lib/ultralib/src/os/rdbsend.c @@ -0,0 +1,76 @@ +#include "PR/os_internal.h" +#include "PR/rdb.h" +#include "PR/R4300.h" + +#ifndef _FINALROM +extern rdbPacket* __osRdb_IP6_Data; +extern u32 __osRdb_IP6_Size; +extern u32 __osRdb_IP6_Ct; +extern u32 __osRdb_IP6_CurWrite; + +u32 __osRdb_IP6_Empty = 1; + +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +u32 __osRdbSend(u8* buf, u32 size, u32 type) { + rdbPacket* pPtr; + rdbPacket pkt; + u32 len; + u32 c; + u32 inCt = 0; + u32 needFirst = 0; + u32 mask; + u32 sent = 0; + + mask = __osDisableInt(); + + if (__osRdb_IP6_Empty != 0) { + __osRdb_IP6_Empty = 0; + pkt.type = type; + + len = MIN(size, sizeof(pkt.buf)); + + pkt.length = len; + + c = 0; + while (c < len) { + pkt.buf[c++] = buf[inCt++]; + } + + size -= len; + sent = len; + needFirst = 1; + } + + while (size != 0 && __osRdb_IP6_Ct < __osRdb_IP6_Size) { + len = MIN(size, sizeof(pPtr->buf)); + + pPtr = &__osRdb_IP6_Data[__osRdb_IP6_CurWrite]; + + pPtr->type = type; + pPtr->length = len; + + c = 0; + while (c < len) { + pPtr->buf[c++] = buf[inCt++]; + } + + __osRdb_IP6_CurWrite++; + if (__osRdb_IP6_CurWrite >= __osRdb_IP6_Size) { + __osRdb_IP6_CurWrite = 0; + } + + __osRdb_IP6_Ct++; + size -= len; + sent += len; + } + + if (needFirst) { + *(u32*)RDB_BASE_REG = *(u32*)&pkt; + } + __osRestoreInt(mask); + + return sent; +} + +#endif diff --git a/lib/ultralib/src/os/recvmesg.c b/lib/ultralib/src/os/recvmesg.c new file mode 100644 index 0000000..043ed21 --- /dev/null +++ b/lib/ultralib/src/os/recvmesg.c @@ -0,0 +1,40 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" + +s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags) { + register u32 saveMask; + +#ifdef _DEBUG + if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { + __osError(ERR_OSRECVMESG, 1, flags); + return -1; + } +#endif + + saveMask = __osDisableInt(); + + while (MQ_IS_EMPTY(mq)) { + if (flags == OS_MESG_NOBLOCK) { + __osRestoreInt(saveMask); + return -1; + } else { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->mtqueue); + } + } + + if (msg != NULL) { + *msg = mq->msg[mq->first]; + } + + mq->first = (mq->first + 1) % mq->msgCount; + mq->validCount--; + + if (mq->fullqueue->next != NULL) { + osStartThread(__osPopThread(&mq->fullqueue)); + } + + __osRestoreInt(saveMask); + return 0; +} diff --git a/lib/ultralib/src/os/resetglobalintmask.c b/lib/ultralib/src/os/resetglobalintmask.c new file mode 100644 index 0000000..780da7c --- /dev/null +++ b/lib/ultralib/src/os/resetglobalintmask.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" + +void __osResetGlobalIntMask(OSHWIntr mask) { + register u32 saveMask = __osDisableInt(); + + __OSGlobalIntMask &= ~(mask & ~OS_IM_RCP); + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/sendmesg.c b/lib/ultralib/src/os/sendmesg.c new file mode 100644 index 0000000..19cf3de --- /dev/null +++ b/lib/ultralib/src/os/sendmesg.c @@ -0,0 +1,38 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" + +s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags) { + register u32 saveMask; + register s32 last; + +#ifdef _DEBUG + if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { + __osError(ERR_OSSENDMESG, 1, flags); + return -1; + } +#endif + + saveMask = __osDisableInt(); + + while (MQ_IS_FULL(mq)) { + if (flags == OS_MESG_BLOCK) { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } else { + __osRestoreInt(saveMask); + return -1; + } + } + + last = (mq->first + mq->validCount) % mq->msgCount; + mq->msg[last] = msg; + mq->validCount++; + + if (mq->mtqueue->next != NULL) { + osStartThread(__osPopThread(&mq->mtqueue)); + } + + __osRestoreInt(saveMask); + return 0; +} diff --git a/lib/ultralib/src/os/setcause.s b/lib/ultralib/src/os/setcause.s new file mode 100644 index 0000000..52e4950 --- /dev/null +++ b/lib/ultralib/src/os/setcause.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osSetCause) + STAY2(mtc0 a0, C0_CAUSE) + jr ra +END(__osSetCause) diff --git a/lib/ultralib/src/os/setcompare.s b/lib/ultralib/src/os/setcompare.s new file mode 100644 index 0000000..dec29a2 --- /dev/null +++ b/lib/ultralib/src/os/setcompare.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osSetCompare) + STAY2(mtc0 a0, C0_COMPARE) + jr ra +END(__osSetCompare) diff --git a/lib/ultralib/src/os/setconfig.s b/lib/ultralib/src/os/setconfig.s new file mode 100644 index 0000000..4f062bd --- /dev/null +++ b/lib/ultralib/src/os/setconfig.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osSetConfig) + STAY2(mtc0 a0, C0_CONFIG) + jr ra +END(__osSetConfig) diff --git a/lib/ultralib/src/os/setcount.s b/lib/ultralib/src/os/setcount.s new file mode 100644 index 0000000..f94f1d2 --- /dev/null +++ b/lib/ultralib/src/os/setcount.s @@ -0,0 +1,9 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osSetCount) + STAY2(mtc0 a0, C0_COUNT) + jr ra +END(__osSetCount) diff --git a/lib/ultralib/src/os/seterrorhandler.c b/lib/ultralib/src/os/seterrorhandler.c new file mode 100644 index 0000000..4e839e8 --- /dev/null +++ b/lib/ultralib/src/os/seterrorhandler.c @@ -0,0 +1,10 @@ +#include "PR/ultraerror.h" + +extern OSErrorHandler __osErrorHandler; + +OSErrorHandler osSetErrorHandler(OSErrorHandler handler) { + OSErrorHandler oldHandler = __osErrorHandler; + + __osErrorHandler = handler; + return oldHandler; +} diff --git a/lib/ultralib/src/os/seteventmesg.c b/lib/ultralib/src/os/seteventmesg.c new file mode 100644 index 0000000..f59308c --- /dev/null +++ b/lib/ultralib/src/os/seteventmesg.c @@ -0,0 +1,39 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" + +__OSEventState __osEventStateTab[OS_NUM_EVENTS] ALIGNED(8); +#if BUILD_VERSION >= VERSION_J +u32 __osPreNMI = FALSE; +#endif + +void osSetEventMesg(OSEvent event, OSMesgQueue* mq, OSMesg msg) { + register u32 saveMask; + __OSEventState* es; + +#ifdef _DEBUG + if (event >= OS_NUM_EVENTS) { + __osError(ERR_OSSETEVENTMESG, 1, event); + return; + } +#endif + + saveMask = __osDisableInt(); + + es = &__osEventStateTab[event]; + + es->messageQueue = mq; + es->message = msg; + +#if BUILD_VERSION >= VERSION_J + if (event == OS_EVENT_PRENMI) { + if (__osShutdown && !__osPreNMI) { + osSendMesg(mq, msg, OS_MESG_NOBLOCK); + } + __osPreNMI = TRUE; + } +#endif + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/setfpccsr.s b/lib/ultralib/src/os/setfpccsr.s new file mode 100644 index 0000000..caeccaf --- /dev/null +++ b/lib/ultralib/src/os/setfpccsr.s @@ -0,0 +1,10 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osSetFpcCsr) + STAY2(cfc1 v0, fcr31) + STAY2(ctc1 a0, fcr31) + jr ra +END(__osSetSR) # @bug: Should be __osSetFpcCsr diff --git a/lib/ultralib/src/os/setglobalintmask.c b/lib/ultralib/src/os/setglobalintmask.c new file mode 100644 index 0000000..a718980 --- /dev/null +++ b/lib/ultralib/src/os/setglobalintmask.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" + +void __osSetGlobalIntMask(OSHWIntr mask) { + register u32 saveMask = __osDisableInt(); + + __OSGlobalIntMask |= mask; + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/sethwinterrupt.c b/lib/ultralib/src/os/sethwinterrupt.c new file mode 100644 index 0000000..9aafe1b --- /dev/null +++ b/lib/ultralib/src/os/sethwinterrupt.c @@ -0,0 +1,32 @@ +#include "PR/os_internal.h" + +// A stack frame was added to hardware interrupt handlers in 2.0J +#if BUILD_VERSION >= VERSION_J + +struct __osHwInt { + s32 (*handler)(void); + void* stackEnd; +}; + +extern struct __osHwInt __osHwIntTable[]; + +void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* stackEnd) { + register u32 saveMask = __osDisableInt(); + + __osHwIntTable[interrupt].handler = handler; + __osHwIntTable[interrupt].stackEnd = stackEnd; + __osRestoreInt(saveMask); +} + +#else + +extern struct s32 (*__osHwIntTable[])(void); + +void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void)) { + register u32 saveMask = __osDisableInt(); + + __osHwIntTable[interrupt] = handler; + __osRestoreInt(saveMask); +} + +#endif diff --git a/lib/ultralib/src/os/setintmask.s b/lib/ultralib/src/os/setintmask.s new file mode 100644 index 0000000..f19ed17 --- /dev/null +++ b/lib/ultralib/src/os/setintmask.s @@ -0,0 +1,124 @@ +#include "PR/R4300.h" +#include "PR/rcp.h" +#include "PR/os.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +#define MI_INTR_MASK ((1 << 6) - 1) + +.globl __osRcpImTable + +.text +.set noreorder +LEAF(osSetIntMask) + mfc0 ta0, C0_SR + + andi v0, ta0, OS_IM_CPU + + la t0, __OSGlobalIntMask + lw t3, 0(t0) + + xor t0, t3,-1 + andi t0, t0,(SR_IMASK) + or v0, v0,t0 + + lw t2, PHYS_TO_K1(MI_INTR_MASK_REG) + beqz t2, 1f + srl t1, t3,0x10 + + xor t1, t1,-1 + andi t1, t1, MI_INTR_MASK + or t2, t2,t1 +1: + sll t2, t2,0x10 + or v0, v0,t2 + + and t0, a0, MI_INTR_MASK<<0x10 + and t0, t0,t3 + srl t0, t0,0xf + lhu t2, __osRcpImTable(t0) + sw t2, PHYS_TO_K1(MI_INTR_MASK_REG) + + andi t0, a0, OS_IM_CPU + andi t1, t3, SR_IMASK + and t0, t0,t1 + + and ta0, ta0, ~SR_IMASK + or ta0, ta0,t0 + + mtc0 ta0, C0_SR + nop + nop + jr ra + nop +END(osSetIntMask) + +.rdata +EXPORT(__osRcpImTable) +/* LUT to convert between MI_INTR and MI_INTR_MASK */ +/* MI_INTR is status for each interrupt whereas */ +/* MI_INTR_MASK has seperate bits for set/clr */ +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_CLR_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_CLR_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_CLR_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_CLR_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_CLR_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP +.half MI_INTR_MASK_SET_SP | MI_INTR_MASK_SET_SI | MI_INTR_MASK_SET_AI | MI_INTR_MASK_SET_VI | MI_INTR_MASK_SET_PI | MI_INTR_MASK_SET_DP diff --git a/lib/ultralib/src/os/setpiinterrupt.c b/lib/ultralib/src/os/setpiinterrupt.c new file mode 100644 index 0000000..1af72b5 --- /dev/null +++ b/lib/ultralib/src/os/setpiinterrupt.c @@ -0,0 +1,16 @@ +#include "PR/os_internal.h" + +struct __osHwInt { + s32 (*handler)(void); + void* stackEnd; +}; + +extern struct __osHwInt __osPiIntTable; + +void __osSetPIIntrRoutine(struct __osHwInt* ir) { + register u32 saveMask = __osDisableInt(); + + __osPiIntTable.handler = ir->handler; + __osPiIntTable.stackEnd = ir->stackEnd; + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/setsr.s b/lib/ultralib/src/os/setsr.s new file mode 100644 index 0000000..d7d98fa --- /dev/null +++ b/lib/ultralib/src/os/setsr.s @@ -0,0 +1,10 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osSetSR) + STAY2(mtc0 a0, C0_SR) + NOP + jr ra +END(__osSetSR) diff --git a/lib/ultralib/src/os/setthreadpri.c b/lib/ultralib/src/os/setthreadpri.c new file mode 100644 index 0000000..d836323 --- /dev/null +++ b/lib/ultralib/src/os/setthreadpri.c @@ -0,0 +1,36 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" + +void osSetThreadPri(OSThread* t, OSPri pri) { + register u32 saveMask; + +#ifdef _DEBUG + if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { + __osError(ERR_OSSETTHREADPRI, 1, pri); + return; + } +#endif + + saveMask = __osDisableInt(); + + if (t == NULL) { + t = __osRunningThread; + } + + if (t->priority != pri) { + t->priority = pri; + + if (t != __osRunningThread && t->state != OS_STATE_STOPPED) { + __osDequeueThread(t->queue, t); + __osEnqueueThread(t->queue, t); + } + + if (__osRunningThread->priority < __osRunQueue->priority) { + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + } + } + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/settime.c b/lib/ultralib/src/os/settime.c new file mode 100644 index 0000000..b7d14e3 --- /dev/null +++ b/lib/ultralib/src/os/settime.c @@ -0,0 +1,16 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" +#include "../io/viint.h" + +void osSetTime(OSTime time) { + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSSETTIME, 0); + return; + } +#endif + + __osCurrentTime = time; +} diff --git a/lib/ultralib/src/os/settimer.c b/lib/ultralib/src/os/settimer.c new file mode 100644 index 0000000..252f63c --- /dev/null +++ b/lib/ultralib/src/os/settimer.c @@ -0,0 +1,56 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" +#include "../io/viint.h" + +int osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg) { + OSTime time; +#if BUILD_VERSION >= VERSION_K + OSTimer* next; + u32 count; + u32 value; + u32 saveMask; +#endif + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSSETTIMER, 0); + return 0; + } +#endif + + t->next = NULL; + t->prev = NULL; + t->interval = interval; + t->value = (countdown != 0) ? countdown : interval; + t->mq = mq; + t->msg = msg; + +#if BUILD_VERSION >= VERSION_K + saveMask = __osDisableInt(); + if (__osTimerList->next == __osTimerList) { + + } else { + next = __osTimerList->next; + count = osGetCount(); + value = count - __osTimerCounter; + + if (value < next->value) { + next->value -= value; + } else { + next->value = 1; + } + } + + time = __osInsertTimer(t); + __osSetTimerIntr(__osTimerList->next->value); + __osRestoreInt(saveMask); +#else + time = __osInsertTimer(t); + if (__osTimerList->next == t) { + __osSetTimerIntr(time); + } +#endif + + return 0; +} diff --git a/lib/ultralib/src/os/settlbasid.s b/lib/ultralib/src/os/settlbasid.s new file mode 100644 index 0000000..13a17e8 --- /dev/null +++ b/lib/ultralib/src/os/settlbasid.s @@ -0,0 +1,32 @@ +#include "PR/ultraerror.h" +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(osSetTLBASID) +#if defined (_DEBUG) && defined (__sgi) +.set noreorder + bgez a0, 1f + nop + b 2f + nop +1: + li t1, 0xFF +.set noat + slt AT, t1, a0 + beqz AT, 3f + nop +.set at +2: + move a2, a0 + li a0, ERR_OSSETTLBASID + li a1, 1 + j __osError + nop +3: +.set reorder +#endif + STAY2(mtc0 a0, C0_ENTRYHI) + jr ra +END(osSetTLBASID) diff --git a/lib/ultralib/src/os/setwatchlo.s b/lib/ultralib/src/os/setwatchlo.s new file mode 100644 index 0000000..91cc58e --- /dev/null +++ b/lib/ultralib/src/os/setwatchlo.s @@ -0,0 +1,10 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(__osSetWatchLo) + STAY2(mtc0 a0, C0_WATCHLO) + NOP + jr ra +END(__osSetWatchLo) diff --git a/lib/ultralib/src/os/startthread.c b/lib/ultralib/src/os/startthread.c new file mode 100644 index 0000000..2ce1546 --- /dev/null +++ b/lib/ultralib/src/os/startthread.c @@ -0,0 +1,39 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" + +void osStartThread(OSThread* t) { + register u32 saveMask = __osDisableInt(); + + switch (t->state) { + case OS_STATE_WAITING: + t->state = OS_STATE_RUNNABLE; + __osEnqueueThread(&__osRunQueue, t); + break; + case OS_STATE_STOPPED: + if (t->queue == NULL || t->queue == &__osRunQueue) { + t->state = OS_STATE_RUNNABLE; + __osEnqueueThread(&__osRunQueue, t); + } else { + t->state = OS_STATE_WAITING; + __osEnqueueThread(t->queue, t); + __osEnqueueThread(&__osRunQueue, __osPopThread(t->queue)); + } + break; +#ifdef _DEBUG + default: + __osError(ERR_OSSTARTTHREAD, 0); + __osRestoreInt(saveMask); + return; +#endif + } + + if (__osRunningThread == NULL) { + __osDispatchThread(); + } else if (__osRunningThread->priority < __osRunQueue->priority) { + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + } + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/stopthread.c b/lib/ultralib/src/os/stopthread.c new file mode 100644 index 0000000..9a51652 --- /dev/null +++ b/lib/ultralib/src/os/stopthread.c @@ -0,0 +1,23 @@ +#include "PR/os_internal.h" +#include "osint.h" + +void osStopThread(OSThread* t) { + register u32 saveMask = __osDisableInt(); + register u16 state; + + state = (t == NULL) ? OS_STATE_RUNNING: t->state; + + switch (state) { + case OS_STATE_RUNNING: + __osRunningThread->state = OS_STATE_STOPPED; + __osEnqueueAndYield(NULL); + break; + case OS_STATE_RUNNABLE: + case OS_STATE_WAITING: + t->state = OS_STATE_STOPPED; + __osDequeueThread(t->queue, t); + break; + } + + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/os/stoptimer.c b/lib/ultralib/src/os/stoptimer.c new file mode 100644 index 0000000..b6db1c1 --- /dev/null +++ b/lib/ultralib/src/os/stoptimer.c @@ -0,0 +1,39 @@ +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" +#include "../io/viint.h" + +int osStopTimer(OSTimer* t) { + register u32 savedMask; + OSTimer* timep; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSSTOPTIMER, 0); + return 0; + } +#endif + + if (t->next == NULL) { + return -1; + } + + savedMask = __osDisableInt(); + timep = t->next; + + if (timep != __osTimerList) { + timep->value += t->value; + } + + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + + if (__osTimerList->next == __osTimerList) { + __osSetCompare(0); + } + + __osRestoreInt(savedMask); + return 0; +} diff --git a/lib/ultralib/src/os/syncputchars.c b/lib/ultralib/src/os/syncputchars.c new file mode 100644 index 0000000..d2d5332 --- /dev/null +++ b/lib/ultralib/src/os/syncputchars.c @@ -0,0 +1,35 @@ +#include "PR/os_internal.h" +#include "PR/rdb.h" +#include "PR/rcp.h" +#include "PR/R4300.h" + +unsigned int __osRdbSendMessage = 0; +unsigned int __osRdbWriteOK = 1; + +void __osSyncPutChars(int type, int length, const char* buf) { + rdbPacket packet; + int i; + u32 mask; + + packet.type = type; + packet.length = length; + + for (i = 0; i < length; i++) { + packet.buf[i] = buf[i]; + } + + while (!__osAtomicDec(&__osRdbWriteOK)) { + ; + } + + mask = __osDisableInt(); + *(vu32*)RDB_BASE_REG = *(vu32*)&packet; + + while (!(__osGetCause() & CAUSE_IP6)) { + ; + } + + *(vu32*)RDB_READ_INTR_REG = 0; + __osRdbWriteOK++; + __osRestoreInt(mask); +} diff --git a/lib/ultralib/src/os/testhost.c b/lib/ultralib/src/os/testhost.c new file mode 100644 index 0000000..c134317 --- /dev/null +++ b/lib/ultralib/src/os/testhost.c @@ -0,0 +1,12 @@ +#include "PR/os_internal.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif diff --git a/lib/ultralib/src/os/thread.c b/lib/ultralib/src/os/thread.c new file mode 100644 index 0000000..9a4a141 --- /dev/null +++ b/lib/ultralib/src/os/thread.c @@ -0,0 +1,28 @@ +#include "PR/os_internal.h" +#include "osint.h" + +struct __osThreadTail __osThreadTail = { NULL, -1 }; +OSThread* __osRunQueue = (OSThread*)&__osThreadTail; +OSThread* __osActiveQueue = (OSThread*)&__osThreadTail; +OSThread* __osRunningThread = { 0 }; +OSThread* __osFaultedThread = { 0 }; + +void __osDequeueThread(register OSThread** queue, register OSThread* t) { + register OSThread* pred; + register OSThread* succ; + + pred = (OSThread*)queue; + succ = pred->next; + + while (succ != NULL) { + if (succ == t) { + pred->next = t->next; +#ifdef _DEBUG + t->next = NULL; +#endif + return; + } + pred = succ; + succ = pred->next; + } +} diff --git a/lib/ultralib/src/os/threadasm.h b/lib/ultralib/src/os/threadasm.h new file mode 100644 index 0000000..dfd91b6 --- /dev/null +++ b/lib/ultralib/src/os/threadasm.h @@ -0,0 +1,68 @@ +#ifndef _THREADASM_H_ +#define _THREADASM_H_ + +/* Offsets of members in the OSThread struct */ +#define THREAD_NEXT 0 +#define THREAD_PRI 4 +#define THREAD_QUEUE 8 +#define THREAD_TLNEXT 12 +#define THREAD_STATE 16 +#define THREAD_FLAGS 18 +#define THREAD_ID 20 +#define THREAD_FP 24 +#define THREAD_GP1 32 +#define THREAD_GP2 40 +#define THREAD_GP3 48 +#define THREAD_GP4 56 +#define THREAD_GP5 64 +#define THREAD_GP6 72 +#define THREAD_GP7 80 +#define THREAD_GP8 88 +#define THREAD_GP9 96 +#define THREAD_GP10 104 +#define THREAD_GP11 112 +#define THREAD_GP12 120 +#define THREAD_GP13 128 +#define THREAD_GP14 136 +#define THREAD_GP15 144 +#define THREAD_GP16 152 +#define THREAD_GP17 160 +#define THREAD_GP18 168 +#define THREAD_GP19 176 +#define THREAD_GP20 184 +#define THREAD_GP21 192 +#define THREAD_GP22 200 +#define THREAD_GP23 208 +#define THREAD_GP24 216 +#define THREAD_GP25 224 +/* k0 and k1 are reserved for the kernel */ +#define THREAD_GP28 232 +#define THREAD_GP29 240 +#define THREAD_GP30 248 +#define THREAD_GP31 256 +#define THREAD_LO 264 +#define THREAD_HI 272 +#define THREAD_SR 280 +#define THREAD_PC 284 +#define THREAD_CAUSE 288 +#define THREAD_BADVADDR 292 +#define THREAD_RCP 296 +#define THREAD_FPCSR 300 +#define THREAD_FP0 304 +#define THREAD_FP2 312 +#define THREAD_FP4 320 +#define THREAD_FP6 328 +#define THREAD_FP8 336 +#define THREAD_FP10 344 +#define THREAD_FP12 352 +#define THREAD_FP14 360 +#define THREAD_FP16 368 +#define THREAD_FP18 376 +#define THREAD_FP20 384 +#define THREAD_FP22 392 +#define THREAD_FP24 400 +#define THREAD_FP26 408 +#define THREAD_FP28 416 +#define THREAD_FP30 424 + +#endif diff --git a/lib/ultralib/src/os/timerintr.c b/lib/ultralib/src/os/timerintr.c new file mode 100644 index 0000000..10dae50 --- /dev/null +++ b/lib/ultralib/src/os/timerintr.c @@ -0,0 +1,141 @@ +#include "macros.h" +#include "PR/os_internal.h" +#include "osint.h" + +OSTime __osCurrentTime; +u32 __osBaseCounter; +u32 __osViIntrCount; +u32 __osTimerCounter; +OSTimer __osBaseTimer; +OSTimer* __osTimerList = &__osBaseTimer; + +#ifndef _FINALROM +OSMesgQueue __osProfTimerQ ALIGNED(8); +OSProf* __osProfileList; +OSProf* __osProfileListEnd; +u32 __osProfileOverflowBin; +#endif + +void __osTimerServicesInit(void) { + __osCurrentTime = 0; + __osBaseCounter = 0; + __osViIntrCount = 0; + __osTimerList->next = __osTimerList->prev = __osTimerList; + __osTimerList->interval = __osTimerList->value = 0; + __osTimerList->mq = NULL; + __osTimerList->msg = 0; +} + +void __osTimerInterrupt(void) { + OSTimer* t; + u32 count; + u32 elapsed_cycles; + +#ifndef _FINALROM + u32 pc; + s32 offset; + OSProf* prof = __osProfileList; +#endif + + if (__osTimerList->next == __osTimerList) { + return; + } + for (;;) { + t = __osTimerList->next; + + if (t == __osTimerList) { + __osSetCompare(0); + __osTimerCounter = 0; + break; + } + + count = osGetCount(); + elapsed_cycles = count - __osTimerCounter; + __osTimerCounter = count; + + if (elapsed_cycles < t->value) { + t->value -= elapsed_cycles; + __osSetTimerIntr(t->value); + break; + } + + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + + if (t->mq != NULL) { +#ifdef _FINALROM + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } +#else + if (t->mq != &__osProfTimerQ) { + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } else { + pc = __osRunQueue->context.pc; + for (prof = __osProfileList; prof < __osProfileListEnd; prof++) { + offset = pc - (u32)prof->text_start; + + if (offset >= 0) { + if ((s32)prof->text_end - (s32)pc > 0) { + (*(u16*)(u32)((offset >> 2) + prof->histo_base))++; + goto __ProfDone; + } + } + } + + __osProfileOverflowBin++; + } + } +#endif + + __ProfDone: + + if (t->interval != 0) { + t->value = t->interval; + __osInsertTimer(t); + } + } +} + +void __osSetTimerIntr(OSTime tim) { + OSTime NewTime; + u32 savedMask; + +#if BUILD_VERSION >= VERSION_K + if (tim < 468) { + tim = 468; + } +#endif + + savedMask = __osDisableInt(); + __osTimerCounter = osGetCount(); + NewTime = __osTimerCounter + tim; + __osSetCompare(NewTime); + __osRestoreInt(savedMask); +} + +OSTime __osInsertTimer(OSTimer* t) { + OSTimer* timep; + OSTime tim; + u32 savedMask = __osDisableInt(); + + timep = __osTimerList->next; + tim = t->value; + for (; timep != __osTimerList && tim > timep->value; timep = timep->next) { + tim -= timep->value; + } + + t->value = tim; + + if (timep != __osTimerList) { + timep->value -= tim; + } + + t->next = timep; + t->prev = timep->prev; + timep->prev->next = t; + timep->prev = t; + __osRestoreInt(savedMask); + return tim; +} diff --git a/lib/ultralib/src/os/unmaptlb.s b/lib/ultralib/src/os/unmaptlb.s new file mode 100644 index 0000000..362fd1e --- /dev/null +++ b/lib/ultralib/src/os/unmaptlb.s @@ -0,0 +1,45 @@ +#include "PR/ultraerror.h" +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +.set noreorder +LEAF(osUnmapTLB) +#if defined (_DEBUG) && defined (__sgi) + bgez a0, 1f + nop + b 2f + nop +1: + li t0, 0x1F +.set noat + slt AT, a0, t0 + bnez AT, 3f + nop +.set at +2: + move a2, a0 + li a0, ERR_OSUNMAPTLB + li a1, 1 + j __osError + nop +3: +#endif + mfc0 t0, C0_ENTRYHI + mtc0 a0, C0_INX + li t1, K0BASE + mtc0 t1, C0_ENTRYHI + mtc0 zero, C0_ENTRYLO0 + mtc0 zero, C0_ENTRYLO1 + nop + tlbwi + nop + nop + nop + nop + mtc0 t0, C0_ENTRYHI + jr ra + nop +END(osUnmapTLB) + diff --git a/lib/ultralib/src/os/unmaptlball.s b/lib/ultralib/src/os/unmaptlball.s new file mode 100644 index 0000000..6d4b264 --- /dev/null +++ b/lib/ultralib/src/os/unmaptlball.s @@ -0,0 +1,26 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +.set noreorder +LEAF(osUnmapTLBAll) + mfc0 t0, C0_ENTRYHI + li t1, NTLBENTRIES-1 /* last reserved for rdb */ + li t2, KUSIZE + mtc0 t2, C0_ENTRYHI + mtc0 zero, C0_ENTRYLO0 + mtc0 zero, C0_ENTRYLO1 +1: + mtc0 t1, C0_INX + nop + tlbwi + nop + nop + addi t1, t1,-1 + bgez t1, 1b + nop + mtc0 t0, C0_ENTRYHI + jr ra + nop +END(osUnmapTLBAll) diff --git a/lib/ultralib/src/os/virtualtophysical.c b/lib/ultralib/src/os/virtualtophysical.c new file mode 100644 index 0000000..553fe68 --- /dev/null +++ b/lib/ultralib/src/os/virtualtophysical.c @@ -0,0 +1,13 @@ +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "osint.h" + +u32 osVirtualToPhysical(void* addr) { + if (IS_KSEG0(addr)) { + return K0_TO_PHYS(addr); + } else if (IS_KSEG1(addr)) { + return K1_TO_PHYS(addr); + } else { + return __osProbeTLB(addr); + } +} diff --git a/lib/ultralib/src/os/writebackdcache.s b/lib/ultralib/src/os/writebackdcache.s new file mode 100644 index 0000000..5f5b485 --- /dev/null +++ b/lib/ultralib/src/os/writebackdcache.s @@ -0,0 +1,35 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(osWritebackDCache) + blez a1, 2f + li t3, DCACHE_SIZE + bgeu a1,t3, 3f + move t0, a0 + addu t1, a0,a1 + bgeu t0, t1, 2f + addiu t1, t1, -DCACHE_LINESIZE + andi t2, t0, DCACHE_LINEMASK + subu t0, t0,t2 +1: + .set noreorder + cache (C_HWB|CACH_PD), (t0) + bltu t0, t1, 1b + addiu t0, t0, DCACHE_LINESIZE + .set reorder +2: + jr ra +3: + li t0, KUSIZE + addu t1, t0,t3 + addiu t1, t1, -DCACHE_LINESIZE +4: + .set noreorder + cache (C_IWBINV|CACH_PD), (t0) + bltu t0, t1, 4b + addiu t0, t0, DCACHE_LINESIZE + .set reorder + jr ra +END(osWritebackDCache) diff --git a/lib/ultralib/src/os/writebackdcacheall.s b/lib/ultralib/src/os/writebackdcacheall.s new file mode 100644 index 0000000..ee8df88 --- /dev/null +++ b/lib/ultralib/src/os/writebackdcacheall.s @@ -0,0 +1,18 @@ +#include "PR/R4300.h" +#include "sys/asm.h" +#include "sys/regdef.h" + +.text +LEAF(osWritebackDCacheAll) + li t0, KUSIZE + li t2, DCACHE_SIZE + addu t1, t0,t2 + addiu t1, t1, -DCACHE_LINESIZE +1: + .set noreorder + cache (C_IWBINV | CACH_PD), (t0) + bltu t0, t1, 1b + addiu t0, t0, DCACHE_LINESIZE + .set reorder + jr ra +END(osWritebackDCacheAll) diff --git a/lib/ultralib/src/os/yieldthread.c b/lib/ultralib/src/os/yieldthread.c new file mode 100644 index 0000000..9a4dafb --- /dev/null +++ b/lib/ultralib/src/os/yieldthread.c @@ -0,0 +1,10 @@ +#include "PR/os_internal.h" +#include "osint.h" + +void osYieldThread(void) { + register u32 saveMask = __osDisableInt(); + + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + __osRestoreInt(saveMask); +} diff --git a/lib/ultralib/src/rg/free.c b/lib/ultralib/src/rg/free.c new file mode 100644 index 0000000..c426000 --- /dev/null +++ b/lib/ultralib/src/rg/free.c @@ -0,0 +1,73 @@ +#include "PR/region.h" +#include "PR/R4300.h" +#include "PR/ultraerror.h" +#include "PR/os_internal.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osFree(void* region, void* addr) { + register OSRegion* rp = region; + int i; + +#ifdef _DEBUG + assert((region != NULL) && (addr != NULL)); + if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { + __osError(ERR_OSFREE_REGION, 1, region); + return; + } +#endif + + i = ((u8*)addr - rp->r_startBufferAddress) / rp->r_bufferSize; + +#ifdef _DEBUG + if ((i < 0) || (i >= rp->r_bufferCount)) { + __osError(ERR_OSFREE_ADDR, 2, addr, region); + return; + } + + if (((unsigned char*)addr - rp->r_startBufferAddress) % (rp->r_bufferSize) != 0) { + __osError(ERR_OSFREE_ADDR, 2, addr, region); + return; + } +#endif + *(u16*)(&rp->r_startBufferAddress[i * rp->r_bufferSize]) = rp->r_freeList; + rp->r_freeList = i; +} diff --git a/lib/ultralib/src/rg/getbufcount.c b/lib/ultralib/src/rg/getbufcount.c new file mode 100644 index 0000000..d4deeba --- /dev/null +++ b/lib/ultralib/src/rg/getbufcount.c @@ -0,0 +1,57 @@ +#include "PR/region.h" +#include "PR/ultraerror.h" +#include "PR/os_internal.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osGetRegionBufCount(void* region) { + register OSRegion* rp = region; + +#ifdef _DEBUG + assert(rp != NULL); + if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { + __osError(ERR_OSGETREGIONBUFCOUNT, 1, region); + return 0; + } +#endif + return rp->r_bufferCount; +} diff --git a/lib/ultralib/src/rg/getsize.c b/lib/ultralib/src/rg/getsize.c new file mode 100644 index 0000000..2b1fb90 --- /dev/null +++ b/lib/ultralib/src/rg/getsize.c @@ -0,0 +1,57 @@ +#include "PR/region.h" +#include "PR/ultraerror.h" +#include "PR/os_internal.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osGetRegionBufSize(void* region) { + register OSRegion* rp = region; + +#ifdef _DEBUG + assert(rp != NULL); + if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { + __osError(ERR_OSGETREGIONBUFSIZE, 1, region); + return 0; + } +#endif + + return rp->r_bufferSize; +} diff --git a/lib/ultralib/src/rg/malloc.c b/lib/ultralib/src/rg/malloc.c new file mode 100644 index 0000000..59c0399 --- /dev/null +++ b/lib/ultralib/src/rg/malloc.c @@ -0,0 +1,70 @@ +#include "PR/region.h" +#include "PR/ultraerror.h" +#include "PR/os_internal.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void* osMalloc(void* region) { + register OSRegion* rp = region; + char* addr; + +#ifdef _DEBUG + assert(rp != NULL); + if (((char*)rp + ALIGN(sizeof(OSRegion), rp->r_alignSize)) != rp->r_startBufferAddress) { + __osError(ERR_OSMALLOC, 1, region); + return NULL; + } +#endif + + if (rp->r_freeList == MAX_BUFCOUNT) { + return NULL; + } + + addr = &rp->r_startBufferAddress[rp->r_freeList * rp->r_bufferSize]; + rp->r_freeList = *(u16*)addr; + return addr; +} diff --git a/lib/ultralib/src/rg/printregion.c b/lib/ultralib/src/rg/printregion.c new file mode 100644 index 0000000..6db8f18 --- /dev/null +++ b/lib/ultralib/src/rg/printregion.c @@ -0,0 +1,27 @@ +#include "os_version.h" +#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J + +#include "../os/osint.h" +#include "PR/rmon.h" +#include "PR/region.h" + +void __osPrintRegion(void* region) { + register OSRegion* rp = region; + int i; + + rmonPrintf("Region = 0x%x\n", rp); + rmonPrintf("\tstartBufferAddress = 0x%x\n", RP(startBufferAddress)); + rmonPrintf("\tendAddress = 0x%x\n", RP(endAddress)); + rmonPrintf("\tbufferSize = %d\n", RP(bufferSize)); + rmonPrintf("\tbufferCount = %d\n", RP(bufferCount)); + rmonPrintf("\tfreeList = %d\n", RP(freeList)); + rmonPrintf("\talignSize = %d\n", RP(alignSize)); + rmonPrintf("\tMemory Header Layout:\n"); + + for (i = 0; i < RP(bufferCount); i++) { + rmonPrintf("\tBuf[%d]:\tAddress: 0x%x Value: 0x%x\n", i, RP(startBufferAddress) + i * RP(bufferSize), + *(u16*)(RP(startBufferAddress) + i * RP(bufferSize))); + } +} + +#endif diff --git a/lib/ultralib/src/rg/region.c b/lib/ultralib/src/rg/region.c new file mode 100644 index 0000000..377ec9e --- /dev/null +++ b/lib/ultralib/src/rg/region.c @@ -0,0 +1,232 @@ +#include "PR/region.h" +#include "PR/ultraerror.h" +#include "os_internal_error.h" +#include "assert.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void* osCreateRegion(void* startAddress, u32 length, u32 bufferSize, u32 alignSize) { + register OSRegion* rp; + register int i; + register char* addr; + + assert(startAddress != NULL); + +#ifdef _DEBUG + if ((alignSize != 0) && (alignSize != OS_RG_ALIGN_2B) && (alignSize != OS_RG_ALIGN_4B) && + (alignSize != OS_RG_ALIGN_8B) && (alignSize != OS_RG_ALIGN_16B)) { + __osError(ERR_OSCREATEREGION_ALIGN, 1, alignSize); + return 0; + } +#endif + + if (alignSize == 0) { + alignSize = OS_RG_ALIGN_DEFAULT; + } + + rp = (OSRegion*)ALIGN(startAddress, alignSize); + length = length - ((s32)rp - (s32)startAddress); + rp->r_bufferSize = ALIGN(bufferSize, alignSize); + rp->r_bufferCount = (s32)(length - ALIGN(sizeof(OSRegion), alignSize)) / rp->r_bufferSize; + +#ifdef _DEBUG + if (rp->r_bufferCount <= 0) { + __osError(ERR_OSCREATEREGION_SIZE, 2, length, bufferSize); + return 0; + } +#endif + + if (rp->r_bufferCount > MAX_BUFCOUNT) { + rp->r_bufferCount = MAX_BUFCOUNT; + } + + rp->r_startBufferAddress = (u8*)rp + ALIGN(sizeof(OSRegion), alignSize); + rp->r_endAddress = (u8*)rp + length; + addr = rp->r_startBufferAddress; + + for (i = 0; i < rp->r_bufferCount - 1; i++) { + *((s16*)(&addr[i * rp->r_bufferSize])) = i + 1; + } + + *((u16*)(&addr[i * rp->r_bufferSize])) = BUF_FREE_WO_NEXT; + rp->r_alignSize = alignSize; + rp->r_freeList = 0; + return rp; +} diff --git a/lib/ultralib/src/rmon/rmonbrk.c b/lib/ultralib/src/rmon/rmonbrk.c new file mode 100644 index 0000000..0eb3242 --- /dev/null +++ b/lib/ultralib/src/rmon/rmonbrk.c @@ -0,0 +1,432 @@ +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "dbgproto.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "rmonint.h" + +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +#define TMP_BP 0 +#define NUM_BREAKPOINTS 16 + +typedef struct { + TVushort type; + TVushort response; + TVid threadID; + void* pc; +} TVExceptionReplyMsg; + +typedef struct { + u32* breakAddress; + u32 oldInstruction; +} BREAKINFO; + +/* first breakpoint is reserved for implementing single-stepping */ +static BREAKINFO breakpoints[NUM_BREAKPOINTS] ALIGNED(8); +/* breakpoint for alternate branch target */ +static BREAKINFO altBreak; + +static BREAKINFO RCPbreakpoints[NUM_BREAKPOINTS] ALIGNED(8); + +u8 __rmonRcpAtBreak; + +static void rmonFindFaultedThreads(void); + +static void SetTempBreakpoint(u32* addr1, u32* addr2) { + STUBBED_PRINTF(("Set temp BP at %08x", addr1)); + if (addr2 != NULL) { + STUBBED_PRINTF((" and %08x", addr2)); + } + STUBBED_PRINTF(("\n")); + + /* Save the word at the target address to be restored later */ + breakpoints[TMP_BP].oldInstruction = *addr1; + /* Install a break instruction at the target address */ + *addr1 = MIPS_BREAK(16); + osWritebackDCache(addr1, sizeof(*addr1)); + osInvalICache(addr1, sizeof(*addr1)); + breakpoints[TMP_BP].breakAddress = addr1; + + /* Also do so for an alt address if required */ + if (addr2 != NULL) { + altBreak.oldInstruction = *addr2; + *addr2 = MIPS_BREAK(16); + osWritebackDCache(addr2, sizeof(*addr2)); + osInvalICache(addr2, sizeof(*addr2)); + altBreak.breakAddress = addr2; + } +} + +static void ClearTempBreakpoint(void) { + u32 inst; + + if (breakpoints[TMP_BP].breakAddress != NULL) { + inst = *breakpoints[TMP_BP].breakAddress; + + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + STUBBED_PRINTF(("ClearTempBreak @ %08x\n", breakpoints[TMP_BP].breakAddress)); + + /* After confirming that there is a break instruction with code at the target + address, restore the original contents of the word at the target address */ + *breakpoints[TMP_BP].breakAddress = breakpoints[TMP_BP].oldInstruction; + osWritebackDCache(breakpoints[TMP_BP].breakAddress, sizeof(*breakpoints[TMP_BP].breakAddress)); + osInvalICache(breakpoints[TMP_BP].breakAddress, sizeof(*breakpoints[TMP_BP].breakAddress)); + } + breakpoints[TMP_BP].breakAddress = NULL; + } + + /* Same as above for the alt breakpoint */ + if (altBreak.breakAddress != NULL) { + inst = *altBreak.breakAddress; + + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + STUBBED_PRINTF(("ClearTempBreak @ %08x\n", altBreak.breakAddress)); + + *altBreak.breakAddress = altBreak.oldInstruction; + osWritebackDCache(altBreak.breakAddress, sizeof(*altBreak.breakAddress)); + osInvalICache(altBreak.breakAddress, sizeof(*altBreak.breakAddress)); + } + altBreak.breakAddress = NULL; + } +} + +int __rmonSetBreak(KKHeader* req) { + register KKSetBkptRequest* request = (KKSetBkptRequest*)req; + register BREAKINFO* breakBase; + register BREAKINFO* whichBreak; + register BREAKINFO* lastBreak; + KKBkptEvent reply; + + STUBBED_PRINTF(("SetBreak at %08x, method %d\n", request->addr, req->method)); + + /* Select breakpoint list */ + if (req->method == RMON_RSP) { + breakBase = RCPbreakpoints; + whichBreak = &RCPbreakpoints[1]; + lastBreak = &RCPbreakpoints[NUM_BREAKPOINTS]; + } else { + breakBase = breakpoints; + whichBreak = &breakpoints[1]; + lastBreak = &breakpoints[NUM_BREAKPOINTS]; + } + + /* Find breakpoint slot */ + for (; whichBreak < lastBreak; whichBreak++) { + if (whichBreak->breakAddress != NULL) { + if (whichBreak->breakAddress == (u32*)request->addr) { + /* Breakpoint already set here */ + break; + } + continue; + } else { + /* Empty slot */ + break; + } + } + + /* No breakpoints available */ + if (whichBreak == lastBreak) { + return TV_ERROR_NO_MORE_IDS; + } + + /* Set breakpoint if not already set */ + if (whichBreak->breakAddress == NULL) { + if (req->method == RMON_RSP) { + whichBreak->oldInstruction = __rmonReadWordAt((u32*)request->addr); + __rmonWriteWordTo((u32*)request->addr, MIPS_BREAK((whichBreak - breakBase) + NUM_BREAKPOINTS)); + } else { + whichBreak->oldInstruction = *(u32*)request->addr; + *(u32*)request->addr = MIPS_BREAK((whichBreak - breakBase) + NUM_BREAKPOINTS); + osWritebackDCache((void*)request->addr, sizeof(whichBreak->oldInstruction)); + osInvalICache((void*)request->addr, sizeof(whichBreak->oldInstruction)); + } + whichBreak->breakAddress = (u32*)request->addr; + STUBBED_PRINTF(("* (%08x) = %08x (was %08x)\n", whichBreak->breakAddress, *whichBreak->breakAddress, + whichBreak->oldInstruction)); + } + + /* Send reply */ + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->object; + reply.bp = whichBreak - breakBase; + reply.instruction = whichBreak->oldInstruction; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonListBreak(KKHeader* request UNUSED) { + STUBBED_PRINTF(("ListBreak\n")); + + return TV_ERROR_ILLEGAL_CALL; +} + +int __rmonClearBreak(KKHeader* req) { + register KKClrBkptRequest* request = (KKClrBkptRequest*)req; + register BREAKINFO* whichBreak; + KKBkptEvent reply; + u32 inst; + + STUBBED_PRINTF(("ClearBreak\n")); + + /* Check valid breakpoint index */ + if (request->bp >= NUM_BREAKPOINTS) { + return TV_ERROR_INVALID_ID; + } + + /* Clear the breakpoint, restore whatever was there before */ + if (req->method == RMON_RSP) { + whichBreak = &RCPbreakpoints[request->bp]; + + if (whichBreak->breakAddress == NULL) { + return TV_ERROR_INVALID_ID; + } + + inst = __rmonReadWordAt(whichBreak->breakAddress); + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + __rmonWriteWordTo(whichBreak->breakAddress, whichBreak->oldInstruction); + } + } else { + whichBreak = &breakpoints[request->bp]; + + if (whichBreak->breakAddress == NULL) { + return TV_ERROR_INVALID_ID; + } + + inst = *whichBreak->breakAddress; + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + *whichBreak->breakAddress = whichBreak->oldInstruction; + osWritebackDCache(whichBreak->breakAddress, sizeof(*whichBreak->breakAddress)); + osInvalICache(whichBreak->breakAddress, sizeof(*whichBreak->breakAddress)); + } + } + whichBreak->breakAddress = NULL; + + /* Send reply */ + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->object; + reply.bp = request->bp; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +u32 __rmonGetBranchTarget(int method, int thread, char* addr) { + int inst; + + if (method == RMON_RSP) { + inst = __rmonReadWordAt((u32*)addr); + } else { + inst = *(u32*)addr; + } + + switch ((inst >> 26) & 0x3F) { + case 0: /* SPECIAL */ + if (((inst >> 5) & 0x7FFF) == 0 && (inst & 0x3F) == 8) { + /* JR */ + return __rmonGetRegisterContents(method, thread, (inst >> 21) & 0x1F); + } + if (((inst >> 16) & 0x1F) == 0 && (inst & 0x7FF) == 9) { + /* JALR */ + return __rmonGetRegisterContents(method, thread, (inst >> 21) & 0x1F); + } + break; + case 1: /* REGIMM */ + switch ((inst >> 16) & 0x1F) { + case 0: /* BLTZ */ + case 1: /* BGEZ */ + case 2: /* BLTZL */ + case 3: /* BGEZL */ + case 16: /* BLTZAL */ + case 17: /* BGEZAL */ + case 18: /* BLTZALL */ + case 19: /* BGEZALL */ + return (((inst << 0x10) >> 0xE) + addr + 4); + } + break; + case 2: /* J */ + case 3: /* JAL */ + return (((u32)inst << 6) >> 4) + (((s32)((u32)addr + 4) >> 0x1C) << 0x1C); + case 4: /* BEQ */ + case 5: /* BNE */ + case 20: /* BEQL */ + case 21: /* BNEL */ + return (((inst << 0x10) >> 0xE) + addr + 4); + case 6: /* BLEZ */ + case 7: /* BGTZ */ + case 22: /* BLEZL */ + case 23: /* BGTZL */ + if (((inst >> 16) & 0x1F) == 0) { + return (((inst << 0x10) >> 0xE) + addr + 4); + } + break; + case 16: /* COP0 */ + case 17: /* COP1 */ + case 18: /* COP2 */ + case 19: /* COP3 */ + if (((inst >> 21) & 0x1F) == 8) { + switch ((inst >> 16) & 0x1F) { + case 0: /* BCzF */ + case 1: /* BCzT */ + case 2: /* BCzFL */ + case 3: /* BCzTL */ + return (((inst << 0x10) >> 0xE) + addr + 4); + } + } + break; + } + return -1; +} + +static int IsJump(u32 inst) { + switch ((inst >> 26) & 0x3F) { + case 0: /* SPECIAL */ + if (((inst >> 5) & 0x7FFF) == 0 && (inst & 0x3F) == 8) { + /* JR */ + return TRUE; + } + if (((inst >> 16) & 0x1F) == 0 && (inst & 0x7FF) == 9) { + /* JALR */ + return TRUE; + } + break; + case 2: /* J */ + case 3: /* JAL */ + return TRUE; + } + return FALSE; +} + +int __rmonSetSingleStep(int thread, u32* instptr) { + u32 branchTarget = __rmonGetBranchTarget(RMON_CPU, thread, (void*)instptr); + + STUBBED_PRINTF(("SingleStep\n")); + + if ((branchTarget & 3) != 0) { + /* no branch target, set breakpoint at next pc */ + SetTempBreakpoint(instptr + 1, NULL); + } else if (branchTarget == (u32)instptr) { + /* branch target is this instruction, can't single step here */ + return FALSE; + } else if (IsJump(*instptr) || branchTarget == (u32)(instptr + 2)) { + /* unconditional branch, set at branch target */ + SetTempBreakpoint((u32*)branchTarget, NULL); + } else { + /* set two breakpoints for handling conditional branches */ + SetTempBreakpoint((u32*)branchTarget, instptr + 2); + } + return TRUE; +} + +void __rmonGetExceptionStatus(KKStatusEvent* reply) { + reply->status.flags = OS_STATE_STOPPED; + reply->status.why = 2; + reply->status.what = 0; + reply->status.rv = 0; + reply->status.info.major = 2; + reply->status.info.minor = 4; + reply->header.code = KK_CODE_THREAD_STATUS; + reply->header.error = TV_ERROR_NO_ERROR; + reply->header.length = sizeof(*reply); +} + +#define FAULT_BREAKNUM (NUM_BREAKPOINTS - 1) + +static void rmonSendBreakMessage(s32 whichThread, int breakNumber) { + KKStatusEvent reply; + + STUBBED_PRINTF(("Break %d in thread %d\n", breakNumber, whichThread)); + + /* Build thread exception status */ + __rmonGetThreadStatus(RMON_CPU, (whichThread != 0) ? whichThread : RMON_TID_NOTHREAD, &reply); + __rmonGetExceptionStatus(&reply); + + if (breakNumber == FAULT_BREAKNUM) { + /* Hit fault */ + reply.status.info.major = 1; + reply.status.info.minor = 2; + } + if (breakNumber < NUM_BREAKPOINTS) { + breakNumber = 0; + } else { + breakNumber -= NUM_BREAKPOINTS; + } + if (breakNumber != 0) { + /* Break not set by debugger, or set during single-step */ + reply.status.instr = MIPS_BREAK_OPCODE; + } + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_EXCEPTION); +} + +void __rmonHitBreak(void) { + STUBBED_PRINTF(("HitBreak\n")); + + /* Stop all user threads and report faulted threads */ + ClearTempBreakpoint(); + __rmonStopUserThreads(0); + rmonFindFaultedThreads(); +} + +void __rmonHitSpBreak(void) { + KKStatusEvent exceptionReply; + + STUBBED_PRINTF(("Hit SP Break\n")); + + /* Rewind RSP PC by one instruction to return to the location of the break instruction */ + __rmonWriteWordTo((u32*)SP_PC_REG, __rmonReadWordAt((u32*)SP_PC_REG) - 4); + + /* Report RSP break event */ + __rmonGetThreadStatus(RMON_RSP, RMON_TID_RSP, &exceptionReply); + __rmonGetExceptionStatus(&exceptionReply); + __rmonSendReply(&exceptionReply.header, sizeof(exceptionReply), KK_TYPE_EXCEPTION); + __rmonRcpAtBreak = TRUE; +} + +void __rmonHitCpuFault(void) { + STUBBED_PRINTF(("HitCpuFault\n")); + + /* Stop all user threads and report faulted threads */ + __rmonMaskIdleThreadInts(); + __rmonStopUserThreads(0); + rmonFindFaultedThreads(); +} + +static void rmonFindFaultedThreads(void) { + register OSThread* tptr = __osGetActiveQueue(); + + while (tptr->priority != -1) { + if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { + if (tptr->flags & OS_FLAG_CPU_BREAK) { + int inst = *(u32*)tptr->context.pc; + + STUBBED_PRINTF(("Brk in thread %d @ %08x, inst %08x\r\n", tptr->id, tptr->context.pc, inst)); + + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + rmonSendBreakMessage(tptr->id, inst >> 6); + } else { + rmonSendBreakMessage(tptr->id, 0); + } + } + if (tptr->flags & OS_FLAG_FAULT) { + __rmonSendFault(tptr); + rmonSendBreakMessage(tptr->id, FAULT_BREAKNUM); + } + } + tptr = tptr->tlnext; + } +} + +#endif diff --git a/lib/ultralib/src/rmon/rmoncmds.c b/lib/ultralib/src/rmon/rmoncmds.c new file mode 100644 index 0000000..88600a6 --- /dev/null +++ b/lib/ultralib/src/rmon/rmoncmds.c @@ -0,0 +1,54 @@ +#ifndef _FINALROM + +#include "dbgproto.h" +#include "rmonint.h" + +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +static int NotImplemented(KKHeader* dummy UNUSED) { + return TV_ERROR_ILLEGAL_CALL; +} + +static FUNPTR dispatchTable[] = { + __rmonLoadProgram, __rmonListProcesses, __rmonGetExeName, __rmonListThreads, __rmonThreadStatus, + NotImplemented, __rmonStopThread, __rmonRunThread, NotImplemented, NotImplemented, + __rmonSetFault, NotImplemented, __rmonGetRegionCount, __rmonGetRegions, __rmonGetGRegisters, + __rmonSetGRegisters, __rmonGetFRegisters, __rmonSetFRegisters, __rmonReadMem, __rmonWriteMem, + __rmonSetBreak, __rmonClearBreak, __rmonListBreak, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + __rmonSetComm, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, __rmonGetSRegs, + __rmonSetSRegs, __rmonGetVRegs, __rmonSetVRegs, NotImplemented, +}; + +int __rmonExecute(KKHeader* request) { + int retval; + KKHeader reply; + + if (request->code >= ARRLEN(dispatchTable) - 1) { + return TV_ERROR_ILLEGAL_CALL; + } + + retval = dispatchTable[(int)request->code](request); + if (retval < TV_ERROR_NO_ERROR) { + reply.code = request->code; + reply.error = retval; + __rmonSendReply(&reply, sizeof(reply), KK_TYPE_REPLY); + } + return retval; +} + +#endif diff --git a/lib/ultralib/src/rmon/rmonint.h b/lib/ultralib/src/rmon/rmonint.h new file mode 100644 index 0000000..59ad736 --- /dev/null +++ b/lib/ultralib/src/rmon/rmonint.h @@ -0,0 +1,169 @@ +#ifndef _RMONINT_H +#define _RMONINT_H + +#include "dbgproto.h" +#include "PR/os_internal.h" + +/* mips */ + +#define MIPS_LWC2_OPCODE 50 +#define MIPS_SWC2_OPCODE 58 + +#define MIPS_LW_OPCODE 35 +#define MIPS_SW_OPCODE 43 + +#define MIPS_BREAK_OPCODE 0xD +#define MIPS_BREAK_MASK 0xFC00003F + +#define MIPS_BREAK(code) \ + ((((code) & 0xFFFFF) << 6) | MIPS_BREAK_OPCODE) + +/* R4300 General Purpose Register Indices */ +#define GREG_IDX_ZERO 0 +#define GREG_IDX_AT 1 +#define GREG_IDX_T9 25 +#define GREG_IDX_K0 26 +#define GREG_IDX_GP 28 +#define GREG_IDX_RA 31 +#define GREG_IDX_LO 32 +#define GREG_IDX_HI 33 +#define GREG_IDX_CAUSE 34 +#define GREG_IDX_PC 35 +#define GREG_IDX_SR 36 + +/* RSP Scalar Register Indices */ +#define SREG_IDX_ZERO 0 +#define SREG_IDX_RA 31 +#define SREG_IDX_DRAM_ADDR (32 + 0) +#define SREG_IDX_MEM_ADDR (32 + 1) +#define SREG_IDX_RD_LEN (32 + 2) +#define SREG_IDX_PC (32 + 3) +#define SREG_IDX_WR_LEN (32 + 4) +#define SREG_IDX_STATUS (32 + 5) +#define SREG_IDX_DMA_FULL (32 + 6) +#define SREG_IDX_DMA_BUSY (32 + 7) + +/* RSP Vector Register Properties */ +#define VREG_NUM 32 +#define VREG_SIZE 0x10 + +/* rmon */ + +#define RMON_MESG_CPU_BREAK 2 +#define RMON_MESG_SP_BREAK 4 +#define RMON_MESG_FAULT 8 + +#define RMON_CPU 0 +#define RMON_RSP 1 + +/* "thread id" for rsp */ +#define RMON_TID_RSP 1000 +/* "thread priority" for rsp */ +#define RMON_PRI_RSP 42 + +/* "thread id" for no thread running */ +#define RMON_TID_NOTHREAD 1003 + +#define RMON_PID_CPU 1002 +#define RMON_PID_RSP 1001 + +/* Largest serviceable read/write memory request */ +#define RMON_MAX_XFER_SIZE 1024 + +/* rmonmain */ + +void __rmonSendHeader(KKHeader* const block, u32 blockSize, u32 type); +void __rmonSendReply(KKHeader* const block, u32 blockSize, u32 replyType); +void __rmonSendData(char* const block, unsigned int blockSize); + +extern int __rmonActive; + +/* rmonmisc */ + +void __rmonInit(void); +void __rmonPanic(void); + +extern OSMesgQueue __rmonMQ; + +/* rmonmem */ + +void __rmonWriteWordTo(u32* addr, u32 val); +u32 __rmonReadWordAt(u32* addr); +void __rmonMemcpy(u8* dest, u8* srce, u32 count); +void __rmonCopyWords(u32* dest, u32* srce, u32 count); + +extern u8 __rmonUtilityBuffer[]; + +/* rmonsio */ + +void __rmonSendFault(OSThread* thread); +void __rmonIOflush(void); +void __rmonIOputw(u32 word); +void __rmonIOhandler(void); + +extern void* __osRdb_DbgRead_Buf; +extern u8 rmonRdbReadBuf[]; + +/* rmonrcp */ + +int __rmonRCPrunning(void); +void __rmonIdleRCP(void); +void __rmonStepRCP(void); +void __rmonRunRCP(void); + +/* rmonbrk */ + +u32 __rmonGetBranchTarget(int method, int thread, char* addr); +int __rmonSetSingleStep(int thread, u32* instptr); +void __rmonGetExceptionStatus(KKStatusEvent* reply); +void __rmonHitBreak(void); +void __rmonHitSpBreak(void); +void __rmonHitCpuFault(void); + +extern u8 __rmonRcpAtBreak; + +/* rmonregs */ + +u32 __rmonGetRegisterContents(int method, int threadNumber, int regNumber); + +/* rmontask */ + +void __rmonMaskIdleThreadInts(void); +OSThread* __rmonGetTCB(int threadNumber); +int __rmonStopUserThreads(int whichThread); +int __rmonGetThreadStatus(int method, int id, KKStatusEvent* reply); + +/* rmoncmds */ + +int __rmonExecute(KKHeader* request); + +/* commands */ + +typedef int (*FUNPTR)(); + +int __rmonLoadProgram(KKHeader* req); +int __rmonListProcesses(KKHeader* req); +int __rmonGetExeName(KKHeader* req); +int __rmonListThreads(KKHeader* req); +int __rmonThreadStatus(KKHeader* req); +int __rmonStopThread(KKHeader* req); +int __rmonRunThread(KKHeader* req); +int __rmonSetFault(KKHeader* req); +int __rmonGetRegionCount(KKHeader* req); +int __rmonGetRegions(KKHeader* req); +int __rmonGetGRegisters(KKHeader* req); +int __rmonSetGRegisters(KKHeader* req); +int __rmonGetFRegisters(KKHeader* req); +int __rmonSetFRegisters(KKHeader* req); +int __rmonReadMem(KKHeader* req); +int __rmonWriteMem(KKHeader* req); +int __rmonSetBreak(KKHeader* req); +int __rmonClearBreak(KKHeader* req); +int __rmonListBreak(KKHeader* req); +int __rmonSetComm(KKHeader* req); +int __rmonGetSRegs(KKHeader* req); +int __rmonSetSRegs(KKHeader* req); +int __rmonGetVRegs(KKHeader* req); +int __rmonSetVRegs(KKHeader* req); + +#endif diff --git a/lib/ultralib/src/rmon/rmonmain.c b/lib/ultralib/src/rmon/rmonmain.c new file mode 100644 index 0000000..564ac44 --- /dev/null +++ b/lib/ultralib/src/rmon/rmonmain.c @@ -0,0 +1,138 @@ +#include "PR/os_version.h" + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +#ifndef _FINALROM + +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "rmonint.h" +#include "PR/rcp.h" +#include "sptask.h" +#include "PR/rdb.h" + +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#endif + +int __rmonActive = FALSE; + +static vu32 somethingToDo; +static u32 inbuffer[280] ALIGNED(0x10); +static u8 cmdinptr; +static u8 cmdoutptr; +static int state; +static char* inPointer; + +void __rmonSendHeader(KKHeader* const block, u32 blockSize, u32 type) { + int sent; + char* cPtr = (char*)block; + + block->rev = KK_REV; + block->type = type; + + sent = 0; + while (sent < blockSize) { + sent += __osRdbSend(cPtr + sent, blockSize - sent, RDB_TYPE_GtoH_DEBUG); + } +} + +void __rmonSendReply(KKHeader* const block, u32 blockSize, u32 replyType) { + char* cPtr; + int sent = 0; + + block->length = blockSize; + cPtr = (char*)&blockSize; + + /* send size */ + while (sent < (signed)sizeof(blockSize)) { + sent += __osRdbSend(cPtr + sent, sizeof(blockSize) - sent, RDB_TYPE_GtoH_DEBUG); + } + + /* send data */ + __rmonSendHeader(block, blockSize, replyType); + __rmonIOflush(); +} + +void __rmonSendData(char* const block, unsigned int blockSize) { + int* blockPointer = (int*)block; + unsigned int wordCount = (u32)(blockSize + 3) / 4; + u32 data; + union { + char bufBytes[4]; + u32 bufWord; + } buffer; + + if (((u32)block & 3) == 0) { + while (wordCount--) { + if ((u32)blockPointer >= SP_DMEM_START && (u32)blockPointer < 0x05000000) { + __osSpRawReadIo((u32)blockPointer++, &data); + __rmonIOputw(data); + } else { + __rmonIOputw(*(blockPointer++)); + } + } + } else + while (wordCount--) { + __rmonMemcpy((u8*)buffer.bufBytes, (u8*)blockPointer, sizeof(buffer)); + __rmonIOputw(buffer.bufWord); + blockPointer++; + } + __rmonIOflush(); +} + +void rmonMain(void) { + register int newChars UNUSED; + + STUBBED_PRINTF(("rmon: Thread %d created\n")); + STUBBED_PRINTF(("rmon: Thread %d destroyed\n")); + + somethingToDo = 0; + cmdoutptr = 0; + cmdinptr = 0; + + __rmonInit(); + __rmonActive = TRUE; + + + state = 0, newChars = 0, inPointer = (void*)&inbuffer; + for (;;) { + OSMesg work; + + osRecvMesg(&__rmonMQ, &work, OS_MESG_BLOCK); + + somethingToDo |= (u32)work; + + if (somethingToDo & RMON_MESG_CPU_BREAK) { + somethingToDo &= ~RMON_MESG_CPU_BREAK; + __rmonHitBreak(); + } + if (somethingToDo & RMON_MESG_SP_BREAK) { + somethingToDo &= ~RMON_MESG_SP_BREAK; + __rmonHitSpBreak(); + } + if (somethingToDo & RMON_MESG_FAULT) { + somethingToDo &= ~RMON_MESG_FAULT; + __rmonHitCpuFault(); + } + if (somethingToDo & 0x10) { + somethingToDo; + somethingToDo &= (u8)~0x10; + } + if (somethingToDo & 0x20) { + somethingToDo; + somethingToDo &= (u8)~0x20; + } + } +} + +#endif diff --git a/lib/ultralib/src/rmon/rmonmem.c b/lib/ultralib/src/rmon/rmonmem.c new file mode 100644 index 0000000..a11051b --- /dev/null +++ b/lib/ultralib/src/rmon/rmonmem.c @@ -0,0 +1,283 @@ +#include "PR/os_version.h" + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +#ifndef _FINALROM + +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "rmonint.h" +#include "PR/rdb.h" + +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#endif + +u8 __rmonUtilityBuffer[256] ALIGNED(8); + +void __rmonWriteWordTo(u32* addr, u32 val) { + while (__osSpRawWriteIo((u32)addr, val) != 0) { + ; + } +} + +u32 __rmonReadWordAt(u32* addr) { + u32 data; + + if ((u32)addr >= SP_DMEM_START && (u32)addr < 0x05000000) { + __osSpRawReadIo((u32)addr, &data); + return data; + } + return 0; +} + +void __rmonMemcpy(u8* dest, u8* srce, u32 count) { + while (count--) { + *dest++ = *srce++; + } +} + +void __rmonCopyWords(u32* dest, u32* srce, u32 count) { + while (count--) { + *dest++ = *srce++; + } +} + +static void strcpy(char* dest, char* srce) { + while ((*dest++ = *srce++)) { + ; + } +} + +int __rmonReadMem(KKHeader* req) { + char* cPtr; + int sent; + int dataSize; + KKReadRequest* request = (KKReadRequest*)req; + KKBufferEvent* reply = (KKBufferEvent*)__rmonUtilityBuffer; + u8* blockStart; + + STUBBED_PRINTF(("ReadMem @ %08x for %d\n", request->addr, request->nbytes)); + + reply->header.code = request->header.code; + reply->object = request->object; + reply->header.error = TV_ERROR_NO_ERROR; + + if (request->addr == (u32)-1) { + return TV_ERROR_INVALID_ADDRESS; + } + if (request->nbytes > RMON_MAX_XFER_SIZE) { + return TV_ERROR_INVALID_CAPABILITY; + } + + if (req->method == RMON_RSP) { + if (!((request->addr < SP_IMEM_START || (request->addr + request->nbytes) > SP_IMEM_END) ? FALSE : TRUE) && + !((request->addr < SP_DMEM_START || (request->addr + request->nbytes) > SP_DMEM_END) ? FALSE : TRUE)) { + return TV_ERROR_INVALID_ADDRESS; + } + } else if (osVirtualToPhysical((void*)request->addr) == (u32)-1) { + return TV_ERROR_INVALID_ADDRESS; + } + + blockStart = (u8*)request->addr; + reply->header.length = request->nbytes + sizeof(reply->header) + sizeof(reply->object); + dataSize = request->nbytes + sizeof(reply->header) + sizeof(reply->object); + + cPtr = (char*)&dataSize; + sent = 0; + while (sent < (signed)sizeof(dataSize)) { + sent += __osRdbSend(cPtr + sent, sizeof(dataSize) - sent, RDB_TYPE_GtoH_DEBUG); + } + + __rmonSendHeader(&reply->header, sizeof(reply->header) + sizeof(reply->object), KK_TYPE_REPLY); + __rmonSendData(blockStart, request->nbytes); + return TV_ERROR_NO_ERROR; +} + +int __rmonWriteMem(KKHeader* req) { + register KKWriteRequest* request = (KKWriteRequest*)req; + KKObjectEvent reply; + + STUBBED_PRINTF(("WriteMem\n")); + + /* Bad virtual address, abort */ + if (req->method == RMON_CPU && osVirtualToPhysical((u32*)request->writeHeader.addr) == (u32)-1) { + return TV_ERROR_INVALID_ADDRESS; + } + + /* Transfer size too large, abort */ + if (request->writeHeader.nbytes > RMON_MAX_XFER_SIZE) { + return TV_ERROR_INVALID_CAPABILITY; + } + + if (((request->writeHeader.addr < SP_DMEM_START || + (request->writeHeader.addr + request->writeHeader.nbytes) > 0x04FFFFFF) ? FALSE : TRUE)) { + int align; + u32 word; + + if ((align = request->writeHeader.addr & 3) != 0) { + STUBBED_PRINTF(("Long unaligned write...\n")); + + if (request->writeHeader.nbytes != 1) { + return TV_ERROR_INVALID_ADDRESS; + } + + /* Unaligned write; read the word, substitute in the written byte, write it back */ + word = __rmonReadWordAt((u32*)(request->writeHeader.addr & ~3)); + if (align == 1) { + word = (word & ~0xFF0000) | (request->buffer[0] << 0x10); + } else if (align == 2) { + word = (word & ~0xFF00) | (request->buffer[0] << 8); + } else { + word = (word & ~0xFF) | (request->buffer[0] << 0); + } + __rmonWriteWordTo((u32*)(request->writeHeader.addr & ~3), word); + } else { + int wordCount = request->writeHeader.nbytes / sizeof(u32); + u32* wordPointer = (u32*)request->buffer; + + if (request->writeHeader.nbytes % sizeof(u32) != 0) { + STUBBED_PRINTF(("RCP write not an integral number of words\n")); + return TV_ERROR_INVALID_ADDRESS; + } + + while (wordCount--) { + __rmonWriteWordTo((u32*)request->writeHeader.addr, *(wordPointer++)); + request->writeHeader.addr += sizeof(*wordPointer); + } + } + } else { + __rmonMemcpy((u8*)request->writeHeader.addr, (u8*)request->buffer, request->writeHeader.nbytes); + } + + reply.header.code = request->writeHeader.header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->writeHeader.object; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +int __rmonListProcesses(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*)req; + KKObjsEvent reply; + + STUBBED_PRINTF(("ListProcesses\n")); + + reply.object = 0; + reply.objs.number = 1; + reply.objs.objects[0] = (req->method == RMON_RSP) ? RMON_PID_RSP : RMON_PID_CPU; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonLoadProgram(KKHeader* request UNUSED) { + STUBBED_PRINTF(("LoadProgram\n")); + + return TV_ERROR_ILLEGAL_CALL; +} + +int __rmonGetExeName(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*)req; + KKBufferEvent* reply = (KKBufferEvent*)__rmonUtilityBuffer; + + STUBBED_PRINTF(("GetExeName\n")); + + reply->header.code = request->header.code; + reply->header.error = TV_ERROR_NO_ERROR; + reply->object = request->object; + + if (req->method == RMON_RSP) { + strcpy(reply->buffer, "imem"); + } else { + strcpy(reply->buffer, "rmon"); + } + __rmonSendReply(&reply->header, sizeof(reply->header) + sizeof(reply->object) + 8, KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +int __rmonGetRegionCount(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*)req; + KKNumberEvent reply; + + STUBBED_PRINTF(("GetRegionCount\n")); + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->object; + + reply.number = (req->method == RMON_RSP) ? 2 : 5; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +int __rmonGetRegions(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*)req; + KKRegionEvent* reply = (KKRegionEvent*)__rmonUtilityBuffer; + int numRegions; + + STUBBED_PRINTF(("GetRegions\n")); + + numRegions = (req->method == RMON_RSP) ? 2 : 6; + + reply->header.length = numRegions * sizeof(reply->regions[0]) + sizeof(*reply); + reply->header.code = request->header.code; + reply->header.error = TV_ERROR_NO_ERROR; + reply->object = request->object; + reply->number = numRegions; + + reply->regions[1].vaddr = SP_IMEM_START; + reply->regions[1].size = SP_IMEM_END + 1 - SP_IMEM_START; + reply->regions[1].flags = 1 | 2 | 4; + reply->regions[1].paddr = SP_IMEM_START; + + reply->regions[0].vaddr = SP_DMEM_START; + reply->regions[0].size = SP_DMEM_END + 1 - SP_DMEM_START; + reply->regions[0].flags = 1 | 2; + reply->regions[0].paddr = SP_DMEM_START; + + if (numRegions > 2) { + reply->regions[2].vaddr = 0x88200000; + reply->regions[2].size = 0x6130; + reply->regions[2].flags = 1 | 4; + reply->regions[2].paddr = 0; + + reply->regions[3].vaddr = 4; + reply->regions[3].size = 0x200000; + reply->regions[3].flags = 1 | 2; + reply->regions[3].paddr = 0; + + reply->regions[4].vaddr = 0x4002000; + reply->regions[4].size = 0x800000; + reply->regions[4].flags = 1 | 2; + reply->regions[4].paddr = 0; + + reply->regions[5].vaddr = 0x88206130; + reply->regions[5].size = 0x9000; + reply->regions[5].flags = 1 | 2; + reply->regions[5].paddr = 0; + } + + __rmonSendReply(&reply->header, reply->header.length, KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +#endif diff --git a/lib/ultralib/src/rmon/rmonmisc.c b/lib/ultralib/src/rmon/rmonmisc.c new file mode 100644 index 0000000..a1aa96c --- /dev/null +++ b/lib/ultralib/src/rmon/rmonmisc.c @@ -0,0 +1,76 @@ +#ifndef _FINALROM + +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "PR/sptask.h" +#include "rmonint.h" + +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +int __rmonSetFault(KKHeader* req) { + KKFaultRequest* request = (KKFaultRequest*)req; + KKObjectEvent reply; + + STUBBED_PRINTF(("SetFault\n")); + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->tid; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +OSMesgQueue __rmonMQ ALIGNED(8); +static OSThread rmonIOThread ALIGNED(8); +static OSMesg rmonMsgs[8] ALIGNED(8); +static u64 rmonIOStack[2048] ALIGNED(16); +static OSMesg rmonPiMsgs[8] ALIGNED(8); +static OSMesgQueue rmonPiMQ ALIGNED(8); + +void __rmonInit(void) { + osCreateMesgQueue(&__rmonMQ, rmonMsgs, ARRLEN(rmonMsgs)); + osSetEventMesg(OS_EVENT_CPU_BREAK, &__rmonMQ, (OSMesg)RMON_MESG_CPU_BREAK); + osSetEventMesg(OS_EVENT_SP_BREAK, &__rmonMQ, (OSMesg)RMON_MESG_SP_BREAK); + osSetEventMesg(OS_EVENT_FAULT, &__rmonMQ, (OSMesg)RMON_MESG_FAULT); + osSetEventMesg(OS_EVENT_THREADSTATUS, &__rmonMQ, NULL); + osCreateThread(&rmonIOThread, 0, (void (*)(void*))__rmonIOhandler, NULL, rmonIOStack + ARRLEN(rmonIOStack), + OS_PRIORITY_MAX); + osCreatePiManager(OS_PRIORITY_PIMGR, &rmonPiMQ, rmonPiMsgs, ARRLEN(rmonPiMsgs)); + osStartThread(&rmonIOThread); +} + +void __rmonPanic(void) { + STUBBED_PRINTF(("PANIC!!\n")); + + for (;;) { + ; + } +} + +int __rmonSetComm(KKHeader* req) { + KKObjectEvent reply; + + STUBBED_PRINTF(("SetComm\n")); + + reply.header.code = req->code; + reply.object = 0; + reply.header.error = TV_ERROR_NO_ERROR; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +#endif diff --git a/lib/ultralib/src/rmon/rmonprint.c b/lib/ultralib/src/rmon/rmonprint.c new file mode 100644 index 0000000..8ac91a5 --- /dev/null +++ b/lib/ultralib/src/rmon/rmonprint.c @@ -0,0 +1 @@ +/* Empty file */ diff --git a/lib/ultralib/src/rmon/rmonrcp.s b/lib/ultralib/src/rmon/rmonrcp.s new file mode 100644 index 0000000..539f41d --- /dev/null +++ b/lib/ultralib/src/rmon/rmonrcp.s @@ -0,0 +1,60 @@ +#include "PR/os_version.h" +#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J + +#include "sys/asm.h" +#include "sys/regdef.h" +#include "PR/rcp.h" +#include "PR/R4300.h" + +.text + +/* check if the rsp is currently running by polling HALT or BROKE bits in SP_STATUS */ +LEAF(__rmonRCPrunning) + move v0, zero + lw t0, PHYS_TO_K1(SP_STATUS_REG) + and t0, SP_STATUS_HALT | SP_STATUS_BROKE + bnez t0, isHalted + ori v0, 1 +isHalted: + jr ra +END(__rmonRCPrunning) + +/* stop the rsp, first wait for any ongoing dma to complete before setting HALT in SP_STATUS */ +LEAF(__rmonIdleRCP) + li a0, PHYS_TO_K1(SP_DMA_BUSY_REG) +wait4dma: + lw v0, (a0) + bnez v0, wait4dma + li a1, SP_CLR_INTR_BREAK | SP_SET_HALT + li a0, PHYS_TO_K1(SP_STATUS_REG) + sw a1, (a0) + +/* wait for the rsp to stop */ +awaitIdle: + li a0, PHYS_TO_K1(SP_STATUS_REG) + lw v0, (a0) + and v0, SP_STATUS_HALT | SP_STATUS_BROKE + beqz v0, awaitIdle + jr ra +END(__rmonIdleRCP) + +/* run the rsp in single-step mode to step one instruction */ +LEAF(__rmonStepRCP) + li a0, PHYS_TO_K1(SP_STATUS_REG) + li a1, SP_CLR_INTR_BREAK | SP_SET_SSTEP | SP_CLR_BROKE | SP_CLR_HALT + sw a1, (a0) + b awaitIdle +END(__rmonStepRCP) + +/* run the rsp normally */ +LEAF(__rmonRunRCP) + li a0, PHYS_TO_K1(MI_INTR_MASK_REG) + li a1, MI_INTR_MASK_SET_SP + sw a1, (a0) + li a0, PHYS_TO_K1(SP_STATUS_REG) + li a1, SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT + sw a1, (a0) + jr ra +END(__rmonRunRCP) + +#endif diff --git a/lib/ultralib/src/rmon/rmonregs.c b/lib/ultralib/src/rmon/rmonregs.c new file mode 100644 index 0000000..39cf5b2 --- /dev/null +++ b/lib/ultralib/src/rmon/rmonregs.c @@ -0,0 +1,417 @@ +#ifndef _FINALROM + +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "rmonint.h" +#include "PR/rdb.h" +#include "PR/os_version.h" + +#include "macros.h" + +// TODO: these come from headers +#if BUILD_VERSION >= VERSION_K +#ident "$Revision: 1.4 $" +// This revision was bumped down at K for some reason +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#elif BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#ident "$Revision: 3.71 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +static u32 RCPpc; +static u32 oldIMEMvalue; +static u32 DMEMbuffer[4] ALIGNED(8); + +typedef union { + u32 everything; + struct { + int opcode : 6; + int base : 5; + int rt : 5; + int offset : 16; + } scalarop; + struct { + int opcode : 6; + int base : 5; + int rt : 5; + int size : 5; + int element : 4; + int offset : 7; + } vectorop; +} INSTRUCTION; + +static void LoadStoreSU(int opcode, int regno) { + INSTRUCTION inst; + + /* Prepare a scalar load or store instruction at DMEM address 0 */ + inst.everything = 0; + inst.scalarop.opcode = opcode; + inst.scalarop.rt = regno; + __rmonWriteWordTo((u32*)SP_IMEM_START, inst.everything); + __rmonWriteWordTo((u32*)SP_PC_REG, 0); +} + +static void LoadStoreVU(int opcode, int regno) { + INSTRUCTION inst; + + /* Prepare a vector 128-bit load or store instruction at DMEM address 0 */ + inst.everything = 0; + inst.vectorop.opcode = opcode; + inst.vectorop.rt = regno; + inst.vectorop.size = 4; /* LQV / SQV */ + __rmonWriteWordTo((u32*)SP_IMEM_START, inst.everything); + __rmonWriteWordTo((u32*)SP_PC_REG, 0); +} + +static void SetUpForRCPop(int isVector) { + /* Save RSP data that would be overwritten when reading or writing registers */ + RCPpc = __rmonReadWordAt((u32*)SP_PC_REG); + oldIMEMvalue = __rmonReadWordAt((u32*)SP_IMEM_START); + DMEMbuffer[0] = __rmonReadWordAt((u32*)SP_DMEM_START); + if (isVector) { + DMEMbuffer[1] = __rmonReadWordAt((u32*)(SP_DMEM_START + 0x4)); + DMEMbuffer[2] = __rmonReadWordAt((u32*)(SP_DMEM_START + 0x8)); + DMEMbuffer[3] = __rmonReadWordAt((u32*)(SP_DMEM_START + 0xC)); + } +} + +static void CleanupFromRCPop(int isVector) { + /* Restore RSP data that was saved to read or write registers */ + __rmonWriteWordTo((u32*)SP_DMEM_START, DMEMbuffer[0]); + if (isVector) { + __rmonWriteWordTo((u32*)(SP_DMEM_START + 0x4), DMEMbuffer[1]); + __rmonWriteWordTo((u32*)(SP_DMEM_START + 0x8), DMEMbuffer[2]); + /* BUG: the last word is not restored properly */ + __rmonWriteWordTo((u32*)(SP_DMEM_START + 0xC), DMEMbuffer[2]); + } + __rmonWriteWordTo((u32*)SP_IMEM_START, oldIMEMvalue); + __rmonWriteWordTo((u32*)SP_PC_REG, RCPpc); +} + +int __rmonGetGRegisters(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*)req; + KKGregEvent reply; + + STUBBED_PRINTF(("GetGRegisters\n")); + + reply.tid = request->object; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + + if (request->header.method == RMON_CPU) { + OSThread* tptr = __rmonGetTCB(request->object); + u64* tcbregptr; + register s32 i; + + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + for (i = GREG_IDX_AT, tcbregptr = &tptr->context.at; i < GREG_IDX_K0; i++, tcbregptr++) { + reply.registers.gregs[i] = *tcbregptr; + } + for (i = GREG_IDX_GP, tcbregptr = &tptr->context.gp; i < GREG_IDX_CAUSE; i++, tcbregptr++) { + reply.registers.gregs[i] = *tcbregptr; + } + + reply.registers.gregs[GREG_IDX_CAUSE] = tptr->context.cause; + reply.registers.gregs[GREG_IDX_PC] = tptr->context.pc; + reply.registers.gregs[GREG_IDX_SR] = tptr->context.sr; + reply.registers.gregs[GREG_IDX_ZERO] = 0; + } else { + return TV_ERROR_INVALID_ID; + } + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonSetGRegisters(KKHeader* req) { + register KKGRegsetRequest* request = (KKGRegsetRequest*)req; + KKObjectEvent reply; + + STUBBED_PRINTF(("SetGRegisters\n")); + + if (request->header.method == RMON_CPU) { + OSThread* tptr = __rmonGetTCB(request->tid); + u64* tcbregptr; + register int i; + + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + for (i = GREG_IDX_AT, tcbregptr = &tptr->context.at; i < GREG_IDX_K0; i++, tcbregptr++) { + *tcbregptr = (s32)request->registers.gregs[i]; + } + + for (i = GREG_IDX_GP, tcbregptr = &tptr->context.gp; i < GREG_IDX_CAUSE; i++, tcbregptr++) { + *tcbregptr = (s32)request->registers.gregs[i]; + } + + tptr->context.cause = request->registers.gregs[GREG_IDX_CAUSE]; + tptr->context.pc = request->registers.gregs[GREG_IDX_PC]; + tptr->context.sr = request->registers.gregs[GREG_IDX_SR]; + } else { + return TV_ERROR_INVALID_ID; + } + + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonGetFRegisters(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*)req; + KKFPregEvent reply; + OSThread* tptr; + volatile float f UNUSED; + + STUBBED_PRINTF(("GetFRegisters\n")); + + if (req->method != RMON_CPU) { + return TV_ERROR_INVALID_ID; + } + + /* touch fpu to ensure registers are saved to the context structure */ + f = 0.0f; + + tptr = __rmonGetTCB(request->object); + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + __rmonCopyWords((u32*)reply.registers.fpregs.regs, (u32*)&tptr->context.fp0, ARRLEN(reply.registers.fpregs.regs)); + + reply.registers.fpcsr = tptr->context.fpcsr; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.tid = request->object; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonSetFRegisters(KKHeader* req) { + register KKFPRegsetRequest* request = (KKFPRegsetRequest*)req; + KKObjectEvent reply; + OSThread* tptr; + volatile float f UNUSED; + + STUBBED_PRINTF(("SetFRegisters\n")); + + if (req->method != RMON_CPU) { + return TV_ERROR_INVALID_ID; + } + + /* touch fpu to ensure registers are saved to the context structure */ + f = 0.0f; + + tptr = __rmonGetTCB(request->tid); + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + __rmonCopyWords((u32*)&tptr->context.fp0, (u32*)request->registers.fpregs.regs, + ARRLEN(request->registers.fpregs.regs)); + tptr->context.fpcsr = request->registers.fpcsr; + + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +static u32 rmonGetRcpRegister(int regNumber) { + u32 contents; + + if (__rmonRCPrunning()) { + return 0; + } + + SetUpForRCPop(FALSE); + LoadStoreSU(MIPS_SW_OPCODE, regNumber); + __rmonStepRCP(); + contents = __rmonReadWordAt((u32*)SP_DMEM_START); + CleanupFromRCPop(FALSE); + + return contents; +} + +int __rmonGetSRegs(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*)req; + KKCpSregEvent reply; + register int i; + + STUBBED_PRINTF(("GetSRegisters\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + + reply.tid = request->object; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + + SetUpForRCPop(FALSE); + for (i = SREG_IDX_ZERO; i <= SREG_IDX_RA; i++) { + LoadStoreSU(MIPS_SW_OPCODE, i); + __rmonStepRCP(); + reply.registers.sregs[i] = __rmonReadWordAt((u32*)SP_DMEM_START); + } + CleanupFromRCPop(FALSE); + + reply.registers.sregs[SREG_IDX_DRAM_ADDR] = __rmonReadWordAt((u32*)SP_DRAM_ADDR_REG); + reply.registers.sregs[SREG_IDX_MEM_ADDR] = __rmonReadWordAt((u32*)SP_MEM_ADDR_REG); + reply.registers.sregs[SREG_IDX_RD_LEN] = __rmonReadWordAt((u32*)SP_RD_LEN_REG); + reply.registers.sregs[SREG_IDX_PC] = __rmonReadWordAt((u32*)SP_PC_REG) + SP_IMEM_START; + reply.registers.sregs[SREG_IDX_WR_LEN] = __rmonReadWordAt((u32*)SP_WR_LEN_REG); + reply.registers.sregs[SREG_IDX_STATUS] = __rmonReadWordAt((u32*)SP_STATUS_REG); + reply.registers.sregs[SREG_IDX_DMA_FULL] = __rmonReadWordAt((u32*)SP_DMA_FULL_REG); + reply.registers.sregs[SREG_IDX_DMA_BUSY] = __rmonReadWordAt((u32*)SP_DMA_BUSY_REG); + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonSetSRegs(KKHeader* req) { + register KKCpScalarRegsetRequest* request = (KKCpScalarRegsetRequest*)req; + KKObjectEvent reply; + register int i; + + STUBBED_PRINTF(("SetSRegisters\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + + SetUpForRCPop(FALSE); + for (i = SREG_IDX_ZERO; i <= SREG_IDX_RA; i++) { + __rmonWriteWordTo((u32*)SP_DMEM_START, request->registers.sregs[i]); + LoadStoreSU(MIPS_LW_OPCODE, i); + __rmonStepRCP(); + } + CleanupFromRCPop(FALSE); + + __rmonWriteWordTo((u32*)SP_DRAM_ADDR_REG, request->registers.sregs[SREG_IDX_DRAM_ADDR]); + __rmonWriteWordTo((u32*)SP_MEM_ADDR_REG, request->registers.sregs[SREG_IDX_MEM_ADDR]); + __rmonWriteWordTo((u32*)SP_PC_REG, request->registers.sregs[SREG_IDX_PC] & 0xFFF); + __rmonWriteWordTo((u32*)SP_WR_LEN_REG, request->registers.sregs[SREG_IDX_WR_LEN]); + __rmonWriteWordTo((u32*)SP_STATUS_REG, request->registers.sregs[SREG_IDX_STATUS]); + + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonGetVRegs(KKHeader* req) { + char* cPtr; + int sent; + int dataSize; + register KKObjectRequest* request = (KKObjectRequest*)req; + KKCpVregEvent reply; + register int i; + + STUBBED_PRINTF(("GetVRegisters\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + + reply.tid = request->object; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.header.length = sizeof(reply); + + dataSize = sizeof(reply); + cPtr = (char*)&dataSize; + sent = 0; + while (sent < (signed)sizeof(dataSize)) { + sent += __osRdbSend(cPtr + sent, sizeof(dataSize) - sent, RDB_TYPE_GtoH_DEBUG); + } + + __rmonSendHeader(&reply.header, VREG_SIZE, KK_TYPE_REPLY); + + SetUpForRCPop(TRUE); + for (i = 0; i < VREG_NUM; i++) { + LoadStoreVU(MIPS_SWC2_OPCODE, i); + __rmonStepRCP(); + __rmonSendData((void*)SP_DMEM_START, VREG_SIZE); + } + CleanupFromRCPop(TRUE); + + return TV_ERROR_NO_ERROR; +} + +int __rmonSetVRegs(KKHeader* req) { + register KKCpVectorRegsetRequest* request = (KKCpVectorRegsetRequest*)req; + KKObjectEvent reply; + register int i; + + STUBBED_PRINTF(("SetVRegs\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + + SetUpForRCPop(TRUE); + for (i = 0; i < VREG_NUM; i++) { + __rmonCopyWords((u32*)SP_DMEM_START, (u32*)&request->registers.vregs[i], VREG_SIZE / sizeof(u32)); + LoadStoreVU(MIPS_LWC2_OPCODE, i); + __rmonStepRCP(); + } + CleanupFromRCPop(TRUE); + + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +u32 __rmonGetRegisterContents(int method, int threadNumber, int regNumber) { + if (method == RMON_CPU) { + /* CPU register */ + u32* regPointer; + OSThread* tptr; + + if (regNumber >= GREG_IDX_AT && regNumber < GREG_IDX_K0) { + regNumber -= GREG_IDX_AT - GREG_IDX_ZERO; + } else if (regNumber >= GREG_IDX_GP && regNumber < GREG_IDX_LO) { + regNumber -= GREG_IDX_GP - GREG_IDX_T9; + } else { + return 0; + } + tptr = __rmonGetTCB(threadNumber); + if (tptr == NULL) { + return 0; + } + regPointer = (u32*)&tptr->context; + regPointer += regNumber; + return *regPointer; + } else { + /* RSP register */ + return rmonGetRcpRegister(regNumber); + } +} + +#endif diff --git a/lib/ultralib/src/rmon/rmonsio.c b/lib/ultralib/src/rmon/rmonsio.c new file mode 100644 index 0000000..3e45995 --- /dev/null +++ b/lib/ultralib/src/rmon/rmonsio.c @@ -0,0 +1,89 @@ +#include "PR/os_version.h" + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +#ifndef _FINALROM + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/ultralog.h" +#include "PR/sptask.h" +#include "dbgproto.h" +#include "rmonint.h" +#include "PR/ramrom.h" +#include "PR/rdb.h" +#include "PR/rmon.h" + +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#endif + +static OSMesgQueue IOmq ALIGNED(8); +static OSMesg IOmsgs; + +void* __osRdb_DbgRead_Buf; +u8 rmonRdbReadBuf[RMON_DBG_BUF_SIZE] ALIGNED(0x10); + +void __rmonSendFault(OSThread* thread) { + volatile float f UNUSED; + u8* tPtr; + u32 sent = 0; + + /* touch fpu to ensure registers are saved to the context structure */ + f = 0.0f; + + tPtr = (u8*)thread; + while (sent < sizeof(OSThread)) { + sent += __osRdbSend(tPtr + sent, sizeof(OSThread) - sent, RDB_TYPE_GtoH_FAULT); + } +} + +void __rmonIOflush(void) { + int sent = 0; + char tstr[4]; + + while (sent <= 0) { + sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_DEBUG_DONE); + } +} + +void __rmonIOputw(u32 word) { + int sent = 0; + char* cPtr = (char*)&word; + + while (sent < 4) { + sent += __osRdbSend(cPtr + sent, sizeof(word) - sent, RDB_TYPE_GtoH_DEBUG); + } +} + +void __rmonIOhandler(void) { + int sent; + char tstr[4]; + + osCreateMesgQueue(&IOmq, &IOmsgs, 1); + osSetEventMesg(OS_EVENT_RDB_DBG_DONE, &IOmq, NULL); + __osRdb_DbgRead_Buf = rmonRdbReadBuf; + + while (TRUE) { + osRecvMesg(&IOmq, NULL, OS_MESG_BLOCK); + + __rmonExecute((KKHeader*)&rmonRdbReadBuf); + __osRdb_DbgRead_Buf = rmonRdbReadBuf; + + sent = 0; + while (sent <= 0) { + sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_DEBUG_READY); + } + } +} + +#endif diff --git a/lib/ultralib/src/rmon/rmontask.c b/lib/ultralib/src/rmon/rmontask.c new file mode 100644 index 0000000..25757a7 --- /dev/null +++ b/lib/ultralib/src/rmon/rmontask.c @@ -0,0 +1,343 @@ +#ifndef _FINALROM + +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "rmonint.h" +#include "PR/rcp.h" +#include "PR/sptask.h" + +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +void __rmonMaskIdleThreadInts(void) { + register OSThread* tptr = __osGetActiveQueue(); + + while (tptr->priority != -1) { + if (tptr->priority == OS_PRIORITY_IDLE) { + tptr->context.sr &= ~OS_IM_CPU; + tptr->context.sr |= (OS_IM_RDBREAD | OS_IM_RDBWRITE | OS_IM_CART); + break; + } + tptr = tptr->tlnext; + } +} + +OSThread* __rmonGetTCB(int threadNumber) { + register OSThread* tptr = __osGetActiveQueue(); + + if (threadNumber < 1) { + return NULL; + } + + while (tptr->priority != -1) { + if (tptr->id == threadNumber) { + return tptr; + } + tptr = tptr->tlnext; + } + + return NULL; +} + +int __rmonStopUserThreads(int whichThread) { + register int whichOne = 0; + register OSThread* tptr = __osGetActiveQueue(); + + STUBBED_PRINTF(("StopThreads %d\n", whichThread)); + + if (whichThread != 0) { + /* Stop specified thread */ + + while (tptr->priority != -1) { + if (tptr->id == whichThread) { + break; + } + tptr = tptr->tlnext; + } + + if (tptr->priority == -1) { + return 0; + } + + if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { + osStopThread(tptr); + if (tptr->state != OS_STATE_STOPPED) { + STUBBED_PRINTF(("Couldn't stop thread %d\n", tptr->id)); + } + whichOne = whichThread; + } + } else { + /* Stop all threads */ + + while (tptr->priority != -1) { + if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { + osStopThread(tptr); + if (tptr->state != OS_STATE_STOPPED) { + STUBBED_PRINTF(("Couldn\'t stop thread %d\n", tptr->id)); + } + whichOne = -1; + } + tptr = tptr->tlnext; + } + } + return whichOne; +} + +int __rmonListThreads(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*)req; + KKObjsEvent* reply = (KKObjsEvent*)__rmonUtilityBuffer; + + STUBBED_PRINTF(("ListThreads\n")); + + reply->object = (request->object == -1) ? RMON_PID_CPU : request->object; + + if (req->method == RMON_RSP) { + reply->objs.number = 1; + reply->objs.objects[0] = RMON_TID_RSP; + } else { + register OSThread* tptr = __osGetActiveQueue(); + + reply->objs.number = 0; + + while (tptr->priority != -1) { + if (tptr->id != 0) { + reply->objs.objects[reply->objs.number] = tptr->id; + reply->objs.number++; + } + tptr = tptr->tlnext; + } + } + reply->header.code = request->header.code; + reply->header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply->header, sizeof(*reply) + sizeof(reply->objs.objects[0]) * (reply->objs.number - 1), + KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonGetThreadStatus(int method, int id, KKStatusEvent* reply) { + u32 inst; + + STUBBED_PRINTF(("ThreadStatus %d method %d\n", id, method)); + + reply->status.tid = id; + reply->status.pid = (method == RMON_RSP) ? RMON_PID_RSP : RMON_PID_CPU; + reply->status.why = 1; + reply->status.what = 0; + reply->status.info.major = 0; + reply->status.info.minor = 0; + reply->status.rv = 0; + + if (method == RMON_RSP) { + reply->status.start = SP_IMEM_START; + reply->status.priority = RMON_PRI_RSP; + + if (__rmonRCPrunning()) { + reply->status.flags = OS_STATE_RUNNING; + /* Cannot read RSP PC or current instruction while the RSP is running */ + reply->status.info.addr = 0; + reply->status.instr = 0; + } else { + reply->status.flags = OS_STATE_STOPPED; + reply->status.info.addr = __rmonReadWordAt((u32*)SP_PC_REG) + SP_IMEM_START; + inst = __rmonReadWordAt((u32*)reply->status.info.addr); + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + inst = MIPS_BREAK_OPCODE; + } + if (__rmonRcpAtBreak) { + /* Report RSP break */ + reply->status.why = 2; + reply->status.info.major = 2; + reply->status.info.minor = 4; + } + reply->status.instr = inst; + } + } else { + OSThread* tptr = __osGetActiveQueue(); + + while (tptr->priority != -1) { + if (tptr->id == id) { + break; + } + tptr = tptr->tlnext; + } + if (tptr->priority == -1) { + return TV_ERROR_INVALID_ID; + } + + reply->status.priority = tptr->priority; + reply->status.flags = (tptr->state != 0) ? tptr->state : OS_STATE_STOPPED; + reply->status.info.addr = tptr->context.pc; + + inst = *(u32*)(tptr->context.pc); + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + inst = MIPS_BREAK_OPCODE; + } + + reply->status.instr = inst; + reply->status.start = (int)tptr; + + if (tptr->flags & OS_FLAG_CPU_BREAK) { + /* Report break */ + reply->status.why = 2; + reply->status.info.major = 2; + reply->status.info.minor = 4; + } else if (tptr->flags & OS_FLAG_FAULT) { + /* Report fault */ + reply->status.why = 2; + reply->status.info.major = 1; + reply->status.info.minor = 2; + } + } + + return TV_ERROR_NO_ERROR; +} + +int __rmonThreadStatus(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*)req; + KKStatusEvent reply; + + if (__rmonGetThreadStatus(req->method, request->object, &reply) != TV_ERROR_NO_ERROR) { + return TV_ERROR_INVALID_ID; + } + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonStopThread(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*)req; + KKStatusEvent reply; + u32* pc; + + STUBBED_PRINTF(("StopThread %d\n", request->object)); + + switch (req->method) { + case RMON_CPU: + __rmonStopUserThreads(request->object); + break; + case RMON_RSP: + if (__rmonRCPrunning()) { + /* Stop the rsp */ + __rmonIdleRCP(); + pc = (u32*)__rmonReadWordAt((u32*)SP_PC_REG); + if (pc == NULL) { + break; + } + pc--; + /* Check if the RSP is stopped in a branch delay slot, if it is step out of it. The RSP would otherwise + lose information about whether the branch should or should not be taken when reading registers. */ + if (__rmonGetBranchTarget(RMON_RSP, RMON_TID_RSP, (void*)((u32)pc + SP_IMEM_START)) % 4 == 0) { + __rmonStepRCP(); + } + } + break; + default: + return TV_ERROR_OPERATIONS_PROTECTED; + } + + if (__rmonGetThreadStatus(req->method, request->object, &reply) != TV_ERROR_NO_ERROR) { + return TV_ERROR_INVALID_ID; + } + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + if (reply.status.flags == OS_STATE_STOPPED) { + reply.header.code = KK_CODE_THREAD_STATUS; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_EXCEPTION); + } + return TV_ERROR_NO_ERROR; +} + +int __rmonRunThread(KKHeader* req) { + KKRunThreadRequest* request = (KKRunThreadRequest*)req; + KKObjectEvent reply; + KKStatusEvent exceptionReply; + register OSThread* tptr; + register int runNeeded = FALSE; + + STUBBED_PRINTF(("RunThread %d\n", request->tid)); + + switch (req->method) { + case RMON_CPU: + tptr = __osGetActiveQueue(); + while (tptr->priority != -1) { + if (tptr->id == request->tid) { + break; + } + tptr = tptr->tlnext; + } + + if (tptr->priority == -1) { + return TV_ERROR_INVALID_ID; + } + if (tptr->state != OS_STATE_STOPPED) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + tptr->flags &= ~(OS_FLAG_CPU_BREAK | OS_FLAG_FAULT); + if (request->actions.flags & KK_RUN_SETPC) { + tptr->context.pc = request->actions.vaddr; + } + if ((request->actions.flags & KK_RUN_SSTEP) && !__rmonSetSingleStep(request->tid, (u32*)tptr->context.pc)) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + runNeeded = TRUE; + break; + case RMON_RSP: + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + if (request->actions.flags & KK_RUN_SETPC) { + __rmonWriteWordTo((u32*)SP_PC_REG, request->actions.vaddr - SP_IMEM_START); + } + if (request->actions.flags & KK_RUN_SSTEP) { + /* If the RSP is stopped at a branch step twice so as to not stop in a branch delay slot. */ + if (__rmonGetBranchTarget(RMON_RSP, RMON_TID_RSP, + (void*)(__rmonReadWordAt((u32*)SP_PC_REG) + SP_IMEM_START)) % + 4 == + 0) { + __rmonStepRCP(); + } + __rmonStepRCP(); + __rmonRcpAtBreak = TRUE; + } else { + __rmonRcpAtBreak = FALSE; + __rmonRunRCP(); + } + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->tid; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + if (request->actions.flags & KK_RUN_SSTEP) { + __rmonGetThreadStatus(RMON_RSP, RMON_TID_RSP, &exceptionReply); + __rmonGetExceptionStatus(&exceptionReply); + __rmonSendReply(&exceptionReply.header, sizeof(exceptionReply), KK_TYPE_EXCEPTION); + } + return TV_ERROR_NO_ERROR; + default: + return TV_ERROR_OPERATIONS_PROTECTED; + } + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->tid; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + + if (runNeeded) { + osStartThread(tptr); + } + return 1; +} + +#endif diff --git a/lib/ultralib/src/sched/Makefile b/lib/ultralib/src/sched/Makefile new file mode 100644 index 0000000..d4cd659 --- /dev/null +++ b/lib/ultralib/src/sched/Makefile @@ -0,0 +1,19 @@ +#!smake +# +# Makefile for the scheduler subdirectory +# + +include $(ROOT)/usr/include/make/PRdefs + + +# LCOPTS = -mips2 -non_shared -fullwarn -G 0 +LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include + +CFILES = \ + sched.c + +OBJECTS = $(CFILES:.c=.o) + +default: $(OBJECTS) + +include $(COMMONRULES) diff --git a/lib/ultralib/src/sched/sched.c b/lib/ultralib/src/sched/sched.c new file mode 100644 index 0000000..70ebf55 --- /dev/null +++ b/lib/ultralib/src/sched/sched.c @@ -0,0 +1,620 @@ +/*==================================================================== + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ +#include +#include +#include +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +/* + * private typedefs and defines + */ +#define VIDEO_MSG 666 +#define RSP_DONE_MSG 667 +#define RDP_DONE_MSG 668 +#define PRE_NMI_MSG 669 + +/* + * OSScTask state + */ +#define OS_SC_DP 0x0001 /* set if still needs dp */ +#define OS_SC_SP 0x0002 /* set if still needs sp */ +#define OS_SC_YIELD 0x0010 /* set if yield requested */ +#define OS_SC_YIELDED 0x0020 /* set if yield completed */ + +/* + * OSScTask->flags type identifier + */ +#define OS_SC_XBUS (OS_SC_SP | OS_SC_DP) +#define OS_SC_DRAM (OS_SC_SP | OS_SC_DP | OS_SC_DRAM_DLIST) +#define OS_SC_DP_XBUS (OS_SC_SP) +#define OS_SC_DP_DRAM (OS_SC_SP | OS_SC_DRAM_DLIST) +#define OS_SC_SP_XBUS (OS_SC_DP) +#define OS_SC_SP_DRAM (OS_SC_DP | OS_SC_DRAM_DLIST) + +/* + * private functions + */ +static void __scMain(void *arg); +static void __scHandleRetrace(OSSched *s); +static void __scHandleRSP(OSSched *s); +static void __scHandleRDP(OSSched *s); + +static void __scAppendList(OSSched *s, OSScTask *t); +OSScTask *__scTaskReady(OSScTask *t); +static s32 __scTaskComplete(OSSched *s,OSScTask *t); +static void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp); +static void __scYield(OSSched *s); +static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, + s32 availRCP); + + +/* +#define SC_LOGGING 1 +*/ + + +#ifdef SC_LOGGING +#define SC_LOG_LEN 32*1024 +static OSLog scLog; +static OSLog *l = &scLog; +static u32 logArray[SC_LOG_LEN/sizeof(u32)]; +#endif + +/*********************************************************************** + * Scheduler API + **********************************************************************/ +void osCreateScheduler(OSSched *sc, void *stack, OSPri priority, + u8 mode, u8 numFields) +{ + sc->curRSPTask = 0; + sc->curRDPTask = 0; + sc->clientList = 0; + sc->frameCount = 0; + sc->audioListHead = 0; + sc->gfxListHead = 0; + sc->audioListTail = 0; + sc->gfxListTail = 0; + sc->retraceMsg.type = OS_SC_RETRACE_MSG; /* sent to apps */ + sc->prenmiMsg.type = OS_SC_PRE_NMI_MSG; + + osCreateMesgQueue(&sc->interruptQ, sc->intBuf, OS_SC_MAX_MESGS); + osCreateMesgQueue(&sc->cmdQ, sc->cmdMsgBuf, OS_SC_MAX_MESGS); + + /* + * Set up video manager, listen for Video, RSP, and RDP interrupts + */ + osCreateViManager(OS_PRIORITY_VIMGR); + osViSetMode(&osViModeTable[mode]); + osViBlack(TRUE); + osSetEventMesg(OS_EVENT_SP, &sc->interruptQ, (OSMesg)RSP_DONE_MSG); + osSetEventMesg(OS_EVENT_DP, &sc->interruptQ, (OSMesg)RDP_DONE_MSG); + osSetEventMesg(OS_EVENT_PRENMI, &sc->interruptQ, (OSMesg)PRE_NMI_MSG); + + osViSetEvent(&sc->interruptQ, (OSMesg)VIDEO_MSG, numFields); + +#ifdef SC_LOGGING + osCreateLog(l, logArray, sizeof(logArray)); +#endif + + osCreateThread(&sc->thread, 4, __scMain, (void *)sc, stack, priority); + osStartThread(&sc->thread); +} + +/* + * Add a client to the scheduler. Clients receive messages at retrace time + */ +void osScAddClient(OSSched *sc, OSScClient *c, OSMesgQueue *msgQ) +{ + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + c->msgQ = msgQ; + c->next = sc->clientList; + sc->clientList = c; + + osSetIntMask(mask); +} + +void osScRemoveClient(OSSched *sc, OSScClient *c) +{ + OSScClient *client = sc->clientList; + OSScClient *prev = 0; + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + while (client != 0) { + if (client == c) { + if(prev) + prev->next = c->next; + else + sc->clientList = c->next; + break; + } + prev = client; + client = client->next; + } + + osSetIntMask(mask); +} + +OSMesgQueue *osScGetCmdQ(OSSched *sc) +{ + return &sc->cmdQ; +} + +/*********************************************************************** + * Scheduler implementation + **********************************************************************/ +static void __scMain(void *arg) +{ + OSMesg msg; + OSSched *sc = (OSSched *)arg; + OSScClient *client; + static int count = 0; + + while (1) { + + osRecvMesg(&sc->interruptQ, (OSMesg *)&msg, OS_MESG_BLOCK); + +#ifdef SC_LOGGING + if (++count % 1024 == 0) + osFlushLog(l); +#endif + + + switch ((int) msg) { + case (VIDEO_MSG): + __scHandleRetrace(sc); + break; + + case (RSP_DONE_MSG): + __scHandleRSP(sc); + break; + + case (RDP_DONE_MSG): + __scHandleRDP(sc); + break; + + case (PRE_NMI_MSG): + /* + * notify audio and graphics threads to fade out + */ + for (client = sc->clientList;client != 0;client = client->next) { + osSendMesg(client->msgQ, (OSMesg) &sc->prenmiMsg, + OS_MESG_NOBLOCK); + } + break; + } + } +} + +/* + * scHandleRetrace() + */ +static int dp_busy = 0; +static int dpCount = 0; + +void __scHandleRetrace(OSSched *sc) +{ + OSScTask *rspTask; + OSScClient *client; + s32 i; + s32 state; + OSScTask *sp = 0; + OSScTask *dp = 0; + + sc->frameCount++; + +#ifdef SC_LOGGING + osLogEvent(l, 500, 4, sc->frameCount, sc->curRSPTask, sc->curRDPTask); +#endif + + /* + * Read the task command queue and schedule tasks + */ + while (osRecvMesg(&sc->cmdQ, (OSMesg *)&rspTask, OS_MESG_NOBLOCK) != -1) { + __scAppendList(sc, rspTask); + } + + if (sc->doAudio && sc->curRSPTask) { + /* + * Preempt the running gfx task. Note: if the RSP + * component of the graphics task has finished, but the + * RDP component is still running, we can start an audio + * task which will freeze the RDP (and save the RDP cmd + * FIFO) while the audio RSP code is running. + */ + __scYield(sc); + } else { + state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); + if ( __scSchedule (sc, &sp, &dp, state) != state) + __scExec(sc, sp, dp); + } + + /* + * notify audio and graphics threads to start building the command + * lists for the next frame (client threads may choose not to + * build the list in overrun case) + */ + for (client = sc->clientList; client != 0; client = client->next) { + osSendMesg(client->msgQ, (OSMesg) &sc->retraceMsg, OS_MESG_NOBLOCK); + } +} + +/* + * __scHandleRSP is called when an RSP task signals that it has + * finished or yielded (at the hosts request) + */ +void __scHandleRSP(OSSched *sc) +{ + OSScTask *t, *sp = 0, *dp = 0; + s32 state; + + + assert(sc->curRSPTask); + + t = sc->curRSPTask; + sc->curRSPTask = 0; + +#ifdef SC_LOGGING + osLogEvent(l, 510, 3, t, t->state, t->flags); +#endif + + if ((t->state & OS_SC_YIELD) && osSpTaskYielded(&t->list)) { + t->state |= OS_SC_YIELDED; +#ifndef _FINALROM + t->totalTime += osGetTime() - t->startTime; +#endif + if ((t->flags & OS_SC_TYPE_MASK) == OS_SC_XBUS) { + /* push the task back on the list */ + t->next = sc->gfxListHead; + sc->gfxListHead = t; + if (sc->gfxListTail == 0) + sc->gfxListTail = t; + } + +#ifdef SC_LOGGING + osLogEvent(l, 521, 1, t); +#endif + + } else { + t->state &= ~OS_SC_NEEDS_RSP; + __scTaskComplete(sc, t); + } + + state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); + if ( (__scSchedule (sc, &sp, &dp, state)) != state) + __scExec(sc, sp, dp); +} + +/* + * __scHandleRDP is called when an RDP task signals that it has + * finished + */ +void __scHandleRDP(OSSched *sc) +{ + OSScTask *t, *sp = 0, *dp = 0; + s32 state; + + assert(sc->curRDPTask); + assert(sc->curRDPTask->list.t.type == M_GFXTASK); + + t = sc->curRDPTask; + sc->curRDPTask = 0; + +#ifdef SC_LOGGING + osLogEvent(l, 515, 3, t, t->state, t->flags); +#endif + + t->state &= ~OS_SC_NEEDS_RDP; + + __scTaskComplete(sc, t); + + state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); + if ( (__scSchedule (sc, &sp, &dp, state)) != state) + __scExec(sc, sp, dp); +} + +/* + * __scTaskReady checks to see if the graphics task is able to run + * based on the current state of the RCP. + */ +OSScTask *__scTaskReady(OSScTask *t) +{ + int rv = 0; + void *a; + void *b; + + if (t) { + /* + * If there is a pending swap bail out til later (next + * retrace). + */ + if ((a=osViGetCurrentFramebuffer()) != (b=osViGetNextFramebuffer())) { +#ifdef SC_LOGGING + osLogEvent(l, 513, 2, a, b); +#endif + return 0; + } + + return t; + } + + return 0; +} + +/* + * __scTaskComplete checks to see if the task is complete (all RCP + * operations have been performed) and sends the done message to the + * client if it is. + */ +s32 __scTaskComplete(OSSched *sc, OSScTask *t) +{ + int rv; + static int firsttime = 1; + + if ((t->state & OS_SC_RCP_MASK) == 0) { /* none of the needs bits set */ + + assert (t->msgQ); + +#ifndef _FINALROM + t->totalTime += osGetTime() - t->startTime; +#endif + +#ifdef SC_LOGGING + osLogEvent(l, 504, 1, t); +#endif + rv = osSendMesg(t->msgQ, t->msg, OS_MESG_BLOCK); + + if (t->list.t.type == M_GFXTASK) { + if ((t->flags & OS_SC_SWAPBUFFER) && (t->flags & OS_SC_LAST_TASK)){ + if (firsttime) { + osViBlack(FALSE); + firsttime = 0; + } + osViSwapBuffer(t->framebuffer); +#ifdef SC_LOGGING + osLogEvent(l, 525, 1, t->framebuffer); +#endif + } + } + return 1; + } + + return 0; +} + +/* + * Place task on either the audio or graphics queue + */ +void __scAppendList(OSSched *sc, OSScTask *t) +{ + long type = t->list.t.type; + + assert ( (type == M_AUDTASK) || (type == M_GFXTASK)); + + if (type == M_AUDTASK) { + if (sc->audioListTail) + sc->audioListTail->next = t; + else + sc->audioListHead = t; + + sc->audioListTail = t; + sc->doAudio = 1; +#ifdef SC_LOGGING + osLogEvent(l, 506, 1, t); +#endif + } else { + if (sc->gfxListTail) + sc->gfxListTail->next = t; + else + sc->gfxListHead = t; + + sc->gfxListTail = t; +#ifdef SC_LOGGING + osLogEvent(l, 507, 1, t); +#endif + } + + t->next = NULL; + t->state = t->flags & OS_SC_RCP_MASK; +} + +/* + * + */ +void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp) +{ + int rv; + +#ifdef SC_LOGGING + osLogEvent(l, 511, 2, sp, dp); +#endif + + assert(sc->curRSPTask == 0); + + if (sp) { + if (sp->list.t.type == M_AUDTASK) { + osWritebackDCacheAll(); /* flush the cache */ + } + + sp->state &= ~(OS_SC_YIELD | OS_SC_YIELDED); +#ifndef _FINALROM + sp->startTime = osGetTime(); +#endif + osSpTaskLoad(&sp->list); + osSpTaskStartGo(&sp->list); + sc->curRSPTask = sp; + if (sp == dp) + sc->curRDPTask = dp; + } + + if (dp && (dp != sp)) { + assert(dp->list.t.output_buff); + +#ifdef SC_LOGGING + osLogEvent(l, 523, 3, dp, dp->list.t.output_buff, + (u32)*dp->list.t.output_buff_size); +#endif + rv = osDpSetNextBuffer(dp->list.t.output_buff, + *dp->list.t.output_buff_size); + + dp_busy = 1; + dpCount = 0; + + assert(rv == 0); + + sc->curRDPTask = dp; + } +} + +static void __scYield(OSSched *sc) +{ + +#ifdef SC_LOGGING + osLogEvent(l, 503, 1, sc->curRSPTask ); +#endif + + if (sc->curRSPTask->list.t.type == M_GFXTASK) { + +/* assert(sc->curRSPTask->state & OS_SC_YIELD);*/ + + sc->curRSPTask->state |= OS_SC_YIELD; + + osSpTaskYield(); + } else { +#ifdef SC_LOGGING + osLogEvent(l, 508, 1, sc->curRSPTask); +#endif + } +} + +/* + * Schedules the tasks to be run on the RCP + */ +s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) +{ + s32 avail = availRCP; + OSScTask *gfx = sc->gfxListHead; + OSScTask *audio = sc->audioListHead; + +#ifdef SC_LOGGING + osLogEvent(l, 517, 3, *sp, *dp, availRCP); +#endif + + if (sc->doAudio && (avail & OS_SC_SP)) { + + if (gfx && (gfx->flags & OS_SC_PARALLEL_TASK)) { + *sp = gfx; + avail &= ~OS_SC_SP; + } else { + *sp = audio; + avail &= ~OS_SC_SP; + sc->doAudio = 0; + sc->audioListHead = sc->audioListHead->next; + if (sc->audioListHead == NULL) + sc->audioListTail = NULL; + } + } else { +#ifdef SC_LOGGING + osLogEvent(l, 520, 1, gfx); +#endif + if (__scTaskReady(gfx)) { + +#ifdef SC_LOGGING + osLogEvent(l, 522, 3, gfx, gfx->state, gfx->flags); +#endif + switch (gfx->flags & OS_SC_TYPE_MASK) { + case (OS_SC_XBUS): + if (gfx->state & OS_SC_YIELDED) { +#ifdef SC_LOGGING + osLogEvent(l, 518, 0); +#endif + /* can hit this if RDP finishes at yield req */ + /* assert(gfx->state & OS_SC_DP); */ + + if (avail & OS_SC_SP) { /* if SP is available */ +#ifdef SC_LOGGING + osLogEvent(l, 519, 0); +#endif + *sp = gfx; + avail &= ~OS_SC_SP; + + if (gfx->state & OS_SC_DP) { /* if it needs DP */ + *dp = gfx; + avail &= ~OS_SC_DP; + + if (avail & OS_SC_DP == 0) + assert(sc->curRDPTask == gfx); + + } + + sc->gfxListHead = sc->gfxListHead->next; + if (sc->gfxListHead == NULL) + sc->gfxListTail = NULL; + + } + } else { + if (avail == (OS_SC_SP | OS_SC_DP)) { + *sp = *dp = gfx; + avail &= ~(OS_SC_SP | OS_SC_DP); + sc->gfxListHead = sc->gfxListHead->next; + if (sc->gfxListHead == NULL) + sc->gfxListTail = NULL; + } + } + + break; + + case (OS_SC_DRAM): + case (OS_SC_DP_DRAM): + case (OS_SC_DP_XBUS): + if (gfx->state & OS_SC_SP) { /* if needs SP */ + if (avail & OS_SC_SP) { /* if SP is available */ + *sp = gfx; + avail &= ~OS_SC_SP; + } + } else if (gfx->state & OS_SC_DP) { /* if needs DP */ + if (avail & OS_SC_DP) { /* if DP available */ + *dp = gfx; + avail &= ~OS_SC_DP; + sc->gfxListHead = sc->gfxListHead->next; + if (sc->gfxListHead == NULL) + sc->gfxListTail = NULL; + } + } + break; + + case (OS_SC_SP_DRAM): + case (OS_SC_SP_XBUS): + default: + break; + } + } + } + + if (avail != availRCP) + avail = __scSchedule(sc, sp, dp, avail); + + return avail; + +} + diff --git a/lib/ultralib/src/sched/sched_log.fmt b/lib/ultralib/src/sched/sched_log.fmt new file mode 100644 index 0000000..50e042d --- /dev/null +++ b/lib/ultralib/src/sched/sched_log.fmt @@ -0,0 +1,19 @@ +500 "__scHandleRetrace: framecount %d, curRSPTask 0x%x, curRDPTask 0x%x" +510 "__scHandleRSP: Current 0x%x state 0x%x flags 0x%x" +521 "__scHandleRSP: Yielded Task 0x%x" +515 "__scHandleRDP: Current 0x%x state 0x%x flags 0x%x" +513 "__scTaskReady: Pending swap bail - current 0x%x next 0x%x" +514 "__scTaskReady: Rendering bail - current 0x%x" +504 "__scTaskComplete: Task 0x%x" +525 "__scTaskComplete: Swapbuffer 0x%x" +506 "__scAppendList: Audio task 0x%x" +507 "__scAppendList: Gfx task 0x%x" +511 "__scExec: sp 0x%x, dp 0x%x" +523 "__scExec: DP only buf 0x%x, size %d" +503 "__scYield: curRSPtask 0x%x" +508 "__scYield: NOT A GFX TASK!! curRSPtask 0x%x" +517 "__scSchedule: sp 0x%x, dp 0x%x, avail 0x%x" +520 "__scSchedule: gfx task 0x%x" +522 "__scSchedule: gfx task ready 0x%x, state 0x%x, flags 0x%x" +518 "__scSchedule: Yielded" +519 "__scSchedule: SP available" diff --git a/lib/ultralib/src/sp/Makefile b/lib/ultralib/src/sp/Makefile new file mode 100644 index 0000000..7807431 --- /dev/null +++ b/lib/ultralib/src/sp/Makefile @@ -0,0 +1,30 @@ +#!smake +# +# Makefile for the sp subdirectory +# + +include $(ROOT)/usr/include/make/PRdefs + + +# LCOPTS = -mips2 -non_shared -fullwarn -G 0 +LCINCS = -I. -I$(ROOT)/usr/include/PR -I$(ROOT)/usr/include + +CFILES = \ + clearattribute.c \ + color.c \ + hide.c \ + setattribute.c \ + show.c \ + sprite.c \ + spriteex.c \ + spriteex2.c \ + spscale.c + + +ASFILES = + +OBJECTS = $(CFILES:.c=.o) + +default: $(OBJECTS) + +include $(COMMONRULES) diff --git a/lib/ultralib/src/sp/clearattribute.c b/lib/ultralib/src/sp/clearattribute.c new file mode 100644 index 0000000..e5faf16 --- /dev/null +++ b/lib/ultralib/src/sp/clearattribute.c @@ -0,0 +1,35 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + */ + +#include + +/* + * spClearAttribute() + * + * Clears attributes about a sprite. + */ +void +spClearAttribute (Sprite *sp, s32 attr) +{ + sp->attr &= ~attr; +} diff --git a/lib/ultralib/src/sp/color.c b/lib/ultralib/src/sp/color.c new file mode 100644 index 0000000..a5abc85 --- /dev/null +++ b/lib/ultralib/src/sp/color.c @@ -0,0 +1,39 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + */ + +#include + +/* + * spColor() + * + * Sets the color for IA or I images. + */ +void +spColor (Sprite *sp, unsigned char red, unsigned char green, + unsigned char blue, unsigned char alpha) +{ + sp->red = red; + sp->green = green; + sp->blue = blue; + sp->alpha = alpha; +} diff --git a/lib/ultralib/src/sp/hide.c b/lib/ultralib/src/sp/hide.c new file mode 100644 index 0000000..6223c2c --- /dev/null +++ b/lib/ultralib/src/sp/hide.c @@ -0,0 +1,35 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + */ + +#include + +/* + * spHide() + * + * Hides a sprite so that it will not be drawn at the next spUpdate(). + */ +void +spHide (Sprite *sp) +{ + spSetAttribute (sp, SP_HIDDEN); +} diff --git a/lib/ultralib/src/sp/setattribute.c b/lib/ultralib/src/sp/setattribute.c new file mode 100644 index 0000000..887df08 --- /dev/null +++ b/lib/ultralib/src/sp/setattribute.c @@ -0,0 +1,35 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + */ + +#include + +/* + * spSetAttribute() + * + * Sets attributes about a sprite. + */ +void +spSetAttribute ( Sprite *sp, s32 attr) +{ + sp->attr |= attr; +} diff --git a/lib/ultralib/src/sp/show.c b/lib/ultralib/src/sp/show.c new file mode 100644 index 0000000..dc0db54 --- /dev/null +++ b/lib/ultralib/src/sp/show.c @@ -0,0 +1,35 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + */ + +#include + +/* + * spShow() + * + * Shows a sprite so that it will be drawn at the next spUpdate(). + */ +void +spShow (Sprite *sp) +{ + spClearAttribute (sp, SP_HIDDEN); +} diff --git a/lib/ultralib/src/sp/sprite.c b/lib/ultralib/src/sp/sprite.c new file mode 100644 index 0000000..719a662 --- /dev/null +++ b/lib/ultralib/src/sp/sprite.c @@ -0,0 +1,761 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + */ +#include +#include +#include +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +/* + * spSetZ() + * + */ +void +spSetZ (Sprite *sp, s32 z) +{ + +#ifdef DEBUG + emPrintf("spSetZ (Sprite 0x%08x, (%d))\n", sp, z ); +#endif + + sp->zdepth = (s16)z; +} + +/* + * spMove() + * + * Moves a sprite on the screen. + */ +void +spMove (Sprite *sp, s32 x, s32 y) +{ + +#ifdef DEBUG + emPrintf("spMove (Sprite 0x%08x, (%d,%d))\n", sp, x, y ); +#endif + + sp->x = (s16)x; + sp->y = (s16)y; +} + +static s32 scissor_xmax; +static s32 scissor_ymax; + +static s32 scissor_xmin; +static s32 scissor_ymin; + +/* + * spScissor() + * + * Sets the scissoring box to be used for subsequent Sprite Drawing + */ +void +spScissor (s32 xmin, s32 xmax, s32 ymin, s32 ymax ) +{ + scissor_xmin = xmin; + scissor_ymin = ymin; + + scissor_xmax = xmax; + scissor_ymax = ymax; +} + +static int *prev_bmbuf = NULL; + +/* + * drawbitmap() + * + * Draws a bitmap from a sprite at a location on the screen. If the + * "usevert" flag is set, then the routine will use vertices and triangles + * to draw the bitmap. Otherwise, the texture rectangle instruction + * will be used. + */ + +static void +drawbitmap (Gfx **glp, Sprite *s, Bitmap *b, + s32 x, s32 y, s32 xx, s32 yy, s32 fs, s32 ft, s32 sx, s32 sy) +{ + s32 rs, rt; + s32 rxh, ryh; + s32 rxl, ryl; + Gfx *gl; + s32 tex_width, tex_height; + Gtexrect gt, *g; + s32 s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod; + + g = > + + tex_width = b->width_img; + tex_height= s->bmHreal; + +#ifdef rmDEBUG + rmonPrintf("\tdrawbitmap (buf= 0x%08x; x,y= %d,%d; w,h= %d,%d )\n", + b->buf, x, y, b->width, s->bmheight ); +#endif + gl = *glp; + + /* Scissoring */ + if( (x >= scissor_xmax) || (y >= scissor_ymax) ) { +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: Upper Left corner (%d,%d) beyond range (%d,%d)\n", + x, y, scissor_xmax, scissor_ymax ); +#endif + return; + } + + if( (xx < scissor_xmin) || (yy < scissor_ymin) ) { +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: Lower Right corner (%d,%d) not in range (%d,%d)\n", + xx, yy, scissor_xmin, scissor_ymin ); +#endif + return; + } + + + if (x < scissor_xmin) { + rxh = scissor_xmin*4; + rs = (b->s<<5) + fs + (((scissor_xmin - x)*sx)>>5); +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: Left Edge (%d) not in range (%d,%d)\n", + x, scissor_xmin, scissor_xmax ); +#endif + } else { + rxh = x*4; + rs = (b->s<<5) + fs; + }; + + if (y < scissor_ymin) { + ryh = scissor_ymin*4; + rt = (b->t<<5) + ft + (((scissor_ymin-y)*sy)>>5); +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: Top Edge (%d) not in range (%d,%d)\n", + y, scissor_ymin, scissor_ymax ); +#endif + } else { + ryh = y*4; + rt = (b->t<<5) + ft; + } + + if( xx >= scissor_xmax ) { + rxl = scissor_xmax*4; +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: Right Edge (%d) not in range (%d,%d)\n", + xx, scissor_xmin, scissor_xmax ); +#endif + } else { + rxl = xx*4; + }; + + if( yy >= scissor_ymax ) { + ryl = scissor_ymax*4; +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: Bottom Edge (%d) not in range (%d,%d)\n", + yy, scissor_ymin, scissor_ymax ); +#endif + } else { + ryl = yy*4; + }; + + s_clamp = G_TX_CLAMP; t_clamp = G_TX_CLAMP; + s_mask = G_TX_NOMASK; t_mask = G_TX_NOMASK; + s_lod = G_TX_NOLOD; t_lod = G_TX_NOLOD; + +#define LOAD_TEX + +#ifdef LOAD_TEX + if( b->buf != prev_bmbuf ) { + switch(s->bmsiz) + { +#if BUILD_VERSION >= VERSION_J + case G_IM_SIZ_DD: + gDPLoadTextureTile_4b(gl++, b->buf, s->bmfmt, tex_width, tex_height, + b->s, b->t, + b->s + b->width,b->t + b->actualHeight, + 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + break; +#endif + case G_IM_SIZ_4b: + if (s->attr & SP_TEXSHUF) { + gDPLoadTextureBlock_4bS(gl++, b->buf, s->bmfmt, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + } else { + gDPLoadTextureBlock_4b(gl++, b->buf, s->bmfmt, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + }; + break; + + case G_IM_SIZ_8b: + if (s->attr & SP_TEXSHUF) { + gDPLoadTextureBlockS(gl++, b->buf, s->bmfmt, G_IM_SIZ_8b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + } else { + gDPLoadTextureBlock(gl++, b->buf, s->bmfmt, G_IM_SIZ_8b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + }; + break; + case G_IM_SIZ_16b: + if (s->bmfmt == G_IM_FMT_YUV ) { + if (s->attr & SP_TEXSHUF) { + gDPLoadTextureBlockYuvS(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + } else { + if( b->LUToffset != 0 ) { /* Split Y and UV areas */ + unsigned char *uv, *addr; + int j; + s32 tmem, siz; + + gDPSetTextureImage( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 1, b->buf); + gDPSetTile( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 0, 256, G_TX_LOADTILE, 0, + t_clamp, t_mask, t_lod, + s_clamp, s_mask, s_lod ); + gDPLoadSync( gl++ ); + gDPLoadBlock( gl++, G_TX_LOADTILE, 0,0, tex_width*tex_height -1, + CALC_DXT(tex_width,1) ); + gDPLoadSync( gl++ ); + + uv = ((unsigned char *)b->buf) + + ((tex_width*tex_height)/2)*b->LUToffset; + + for( j=0; j<=(tex_height/2); j++ ) { + addr = uv + ((tex_height/2) -2 -j)*tex_width; + siz = 3*tex_width; + tmem = (tex_width/8)*(tex_height - 2 - 2*j); + if( tmem < 0 ) { + addr += (-tmem)*8; + siz -= (-tmem)*8; + tmem = 0; + }; + if( j == 0 ) + siz = 2*tex_width; + + gDPSetTextureImage( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 1, addr); + gDPSetTile( gl++, G_IM_FMT_I, G_IM_SIZ_8b, 0, tmem, + G_TX_LOADTILE, 0, + t_clamp, t_mask, t_lod, + s_clamp, s_mask, s_lod ); + gDPLoadSync( gl++ ); + gDPLoadBlock( gl++, G_TX_LOADTILE, 0,0, siz -1, + CALC_DXT(tex_width,1) ); + gDPLoadSync( gl++ ); + }; + + gDPSetTile( gl++, s->bmfmt, G_IM_SIZ_16b, (((tex_width) * 1)+7)>>3, 0, + G_TX_RENDERTILE, 0, + t_clamp, t_mask, t_lod, + s_clamp, s_mask, s_lod ); + gDPSetTileSize( gl++, G_TX_RENDERTILE, 0, 0, + ((tex_width)-1) << G_TEXTURE_IMAGE_FRAC, + ((tex_height)-1) << G_TEXTURE_IMAGE_FRAC ); + + } else { + gDPLoadTextureBlockYuv(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + }; + }; + } else { + if (s->attr & SP_TEXSHUF) { + gDPLoadTextureBlockS(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + } else { + gDPLoadTextureBlock(gl++, b->buf, s->bmfmt, G_IM_SIZ_16b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + }; + }; + break; + case G_IM_SIZ_32b: + if (s->attr & SP_TEXSHUF) { + gDPLoadTextureBlockS(gl++, b->buf, s->bmfmt, G_IM_SIZ_32b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + } else { + gDPLoadTextureBlock(gl++, b->buf, s->bmfmt, G_IM_SIZ_32b, + tex_width, tex_height, 0, + s_clamp, t_clamp, + s_mask, t_mask, + s_lod, t_lod); + }; + break; + } + prev_bmbuf = b->buf; + } +#endif /* LOAD_TEX */ + + + g->cmd = G_TEXRECT; + g->tile = 0; + + g->xh = rxh; + g->xl = rxl; + g->yh = ryh; + g->yl = ryl; + + g->s = rs; + g->t = rt; + + if ((s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) + g->dsdx = sx * 4; + else + g->dsdx = sx; + + g->dtdy = sy; + +#ifdef rmDEBUG + rmonPrintf("\trect (xh,l= %d,%d, yh,l= %d,%d, s,t= %d,%d, dsdx=%d, dtdy=%d )\n", + rxh,rxl,ryh,ryl,rs,rt,g->dsdx,sy ); +#endif + + gSPTextureRectangle(gl++,g->xh,g->yh,g->xl,g->yl,g->tile,g->s,g->t,g->dsdx,g->dtdy); + + gDPPipeSync(gl++); + + *glp = gl; +} + +static u16 sp_attr = 0; + +void +spInit( Gfx **glistp ) +{ + Gfx *gl; + + gl = *glistp; + +#ifdef DEBUG + emPrintf("spInit ()\n" ); +#endif + sp_attr = 0; + + scissor_xmin = 0; + scissor_ymin = 0; + + scissor_xmax = 320; + scissor_ymax = 240; + + /* Turn on texturing */ + gDPPipeSync ( gl++ ); + gDPSetCycleType ( gl++, G_CYC_1CYCLE); + gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON); + gDPSetAlphaCompare ( gl++, G_AC_NONE ); + gDPSetTexturePersp ( gl++, G_TP_NONE ); + gDPSetTextureFilter ( gl++, G_TF_BILERP ); + gDPSetTextureConvert( gl++, G_TC_FILT ); + gDPSetTextureDetail ( gl++, G_TD_CLAMP ); + gDPSetTextureLOD ( gl++, G_TL_TILE ); + gDPSetTextureLUT ( gl++, G_TT_NONE ); + +#define SPRITE_SURF G_RM_TEX_EDGE +#define SPRITE_SURF2 G_RM_TEX_EDGE2 + + gDPSetRenderMode( gl++, SPRITE_SURF, SPRITE_SURF2); + + *glistp = gl; +} + + +/* + * spDraw() + * + * Draws all of the sprites that are associated with bitmaps and that + * are supposed to be drawn (spDraw()). They are drawn from 0 to maxsp, + * so sprites with higher numbers will overwrite lower-numbered sprites. + * + */ +Gfx * +spDraw ( Sprite *s ) +{ + int i; + s32 x, y; + float sx, sy; + Bitmap *b; + Gfx *gl; +#ifndef NDEBUG + Gfx *ogl; +#endif + Gfx *dl_start; + s32 isx, isy; + s32 tx, ty; + s32 tx2, ty2; + s32 x2, y2; + float ftx, fty; + s32 fs, ft; + s32 ex, ey; + +#ifdef rmDEBUG + rmonPrintf("spDraw (Sprite 0x%08x )\n", s ); +#endif + + if (s->attr & SP_HIDDEN) + return(NULL); + + prev_bmbuf = NULL; + + gl = s->rsp_dl_next; + if( gl == NULL ) + gl = s->rsp_dl; + dl_start = gl; + +#ifndef NDEBUG + ogl = gl; +#endif + + b = s->bitmap; + ex = 0; + ey = 0; + + if (sp_attr & SP_EXTERN) /* previous attr was extern? */ + sp_attr = ~s->attr; /* Assume previous modes are all different + from new ones */ + + if (s->attr & SP_EXTERN) /* current attr is extern? */ + sp_attr = s->attr; /* Assume all settings should remain the same */ + + if (s->attr != sp_attr) { + if ((s->attr & SP_TRANSPARENT) && !(sp_attr & SP_TRANSPARENT)) { + gDPSetRenderMode( gl++, G_RM_XLU_SURF, G_RM_XLU_SURF2); + } else if (!(s->attr & SP_TRANSPARENT) && + (sp_attr & SP_TRANSPARENT)) { + gDPSetRenderMode( gl++, + SPRITE_SURF, SPRITE_SURF2); + } + + if ((s->attr & SP_CUTOUT) && !(sp_attr & SP_CUTOUT)) { + gDPSetBlendColor ( gl++, 0xff, 0xff, 0xff, 0x01); + gDPSetAlphaCompare ( gl++, G_AC_THRESHOLD) ; + } else if (!(s->attr & SP_CUTOUT) && (sp_attr & SP_CUTOUT)) { + gDPSetAlphaCompare ( gl++, G_AC_NONE) ; + } + + if( (s->attr & SP_TEXSHIFT) && !(sp_attr & SP_TEXSHIFT) ) { + gDPSetTextureFilter( gl++, G_TF_AVERAGE ); + } else if( !(s->attr & SP_TEXSHIFT) && (sp_attr & SP_TEXSHIFT) ) { + gDPSetTextureFilter( gl++, G_TF_BILERP ); + }; + + }; + + sp_attr = s->attr; + + if( sp_attr & SP_Z ) { + gDPSetPrimDepth(gl++, s->zdepth, 0); + }; + + + gDPSetPrimColor( gl++, 0, 0, s->red, s->green, s->blue, s->alpha); + + if (s->bmfmt == G_IM_FMT_IA || s->bmfmt == G_IM_FMT_I) { + if( s->alpha == 255 ) { + gDPSetCombineMode ( gl++, + G_CC_MODULATEIDECALA_PRIM, + G_CC_MODULATEIDECALA_PRIM); + } else { + gDPSetCombineMode ( gl++, + G_CC_MODULATEIA_PRIM, + G_CC_MODULATEIA_PRIM); + }; + } else { + if( s->alpha == 255 ) { + gDPSetCombineMode ( gl++, + G_CC_MODULATEIDECALA_PRIM, + G_CC_MODULATEIDECALA_PRIM); + } else { + gDPSetCombineMode ( gl++, + G_CC_MODULATERGBA_PRIM, + G_CC_MODULATERGBA_PRIM); + }; + } + + + if( s->bmfmt == G_IM_FMT_CI ) { + gDPSetTextureLUT( gl++, G_TT_RGBA16); + gDPLoadTLUT( gl++, s->nTLUT, 256+s->startTLUT, s->LUT ); + gDPLoadSync( gl++ ); + }; + +#define MY_K0 (175 & 0x1ff) +#define MY_K1 (-43 & 0x1ff) +#define MY_K2 (-89 & 0x1ff) +#define MY_K3 (222 & 0x1ff) +#define MY_K4 (114 & 0x1ff) +#define MY_K5 (42 & 0x1ff) + + if( (s->bmfmt == G_IM_FMT_YUV) && (s->attr & SP_FASTCOPY) ) { + gDPSetTextureConvert( gl++, G_TC_CONV); + gDPSetTextureFilter( gl++, G_TF_POINT); + gDPSetCombineMode( gl++, G_CC_1CYUV2RGB, G_CC_1CYUV2RGB); + gDPSetConvert( gl++, MY_K0, MY_K1, MY_K2, MY_K3, MY_K4, MY_K5); + } else if(s->bmfmt == G_IM_FMT_YUV) { + gDPSetCycleType( gl++, G_CYC_2CYCLE ); + gDPSetTextureFilter( gl++, G_TF_BILERP); + gDPSetTextureConvert( gl++, G_TC_FILTCONV); + gDPSetConvert( gl++, MY_K0, MY_K1, MY_K2, MY_K3, MY_K4, MY_K5); + gDPSetCombineMode( gl++, G_CC_YUV2RGB, G_CC_PASS2); + } + + if (s->attr & SP_SCALE) { + sx = s->scalex; + sy = s->scaley; + } else { + sx = 1.0F; + sy = 1.0F; + } + + isx = (int) ((1<<10) / sx + 0.5F); + isy = (int) ((1<<10) / sy + 0.5F); + + if( b ) { + + if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) + gDPSetCycleType( gl++, G_CYC_COPY); + + x = 0.0F; + y = 0.0F; + + fty = s->y+y*sy; + ty = (int) ( fty + 0.99999F); + ft = (int) (isy * (ty - fty)); + ft = (ft + 16)>>5; + if( s->attr & SP_TEXSHIFT ) + ft += 16; /* 1/2 Texel for AntiAliasing */ + + if( s->attr & SP_FRACPOS ) + ft += s->frac_t; /* Micro-positioning */ + + y2 = y + s->bmheight; + ty2 = (int) (s->y+y2*sy + 0.99999F); + + if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) + ty2--; + + +#ifdef rmDEBUG + rmonPrintf("\tiscale=(%d,%d), %d bitmaps, sprite_size=(%d,%d)\n", + isx, isy, s->nbitmaps, s->width, s->height ); +#endif + + for( i=0; (i < s->nbitmaps) && (b->width > 0); i++, b++ ) { + + if( (x+b->width) > s->width ) { /* Next bitmap hits edge? */ + int bh; + + x = 0; + fs = 0; + ex = 0; + ey += s->expy; + y += s->bmheight; /* Wrap to next line */ + y2 = y + s->bmheight; /* Wrap to next line */ + + fty = s->y+y*sy; + ty = (int) ( fty + 0.9999F); + ft = (int) (isy * (ty - fty)); + ft = (ft + 16)>>5; + if( s->attr & SP_TEXSHIFT ) + ft += 16; /* 1/2 Texel for AntiAliasing */ + + if( s->attr & SP_FRACPOS ) + ft += s->frac_t; /* Micro-positioning */ + + ty2 = (int) (s->y+y2*sy + 0.9999F); + + ty += ey; + ty2 += ey; + + if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) + ty2--; + + /* Fill out to rect. bdy? */ + + if( (b->actualHeight != 0) ) + bh = b->actualHeight; + else + bh = s->bmheight; + + if( (y + bh) > s->height ) /* Can't wrap any more? */ + break; + }; + +#ifdef rmDEBUG + rmonPrintf("bm# %d, x,y=(%d,%d) width=%d \n", i, x, y, b->width ); +#endif + + ftx = s->x+x*sx; + tx = (s32) (ftx + 0.9999F); + fs = (s32) (isx * (tx - ftx)); + fs = (fs + 16)>>5; + if( s->attr & SP_TEXSHIFT ) + fs += 16; /* 1/2 Texel for AntiAliasing */ + + if( s->attr & SP_FRACPOS ) + fs += s->frac_s; /* Micro-positioning */ + + x2 = x + b->width; + tx2 = (int) (s->x+x2*sx + 0.9999F); + + if( (b->actualHeight != 0) ) { + y2 = y + b->actualHeight; + ty2 = (s32) (s->y+y2*sy + 0.9999F); + ty2 += ey; + + if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) + ty2--; + }; + +#ifdef rmDEBUG + rmonPrintf("\tfull(%g,%g) = int(%d,%d) + frac(%d,%d)\n", + ftx, fty, tx,ty, fs,ft ); +#endif + + tx += ex; + tx2 += ex; + + if( (s->attr & SP_FASTCOPY) && (s->bmfmt != G_IM_FMT_YUV) ) + tx2--; + + if( b->buf != NULL ) /* Skip over null bitmaps (blanks) */ + drawbitmap ( &gl, s, b, tx, ty, tx2, ty2, fs, ft, isx, isy); + + x += b->width; + ex += s->expx; + } + + if (s->attr & SP_FASTCOPY) + gDPSetCycleType( gl++, G_CYC_1CYCLE); + + if(s->bmfmt == G_IM_FMT_YUV) { + gDPSetCycleType( gl++, G_CYC_1CYCLE); + gDPSetTextureFilter ( gl++, G_TF_BILERP ); + gDPSetTextureConvert( gl++, G_TC_FILT ); + }; + + } else { + int rgba; + + x = (s32)s->x; + y = (s32)s->y; + x2 = s->x + (s->width*sx)-1; + y2 = s->y + (s->height*sy)-1; + + if( ( x >= scissor_xmax) || (y >= scissor_ymax) ) { +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: FILL Upper Left corner (%d,%d) beyond range (%d,%d)\n", + x, y, scissor_xmax, scissor_ymax ); +#endif + } else if( ( x2 < scissor_xmin) || (y2 < scissor_ymin) ) { +#ifdef DEBUG_SCISSOR + emPrintf("Sprite Scissoring: FILL Lower Right corner (%d,%d) below range (%d,%d)\n", + x2, y2, scissor_xmin, scissor_ymin ); +#endif + } else { + + if( x < scissor_xmin ) + x = scissor_xmin; + + if( x2 >= scissor_xmax ) + x2 = scissor_xmax - 1; + + if( y < scissor_ymin ) + y = scissor_ymin; + + if( y2 >= scissor_ymax ) + y2 = scissor_ymax - 1; + + rgba = GPACK_RGBA5551((s->red), (s->green), (s->blue), (s->alpha>>7)); + + gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_OFF); + gDPSetCycleType( gl++, G_CYC_FILL); + gDPSetFillColor( gl++, (rgba << 16) | (rgba) ); + + gDPFillRectangle( gl++, x,y, x2,y2 ); + gDPSetCycleType( gl++, G_CYC_1CYCLE); + gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON); + } + } + + if( s->bmfmt == G_IM_FMT_CI ) { + gDPSetTextureLUT( gl++, G_TT_NONE); + }; + + gSPEndDisplayList ( gl++ ); + +#if BUILD_VERSION >= VERSION_J +#line 722 +#else +#line 714 +#endif + assert((gl - ogl) < s->ndisplist); + s->rsp_dl_next = gl; + return( dl_start ); +} + +void +spFinish( Gfx **glistp ) +{ + Gfx *gl; + + gl = *glistp; + + /* Turn off texturing */ + gSPTexture ( gl++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_OFF); + gDPSetCombineMode ( gl++, G_CC_SHADE, G_CC_SHADE); + + if (sp_attr & SP_TRANSPARENT) { + /* Turn off transparency */ + gDPSetRenderMode( gl++, G_RM_OPA_SURF, G_RM_OPA_SURF2); + } + + if (sp_attr & SP_CUTOUT) { + /* Turn off Alpha write enable */ + gDPSetAlphaCompare ( gl++, G_AC_NONE) ; + } + + gSPEndDisplayList ( gl++ ); + + *glistp = gl; +} diff --git a/lib/ultralib/src/sp/spriteex.c b/lib/ultralib/src/sp/spriteex.c new file mode 100644 index 0000000..772036f --- /dev/null +++ b/lib/ultralib/src/sp/spriteex.c @@ -0,0 +1,2 @@ +#define F3DEX_GBI +#include "sprite.c" diff --git a/lib/ultralib/src/sp/spriteex2.c b/lib/ultralib/src/sp/spriteex2.c new file mode 100644 index 0000000..2ef1221 --- /dev/null +++ b/lib/ultralib/src/sp/spriteex2.c @@ -0,0 +1,2 @@ +#define F3DEX_GBI_2 +#include "sprite.c" diff --git a/lib/ultralib/src/sp/spscale.c b/lib/ultralib/src/sp/spscale.c new file mode 100644 index 0000000..4f1bd92 --- /dev/null +++ b/lib/ultralib/src/sp/spscale.c @@ -0,0 +1,42 @@ +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + */ + +#include + +/* + * spScale() + * + * Scales the sprite by a vertical and horizontal factor. + */ +void +spScale (Sprite *sp, float sx, float sy) +{ + + sp->scalex = sx; + sp->scaley = sy; + + if( (sx == 1.0F) && (sy == 1.0F) ) + spClearAttribute( sp, SP_SCALE ); + else + spSetAttribute( sp, SP_SCALE ); +} diff --git a/lib/ultralib/src/vimodes/vimodefpalhaf1.c b/lib/ultralib/src/vimodes/vimodefpalhaf1.c new file mode 100644 index 0000000..5ad95fa --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpalhaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalHaf1 = { + OS_VI_FPAL_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhan1.c b/lib/ultralib/src/vimodes/vimodefpalhan1.c new file mode 100644 index 0000000..f29ff4b --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpalhan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalHan1 = { + OS_VI_FPAL_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpf1.c b/lib/ultralib/src/vimodes/vimodefpalhpf1.c new file mode 100644 index 0000000..db0eb9d --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpalhpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalHpf1 = { + OS_VI_FPAL_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpf2.c b/lib/ultralib/src/vimodes/vimodefpalhpf2.c new file mode 100644 index 0000000..dfd3d92 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpalhpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalHpf2 = { + OS_VI_FPAL_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpn1.c b/lib/ultralib/src/vimodes/vimodefpalhpn1.c new file mode 100644 index 0000000..8b665a8 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpalhpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalHpn1 = { + OS_VI_FPAL_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpalhpn2.c b/lib/ultralib/src/vimodes/vimodefpalhpn2.c new file mode 100644 index 0000000..c046e97 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpalhpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalHpn2 = { + OS_VI_FPAL_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallaf1.c b/lib/ultralib/src/vimodes/vimodefpallaf1.c new file mode 100644 index 0000000..e4a8a9e --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLaf1 = { + OS_VI_FPAL_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallaf2.c b/lib/ultralib/src/vimodes/vimodefpallaf2.c new file mode 100644 index 0000000..8b3b608 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallaf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLaf2 = { + OS_VI_FPAL_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallan1.c b/lib/ultralib/src/vimodes/vimodefpallan1.c new file mode 100644 index 0000000..f190f55 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLan1 = { + OS_VI_FPAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallan2.c b/lib/ultralib/src/vimodes/vimodefpallan2.c new file mode 100644 index 0000000..13c71e5 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallan2.c @@ -0,0 +1,36 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLan2 = { + OS_VI_FPAL_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpf1.c b/lib/ultralib/src/vimodes/vimodefpallpf1.c new file mode 100644 index 0000000..d1c307c --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLpf1 = { + OS_VI_FPAL_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpf2.c b/lib/ultralib/src/vimodes/vimodefpallpf2.c new file mode 100644 index 0000000..385b1df --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLpf2 = { + OS_VI_FPAL_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(45, 615), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(47, 617), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpn1.c b/lib/ultralib/src/vimodes/vimodefpallpn1.c new file mode 100644 index 0000000..6fbcfe9 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLpn1 = { + OS_VI_FPAL_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodefpallpn2.c b/lib/ultralib/src/vimodes/vimodefpallpn2.c new file mode 100644 index 0000000..c852cf9 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodefpallpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeFpalLpn2 = { + OS_VI_FPAL_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempalhaf1.c b/lib/ultralib/src/vimodes/vimodempalhaf1.c new file mode 100644 index 0000000..c9a74dc --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempalhaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalHaf1 = { + OS_VI_MPAL_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + //[0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + //[1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempalhan1.c b/lib/ultralib/src/vimodes/vimodempalhan1.c new file mode 100644 index 0000000..038163b --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempalhan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalHan1 = { + OS_VI_MPAL_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpf1.c b/lib/ultralib/src/vimodes/vimodempalhpf1.c new file mode 100644 index 0000000..4bbb0e5 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempalhpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalHpf1 = { + OS_VI_MPAL_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpf2.c b/lib/ultralib/src/vimodes/vimodempalhpf2.c new file mode 100644 index 0000000..b2fad3d --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempalhpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalHpf2 = { + OS_VI_MPAL_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpn1.c b/lib/ultralib/src/vimodes/vimodempalhpn1.c new file mode 100644 index 0000000..3955a4f --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempalhpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalHpn1 = { + OS_VI_MPAL_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempalhpn2.c b/lib/ultralib/src/vimodes/vimodempalhpn2.c new file mode 100644 index 0000000..b4c7a6d --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempalhpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalHpn2 = { + OS_VI_MPAL_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallaf1.c b/lib/ultralib/src/vimodes/vimodempallaf1.c new file mode 100644 index 0000000..1369d39 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLaf1 = { + OS_VI_MPAL_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallaf2.c b/lib/ultralib/src/vimodes/vimodempallaf2.c new file mode 100644 index 0000000..0502362 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallaf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLaf2 = { + OS_VI_MPAL_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallan1.c b/lib/ultralib/src/vimodes/vimodempallan1.c new file mode 100644 index 0000000..a3f4e69 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLan1 = { + OS_VI_MPAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallan2.c b/lib/ultralib/src/vimodes/vimodempallan2.c new file mode 100644 index 0000000..65817e7 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallan2.c @@ -0,0 +1,36 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLan2 = { + OS_VI_MPAL_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallpf1.c b/lib/ultralib/src/vimodes/vimodempallpf1.c new file mode 100644 index 0000000..7df1655 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLpf1 = { + OS_VI_MPAL_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallpf2.c b/lib/ultralib/src/vimodes/vimodempallpf2.c new file mode 100644 index 0000000..285832e --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLpf2 = { + OS_VI_MPAL_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(524), // vSync + HSYNC(3088, 0), // hSync + LEAP(3100, 3100), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(2, 2, 11, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallpn1.c b/lib/ultralib/src/vimodes/vimodempallpn1.c new file mode 100644 index 0000000..8914794 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLpn1 = { + OS_VI_MPAL_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodempallpn2.c b/lib/ultralib/src/vimodes/vimodempallpn2.c new file mode 100644 index 0000000..40f381c --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodempallpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeMpalLpn2 = { + OS_VI_MPAL_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentschaf1.c b/lib/ultralib/src/vimodes/vimodentschaf1.c new file mode 100644 index 0000000..e6ad8bc --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentschaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscHaf1 = { + OS_VI_NTSC_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentschan1.c b/lib/ultralib/src/vimodes/vimodentschan1.c new file mode 100644 index 0000000..14711e7 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentschan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscHan1 = { + OS_VI_NTSC_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentschpf1.c b/lib/ultralib/src/vimodes/vimodentschpf1.c new file mode 100644 index 0000000..8f70311 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentschpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscHpf1 = { + OS_VI_NTSC_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentschpf2.c b/lib/ultralib/src/vimodes/vimodentschpf2.c new file mode 100644 index 0000000..8533e23 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentschpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscHpf2 = { + OS_VI_NTSC_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentschpn1.c b/lib/ultralib/src/vimodes/vimodentschpn1.c new file mode 100644 index 0000000..f82e277 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentschpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscHpn1 = { + OS_VI_NTSC_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentschpn2.c b/lib/ultralib/src/vimodes/vimodentschpn2.c new file mode 100644 index 0000000..d1b5974 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentschpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscHpn2 = { + OS_VI_NTSC_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclaf1.c b/lib/ultralib/src/vimodes/vimodentsclaf1.c new file mode 100644 index 0000000..fe12792 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLaf1 = { + OS_VI_NTSC_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclaf2.c b/lib/ultralib/src/vimodes/vimodentsclaf2.c new file mode 100644 index 0000000..acf2c3c --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclaf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLaf2 = { + OS_VI_NTSC_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclan1.c b/lib/ultralib/src/vimodes/vimodentsclan1.c new file mode 100644 index 0000000..0092a00 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLan1 = { + OS_VI_NTSC_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclan2.c b/lib/ultralib/src/vimodes/vimodentsclan2.c new file mode 100644 index 0000000..da2747b --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclan2.c @@ -0,0 +1,36 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLan2 = { + OS_VI_NTSC_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpf1.c b/lib/ultralib/src/vimodes/vimodentsclpf1.c new file mode 100644 index 0000000..b6bb5e7 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLpf1 = { + OS_VI_NTSC_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpf2.c b/lib/ultralib/src/vimodes/vimodentsclpf2.c new file mode 100644 index 0000000..f3f82c7 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLpf2 = { + OS_VI_NTSC_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpn1.c b/lib/ultralib/src/vimodes/vimodentsclpn1.c new file mode 100644 index 0000000..ecc68cb --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLpn1 = { + OS_VI_NTSC_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodentsclpn2.c b/lib/ultralib/src/vimodes/vimodentsclpn2.c new file mode 100644 index 0000000..bce83b8 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodentsclpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModeNtscLpn2 = { + OS_VI_NTSC_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepalhaf1.c b/lib/ultralib/src/vimodes/vimodepalhaf1.c new file mode 100644 index 0000000..3ff1394 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepalhaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalHaf1 = { + OS_VI_PAL_HAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepalhan1.c b/lib/ultralib/src/vimodes/vimodepalhan1.c new file mode 100644 index 0000000..3d32ba6 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepalhan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalHan1 = { + OS_VI_PAL_HAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpf1.c b/lib/ultralib/src/vimodes/vimodepalhpf1.c new file mode 100644 index 0000000..bdd0871 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepalhpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalHpf1 = { + OS_VI_PAL_HPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(0.5, 0.5), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpf2.c b/lib/ultralib/src/vimodes/vimodepalhpf2.c new file mode 100644 index 0000000..565ac4f --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepalhpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalHpf2 = { + OS_VI_PAL_HPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(0.5, 0.5), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(0.5, 0.5), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpn1.c b/lib/ultralib/src/vimodes/vimodepalhpn1.c new file mode 100644 index 0000000..a0c1ecc --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepalhpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalHpn1 = { + OS_VI_PAL_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepalhpn2.c b/lib/ultralib/src/vimodes/vimodepalhpn2.c new file mode 100644 index 0000000..d6e05b8 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepalhpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalHpn2 = { + OS_VI_PAL_HPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(5120), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallaf1.c b/lib/ultralib/src/vimodes/vimodepallaf1.c new file mode 100644 index 0000000..3d03857 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallaf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLaf1 = { + OS_VI_PAL_LAF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallaf2.c b/lib/ultralib/src/vimodes/vimodepallaf2.c new file mode 100644 index 0000000..4fc496c --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallaf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLaf2 = { + OS_VI_PAL_LAF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_SERRATE_ON | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallan1.c b/lib/ultralib/src/vimodes/vimodepallan1.c new file mode 100644 index 0000000..22a893c --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLan1 = { + OS_VI_PAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallan2.c b/lib/ultralib/src/vimodes/vimodepallan2.c new file mode 100644 index 0000000..d32360b --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallan2.c @@ -0,0 +1,36 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLan2 = { + OS_VI_PAL_LAN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallpf1.c b/lib/ultralib/src/vimodes/vimodepallpf1.c new file mode 100644 index 0000000..37d68e4 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallpf1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLpf1 = { + OS_VI_PAL_LPF1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallpf2.c b/lib/ultralib/src/vimodes/vimodepallpf2.c new file mode 100644 index 0000000..c37ebe1 --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallpf2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLpf2 = { + OS_VI_PAL_LPF2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(624), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0.25), // yScale + HSTART(93, 567), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0.75), // yScale + HSTART(95, 569), // vStart + BURST(105, 2, 13, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallpn1.c b/lib/ultralib/src/vimodes/vimodepallpn1.c new file mode 100644 index 0000000..eafbe6b --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLpn1 = { + OS_VI_PAL_LPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/vimodes/vimodepallpn2.c b/lib/ultralib/src/vimodes/vimodepallpn2.c new file mode 100644 index 0000000..49a26fd --- /dev/null +++ b/lib/ultralib/src/vimodes/vimodepallpn2.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "../io/viint.h" + +OSViMode osViModePalLpn2 = { + OS_VI_PAL_LPN2, // type + { + // comRegs + VI_CTRL_TYPE_32 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_ANTIALIAS_MODE_3 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/lib/ultralib/src/voice/voicecheckresult.c b/lib/ultralib/src/voice/voicecheckresult.c new file mode 100644 index 0000000..5318652 --- /dev/null +++ b/lib/ultralib/src/voice/voicecheckresult.c @@ -0,0 +1,28 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* stat) { + s32 ret; + u8 buf[2]; + + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, stat); + if (ret == 0) { + if (*stat & 1) { + ret = CONT_ERR_VOICE_NO_RESPONSE; + } else { + ret = __osVoiceContRead2(hd->__mq, hd->__channel, 0, buf); + if (ret == 0) { + hd->cmd_status = buf[0] & 7; + + if (buf[0] & 0x40) { + ret = CONT_ERR_VOICE_NO_RESPONSE; + } else { + ret = buf[1] << 8; + } + } + } + } + return ret; +} diff --git a/lib/ultralib/src/voice/voicecheckword.c b/lib/ultralib/src/voice/voicecheckword.c new file mode 100644 index 0000000..05c2a59 --- /dev/null +++ b/lib/ultralib/src/voice/voicecheckword.c @@ -0,0 +1,80 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" + +s32 osVoiceCheckWord(u8* word) { + s32 k; + s32 ret = 0; + u16 sjis; + u16 old = 0; + + for (k = 0; word[k] != 0; k += 2) { + sjis = (word[k] << 8) + word[k + 1]; + if (((sjis != 'ー') && (sjis < 'ぁ')) || ((sjis > 'ん') && (sjis < 'ァ')) || (sjis == 0x837F) || + (sjis > 'ヶ')) { + ret = CONT_ERR_VOICE_WORD; + } else if ((k == 0) && + ((sjis == 'ー') || (sjis == 'ん') || (sjis == 'っ') || (sjis == 'ゎ') || (sjis == 'ン') || + (sjis == 'ッ') || (sjis == 'ヮ') || (sjis == 'ヵ') || (sjis == 'ヶ'))) { + ret = CONT_ERR_VOICE_WORD; + } else if (((sjis == 'ぁ') || (sjis == 'ァ')) && (old != 'ふ') && (old != 'フ') && (old != 'ヴ')) { + ret = CONT_ERR_VOICE_WORD; + } else if (((sjis == 'ぃ') || (sjis == 'ィ')) && (old != 'う') && (old != 'て') && (old != 'で') && + (old != 'ふ') && (old != 'ウ') && (old != 'テ') && (old != 'デ') && (old != 'フ') && (old != 'ヴ')) { + ret = CONT_ERR_VOICE_WORD; + } else if (((sjis == 'ぅ') || (sjis == 'ゥ')) && (old != 'と') && (old != 'ど') && (old != 'ふ') && + (old != 'ト') && (old != 'ド') && (old != 'フ') && (old != 'ヴ')) { + ret = CONT_ERR_VOICE_WORD; + } else if (((sjis == 'ぇ') || (sjis == 'ェ')) && (old != 'う') && (old != 'し') && (old != 'じ') && + (old != 'ち') && (old != 'ぢ') && (old != 'つ') && (old != 'ふ') && (old != 'ウ') && (old != 'シ') && + (old != 'ジ') && (old != 'チ') && (old != 'ヂ') && (old != 'ツ') && (old != 'フ') && (old != 'ヴ')) { + ret = CONT_ERR_VOICE_WORD; + } else if (((sjis == 'ぉ') || (sjis == 'ォ')) && (old != 'う') && (old != 'ふ') && (old != 'ウ') && + (old != 'フ') && (old != 'ヴ')) { + ret = CONT_ERR_VOICE_WORD; + } else if (((sjis == 'ゃ') || (sjis == 'ゅ') || (sjis == 'ょ') || (sjis == 'ャ') || (sjis == 'ュ') || + (sjis == 'ョ')) && + (old != 'き') && (old != 'し') && (old != 'ち') && (old != 'に') && (old != 'ひ') && (old != 'み') && + (old != 'り') && (old != 'ぎ') && (old != 'じ') && (old != 'ぢ') && (old != 'び') && (old != 'ぴ') && + (old != 'キ') && (old != 'シ') && (old != 'チ') && (old != 'ニ') && (old != 'ヒ') && (old != 'ミ') && + (old != 'リ') && (old != 'ギ') && (old != 'ジ') && (old != 'ヂ') && (old != 'ビ') && (old != 'ピ') && + (old != 'ヴ')) { + ret = CONT_ERR_VOICE_WORD; + } else if ((sjis == 'ー') && ((old == 'ん') || (old == 'っ') || (old == 'ン') || (old == 'ッ'))) { + ret = CONT_ERR_VOICE_WORD; + } else if (((sjis == 'ん') || (sjis == 'ン')) && ((old == 'ん') || (old == 'ン'))) { + ret = CONT_ERR_VOICE_WORD; + } else if (((old == 'っ') || (old == 'ッ')) && + ((sjis == 'ー') || (sjis == 'あ') || (sjis == 'い') || (sjis == 'う') || (sjis == 'え') || + (sjis == 'お') || (sjis == 'な') || (sjis == 'に') || (sjis == 'ぬ') || (sjis == 'ね') || + (sjis == 'の') || (sjis == 'ま') || (sjis == 'み') || (sjis == 'む') || (sjis == 'め') || + (sjis == 'も') || (sjis == 'や') || (sjis == 'ゆ') || (sjis == 'よ') || (sjis == 'ら') || + (sjis == 'り') || (sjis == 'る') || (sjis == 'れ') || (sjis == 'ろ') || (sjis == 'わ') || + (sjis == 'ゐ') || (sjis == 'ゑ') || (sjis == 'を') || (sjis == 'ん') || (sjis == 'ぁ') || + (sjis == 'ぃ') || (sjis == 'ぅ') || (sjis == 'ぇ') || (sjis == 'ぉ') || (sjis == 'ゃ') || + (sjis == 'ゅ') || (sjis == 'ょ') || (sjis == 'っ') || (sjis == 'ゎ') + + || (sjis == 'ア') || (sjis == 'イ') || (sjis == 'ウ') || (sjis == 'エ') || (sjis == 'オ') || + (sjis == 'ナ') || (sjis == 'ニ') || (sjis == 'ヌ') || (sjis == 'ネ') || (sjis == 'ノ') || + (sjis == 'マ') || (sjis == 'ミ') || (sjis == 'ム') || (sjis == 'メ') || (sjis == 'モ') || + (sjis == 'ヤ') || (sjis == 'ユ') || (sjis == 'ヨ') || (sjis == 'ラ') || (sjis == 'リ') || + (sjis == 'ル') || (sjis == 'レ') || (sjis == 'ロ') || (sjis == 'ワ') || (sjis == 'ヰ') || + (sjis == 'ヱ') || (sjis == 'ヲ') || (sjis == 'ン') || (sjis == 'ァ') || (sjis == 'ィ') || + (sjis == 'ゥ') || (sjis == 'ェ') || (sjis == 'ォ') || (sjis == 'ャ') || (sjis == 'ュ') || + (sjis == 'ョ') || (sjis == 'ッ') || (sjis == 'ヮ'))) { + ret = CONT_ERR_VOICE_WORD; + } + + if (ret != 0) { + return ret; + } else { + old = sjis; + } + } + + if ((sjis == 'っ') || (sjis == 'ッ')) { + ret = CONT_ERR_VOICE_WORD; + } + + return ret; +} diff --git a/lib/ultralib/src/voice/voicecleardictionary.c b/lib/ultralib/src/voice/voicecleardictionary.c new file mode 100644 index 0000000..6ed1464 --- /dev/null +++ b/lib/ultralib/src/voice/voicecleardictionary.c @@ -0,0 +1,29 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words) { + s32 ret; + u8 stat; + u8 buf[4]; + + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); + if (ret != 0) { + return ret; + } else if (stat & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + *(u32*)buf = 0x02000000; + buf[2] = words; + + ERRCK(__osVoiceContWrite4(hd->__mq, hd->__channel, 0, buf)); + + ret = __osVoiceCheckResult(hd, &stat); + if (ret & 0xFF00) { + ret = CONT_ERR_INVALID; + } + + return ret; +} diff --git a/lib/ultralib/src/voice/voicecontread2.c b/lib/ultralib/src/voice/voicecontread2.c new file mode 100644 index 0000000..a204ffc --- /dev/null +++ b/lib/ultralib/src/voice/voicecontread2.c @@ -0,0 +1,73 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" +#include "io/controller_voice.h" +#include "io/siint.h" + +#define READ2FORMAT(ptr) ((__OSVoiceRead2Format*)(ptr)) + +s32 __osVoiceContRead2(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + u8 status; + int i; + u8* ptr; + int retry = 2; + + __osSiGetAccess(); + + do { + + ptr = (u8*)&__osPfsPifRam.ramarray; + + if ((__osContLastCmd != CONT_CMD_READ2_VOICE) || ((u32)__osPfsLastChannel != channel)) { + __osContLastCmd = CONT_CMD_READ2_VOICE; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + READ2FORMAT(ptr)->dummy = CONT_CMD_NOP; + READ2FORMAT(ptr)->txsize = CONT_CMD_READ2_VOICE_TX; + READ2FORMAT(ptr)->rxsize = CONT_CMD_READ2_VOICE_RX; + READ2FORMAT(ptr)->cmd = CONT_CMD_READ2_VOICE; + READ2FORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSVoiceRead2Format)] = CONT_CMD_END; + } else { + ptr += channel; + } + + READ2FORMAT(ptr)->addrh = address >> 3; + READ2FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*READ2FORMAT(ptr)); + + if (ret == 0) { + if (__osVoiceContDataCrc(READ2FORMAT(ptr)->data, ARRLEN(READ2FORMAT(ptr)->data)) != + READ2FORMAT(ptr)->datacrc) { + ret = __osVoiceGetStatus(mq, channel, &status); + if (ret != 0) { + break; + } else { + ret = CONT_ERR_CONTRFAIL; + } + } else { + bcopy(READ2FORMAT(ptr)->data, buffer, ARRLEN(READ2FORMAT(ptr)->data)); + } + } else { + ret = CONT_ERR_NO_CONTROLLER; + } + + } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/voice/voicecontread36.c b/lib/ultralib/src/voice/voicecontread36.c new file mode 100644 index 0000000..c537aff --- /dev/null +++ b/lib/ultralib/src/voice/voicecontread36.c @@ -0,0 +1,73 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" +#include "io/controller_voice.h" +#include "io/siint.h" + +#define READ36FORMAT(ptr) ((__OSVoiceRead36Format*)(ptr)) + +s32 __osVoiceContRead36(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + u8 status; + s32 i; + u8* ptr; + s32 retry = 2; + + __osSiGetAccess(); + + do { + + ptr = (u8*)&__osPfsPifRam.ramarray; + + if ((__osContLastCmd != CONT_CMD_READ36_VOICE) || ((u32)__osPfsLastChannel != channel)) { + __osContLastCmd = CONT_CMD_READ36_VOICE; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + READ36FORMAT(ptr)->dummy = CONT_CMD_NOP; + READ36FORMAT(ptr)->txsize = CONT_CMD_READ36_VOICE_TX; + READ36FORMAT(ptr)->rxsize = CONT_CMD_READ36_VOICE_RX; + READ36FORMAT(ptr)->cmd = CONT_CMD_READ36_VOICE; + READ36FORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSVoiceRead36Format)] = CONT_CMD_END; + } else { + ptr += channel; + } + + READ36FORMAT(ptr)->addrh = address >> 3; + READ36FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*READ36FORMAT(ptr)); + + if (ret == 0) { + if (__osVoiceContDataCrc(READ36FORMAT(ptr)->data, ARRLEN(READ36FORMAT(ptr)->data)) != + READ36FORMAT(ptr)->datacrc) { + ret = __osVoiceGetStatus(mq, channel, &status); + if (ret != 0) { + break; + } else { + ret = CONT_ERR_CONTRFAIL; + } + } else { + bcopy(READ36FORMAT(ptr)->data, buffer, ARRLEN(READ36FORMAT(ptr)->data)); + } + } else { + ret = CONT_ERR_NO_CONTROLLER; + } + + } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/voice/voicecontrolgain.c b/lib/ultralib/src/voice/voicecontrolgain.c new file mode 100644 index 0000000..95e9bb2 --- /dev/null +++ b/lib/ultralib/src/voice/voicecontrolgain.c @@ -0,0 +1,28 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { + s32 ret; + u8 cmd; + + static u8 digital_table[] = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0 }; + + if (analog == 0) { + cmd = 0x18; + } else { + cmd = 0x98; + } + + ERRCK(__osVoiceSetADConverter(hd->__mq, hd->__channel, cmd)); + + if ((digital < ARRLEN(digital_table)) && (digital >= 0)) { + cmd = digital_table[digital] + 2; + } else { + return CONT_ERR_INVALID; + } + + ERRCK(__osVoiceSetADConverter(hd->__mq, hd->__channel, cmd)); + return ret; +} diff --git a/lib/ultralib/src/voice/voicecontwrite20.c b/lib/ultralib/src/voice/voicecontwrite20.c new file mode 100644 index 0000000..d1a7446 --- /dev/null +++ b/lib/ultralib/src/voice/voicecontwrite20.c @@ -0,0 +1,74 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" +#include "io/controller_voice.h" +#include "io/siint.h" + +#define WRITE20FORMAT(ptr) ((__OSVoiceWrite20Format*)(ptr)) + +s32 __osVoiceContWrite20(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + u8 status; + int i; + u8* ptr; + int retry = 2; + u8 crc; + + __osSiGetAccess(); + + do { + + ptr = (u8*)&__osPfsPifRam; + + if ((__osContLastCmd != CONT_CMD_WRITE20_VOICE) || ((u32)__osPfsLastChannel != channel)) { + __osContLastCmd = CONT_CMD_WRITE20_VOICE; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + WRITE20FORMAT(ptr)->dummy = CONT_CMD_NOP; + WRITE20FORMAT(ptr)->txsize = CONT_CMD_WRITE20_VOICE_TX; + WRITE20FORMAT(ptr)->rxsize = CONT_CMD_WRITE20_VOICE_RX; + WRITE20FORMAT(ptr)->cmd = CONT_CMD_WRITE20_VOICE; + WRITE20FORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSVoiceWrite20Format)] = CONT_CMD_END; + } else { + ptr += channel; + } + + WRITE20FORMAT(ptr)->addrh = address >> 3; + WRITE20FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); + + bcopy(buffer, WRITE20FORMAT(ptr)->data, ARRLEN(WRITE20FORMAT(ptr)->data)); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + crc = __osVoiceContDataCrc(buffer, ARRLEN(WRITE20FORMAT(ptr)->data)); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*WRITE20FORMAT(ptr)); + + if (ret == 0) { + if (crc != WRITE20FORMAT(ptr)->datacrc) { + ret = __osVoiceGetStatus(mq, channel, &status); + if (ret != 0) { + break; + } else { + ret = CONT_ERR_CONTRFAIL; + } + } + } else { + ret = CONT_ERR_NO_CONTROLLER; + } + + } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/voice/voicecontwrite4.c b/lib/ultralib/src/voice/voicecontwrite4.c new file mode 100644 index 0000000..6f00586 --- /dev/null +++ b/lib/ultralib/src/voice/voicecontwrite4.c @@ -0,0 +1,74 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" +#include "io/controller_voice.h" +#include "io/siint.h" + +#define WRITE4FORMAT(ptr) ((__OSVoiceWrite4Format*)(ptr)) + +s32 __osVoiceContWrite4(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + u8 status; + int i; + u8* ptr; + s32 retry = 2; + u8 crc; + + __osSiGetAccess(); + + do { + + ptr = (u8*)&__osPfsPifRam; + + if ((__osContLastCmd != CONT_CMD_WRITE4_VOICE) || ((u32)__osPfsLastChannel != channel)) { + __osContLastCmd = CONT_CMD_WRITE4_VOICE; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + WRITE4FORMAT(ptr)->dummy = CONT_CMD_NOP; + WRITE4FORMAT(ptr)->txsize = CONT_CMD_WRITE4_VOICE_TX; + WRITE4FORMAT(ptr)->rxsize = CONT_CMD_WRITE4_VOICE_RX; + WRITE4FORMAT(ptr)->cmd = CONT_CMD_WRITE4_VOICE; + WRITE4FORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSVoiceWrite4Format)] = CONT_CMD_END; + } else { + ptr += channel; + } + + WRITE4FORMAT(ptr)->addrh = address >> 3; + WRITE4FORMAT(ptr)->addrl = (address << 5) | __osContAddressCrc(address); + + bcopy(buffer, WRITE4FORMAT(ptr)->data, ARRLEN(WRITE4FORMAT(ptr)->data)); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + crc = __osVoiceContDataCrc(buffer, ARRLEN(WRITE4FORMAT(ptr)->data)); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*WRITE4FORMAT(ptr)); + + if (ret == 0) { + if (crc != WRITE4FORMAT(ptr)->datacrc) { + ret = __osVoiceGetStatus(mq, channel, &status); + if (ret != 0) { + break; + } else { + ret = CONT_ERR_CONTRFAIL; + } + } + } else { + ret = CONT_ERR_NO_CONTROLLER; + } + + } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/voice/voicecountsyllables.c b/lib/ultralib/src/voice/voicecountsyllables.c new file mode 100644 index 0000000..b0112ef --- /dev/null +++ b/lib/ultralib/src/voice/voicecountsyllables.c @@ -0,0 +1,55 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" + +// The VRU can store only 880 semisyllables of words in its dictionary. +// Use this function to determine the semisyllable count before adding a word with osVoiceSetWord, +// to properly see whether it will fit. + +void osVoiceCountSyllables(u8* data, u32* syllable) { + s32 k; + u16 sjis; + u16 old; + + old = 0; + *syllable = 1; + for (k = 0; data[k] != 0; k += 2) { + sjis = (data[k] << 8) + data[k + 1]; + if ((sjis == 'あ') || (sjis == 'い') || (sjis == 'う') || (sjis == 'え') || (sjis == 'お') || (sjis == 'ア') || + (sjis == 'イ') || (sjis == 'ウ') || (sjis == 'エ') || (sjis == 'オ')) { + if (k == 0) { + *syllable += 2; + } else { + *syllable += 1; + } + } else if ((sjis == 'か') || (sjis == 'き') || (sjis == 'く') || (sjis == 'け') || (sjis == 'こ') || + (sjis == 'た') || (sjis == 'ち') || (sjis == 'つ') || (sjis == 'て') || (sjis == 'と') || + (sjis == 'ぱ') || (sjis == 'ぴ') || (sjis == 'ぷ') || (sjis == 'ぺ') || (sjis == 'ぽ') || + (sjis == 'カ') || (sjis == 'キ') || (sjis == 'ク') || (sjis == 'ケ') || (sjis == 'コ') || + (sjis == 'タ') || (sjis == 'チ') || (sjis == 'ツ') || (sjis == 'テ') || (sjis == 'ト') || + (sjis == 'パ') || (sjis == 'ピ') || (sjis == 'プ') || (sjis == 'ペ') || (sjis == 'ポ')) { + if (k == 0) { + *syllable += 2; + } else if ((old == 'っ') || (old == 'ッ')) { + *syllable += 2; + } else { + *syllable += 3; + } + } else if ((sjis == 'ぁ') || (sjis == 'ぃ') || (sjis == 'ぅ') || (sjis == 'ぇ') || (sjis == 'ぉ') || + (sjis == 'ゃ') || (sjis == 'ゅ') || (sjis == 'ょ') || (sjis == 'ゎ') + + || (sjis == 'ァ') || (sjis == 'ィ') || (sjis == 'ゥ') || (sjis == 'ェ') || (sjis == 'ォ') || + (sjis == 'ャ') || (sjis == 'ュ') || (sjis == 'ョ') || (sjis == 'ヮ') || (sjis == 'ヵ') || + (sjis == 'ヶ')) { + if ((old == 'あ') || (old == 'い') || (old == 'う') || (old == 'え') || (old == 'お') || (old == 'ア') || + (old == 'イ') || (old == 'ウ') || (old == 'エ') || (old == 'オ')) { + *syllable += 1; + } + } else if ((sjis == 'ん') || (sjis == 'ー') || (sjis == 'っ') || (sjis == 'ン') || (sjis == 'ッ')) { + *syllable += 1; + } else { + *syllable += 2; + } + old = sjis; + } +} diff --git a/lib/ultralib/src/voice/voicecrc.c b/lib/ultralib/src/voice/voicecrc.c new file mode 100644 index 0000000..56b4838 --- /dev/null +++ b/lib/ultralib/src/voice/voicecrc.c @@ -0,0 +1,40 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" + +#define VOICE_CRC_LENGTH 8 +#define VOICE_CRC_GENERATOR 0x85 + +u8 __osVoiceContDataCrc(u8* data, u32 length) { + s32 temp = 0; + u32 i; + u32 j; + + for (i = length; i != 0; i--) { + // Loop over each j in the i starting with most significant + for (j = (1 << (VOICE_CRC_LENGTH - 1)); j != 0; j >>= 1) { + temp <<= 1; + if (*data & j) { + if (temp & (1 << VOICE_CRC_LENGTH)) { + // Same as temp++; temp ^= 0x85 since last j always 0 after the shift + temp ^= VOICE_CRC_GENERATOR - 1; + } else { + temp++; + } + } else if (temp & (1 << VOICE_CRC_LENGTH)) { + temp ^= VOICE_CRC_GENERATOR; + } + } + data++; + } + // Act like a i of zeros is appended to data + do { + temp <<= 1; + if (temp & (1 << VOICE_CRC_LENGTH)) { + temp ^= VOICE_CRC_GENERATOR; + } + } while (++i < VOICE_CRC_LENGTH); + + // Discarding the excess is done automatically by the return type + return temp; +} diff --git a/lib/ultralib/src/voice/voicegetreaddata.c b/lib/ultralib/src/voice/voicegetreaddata.c new file mode 100644 index 0000000..d2f5063 --- /dev/null +++ b/lib/ultralib/src/voice/voicegetreaddata.c @@ -0,0 +1,94 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* micdata) { + s32 ret = 0; + s32 i; + u8 stat; + u8 temp[36]; + static u8 c; + + switch (hd->__mode) { + case 1: + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); + if (ret != 0) { + return ret; + } else if (stat & 1) { + return CONT_ERR_NOT_READY; + } + + ERRCK(__osVoiceContRead2(hd->__mq, hd->__channel, 0, temp)); + + c = temp[0] & 7; + hd->cmd_status = c; + if ((c != 0) && (c != 7)) { + return CONT_ERR_NOT_READY; + } + case 2: + hd->__mode = 2; + + ERRCK(__osVoiceGetStatus(hd->__mq, hd->__channel, &stat)); + + if (stat & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + *(u32*)temp = 0x600; + ERRCK(__osVoiceContWrite4(hd->__mq, hd->__channel, 0, temp)); + + case 3: + hd->__mode = 3; + + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); + if (ret != 0) { + return ret; + } else if (stat & 1) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + ERRCK(__osVoiceContRead36(hd->__mq, hd->__channel, 0, temp)); + + micdata->warning = temp[4] + (temp[5] << 8); + micdata->answer_num = temp[6]; + micdata->voice_level = temp[8] + (temp[9] << 8); + micdata->voice_sn = temp[10] + (temp[11] << 8); + micdata->voice_time = temp[12] + (temp[13] << 8); + + for (i = 0; i < 5; i++) { + micdata->answer[i] = temp[14 + (i << 2)] + (temp[15 + (i << 2)] << 8); + micdata->distance[i] = temp[16 + (i << 2)] + (temp[17 + (i << 2)] << 8); + } + + if (micdata->answer[0] == 0x7FFF) { + micdata->answer_num = 0; + } + + hd->cmd_status = temp[34] & 7; + if ((c == 0) || (hd->cmd_status == 0)) { + break; + } + case 4: + hd->__mode = 4; + + ERRCK(__osVoiceGetStatus(hd->__mq, hd->__channel, &stat)); + + if (stat & 1) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + ERRCK(__osVoiceContRead2(hd->__mq, hd->__channel, 0, temp)); + + hd->cmd_status = temp[0] & 7; + if (temp[0] & 7) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + break; + default: + return CONT_ERR_INVALID; + } + hd->__mode = 0; + return ret; +} diff --git a/lib/ultralib/src/voice/voicegetstatus.c b/lib/ultralib/src/voice/voicegetstatus.c new file mode 100644 index 0000000..e7328c1 --- /dev/null +++ b/lib/ultralib/src/voice/voicegetstatus.c @@ -0,0 +1,62 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" +#include "io/siint.h" + +s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 port, u8* status) { + __OSContRequesFormatShort header; + s32 ret = 0; + s32 i; + u8* ptr = (u8*)&__osContPifRam.ramarray; + s32 retry = 2; + + __osSiGetAccess(); + + do { + if (ret != CONT_ERR_CONTRFAIL) { + __osContPifRam.pifstatus = CONT_CMD_EXE; + + for (i = 0; i < port; i++, *ptr++ = CONT_CMD_REQUEST_STATUS) { + ; + } + + *ptr++ = CONT_CMD_REQUEST_STATUS_TX; + *ptr++ = CONT_CMD_REQUEST_STATUS_RX; + *ptr = CONT_CMD_REQUEST_STATUS; + ptr += 4; + *ptr = CONT_CMD_END; + + __osContLastCmd = CONT_CMD_END; + ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + } + ret = __osSiRawStartDma(OS_READ, &__osContPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ptr = (u8*)&__osContPifRam.ramarray + port; + + header = *((__OSContRequesFormatShort*)ptr); + + ret = (u8)CHNL_ERR(header); + *status = header.status; + + if (ret == 0) { + if (header.typeh == 0 && header.typel == 1) { + if (header.status & 4) { + ret = CONT_ERR_CONTRFAIL; + } + } else { + ret = CONT_ERR_DEVICE; + } + } else if (ret & CONT_NO_RESPONSE_ERROR) { + ret = CONT_ERR_NO_CONTROLLER; + } else { + ret = CONT_ERR_CONTRFAIL; + } + } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/voice/voiceinit.c b/lib/ultralib/src/voice/voiceinit.c new file mode 100644 index 0000000..5074a84 --- /dev/null +++ b/lib/ultralib/src/voice/voiceinit.c @@ -0,0 +1,42 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 osVoiceInit(OSMesgQueue* mq, OSVoiceHandle* handle, int channel) { + s32 ret; + s32 i; + u8 stat = 0; + u8 buf[4]; + static u8 cmd[] = { 0x1E, 0x6E, 0x08, 0x56, 0x03 }; + + handle->__channel = channel; + handle->__mq = mq; + handle->__mode = 0; + + ERRCK(__osVoiceGetStatus(mq, channel, &stat)); + + ret = __osContChannelReset(mq, channel); + if (ret != 0) { + return CONT_ERR_CONTRFAIL; + } + + for (i = 0; i < ARRLEN(cmd); i++) { + ERRCK(__osVoiceSetADConverter(mq, channel, cmd[i])); + } + + ERRCK(__osVoiceGetStatus(mq, channel, &stat)); + if (stat & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + *(u32*)buf = 0x100; + ERRCK(__osVoiceContWrite4(mq, channel, 0, buf)); + + ret = __osVoiceCheckResult(handle, &stat); + if (ret & 0xFF00) { + ret = CONT_ERR_INVALID; + } + + return ret; +} diff --git a/lib/ultralib/src/voice/voiceinternal.h b/lib/ultralib/src/voice/voiceinternal.h new file mode 100644 index 0000000..8dc6299 --- /dev/null +++ b/lib/ultralib/src/voice/voiceinternal.h @@ -0,0 +1,18 @@ +#ifndef VOICE_INTERNAL_H +#define VOICE_INTERNAL_H + +// Various prototypes and externs that don't show up in os_voice.h +extern s32 __osPfsLastChannel; + +s32 __osContChannelReset(OSMesgQueue* mq, int channel); + +s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* stat); +s32 __osVoiceContRead2(OSMesgQueue* mq, int channel, u16 address, u8* buffer); +s32 __osVoiceContRead36(OSMesgQueue* mq, int channel, u16 address, u8* buffer); +s32 __osVoiceContWrite4(OSMesgQueue* mq, int channel, u16 address, u8* buffer); +s32 __osVoiceContWrite20(OSMesgQueue* mq, int channel, u16 address, u8* buffer); +u8 __osVoiceContDataCrc(u8* data, u32 length); +s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 port, u8* status); +s32 __osVoiceSetADConverter(OSMesgQueue*, s32 channel, u8 cmd); + +#endif diff --git a/lib/ultralib/src/voice/voicemaskdictionary.c b/lib/ultralib/src/voice/voicemaskdictionary.c new file mode 100644 index 0000000..39db7ac --- /dev/null +++ b/lib/ultralib/src/voice/voicemaskdictionary.c @@ -0,0 +1,48 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 osVoiceMaskDictionary(OSVoiceHandle* hd, u8* pattern, int size) { + s32 ret = 0; + s32 i; + s32 j; + u8 stat; + u8 buf[20]; + + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); + if (ret != 0) { + return ret; + } else if (stat & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + if (size & 1) { + j = size + 1; + } else { + j = size; + } + + bzero(&buf, ARRLEN(buf)); + + buf[18 - j] = 4; + + for (i = 0; i < j; i += 2) { + buf[i + ARRLEN(buf) - j] = pattern[i]; + buf[i + ARRLEN(buf) - j + 1] = pattern[i + 1]; + } + + if (size & 1) { + buf[ARRLEN(buf) - 1] = 0; + } + + ret = __osVoiceContWrite20(hd->__mq, hd->__channel, 0, (u8*)&buf); + if (ret == 0) { + ret = __osVoiceCheckResult(hd, &stat); + if (ret & 0xFF00) { + ret = CONT_ERR_INVALID; + } + } + + return ret; +} diff --git a/lib/ultralib/src/voice/voicesetadconverter.c b/lib/ultralib/src/voice/voicesetadconverter.c new file mode 100644 index 0000000..d1c5eb2 --- /dev/null +++ b/lib/ultralib/src/voice/voicesetadconverter.c @@ -0,0 +1,69 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" +#include "io/controller_voice.h" +#include "io/siint.h" + +#define SWRITEFORMAT(ptr) ((__OSVoiceSWriteFormat*)(ptr)) + +s32 __osVoiceSetADConverter(OSMesgQueue* mq, s32 channel, u8 data) { + s32 ret = 0; + int i; + u8* ptr; + u8 status; + int retry = 2; + + __osSiGetAccess(); + + do { + + ptr = (u8*)__osPfsPifRam.ramarray; + + if ((__osContLastCmd != CONT_CMD_SWRITE_VOICE) || (__osPfsLastChannel != channel)) { + __osContLastCmd = CONT_CMD_SWRITE_VOICE; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + SWRITEFORMAT(ptr)->txsize = CONT_CMD_SWRITE_VOICE_TX; + SWRITEFORMAT(ptr)->rxsize = CONT_CMD_SWRITE_VOICE_RX; + SWRITEFORMAT(ptr)->cmd = CONT_CMD_SWRITE_VOICE; + SWRITEFORMAT(ptr)->datacrc = 0; + + ptr[sizeof(__OSVoiceSWriteFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + + SWRITEFORMAT(ptr)->data = data; + SWRITEFORMAT(ptr)->scrc = __osContAddressCrc(data << 3); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*SWRITEFORMAT(ptr)); + + if (ret == 0) { + if (SWRITEFORMAT(ptr)->datacrc & 1) { + ret = __osVoiceGetStatus(mq, channel, &status); + if (ret != 0) { + break; + } else { + ret = CONT_ERR_CONTRFAIL; + } + } + } else { + ret = CONT_ERR_NO_CONTROLLER; + } + + } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} diff --git a/lib/ultralib/src/voice/voicesetword.c b/lib/ultralib/src/voice/voicesetword.c new file mode 100644 index 0000000..7969fae --- /dev/null +++ b/lib/ultralib/src/voice/voicesetword.c @@ -0,0 +1,54 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word) { + s32 j; + s32 k; + s32 ret; + u8 stat; + u8 buf[40]; + + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); + if (ret != 0) { + return ret; + } else if (stat & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + for (k = 0; word[k] != 0; k += 2) { + ; + } + +#ifndef NDEBUG + if (k >= 34) { + return CONT_ERR_VOICE_WORD; + } +#endif + + bzero(buf, ARRLEN(buf)); + + for (j = 0; j < k; j += 2) { + buf[ARRLEN(buf) - 1 - k + j] = word[j]; + buf[ARRLEN(buf) - 1 - k + j - 1] = word[j + 1]; + } + + buf[ARRLEN(buf) - 1 - j - 5] = 3; + + if (k >= 15) { + ERRCK(__osVoiceContWrite20(hd->__mq, hd->__channel, 0, buf)); + } + ERRCK(__osVoiceContWrite20(hd->__mq, hd->__channel, 0, buf + 20)); + ret = __osVoiceCheckResult(hd, &stat); + if (ret != 0) { + if (ret & 0x100) { + ret = CONT_ERR_VOICE_MEMORY; + } else if (ret & 0x200) { + ret = CONT_ERR_VOICE_WORD; + } else if (ret & 0xFF00) { + ret = CONT_ERR_INVALID; + } + } + return ret; +} diff --git a/lib/ultralib/src/voice/voicestartreaddata.c b/lib/ultralib/src/voice/voicestartreaddata.c new file mode 100644 index 0000000..ea83da0 --- /dev/null +++ b/lib/ultralib/src/voice/voicestartreaddata.c @@ -0,0 +1,36 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" + +s32 osVoiceStartReadData(OSVoiceHandle* hd) { + s32 ret; + u8 stat; + u8 temp[4]; + + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); + if (ret != 0) { + return ret; + } else if (stat & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + if (hd->__mode != 0) { + return CONT_ERR_INVALID; + } + + *(u32*)temp = 0x5000000; + ret = __osVoiceContWrite4(hd->__mq, hd->__channel, 0, temp); + + if (ret == 0) { + ret = __osVoiceCheckResult(hd, &stat); + + if (ret & 0xFF00) { + ret = CONT_ERR_INVALID; + } else { + hd->__mode = 1; + } + } + + return ret; +} diff --git a/lib/ultralib/src/voice/voicestopreaddata.c b/lib/ultralib/src/voice/voicestopreaddata.c new file mode 100644 index 0000000..b43eb81 --- /dev/null +++ b/lib/ultralib/src/voice/voicestopreaddata.c @@ -0,0 +1,59 @@ +#include "PR/os_internal.h" +#include "io/controller.h" +#include "PR/os_voice.h" +#include "voiceinternal.h" +#include "os_version.h" + +s32 osVoiceStopReadData(OSVoiceHandle* hd) { + s32 ret; +#if BUILD_VERSION >= VERSION_K + s32 i; +#endif + u8 stat; + u8 temp[4]; + + ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat); + if (ret != 0) { + return ret; + } else if (stat & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; + } + + if (hd->__mode == 0) { + return CONT_ERR_INVALID; + } + + *(u32*)temp = 0x700; + ret = __osVoiceContWrite4(hd->__mq, hd->__channel, 0, temp); + + if (ret == 0) { +#if BUILD_VERSION >= VERSION_K + i = 0; +#endif + do { + ret = __osVoiceCheckResult(hd, &stat); + if (ret & 0xFF00) { + if (((ret & 7) == 0) || ((ret & 7) == 7)) { + ret = 0; + hd->__mode = 0; + } else { + ret = CONT_ERR_INVALID; + } + } else { + hd->__mode = 0; + } +#if BUILD_VERSION >= VERSION_K + i++; + } while ((ret == CONT_ERR_VOICE_NO_RESPONSE) && (i < 20)); +#else + } while ((ret == CONT_ERR_VOICE_NO_RESPONSE)); +#endif + } +#if BUILD_VERSION >= VERSION_K + if (i >= 20) { + ret == CONT_ERR_VOICE_NO_RESPONSE; + } +#endif + + return ret; +} diff --git a/lib/ultralib/tools/Makefile b/lib/ultralib/tools/Makefile new file mode 100644 index 0000000..cf0d35e --- /dev/null +++ b/lib/ultralib/tools/Makefile @@ -0,0 +1,46 @@ + +.PHONY: all clean distclean + +# GCC +GCC_DIR := gcc +AR := $(GCC_DIR)/ar +GCC-2.7.2 := $(GCC_DIR)/gcc +STRIP-2.7 := $(GCC_DIR)/strip-2.7 + +# IDO +IDO_DIR := ido +IDO-5.3 := $(IDO_DIR)/cc + +all: $(AR) $(GCC-2.7.2) $(STRIP-2.7) $(IDO-5.3) + +$(AR): | $(GCC_DIR) + wget https://github.com/decompals/mips-binutils-2.6/releases/download/main/binutils-2.6-linux.tar.gz + tar xf binutils-2.6-linux.tar.gz -C $(GCC_DIR) + $(RM) binutils-2.6-linux.tar.gz + +$(GCC-2.7.2): | $(GCC_DIR) + wget https://github.com/decompals/mips-gcc-2.7.2/releases/download/main/gcc-2.7.2-linux.tar.gz + tar xf gcc-2.7.2-linux.tar.gz -C $(GCC_DIR) + $(RM) gcc-2.7.2-linux.tar.gz + +$(STRIP-2.7): | $(GCC_DIR) + wget https://github.com/decompals/mips-binutils-2.7/releases/download/release/binutils-2.7.tar.gz + tar xf binutils-2.7.tar.gz -C $(GCC_DIR) + $(RM) binutils-2.7.tar.gz + +$(GCC_DIR): + mkdir -p $@ + +$(IDO-5.3): | $(IDO_DIR) + wget https://github.com/decompals/ido-static-recomp/releases/latest/download/ido-5.3-recomp-linux.tar.gz + tar xf ido-5.3-recomp-linux.tar.gz -C $(IDO_DIR) + $(RM) ido-5.3-recomp-linux.tar.gz + +$(IDO_DIR): + mkdir -p $@ + +clean: + $(RM) -rf $(GCC_DIR) + $(RM) -rf $(IDO_DIR) + +distclean: clean diff --git a/lib/ultralib/tools/ar.py b/lib/ultralib/tools/ar.py new file mode 100755 index 0000000..0f3e574 --- /dev/null +++ b/lib/ultralib/tools/ar.py @@ -0,0 +1,476 @@ +#!/usr/bin/env python3 +# +# ar +# + +from genericpath import isfile +import os, struct, time +from dataclasses import dataclass +from libelf import ElfFile, SB_GLOBAL, SHN_UND + +class Archive: + @dataclass + class ArchiveFileRecord: + """ + AR file headers + data + + Offset Length Name Format + 0 16 File identifier ASCII + 16 12 File modification timestamp (in seconds) Decimal + 28 6 Owner ID Decimal + 34 6 Group ID Decimal + 40 8 File mode (type and permission) Octal + 48 10 File size in bytes Decimal + 58 2 Ending characters 0x60 0x0A + """ + name : str + time : int + uid : int + gid : int + mode : int + size : int + data : bytes + + def __init__(self): + self.files = [] # List[ArchiveFileRecord] + self.armap_entries = None + self.time = int(time.time()) + + def add_data(self, name, time, uid, gid, mode, size, data): + self.files.append(Archive.ArchiveFileRecord(name, time, uid, gid, mode, size, data)) + + def add_file(self, file_path): + if not os.path.isfile(file_path): + print(f"Error: No file named {file_path}") + return + + st = os.stat(file_path) + name = os.path.basename(file_path) + time = int(st.st_mtime) + uid = st.st_uid + gid = st.st_gid + mode = st.st_mode + size = st.st_size + + data = None + with open(file_path, "rb") as infile: + data = bytes(infile.read()) + + self.add_data(name, time, uid, gid, mode, size, data) + + def add_ar(self, file_path): + for file in Archive.from_file(file_path).files: + self.add_data(file) + + def build_image(self): + def add_bin(ba, bin): + for b in bin: + ba.append(b) + + def add_str(ba, s, pad_to_len=-1): + if pad_to_len != -1: + s = f"{s:{pad_to_len}}" + s = s.encode("ASCII") + for c in s: + ba.append(c) + + def add_pad(ba): + if len(ba) % 2 != 0: + ba.append(0) + + def add_ar_hdr(ba, name, time, uid, gid, mode, length): + add_str(ba, name, 16) + add_str(ba, str(time), 12) + add_str(ba, str(uid), 6) + add_str(ba, str(gid), 6) + add_str(ba, oct(mode)[2:], 8) + add_str(ba, str(length), 10) + add_str(ba, "`\n") + + b = bytearray() + + # MAGIC + + add_str(b, "!\n") + + # ARMAP + + armap_data= bytearray() + + armap_entries_files = [] + + num_entries = 0 + armap_size = 4 + armap_string_data = bytearray() + for i,file in enumerate(self.files): + elf = ElfFile(file.data) + if elf.symtab is not None: + for sym in elf.symtab.symbol_entries: + if sym.st_shndx != SHN_UND and sym.bind == SB_GLOBAL: + num_entries += 1 + armap_size += 4 + len(sym.name) + 1 + armap_string_data.extend(sym.name.encode("latin1") + b'\0') + armap_entries_files.append(i) + + armap_data.extend(struct.pack(">I", num_entries)) + armap_data.extend([0] * 4 * num_entries) # defer writing file positions until files are emplaced later + armap_data.extend(armap_string_data) + + if len(armap_data) % 4 != 0: + alsiz = (len(armap_data) + 3) & ~3 + armap_data.extend([0] * (alsiz - len(armap_data))) + + current_time = int(time.time()) + + add_ar_hdr(b, "/", current_time, 0, 0, 0, len(armap_data)) + armap_offsets_start = len(b) + 4 + add_bin(b, armap_data) + add_pad(b) + + # LONG STRINGS + + long_strings = "" + + file_names = [] + flag = False + for _,file in enumerate(self.files): + if len(file.name) >= 16: + fname = f"{file.name}/\n" + ind = len(long_strings) + long_strings += fname + else: + fname = f"{file.name}/" + ind = None + file_names.append((fname, ind)) + + # Weird hack + if len(long_strings) != 0 and not flag: + flag = True + long_strings += "/\n" + + long_strings += "/" + + add_ar_hdr(b, "//", current_time, 0, 0, 0, len(long_strings)) + add_str(b, long_strings) + add_pad(b) + + # FILES + + armap_pos = 0 + for i,(file,(fname,ind)) in enumerate(zip(self.files, file_names)): + file_pos = len(b) + add_ar_hdr(b, f"/{ind}" if ind is not None else fname, file.time, file.uid, file.gid, file.mode, file.size) + add_bin(b, file.data) + add_pad(b) + + # Patch the armap with file locations + while armap_pos < len(armap_entries_files) and armap_entries_files[armap_pos] == i: + b[armap_offsets_start+armap_pos*4:armap_offsets_start+armap_pos*4+4] = struct.pack(">I", file_pos) + armap_pos += 1 + + return b + + def write(self, file_path): + ar = self.build_image() + with open(file_path, "wb") as outfile: + outfile.write(ar) + + @staticmethod + def from_image(ar_data): + long_strings = None + ar = Archive() + + assert ar_data[:8].decode("ASCII") == "!\n" , "Not an archive file? Bad file magic value" + + i = 8 + while i < len(ar_data): + file_name = ar_data[i:][ 0:][:16].decode("ASCII").strip() + file_time = int(ar_data[i:][16:][:12].decode("ASCII").strip()) + file_uid = int(ar_data[i:][28:][: 6].decode("ASCII").strip()) + file_gid = int(ar_data[i:][34:][: 6].decode("ASCII").strip()) + file_mode = int(ar_data[i:][40:][: 8].decode("ASCII").strip(), 8) + file_size = int(ar_data[i:][48:][:10].decode("ASCII").strip()) + end = ar_data[i:][58:][:2].decode("ASCII") + assert end == "`\n" + + data = ar_data[i:][60:][:file_size] + assert len(data) == file_size + + if file_name == '/': + """ + "armap" + The special filename "/" denotes that this entry contains a symbol lookup table used by some libraries + to speed up file access. + The symbol table is comprised of three contiguous parts: + - A 32-bit Big Endian integer recording the number of symbol entries. + - A list of 32-bit Big Endian integers for each symbol entry, recording the position within the + archive of the header of the file containing the symbol. + - A list of null-terminated strings, the symbol names for each symbol entry. + + We rebuild this from scratch on write out. + """ + ar.time = file_time + assert file_uid == 0 + assert file_gid == 0 + assert file_mode == 0 + + # Code to interpret the armap, currently unused + """ + armap_n_syms = struct.unpack(">I", data[0:4])[0] + offsets = [i[0] for i in struct.iter_unpack(">I", data[4:4+4*armap_n_syms])] + + strings = [] + ofs = 4 + 4 * armap_n_syms + for _ in range(armap_n_syms): + to = data.find(b'\0', ofs) + assert to != -1 + string = data[ofs:to].decode('latin1') + strings.append(string) + ofs += len(string) + 1 + assert all([b == 0 for b in data[ofs:]]) + assert len(strings) == len(offsets) + + ar.armap_entries = list(zip(offsets, strings)) + """ + elif file_name == '//': + """ + Long string table. Strings larger than 16 are placed here and referenced from the header by /. + + We rebuild this from scratch on write out. + """ + assert file_time == ar.time + assert file_uid == 0 + assert file_gid == 0 + assert file_mode == 0 + long_strings = data.decode("ASCII") + else: + """ + Normal files. + """ + if file_name.startswith("/"): + assert long_strings is not None + # Fetch the name from the long string table + file_name = long_strings[int(file_name[1:]):].split("\n")[0] + # Add file + ar.add_data(file_name[:-1], file_time, file_uid, file_gid, file_mode, file_size, data) + + if file_size % 2 != 0: + file_size += 1 + i += 60 + file_size + + return ar + + @staticmethod + def from_file(file_path): + ar_file = None + with open(file_path, "rb") as infile: + ar_file = infile.read() + + return Archive.from_image(ar_file) + +def ar_usage(progname): + print(f"Usage: {progname} [-]{{dmpqrstx}}[abcDfilMNoOPsSTuvV] [member-name] [count] archive-file file...") + print(f" commands:") + print(f" d - delete file(s) from the archive") + print(f" m[ab] - move file(s) in the archive") + print(f" p - print file(s) found in the archive") + print(f" q[f] - quick append file(s) to the archive") + print(f" r[ab][f][u] - replace existing or insert new file(s) into the archive") + print(f" s - act as ranlib") + print(f" t[O][v] - display contents of the archive") + print(f" x[o] - extract file(s) from the archive") + print(f" command specific modifiers:") + print(f" [a] - put file(s) after [member-name]") + print(f" [b] - put file(s) before [member-name] (same as [i])") + print(f" [D] - use zero for timestamps and uids/gids (default)") + print(f" [U] - use actual timestamps and uids/gids") + print(f" [N] - use instance [count] of name") + print(f" [f] - truncate inserted file names") + print(f" [P] - use full path names when matching") + print(f" [o] - preserve original dates") + print(f" [O] - display offsets of files in the archive") + print(f" [u] - only replace files that are newer than current archive contents") + print(f" generic modifiers:") + print(f" [c] - do not warn if the library had to be created") + print(f" [s] - create an archive index (cf. ranlib)") + print(f" [S] - do not build a symbol table") + print(f" [v] - be verbose") + print(f" [V] - display the version number") + print(f" @ - read options from ") + print(f" --output=DIRNAME - specify the output directory for extraction operations") + return 1 + +def ar(argv): + if len(argv) < 2: + return ar_usage(argv[0]) + + progname = argv[0] + create_ok = False + make_ar_idx = False + no_symtab = False + verbose = False + + def verbose_print(msg): + if verbose: + print(msg) + + def dcmd(modifiers, args): + if modifiers != "": + print(f"{progname}: bad modifiers -- '{modifiers}'") + return ar_usage(progname) + + ar_file = args[0] + o_files = args[1:] + + ar = Archive.from_file(ar_file) + for file in ar.files: + if file.name in o_files: + ar.files.remove(file) + ar.write(ar_file) + return 0 + + def mcmd(modifiers, args): + print("") + return 1 + + def pcmd(modifiers, args): + if modifiers != "": + print(f"{progname}: bad modifiers -- '{modifiers}'") + return ar_usage(progname) + if len(args) != 1: + print(f"{progname} p: bad args") + return ar_usage(progname) + + ar_file = args[0] + + ar = Archive.from_file(ar_file) + for file in ar.files: + print(file.data) + return 0 + + def qcmd(modifiers, args): + print("") + return 1 + + def rcmd(modifiers, args): + if modifiers !="": + print("") + if len(args) < 2: + print(f"{progname} r: bad args") + return ar_usage(progname) + + ar_file = args[0] + o_files = args[1:] + + ar = Archive() + if os.path.isfile(ar_file): + ar = Archive.from_file(ar_file) + else: + if not create_ok: + print(f"Warning: Created file {ar_file}") + ar = Archive() + + for o_file in o_files: + ar.add_file(o_file) + + ar.write(ar_file) + + def scmd(modifiers, args): + print("") + return 1 + + def tcmd(modifiers, args): + # TODO modifiers + + if len(args) != 1: + print(f"{progname} t: bad args") + return ar_usage(progname) + + ar_file = args[0] + + ar = Archive.from_file(ar_file) + for file in ar.files: + print(file.name) + return 0 + + def xcmd(modifiers, args): + if modifiers not in ('', 'o'): + print(f"{progname}: bad modifiers -- '{modifiers}'") + return ar_usage(progname) + if len(args) not in (1, 3) or not (args[0].startswith("--output") or args[1].startswith("--output")): + print(f"{progname} t: bad args") + return ar_usage(progname) + + original_times = modifiers == 'o' + + if args[0].startswith("--output"): + out_dir = args[1] + ar_file = args[2] + elif args[1].startswith("--output"): + out_dir = args[2] + ar_file = args[0] + else: + ar_file = args[0] + out_dir = "" + + # Create dir if not exists + if not os.path.exists(out_dir): + os.makedirs(out_dir, exist_ok=True) + + if not os.path.isdir(out_dir): + print(f"Output directory {out_dir} is a file") + return ar_usage(progname) + + # Extract files to destination + ar = Archive.from_file(ar_file) + for file in ar.files: + opath =os.path.join(out_dir, file.name) + with open(opath, "wb") as ofile: + ofile.write(file.data) + + if not original_times: + t = time.time() + os.utime(opath, (t, t)) + # TODO patch with original dates etc. + + return 0 + + argtbl = { + 'd': dcmd, # delete file(s) from the archive + 'm': mcmd, # [ab] move file(s) in the archive + 'p': pcmd, # print file(s) found in the archive + 'q': qcmd, # [f] quick append file(s) to the archive + 'r': rcmd, # [ab][f][u] replace existing or insert new file(s) into the archive + 's': scmd, # act as ranlib + 't': tcmd, # [O][v] display contents of the archive + 'x': xcmd, # [o] extract file(s) from the archive + } + + arg1 = argv[1] + if arg1[0] == '-': + arg1 = arg1[1:] + cmd = arg1[0] + + if cmd not in argtbl: + print(f"{progname}: invalid option -- '{cmd}'") + return ar_usage(argv[0]) + + modifiers = arg1[1:] + + create_ok = "c" in modifiers + modifiers = modifiers.replace("c","") + make_ar_idx = "s" in modifiers + modifiers = modifiers.replace("s","") + no_symtab = "S" in modifiers + modifiers = modifiers.replace("S","") + verbose = "v" in modifiers + modifiers = modifiers.replace("v","") + + if "V" in modifiers: + print(f"{progname} v1.0") + + return argtbl[cmd](modifiers, argv[2:]) + +if __name__ == '__main__': + import sys + sys.exit(ar(sys.argv)) diff --git a/lib/ultralib/tools/asm_differ/.gitignore b/lib/ultralib/tools/asm_differ/.gitignore new file mode 100644 index 0000000..eb176dc --- /dev/null +++ b/lib/ultralib/tools/asm_differ/.gitignore @@ -0,0 +1,2 @@ +.mypy_cache/ +__pycache__/ diff --git a/lib/ultralib/tools/asm_differ/.gitrepo b/lib/ultralib/tools/asm_differ/.gitrepo new file mode 100644 index 0000000..2e999c8 --- /dev/null +++ b/lib/ultralib/tools/asm_differ/.gitrepo @@ -0,0 +1,12 @@ +; DO NOT EDIT (unless you know what you are doing) +; +; This subdirectory is a git "subrepo", and this file is maintained by the +; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme +; +[subrepo] + remote = https://github.com/simonlindholm/asm-differ + branch = main + commit = 4b38c884c1efdc3bfa8b14f13015a69368a8d3a2 + parent = 32a1a8061de197c4f10d4904cd72a22dd7cf905c + method = merge + cmdver = 0.4.3 diff --git a/lib/ultralib/tools/asm_differ/.pre-commit-config.yaml b/lib/ultralib/tools/asm_differ/.pre-commit-config.yaml new file mode 100644 index 0000000..6695f71 --- /dev/null +++ b/lib/ultralib/tools/asm_differ/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + language_version: python3.6 diff --git a/lib/ultralib/tools/asm_differ/LICENSE b/lib/ultralib/tools/asm_differ/LICENSE new file mode 100644 index 0000000..cf1ab25 --- /dev/null +++ b/lib/ultralib/tools/asm_differ/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/lib/ultralib/tools/asm_differ/README.md b/lib/ultralib/tools/asm_differ/README.md new file mode 100644 index 0000000..4a7f329 --- /dev/null +++ b/lib/ultralib/tools/asm_differ/README.md @@ -0,0 +1,56 @@ +# asm-differ + +Nice differ for assembly code. Currently supports MIPS, PPC, AArch64, and ARM32; should be easy to hack to support other instruction sets. + +![](screenshot.png) + +## Dependencies + +- Python >= 3.6 +- `python3 -m pip install --user colorama watchdog python-Levenshtein` (also `dataclasses` if on 3.6) + +## Usage + +Create a file `diff_settings.sh` in some directory (see the one in this repo for an example). Then from that directory, run + +```bash +/path/to/diff.sh [flags] (function|rom addr) +``` + +Recommended flags are `-mwo` (automatically run `make` on source file changes, and include symbols in diff). See `--help` for more details. + +### Tab completion + +[argcomplete](https://kislyuk.github.io/argcomplete/) can be optionally installed (with `python3 -m pip install argcomplete`) to enable tab completion in a bash shell, completing options and symbol names using the linker map. It also requires a bit more setup: + +If invoking the script **exactly** as `./diff.py`, the following should be added to the `.bashrc` according to argcomplete's instructions: + +```bash +eval "$(register-python-argcomplete ./diff.py)" +``` + +If that doesn't work, run `register-python-argcomplete ./diff.py` in your terminal and copy the output to `.bashrc`. + +If setup correctly (don't forget to restart the shell), `complete | grep ./diff.py` should output: + +```bash +complete -o bashdefault -o default -o nospace -F _python_argcomplete ./diff.py +``` + +Note for developers or for general troubleshooting: run `export _ARC_DEBUG=` to enable debug output during tab-completion, it may show otherwise silenced errors. Use `unset _ARC_DEBUG` or restart the terminal to disable. + +### Contributing + +Contributions are very welcome! Some notes on workflow: + +`black` is used for code formatting. You can either run `black diff.py` manually, or set up a pre-commit hook: +```bash +pip install pre-commit black +pre-commit install +``` + +Type annotations are used for all Python code. `mypy` should pass without any errors. + +PRs that skip the above are still welcome, however. + +The targeted Python version is 3.6. There are currently no tests. diff --git a/lib/ultralib/tools/asm_differ/diff-stylesheet.css b/lib/ultralib/tools/asm_differ/diff-stylesheet.css new file mode 100644 index 0000000..79da120 --- /dev/null +++ b/lib/ultralib/tools/asm_differ/diff-stylesheet.css @@ -0,0 +1,67 @@ +table.diff { + border: none; + font-family: Monospace; + white-space: pre; +} +tr.data-ref { + background-color: gray; +} +.immediate { + color: lightblue; +} +.stack { + color: yellow; +} +.register { + color: yellow; +} +.delay-slot { + font-weight: bold; + color: gray; +} +.diff-change { + color: lightblue; +} +.diff-add { + color: green; +} +.diff-remove { + color: red; +} +.source-filename { + font-weight: bold; +} +.source-function { + font-weight: bold; + text-decoration: underline; +} +.source-other { + font-style: italic; +} +.rotation-0 { + color: magenta; +} +.rotation-1 { + color: cyan; +} +.rotation-2 { + color: green; +} +.rotation-3 { + color: red; +} +.rotation-4 { + color: yellow; +} +.rotation-5 { + color: pink; +} +.rotation-6 { + color: blue; +} +.rotation-7 { + color: lime; +} +.rotation-8 { + color: gray; +} diff --git a/lib/ultralib/tools/asm_differ/diff.py b/lib/ultralib/tools/asm_differ/diff.py new file mode 100755 index 0000000..8ed764f --- /dev/null +++ b/lib/ultralib/tools/asm_differ/diff.py @@ -0,0 +1,2923 @@ +#!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK +import argparse +import sys +from typing import ( + Any, + Callable, + Dict, + Iterator, + List, + Match, + NoReturn, + Optional, + Pattern, + Set, + Tuple, + Type, + Union, +) + + +def fail(msg: str) -> NoReturn: + print(msg, file=sys.stderr) + sys.exit(1) + + +def static_assert_unreachable(x: NoReturn) -> NoReturn: + raise Exception("Unreachable! " + repr(x)) + + +# ==== COMMAND-LINE ==== + +if __name__ == "__main__": + # Prefer to use diff_settings.py from the current working directory + sys.path.insert(0, ".") + try: + import diff_settings + except ModuleNotFoundError: + fail("Unable to find diff_settings.py in the same directory.") + sys.path.pop(0) + + try: + import argcomplete + except ModuleNotFoundError: + argcomplete = None + + parser = argparse.ArgumentParser( + description="Diff MIPS, PPC, AArch64, or ARM32 assembly." + ) + + start_argument = parser.add_argument( + "start", + help="Function name or address to start diffing from.", + ) + + if argcomplete: + + def complete_symbol( + prefix: str, parsed_args: argparse.Namespace, **kwargs: object + ) -> List[str]: + if not prefix or prefix.startswith("-"): + # skip reading the map file, which would + # result in a lot of useless completions + return [] + config: Dict[str, Any] = {} + diff_settings.apply(config, parsed_args) # type: ignore + mapfile = config.get("mapfile") + if not mapfile: + return [] + completes = [] + with open(mapfile) as f: + data = f.read() + # assume symbols are prefixed by a space character + search = f" {prefix}" + pos = data.find(search) + while pos != -1: + # skip the space character in the search string + pos += 1 + # assume symbols are suffixed by either a space + # character or a (unix-style) line return + spacePos = data.find(" ", pos) + lineReturnPos = data.find("\n", pos) + if lineReturnPos == -1: + endPos = spacePos + elif spacePos == -1: + endPos = lineReturnPos + else: + endPos = min(spacePos, lineReturnPos) + if endPos == -1: + match = data[pos:] + pos = -1 + else: + match = data[pos:endPos] + pos = data.find(search, endPos) + completes.append(match) + return completes + + setattr(start_argument, "completer", complete_symbol) + + parser.add_argument( + "end", + nargs="?", + help="Address to end diff at.", + ) + parser.add_argument( + "-o", + dest="diff_obj", + action="store_true", + help="""Diff .o files rather than a whole binary. This makes it possible to + see symbol names. (Recommended)""", + ) + parser.add_argument( + "-e", + "--elf", + dest="diff_elf_symbol", + metavar="SYMBOL", + help="""Diff a given function in two ELFs, one being stripped and the other + one non-stripped. Requires objdump from binutils 2.33+.""", + ) + parser.add_argument( + "-c", + "--source", + dest="show_source", + action="store_true", + help="Show source code (if possible). Only works with -o or -e.", + ) + parser.add_argument( + "-C", + "--source-old-binutils", + dest="source_old_binutils", + action="store_true", + help="""Tweak --source handling to make it work with binutils < 2.33. + Implies --source.""", + ) + parser.add_argument( + "-j", + "--section", + dest="diff_section", + default=".text", + metavar="SECTION", + help="Diff restricted to a given output section.", + ) + parser.add_argument( + "-L", + "--line-numbers", + dest="show_line_numbers", + action="store_const", + const=True, + help="""Show source line numbers in output, when available. May be enabled by + default depending on diff_settings.py.""", + ) + parser.add_argument( + "--no-line-numbers", + dest="show_line_numbers", + action="store_const", + const=False, + help="Hide source line numbers in output.", + ) + parser.add_argument( + "--inlines", + dest="inlines", + action="store_true", + help="Show inline function calls (if possible). Only works with -o or -e.", + ) + parser.add_argument( + "--base-asm", + dest="base_asm", + metavar="FILE", + help="Read assembly from given file instead of configured base img.", + ) + parser.add_argument( + "--write-asm", + dest="write_asm", + metavar="FILE", + help="Write the current assembly output to file, e.g. for use with --base-asm.", + ) + parser.add_argument( + "-m", + "--make", + dest="make", + action="store_true", + help="Automatically run 'make' on the .o file or binary before diffing.", + ) + parser.add_argument( + "-l", + "--skip-lines", + dest="skip_lines", + metavar="LINES", + type=int, + default=0, + help="Skip the first LINES lines of output.", + ) + parser.add_argument( + "-s", + "--stop-jr-ra", + dest="stop_jrra", + action="store_true", + help="""Stop disassembling at the first 'jr ra'. Some functions have + multiple return points, so use with care!""", + ) + parser.add_argument( + "-i", + "--ignore-large-imms", + dest="ignore_large_imms", + action="store_true", + help="Pretend all large enough immediates are the same.", + ) + parser.add_argument( + "-I", + "--ignore-addr-diffs", + dest="ignore_addr_diffs", + action="store_true", + help="Ignore address differences. Currently only affects AArch64 and ARM32.", + ) + parser.add_argument( + "-B", + "--no-show-branches", + dest="show_branches", + action="store_false", + help="Don't visualize branches/branch targets.", + ) + parser.add_argument( + "-S", + "--base-shift", + dest="base_shift", + metavar="N", + type=str, + default="0", + help="""Diff position N in our img against position N + shift in the base img. + Arithmetic is allowed, so e.g. |-S "0x1234 - 0x4321"| is a reasonable + flag to pass if it is known that position 0x1234 in the base img syncs + up with position 0x4321 in our img. Not supported together with -o.""", + ) + parser.add_argument( + "-w", + "--watch", + dest="watch", + action="store_true", + help="""Automatically update when source/object files change. + Recommended in combination with -m.""", + ) + parser.add_argument( + "-3", + "--threeway=prev", + dest="threeway", + action="store_const", + const="prev", + help="""Show a three-way diff between target asm, current asm, and asm + prior to -w rebuild. Requires -w.""", + ) + parser.add_argument( + "-b", + "--threeway=base", + dest="threeway", + action="store_const", + const="base", + help="""Show a three-way diff between target asm, current asm, and asm + when diff.py was started. Requires -w.""", + ) + parser.add_argument( + "--width", + dest="column_width", + metavar="COLS", + type=int, + default=50, + help="Sets the width of the left and right view column.", + ) + parser.add_argument( + "--algorithm", + dest="algorithm", + default="levenshtein", + choices=["levenshtein", "difflib"], + help="""Diff algorithm to use. Levenshtein gives the minimum diff, while difflib + aims for long sections of equal opcodes. Defaults to %(default)s.""", + ) + parser.add_argument( + "--max-size", + "--max-lines", + metavar="LINES", + dest="max_lines", + type=int, + default=1024, + help="The maximum length of the diff, in lines.", + ) + parser.add_argument( + "--no-pager", + dest="no_pager", + action="store_true", + help="""Disable the pager; write output directly to stdout, then exit. + Incompatible with --watch.""", + ) + parser.add_argument( + "--format", + choices=("color", "plain", "html", "json"), + default="color", + help="Output format, default is color. --format=html or json implies --no-pager.", + ) + parser.add_argument( + "-U", + "--compress-matching", + metavar="N", + dest="compress_matching", + type=int, + help="""Compress streaks of matching lines, leaving N lines of context + around non-matching parts.""", + ) + parser.add_argument( + "-V", + "--compress-sameinstr", + metavar="N", + dest="compress_sameinstr", + type=int, + help="""Compress streaks of lines with same instructions (but possibly + different regalloc), leaving N lines of context around other parts.""", + ) + + # Project-specific flags, e.g. different versions/make arguments. + add_custom_arguments_fn = getattr(diff_settings, "add_custom_arguments", None) + if add_custom_arguments_fn: + add_custom_arguments_fn(parser) + + if argcomplete: + argcomplete.autocomplete(parser) + +# ==== IMPORTS ==== + +# (We do imports late to optimize auto-complete performance.) + +import abc +import ast +from collections import Counter, defaultdict +from dataclasses import asdict, dataclass, field, replace +import difflib +import enum +import html +import itertools +import json +import os +import queue +import re +import string +import struct +import subprocess +import threading +import time +import traceback + + +MISSING_PREREQUISITES = ( + "Missing prerequisite python module {}. " + "Run `python3 -m pip install --user colorama watchdog python-Levenshtein cxxfilt` to install prerequisites (cxxfilt only needed with --source)." +) + +try: + from colorama import Back, Fore, Style + import watchdog +except ModuleNotFoundError as e: + fail(MISSING_PREREQUISITES.format(e.name)) + +# ==== CONFIG ==== + + +@dataclass +class ProjectSettings: + arch_str: str + objdump_executable: str + build_command: List[str] + map_format: str + mw_build_dir: str + baseimg: Optional[str] + myimg: Optional[str] + mapfile: Optional[str] + source_directories: Optional[List[str]] + source_extensions: List[str] + show_line_numbers_default: bool + disassemble_all: bool + + +@dataclass +class Compress: + context: int + same_instr: bool + + +@dataclass +class Config: + arch: "ArchSettings" + + # Build/objdump options + diff_obj: bool + make: bool + source_old_binutils: bool + diff_section: str + inlines: bool + max_function_size_lines: int + max_function_size_bytes: int + + # Display options + formatter: "Formatter" + threeway: Optional[str] + base_shift: int + skip_lines: int + compress: Optional[Compress] + show_branches: bool + show_line_numbers: bool + show_source: bool + stop_jrra: bool + ignore_large_imms: bool + ignore_addr_diffs: bool + algorithm: str + + # Score options + score_stack_differences = True + penalty_stackdiff = 1 + penalty_regalloc = 5 + penalty_reordering = 60 + penalty_insertion = 100 + penalty_deletion = 100 + + +def create_project_settings(settings: Dict[str, Any]) -> ProjectSettings: + return ProjectSettings( + arch_str=settings.get("arch", "mips"), + baseimg=settings.get("baseimg"), + myimg=settings.get("myimg"), + mapfile=settings.get("mapfile"), + build_command=settings.get( + "make_command", ["make", *settings.get("makeflags", [])] + ), + source_directories=settings.get("source_directories"), + source_extensions=settings.get( + "source_extensions", [".c", ".h", ".cpp", ".hpp", ".s"] + ), + objdump_executable=get_objdump_executable(settings.get("objdump_executable")), + map_format=settings.get("map_format", "gnu"), + mw_build_dir=settings.get("mw_build_dir", "build/"), + show_line_numbers_default=settings.get("show_line_numbers_default", True), + disassemble_all=settings.get("disassemble_all", False) + ) + + +def create_config(args: argparse.Namespace, project: ProjectSettings) -> Config: + arch = get_arch(project.arch_str) + + formatter: Formatter + if args.format == "plain": + formatter = PlainFormatter(column_width=args.column_width) + elif args.format == "color": + formatter = AnsiFormatter(column_width=args.column_width) + elif args.format == "html": + formatter = HtmlFormatter() + elif args.format == "json": + formatter = JsonFormatter(arch_str=arch.name) + else: + raise ValueError(f"Unsupported --format: {args.format}") + + compress = None + if args.compress_matching is not None: + compress = Compress(args.compress_matching, False) + if args.compress_sameinstr is not None: + if compress is not None: + raise ValueError( + "Cannot pass both --compress-matching and --compress-sameinstr" + ) + compress = Compress(args.compress_sameinstr, True) + + show_line_numbers = args.show_line_numbers + if show_line_numbers is None: + show_line_numbers = project.show_line_numbers_default + + return Config( + arch=arch, + # Build/objdump options + diff_obj=args.diff_obj, + make=args.make, + source_old_binutils=args.source_old_binutils, + diff_section=args.diff_section, + inlines=args.inlines, + max_function_size_lines=args.max_lines, + max_function_size_bytes=args.max_lines * 4, + # Display options + formatter=formatter, + threeway=args.threeway, + base_shift=eval_int( + args.base_shift, "Failed to parse --base-shift (-S) argument as an integer." + ), + skip_lines=args.skip_lines, + compress=compress, + show_branches=args.show_branches, + show_line_numbers=show_line_numbers, + show_source=args.show_source or args.source_old_binutils, + stop_jrra=args.stop_jrra, + ignore_large_imms=args.ignore_large_imms, + ignore_addr_diffs=args.ignore_addr_diffs, + algorithm=args.algorithm, + ) + + +def get_objdump_executable(objdump_executable: Optional[str]) -> str: + if objdump_executable is not None: + return objdump_executable + + objdump_candidates = [ + "mips-linux-gnu-objdump", + "mips64-elf-objdump", + "mips-elf-objdump", + ] + for objdump_cand in objdump_candidates: + try: + subprocess.check_call( + [objdump_cand, "--version"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + return objdump_cand + except subprocess.CalledProcessError: + pass + except FileNotFoundError: + pass + + return fail( + f"Missing binutils; please ensure {' or '.join(objdump_candidates)} exists, or configure objdump_executable." + ) + + +def get_arch(arch_str: str) -> "ArchSettings": + for settings in ARCH_SETTINGS: + if arch_str == settings.name: + return settings + raise ValueError(f"Unknown architecture: {arch_str}") + + +BUFFER_CMD: List[str] = ["tail", "-c", str(10 ** 9)] + +# -S truncates long lines instead of wrapping them +# -R interprets color escape sequences +# -i ignores case when searching +# -c something about how the screen gets redrawn; I don't remember the purpose +# -#6 makes left/right arrow keys scroll by 6 characters +LESS_CMD: List[str] = ["less", "-SRic", "-#6"] + +DEBOUNCE_DELAY: float = 0.1 + +# ==== FORMATTING ==== + + +@enum.unique +class BasicFormat(enum.Enum): + NONE = enum.auto() + IMMEDIATE = enum.auto() + STACK = enum.auto() + REGISTER = enum.auto() + DELAY_SLOT = enum.auto() + DIFF_CHANGE = enum.auto() + DIFF_ADD = enum.auto() + DIFF_REMOVE = enum.auto() + SOURCE_FILENAME = enum.auto() + SOURCE_FUNCTION = enum.auto() + SOURCE_LINE_NUM = enum.auto() + SOURCE_OTHER = enum.auto() + + +@dataclass(frozen=True) +class RotationFormat: + group: str + index: int + key: str + + +Format = Union[BasicFormat, RotationFormat] +FormatFunction = Callable[[str], Format] + + +class Text: + segments: List[Tuple[str, Format]] + + def __init__(self, line: str = "", f: Format = BasicFormat.NONE) -> None: + self.segments = [(line, f)] if line else [] + + def reformat(self, f: Format) -> "Text": + return Text(self.plain(), f) + + def plain(self) -> str: + return "".join(s for s, f in self.segments) + + def __repr__(self) -> str: + return f"" + + def __bool__(self) -> bool: + return any(s for s, f in self.segments) + + def __str__(self) -> str: + # Use Formatter.apply(...) instead + return NotImplemented + + def __eq__(self, other: object) -> bool: + return NotImplemented + + def __add__(self, other: Union["Text", str]) -> "Text": + if isinstance(other, str): + other = Text(other) + result = Text() + # If two adjacent segments have the same format, merge their lines + if ( + self.segments + and other.segments + and self.segments[-1][1] == other.segments[0][1] + ): + result.segments = ( + self.segments[:-1] + + [(self.segments[-1][0] + other.segments[0][0], self.segments[-1][1])] + + other.segments[1:] + ) + else: + result.segments = self.segments + other.segments + return result + + def __radd__(self, other: Union["Text", str]) -> "Text": + if isinstance(other, str): + other = Text(other) + return other + self + + def finditer(self, pat: Pattern[str]) -> Iterator[Match[str]]: + """Replacement for `pat.finditer(text)` that operates on the inner text, + and returns the exact same matches as `Text.sub(pat, ...)`.""" + for chunk, f in self.segments: + for match in pat.finditer(chunk): + yield match + + def sub(self, pat: Pattern[str], sub_fn: Callable[[Match[str]], "Text"]) -> "Text": + result = Text() + for chunk, f in self.segments: + i = 0 + for match in pat.finditer(chunk): + start, end = match.start(), match.end() + assert i <= start <= end <= len(chunk) + sub = sub_fn(match) + if i != start: + result.segments.append((chunk[i:start], f)) + result.segments.extend(sub.segments) + i = end + if chunk[i:]: + result.segments.append((chunk[i:], f)) + return result + + def ljust(self, column_width: int) -> "Text": + length = sum(len(x) for x, _ in self.segments) + return self + " " * max(column_width - length, 0) + + +@dataclass +class TableMetadata: + headers: Tuple[Text, ...] + current_score: int + max_score: int + previous_score: Optional[int] + + +class Formatter(abc.ABC): + @abc.abstractmethod + def apply_format(self, chunk: str, f: Format) -> str: + """Apply the formatting `f` to `chunk` and escape the contents.""" + ... + + @abc.abstractmethod + def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: + """Format a multi-column table with metadata""" + ... + + def apply(self, text: Text) -> str: + return "".join(self.apply_format(chunk, f) for chunk, f in text.segments) + + @staticmethod + def outputline_texts(lines: Tuple["OutputLine", ...]) -> Tuple[Text, ...]: + return tuple([lines[0].base or Text()] + [line.fmt2 for line in lines[1:]]) + + +@dataclass +class PlainFormatter(Formatter): + column_width: int + + def apply_format(self, chunk: str, f: Format) -> str: + return chunk + + def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: + rows = [meta.headers] + [self.outputline_texts(ls) for ls in lines] + return "\n".join( + "".join(self.apply(x.ljust(self.column_width)) for x in row) for row in rows + ) + + +@dataclass +class AnsiFormatter(Formatter): + # Additional ansi escape codes not in colorama. See: + # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters + STYLE_UNDERLINE = "\x1b[4m" + STYLE_NO_UNDERLINE = "\x1b[24m" + STYLE_INVERT = "\x1b[7m" + + BASIC_ANSI_CODES = { + BasicFormat.NONE: "", + BasicFormat.IMMEDIATE: Fore.LIGHTBLUE_EX, + BasicFormat.STACK: Fore.YELLOW, + BasicFormat.REGISTER: Fore.YELLOW, + BasicFormat.DELAY_SLOT: Fore.LIGHTBLACK_EX, + BasicFormat.DIFF_CHANGE: Fore.LIGHTBLUE_EX, + BasicFormat.DIFF_ADD: Fore.GREEN, + BasicFormat.DIFF_REMOVE: Fore.RED, + BasicFormat.SOURCE_FILENAME: Style.DIM + Style.BRIGHT, + BasicFormat.SOURCE_FUNCTION: Style.DIM + Style.BRIGHT + STYLE_UNDERLINE, + BasicFormat.SOURCE_LINE_NUM: Fore.LIGHTBLACK_EX, + BasicFormat.SOURCE_OTHER: Style.DIM, + } + + BASIC_ANSI_CODES_UNDO = { + BasicFormat.NONE: "", + BasicFormat.SOURCE_FILENAME: Style.NORMAL, + BasicFormat.SOURCE_FUNCTION: Style.NORMAL + STYLE_NO_UNDERLINE, + BasicFormat.SOURCE_OTHER: Style.NORMAL, + } + + ROTATION_ANSI_COLORS = [ + Fore.MAGENTA, + Fore.CYAN, + Fore.GREEN, + Fore.RED, + Fore.LIGHTYELLOW_EX, + Fore.LIGHTMAGENTA_EX, + Fore.LIGHTCYAN_EX, + Fore.LIGHTGREEN_EX, + Fore.LIGHTBLACK_EX, + ] + + column_width: int + + def apply_format(self, chunk: str, f: Format) -> str: + if f == BasicFormat.NONE: + return chunk + undo_ansi_code = Fore.RESET + if isinstance(f, BasicFormat): + ansi_code = self.BASIC_ANSI_CODES[f] + undo_ansi_code = self.BASIC_ANSI_CODES_UNDO.get(f, undo_ansi_code) + elif isinstance(f, RotationFormat): + ansi_code = self.ROTATION_ANSI_COLORS[ + f.index % len(self.ROTATION_ANSI_COLORS) + ] + else: + static_assert_unreachable(f) + return f"{ansi_code}{chunk}{undo_ansi_code}" + + def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: + rows = [(meta.headers, False)] + [ + (self.outputline_texts(line), line[1].is_data_ref) for line in lines + ] + return "\n".join( + "".join( + (self.STYLE_INVERT if is_data_ref else "") + + self.apply(x.ljust(self.column_width)) + for x in row + ) + for (row, is_data_ref) in rows + ) + + +@dataclass +class HtmlFormatter(Formatter): + rotation_formats: int = 9 + + def apply_format(self, chunk: str, f: Format) -> str: + chunk = html.escape(chunk) + if f == BasicFormat.NONE: + return chunk + if isinstance(f, BasicFormat): + class_name = f.name.lower().replace("_", "-") + data_attr = "" + elif isinstance(f, RotationFormat): + class_name = f"rotation-{f.index % self.rotation_formats}" + rotation_key = html.escape(f"{f.group};{f.key}", quote=True) + data_attr = f'data-rotation="{rotation_key}"' + else: + static_assert_unreachable(f) + return f"{chunk}" + + def table(self, meta: TableMetadata, lines: List[Tuple["OutputLine", ...]]) -> str: + def table_row(line: Tuple[Text, ...], is_data_ref: bool, cell_el: str) -> str: + tr_attrs = " class='data-ref'" if is_data_ref else "" + output_row = f" " + for cell in line: + cell_html = self.apply(cell) + output_row += f"<{cell_el}>{cell_html}" + output_row += "\n" + return output_row + + output = "\n" + output += " \n" + output += table_row(meta.headers, False, "th") + output += " \n" + output += " \n" + output += "".join( + table_row(self.outputline_texts(line), line[1].is_data_ref, "td") + for line in lines + ) + output += " \n" + output += "
\n" + return output + + +@dataclass +class JsonFormatter(Formatter): + arch_str: str + + def apply_format(self, chunk: str, f: Format) -> str: + # This method is unused by this formatter + return NotImplemented + + def table(self, meta: TableMetadata, rows: List[Tuple["OutputLine", ...]]) -> str: + def serialize_format(s: str, f: Format) -> Dict[str, Any]: + if f == BasicFormat.NONE: + return {"text": s} + elif isinstance(f, BasicFormat): + return {"text": s, "format": f.name.lower()} + elif isinstance(f, RotationFormat): + attrs = asdict(f) + attrs.update( + { + "text": s, + "format": "rotation", + } + ) + return attrs + else: + static_assert_unreachable(f) + + def serialize(text: Optional[Text]) -> List[Dict[str, Any]]: + if text is None: + return [] + return [serialize_format(s, f) for s, f in text.segments] + + is_threeway = len(meta.headers) == 3 + + output: Dict[str, Any] = {} + output["arch_str"] = self.arch_str + output["header"] = { + name: serialize(h) + for h, name in zip(meta.headers, ("base", "current", "previous")) + } + output["current_score"] = meta.current_score + output["max_score"] = meta.max_score + if meta.previous_score is not None: + output["previous_score"] = meta.previous_score + output_rows: List[Dict[str, Any]] = [] + for row in rows: + output_row: Dict[str, Any] = {} + output_row["key"] = row[0].key2 + output_row["is_data_ref"] = row[1].is_data_ref + iters = [ + ("base", row[0].base, row[0].line1), + ("current", row[1].fmt2, row[1].line2), + ] + if is_threeway: + iters.append(("previous", row[2].fmt2, row[2].line2)) + if all(line is None for _, _, line in iters): + # Skip rows that were only for displaying source code + continue + for column_name, text, line in iters: + column: Dict[str, Any] = {} + column["text"] = serialize(text) + if line: + if line.line_num is not None: + column["line"] = line.line_num + if line.branch_target is not None: + column["branch"] = line.branch_target + if line.source_lines: + column["src"] = line.source_lines + if line.comment is not None: + column["src_comment"] = line.comment + if line.source_line_num is not None: + column["src_line"] = line.source_line_num + if line or column["text"]: + output_row[column_name] = column + output_rows.append(output_row) + output["rows"] = output_rows + return json.dumps(output) + + +def format_fields( + pat: Pattern[str], + out1: Text, + out2: Text, + color1: FormatFunction, + color2: Optional[FormatFunction] = None, +) -> Tuple[Text, Text]: + diffs = [ + of.group() != nf.group() + for (of, nf) in zip(out1.finditer(pat), out2.finditer(pat)) + ] + + it = iter(diffs) + + def maybe_color(color: FormatFunction, s: str) -> Text: + return Text(s, color(s)) if next(it, False) else Text(s) + + out1 = out1.sub(pat, lambda m: maybe_color(color1, m.group())) + it = iter(diffs) + out2 = out2.sub(pat, lambda m: maybe_color(color2 or color1, m.group())) + + return out1, out2 + + +def symbol_formatter(group: str, base_index: int) -> FormatFunction: + symbol_formats: Dict[str, Format] = {} + + def symbol_format(s: str) -> Format: + # TODO: it would be nice to use a unique Format for each symbol, so we could + # add extra UI elements in the HTML version + f = symbol_formats.get(s) + if f is None: + index = len(symbol_formats) + base_index + f = RotationFormat(key=s, index=index, group=group) + symbol_formats[s] = f + return f + + return symbol_format + + +# ==== LOGIC ==== + +ObjdumpCommand = Tuple[List[str], str, Optional[str]] + + +def maybe_eval_int(expr: str) -> Optional[int]: + try: + ret = ast.literal_eval(expr) + if not isinstance(ret, int): + raise Exception("not an integer") + return ret + except Exception: + return None + + +def eval_int(expr: str, emsg: str) -> int: + ret = maybe_eval_int(expr) + if ret is None: + fail(emsg) + return ret + + +def eval_line_num(expr: str) -> Optional[int]: + expr = expr.strip().replace(":", "") + if expr == "": + return None + return int(expr, 16) + + +def run_make(target: str, project: ProjectSettings) -> None: + subprocess.check_call(project.build_command + [target]) + + +def run_make_capture_output( + target: str, project: ProjectSettings +) -> "subprocess.CompletedProcess[bytes]": + return subprocess.run( + project.build_command + [target], + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + ) + + +def restrict_to_function(dump: str, fn_name: str) -> str: + try: + ind = dump.index("\n", dump.index(f"<{fn_name}>:")) + return dump[ind + 1 :] + except ValueError: + return "" + + +def serialize_data_references(references: List[Tuple[int, int, str]]) -> str: + return "".join( + f"DATAREF {text_offset} {from_offset} {from_section}\n" + for (text_offset, from_offset, from_section) in references + ) + + +def maybe_get_objdump_source_flags(config: Config) -> List[str]: + flags = [] + + if config.show_line_numbers or config.show_source: + flags.append("--line-numbers") + + if config.show_source: + flags.append("--source") + + if not config.source_old_binutils: + flags.append("--source-comment=│ ") + + if config.inlines: + flags.append("--inlines") + + return flags + + +def run_objdump(cmd: ObjdumpCommand, config: Config, project: ProjectSettings) -> str: + flags, target, restrict = cmd + try: + out = subprocess.run( + [project.objdump_executable] + config.arch.arch_flags + flags + [target], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ).stdout + except subprocess.CalledProcessError as e: + print(e.stdout) + print(e.stderr) + if "unrecognized option '--source-comment" in e.stderr: + fail("** Try using --source-old-binutils instead of --source **") + raise e + + obj_data: Optional[bytes] = None + if config.diff_obj: + with open(target, "rb") as f: + obj_data = f.read() + + return preprocess_objdump_out(restrict, obj_data, out, config) + + +def preprocess_objdump_out( + restrict: Optional[str], obj_data: Optional[bytes], objdump_out: str, config: Config +) -> str: + """ + Preprocess the output of objdump into a format that `process()` expects. + This format is suitable for saving to disk with `--write-asm`. + + - Optionally filter the output to a single function (`restrict`) + - Otherwise, strip objdump header (7 lines) + - Prepend .data references ("DATAREF" lines) when working with object files + """ + out = objdump_out + + if restrict is not None: + out = restrict_to_function(out, restrict) + else: + for i in range(7): + out = out[out.find("\n") + 1 :] + out = out.rstrip("\n") + + if obj_data: + out = serialize_data_references(parse_elf_data_references(obj_data, config)) + out + + return out + + +def search_map_file( + fn_name: str, project: ProjectSettings, config: Config +) -> Tuple[Optional[str], Optional[int]]: + if not project.mapfile: + fail(f"No map file configured; cannot find function {fn_name}.") + + try: + with open(project.mapfile) as f: + contents = f.read() + except Exception: + fail(f"Failed to open map file {project.mapfile} for reading.") + + if project.map_format == "gnu": + lines = contents.split("\n") + + try: + cur_objfile = None + ram_to_rom = None + cands = [] + last_line = "" + for line in lines: + if line.startswith(" " + config.diff_section): + cur_objfile = line.split()[3] + if "load address" in line: + tokens = last_line.split() + line.split() + ram = int(tokens[1], 0) + rom = int(tokens[5], 0) + ram_to_rom = rom - ram + if line.endswith(" " + fn_name): + ram = int(line.split()[0], 0) + if cur_objfile is not None and ram_to_rom is not None: + cands.append((cur_objfile, ram + ram_to_rom)) + last_line = line + except Exception as e: + traceback.print_exc() + fail(f"Internal error while parsing map file") + + if len(cands) > 1: + fail(f"Found multiple occurrences of function {fn_name} in map file.") + if len(cands) == 1: + return cands[0] + elif project.map_format == "mw": + section_pattern = re.escape(config.diff_section) + find = re.findall( + re.compile( + # ram elf rom + r" \S+ \S+ (\S+) (\S+) . " + + fn_name + # object name + + r"(?: \(entry of " + section_pattern + r"\))? \t(\S+)" + ), + contents, + ) + if len(find) > 1: + fail(f"Found multiple occurrences of function {fn_name} in map file.") + if len(find) == 1: + rom = int(find[0][1], 16) + objname = find[0][2] + # The metrowerks linker map format does not contain the full object path, + # so we must complete it manually. + objfiles = [ + os.path.join(dirpath, f) + for dirpath, _, filenames in os.walk(project.mw_build_dir) + for f in filenames + if f == objname + ] + if len(objfiles) > 1: + all_objects = "\n".join(objfiles) + fail( + f"Found multiple objects of the same name {objname} in {project.mw_build_dir}, " + f"cannot determine which to diff against: \n{all_objects}" + ) + if len(objfiles) == 1: + objfile = objfiles[0] + # TODO Currently the ram-rom conversion only works for diffing ELF + # executables, but it would likely be more convenient to diff DOLs. + # At this time it is recommended to always use -o when running the diff + # script as this mode does not make use of the ram-rom conversion. + return objfile, rom + else: + fail(f"Linker map format {project.map_format} unrecognised.") + return None, None + + +def parse_elf_data_references(data: bytes, config: Config) -> List[Tuple[int, int, str]]: + e_ident = data[:16] + if e_ident[:4] != b"\x7FELF": + return [] + + SHT_SYMTAB = 2 + SHT_REL = 9 + SHT_RELA = 4 + + is_32bit = e_ident[4] == 1 + is_little_endian = e_ident[5] == 1 + str_end = "<" if is_little_endian else ">" + str_off = "I" if is_32bit else "Q" + sym_size = {"B": 1, "H": 2, "I": 4, "Q": 8} + + def read(spec: str, offset: int) -> Tuple[int, ...]: + spec = spec.replace("P", str_off) + size = struct.calcsize(spec) + return struct.unpack(str_end + spec, data[offset : offset + size]) + + ( + e_type, + e_machine, + e_version, + e_entry, + e_phoff, + e_shoff, + e_flags, + e_ehsize, + e_phentsize, + e_phnum, + e_shentsize, + e_shnum, + e_shstrndx, + ) = read("HHIPPPIHHHHHH", 16) + if e_type != 1: # relocatable + return [] + assert e_shoff != 0 + assert e_shnum != 0 # don't support > 0xFF00 sections + assert e_shstrndx != 0 + + @dataclass + class Section: + sh_name: int + sh_type: int + sh_flags: int + sh_addr: int + sh_offset: int + sh_size: int + sh_link: int + sh_info: int + sh_addralign: int + sh_entsize: int + + sections = [ + Section(*read("IIPPPPIIPP", e_shoff + i * e_shentsize)) for i in range(e_shnum) + ] + shstr = sections[e_shstrndx] + sec_name_offs = [shstr.sh_offset + s.sh_name for s in sections] + sec_names = [data[offset : data.index(b"\0", offset)] for offset in sec_name_offs] + + symtab_sections = [i for i in range(e_shnum) if sections[i].sh_type == SHT_SYMTAB] + assert len(symtab_sections) == 1 + symtab = sections[symtab_sections[0]] + + section_name = config.diff_section.encode("utf-8") + text_sections = [i for i in range(e_shnum) if sec_names[i] == section_name and sections[i].sh_size != 0] + if len(text_sections) != 1: + return [] + text_section = text_sections[0] + + ret: List[Tuple[int, int, str]] = [] + for s in sections: + if s.sh_type == SHT_REL or s.sh_type == SHT_RELA: + if s.sh_info == text_section: + # Skip section_name -> section_name references + continue + sec_name = sec_names[s.sh_info].decode("latin1") + if sec_name == ".mwcats.text": + # Skip Metrowerks CATS Utility section + continue + sec_base = sections[s.sh_info].sh_offset + for i in range(0, s.sh_size, s.sh_entsize): + if s.sh_type == SHT_REL: + r_offset, r_info = read("PP", s.sh_offset + i) + else: + r_offset, r_info, r_addend = read("PPP", s.sh_offset + i) + + if is_32bit: + r_sym = r_info >> 8 + r_type = r_info & 0xFF + sym_offset = symtab.sh_offset + symtab.sh_entsize * r_sym + st_name, st_value, st_size, st_info, st_other, st_shndx = read( + "IIIBBH", sym_offset + ) + else: + r_sym = r_info >> 32 + r_type = r_info & 0xFFFFFFFF + sym_offset = symtab.sh_offset + symtab.sh_entsize * r_sym + st_name, st_info, st_other, st_shndx, st_value, st_size = read( + "IBBHQQ", sym_offset + ) + if st_shndx == text_section: + if s.sh_type == SHT_REL: + if e_machine == 8 and r_type == 2: # R_MIPS_32 + (r_addend,) = read("I", sec_base + r_offset) + else: + continue + text_offset = (st_value + r_addend) & 0xFFFFFFFF + ret.append((text_offset, r_offset, sec_name)) + return ret + + +def dump_elf( + start: str, + end: Optional[str], + diff_elf_symbol: str, + config: Config, + project: ProjectSettings, +) -> Tuple[str, ObjdumpCommand, ObjdumpCommand]: + if not project.baseimg or not project.myimg: + fail("Missing myimg/baseimg in config.") + if config.base_shift: + fail("--base-shift not compatible with -e") + + start_addr = eval_int(start, "Start address must be an integer expression.") + + if end is not None: + end_addr = eval_int(end, "End address must be an integer expression.") + else: + end_addr = start_addr + config.max_function_size_bytes + + flags1 = [ + f"--start-address={start_addr}", + f"--stop-address={end_addr}", + ] + + if project.disassemble_all: + disassemble_flag = "-D" + else: + disassemble_flag = "-d" + + flags2 = [ + f"--disassemble={diff_elf_symbol}", + ] + + objdump_flags = [disassemble_flag, "-rz", "-j", config.diff_section] + return ( + project.myimg, + (objdump_flags + flags1, project.baseimg, None), + ( + objdump_flags + flags2 + maybe_get_objdump_source_flags(config), + project.myimg, + None, + ), + ) + + +def dump_objfile( + start: str, end: Optional[str], config: Config, project: ProjectSettings +) -> Tuple[str, ObjdumpCommand, ObjdumpCommand]: + if config.base_shift: + fail("--base-shift not compatible with -o") + if end is not None: + fail("end address not supported together with -o") + if start.startswith("0"): + fail("numerical start address not supported with -o; pass a function name") + + objfile, _ = search_map_file(start, project, config) + if not objfile: + fail("Not able to find .o file for function.") + + if config.make: + run_make(objfile, project) + + if not os.path.isfile(objfile): + fail(f"Not able to find .o file for function: {objfile} is not a file.") + + refobjfile = "expected/" + objfile + if not os.path.isfile(refobjfile): + fail(f'Please ensure an OK .o file exists at "{refobjfile}".') + + if project.disassemble_all: + disassemble_flag = "-D" + else: + disassemble_flag = "-d" + + objdump_flags = [disassemble_flag, "-rz", "-j", config.diff_section] + return ( + objfile, + (objdump_flags, refobjfile, start), + (objdump_flags + maybe_get_objdump_source_flags(config), objfile, start), + ) + + +def dump_binary( + start: str, end: Optional[str], config: Config, project: ProjectSettings +) -> Tuple[str, ObjdumpCommand, ObjdumpCommand]: + if not project.baseimg or not project.myimg: + fail("Missing myimg/baseimg in config.") + if config.make: + run_make(project.myimg, project) + start_addr = maybe_eval_int(start) + if start_addr is None: + _, start_addr = search_map_file(start, project, config) + if start_addr is None: + fail("Not able to find function in map file.") + if end is not None: + end_addr = eval_int(end, "End address must be an integer expression.") + else: + end_addr = start_addr + config.max_function_size_bytes + objdump_flags = ["-Dz", "-bbinary"] + ["-EB" if config.arch.big_endian else "-EL"] + flags1 = [ + f"--start-address={start_addr + config.base_shift}", + f"--stop-address={end_addr + config.base_shift}", + ] + flags2 = [f"--start-address={start_addr}", f"--stop-address={end_addr}"] + return ( + project.myimg, + (objdump_flags + flags1, project.baseimg, None), + (objdump_flags + flags2, project.myimg, None), + ) + +# Example: "ldr r4, [pc, #56] ; (4c )" +ARM32_LOAD_POOL_PATTERN = r"(ldr\s+r([0-9]|1[0-3]),\s+\[pc,.*;\s*)(\([a-fA-F0-9]+.*\))" + + +# The base class is a no-op. +class AsmProcessor: + def __init__(self, config: Config) -> None: + self.config = config + + def process_reloc(self, row: str, prev: str) -> str: + return prev + + def normalize(self, mnemonic: str, row: str) -> str: + """This should be called exactly once for each line.""" + arch = self.config.arch + row = self._normalize_arch_specific(mnemonic, row) + if self.config.ignore_large_imms and mnemonic not in arch.branch_instructions: + row = re.sub(self.config.arch.re_large_imm, "", row) + return row + + def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: + return row + + def post_process(self, lines: List["Line"]) -> None: + return + + +class AsmProcessorMIPS(AsmProcessor): + def process_reloc(self, row: str, prev: str) -> str: + arch = self.config.arch + if "R_MIPS_NONE" in row: + # GNU as emits no-op relocations immediately after real ones when + # assembling with -mabi=64. Return without trying to parse 'imm' as an + # integer. + return prev + before, imm, after = parse_relocated_line(prev) + repl = row.split()[-1] + if imm != "0": + # MIPS uses relocations with addends embedded in the code as immediates. + # If there is an immediate, show it as part of the relocation. Ideally + # we'd show this addend in both %lo/%hi, but annoyingly objdump's output + # doesn't include enough information to pair up %lo's and %hi's... + # TODO: handle unambiguous cases where all addends for a symbol are the + # same, or show "+???". + mnemonic = prev.split()[0] + if ( + mnemonic in arch.instructions_with_address_immediates + and not imm.startswith("0x") + ): + imm = "0x" + imm + repl += "+" + imm if int(imm, 0) > 0 else imm + if "R_MIPS_LO16" in row: + repl = f"%lo({repl})" + elif "R_MIPS_HI16" in row: + # Ideally we'd pair up R_MIPS_LO16 and R_MIPS_HI16 to generate a + # correct addend for each, but objdump doesn't give us the order of + # the relocations, so we can't find the right LO16. :( + repl = f"%hi({repl})" + elif "R_MIPS_26" in row: + # Function calls + pass + elif "R_MIPS_PC16" in row: + # Branch to glabel. This gives confusing output, but there's not much + # we can do here. + pass + elif "R_MIPS_GPREL16" in row: + repl = f"%gp_rel({repl})" + else: + assert False, f"unknown relocation type '{row}' for line '{prev}'" + return before + repl + after + + +class AsmProcessorPPC(AsmProcessor): + def process_reloc(self, row: str, prev: str) -> str: + arch = self.config.arch + assert any( + r in row for r in ["R_PPC_REL24", "R_PPC_ADDR16", "R_PPC_EMB_SDA21"] + ), f"unknown relocation type '{row}' for line '{prev}'" + before, imm, after = parse_relocated_line(prev) + repl = row.split()[-1] + if "R_PPC_REL24" in row: + # function calls + pass + elif "R_PPC_ADDR16_HI" in row: + # absolute hi of addr + repl = f"{repl}@h" + elif "R_PPC_ADDR16_HA" in row: + # adjusted hi of addr + repl = f"{repl}@ha" + elif "R_PPC_ADDR16_LO" in row: + # lo of addr + repl = f"{repl}@l" + elif "R_PPC_ADDR16" in row: + # 16-bit absolute addr + if "+0x7" in repl: + # remove the very large addends as they are an artifact of (label-_SDA(2)_BASE_) + # computations and are unimportant in a diff setting. + if int(repl.split("+")[1], 16) > 0x70000000: + repl = repl.split("+")[0] + elif "R_PPC_EMB_SDA21" in row: + # small data area + pass + return before + repl + after + + +class AsmProcessorARM32(AsmProcessor): + def process_reloc(self, row: str, prev: str) -> str: + arch = self.config.arch + before, imm, after = parse_relocated_line(prev) + repl = row.split()[-1] + return before + repl + after + + def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: + if self.config.ignore_addr_diffs: + row = self._normalize_bl(mnemonic, row) + row = self._normalize_data_pool(row) + return row + + def _normalize_bl(self, mnemonic: str, row: str) -> str: + if mnemonic != "bl": + return row + + row, _ = split_off_address(row) + return row + "" + + def _normalize_data_pool(self, row: str) -> str: + pool_match = re.search(ARM32_LOAD_POOL_PATTERN, row) + return pool_match.group(1) if pool_match else row + + def post_process(self, lines: List["Line"]) -> None: + lines_by_line_number = {} + for line in lines: + lines_by_line_number[line.line_num] = line + for line in lines: + if line.data_pool_addr is None: + continue + + # Add data symbol and its address to the line. + line_original = lines_by_line_number[line.data_pool_addr].original + value = line_original.split()[1] + addr = "{:x}".format(line.data_pool_addr) + line.original = line.normalized_original + f"={value} ({addr})" + + +class AsmProcessorAArch64(AsmProcessor): + def __init__(self, config: Config) -> None: + super().__init__(config) + self._adrp_pair_registers: Set[str] = set() + + def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: + if self.config.ignore_addr_diffs: + row = self._normalize_adrp_differences(mnemonic, row) + row = self._normalize_bl(mnemonic, row) + return row + + def _normalize_bl(self, mnemonic: str, row: str) -> str: + if mnemonic != "bl": + return row + + row, _ = split_off_address(row) + return row + "" + + def _normalize_adrp_differences(self, mnemonic: str, row: str) -> str: + """Identifies ADRP + LDR/ADD pairs that are used to access the GOT and + suppresses any immediate differences. + + Whenever an ADRP is seen, the destination register is added to the set of registers + that are part of an ADRP + LDR/ADD pair. Registers are removed from the set as soon + as they are used for an LDR or ADD instruction which completes the pair. + + This method is somewhat crude but should manage to detect most such pairs. + """ + row_parts = row.split("\t", 1) + if mnemonic == "adrp": + self._adrp_pair_registers.add(row_parts[1].strip().split(",")[0]) + row, _ = split_off_address(row) + return row + "" + elif mnemonic == "ldr": + for reg in self._adrp_pair_registers: + # ldr xxx, [reg] + # ldr xxx, [reg, ] + if f", [{reg}" in row_parts[1]: + self._adrp_pair_registers.remove(reg) + return normalize_imms(row, AARCH64_SETTINGS) + elif mnemonic == "add": + for reg in self._adrp_pair_registers: + # add reg, reg, + if row_parts[1].startswith(f"{reg}, {reg}, "): + self._adrp_pair_registers.remove(reg) + return normalize_imms(row, AARCH64_SETTINGS) + + return row + + +@dataclass +class ArchSettings: + name: str + re_int: Pattern[str] + re_comment: Pattern[str] + re_reg: Pattern[str] + re_sprel: Pattern[str] + re_large_imm: Pattern[str] + re_imm: Pattern[str] + re_reloc: Pattern[str] + branch_instructions: Set[str] + instructions_with_address_immediates: Set[str] + forbidden: Set[str] = field(default_factory=lambda: set(string.ascii_letters + "_")) + arch_flags: List[str] = field(default_factory=list) + branch_likely_instructions: Set[str] = field(default_factory=set) + proc: Type[AsmProcessor] = AsmProcessor + big_endian: Optional[bool] = True + delay_slot_instructions: Set[str] = field(default_factory=set) + +MIPS_BRANCH_LIKELY_INSTRUCTIONS = { + "beql", + "bnel", + "beqzl", + "bnezl", + "bgezl", + "bgtzl", + "blezl", + "bltzl", + "bc1tl", + "bc1fl", +} +MIPS_BRANCH_INSTRUCTIONS = MIPS_BRANCH_LIKELY_INSTRUCTIONS.union( + { + "b", + "beq", + "bne", + "beqz", + "bnez", + "bgez", + "bgtz", + "blez", + "bltz", + "bc1t", + "bc1f", + } +) + +ARM32_PREFIXES = {"b", "bl"} +ARM32_CONDS = { + "", + "eq", + "ne", + "cs", + "cc", + "mi", + "pl", + "vs", + "vc", + "hi", + "ls", + "ge", + "lt", + "gt", + "le", + "al", +} +ARM32_SUFFIXES = {"", ".n", ".w"} +ARM32_BRANCH_INSTRUCTIONS = { + f"{prefix}{cond}{suffix}" + for prefix in ARM32_PREFIXES + for cond in ARM32_CONDS + for suffix in ARM32_SUFFIXES +} + +AARCH64_BRANCH_INSTRUCTIONS = { + "b", + "b.eq", + "b.ne", + "b.cs", + "b.hs", + "b.cc", + "b.lo", + "b.mi", + "b.pl", + "b.vs", + "b.vc", + "b.hi", + "b.ls", + "b.ge", + "b.lt", + "b.gt", + "b.le", + "cbz", + "cbnz", + "tbz", + "tbnz", +} + +PPC_BRANCH_INSTRUCTIONS = { + "b", + "beq", + "beq+", + "beq-", + "bne", + "bne+", + "bne-", + "blt", + "blt+", + "blt-", + "ble", + "ble+", + "ble-", + "bdnz", + "bdnz+", + "bdnz-", + "bge", + "bge+", + "bge-", + "bgt", + "bgt+", + "bgt-", +} + +MIPS_SETTINGS = ArchSettings( + name="mips", + re_int=re.compile(r"[0-9]+"), + re_comment=re.compile(r"<.*?>"), + re_reg=re.compile( + r"\$?\b(a[0-7]|t[0-9]|s[0-8]|at|v[01]|f[12]?[0-9]|f3[01]|kt?[01]|fp|ra|zero)\b" + ), + re_sprel=re.compile(r"(?<=,)([0-9]+|0x[0-9a-f]+)\(sp\)"), + re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), + re_imm=re.compile(r"(\b|-)([0-9]+|0x[0-9a-fA-F]+)\b(?!\(sp)|%(lo|hi)\([^)]*\)"), + re_reloc=re.compile(r"R_MIPS_"), + arch_flags=["-m", "mips:4300"], + branch_likely_instructions=MIPS_BRANCH_LIKELY_INSTRUCTIONS, + branch_instructions=MIPS_BRANCH_INSTRUCTIONS, + instructions_with_address_immediates=MIPS_BRANCH_INSTRUCTIONS.union({"jal", "j"}), + delay_slot_instructions=MIPS_BRANCH_INSTRUCTIONS.union({"j", "jal", "jr", "jalr"}), + proc=AsmProcessorMIPS, +) + +MIPSEL_SETTINGS = replace(MIPS_SETTINGS, name="mipsel", big_endian=False) + +ARM32_SETTINGS = ArchSettings( + name="arm32", + re_int=re.compile(r"[0-9]+"), + re_comment=re.compile(r"(<.*?>|//.*$)"), + # Includes: + # - General purpose registers: r0..13 + # - Frame pointer registers: lr (r14), pc (r15) + # - VFP/NEON registers: s0..31, d0..31, q0..15, fpscr, fpexc, fpsid + # SP should not be in this list. + re_reg=re.compile( + r"\$?\b([rq][0-9]|[rq]1[0-5]|pc|lr|[ds][12]?[0-9]|[ds]3[01]|fp(scr|exc|sid))\b" + ), + re_sprel=re.compile(r"sp, #-?(0x[0-9a-fA-F]+|[0-9]+)\b"), + re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), + re_imm=re.compile(r"(?|//.*$)"), + # GPRs and FP registers: X0-X30, W0-W30, [BHSDVQ]0..31 + # (FP registers may be followed by data width and number of elements, e.g. V0.4S) + # The zero registers and SP should not be in this list. + re_reg=re.compile(r"\$?\b([bhsdvq]([12]?[0-9]|3[01])(\.\d\d?[bhsdvq])?|[xw][12]?[0-9]|[xw]30)\b"), + re_sprel=re.compile(r"sp, #-?(0x[0-9a-fA-F]+|[0-9]+)\b"), + re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), + re_imm=re.compile(r"(?|//.*$)"), + re_reg=re.compile(r"\$?\b([rf][0-9]+)\b"), + re_sprel=re.compile(r"(?<=,)(-?[0-9]+|-?0x[0-9a-f]+)\(r1\)"), + re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), + re_imm=re.compile(r"(\b|-)([0-9]+|0x[0-9a-fA-F]+)\b(?!\(r1)|[^@]*@(ha|h|lo)"), + re_reloc=re.compile(r"R_PPC_"), + branch_instructions=PPC_BRANCH_INSTRUCTIONS, + instructions_with_address_immediates=PPC_BRANCH_INSTRUCTIONS.union({"bl"}), + proc=AsmProcessorPPC, +) + +ARCH_SETTINGS = [ + MIPS_SETTINGS, + MIPSEL_SETTINGS, + ARM32_SETTINGS, + ARMEL_SETTINGS, + AARCH64_SETTINGS, + PPC_SETTINGS, +] + + +def hexify_int(row: str, pat: Match[str], arch: ArchSettings) -> str: + full = pat.group(0) + if len(full) <= 1: + # leave one-digit ints alone + return full + start, end = pat.span() + if start and row[start - 1] in arch.forbidden: + return full + if end < len(row) and row[end] in arch.forbidden: + return full + return hex(int(full)) + + +def parse_relocated_line(line: str) -> Tuple[str, str, str]: + for c in ",\t ": + if c in line: + ind2 = line.rindex(c) + break + else: + raise Exception(f"failed to parse relocated line: {line}") + before = line[: ind2 + 1] + after = line[ind2 + 1 :] + ind2 = after.find("(") + if ind2 == -1: + imm, after = after, "" + else: + imm, after = after[:ind2], after[ind2:] + if imm == "0x0": + imm = "0" + return before, imm, after + + +def pad_mnemonic(line: str) -> str: + if "\t" not in line: + return line + mn, args = line.split("\t", 1) + return f"{mn:<7s} {args}" + + +@dataclass +class Line: + mnemonic: str + diff_row: str + original: str + normalized_original: str + scorable_line: str + line_num: Optional[int] = None + branch_target: Optional[int] = None + data_pool_addr: Optional[int] = None + source_filename: Optional[str] = None + source_line_num: Optional[int] = None + source_lines: List[str] = field(default_factory=list) + comment: Optional[str] = None + + +def process(dump: str, config: Config) -> List[Line]: + arch = config.arch + processor = arch.proc(config) + skip_next = False + source_lines = [] + source_filename = None + source_line_num = None + + i = 0 + num_instr = 0 + data_refs: Dict[int, Dict[str, List[int]]] = defaultdict(lambda: defaultdict(list)) + output: List[Line] = [] + stop_after_delay_slot = False + lines = dump.split("\n") + while i < len(lines): + row = lines[i] + i += 1 + + if not row: + continue + + if re.match(r"^[0-9a-f]+ <.*>:$", row): + continue + + if row.startswith("DATAREF"): + parts = row.split(" ", 3) + text_offset = int(parts[1]) + from_offset = int(parts[2]) + from_section = parts[3] + data_refs[text_offset][from_section].append(from_offset) + continue + + if config.diff_obj and num_instr >= config.max_function_size_lines: + output.append( + Line( + mnemonic="...", + diff_row="...", + original="...", + normalized_original="...", + scorable_line="...", + ) + ) + break + + if not re.match(r"^\s+[0-9a-f]+:\s+", row): + # This regex is conservative, and assumes the file path does not contain "weird" + # characters like colons, tabs, or angle brackets. + if re.match( + r"^[^ \t<>:][^\t<>:]*:[0-9]+( \(discriminator [0-9]+\))?$", row + ): + source_filename, _, tail = row.rpartition(":") + source_line_num = int(tail.partition(" ")[0]) + source_lines.append(row) + continue + + # If the instructions loads a data pool symbol, extract the address of + # the symbol. + data_pool_addr = None + pool_match = re.search(ARM32_LOAD_POOL_PATTERN, row) + if pool_match: + offset = pool_match.group(3).split(" ")[0][1:] + data_pool_addr = int(offset, 16) + + m_comment = re.search(arch.re_comment, row) + comment = m_comment[0] if m_comment else None + row = re.sub(arch.re_comment, "", row) + line_num_str = row.split(":")[0] + row = row.rstrip() + tabs = row.split("\t") + row = "\t".join(tabs[2:]) + line_num = eval_line_num(line_num_str.strip()) + + if line_num in data_refs: + refs = data_refs[line_num] + ref_str = "; ".join( + section_name + "+" + ",".join(hex(off) for off in offs) + for section_name, offs in refs.items() + ) + output.append( + Line( + mnemonic="", + diff_row="", + original=ref_str, + normalized_original=ref_str, + scorable_line="", + ) + ) + + if "\t" in row: + row_parts = row.split("\t", 1) + else: + # powerpc-eabi-objdump doesn't use tabs + row_parts = [part.lstrip() for part in row.split(" ", 1)] + mnemonic = row_parts[0].strip() + + if mnemonic not in arch.instructions_with_address_immediates: + row = re.sub(arch.re_int, lambda m: hexify_int(row, m, arch), row) + + # Let 'original' be 'row' with relocations applied, while we continue + # transforming 'row' into a coarser version that ignores registers and + # immediates. + original = row + + while i < len(lines): + reloc_row = lines[i] + if re.search(arch.re_reloc, reloc_row): + original = processor.process_reloc(reloc_row, original) + else: + break + i += 1 + + normalized_original = processor.normalize(mnemonic, original) + + scorable_line = normalized_original + if not config.score_stack_differences: + scorable_line = re.sub(arch.re_sprel, "addr(sp)", scorable_line) + if mnemonic in arch.branch_instructions: + # Replace the final argument with "" + scorable_line = re.sub(r"[^, \t]+$", "", scorable_line) + + if skip_next: + skip_next = False + row = "" + mnemonic = "" + scorable_line = "" + if mnemonic in arch.branch_likely_instructions: + skip_next = True + + row = re.sub(arch.re_reg, "", row) + row = re.sub(arch.re_sprel, "addr(sp)", row) + row_with_imm = row + if mnemonic in arch.instructions_with_address_immediates: + row = row.strip() + row, _ = split_off_address(row) + row += "" + else: + row = normalize_imms(row, arch) + + branch_target = None + if mnemonic in arch.branch_instructions: + branch_target = int(row_parts[1].strip().split(",")[-1], 16) + if mnemonic in arch.branch_likely_instructions: + branch_target -= 4 + + output.append( + Line( + mnemonic=mnemonic, + diff_row=row, + original=original, + normalized_original=normalized_original, + scorable_line=scorable_line, + line_num=line_num, + branch_target=branch_target, + data_pool_addr=data_pool_addr, + source_filename=source_filename, + source_line_num=source_line_num, + source_lines=source_lines, + comment=comment, + ) + ) + num_instr += 1 + source_lines = [] + + if config.stop_jrra and mnemonic == "jr" and row_parts[1].strip() == "ra": + stop_after_delay_slot = True + elif stop_after_delay_slot: + break + + processor.post_process(output) + return output + + +def normalize_imms(row: str, arch: ArchSettings) -> str: + return re.sub(arch.re_imm, "", row) + + +def normalize_stack(row: str, arch: ArchSettings) -> str: + return re.sub(arch.re_sprel, "addr(sp)", row) + + +def imm_matches_everything(row: str, arch: ArchSettings) -> bool: + # (this should probably be arch-specific) + return "(." in row + + +def split_off_address(line: str) -> Tuple[str, str]: + """Split e.g. 'beqz $r0,1f0' into 'beqz $r0,' and '1f0'.""" + parts = line.split(",") + if len(parts) < 2: + parts = line.split(None, 1) + off = len(line) - len(parts[-1]) + return line[:off], line[off:] + + +def diff_sequences_difflib( + seq1: List[str], seq2: List[str] +) -> List[Tuple[str, int, int, int, int]]: + differ = difflib.SequenceMatcher(a=seq1, b=seq2, autojunk=False) + return differ.get_opcodes() + + +def diff_sequences( + seq1: List[str], seq2: List[str], algorithm: str +) -> List[Tuple[str, int, int, int, int]]: + if ( + algorithm != "levenshtein" + or len(seq1) * len(seq2) > 4 * 10 ** 8 + or len(seq1) + len(seq2) >= 0x110000 + ): + return diff_sequences_difflib(seq1, seq2) + + # The Levenshtein library assumes that we compare strings, not lists. Convert. + # (Per the check above we know we have fewer than 0x110000 unique elements, so chr() works.) + remapping: Dict[str, str] = {} + + def remap(seq: List[str]) -> str: + seq = seq[:] + for i in range(len(seq)): + val = remapping.get(seq[i]) + if val is None: + val = chr(len(remapping)) + remapping[seq[i]] = val + seq[i] = val + return "".join(seq) + + rem1 = remap(seq1) + rem2 = remap(seq2) + import Levenshtein + + ret: List[Tuple[str, int, int, int, int]] = Levenshtein.opcodes(rem1, rem2) + return ret + + +def diff_lines( + lines1: List[Line], + lines2: List[Line], + algorithm: str, +) -> List[Tuple[Optional[Line], Optional[Line]]]: + ret = [] + for (tag, i1, i2, j1, j2) in diff_sequences( + [line.mnemonic for line in lines1], + [line.mnemonic for line in lines2], + algorithm, + ): + for line1, line2 in itertools.zip_longest(lines1[i1:i2], lines2[j1:j2]): + if tag == "replace": + if line1 is None: + tag = "insert" + elif line2 is None: + tag = "delete" + elif tag == "insert": + assert line1 is None + elif tag == "delete": + assert line2 is None + ret.append((line1, line2)) + + return ret + + +def score_diff_lines( + lines: List[Tuple[Optional[Line], Optional[Line]]], config: Config +) -> int: + # This logic is copied from `scorer.py` from the decomp permuter project + # https://github.com/simonlindholm/decomp-permuter/blob/main/src/scorer.py + score = 0 + deletions = [] + insertions = [] + + def lo_hi_match(old: str, new: str) -> bool: + # TODO: Make this arch-independent, like `imm_matches_everything()` + old_lo = old.find("%lo") + old_hi = old.find("%hi") + new_lo = new.find("%lo") + new_hi = new.find("%hi") + + if old_lo != -1 and new_lo != -1: + old_idx = old_lo + new_idx = new_lo + elif old_hi != -1 and new_hi != -1: + old_idx = old_hi + new_idx = new_hi + else: + return False + + if old[:old_idx] != new[:new_idx]: + return False + + old_inner = old[old_idx + 4 : -1] + new_inner = new[new_idx + 4 : -1] + return old_inner.startswith(".") or new_inner.startswith(".") + + def diff_sameline(old: str, new: str) -> None: + nonlocal score + if old == new: + return + + if lo_hi_match(old, new): + return + + ignore_last_field = False + if config.score_stack_differences: + oldsp = re.search(config.arch.re_sprel, old) + newsp = re.search(config.arch.re_sprel, new) + if oldsp and newsp: + oldrel = int(oldsp.group(1) or "0", 0) + newrel = int(newsp.group(1) or "0", 0) + score += abs(oldrel - newrel) * config.penalty_stackdiff + ignore_last_field = True + + # Probably regalloc difference, or signed vs unsigned + + # Compare each field in order + newfields, oldfields = new.split(","), old.split(",") + if ignore_last_field: + newfields = newfields[:-1] + oldfields = oldfields[:-1] + for nf, of in zip(newfields, oldfields): + if nf != of: + score += config.penalty_regalloc + # Penalize any extra fields + score += abs(len(newfields) - len(oldfields)) * config.penalty_regalloc + + def diff_insert(line: str) -> None: + # Reordering or totally different codegen. + # Defer this until later when we can tell. + insertions.append(line) + + def diff_delete(line: str) -> None: + deletions.append(line) + + # Find the end of the last long streak of matching mnemonics, if it looks + # like the objdump output was truncated. This is used to skip scoring + # misaligned lines at the end of the diff. + last_mismatch = -1 + max_index = None + lines_were_truncated = False + for index, (line1, line2) in enumerate(lines): + if (line1 and line1.original == "...") or (line2 and line2.original == "..."): + lines_were_truncated = True + if line1 and line2 and line1.mnemonic == line2.mnemonic: + if index - last_mismatch >= 50: + max_index = index + else: + last_mismatch = index + if not lines_were_truncated: + max_index = None + + for index, (line1, line2) in enumerate(lines): + if max_index is not None and index > max_index: + break + if line1 and line2 and line1.mnemonic == line2.mnemonic: + diff_sameline(line1.scorable_line, line2.scorable_line) + else: + if line1: + diff_delete(line1.scorable_line) + if line2: + diff_insert(line2.scorable_line) + + insertions_co = Counter(insertions) + deletions_co = Counter(deletions) + for item in insertions_co + deletions_co: + ins = insertions_co[item] + dels = deletions_co[item] + common = min(ins, dels) + score += ( + (ins - common) * config.penalty_insertion + + (dels - common) * config.penalty_deletion + + config.penalty_reordering * common + ) + + return score + + +@dataclass(frozen=True) +class OutputLine: + base: Optional[Text] = field(compare=False) + fmt2: Text = field(compare=False) + key2: Optional[str] + boring: bool = field(compare=False) + is_data_ref: bool = field(compare=False) + line1: Optional[Line] = field(compare=False) + line2: Optional[Line] = field(compare=False) + + +@dataclass(frozen=True) +class Diff: + lines: List[OutputLine] + score: int + max_score: int + + +def trim_nops(lines: List[Line], arch: ArchSettings) -> List[Line]: + lines = lines[:] + while lines and lines[-1].mnemonic == "nop" and (len(lines) == 1 or lines[-2].mnemonic not in arch.delay_slot_instructions): + lines.pop() + return lines + +def do_diff(lines1: List[Line], lines2: List[Line], config: Config) -> Diff: + if config.show_source: + import cxxfilt + arch = config.arch + fmt = config.formatter + output: List[OutputLine] = [] + + sc1 = symbol_formatter("base-reg", 0) + sc2 = symbol_formatter("my-reg", 0) + sc3 = symbol_formatter("base-stack", 4) + sc4 = symbol_formatter("my-stack", 4) + sc5 = symbol_formatter("base-branch", 0) + sc6 = symbol_formatter("my-branch", 0) + bts1: Set[int] = set() + bts2: Set[int] = set() + + if config.show_branches: + for (lines, btset, sc) in [ + (lines1, bts1, sc5), + (lines2, bts2, sc6), + ]: + for line in lines: + bt = line.branch_target + if bt is not None: + btset.add(bt) + sc(str(bt)) + + lines1 = trim_nops(lines1, arch) + lines2 = trim_nops(lines2, arch) + + diffed_lines = diff_lines(lines1, lines2, config.algorithm) + score = score_diff_lines(diffed_lines, config) + max_score = len(lines1) * config.penalty_deletion + + line_num_base = -1 + line_num_offset = 0 + line_num_2to1 = {} + for (line1, line2) in diffed_lines: + if line1 is not None and line1.line_num is not None: + line_num_base = line1.line_num + line_num_offset = 0 + else: + line_num_offset += 1 + if line2 is not None and line2.line_num is not None: + line_num_2to1[line2.line_num] = (line_num_base, line_num_offset) + + for (line1, line2) in diffed_lines: + line_color1 = line_color2 = sym_color = BasicFormat.NONE + line_prefix = " " + is_data_ref = False + out1 = Text() if not line1 else Text(pad_mnemonic(line1.original)) + out2 = Text() if not line2 else Text(pad_mnemonic(line2.original)) + if line1 and line2 and line1.diff_row == line2.diff_row: + if line1.diff_row == "": + if line1.normalized_original != line2.normalized_original: + line_prefix = "i" + sym_color = BasicFormat.DIFF_CHANGE + out1 = out1.reformat(sym_color) + out2 = out2.reformat(sym_color) + is_data_ref = True + elif ( + line1.normalized_original == line2.normalized_original + and line2.branch_target is None + ): + # Fast path: no coloring needed. We don't include branch instructions + # in this case because we need to check that their targets line up in + # the diff, and don't just happen to have the are the same address + # by accident. + pass + elif line1.diff_row == "": + # Don't draw attention to differing branch-likely delay slots: they + # typically mirror the branch destination - 1 so the real difference + # is elsewhere. Still, do mark them as different to avoid confusion. + # No need to consider branches because delay slots can't branch. + out1 = out1.reformat(BasicFormat.DELAY_SLOT) + out2 = out2.reformat(BasicFormat.DELAY_SLOT) + else: + mnemonic = line1.original.split()[0] + branchless1, address1 = out1.plain(), "" + branchless2, address2 = out2.plain(), "" + if mnemonic in arch.instructions_with_address_immediates: + branchless1, address1 = split_off_address(branchless1) + branchless2, address2 = split_off_address(branchless2) + + out1 = Text(branchless1) + out2 = Text(branchless2) + out1, out2 = format_fields( + arch.re_imm, out1, out2, lambda _: BasicFormat.IMMEDIATE + ) + + if line2.branch_target is not None: + target = line2.branch_target + line2_target = line_num_2to1.get(line2.branch_target) + if line2_target is None: + # If the target is outside the disassembly, extrapolate. + # This only matters near the bottom. + assert line2.line_num is not None + line2_line = line_num_2to1[line2.line_num] + line2_target = (line2_line[0] + (target - line2.line_num), 0) + + # Set the key for three-way diffing to a normalized version. + norm2, norm_branch2 = split_off_address(line2.normalized_original) + if norm_branch2 != "": + line2.normalized_original = norm2 + str(line2_target) + same_target = line2_target == (line1.branch_target, 0) + else: + # Do a naive comparison for non-branches (e.g. function calls). + same_target = address1 == address2 + + if normalize_imms(branchless1, arch) == normalize_imms( + branchless2, arch + ): + if imm_matches_everything(branchless2, arch): + # ignore differences due to %lo(.rodata + ...) vs symbol + out1 = out1.reformat(BasicFormat.NONE) + out2 = out2.reformat(BasicFormat.NONE) + elif line2.branch_target is not None and same_target: + # same-target branch, don't color + pass + else: + # must have an imm difference (or else we would have hit the + # fast path) + sym_color = BasicFormat.IMMEDIATE + line_prefix = "i" + else: + out1, out2 = format_fields(arch.re_sprel, out1, out2, sc3, sc4) + if normalize_stack(branchless1, arch) == normalize_stack( + branchless2, arch + ): + # only stack differences (luckily stack and imm + # differences can't be combined in MIPS, so we + # don't have to think about that case) + sym_color = BasicFormat.STACK + line_prefix = "s" + else: + # reg differences and maybe imm as well + out1, out2 = format_fields(arch.re_reg, out1, out2, sc1, sc2) + line_color1 = line_color2 = sym_color = BasicFormat.REGISTER + line_prefix = "r" + + if same_target: + address_imm_fmt = BasicFormat.NONE + else: + address_imm_fmt = BasicFormat.IMMEDIATE + out1 += Text(address1, address_imm_fmt) + out2 += Text(address2, address_imm_fmt) + elif line1 and line2: + line_prefix = "|" + line_color1 = line_color2 = sym_color = BasicFormat.DIFF_CHANGE + out1 = out1.reformat(line_color1) + out2 = out2.reformat(line_color2) + elif line1: + line_prefix = "<" + line_color1 = sym_color = BasicFormat.DIFF_REMOVE + out1 = out1.reformat(line_color1) + out2 = Text() + elif line2: + line_prefix = ">" + line_color2 = sym_color = BasicFormat.DIFF_ADD + out1 = Text() + out2 = out2.reformat(line_color2) + + if config.show_source and line2 and line2.comment: + out2 += f" {line2.comment}" + + def format_part( + out: Text, + line: Optional[Line], + line_color: Format, + btset: Set[int], + sc: FormatFunction, + ) -> Optional[Text]: + if line is None: + return None + if line.line_num is None: + return out + in_arrow = Text(" ") + out_arrow = Text() + if config.show_branches: + if line.line_num in btset: + in_arrow = Text("~>", sc(str(line.line_num))) + if line.branch_target is not None: + out_arrow = " " + Text("~>", sc(str(line.branch_target))) + formatted_line_num = Text(hex(line.line_num)[2:] + ":", line_color) + return formatted_line_num + " " + in_arrow + " " + out + out_arrow + + part1 = format_part(out1, line1, line_color1, bts1, sc5) + part2 = format_part(out2, line2, line_color2, bts2, sc6) + + if config.show_source and line2: + for source_line in line2.source_lines: + line_format = BasicFormat.SOURCE_OTHER + if config.source_old_binutils: + if source_line and re.fullmatch(".*\.c(?:pp)?:\d+", source_line): + line_format = BasicFormat.SOURCE_FILENAME + elif source_line and source_line.endswith("():"): + line_format = BasicFormat.SOURCE_FUNCTION + try: + source_line = cxxfilt.demangle( + source_line[:-3], external_only=False + ) + except: + pass + else: + # File names and function names + if source_line and source_line[0] != "│": + line_format = BasicFormat.SOURCE_FILENAME + # Function names + if source_line.endswith("():"): + line_format = BasicFormat.SOURCE_FUNCTION + try: + source_line = cxxfilt.demangle( + source_line[:-3], external_only=False + ) + except: + pass + padding = " " * 7 if config.show_line_numbers else " " * 2 + output.append( + OutputLine( + base=None, + fmt2=padding + Text(source_line, line_format), + key2=source_line, + boring=True, + is_data_ref=False, + line1=None, + line2=None, + ) + ) + + key2 = line2.normalized_original if line2 else None + boring = False + if line_prefix == " ": + boring = True + elif config.compress and config.compress.same_instr and line_prefix in "irs": + boring = True + + if config.show_line_numbers: + if line2 and line2.source_line_num is not None: + num_color = ( + BasicFormat.SOURCE_LINE_NUM + if sym_color == BasicFormat.NONE + else sym_color + ) + num2 = Text(f"{line2.source_line_num:5}", num_color) + else: + num2 = Text(" " * 5) + else: + num2 = Text() + + fmt2 = Text(line_prefix, sym_color) + num2 + " " + (part2 or Text()) + + output.append( + OutputLine( + base=part1, + fmt2=fmt2, + key2=key2, + boring=boring, + is_data_ref=is_data_ref, + line1=line1, + line2=line2, + ) + ) + + output = output[config.skip_lines :] + return Diff(lines=output, score=score, max_score=max_score) + + +def chunk_diff_lines( + diff: List[OutputLine], +) -> List[Union[List[OutputLine], OutputLine]]: + """Chunk a diff into an alternating list like A B A B ... A, where: + * A is a List[OutputLine] of insertions, + * B is a single non-insertion OutputLine, with .base != None.""" + cur_right: List[OutputLine] = [] + chunks: List[Union[List[OutputLine], OutputLine]] = [] + for output_line in diff: + if output_line.base is not None: + chunks.append(cur_right) + chunks.append(output_line) + cur_right = [] + else: + cur_right.append(output_line) + chunks.append(cur_right) + return chunks + + +def compress_matching( + li: List[Tuple[OutputLine, ...]], context: int +) -> List[Tuple[OutputLine, ...]]: + ret: List[Tuple[OutputLine, ...]] = [] + matching_streak: List[Tuple[OutputLine, ...]] = [] + context = max(context, 0) + + def flush_matching() -> None: + if len(matching_streak) <= 2 * context + 1: + ret.extend(matching_streak) + else: + ret.extend(matching_streak[:context]) + skipped = len(matching_streak) - 2 * context + filler = OutputLine( + base=Text(f"<{skipped} lines>", BasicFormat.SOURCE_OTHER), + fmt2=Text(), + key2=None, + boring=False, + is_data_ref=False, + line1=None, + line2=None, + ) + columns = len(matching_streak[0]) + ret.append(tuple([filler] * columns)) + if context > 0: + ret.extend(matching_streak[-context:]) + matching_streak.clear() + + for line in li: + if line[0].boring: + matching_streak.append(line) + else: + flush_matching() + ret.append(line) + + flush_matching() + return ret + + +def align_diffs( + old_diff: Diff, new_diff: Diff, config: Config +) -> Tuple[TableMetadata, List[Tuple[OutputLine, ...]]]: + meta: TableMetadata + diff_lines: List[Tuple[OutputLine, ...]] + padding = " " * 7 if config.show_line_numbers else " " * 2 + + if config.threeway: + meta = TableMetadata( + headers=( + Text("TARGET"), + Text(f"{padding}CURRENT ({new_diff.score})"), + Text(f"{padding}PREVIOUS ({old_diff.score})"), + ), + current_score=new_diff.score, + max_score=new_diff.max_score, + previous_score=old_diff.score, + ) + old_chunks = chunk_diff_lines(old_diff.lines) + new_chunks = chunk_diff_lines(new_diff.lines) + diff_lines = [] + empty = OutputLine(Text(), Text(), None, True, False, None, None) + assert len(old_chunks) == len(new_chunks), "same target" + for old_chunk, new_chunk in zip(old_chunks, new_chunks): + if isinstance(old_chunk, list): + assert isinstance(new_chunk, list) + if not old_chunk and not new_chunk: + # Most of the time lines sync up without insertions/deletions, + # and there's no interdiffing to be done. + continue + differ = difflib.SequenceMatcher( + a=old_chunk, b=new_chunk, autojunk=False + ) + for (tag, i1, i2, j1, j2) in differ.get_opcodes(): + if tag in ["equal", "replace"]: + for i, j in zip(range(i1, i2), range(j1, j2)): + diff_lines.append((empty, new_chunk[j], old_chunk[i])) + if tag in ["insert", "replace"]: + for j in range(j1 + i2 - i1, j2): + diff_lines.append((empty, new_chunk[j], empty)) + if tag in ["delete", "replace"]: + for i in range(i1 + j2 - j1, i2): + diff_lines.append((empty, empty, old_chunk[i])) + else: + assert isinstance(new_chunk, OutputLine) + # old_chunk.base and new_chunk.base have the same text since + # both diffs are based on the same target, but they might + # differ in color. Use the new version. + diff_lines.append((new_chunk, new_chunk, old_chunk)) + diff_lines = [ + (base, new, old if old != new else empty) for base, new, old in diff_lines + ] + else: + meta = TableMetadata( + headers=( + Text("TARGET"), + Text(f"{padding}CURRENT ({new_diff.score})"), + ), + current_score=new_diff.score, + max_score=new_diff.max_score, + previous_score=None, + ) + diff_lines = [(line, line) for line in new_diff.lines] + if config.compress: + diff_lines = compress_matching(diff_lines, config.compress.context) + return meta, diff_lines + + +def debounced_fs_watch( + targets: List[str], + outq: "queue.Queue[Optional[float]]", + config: Config, + project: ProjectSettings, +) -> None: + import watchdog.events + import watchdog.observers + + class WatchEventHandler(watchdog.events.FileSystemEventHandler): + def __init__( + self, queue: "queue.Queue[float]", file_targets: List[str] + ) -> None: + self.queue = queue + self.file_targets = file_targets + + def on_modified(self, ev: object) -> None: + if isinstance(ev, watchdog.events.FileModifiedEvent): + self.changed(ev.src_path) + + def on_moved(self, ev: object) -> None: + if isinstance(ev, watchdog.events.FileMovedEvent): + self.changed(ev.dest_path) + + def should_notify(self, path: str) -> bool: + for target in self.file_targets: + if os.path.normpath(path) == target: + return True + if config.make and any( + path.endswith(suffix) for suffix in project.source_extensions + ): + return True + return False + + def changed(self, path: str) -> None: + if self.should_notify(path): + self.queue.put(time.time()) + + def debounce_thread() -> NoReturn: + listenq: "queue.Queue[float]" = queue.Queue() + file_targets: List[str] = [] + event_handler = WatchEventHandler(listenq, file_targets) + observer = watchdog.observers.Observer() + observed = set() + for target in targets: + if os.path.isdir(target): + observer.schedule(event_handler, target, recursive=True) + else: + file_targets.append(os.path.normpath(target)) + target = os.path.dirname(target) or "." + if target not in observed: + observed.add(target) + observer.schedule(event_handler, target) + observer.start() + while True: + t = listenq.get() + more = True + while more: + delay = t + DEBOUNCE_DELAY - time.time() + if delay > 0: + time.sleep(delay) + # consume entire queue + more = False + try: + while True: + t = listenq.get(block=False) + more = True + except queue.Empty: + pass + outq.put(t) + + th = threading.Thread(target=debounce_thread, daemon=True) + th.start() + + +class Display: + basedump: str + mydump: str + last_refresh_key: object + config: Config + emsg: Optional[str] + last_diff_output: Optional[Diff] + pending_update: Optional[str] + ready_queue: "queue.Queue[None]" + watch_queue: "queue.Queue[Optional[float]]" + less_proc: "Optional[subprocess.Popen[bytes]]" + + def __init__(self, basedump: str, mydump: str, config: Config) -> None: + self.config = config + self.base_lines = process(basedump, config) + self.mydump = mydump + self.emsg = None + self.last_refresh_key = None + self.last_diff_output = None + + def run_diff(self) -> Tuple[str, object]: + if self.emsg is not None: + return (self.emsg, self.emsg) + + my_lines = process(self.mydump, self.config) + diff_output = do_diff(self.base_lines, my_lines, self.config) + last_diff_output = self.last_diff_output or diff_output + if self.config.threeway != "base" or not self.last_diff_output: + self.last_diff_output = diff_output + + meta, diff_lines = align_diffs(last_diff_output, diff_output, self.config) + output = self.config.formatter.table(meta, diff_lines) + refresh_key = ( + [line.key2 for line in diff_output.lines], + diff_output.score, + ) + return (output, refresh_key) + + def run_less( + self, output: str + ) -> "Tuple[subprocess.Popen[bytes], subprocess.Popen[bytes]]": + # Pipe the output through 'tail' and only then to less, to ensure the + # write call doesn't block. ('tail' has to buffer all its input before + # it starts writing.) This also means we don't have to deal with pipe + # closure errors. + buffer_proc = subprocess.Popen( + BUFFER_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE + ) + less_proc = subprocess.Popen(LESS_CMD, stdin=buffer_proc.stdout) + assert buffer_proc.stdin + assert buffer_proc.stdout + buffer_proc.stdin.write(output.encode()) + buffer_proc.stdin.close() + buffer_proc.stdout.close() + return (buffer_proc, less_proc) + + def run_sync(self) -> None: + output, _ = self.run_diff() + proca, procb = self.run_less(output) + procb.wait() + proca.wait() + + def run_async(self, watch_queue: "queue.Queue[Optional[float]]") -> None: + self.watch_queue = watch_queue + self.ready_queue = queue.Queue() + self.pending_update = None + output, refresh_key = self.run_diff() + self.last_refresh_key = refresh_key + dthread = threading.Thread(target=self.display_thread, args=(output,)) + dthread.start() + self.ready_queue.get() + + def display_thread(self, initial_output: str) -> None: + proca, procb = self.run_less(initial_output) + self.less_proc = procb + self.ready_queue.put(None) + while True: + ret = procb.wait() + proca.wait() + self.less_proc = None + if ret != 0: + # fix the terminal + os.system("tput reset") + if ret != 0 and self.pending_update is not None: + # killed by program with the intent to refresh + output = self.pending_update + self.pending_update = None + proca, procb = self.run_less(output) + self.less_proc = procb + self.ready_queue.put(None) + else: + # terminated by user, or killed + self.watch_queue.put(None) + self.ready_queue.put(None) + break + + def progress(self, msg: str) -> None: + # Write message to top-left corner + sys.stdout.write("\x1b7\x1b[1;1f{}\x1b8".format(msg + " ")) + sys.stdout.flush() + + def update(self, text: str, error: bool) -> None: + if not error and not self.emsg and text == self.mydump: + self.progress("Unchanged. ") + return + if not error: + self.mydump = text + self.emsg = None + else: + self.emsg = text + output, refresh_key = self.run_diff() + if refresh_key == self.last_refresh_key: + self.progress("Unchanged. ") + return + self.last_refresh_key = refresh_key + self.pending_update = output + if not self.less_proc: + return + self.less_proc.kill() + self.ready_queue.get() + + def terminate(self) -> None: + if not self.less_proc: + return + self.less_proc.kill() + self.ready_queue.get() + + +def main() -> None: + args = parser.parse_args() + + # Apply project-specific configuration. + settings: Dict[str, Any] = {} + diff_settings.apply(settings, args) # type: ignore + project = create_project_settings(settings) + + try: + config = create_config(args, project) + except ValueError as e: + fail(str(e)) + + if config.algorithm == "levenshtein": + try: + import Levenshtein + except ModuleNotFoundError as e: + fail(MISSING_PREREQUISITES.format(e.name)) + + if config.show_source: + try: + import cxxfilt + except ModuleNotFoundError as e: + fail(MISSING_PREREQUISITES.format(e.name)) + + if config.threeway and not args.watch: + fail("Threeway diffing requires -w.") + + if args.diff_elf_symbol: + make_target, basecmd, mycmd = dump_elf( + args.start, args.end, args.diff_elf_symbol, config, project + ) + elif config.diff_obj: + make_target, basecmd, mycmd = dump_objfile( + args.start, args.end, config, project + ) + else: + make_target, basecmd, mycmd = dump_binary(args.start, args.end, config, project) + + map_build_target_fn = getattr(diff_settings, "map_build_target", None) + if map_build_target_fn: + make_target = map_build_target_fn(make_target=make_target) + + if args.write_asm is not None: + mydump = run_objdump(mycmd, config, project) + with open(args.write_asm, "w") as f: + f.write(mydump) + print(f"Wrote assembly to {args.write_asm}.") + sys.exit(0) + + if args.base_asm is not None: + with open(args.base_asm) as f: + basedump = f.read() + else: + basedump = run_objdump(basecmd, config, project) + + mydump = run_objdump(mycmd, config, project) + + display = Display(basedump, mydump, config) + + if args.no_pager or args.format in ("html", "json"): + print(display.run_diff()[0]) + elif not args.watch: + display.run_sync() + else: + if not args.make: + yn = input( + "Warning: watch-mode (-w) enabled without auto-make (-m). " + "You will have to run make manually. Ok? (Y/n) " + ) + if yn.lower() == "n": + return + if args.make: + watch_sources = None + watch_sources_for_target_fn = getattr( + diff_settings, "watch_sources_for_target", None + ) + if watch_sources_for_target_fn: + watch_sources = watch_sources_for_target_fn(make_target) + watch_sources = watch_sources or project.source_directories + if not watch_sources: + fail("Missing source_directories config, don't know what to watch.") + else: + watch_sources = [make_target] + q: "queue.Queue[Optional[float]]" = queue.Queue() + debounced_fs_watch(watch_sources, q, config, project) + display.run_async(q) + last_build = 0.0 + try: + while True: + t = q.get() + if t is None: + break + if t < last_build: + continue + last_build = time.time() + if args.make: + display.progress("Building...") + ret = run_make_capture_output(make_target, project) + if ret.returncode != 0: + display.update( + ret.stderr.decode("utf-8-sig", "replace") + or ret.stdout.decode("utf-8-sig", "replace"), + error=True, + ) + continue + mydump = run_objdump(mycmd, config, project) + display.update(mydump, error=False) + except KeyboardInterrupt: + display.terminate() + + +if __name__ == "__main__": + main() diff --git a/lib/ultralib/tools/asm_differ/diff_settings.py b/lib/ultralib/tools/asm_differ/diff_settings.py new file mode 100644 index 0000000..183b96b --- /dev/null +++ b/lib/ultralib/tools/asm_differ/diff_settings.py @@ -0,0 +1,11 @@ +def apply(config, args): + config["baseimg"] = "target.bin" + config["myimg"] = "source.bin" + config["mapfile"] = "build.map" + config["source_directories"] = ["."] + # config["show_line_numbers_default"] = True + # config["arch"] = "mips" + # config["map_format"] = "gnu" # gnu or mw + # config["mw_build_dir"] = "build/" # only needed for mw map format + # config["makeflags"] = [] + # config["objdump_executable"] = "" diff --git a/lib/ultralib/tools/asm_differ/mypy.ini b/lib/ultralib/tools/asm_differ/mypy.ini new file mode 100644 index 0000000..138b939 --- /dev/null +++ b/lib/ultralib/tools/asm_differ/mypy.ini @@ -0,0 +1,17 @@ +[mypy] +check_untyped_defs = True +disallow_any_generics = True +disallow_incomplete_defs = True +disallow_untyped_calls = True +disallow_untyped_decorators = True +disallow_untyped_defs = True +no_implicit_optional = True +warn_redundant_casts = True +warn_return_any = True +warn_unused_ignores = True +ignore_missing_imports = True +python_version = 3.6 +files = diff.py + +[mypy-diff_settings] +ignore_errors = True diff --git a/lib/ultralib/tools/asm_differ/screenshot.png b/lib/ultralib/tools/asm_differ/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..3230555328cd9acdf388ce1626415ceb78760535 GIT binary patch literal 99842 zcmd431yG#Zx~@w?g1b9Gg1b8j?(Ul4?yezdaCdiicXxMpXxtjt+nIC8T?|I+RzvN^@;bCxKz`(%Z#l?gaz`)*jgWgV15TGr};=9eDAJ8^p z>h@q@2))1G@8YNtaKXSnfr$%!RdPu^S#woWo_ig*yyF8fki`5Th6sk)PK;JWNis|Z zsu^+aDCNg#=!G|=0-dGpsRFN!*d=R5V@HWtjq$!zFb{tE^mFtRRO-tUcq%diOwffV zZ^T4S^`iOdq5b%}ds!X2tgI|Lksp!(6cH8H*o@VW-y=UH*`6J5CQL_(Z*_qu*{tga7bR<#a{)OOf4fWVsTgfN-|O~^HU_AgLGLcgL@F$H4n zWr;G-r0}(Es%!V>?c=6wf1ONQ`%w_<1L{LxpY?I@Q-aQ`neWb-rQz3gs#AUH&UsU< zY)xdWjZP#W(P)lq3pRdOxv<-GjZ?%dMuI)7(gO+PE$QRg!DbZbrc6Ovt=^Fq766-5)c zGoJ(ITpZQBar&%xo?I~-vuyJnJBZ*?jigQ@u}@?ogV3@)qEfx%#l}N|r64mG?-`8F zC|c7jt0s+N&^*JzapP;uL>btv30uhMTA6lvAKR9Z$Y&$&h6d2+Y>bJ=mZsGoa5s;2HN!v8s<;Ip1Pf~_@MNjk&d(l7Sf(N7P_`YCW+gYaKmom&3px9qBtjw3|*?;4C zWYSRGs%><_9@!+@vPfgbZQ1gw9dAhe97l8AtHUX3V!}u0`Y2W}g)=yRVqpgc^@(8# zyTX-TaYA|I>_d|(sgQU~Dt+Q^E9jyoI)Is(F}N?#8#r6M#|}oXTZaGM8>l!KbYZx+ zWFc2-%4&qLqa(Fjac)$@qY-EyBh#wN){174%ry zAqm9t3_bi5842voGw*BplO2k@d(jWyeuN{uoyPw$4`s@$wLCykf6TeBCMWjPzM z%;z6e7*CsAvzNXpNt)f;I+bb;H+x3iZG0TgDY@m+4`3xfTljS^I7TWLRB1HU(Z zcp=R2bPm{VtswGqVfo{lV~W`6#Hw<|7CWS}pz0RHc)XngJ_zMzS9$roDh95$b*p|w zq)2{m^ou2Tw9Oy(K1l~rqilZCk-}CTnLCkx8!9EaE=xK^^?Fm6<1LCdA&rsbu6}vZ$nN3VBk^*_{vTVn6%)|Ofsb!l z-*oP1^F5~!k3DN19EQGb@0und49n(;=)6EeiR zlh&o_FGPZ(o|0;5UT~(mr&Fkd)XGI0nJ|x)-?~F^KIEw+NSN(%%0NP(pkay0O>$;W z2XFC3WM6#KN9QK&m-571d0|efRqK`yQuxeijWy)jBR(EtCmZvZzC4o6}C?EOp=3f`~j66SNK z#;z<<$zn6Qs?!WPyIE2h0xrRMcWcJ|H3KjBP(j@yx?3CDj;;G`S;^`WMZdxlosn?rLJheNxys8Q zPKs6=j$^7Jcn6;C7;TxGO38>&4YAW9A*H3?*-)p=Q1gG6$fkec4&SV4pq(Gije6=GAa zLLusT?mQz}LF+S#H+lJY5*k(8Id^*^zRg;|9^GOICQy+X2xWW+ zJU5l{#Xfg}3w-33rRTArnXJ3Y^4UYkR-B!#82O^HkS?XWikPq>%aF!rIAl(BsmVW< zb}Pm>&}s*-W403IT%z$kHco1EFXov=AD(~Xj6HvGXG{KLS{pMVy{Y@gRZY0p5O>Ur z>+Z}KqTZN)%+r-wyVKZKacHABdkz z z1OUA2+f#o)ph6FB9W$7AY&~OQ^j%ruo`G^MYVCbEp(GD?tM~w*glB3_-Ij17 zPeeaNa)%8rjTvzxe;y?|TTOf%SImy@O*bx;o*)`%7!9gp6RJ5L*qk2k-#oX6AkqI6 zG5L@7aU;rK%*-7OyKCj|InW&*sS-IGG6&pe)GCie*{sq93x)#-kCx3&u{vy!?J?<$ z>=u%-_GoA3jZu!<@x=v!*|m$4o>_fOA%q#N-+Ry0GcInr8i~WW=+<`tLveMtt0Rj| zw1gGw!_GN4JgxlKQzywUlp!*Ula|xuwe%MpsM#i@0C*D4jE?H~62mgyyXaK!+k?ph z8(x}^u}U}wJcrv#D6h$V?y9MS2#EW?Fz=)o`}1C0@)7LGAJ0$kE0(+G7S*!hz2d?V zCeB`pkQu@d-^_+jgsr!409xURbw-O98hD8vku!%p*H(9;%oe&7ak_?!nU7j;5Bl+h z;q;HQ+dm1t0J6PyE9B0>zzMH3ztiEbQi~q&7F<_- zh=eEIW*dVTYk zB=@W=Kt`%*J!5O>>9`MeC_7>-rs8`N^|d%m(aVq>yFHmty1HhwE?6U8I1xE{5_Y|m zPNh1dccOYjM0ZtD-=740%>xNs3{Umv`$Hbismpk!H}J-Pgpb+Ou=|DzmHX@Jy){30 zc(+2?tC-K|knBi23IufUJEQlgMO13DJy^>51M ztgPkx`U4s5MYm2ZLj2iMau4kB7AsSgxqmj9e$%J%AgghThUD&t-%oj4Yfs6{>gSex zXmAr{;Fm-@@xs6a_iKxvXbt8k!u{d03ahU}*or?cY@&U8bd(#;4;2 z{LMIMUe~f^J~ojf__b~U9_-&!Dd_b8Q@EIJRy5@PaCb42Xlh}~?4_d<6brtDd4KMg zWl=E`h>eV~PZwE+yQ>`IvgUWF_9HM8R_(3Khp1L?Z+>Nr z#amATJH4>9=8{7aNxm_%{17sUVXlu*ujg`B zSS3YWC)yp6YgNz&6e_c3?0(3EGDIZZ330~o?n3ciSD$>a*IOsM!<64z5?c^i$7@ZL zeM3?C?T(DBI0cUsEO2MCRzeC_5^AZG|=5AWY`VnN&$A1?k*bZt1(gf zqvARNpEv37bXk%WO%dPfUyq<~@!&Qwkg$w|V;p--r+S0=pJU|U*Dy6ySG7J_h%%@@ zJgZd!x5i}Ve%)X4wm(yno+CuD;$N>-(mHsasmtuKwayJCQ6C4^*w}M$cK%ZQj-{;I zwPIbj1<17Q-B^b)Zm4#WT-OdmRh?`qH;{`+P<}vnDjc5|0#l(I8(XK zgeU=fw9m#L)2uo3b3pYRxQvp?AJ^~G@9S4eCA)){j?*_v;4T?ANV2l%%!G^%1^tqI zG}e)4y^^1Zf1h$KknrB@grDZ+f-s&c&g6D$Arx+T^xP6qZPfai{noqZ#1Qi8)H#<- z$evbP5MGlSEgFs=J8X<`p(wXtZS>B$mX){25^W?sW=qx~+RS{mPa3nQytA++V!)0V z8ZI>J&HSv50B_=NhjvjUz7tYuGFcIy0<&(uQ0RlYm|O zw`ia+DW|RxR^yBEwcDgw9Yh>$27zZ?!M;IM8I@9Xv$53|PrQYlYpkWkZ}PdE3TQMb z2;X;sKBZh+B7_lN_S@cAzn2BfJ5+M!4RBcbl&g*4UG zN@&dXqXaz3{}j&$LtY`HQs{lvDDiuy(XE;djd_XsQM${9B1jk?Cs<1-(hkWTC$==S z1vMO4#Dxbj`?8_IH>`(~@=7?2kAh6^g@2;b*%5UI6e9$9d|6vK_<1KRgGIEpd8C6I z^X!F(-LG7{slL$lA$1Zt|be?VA?tucJ<*ca6_vI$k9 zrz>Frd$9j)M?l>Huhn@87l}Ps&);Kfv4WhT+I$gws$Or|;&K-*7Ij2r)NeKGqzsMt zYg0Z&BxnGnSU(Lt2#Aeif)EAM&RJeTvWSoxUUGPv%Tt}p`)MlqI7thBERpc!-XTHb zLAP_-{??Sy3Lo18>bX9ho*r&FX@G&g~HU^GopaZ_)-w?M{WTADp=;v@^M z#vOjA>6kc5U7Rf=g3)n1_3rM68vB*E13o<@!uGhqM}10;Hn!+-8Px~r;Cf#)8XCM3=1-yM6*`;v986Y&NGwlheuuapE%(k?CG6e4cvDhiR!)lWP%vw}r;xb1!#sIiFMp zI^ChJ7E9e`P#a*O1raQ4i5Ge$-uZJmrbQHbsop;`{rs}a#DCPcX3_C9{f1sb+n=#M zOM?|Rly$C>?R{DtYB{UIkW`b%ZdfSfSsaC$TU}O?D?kT!B*5c3{Wv1jN7HFtIKPJvkbI3LN+^{4pP&a>AUW* zK*|W)!p6nI4sayw36#)TPc=A0;%Ej`c~0TI+A|&c3=qJC^Z8<*Xya2G<9BJ^B1JcR zAH{iMs*`0ZX}|xq2{+h8FjltzaWjM9lk?f_kSAV#UUUt&)lKqLmL%qK z+bmSzY>dV89nULnB0H3@^wx9{wTZbaP$VM#`e5CEp>>ThqNDrJw}k`6%*6dFS2R*> z&r!!YLLZnw&4J-PkD2c0vR}bnoql z$!rl{m7lTCpWtQh`ZzRFTgLUa3XkwI*ux*(%h6p#MT@3=UCkk4I11>Q@35Izgs`Nl zavl;tN_idPj0|}6*Nc8AN6J2lNyU5sH6He7O(ZlDzM%HV?bbbEd@PLPey-zzq?N^O z4^!y#-nOlPjC2h#Idwg6@&I zYjN46?amN=z}2BS=QF1{1b_Un2|SUIc;ugZi!petRmj)i*wXU|cSJR+1}Gq}FDgdQ zeh8<2EVv^f#Dz{444~RN5r*(Rg@X%YV-v#^kfGwb#ol<~ zE;{5xDUv`F4dV^DM$v<&9`R<8Kf1Ia81a2uj6awzdb9`fKS$+IXy!+E1QG+u{hyV5 zC>@(0r`Kwt-=S8+68TX$MFRzRFdm4t)+y^*+`ajjA#1baW0Z$JB=%z@^jl(a856Wi zmwhJnN6KaawUw8PyCF8%Mp`-4%wDTq^LZ~euD$70jiDF-Ixml_0OS^9&+Y}t9SNh@ zV!mYU8h*nmXxwJ$N55McJ2hw`Kce4lW%I5WU5>-J^(MPH80$@hm#pGygTYqs4vQNo`J8!v<Iy!dJAbL_Hm@Y~)hQ3F z@kQ@{RMMj(Fj`qwwm=94blq(gn);OLI{#25yWXucds@Vzv>rvyE{*&rjLqz+d1K)- z!S4$&ROG}-3h(bGFfO1WW(HH*-r3HIr&WO=#ZgzB(-9OmQ#cb4l`Q{bVi|n!^@d{%kwY_;dc85NSM*roxT%wZW{y1 zf%pRkeU|D*!jeOOh99IV4Rd1177YEY!&gbTy}Q>aqzM!djQbNMi$MM-vRVR0b-0i% zUhB|3)s1qj0?#;oU~*E;FYkD(!6C-M8tbZmY;94wg~kR z4o0l67~MB;{p=oV@xCk8u+^FZVLS_Nw$@&*+2|NEJy8h%;Y0at+;Wc*%Sb zqQW`GJm7bPsuxxZb*(|TUtGybx+hsj1!9!VWhp~cJJ<`x!=?AOlldns5ma=SIZW4} zolvW1My6YfVbpH`3x4W+jC}@|1KBQ8L?nzaS?z`bK?S0Auh8P-8#T0~0O5zM7GT2( zsQ|)@$Y9pS{cDrXv-uE1Kt0Yc|L2{wBF; zDmO@?KegJ6D?I-x>=-;m8Y^SNEb&K!$E?0koX1n%uAIJ|G*=Hbb3|sojlm|NxlAUo zT|Z5Iew(C!f&f+*`pxy$0Hi( z{2Rv#L6WhYFvC=gqJDtTCHXvp_2fpdh`UD2M9JHrBtwxxTB zpHpq?c8LEtCv9*Z+P3OK@fDq>ZFzE(CvoiEf+3hcl3~E^Giprg1PLeoFeZL5rACef z%NbAnS$G@+SxoG)D%A6LGHPe?U4mURssuW%&nv7!rvuYp{Ciez?Q?|T>9pKzgiJr? zMi`8w(pTcWBCHLJbuUaOriLm-TWfv#^w>3^4C9opF$(L@YbDxb>(L>Z~tUoFf{g*@gk=;T?yi6e!L%Kjt5H{kYiCF zpBEeU*!@0r){aK{rCBQ-1Z zqOo&9AIk`h4@3m2ab1F_+pDD zJTMy75`v6w;FYK@Lut{HKCL|98N#auLQe7R+W{p<`z!Pt&gJ_e}q|E33JFwKW+kVO2;Tswz@sdCpQJyi}EL-w*K>vDP~pX3L)44AB^-HhNur`YG(5 zjN+dSh?!+wuw%tYE#?HrcP|kZpGYmx&*(kHXCUS#2@vU~Q@qeZMBtK{utqits(Za) zVtCIVvgX4O+ETjsYm!>5=!dBA_%j4=SWyoj0&rUv*2*RS3K`pJ3nyzGO$SDxb2F3VpU2 zSw_I!gHYWb0sfL(ynT0VE2KNp-F_I-n3Az)(HuNp#CKLdq{Tz1-MgT@yv4h(*ecjz zv>JhF>-FYCxH6lQUXxzKpVnQygGqz?t$QM4oOrV}UFGITFYiN4=6f7+9TRomSrT)O z^z$8R@OfCpVs;aOv0UB6x(kLP5oMFvB7Sh=@xFO$IBMAqk8er;&d(e`B@W~VfF5O1lsJW(5lhbdOk=*(XESZ*h2oX&6J!&;X=tQyA{UJQrylC(Q`mR zao>Xv3eL*#B86#c*hFu(ymD!ov`y{cW^Y&u1wmZZ)E5DSOvk>lkKIlmVs09b<3tJF zeSXAzU48#k#;(r6)y?EGF>%2GYqNHSGGVcM@f5N zQO(Ll2b~bw=t*jk9>z%3X$wb2Y4#Cq;foz)GM5>Axp4yC`gzOlXO zsT#zMcf{P=2>JWJgD#KWxn`o{INiG6mT*^LJ!JVqS#q+7S#ofaf0M%(%EYUQuw3_!?Xu%3TM z=+3Q^d{3fTZwa`w>|ibl;cZ?9S8sM@vtFb;K(&f2)c9s>9FQ$bLdWKB(TCSEY*Yw+ zNxI%{YEPYZP4jU?0wW@IKY#LOIN`Tde1-VsZ%FDo@G%~mD4pPs|BnqxI~^rF=ZMQc zL`VP85+RerY=ht2;Xvf=oE#V{WoV@k>%v6zoJ?l55k*2n_~4UL z=dFCHmdiL@$U(`%`8BHI44nAN0XqyQils8>Y~M36FBG)B`&B8P%&7mX`H5gfVp?yeuecZA4xMA@jg~;tg(4nYY1d_sr8@XG@cG*F%la%Hc%dRbg1=dB#&O$pJ$| z#qfvm+gz~rBUq%)rn~PR@0e`VU?R_hfE(T29~w`SDV?&)dJ88?N#HzFmW=J1;`oKF z@=ywT4kSk=Kps8FHlAkvgE9yxiT!hQC9L)bg-{X$naad+r9~U=6!_*i334CvXAh4g zohKwdGm8m=oM+IJ?e9VZ`lD7w3)9f`$} zh~d-94E9zsfmZkzw^zM$bg``MUeC50=09pdSADD-8R6v311|(5CsxID)0j{Bo}#PZ z1@9kyDM68(SuTN~D{(s=P{4(d$y0-I>RHVmguocdbJ5ynRh&e?D4;cvyXT47PFNc*rAP&QgX{-xwt@Y-PT8~aK{5n| znm~6M6l&_r1;K(B}Rxz_~oj+b}&w%h*ktYW;?0Xszx+SRz#I{8Z0lYYtK z9Sr7M-xb1&Ckqw5A;wcf$~Lf6(%T<8nUtdu&$k!HhH6dDI`hXEnGTzg41fOpR6zNx z|1~0ZO6;bWQ{kJ&>xAPklwnKrH29O%cc7-M8rn z@r$J5$7tCqx9Nz~4$q>B|H=d$bPtJ|M`y=`T0xeYk155>jA;APIrPcu-B)sfZi0veq=Yj_`t3#Gmg+RA$%+<8j*zEV17PT2 zCRO_UqQUYjKAb~CZ8}$3FqGwt<*vGKv5Kl5TJ@LLtYV5?R^_SU^K7jz4L)-+v?503 zRx9cYU^H9Sk^~Hm+5Lo8nK;5ie`5&f=a;(Id8Z3JHl)_5vkYE3^~XxlFIN)sne0| zGwp_R3E(CsaqjiILIKFa=&7q3o7!*h`7JpjTAU?UOH}seo)GIXQh7cSKB-i)7b z-)%VCcje%>rEu8pNKlxfXZgy#TPYAKqADg}Np97S!~Uv<#didh?kV)vfQwQ|9Q1S>>vQ}u^M5WL)@kn0K%D#k z8y0fysEFrcd&2XqGotsj>S~c-gC?N#2a4d{MIXtN`mcn;<)-^dNJ+SXo?t}vx;1#p zc&r@00MunD$O_qBBGM-LBRVGJPx{Z1uAl$!C^~4Ht{?ULzU0TY!0D=dTWIBP5^3e_ z4tJ$WSEv&pufhe?RUt(Pw?id3|4a6Z>0N$RU!E;)z<5%iwW2w+ILOwJ{>@F;uxV7a zVkKrz*`kr#G!;iwh=}gNI%u@}vg zzCveQwqTpEP%^}RVTlHBtMheYpz8j@m!DpQ%Xr!I_Om{2z{L%u;zdM!k)t2d-X9E{ z!ujt&CfySz{FI#8+d)vTo<_f~pCotwsQU+>m+-SekxK0wBD6@1k9| zfX!UWY1<*w%m0|pG5vRU#clMaS^9qqL-_HYle)CvR9&+2VKww9I_@I;TtJH|{vRok zagXE@xoMaczPsW5>E$Z8qc?(*w*+q*YyoNR!D+^vBnHEGxZ~VY-s3cnvutjKsYRNq zd@20N$zR_FLeIx-HXK{3IQO~Yu4_{w8a3#L-PT%y{{cgmJ#c0JWFb=G#6n3#oVpA{ z4^OJ{pxTP}e<(=eP0pVSDk@KNWE;O`oB5=rVF&YtH7=r6quZZQrDT!y#;DEWQkvmZ zWnpsK_hy{GvPPU9f|spP2O1>19NXfQQd(TJ9Io&wr6B(%+A7g8F^_ zYPj(J!*KbH&+b@dK*x^te~vyTZ^d~Amc-!G$CAG#CC~;NqPFs|Xz{v-?~*U^6$ckX zhV7q~E1Y;>G2dug+)WrvZ~OM{-Mx!L6%pfTY+mT!Wn7@vl~6unFZ{_zlX&rb#QJxz zF%+(YA%K?lH?WcLUxJNw4+hRGt@i93b6ED*J^Y&8BM-m64c03F>+~w|9N11g%=Z1_kdUg;(?|?aF+V*DL4F>V`j6c|`dr~}Xfw2?`PQ3D&gwt$Rlw5U6{ozgi z32wWi*++Ok2D@6iNv8~CQoV-Wy#xS1v+b&Y%B4CDo^sj_u%FR;qAq)FP9E>D{u{m^ zs?p37uMo93H=%`^^hwi3@9o}kg)r#NXBVhIPgYXS~fId z?U<7nq8>Gp$jhIa*I{Asb%SeS{GFMGe>1Iy+(0uLLeX?-3E02q<-=L};*HKHjQ4-2 z%-U5`O+#yVoL2SL^rSd=v=5{5qEJSiD&nxzH?mmuOmYG*EU9#Lgx-NNd!pJOLGZWi zHkN6~)tA@592q7*oQ^|XL-D0)ctYwg(f8URw9!<}$(=S+8nqh|T=t19#l37ouRQsL zdJXP=dad47|B$5BIx-R0k=mQ2-ezmj=}ElV-4_qm;e@Cj@{0|i{~@z`h;I-57~(-5QtkVAQ3pE`wMvaETyBy3+w>$3##mupaQ9!zl0X zM|lyV&!jJEc5rbzmks-2>T$2CXhiRZTEP#n>n&yN30TVxb7Y z&r|Y>`|f*W{{o0m_u^I7dBON!~FO zz=0q=63(~lV~_=a0XjKQ^<&5Xp|{hM*pzeORNp6%BCT-EiD02NUX0(h+S)cHrR8Ec z=zi^9Mb?3mq4TGGbA#TZpsl!!L2oFc% zyS8HyK9AdDQVUfCz3zSUJZ|r-a^#$OFLCyP)siBqt7Zu^jcO&DIk zUXJ&HFPFrleWr5mUyi3zCRDw?Xd5##Wlvn(JsOs-qYt0bnoYXOL&0VYm8R`>h1>c* z?0YwylbIA=jw`gE;diAv8(qmZe|MyePj9`nLew$a?XnNASJTAFF(S2bJ0+J|!t)`Z zE!Xa6Y82J=nxrIS3_dzSx)=(`>Xg(+gherZ^>QWS)CC)I1;-%ge4~g4 zPO#zsNX8jmzkyxCPx%s{CtT(vh;_Mz#zgF)?#hOXX08#I)YFKG`f%K`L=!Q;wVI1+ zJ=b9@4iPIKb9Z&VRlqp2IBoRY+8WalI?~?hO%7-1p2jztxELE_PgX-oddD&%KEk~f zD^Yv2_UlM}>Rw7mlHVP*T94lDAi-Mw)H}&RaNy23!}!CjR82P5Dc5ZCbg$9BjIm4i)N`VS%&Zm5v5x$ zW?txtGn38;Gc6Q&S`CqJT4EnkFtHh`aKp4mA6{MTF6$xXYO%G}s}sYbI5{4!^*8;N z5(^?W-w^f!Y_kCV@1|u5NEv!kFf|&hj=VAL@3Q)nFv`p#ZMQ{b)<$WK#kBuJxM){I z6M^V>fZ^U9UHN!?^SghY%;$#-y70ABsgQjHi)B2LnB4^ZXyETz#&6f-D=8quvPqky znuN2C{%YJ?2Zk+6K813&1Q2A$27{-Q<&KLxUV$@^y^$^NvqOHva#<5FT=m}x5wWK#GbspCXo9zPwA&wk z+@e{cAR>BgQQ@yy=w7lmu!M&vVhY=XJVRz!;Qlscd?Bx+b?+r85B4{8D>DkaS zAZuF(xK-h3iL2ARI#Wt({5kIU+1IUgbh)PkwLsy(_4{DFf+F~$H?i+!nNDv1a>xh3 zkN&>E1hYKb>kiQ-p!#Mjb6-N=CrI85*;#{=<@6z;k zg4syRIF7b6eU;PS_Y;qmrf017-91dq-4s?R;(5t? zG7d;t3wb#op0nM;YK-+JYfJn?Ft)2<`RU=f#{b)Kd8O9Wm{f13KUN5ka=uB;{D=H{ zYe6iG+m|Uc293E$raKI}O=CA+lR6DwmCS3NM;NKGA!1GCLIcMM56?%A@_|Ff>Z-2n zLGWP761tBg`GQyv9-m5N8m9(GB3;kDrPWHdt_zLtIfg}5T_-gD8L8i6{ad15{+pcp z)f4S!_F$#XOknpH(|6uivI34CI+tIJwKAM4ctvOFyk#~Hb5%SX(UbH7{F4Mk+__BTgUyXxXS0kM zi+^~D0(&P=?E^;i(4HO$K&}~0O|##RVP-ZSSFip~KOmdFdGM;A8<%P+RUZ@hs}5o+ z%YG+BhIwnyc$})sLPdU+*M`4?wM4|u?zGWAU|TVTteu)NONen(MgDyf>Mz-VfYW6g zBMC8WL7YHS3Mp}-hGxLC@^ZrVeAF*QC%w0BS*sv75~*#aCu`r0fZ;g8?LctxHMOYAgx$WbzFh3r$QDMDx|(-l7;FHv>+ zJRq27@&IQ1r>X>z=66JY)%cJA{7LrSb>j70DMNo)XG+xZ444`Kd>Tn0Zla2`G1D*LZgfcMcTa`c_~cxa%x(6E%W{?nFec zf#g50vrx-rF&XEPh_fh@@dIB4xR&}V9wUgw_e-X zRJ^ZAAj=2Q!_L4lwb3h@MEF*eZ<7 zQ=uy(+l^5JX}&w)GyGf;fy=U<2(UQ$8XzK3}L8yU?cT z>c~b*4COnRh;t&9nb34!QQMV^uIs~fB-TR)?uCl)&eN=JPu<9+;fBX{f zuGG_FIYtVa>Or*LesDU7pyzD2dh|WEh_|GGH4U=G^|?$R?py9UQ-MHL3-=>c)$r|L3D}*kzOypP|Mj~MH&Ec zk)GHJKoI&a?SOmRDPVOvNra1f8H^C7{%tTLa3mtAW%PEOM(S$m!QsLK!8X9uWX_=C;kJLGT*-aYSY|t4XKtBc2&ZCH(oii9o@| zrc8iTP0}+NKb@E`R+yA9l6eWDZc-bYTUDK_^+U)Q(M0sCvVYZYt!Jy79$=A}6x;Xa z!`^9aNvz4r*AYYpqiAOqWcBPBR{i}bDl>Y8}5y831UvC zt%!u_nT+tfy4^sAYjt%tCqLPRhUISTGj>dQq^EOc49q6A)}LLk0NgZInNlyJIil@@ z<#=$W4R^JL_N~9`jLx~FWD>}~KX@3V=2>6p4t`6SfPoezGK>BDz8DUnbPbC&8N#ju z@2@U7OLcOud<%g=L95d!Sn=Q+j=I)h@0v zEsAe7DY6yJ2(WEe)Oen_y;d_cxtINs9E1L`1MI&=3y(f0X{!HWzt2ie|1J4{6Ybz9 zOxYL0mUC`sqxgcp>;p?1AiGyDh6qWffC*aDy#q4h8-F84t2oG#@0|lJ%@Fd>CDBr)B&cmZwOxOHH1>LV z!Nj0V>R#q#c0ENd8^43xTo6oG}qmIi?#t4)Z(N3UMP?102Z8u4W7R~amrp#+AA4RM-g$- zJ4fSjCFqps;NW?}oqqEc3oT1Kpw>Rta=o8)PDuRb-{Rs9V9n@zf|;83m=0|9ltr!G zduvD@DK0qQ9XmDL(7epPxu6WiU5yKpqn|y|w|IHb=hJZeF~gbFD9U8ADrRN25gp*e z=hAd6A7a1QV1hA0CrzV`A&>h7z@5+hU5q{Xv2eH7O202V;=#*UB(DURs<~?e5q<{a z-O*j5TTU+PpB8B8=lM#S1L0q@KeAYDX==h_Lz+g5oA}ftKd$=@P1~J7?V5|^y<|l~ ze``%JW1epMDtb*5po6>e{o^3?X!`b0b<*9Xz1E&&PO(2D&8r=%Cjp^wMz&jQCurzBycF z`*Z}P?&3+bdR(ehb0lde;5LQb=S|pbm=#P9NYj-y?ko*7Hr>n4<8k4ukJlzML~!=d zJU{fUczBi~ofpbWwcQyK&^Jc_RAS4EbMA#0ZG>cJ(FrfMFvWKhEe=*a2`xaCBmY#YPMtb?pR@O#YtFgWuBsv97fg6VNx7H-xQ+XSA{gRm`Y2r5NFU2_LMET| zcwdaR^Y)~kXQzxt_qlk~+XNLOOGZPR`5!t6qChwLOicJgpCPHmT#Rqu*X9ji>Uhof6D%f#QBx{aPv5(N~CA; zn0_6k6lTk24Lfvw@H#awC|KC_1Cz9&D0cWb5MdJ&ogbsmiqG{5MQ@y&_i&?sQUY z++Nz=Sn8h`JywGwEq5?ekEAhE0=Q2JEa4{F2Ymkny^ct6Qow{IA4Wq-ADrsu$jR#01)U$eH)l*yZ*FNQ}dQ+t-&=E9`7TWf=LmS$}=En{! zCoFlNNP+9bMmOhERDLChYg$>u`;0KME*2MV`)$0{oOSYL>-h57o1ZRfm-d3Im(S=Z? z_f!F+8P@j8-H+iD&o!qz`UVw0gji-1l2XJBT6l{UA~8BM?2sCp`}#Ek%rMX#?tinv)eK{h&h@6s1_g1XW)PPe2+xee0L`uij*@W2@OT{83XqL%GDLjap?hqqjXm+m z5~!bTY|#3f*yA3I%oZ!*OpCIAGZ)yW1o!?#b)dAs{wMrDc!(en2puJ5_qG4aW~?&< z0T$RXWi!?XYf~vY&AxqxB2`y{9d?E;wby#Cj-d%_fy9G*zS($&XZ2|H5fGClV9lIL zuibF+`lvWRq{?+wVk7qjiz|Ie5Z3Au=zBtY*}bxYZEH)LQ2~ycR3hgT&LoIngUuKS z-|0dXPPq=3Hq)v}`Vu87PD8a4uc`?FZy8{JieM#Pxrx<67A94d-t7HbI`HR?0&qPr zYa4Gb3m&}O&6B{lILk95Q!~c&&6AeCQ5jy7bx^_X3DN?dJV^z%#qdMLPphjN=@#Q< zZ`iwy$-E|Cpxf5rB$~lhM;y}YOPFR$Twny(lhXKE{a23IGkuNP$j#Xj>a{-Q=pk%* zWx~`}cv!soh@yE#A`JIwmz#jdbA|r!dmcm6y+@>y&GlEjvvW(sTTxzz&6iTwKtxqP z#`x>RxD1ejbDIc10A7&*DKCh>)yRi%lQJyJD?awVcQKrnF(dlT;^RFNiDMBgZ&1B-Gj$s|9VXJ=79fms?)QS&P8xW!ixIUDx{ZdPkKLeXI!TF z;c0NCDD86VJHN!+VYR%t?k&Y+3s?86;oCTjtKh_?wAa;%z?&2;zL*P8mBx7g^xfoT z?R4>SYaQmy|0lX7OvL&N)VXKK#libpn8MG&=?#o(k8N>iB~EePuCePU$P|VX@%5Ag zp{-Kx7ami1UEH#7_L-V=7GAVWnj4#wihm>#04TTL;jf2mUEw<+;jY3dMaLyP=^}^^86VDB1MY_F_!B)QfK0JW185N$3kf zKd7{XfR_5QpPwH_r89xh?V&&`qs0kZu#2MsXzX2i_7<+!$Pe?jCa|5aM`p5x1`nq% z;;5?K@&agx{jy@(M^Ij^%F~{|Z{U?~yQY9Z4+9AF*zbyqK5!H=9gI{|z^L7x`987? zx}_#0VkESCe}*j2QiHeMHJeCmR@Lh(F0LXG!-eS3K7ABBNvhq)I1 zGK1#n#79^ERZ*}cxq#5CLmsvshbam&L^O#8M$HgZw`cso^XsaTZh~gT;2WF}Y)bEI zpT^wDeXC9Ll);0NO~g%!(HuE}P{%iRT~YCg1re+PPddk>_kj^!$@iD1lX0yHa^SK) z2aNC257sjad0FhI#620nTa%-ul3t=JJ^VrtP;dcK*Ki^bj|t|kd>%@}@pLHj*AG{^ zX2B_A?aVnR&rS;_9;Wc4@s8^~#)gFCz=9I_`0E8w`aVE03n1mtsWMaIj_v;ZqjZ(` z)xNW(9twI?-VVx2sJab9AMW+YnD0o?c8fQgdOHGgS>^fJQt*lKx&plYX`Yjdv7KDz z1KGokM>s8SXSPf5k=6Kg>l8AF6-ylidyUB%)%se7dIhVuW#g+>=duc(oSiLw>>+K( zWU{2M=~8X>gIAB@>Qc}BDq?+c^;06LTJ>l;lI%EeUe8^P&?0)rYdk)qtIuB%%lZ6Ww{|GpJKy)>77 zRwS|_3s+*jI~_RXy6m=WO1ppjDEezA&|!O#T*^yFcJL>LdV=CvsAj^$@vW-)+XNTM z+DZhq|X$SI{aATShn~N6t`3Debvrg z6tn21XYqN&(mfw@_BL5jWMK4I{H-7 zKE`OOId1iLCo$Y-?+b^8eDwWl+i9vS?X=Lfto|xlX`|FRjXQ2v!~_h9{YTc>)|w<{ z_Wkv7IT%B=mtB%4E}n270_+C@aTQ}^)jxsnUo{c9l?-JYez)JYvwP!LV&QvCW=y7} zE!$D&p!e7MTxymN|H@UnEKq+ZU%fx5LnW2jO$bow9t;~`OnGStFN@NEPo z5%`|AjfT%p=*XeDB4expsGxFVgP3(E?V`3Ml|;8Ds_0Mng{0WBU#e~-ojp*?G)P!TLAgA8&J&EHi8SsE*iP zseoMgFM8G2%j0n7FmCMliI-coa>i3nUQp$OA7qdTlGxQ{IwpdR4iCk$i*Glu>z)+Z z+8Y(QeLMOmS{I0((6phiHpuJMu}ps>Xz!>uKtvplrb|eftec zH;2M)Y0of`MSxB3z*}O{kuyYh`YE1I*%n@m168c9@KC!uz{B z8h#YX)7n_5{A#pqwBK_L>U(BDxu29^v8m$7aVGejLSKQM%F8=E@-yP+JkIDeSP+dg zb}n($GAM!h3*Vpa$s^jI1Wi_*zlZK|%A~i~qPG%;=yMd=ew<-R4Sv_s`lfvz_=(wt zxY*=nyjS$yBp1lPAiA;p)*<iB1-^ z?aoo8M?+VBu&tLSG(Y>>O|LFPN`7)<|SvFoU^4>p!@>YozKnoiWn$YHs$# znjeSGP{FK(VS%@zYFl`bYL?g6_5BW$siTEe+JWWbFuKl_+M;z`yEo*zUvk#0{=SRr zb-*W_Mx#>z8d_Ov4VIxR7x5qC$?J7z^HQ~Dg-akIoBY~Hi((Ibn`-*Gu;H1iCs4+bN+F-z}kn<7m=!mgYVKpu_N zWrmpF1k$)Y$+kZ$h%va#0HS}_1kb^dsrYU~yY6FU4-y>UbF`JdEDILKj7Krwm{ldRv0^WrDkxT~!8O{9%O_=ZUp zsc40WwvuwzO!#j9mF^PfkuKLutiSuUmP&Dw?5)KKK!M}?kQ9N&(wIM*xf_d(zv+_f ziEwI$1SQ+Kji0~g{<;%$f31_Khj!aJNhLEV82)F6|Akv6-e+a@hKX*d^IM$z<(}3N ze-zu}`<}}bfst`_hNww1dcfliSocBB7JCZ*F6cYa>Iz;H-xWOq>|}%r!ga-Ih9Kl` zz#+L|-DfRLIE#+&FJ>i}r3*8f?U0GAvqbt#BVpFc*4kcMG!7<4GtUIa?A`{+I!<2b zFx^k-eTgyob)hfR)_*ZN|I>l=hk#zyuv9dBAET1!NtGqLyo;Vze$mxx3Kx&JJ59pF|+6stGk{tq}nz*0x-M$67{X!Srq~vTjV``8AYx-9e+Jzl9k?g z_MS}*Lpk}sxObW|5cdw8OZw5btf%$-Su>u}t-BBmncD?tEsZ6AD0T}L*XM4syIPS- z(=)?y-O)aJvy${Ie|KwAt@=c$BQ0N93oiZ|Egm#GBxh7L{rvSytOc`W1Xa+{#@B}@ z!C!^J@kmr_CCL822zXA8e<$F3l!i%#8_55IfOi-EK^fRg10qL2gK&Xk_v}jqfFDG^ z%Nq{S*QcYTZ}=o^pj0ldV8Sc>cMx;O$W3kYReVA2GXw%Y7Sr)qEcy1K@!~L0c0OKi zp-8qh>E{Ozo+}F3o4Oi{vj{KG-SrtH0WEz{9|w20b-V-TF$?o}R$gSoNkvl=J3*?oq|dh?fVX~^4g4oMRg zS!F?=e2d1vS2eUCA`q$o35XP+x^0yI9s^DMR}6%6{Dl(YJA~BMn|_6noV|9T+qB6| z2dqt5m&kL~x%F5OdS9`FW`QU%fHBc=;24m$i?qnm+25 zztr7KR!y#t1%<5sBbQVUSA%~ zK@5cYiaWF_mI7YJ4UKMqZATwtUpf%X&tJBx_~B~%+1%7Gt%{a9x6g#pG8V;hZvwbB zo;v4|(9qbB{r?JZrfU8(z}bv=O>1s{qNti_JOULHy3M)E#8_Y*ezXKMCW7jSJQek1 z$$EI<*xQF04PTKYOC8T;q?7Utah{Lo*@nI$SC%^ot+Qm2aIWths?KjYPvSbcKny&K z6iM3-7P)pAWkXrCcA|E5N~Qk}zB%8&>`6K~%C>5#c>UdYWhQXIY0Y&C^S*cdIC=d- z8L?P#I?=yxIyJQ4u3{h!tXk0By>Fk8YHh+;M`Owxt)wlRR>38UX_oojcn#zLIWi=d zWvwY=c3zw-G%)Ixlk(jU6GF_3;ct7SEs0ro z5z{-L{bb)m3&p^vX51DDrOr~iYu&3hIlWm}RXk}myk0wgai<21r-V&ELPRW{-Tc!F z@WSPFK)>sgX6utFdavT>jBouR^E_oDkYLU1C_f&hEeb7yXYV=l>#hpw%#_=v7>6bc z-F-+t8f{eBZSgGbY${zd<Tjck8Rl|7(Oek5`JZ}A!2Q?74PH2Z(qGF8DKxrWQs6N zCNXFty*yS#Q8#Hw@}9))-wB#=e;cp2DL0m$XmMry-HVCt+Y-hT6O*U=3&KZ?qU%U* z?pAr$y5Z_7v{md6T@L!|1g0H8y6B)T?N!U)aGGS>Wn@J}n;Ke(YhH_kF{PKxSe(Y19Ea-Ghn1A*EbwZ&F7_@Z}(|7S^q9hdkh)ecOK?%~<6nmFO7 z%JlbQ3U^JFx{iadt*$VeLxtw1lNA)l#}f5(5+j61M1NIx1=V+L^{ULS(!kX}?lGo% za`rw%8>vh-_19XHkb@9VD#liKbCr4pPXrR{x;IHGXs%dmb_$F zj`Mbi(#XplaGy0|y5MSgKKZ1E!_=qvWya=xEQkP zZED-O(UxI_HpN2Hj@18-6j7LW`fvw~CeSDHd8XCTb@)W-mw@s4l<=bT@G64`TDgH< z^e7M7q6ePkjKahuCW}ek>8BdD8P+YZ$Rx<>*#z6Pc4*5xHSF1x7`sUocd9k^<5{Eip-Uw!fTv^8T&C$Grf z%nK*|Zo)JpV1mnIfpzWzo6QydF|!xSX+e(xeGB;M(1R4Uq=u4|dD|A9=ZO^t4WX6i ziRS)Xd&IV>ePo|;ZFuRxH8Fg4n3e(_yL{5zh`;rRZ z{|-fP|2-5@U{lJ1rcI-@GGtcx|BN(fT1VP7#Q1Z=0qI+-tN=hs6{Y;1#3Plb?OU z$nI^lsjw7Ot(bXDa23{m-J%Y_`x-6W~+-BYMDpt|Fj&e*tDh`(ELj?BqmJzT<4@in1tnWM= zj;<;`X>tw8E{AsR(gY9CZ0niOhif{1%9v=ooAX3L21ehM_D6l zTBs!KtsT~=VGe=>q7Iz~|8R(~>^FS;_>uPKTXE)Cg7|@^h~sf+?o9{5C)sVDxAjaZ zsQ;^XWz8o6lR4YaQzp+EeLN>FAJct>?nziw?-$Q-=Qv;qOO<0@44Wru0fT3pyU%la zRWN{nD~+Hp1nCsHk5*H0Bopj^ICg}VUdSrt72R#5@UlDG0~Zad3ybAutf{skH~8#k zka?bOAC^A8CC(=Y)vu+qmzndQBN<|{mykxCLO$+}|FHozX?d6KkZ6Wt+CxrPdOlk2 zKYrec2wiD`G~^?Fif+y%XmTown+Rv=4)H(bz1rWpQhe1iaYuz*P6=?9cXl61L8ga* z)8i8&k<@*UJzd((8|m>T*RlS}Rt`7Vz*|k+;twey@on00Xu86j(F6AD#MGAQJ1i{c zKyAa&WM%Is@e z7yPG;u}l-0|36fWL>_c`e-VcF>tW3OwSf${xr}QCC7H{@l}J{%y&@%^luM>jO6XOK z`GrK<7{t8q{{ZSTEu6hTi>V+d)8C8su%~9ZLKznRs3eQ_(IdT_&2Qsla_QQG$fKZBRKf&v2^5>?O(nf4bE6BL zFx*S}u#3#nMO5cLF1msx)UUOiwHs|44G@=uG0*uuYIO2dfqp78B6&DwD|osAB^;%Z)zxgD6JsGj+-s*l7bz z++R(Qzej6HXj}x3GU&_q9WkcGE_X}X+%XWmZOG+2J@;c1yBsApQzHnH#4@01ec+ZH zX!Gkv`r14Qj?%SWsIj4YIYD|c&z13EW$S~2;Z2Dj%l9Y|)&sHE`IzsL%#HhU+9e11 zGhZwK@$a5whoogo9|2o;j!Pg3M9$vAqQ6R#C-@sBmT&;`INuowuS5I@uH{_VOCkYT zKmrs_M)YpFo`YkRcBwG=At+f#NW0jg+T@VG#-Kuk^w_`((qHUXeU1scVm96tMWx9q zC+6j;T4+Lo#O=Z_Is3!d07tLS$O!029?3|3Klq?;gTPjm1bWIogiGXbY(wCb!Q6j( z@kBRV`zj&g%-JKieY#&e*LanabEISiwO(NB*jq{4(;><7CfIW&{0)3}-=L8_?q2lU zglq98hBjZ%`I)Ls4eS=;UzcWGsAg}e8;G?ZOnwjDHIw^u({qx%UBN$0^HjsbR9=(s zqHAXQZ7o!>&3WOR@UYA*{7XuFBq&E&_trI=%`thpkvAp57fVilTGSZ0@GERJ@yCIU z#Ly|SOQCa<{^;+#wE9IS6(<^&Rok&%b{4;W#r^pjE0P3N{_O91qo>EHg z^|=xl?{qC#7FPuq9ixN5!SGy3bRTPJHqR2dyn*;_sUF^sMgyw(+g=`=r&4U#-D&#Y z&hdF2fX@48tYpbkP^rysD>eJAv0dZYV}eh0+4QK0Y!ooA_}Cgz{^JKyJ@CE^2nV>G z7c=!@`GwY zco)u(dfa=GgQ*?O3Pz0E^yOe3kai%h*+jMW-M-I|k0xvVYzGtfMFAKd`$vfUts;Z2 zrD3u?%ZVb{4%tGVwKH&7qYKC~jpH=eZOM}_cY`f~iz%=ST?;zF$BM%?BQnZ?njO)L zOfAeLohzq4&LK}}3Pf%KpGvuGJDhPb9-jrG8i}MEi`dS|W2Oc9R{yxM)uKJvDFrXY zB>~JuONLN+K^7anQUtDY;Z(s4_-ndB-6eFUP-qcPL|ZyR6UhH`@ltHiquXL7!%)>l z1LD4#xMQbmDQjbH}tK!$}hECblL?8mYiGB!|}nIij?ea zg_JJT!_yc7q043ciRHvmbWiCQX2~H7-HH#X+P^mT#m{`2B!+5qkjfw|qajeiEpLaw ze;YuvYR`u5?ldYeMZf#0o!OiO}Z$(>9a!FbCQk)fFX%ELR=X@%% z!VVr*Z)UEK17!)hX`4yd-GN{8dk?qja8HZTF<=N48H)Vof z&(qDgCff}CED^or4w7B?6lA*(+31!xFAh9Q(6w3^<;rzCT%>i`A-8^AcQw0W%S?|=5>Tjqe9@YjQ80o^FY8fm#kXHySc z<_PgSU~1=Zi@QnXCHbo7<~{66xXsDRP`y2Wj`~qt2UC-H*2oX{n4VW*p-q|VZgD4Y z;FAX{=iE`=(TN$89;+%>y~ri)pfG@tw&$>x!!SJit7%1ayW(!6p=`4(~wids&0{-bA%Bq>j7UW!3-8=<|uD^3MvG$*sMmk;M-9cp; zfE+oO%v;`uBpbQT;J=WA`hsmv_P`mcC@CPOeky)R z+>UA*b6t=#3g0nSP)`FeBpPSW)P*RW5vWX4=S8 zkH)EpZ74V$GFBloN?9Jmg?rD64lH##r_BzhRz60Uy1VcPoC4qgS!u@SHJtQ(RMeYr zwV~xi-ILtXB0xLR+@Hk-$5Y|fkM=b+L<`ixk!B1>%;o0|pdR}#uZZcnQV%L>*wN=J zQnVhH=*hVHPq;rc&MBxF4T;;6+;hAaR_+~=lh*n!&m)Xa}F$7j+Q-BL1}Yd35RW6Q+mBX3~i$P@MX%NaF+o zo1+3QlRu&%r?s#$k4A|UTK4GjSk13zAj%(j{pMcDIhY`Vbt6VBcbof7b%2}+AA?%U z&9FZHPH|J_u2V~(tr*Gdnt&HOgV6Ef()If}>AfT80iMY!mU+!_d2{1<&(I{)_DrpL z|A|L9V^2pS(mAYbI5aA1$5-v3j>M5=$EBL3b7A>nsZY;-SlB{7kM5p;hN_XW?%-TQ zJQ?r_H7V$Wist%>o>6Vlv$$~6qbVkuZs~I=nGC1CN@i<5zHXR>)<58lLeDjiZZP7- z4TEZc`SL2spLrHaT8&yPP;|&FEO1>V0$N&p zC~~2yN_b~75Dv0g&&bJ&LM(68RAwE@WAu0_qaOZg)l~j%X2UOQ#W(M}oVhH_z=iq1 zgz5BhOw$t(bW4cn0g6l~(euvoy~!YMMd+H2n)r{03$ov-L0N3pZd2V>M_55QvNQv zA~0~A5x)w81GJ@qyqek@mxG;d<$zlQ?VwA4x_}}0ey%}Zp)sD$>Gj1~N{nfpffI4% zP9+RcTi)TmlZh9k$yWT4=+pY~Gq8q64rHh*g#VLzomRlQ%}52#D~ljQeU<-^7Tu#f zEn0{;zv6FhOlB@xmQvWwm|QKsw5Y;DvRe|VUm+h3*Q6Q$#b!%ru&HNf1gCc)V>JQf zgD0?v1zPvET|ka9Xw~?~3{)j?0pXv`(S8$kfOkv;mE(8(l5Gnlj;i`X z9dr!ZD}*&~l17zeAeg5dabu7DKud|vl3d)L@YPfoI=oWb{Fq2Nf_RqiPQlh8-a@hs zk%0+xeSc0Td9@0vo%h$PfA{zQT{owL=+A@zdRFCWhs%+eh4DwCw$BW$-rNjACcT zuBk|)_NooCpE(PI4sR7JwzlV-9B&P9>4A_?xWAT_qDPv}gsR0c-1TSoYNc*-0>}El zaM6n&nsg?s4@#3>E*Fh>IP5qOnV4Ek3C^QsjMljwA6CG~bn5YVg6sp@kdcmp(!3)p zczwr2B@tp(C96u%1Q{WuImcjt)4?7_zbRU;VoDQ*s29F-8*6lt} z+I@dh{BGlsDPt`-bruQQ^rwRalv*_7eq}|nwwf{ZLH6eE(@eCD{$rl3I#$9sb9R&V z7x`n5yVqYV(Bjkx+Il1ERP*QG(%Izk+{UP)uQf;g#ia65AXIow#n`Y+U%mfbC^PvXXI*nzK z{1_`p#tbLuV0?WpS#ha%3lThI<0?8dEeQ+x3Ci)&tCTzlZ*tm z_hikgg9?DPF^i1i;tiV{rKCu~0XR&h2mULFAV0-)A31zTzTk6jP<11&dD=6IE@}Pq1N#%8NxXy>pk|upBp`d^c&&#o%3AfY6dNzok)VW=b4-FF+T%htF)ZiO8 zd_Jl`4Hibhtpu?Eq_h3PI` z!FbiK2_DCmibVyr+Yv`9ZuheQqPaBL*6qopN(xCJe!I(tiqFY%`g+H+-NLmYrt6OH znD-^+-EL`4j6v_V;nbTKZVfP zJi+G2O!6nu@{Sy;Qdp59pjg5Y)uv|E_X{D9zOpA86zoX&%#Iq5@AmU{T`Wp<~3mWkSM@#R_er{0$@B~KDvSkGm#Gkz@A0o6l8@p6*B z!=Tw2a`;g~43wsG&c+l|oz@V2?t?!*YM8ydkyNFYoHJE$?sf(*Ycg=+Y?R&N*I;k( zSapJXON-|t*3<4z15ljQSu0zzeB9ed8td3L-fQ+9I$x17sBhiGM(2A=(p}0@!G`2! zpS2nL?8I{ZorERPD+2F*p8C?2f`Gi~hBYkB(a-zRV^GQ~g1VNJDdJk zBzHb9V6^C~lLafLSN^O!8LJcV`#hU%DUPyQ%!bUol`ZMfpJCKnckr(!+4UpXE|#dW z#Ik=i=Nh`X#UjwSps0t@zckx^Rod=Y0f^Z1AMf!0o)T@Qp8Cvfay2W9eBH(FRZCKQ z^COo!iTM4Vq4jyt@!s+LDmEgsH!`9Bg)Jl|DTB+l3>$po*F^n|i{L^&hV|O}x7{0l zkWJ2534mQ8GNGpy%Q!&({CM1;`goGvuJORqhzNZ8vrikX&}+Vsh{y=Lb0T^0-s;TrX>>W#-RK=hz=4yk@9G**k z{ct>o&-Oh635q}{6OD6dY!ZIq~&aHdI%O;zkz-f@N3ioGy=IV@PjnLQkq@@=X7p|CU^Z=E+8_f z%zqXTslFf;!#6wO`rqB0#*Jl@ffQB-XwZ2YvYi4gBVp2F-`GNga;7Ouf<&t`9$+Lp z^8uh*bp6am+>!3G$l<`?%EvV}?c=N8CY9E9Hr!y=6RasRL^`RbWFOgtrG?LR-g+v~ zR^nL6C&)fBk#(}>Ay@~@uVD+*8`6djVBKRRwO`Lq@{CV?O>S(;qgI!dA0s)rDr-la zL8|-;Eiq-MmB!NTV}Ul{o&(nc?tQFZ;@LT5kyMW)@Y}(HzN{28(LgEPNF^u(D+lH* zOi@gdNn>}WSlH2w(*rdV*AvK^!U#S3mL0BPz<#}9R$nqmoq`gT1H*^04C7tk@4ZjE zIFa49*zlRg+D0IMq+n3sXK`N#Ck@itbTgZv{r5&K7_6=$vOA^n8eYYCMY$*O0TgRB z-5a>HTzdt17{i+Wsvd(e%Ga8AF)htty|sHDV)x?g6>>8ynI2{)?CZNiHR}%$Odu|- zY1_gtUdd`0KrYUs?76Su6yD!r&0Al2Mivg&zy@_(+Erapn3$vv)lbfZQ|r@%6?TZ64AD{`Er4?-$D9joA^79|t1rs@XBfKu44t&!KMYG?gcqtQIjZ!SCeFw> za2KJgiCImbJu{T@6j+0F28<+?mY$ zA@lAhdL3>|e-;taT*}1fuh{cXmo361RHsv+y=V!KYpL4IwXj*;>D9;mFv~!*ns?}u zcaEBBYW=FvIdsAWjS(YB(TwOE5AThLm8?|``PRS3ikb{zLKV{4cgBmlZ^Ej#_K4v! z_x1F>?tbsm8UME9-qUAAy`ENdCeBJ!$Cy3Bbx0kj78x4sOR@m+C+k^6j}-xT4^0h^ zmHoSxdT@#Cm6@Ol{RM7>&VPCVpb+mu_~Ier*b39BOyU8L2qCPLz-43pvVdlsZ#p0*3?76(Gp>(HX1y3nIZ`JgMx6&}%S8y}~h z4T8;njD4LrQQT@#0@``tZ;TpIZaR$IAmX=a7ooMbFe-X`op*xul76xZ(JAceg!66u zXPQGE?t9q|JjYv2`t}7oQCZ9wzw@bf*g7Ay8>=B3d?61WOyO9W$RS40R0`Da2-xwS za}Q+F(|l#!kd`Z&z~^sEJvlU5{5Pbb(bRku7MCY_X06JmMr}k@}hrCk;pX|bUg-T4&^6nFZ*eR((E+B$s-ezUf4(43* z5|erl5Y+}i1t3;_)H(#3e}{$KXv}TKB;bSarX&4v{y}J3)v9kQM(_Obu%AJd|9q+k ze>E!I7Ge-ut_Zw~EJ&ax=j&3~TIR}!ed4EYPyFRi%!>h>{tfpzPmJl&)Iuh+kB@_N z1jl)_zJ4VHv89B~xUz-_urg4t#9QO8Ime$eSWdXR`gvPY6}}lX879`puQec)!iOu6 z$q>GWN9wijlQ_Ib4^G!3t!|0K$-x7OgL6ruNnEyunLzh*=ZGXSZ@*@UFQS6K?%og~ zYLW(>Ip6uKDD-&Bl0?|1@pSr8grNVi=dxj08MNf4{=V+#wB7Y9$f0} zl;tE7|Bn)P##{}%d+zXrta@Ru%60u52JYDxO4RV6NxJo4biaS+K!F)6Y+idoXXMChhFgJ^x96pdgqH%+i`JKg>eTf_9AafcC{xADbZ_CS?s4 z_C+*Tb2TIZ^nkmOgy`aA>Ec%xznv+7+nwi>p}p84W(~#5+k0<%xi7;H&rMIZVe&jO zMi?hZOLmi4&+1<5MQh$}Nz-n%;5o1DF#S)9hGJg@)J$yp#L>U`S5w)=2f3aRVnb1D zMxS_KdeTjvZNQx2{&{MH|GpDspAKH!1qB*mnr_MK!|(N#SoKJwrJi^qq@1@4TQ89X ztG7B*8Y1imml4q{=>-O=kNPkHg8?wO{cu8!G$d`?E6pyQOlaYfA&Q*6g0it5^s*&N ztew7S9_qxAdr8wsi3hvJu_sxGyj{4(_iS;kx0vK8eMh~AhgqnT^j_~2_1{1H<~-LM zp%ZDqY1D*m+~Q1hKNKM&4cu?-aQ&DK%0|LOlSJ}v8F#>pIvDuW)dr}x4=NedvM2P| z1E0ZlXF;5pwGnpFAxVAFlzdHQYl1`&GkG^cziB(TOQ^9w z5FO(3X5MrJH}2pG2z&lIdB1Ib4i~UDN3og(bU+rH!fXw=BFA@iOUJFKq2cx})!D}X zdVJ{Myuh;Q(;(S=K(J>_Aevf_nC%F=$a6(u@d@Jm9daWrRDjCf{MnWOkC6oOLJ?2o zL}P46hHK?x2fB4FAn|12&|*N%o-((-`zv_G8#=7U@ZDV|p6M`4uVtkOwomxYn<{As z?~jrWxH_f?&l0rW8v7WUuzJY2N?zAvT$^ORC*!`v8n$L+bw_zbSGbIDAD@rU%=*}zRckb{RG~=OHtee0W%3vhTm@lG; zK3KdmxS_P)vos<^PLY%}zC+Uk>{KQZs`$LI+%yYen+gBXy&8lcUXV@4@V z+OOTf`F3#c1I+>r&Pi#m@4+p1KIOpSENYtdAHF2B*_>k9s8s`6wNUx>Sh?)Kj3{NE zT{8MVagFKZ%4vB80uV(|k*Gh?#75gW5$4WGyHzz9a56@+>1#;tYW+D@Fd1*7|N=4#-&zO(*lgs*YGvW-GzjccgI!f+dUZA z{Sr5T&l$PWh-+%3V5&-Dhrk63I4Az?1o?J$p5-xH1tjX>=w%3yGLAKh&GLwIr$43x zE*Q+S<{kpas>t9`V}j_sUM6hgPGzHgN#aN=A5ar9qgJL)wHK**1;ZsG2Ura%SYkOl zV*qE#s${79m`l%uGs6yIw^`@qW4Mlm*Vpk$!8%=V)R*2f-cf;7%i-(KWLce9fEx7s zO%yl0Zk!d@W9afxbi%ey9XC=;be+E%0F@Rk^%8Dn`Y94qqz_JQ{FCoc%mvAY9$APT z0#A73olW_mN&Bl}m7;3*PPEIq)E z;iMiuC&$|rbN%QUX)PPet}FQ}_q&A4FV41NcGZ;ez{+McZiPrhJcijIPbW?p+w*?M zfsH_AADrUdkkCR~-oDRi0fQ(a2gtljLD?g-fW!bcPo4-u*)fKCAUoQDDoZ}vVJzEa zmb1_!NqI0}N|FMpRcIONr4m1m-393@ZIA#G-_VB&to%!su|;I2wLyHzZ(tb=y6l=M z-z10gARO1cQ}Q=bo72=RN$PJ;LmMaK*jc=yb$XdXiPh5224Hv3xaQ}5ti1MQzk7B{ zAIVWV7F}N_B?VXK{Zc|ckuPXO)z4l?grz``4*OP(KN^5@-^?m9X=Jcv;BzPwY`pg)k`}F=hREkZ;5eqSeZ3rgFI_iw-|+)Us^QSbFdVm} zuo=s~>+OSaW;22x`!d4~E77y-{xudbB1ZT!8qPt*4AYHFkX^^(8TBzL-ne@sZHQ+9 zMvwt2QYfdjZBPsD&8NJBc%$D(SPhvw(_`Jra=3}sW{(k6TY;&p724kYmc}^89V)x`)i)iHFqt#~13s63f8f0Jm8u zhux`TxAn{ev_dv>;|x$mVE7g}c-#ITm_&Q3E9z?l zJ=oWGZeT82S3AQ0X52h3Hf$yz>@+9+k~aR2Bi>qb@tw)2Z>Ur+WN{{|{i9GFQ2~9_ zlBWk1Tfm&tC4&3zRD0#Tu5;SiB+f_-qtPz`^;upNnFlE%jzihPhL$72* z^NQhB#3`Cn^WnKgqIGUfqJJfd;tQIOVFoH>vHY*3-gyevDwZAJ%%};ipab3n(c#-P z+{Zb9njfdo=;u^aTqEO&4*cloI{jJ7kX^;D^a#oXN=j>RCz$X#R+*S+@yV>f#LMA#}J zTl!FI`^W%#;tcAa0D(O&OeY4|la;3n|MsEbn?T)($!TwhU!mN8=Ls_t>Oanb!Qb$| zpJ-a+Ui6oK?@?8rIE?&hi&WW)&T&c2S;akz=_7_m3y%VIRnJE4$(FZGeP$*X_ zlyv~3;fJl|N$lp0mN!Uh?$&5xbSpa%5R~Yn2Yk0F`v`3k93U(@A_>z0XYO_|)is`{ zeRX=DJG>J=%VGK%{PGs!etkRTYE1RtVdOfv5wlHP5biO=m}*a(QX|C32!8ZjQ>ey6 zfOKA}1mED8pvyQ?%Y3UOF6S{tK{XhAA(iR7G@wJgY4@9dK%!lZ$-%Y$Tz>s(07)gJVP|R`(UzEszgx1h zPbg%rX~9uDwROfb6jEbtkHN9$u_J9lC7f^@aN7_naX^}T+xy}fvxPu-Xgwx{RZ=I> zipr|)V!hRgtvnN~{3&}wEglAJGp+a)1f*GyQzO(uI}#4%yE_6efw2C;q>^-*Xlu3v|Ut}7`glcp0!{~y^%Xq>ipV>(36-0KRO{t zL3Gm!AM6Akj?6AzpJA9zf|zrIe}GRAg`nld;8ANj1h}vcJTntarcY)D3XwV}OlYYF z)X*jSy(-!?41mF%hX@}%g0e;|^pRK;wo&5(IShqC^2HdNERx0zXi^Q7G92lPVO$P< zIj*rTejBsMd2FquW_vcXK@8@D^r?f08qw^U@>bWJkIHwx7^(ogzNm{2AN&I{sG0>> z1cU3XHh+uO1ik3oYJVX>a4dPGvbx(rH#~Ta5G$^6Ly=lSKx+!>T;em^L-kTbP~780H3MWQ18)%%J?oN_S4mx=}lQ9!4+C+ z?fxNUfb!|E`v>*l8L(`$JZ$Ax5lf$4@TOP8guTNs-cExrk$($@#(c1DH(b3RjOAw% zllxta^IoNxr#Bo!Igj-$ohwUjslC2ozAuNQ{6UHC-pJCYvXY;Fh1bMxb^_l|^uT8jh1yBI_Y_o>9~W zj@92G-_#NGiSQahXx+3I({88?`r@$b$f~25COp=2WE;;%H^QhLiKz>!pbmL<_!9nZ z%VO<^i7G|Hs2{zc3EOecQR;NExsYfhfvZ0I?g`ysJwBUrHo8!X6qpdD)9cJ5`?x1N z3D`RO;HjvTw61KeLG;uU)e1O;{bUrS+x(sdM5TJaN8M*xd(n?@6=62eY`Rz_U4R0d zF5uVv&YVby(fLZ`(n$@h_eSRR%O@q&izM6()UC%+0b%7)neSMv&5U*pT4j*OK+-s< zv!{v&!eOCURO1j`&PZhrik{L+$9aziPgmo||j-02G#RR^Cox$brA+bPi zotY2qYe}CEwo$;c2Nwi1??;r%uqz;dh))dq4MLeJ27}kds8$mPbsmf)7m5R`#g&k7AROLIOhMT?pM|wS7F0BP(%uw_Vg4aX8I`5o*5w#6= zd^Q{NWA>?Rd`DTl$0GwE{yx#aST?Wag9fDI`~QU51uQKH?*8@E;Ad&xx`w&)SojxL;afI-r9jBc40c{EjR3~aBGkihVC7@i>A5o+UZtiI4e9GVB z4k<822J7+K8*vG7ZGx#~bY^Qgt^N^Pwt6}8=*HBYTqtN0;QF69JAVK_h%+lIB;#=)0}(O@`{Bn-Tk#m z-3wBMlBN*MXtVH@YIq@iO~#yK><(x+g_?HZZ0Zz&fb5WD@^@JM2Hs*?S9>9D_!m85 ziAUsOM5;&6fdk@}@xM`jqH?M;WfT4zQl}*DSaGNh$1kWpafCaAGtBF;ZbDaU7T1v4 zyCSel^KB1rSEt`^(ycGagUc!pJL7ha%4>;i9Wg{TQu*K4Fjp|uunr;RMw%gjj>uR5&e z43Lp@%LzN^A~vi{9=?il8qP6mM!dfX)vq~DE(l@1{0TlH>$n@P!G_D!Wl)^Kj~O;o zG{0t7eNuCLuX!%Y)|Gx4x;jHmXJw=rEotVf zNew?1ir`+@?Ya{H_{gg4a_Hl5`8*k|2 zpaDhPcE=su+D>I~M)D3R7+uw=L&I}7Mjs{M-H|1&AMkdos3&{~(*?o0%Ilkz6c=^zsoS`IMck^kZi8_Zd?%1&?Yq4}Sa++VN2EMKY z<26#$h=)2|%|Eo9#hI1B>P_-i@VHao`QUnc%=(_E2W{SdP+gHL??QLpH$=Rbs0-S) zX%%V75*wPNO^|jXX4C4x{%AZvhQ|Ag3Y*1aH+&}M!u0au~XYe=33nygd|9L?AD*Z`y0g~ z2Cqh@)Nqt(<+-{5lewwOIU?&kvcl-D-}AE|_&e~OPouJ}w*0(25Sn&{QYF62Hr`Qd z-X1*}R70A`|0<4DXbR=XaPrKMWXfz5#`_40n9`?6nu5VEnIfh&H@w-$z~q7DbcJo+ zwK)ywecpy#}giyIGHyu=w%}_Q>pE zG8mR7_{ohp5$+?y2?f2~|1H^JFEGz0BCazElR|30=L~vLx(7RCe@LhKJl-n;OB@mo zeJttHNQI!F^1PyDn$39D;m(8pAPE65lBU>jpxuHks+{TOYy0OYhm9!Po#~oBBlp3b zIZ2+_2ha4me~P-!s2N+WS+zxEIj5*EM+24dnWB>nOtmWl<5JWlcHJ-S3fVAa2}b7B zL*PA_Nz`7QCW`OBgg`#x_akNMM=fgk!%&|k>pOuP#_Sie8y%95g0dCJ-EZBOs;bbF zhI#^ZBcJ$;%81!GV2L-PblVB6Dp=HXQ1Va;6V-%qBb`HLAHG;y*N)F*;+^(Roc5MT z96h@jj0j>-P_BloKH}&NKCzb(*I>(C2Wtv;tEU!vkbQ*qI=n%q(3F>>>iY%77#4H` zMeT%#YXh|-MB#+%9x5&`6yU;qGgNtaE}Hpj^E_VMuM^qo!{B#P5B6dxY`Z%9-r<7P z$LK=qlw9|3DtikAGir=94@`^+oXZ0!4$juULZ37 z{n?!SRUW|23eUBN&|^P*Bod3KABVLXZsNLqr@S(+qplai`Pwr_$XyA~!g!TvB_LIx zo*6p(K!}tNq6*c}h$Z=&HlN1`30sMM28DuRt3PBQq19wI+5ujS2if(6!*=MhgPll( ze;DBh&c+uyr)4ckrH}mm1z+Y1B7B16iNypE(N1cQWgWAyuWoYit^=v&!Y=Ug*j7R* zSK{*tR8IN{3GRQ_mCf{7SP#Y!xSmW`?(#onPhH%9u8X-$FP{m`q3V2FP`F?Z?%H#U zPAE~pD2~T1_<~0*&C#b!nI)NZZOMQFsY3mU`|J-F>WJz7)ria65uuv0VJ|Cq52b~W zRHF^guwOmc{@-4Jo+CjHsh8UOt($L@9bi?-Yy1`lrwsahDSq#}EWI#EG=hDFLakUM zZxKruOe+BRiqq+x*uKd?)u8hEKt1WS?aa06m&s2#P(IHaq#kI^CM?(v&tWCmK*-VL z(um%uL1$SFy7-fuQm|kUMMyM6IO4C~RjLzIb-#m(%OC!c-V$;QqbG_%?-orP!Ux27 zK{AluWNb89OaF$`w9Kg`#;k7jX|vitn+LDjRGLBIKWU@EvJ+$c{8_CQ20#86a&Rz~ zQ~09Ve_=DSyw;$6pLQCSk9{>CFvo!f2#F-=1Lzzs*be7(qn}~}ituy=URUID3L*9wI`^5rlG3Xb-xf0c*L>b!`4e061_A%=MsYY1(60SrN=wM=hmY> z1RJ#zu8aNPV&C{911Hh;jKFo9cJW@*0zxV+82Z)7MqDhWf_dN@2${{ zEPe=A$Kt%=Jh#4^Zz!%5BXa^%h&o1twI)`6S-WhLc;Nu|CIyM8^y0MIP`SFW3cQf| zgaVxp9W%GFGc;zw{l4M(v=fgkskg-Jou~ury z$3JY+qBwS=;$PUd_l4N>aPqXP`=jmqDmH&;G$L-34%+ylTG7YlLoP zzVb@mmQOPWD3kTrtjBWc^~7%fL)?>oSNDcgx854mBy%ei&P+(%?k!|QnSu_-h=RuQ z>L%GJc>Zc1PfEf>0hJ1RbZ%m9cvhxqOSr^sE?5O5Y`pXh)GGcbD^(V>)U?vu^^zPu zBjpn#RetaDhFIy+IP0+fjZP}||3asPFbZCaDIU$`BfTx`B{I)n|yFi+l*&%hs-CxMwK0Eysr)Vq;7Desv4hF zr^jF^r`|Ge--ySMLS>@Re+NS_mmcIZ>dQ zw4@WxYymHNL^QMEC(9rSR-vfv0zpi($xw3c5$~%GH04&(!`N~k>`V@1q>!bFWdR$O zjqJ{bhpY%`>VT_-=#9|4P8GI4i)CiCE2Wx^DV_J!#VeVnizm`AD2S@QjXnQK`Wsx0 z6;F(O%G(OTzn0f!l>{-bFf{!AWJRP3O&%VL@cp%QFym75)AMY0?^?RgY#n zxgIWJJV=)9;@)wvE$Q-nKuIK!l8HMOh+Xx!|(W0xuJG`(R86%_oc z9u~Hk#-o^kvqm{k148|Gy)lc<{==L7SXFQ42Xo^=Q6^%i>_kNW$f2}cpox7z|r`^-g_{;Ghz(vI>NiDLsX^3 z?O>MX(ZhM}>U!SPpG&-`Vb=XQK$+?-j11;k^q{*el!asMzdppRnMw9dr69^JE=5WuHUq~~tgv?MvV-+f+ zD31T-?GsA6ut1SMb*uQPRo8w;8ALL_bGuUlYpKDLE3L#KH=&gyWy@}+(a}_$cs507 zXs?q$h_BXgPhr9;t

Rh_Ur|5z(u7J+6o#YAG+~)h8c>7Y=PVrVP8_0GU>Li{FJJ z>Eio7z(}J7D3kV{c@TMjVfXj2(6p2`tQBUmfeg=)1r-7rfLUAso_>(!#W2~JD$>cW zyRdYboRp==%?fnl*!i%Zs~E4z4eq@OT6eU*GvCZ-tmgo$ktVVcvB+j@d9~a$tlS@2 zdFdgT@7I0rGlgnaD%5O}yU_B35hw=@g zb1deyV3hc4JUQEIzWd)vk9*FZ8oU;?(Am_?63{!d!fra~osm}B`NKQ8EPdghx9=~8 zggC;RhvPYeYbMsd$@8M=AdW-R5jrG)f&P~Smk(dx5;Rdom+*_vELrvb_2ufC!CD!u zE9M4{VB3Z>ABqfRxV?*{{zyb;pZEJJ#z@BN!Qh%Ln^`!AJvr^$eg&Q1A4# zX-a_rOG{81S8S0(hEphghSQYYSkk9|;@tNp)B>-zC%7b)ve`Hb1QJPD>ZqA;}r3Wk=)B+<7@B$(1H6{-ILcB3vr?X+A{FAA=^ zPeq3ozp!&66mPCM<=xc8#wp8G(F*=kB)kMwF;2ykr*=Xv3tO+ft;9liAIMVsSLf#o zC3A!!id)XKb+xViRbcKyt_+ReHM5lpP9!$$Z@_P}RyRGY4AE=~6IITjR~&QAgNTQD z&v$>xg}KU6;U=GwsKfLil||*31F$c*-)~P{0BA- z(?JA4Jr1okMS2zoS&8y)xFD^%PEVgA#U?BxXP%Wy&BFU`!6VYp>6Eotj%)6tUYt5p zoC(uldf8NlLe0|tb!H1nh*|il_PDx-9eqdDunllJNZJuP{S)GwWZSZIkv`J9`Q1L^ z98gj%c1M<(%@T~isUZIf%_sBSOv(k(3ecr_qFxGBARIA2He*{o9F4wnN+@df4zhanT2HI z22K4lo{S@u(Wn&D*>{LJn0B{Zc4&r3TN2N}^APQ;H@bSbv?B0^qa&cxBW-j}?>`{X zorJIpx!xS-e#=eRJF7*?h$rB6Z`D{t zndQk~yrNo+j?||KRq_4CR9B`MPPQGFdn%;7rSG!$7+a{(eBv4bGY$f#E_CN3=H%PU z8!O{oCa`Gehq+D=hd_;<)TzyF~kKM~v{J+$&gAEKr z{xGsZ0ngQ#(D22AU#t+Q8z?mjyo}u<@glJTORI6lh^>Xue}#}jD-efS}M)j6~C5p+YzpiMWPKkP>K$j&M9#~4tivofko;D zBNHW4Od0tjQFROw8p9=%e6n!qiy<$M)GcOK4q`6?lo9S=6V7GZ>Dk1T)_iM=NuAI3 z;sk;oX5fOS(Q{w)d*Mn0qmIIa-~IgFMgxQlTZqCCTmEILT9!7iOai`zW?;Sn^*@C* zdYqIGV?6)#mHsy~=>k^QG^R$n-wDj~%xXGtu~$FI@uA%>hmTD}O`AQEzI?+2QY9EZ zR+@JdnHXzc2MDDr;Z4E8Kzv@$xh}6%e-XAc_6#ifL%r`a(0K1v^eGl=qCT9xqcHC6 zNe%rPU!M!d3nQHhaj>H6tlRNvC0$pJBf%Bpa+%yG=k31g7gtnl=@$^WZ+f@?8xM0_ z3f{c9%tOY*6I~N1vBcRw?sbxwpDTi;_(A33VDjWE;HwL-`$L*l19EajXTs*&o|w~H zC@0O&NCBB6AMplyTp8D-toyK!f?{HjcR?zm@~CO7+b6~`n0TxioAaZ@0M0&j-DI6V zgTI|Pen?(OwolJg4jRnVWS8xsJXc(JNHl*qx^2Gl_q{x(DPK}sO8wfpjubd8!+u^y~B?W;IqRv z{R$MjqVvDi5EQ%NdoI)`#Vb!GhKP4kI^#M^>S}6oZ2cQJG&l;=;eCazr57*N@o;6atvv&OYJ@dG$`{v228Xl>u+-_PeAQiCH3GnV{+M2yO1# zIx5v#OdP-P7zvQjhTJaGTU4BIXMox>WD8>OUWo^T6DhgJ7Xdb(M`I5bxZbe%pLr#3 z0b;`MhtK$xE!%vw*ZUCs?wuaH?n`{S#2sOK$cw6daRvyql~YE1>ZY$@a%JcvA4$Lm zIUs68ggCU~PZ=o@gumaAVs^k!~A}N-AH`N~`=(c&`S?|g% z^dT)TC}?o+R;F)CYYWtz{awLo1|GpQGW{WK&GeZD*T8v`yk;lmZ9vXQWWTMHJPgGqYz3AL{{f#Pc)aO1)ig+Qx`3CS z!Fg|c-a?ORX)3cB8-v5-&zR-JROW5Qz~wNp;glR3A)9Y94`@DM&9|%*Vn+H|!_fBo zt3G#8KuWftvfvlX$nRiVvd41T>__tMVf_2dRIwRrp9`ypdw19C(fe1CZh1H*B^*AG z{{6;iQ+c|Mfu@9RZO8=b)ru7PzCGE|2W_)R28Qb+vAVdXrnJxcwCd4QF%D7!FOlLoYe})1WaS91wm;Vi>7xG_ zAbX`*_4c}QRIoruQ{TaKy^>|@?0+unrt9|04xROcc;Q|AOgOAwk2wv;q>N+Vzh~9o zSnJI=VB7&kXB;22RM2UCij=1tg3C)?+4DQ5C^1R+(L1cv zxG}Kq?lbe~-PJ7aJt$y-?W&r5MdhpF?tSdVRy&4>TD74fX!Qcv3AxT<#V$3-E`E(9 z0Kq^6BkKIm4!b!o)ZHS6KlL(I^oa?*kC;wJgtD;q$DYJSH#aE3`%AAO)#UQx4~-pf zY@1UnG#XvCW*@fdWm=D6a`yZ?mv>vMebU1Oxryw(#V+2!CG<~!$U!0N*gI@Ds9|I; zd|jLSSl!!Xen5bj1oy4PD^L*QXyW~a6T$*9rzC8{ytnEi!HUL51AU0%G zn%fNHIw5C~j4Gp{l)HvKSUuaVV_Txp(`VlHA%shb+4s1%o^z|!GOu8e&vv;XYLRes zKJq|qb_BX&X=a^6XoHcAj0Rgop-_-XLiF=7p^@qvkG6fp)tktyKKL|dCtnh$sKu|J z;Cg|m>#1YVLF-Gf0Rbnl3Y#Q8>N7AwisW=n)!Tz6W0wcjk5$7QMXBCYV6Ds!9?L< zB#*I>=Dy0|2(FJFeY+eDMX9P=&f_tNQkX^Skk<2p^SD>;Ih_X5)UXdO>1QHRfW9~y0SKpS3$d+-C~Gg-#19+gYV006ET_JiVPvE^ z3x7Oeck2)y)`d2Eq`JMLp^#b(Pai#(Mq4n*&>a_I{QJ{+c)~k}p(7$lyhDKQmf(8Z zs-mkrJaq3|mev5f@xzho2C5I;DRLBIR}1bU}b?d3>)(-x)rvsZq;!mi>u&@tX!4%A+bv0 z@TTR7m{wnq=dX`To{_AA*Am1~1UkG11gl)gW2pLyxaL6$^|^)SSTq|P zcQnAJP<7j1w7p>$>0&$BeB!XloZ8Aon}P4wilU z@dj4OE@!j&SzGwwBhF_aF(VENCf3(Nj^nwxb=kU}O~$O8z*)~C5HPLhVlyT82&!yA zhQIrwc;)CW@;BRWaqQ2`tSq!VvqM+T*A;;~X!lnLCvKpkta0#J@%r;F`HRrml5kI! zZ834PhX9XIZ$%|vq_xhcL|A9NEF8&AmbO2 zd;5_~(AzV=|3iuY)TZx&20Bg`SHd2X+I3W(%$kEHcBrdB^LksV8Q?j1NmcMSL^Q>g z=X`ncIBV8zRbW{6t#}V7mRXc;b{x{ zk5xm~98FPUvnV1PU<4mwXA>zNM;B6jG|?118O!W(lL!{hcg|b}g>I@nUD7Aa77Zw+ z%;aLsX3J+{>r+H7f`t4V0+z&{XzoI65#1XcJW4}gvi9c(kww;KX)}I>@4Sx${mNKU zwM8&!`U;olW9;7OoTQhoJq-QL)Xjk;B3wE`8R@j~3|ON-{>%1+Zi-}qSf{-S@BUI^ zr9{YkRA=DPwXr2k&l>d3jL=p~x8Y@v$>$ze?Q|&5#8ORO$anGn;N}5}qCJBy`!x69 zfX}&K#oa-3&?ws@-@;V3Ft-6&Iy}uiM1NezF|Dwm5tJ{GtXM0qE-1z|+dtehZRG)# zpR|%smAO|7?GscYo#)~QT?B$;5nPGzj700hXbp`>8%`m;C%SQ8`<|b_Ad&}lA{4YV zqdQ$R!UJ3gzzL|hfx^^;F$KPOrka65i|MC|o&(aUKs`zP%ThVcbnAVO!OsS|)R#j> z2c=xM(W96$T8J@J%uwk@(h4KJ_aCEMOIZ0s7CYkn!K>~Xw~&kZ&*sb9>AI&6-a;q% z3XtY`CnBUkaVkWBhb1BY>65rbtx@wLq*J|C`TZhmQ{!1@q^go3S_UE4YRN9%)rT}DJH8Hn;7rjZr zb(_9`>q-CGoksjXH2V8&AK|Z}A=wn98%EizUeW2tvI8lsdrT;u73hKlg{ON9_qIZ6 z9pAW4L@V}JEP(9&jiL9FPt}PV&%A8at(ihqol*LbZ7s?M#YYQeqItwu@sA^C)t3V5 zz|d6&TV{syqZDq}D`kS*7wy8Jv7+alvUc#&4R(h<8-d%@f`LGO#L~G>v-A0+2$U29 z*>Lo4zx;!bs=6+?Dd?+{O72xX)i8RH8PWIox!t+2KCyXil- z$5G!p_AI}5%ETMEVvOszRruQ<3(`~X;`xU}9I5@biHdJb<~(|4YRN5);nV(pv8_?q z!{IB+^=+Y}rs_=k+#@j-i4ce(tA>DNHJNk}H!Mf2U@}MvJs)yEnMpAZeXSx0)%})> z6deuXoEqo%_fe0EjPzT4=nfQbM>4ZXo0uAIq@5M-n3N5Y=X8yXgPVh% zAW4Jn{>75hwtR5$SSpM8m8&2{I+be@a4Isc+ifK8a2cnrIige9gF=*&9nRM@=_9{wwHj{% zG(UT@N_wSc<;>^CX7=Y>q|}`5&@iWR!Dm#5s+1>#Ozf)8mZ=xTbN7U&i067yx*w@+ z+ubhqbW$ADOt*hVz;1ZP@~DUuzUxyMJc`n3b74?oGwN%#QZA%#3P~aN`a!pN>p;m9 zw;g%mA5^K!ezZsV&GA4r275(I{MVbjadM*LYwitVUJ_KZGkw2sKjF9g zFY_G@1Nq+AK7*V|wX7&cZ>lR?2#O}=nJJD&Ll3(l1Y&+29fU_#eY}xuFE@TwOrBXn z-=DEp#8Hb!i4p3)(H05SNtSldaKjv3!jO zUvat)Gm*yZ2LsnLs!(pJ2Zu#v6O_sBC=6_F^bWnxyQ8cY(;$yF~i;7d>5yu zgZSRDwCjMC&COoJvlOm|ym4y2?c&oUu2$12R~&&Db2Cw*rmDSO@|PHlK$!e}I&=|f z?=v}JPav0YcPqXowZc#Ctr32c+niOr%D)p^78i^!m|Woi;e~QM+1oy2~~$=n93+>?-LewbuuyPfcq6 z>er>EnE>sJ&K%;BR*U!~bmgIk0=e1*EArqc0(%ld;8VHC3*@y-(nMmKdLe}b8mTsl zASl&R07_Xgr7~lVqQni%h7E{pp;cqap5cb9`{h9EnnhvBY(jJDHI4gqr;O~z>w`OZoyfR)rQ+VxJ9a|c7USI* zd)4zxzkyKM$?q)F+s>5hi}CvjgmgR02e$6G>jGoPRg7-A{z~^NulmgKkH`9SmYL1* zrI}&wEA&6z)K|-|Ds%$ci|%uzF^jR38Q2Pnx_*6W#^9zzPUH4r?e_xrrDeZHFYpix zb~VJl#>h5;V4xRMo>s;^KKd=o>@A69M1 zm(bMxMvQUK$qyZWwt7cW3;DfwgOTgW`*UwEtlfUY-M}!x+Pm*^3dIS{ey-#NkdjK( z)3Na4+6ya`fPeISm}&<<+lVrMPO|4<>Qd)quBE(kT9o_I1HD>jIM-SjT|C(r?OkM| zb~g(~nrIf%D4rGB4<%*hnHShFl_C_oKIB~Q5cR{$+3d~qjNr=|!@-q4&n6rIyW{sg z(F&GRw)=fZ9LOrj8+h38a6X19ZsDALcw0>w8EGv*4fV%4r|(ZlSw?@CaNkw$nKLI4co-w!GA8d4(#A zqeqFATjWP~A@cg}t-cH2+3{eWOnumB4DjZ}v^!S$A)OC&p6I_dv)||)=eeCW+pTXkDJKk^Tm^5Xg?a8xe%%q^9TL457QXAR?RdyKd6-KEh_Mv0pN?Z(wJQ;~+>g71 z{Fs~Dg3W}Zy6PZVQnZDAp=v#?Z)&N z554d9d6V9H1>ak<#BlK3#!r#V7uUNue!3y=a`^~Ze8|FuL z&E?FoL%%tCZU64r)4=z?|c1Sv1tJI>&w$#x^* zy$p%YD*eWWqWcW_LL<$I$yM7Ds$-tw5$r3e7R#C9V>G+m*u)GgYImwJE_FKlYMiUL z({nb%o~HD{W((P0%9EUqkNU%Xz}k!Vf3i%>u4C@6>uCZ%$GwHpiK6|m;$3>)qGDwF z_6&Gb-)us_{2B-_dbZEDou|)o$6fNfPx)iIxz(-Z4sRy%aWaz5zkl`2?|t9kh_n3` zar353{XkV0N zLH8ZI|Fb^zYiek3c9`|oMUrxVyLtTPESn&2&T> zj!to@0fxNSO3GZBce4Ty4%DvpJLW9@blBjSWE=9}mH4sAHrykBMa)Zq<#FSr8K5zm%H*nikma?9})^N%@r!oa#> z9ylpZ+N^Z2+#G$q(KjS)dfR2Ic$sN_c){rRd7fBRZuLVtA@2xL%kLDDk?!?j?as|i zr|X`wH!78b5q&L0-`x^(+TRB~JPm0J4cGmaBGiC#wb#0DA*1pqOEF|m4K1-h&<30z zpHgzR>85sucXWLR0QF5y#)a>8BBzX^;%wPbUr?4f z6hW{aw4+>2-b>Pd9Z1~Nj+n0oP7agrT>Xj>xu5z_zO2E<@9F`^Sh*aIAi1z7KQWv!6?Kd25K$b`db^51cfp*0OCs+;{Q#Vl&oeLCRuL_6UB#n)qhxp*m$d`{$jVlI zh@)?M?7FPjH?E*TwyaFA)vK2vw5)n({2eVZZ;&c8(Zv;5JuJ>DsW!`-DuXxBG)$5ibJ#S1HxUb}l@#a|-Z(Dy;c-`B zg76AdyrIbgBdnl(W_*<+ep1%k-qr|3S%$P^-?eQ7}F5T7d!^YXiyXk{HPz zJYe5AnN(QFCn|s+57a`J0WDt3_mA5Wyl^}ykA{! zb3xJARc=e3CH=&k{I-4HF{3q+>4}i4q^VP@4;P_Rp&hqev}qaO=g#~a6`sssuq9t$_5h|T1-sj;5Z-t#pND^#k$1rA!ZKl5v`$ZtB#S<4v!XL_vT8TqoblVPVe8DPy|_{T_tI=MakB6hH+E~%vRwSw4|dx> zZEuR&NP|7;DSbTZv|Zy(n)s+@u4pCmJb_LNa)uNRE?&})wX7yNV~v~XLkD4GCK-@b zm@nvMFGApk-u~SDs)F^|!a2ddul*}_Io6GRVcQ(7t?P!NO0D(~gvo?O zkdfiNIah3J&hbSZqYf%K>V12bOT%w`v!Hes$)N||zW}TY0lv=icolAr&O@Mlvfs)C z&P4U+=Kk|EHLKCnz;JhVS4M_3787xF;Uv=aU{@=pGedn`-#IV#&ip$i#u%UXbM)`= zv`*O*2YVK?csWsgd@Py*_HW_q7GXUD%{=G|u+dNZGTf09qu}(+S=#5;fxg^kd}$gr zX76)L-7*ijby;LT)W1nlfP%|gfmSIWYmO+-p9hJ#FPcmJ%9Q?;cARUeu0OIj`{I1y zC|QEm<_BxsoqBoz*#~ZtL}X=e;Z`*!yLqEE!CZE^Q35EYs;O znC6<#QVkL1o}skwBCgiceW4%RP32fnn>QF^h^pF|HEH)en!*LUikI)!6U7Kv8TbA? zPFY?_5dR~mG2h>jjbMlIj;P(pHz6ivZKARn@n`wDiKkM^?S+aVf`$3oPBlBn3j>cG zR^8%9+AM!Ke4NIsgRwIa;Yb|*Vt`d>Wjg+1W7e0rwxX92{+uA@1D4M^CD{tYJ^`hE zXjV1jx(Rl}jd`)t%OIOurWSn)0ShvXWBQfZs}SM6El08&mw1OoWt&$IpN0e+EfOkm zLyye~BuN&E%|h(UCyewS2uA)j?S!eZFp}KVKYF1kDx|i~`DO}<^ihb?e`NlP^oKs0o zg}S)bng1;xMF99$jV8mxUkaOHw&AArOacEcjY@P{_7z^v=2~bzS0f=dTIpJ*#oHYugNt3I%{uG!f z8?U+$|90SH&~<(!hwf+;hp9;DAQZ+q!IjzTh9Nttq{Q5IZz*1jYEdyBxYV6^HxclW z;IC{w#qm`>{Azc2oH*Ez_FDmXR_y}V_H(IqcSx-Eg}&>5u=W-}akSmKXbA4^4uk6; z!JPnuySo$I9fG^N6C^-z2@rz2Yw+Oi?sg{m{(s-S_uco@tvaV>rmBl>x?k(}S@Nv4 zx)<|Yi8G}iroHdSxM1sFU(e1v`Iul&cF?Fsn%}DDF`MrYPW2Z@cvy;qFdwpSPu{i% zoOL|zmxVTGbKh41Kw)zIo?z<(57_$PB-_sD&c>cRw!JCCywP1tzS?reBPb9FQ7&{e z93!zMbLZsW_wu|S`}7d&2aDSJ^iW8ESva9T9InbF_sZSP6ReV^*L8nRa9YWmxpu$@ zA3su+qLE4A9gXXeFmMuN#s(=%ef1>uhQ8dxsuaRDtU zf+3mr!CARFs$)qL`q+S<`OFInzm?d7EvVj)S(B{Dv5MR@u^Yw8yoa-5Z!s>vhQu`! z0SDr^?vsy2&>t7sFv1q{SGI~9Z<)6d0e+e?Y9ZRuPY7~8b{H{ex# z{NO0_ZCMJ6hl5c{O|;9nSA<7qpnGT9H1*}5LS5=LQBQ&o3Wn-cuKB^#cne^3*p?*22df_mgzoB@OJ z2Okq%$(B+v4*90{^{;@>0H-(1IY2BO#AS&Dkl=qbUU=*j}d?fpn{~x&PhGxU2A4I!r3zZD*x9OQuZE?&MfY zl`?ttcj%)Z^iM9l*fq)Nu>5E{v-?fJmk!h~ZB_<2pE7@BMOsN{lhBbTP6O546cvpC z_g=uzAGQmqh0L>GzPOg|1F^^Ay9}osvN!s4^~8HlU+!x0j!pKtmVoIZS32-*2I1BH zlRw(LYguG5gBCbo$Bs~0T||cr`DSIhitx-!Q0P(`)?`gx(N|ma0pocr7EVa@$ZRJc zM9UG+=kaf=n*dS|oWz>^T6H3b8*vB+3+782{WxFlF<4^xk=4*GA=ndKLtJctJ3d<} z%YtLI%rfuqM#*BkK(g}4vlU|6RP8O%{mA{kDVbYXy8B{f1manRDbpgbmb%lC_TP#3 zJVkU#U|)q}8K{V{+0at~AcE3pD@GIF?Xfd5y*+^D4uz^Ug?9zpM03y_O$9AQ&{b=| zoz$a)8R2p7w31DaO88fSp#mur(hSk+J2V*xxJ2vWGCfFI5W+5rzFtOrWGx`#P|kQ5 zFFe(oj`91{ZSoBwD3|0wHk~blF_ljL61;po3!)9ff8T|G?~*{Flcd17xV2=GGb5`- zl@nnfh0urx9Tli~GK4}(6?+pE zF1qjqD|1zz$W1|I*0^gGDNu@O-ej!RrNB}E8 zB#pj*K+g_Am_oJn<$e~6Ur-cwafHQ=!Zto4(zFN*Zxd+V18^Er>Dr3H8Ve#X-{>EU zaRlo80uN4NcQ)!!<=0&ApcAD_c~FuzU;3P@_i!n}DdY7gv=Bm{p%ZpWIeqNbmN$9>IK!6+23A5iCg~lA#Z*aWRIG ziwC7gTjX>`d?ynNRy0w*U3QTKD^UHMz~ffNj2!5OikdtATW)he4os4OOtrGA7|zE4 zo4UOlv=Dg4Zvl#J7vYIOup_X70Pf_pF1sQ@GbrHs0whas>eW&>iQJoo#3~p83W$bT z!0<4Ca!@N`)g~iUL4z5@^P1@ayZd}ZzJp@(G2L>QkjYo6$Jjwmo}`+1lnCQ7yl(x}_o((jcH zAJjv==!lGqP1GU_GSoBQ<|B_TQTX|6TsZEYxx8?K_Zu%zzq7C*Xdxq|G79+du3zmS zC;P}2IkJ5EI%(T?=LfHp7g^Ik*fBYO6ucAv)DU;592(-t%U)9&s}v>p_9eDcp>GU+ z=}ldlb;(ztzLa{9*#4rZRUGSmj;eY{(`l`^MYZuP}*QMSHSzsh7+h0-AohS)AAX%%bg zoE=!d30P&Kv9lMu-~maD0iFrmXdFI^H(P`);A&xlNEf6NY4O^*QFsg~DkW=>rt^2u z=($`{@XWJBPevLl02E? z8$x$xziNIy4RR61in$N%jY>Pm=P$MK{TkUtcQLq~AAS;ht3V)g(l2h%Yh{Is%(5=1 zvL*Cb-gVuE*a5Un3JgC%W%bDyJrzFX2MNo47OB^!ox2K$a*f_GVx;$RG_MOH5<-V< zmlGMbXjHD)LB9>~Y|U#GrTpU0eXB5;13Jd0*Ajy{0tk6ROT1?}&X8cVrkH|=b%fwQ zVctX!V5I_Hr&kgkd#u*mqBJUatIdlPAr<-P`R5l>Lz!Yt`-#P|G|`JuF36cbe`iDH zoBLHzP>@G_^j88B7$k^L{{cU*B}MbN*~cyNwI^H|qfZULo0C6;pb2e}U65nhj*3p1 zn;P~)7Jh>$H}rGHf;?>P=ejkg1~*KsJ_otQrtEX{SayM3WeE-qygM?;04~IEiMzGk z0@}{?a&5ZOXye+?%2<7R_}xYg=oO1^H?&)Lq#=bfr6f6~DM{P8vWob}#n-ASu^N}W z{x}~BP*D|G=|X|)T{>peGB_i>WQ`5PZ+ikM(gaTpaG^N3UHw%i!KiI44f&nQ_?<>| zXjMn;aahW(>KqnC8fIvB_uSMU$+8I+wYk2ezT779Fo=sq$y@+S}is_Ywv z_Ei?1i#{e*^3>(QUYbAgRWsRcbcBm6gbcycuXm}zF{v;aPtZs}KAA($u>P>O1O zPUG7M4Tg|gr2zQ>{Q(MLJ1+k{A?&at`Op{iKlcKFra>UVyZ>;D{uL+woRF9PPluOg zJm5>=ZODi1Z3Y_mh)MpDlW+6P8PeDW*iB$Y*0H>zVv2l}WE15P{`p6;)BGC{V&tSl z?y~IaMk-HiL?9WJOo4bFu_)VWPZ%bW6%l*ewnDf`o#+Qc^49iuXE-ysf_lF#Y%l+l z_#5Up1D30cg9;9mMn4QTEW@|zNagRGlfaRBdIPKs6aK0IP%WbU*6$O@ulnqdcJ+6I zi%kRyGeowK?$^*+UQ+(e1)wXQMg8h17>UC{Ng-xgezcqr+MU@8q!NDpMJrL*{zen& z-NjlPQwL7BJ&!Z>3u?|vAA!Y=@@bn)bmP@N4uH(@FIh_*=84YnTAQzS9i3YHE1-%; z|5AbqsO@^49JuQ~eH-`QxUAjk)KMlv#YGI0#9~iKPUCcGdAZV-xp+74g9}xNuV(0I zqp=SkueWH@s?TU)W=%>ly6f(5Z%JG9NS2FDaGne70323KEe)xG)m$@T6*E|9Y>B{X zT$A+W(3hGyh6ryjBsZLyy5RtrUhPg7U&34vU3amBR-NNVq9 zKrb)D@U}U<`N4f23;ELfzG8SRSxa(D+^xqPFdf<_n^_dJ-^#b zB5$bREZCx`Sp`k)jA2dGp?mk_E{~#9#CR*QhuAT+-^qkOss?jPyoR(3c90zbA@S?* zj=lDxVvXJ*2T>vdQ)K61_%Ig`T6%}7Hqb2uu_F1ht__X!L~3*HI1aqlVb zdL%1N4i%((-{(+;3^7YRAwBg&(lGV%LD^Zre2mvQYf0?ZE=bbOi?a_ayR!HuLG6si zJP2fuc-I`(r`Y7y&KO1&TM4DCmg*bvlN|I~fKqW1!qG}e+uE9w_ydPvwUPL{)ds*S z|KE+JcFe&Msl1xJOie0%bFhe=td&3OOs&PR=PIz`4V?ynA1d!+@Kto!`tuO^B@JFU zHD`1>yjoUED_W{d##S5&TY|I|xA}bpB12|kS5YSXDaV(AirzL}&-!IYi{HIHhIm8( z|6ut~l_|1K*to@h!)Y+A95~bWkxAEk9TS;SE}uWI-= zsbU9n#*_(*C=f_}OeQ*F!_>9!YwMI5IzY388R1|-v1zb<^)WE39sfkRW>vD|uUBL| z`6wS9`SAp64(V&9#EGjn;J~8*2OIn4Sd&W>3~xV#2Jsd2MQy{sD``~X4_FJ5#U0f`9gr2i^fQSc{v3~v2X{8!9DqMr8;!74 zhO|YLD;jaC#iB>0WG|X5elZFcFT@mGh?bazVD&Wk7_w^kUqp>n+zHi0WNL9oth;0~ zPZcq4NgAa>>djgCg4OXNWh`hsA2kN(6eUI+#mItY1~KmF4}qNhL`Q)(KXW|TVoanz zw+;biL4@sGk#JsoaWud|g##Xtu{}!n+MHI?X?;8sN`jC+P5Yt*_3}^frg9-3O)B)- z9INvO{y5gt6StYHzIN`I-kCrHVt4U^UMpl0M6+9(6$LbK872CzBYf(zf@4^Q()gL1}l&n(C1g z>v`iL(`8$D43Ux!SgJ}j5uhQMwlME0nu$j~vz+y>=t`eBS?|%L&B7IPHGOF}=sHD) zysmRDJt+h@D#Ue-8*8icOn%lxOs}%HTbTlB>@s)2{M?YRsbFsq4a$G619Eg7g$b>O%!a z8S8}(B8XaRXuO%w`9?xNGZK~Pzo=0)z`DwciEgL3>Pa!1#j1oY2{r<7PyusVO4M8` zK$(FzANVO8T4uR?LyD4l=z1KV2{klE6vakXiQ^mP_ry7%Z@H>`N#hmLyZ}~JabOlB zK$(mmp3yDEGzz%a%du=olNxJGm@CS00?PeJ@HB|!)fT3S;BYOC-HsVpM7VJym3M>aQo2d6ITEZjwTIB&MxgO2TYQ* zOJP!QX6F|RU>vf^vN<)z@C}R!yqm#1wpS-;ZR1H zpC~P&)JXY84yNQ^6Awo8Rm8HNuOPz}LMQ9y!egU4y=XqBajEc+NE{=3kF!gfTI-1y zjByW8T|BtxZcP_8;bKk@1%Vp`A@whHy1)n@vs-{CxR5cbaarWNvMbmv!|SeD8)U>Z z1*)7FXzKa(z^+D_wCIjL$u|o4&f56JO5AyZMQTSGM(<-(&?cx5VUP&*!2xACEImW~ z-R~abQXM`6`W}n{_4j4;GG`?mBeeUbN}~eL|HnNzY$xLvrz)fYhAn^zgt$g}GEjkbarW7gD z4x{Ioxau5KK_E`d-&Ue=S`pr^m*!1dviYT|_S9Cx2T4EIA0NoMc#uaJhA_rNN%?ylg z9)4s9_S&4MVI;;MHl%}%%Mmm)++U#vvxs_<8#cTP!}IT=p8C1_B{%jtzDd$(?Eo?k z)P>m-k@htuLM~K89Z?j%h=YMPX1_(cU^SRFVlxAs%wHQ%k{rN=J$;*SgV@#;R>5E< z?i}KX%7*4q|Jl;z?e^BZ4eWrR?2jX5vA_R=LS-x&|97CyE7?NxbfN`t00sDe95%%P z_j7@N9s~XoyZ(cZ;A45|uspaZteM>gr&ouQPE!2g;%JvkbUSMOM>QN&F5<#R+i0FM z7&~pYQvfl*{{Iit*7M`de_`4>S-y2r@kjl5nr-rU$;)|b^O(;da+JdK9KD}|{Ovo& zD3RLYuC;DH}il1wy3nNV2g`xulc`Ekdm-Rtb-H}@D*P?3uv+j!nNn3-99 zd(95^u(`>GN~EuVA{p_e5!h%Zb23B3cRV@3$&!BB{m5t;nV{hwWHUTc9vR<>UE?40 z?Rc>FYjxq4cn9Tq&pR`=fjus(tWS57Fk-aBWG9Z10>9k8+Y6ts*dwlQ;!HL$^cy8vKr8Ibw%4yM8l6LvuOZdRf!Qa3|wl2Ay=K+(RhrTS7#DM|` zU-|e92SKK*&;lF(ED@HD7Gqu4 zeA|1UA+h>6>)VQv3C^^i6DH|~E9HCK8+Aoi0m`n|E^GdVT(Y+>zu>*?I>fz31EcNT z67SelT{TBr)Sk`-g*Qv}jUbQ(v$Mgu#3< zaY1wqbo0rsIrXWheClgM_VVk*$Ce{D@kFZmSqJkiG{5t&IY^%gHVK=!HuQmsuygoN zH_LmAQ&D9)+;H<({)PDmSB3zo95?KrB@c9-*J{TZqM|dQ-4@j2A zh!F0%hCLUWHGkK#ZQK_4x%;X2#89IpD(j;rbI4r4PqWp{z9tp!gdis4M>B)HOhkDT zkK9;r5P`n;@x-&QFW=ItD1sO+vx%1%)g6CR5Q&1$_joIC+?h4bgrWEsYzzqPL-)(o zE!1*;2{-Je!HBuY>dC;(X(N>RTF~p_>SW9G$k149Ey=+=aMbY+VR6$;E+_GH;PO z%(=4|i7ZOzS|_t#po({6SghKR&M;sgIhi?Rx?VQ~5TB`?uX|zsIOPP#zsTaR44?Ob zMEyxcy=U6t{x{w_SQkCE@u0tM=1d4-1Cak9#nPs>m`S{Ug=(2{+d2v$KDnx)#!V~6a0+BD)KFYz zY4at?CP>VfUAEgwq7t(#U+MaD93}?4GHX;-t*E7aAg_^^M5eVPv1%EZ2 zKm=#5*W}7VGtWUwffyT;RH|p3Ujfj8m=O99lbf`|tw- z;9`IS>6TwyWu)CyYMXs;dCfxpFn!VyV+3SX@X6%t-+L$tVLEJ&m7I!3-}+sizwGE|7I_P ziL5&RCq!1NLkEr`D?(u6uT1q(Ei!+Ogl??c@0_%s?dl5?y79*1ncNGtkW5FdDyBG+ z7pAZjoqrhL{2y{$FAhHQCZl63-kEa>oOmS&#f>oI$@a`}U6ot7yWXPVuP~14i|ZRS z?Oj#Y+?bJgJASmN?i=953w;eaO3fKEvDPmTgJp~HsjG85t8-V+;xT*GlTBBQURX+2 zVV$Bp@;KXqav#kcs~K=ptPD^F#{Hly^tt{edEBPHt*eo^G+TYOx|I9AA%FeY-g&0k z_4zUN?);E`M<97gp)Qm7CQv0zBY%3hlMsT&6@$ZX*J!1R(xZ`X>p6g`Li`Y#in1_W zJqu(W@C-LD8nPeOsK4TXl>N_)@Zr*cNz8cfuyms9cU>L&YXHzVIpV5artk7ZB;QGk z1UmH%exvSzKt)Q`u5IqAN-Tz&TxD>Yqr`#Y<0QyeZE0~UA=qlWqCUnv54n}a$Vq-z|+>!pKUmE zOrDccQ)AFz!Rt}HQS-s?H0?2;jQF@EKtg(Wei6;qcr_mSNXZLw{uDRYLwd+$v+_IA z=~Rkdb$<{nCyq`Zb#!~qNGKjFhC^>^GESPaQIIul>7v%UJ%ow-^M~v_7SD z$vWgw6UuaBH{Qd?$I<-`@YtP6{Gq9M8wwX?G&Kas2)OBcHD!GkKtC5o5Wo2Wu7EA>QuyiT9_*@2SDXjr80fWNF@J5B&$Pvl9)b#^n#K zvy$r`?-%s@fd;~6D{1VwXIrSXM{sswe``oYKX1elb)Uh!rfr;WD6Jzuk9$<3HMJG@ z8z{qlFVGZKRoP4%DA&$-zL%7AVB~x$y;9mC!+ATmvtwN8e0zS_tFR8wZ&uhj%=ml_l{DLa(OvA_!sm6X-Dksz0&wZ0=F~9# z^wG2GH}dL-7F$T8K09o{``Y%Cn?x8K@HS8PKe=4@1&=2FjM(j8S}L9*Ml?~;%(W7F zwLO=+9e^{4t7r9H*&kMFAefcfJ85}vA7vYXqgqZWO53S2Z{mbW|XT%0TX zlWNt=9LEQtYum=1wTR+Z6EJHPZ+d;Bfdc#Xw2$MUA+~0z20_Yokw*K(?Hl_Z@JAhz ztIi%J{Vyka2AM(Cv!c_hpH7vrdN-`TqqL(9GcP+jm9?=e*<<&PAHz?W!kR;GMZ8^3@@cDAQT{#ZT7WhU*!u`6dv9vgVRk#U^=ZP8dueIc+|Y$#YJ_=*)FwG?=TFdm2;p^*J@0rOolI(TT=#F35=$))pk<4 zL_$rCaaaZ;Oyg-og4X&LLp?HMHCOz1>OoAR9=?qK7t^vU_5X`$$*1w(39Cl~`ON>D zaA9U|IWTVjZvuVa>fQG)Ty<|=-V7{Ke|}oS)mg<|l+X5%BUU-0l9wKuYG})lvqrm~JF3F~&ytHW)x1v9+K@bQWa;nsfVZu;P0<>hl(F zGjdsAt<#cNF>!SPhw9_Xu{XMKCtxw2&Eq^je_wFJu5YI(Yw!jy_@O?dq~r3k3^RMC zJC-ZX@$TeEE4L}8a$}~W!fr(7*=t$yVS2@2%Xxglvu!rtXKHMeos8qUdP{kk-66iA z?t!tRC9AY4k-@$_itj7wo`!*Eh#hXt5s%L=^BZJ$r;!AM`XMx_(!;VAC@3L z%dMy=)LD<@UGC+n01V#v^lgZ<4{;U21@~&*GUdI|e&@3qZ)vwR5Zlu@_2Wt<)VmOm zKuUVpNba-!oMn=y?8IPNEhpET-nv&Ug8xRpg55fA315@t0YdJm}CW9qG7de?B=2dx(3xL6gKV4AYjX zY>rZ}X$c+v8rJ+a)KfxzzcuOD06)<>YtwquQ_*40>?v?|_0v5QWHfa52%*d%hw~8%iUVpWp=VTDTN2vhxOkmBu`-edyx?m3PP*j8p7z@zbmzJM^3n5vd>(g%P1JiawHsxzb2$wHf7c^h=ZDWnSZqzPV$NnDw6E>>83 z@Xltv#lBt9s4RG{8C>3V*b1E45~%s{-M#DyT>Bi!w?7<0S9#KnD`3}duAZH9S!+Ku zd3Ow};6qoTQK%$dC0?1xI|)*zEoZR|2o!#zYO-DI4%-Xy+*potFvNmn$Z|F7|9YUY zw%MNfbbpw3y2Y}>a&gC!*Q~Z>G>)8=k-;nB>`s)zmtxkm2C`lI(0-%u6TR%4p;TP) z`24mza>SJTN_uzE5L}2xDgCEIqo8pMS>A4~T^NS4i{q^lgIDSf0T&4SDf~TGv(b~? zO8*B81M4^183Nc9Wt9h2y$6U>-4~Fwvs|_&Zj86Vj<>-JusX-FT2dE-OZKVuSpTZEI^S1T77H$aClcNW+r{%pf2S2G^=5r>4@<(SrMPEGs>YjsyNnFj~@dpL?(x zP+|;bG_bQc1zi*lCBBi@5N4@S`t;FKen!}SUuiNOoUkWW-hysFtIHAB9YfOj%^RZJo+C9F zf1~9Y@q+mt&FhXOe3moTMkNF-DQWw;xm0F{vA;qqG(jV9n(?1WQhc(}H7bgJjE?!s5C_?nG zTDscRqzlzZIUKn}^!77%sSLJ}tU*w&SK6fe_3C5oBMMX9u&<@^hv)w8sb? zZ{j$Nm5#G(oHDl2a>0_x@m63zsS8{y&f_r+6zc5;b$C=nd>#{X?nNE?c|o0pe)micNE|-m5NO~ ztUgfpZcnb=ftnKSd@^0wBBMwveTZ`xb;xeTlzl&-3FqAaTlUk+#$@Z-aRc$NHt!+ zGrViDOi@vy@uN#(v%}!Z?WGFgOJEic;}gs!N|xR%VjN@<&Y&KyaZsik91@{(V3(`3 znWG9$=LffjNiS?Ashc)8YHl)c>;3BkUKhY^E8$gsPs+^x!x6!-J5}yMyIg0&sC0qQ{v=d(x*cDame~g0tK!#{eGu)0Z(c*i zeGB<9DSF>QBCziHV#S@|m6^mD4`3RO_Nx4}o5XHMEO~Wt%SavyM`X_LANeWB#w}O| zS9SE!Q`P~q8T3wQcngBT3qs>`u|ft8=qWXhI&iWYlJiLGWkuEN5?Ly&VkM9ctXs1Wu>xQX1%deA>g=?HRY z*YYk0;JIl~o{n0d&-K=LJ#})=yVa2;ZEZCgan2fzu72jKs(BPH*Nzh*9%`J-SRU02 zvhR{^SltUhTXX%?QKyCb8AtpIS{S>416l$?n+)P0_w|RBX!uCbwhs(Zc4N-MEZ1g6 zS^m|<%-&S2>8*JsGjZjk7m{ndsWl6|qSrSQ+q(?_Ca!;TaI@@wF%{36gO^z8I{)Z5 z>~u95)+h$0GPmq1frVOt;npoluVd8YNZLl3ZlIDX(uMhPtiVEqOQ@N=gJa0AjWFExr<#q!qT2bbuuU-skhWp5xdIFSw05C9+ zDMppx9dA87lGe14Wtfhbjz2)S(NvvDkNy^%4%6?HN9LKNOli|9XFx49=k&@aDm11u z-^qV_uUE9plE#@E()<^S?UGHi^aHfKaY@d+d)NFfDC9qFH87L+?$a%bIxqv81f;dq z+X>zPdm-s)+r$WqyIC<>ZSUD>FL(!o zmaTby(T5nKa8qDx35OT^D)ASy!a-KgjGMH7kxU#1B&qo?B*R@pSMS5)BxFT=pQiq= zOMwm-s3T=;*K{L_1FPM<^NIC)w1t=RTjg!<@9rT1u}%6en89eq(|9L4GymSqHxgnc zBTm=cZ|l4Swf*R>iTg8b&Q>!M|1>k!sJzc$DuJcw*UI zzf)g9)buU9z&fM-g{>KBKP7Sfi=lVTTP}4S-M9{PM)P2YDGd!Y_eZ+&F@u!37|#oP z@gt_QPGtI&{oOZjeGiMAIvkimdE6)<^1Sj!=664-sVank_05O99iJUsJ&mgN41f9n z-vj4&;D%by+oR_EP6xtTH>ahY*L@v$u_k48#(dur=X13EfkC2!`J7GB3pFi7VKcX> z*8s7S7o_~bt{~$20=H&qNxrRKm!T`&kJ8)5HIl=c%*e$Oka1 zAi-|%m@{>;;s{U(Gx3ZnJkkSb(>dSKU#LbTr-o}IGI@j<-K6JGf#r+EToe0rhq&Mt zx~$0Qk?Kq2oF7!g^g7%*SR1wc_^!6cb&I)&{ljlh)+FBv;W=l&g%^Si=SVb6S$|3H z73r1>tLY(HX1|6@R}XXhfCW_0&7$x--?@Qv97)i;kUagDLTud_Pwf)AAhrWvz?#)@ z$IXYms;f0GLYm*XK?}D&*WFHVP1pXVk&{s}j^3;LLIECM^B;7xw{A)!pln6K#m`^FqpB*uzPYJ|d}(tmB;b766VtA{X}1@<5|e@1~r{^pPnX9wPS|zp~j}$(*h*g&g?rS z{&th1Sb<1lh0j1tg_9N$${*k=#zhaZ!=}B^xQbgA!PEZ(FybLeeRR-c88*2Ua!7SGtQ1Wqj(rMs_2Hs zD@MHdr4Q*_o$&h(T$u(bt^b=S)Ps@H++Z^Hzf9<|H3;HUa#10E31|o-$7+PyZQQF_jZnbOytU4=GHC& zz^#4S4KSpc=m#*ninyr7E&j5)*M0WJV|a~b^_M_t{L0$HRGY=_6?`o8aM1L`v>Z_! zzF@ZOco0pt{Th2prL#2k6KCR|PLM%1LDHC;Bv*Aux5wnv3A0EN`T+BmqGnq#){^9|~zdB|#R-$|&U>6@=sIglS~sF&Lr&X51d!lc1D~U>hVkxgg5dRgw@*?&TDMORJO zJZfUXCH)Y3y|AWcxSbhC?b~%E-&Kk%S7iEf?8?sb#&|nxq7E8Ha_Vwnrd;EixU-+( zxU2V*2%mrqX-4Wy0~MN|NgN!sb1A{KoltV42#-W}atHUMYX}r}*gr4FB%SA{F_H}K zBS^(uAqiD;_vFFCA~l_L-VZ$>-7#!|hv2z%X-WIw>c0TJqs!W6>R3xKTA@XQK`q#` zz1@n2*}c$e?8$aD)?c9?kbz0#dpikEEtdjgJ{uRMbR$>;%v7{U_1qlReZ6jd{Shk98cHX!wQ5KRRlX z8fEJPNZQw`Vv_^LFzzFzM0Q;7=64t73^_J9uP1Z_eb12Rx!&N?5q4j8gO|BI&7~WY z*K6muk3khG^uf(gX%^#mD$wY|cD4il6^V};K826(3lb{828wX@7?5Q1-OHy}NpFOo zGm=jCo0y*|+6*Zxtw+vJJt87;q;$WBj*k&e`CR~h_)_90Q5vKvfuHj5Q^+)w{aUSD z6wc9+xg#5PMwO9X8xmL|mw*a(aI?1I3Eps$YGy zHVY@r} zfVg(C zMp()8st>)007INgeQ(i?&~QYNE`JmsZ58mq_bZZ#T=+V7^$`?UWE>xR=YT2L*rC+b zSRP$zw|c)bh=Qhi(eNK8TAORL<4SDq&B;GS|Z zsgBwP3fYhoYszq>`J)dHSRrB57eJX8DUPka$~V`+jZ1HQzye1_(k3o{<7q^mOvI|j ze{+RMyb?t!^#2sRW%TAZF@$;~Mm4H4*?UZnIJ+It%6eoy^Q(<5Ca-P9zqox5Z&V9| z(tq6@thGCEw*2JJ=jbj$MvXR!@Nyzx5@okYSegr+hlt!oqXVJ)9MKZ2!vroAu@+io zANttji7Z)f#Az#%^v(%SY)7YzwJ2h(Ik5Qi`@^oi{8s1H%Q@We2f+cUvE;%K7nI!L zkJzNf^K`luibRwI86x+PSwOI~k?}eO=)UX@BDh3b-6fGh(R`3?&<# zbKSZpH?!sA{loO98*exXdrG$I>~8s(_J@#k*xVkj^XtIKk5dWP| zlIZC(Ku?d^^NOkB#jICyBcj=6mWqd^_Z+DKs-9jqvnlOz)X)CS7GFTlA~OlXs_Dt9 z#ydkuAYy8p?`WnR45=Rzq=PP(pgym52|2lT1J7~44yv#+w-+94ZJ(TcwV%Qk=S8Ln zP)BeNlNU(FvG1BMgj2|htUptH+Z=5tFy29M)))z4n#(S3F}8ok^uIjtCsozASS9^E zfNTDe`t~YBYGg3s!F?_oj!w=a)Y=fYDnRWS)xGV~vJK@1ldzDzHiu)jFRp)*e5>LaC#^o+8MXp`vY?_>##J|W_&y*;qUws; z#28y+DbF%LA&26lg?vkb5MOn=xmDiHn7!1I(+%`BO9*nG0H-DJbg9TfmRu!oa##G! zeX`xAg6cds)#yZ0Yjw51dJj?XOQoh{D_V`H6;ZIuoy04U)Zdme#o}1Q?a;~OgoE?L zw8v$~Rxrhfs#%%k3pa|o_9C=2R4}N~CjPvN@TN%CBMqT^xV}N5GhRsVqvP+xX+asb z-=LG<7~)}PoyfadEc<8uG?Vx}9esK~?_Tq|D{*@MV%BJN*xbPZQcc@Y?{{-*GkHahcD1hRVeQ454et43P`&-Ex0Ez7|QZsyXQWWy!999S#;*rRJ-__yi4HlZkp&JkosU0~qbJpjE&0 zO&SB9k(Tzzf~De71~_BgpQ#^tCZ^aLWIr5Xi0Zxq_Sk3A#O_}0zTsNAoWNyYV4$h} zmYL02@sQ^L3W>`x6}hW99)EnxM_-Y35{z<%Cm#pR&dm*TQIDt^e(1QndAc`!VD~v- z7czaLts4GM;B1VS#5E#kE-@=@w_F#3I)QlA-9)<4NeiR?=gI%*=n-Q7-HeSzGD{U+ zrZD)xba2=wLJxN#5>%;eJbStV86^iLDRqr@UIXlaN1# zXz&#jPt5I<$JEVV>$A#}_Oue7h|GLy(bo7q!mC}WCnqkzsQE`&i2e%H;_SAjqN|_L z9O8h73 zV=c*WzD(T~bNLNUElq_#4N2pH6fW-hJ%eZLNiWx_cAeqphLv_991zzVktm<2c4GT` ziLh{VYX97u_49a_4&m2m>AUlt9wuEN>u<{)wX1epJH@j0vd`yX$=WcTQZB_HziNZN&dW;Su89iFNSV%(e? zyJADzjxiGMxdw#om5gtGEQXOt3_6}s(OpC{m!IC@6f<{41PcDZ>V49*^7H^sgtZEZ zz>zcOLaZMOHezd>w^+sZnrqvK3t8GyY~&0<`av%+TG?*LQSer$s$cobrA1nzHub{T zf4XO@N*IVUhdKXYRb^$h-lMfL8-d2_z@6sdWY;nprT6*N<_k`*ML;yNS57W zk?C~B^x39(ieIci>=ampKi!ilx!CwJOPOOx-cPurIf{5!)BZEe43xI}jNrEYAWs?% zUN4R!kM^G#P`$7CX@vL>nZA7Z-TS*a#)f2T3_QYe)~c;dKQ}?bk0W~ z#Fjs`bMcN~1HR57s~mQbTX3z?YpdJVrpK0X0-ST4>XT|FZO#U? zLa$x{wi{0j%S=1aa=|H#eR({KHK+(t(O$=FYt9jyxG#A|KI6s5iP$_sldwE>Sb~#K zzxO>Abp61a>Dmc8kh+L`-JmT!(3mZ_epkViXaBvq-&JMt!9@Nb0N|8J@XcjV#)S)W z?2wMMf5aBNH?p>XU6_&~>ot$@b391;eYuu?%jFYNlg4;&WsY{nF+|m0vyJ>*iT?4p zj?~iHVt-O4M0iw7p-09`4?%wz)pCxVmaOG=A6!8Q6x&8oXBs zI)AvFq{Kw;JhGME`cG-e#k(AA!peT7y>c&a0@{e!O{u~3tg$_5`^`*`u#Tes3XBVc*4MN<<4*Qlx5od-<`{1S5e6?LBlfb zIjy}#^PrCXdfM=3@Tf!R3Y#0m`+iGUQH7SVf@VN+SAz6VR&PU(Km(K{cqre(pku@S zvmtdnvVbPIl7_}9u5y5eAVFE!7pfX9ODPKd~9C=Dr##s-)_OqtKz_XPuD#!kD zJH6PFH_s+3vW3>VgujQVZ-OWFIQ_>(hWfWnMo}RcCTDcg_o*^a`;hIgUTh8PXhQtf z!7hSlAN7{cIPLBg<-{nc6ZI!2qlLEd(~d?c1|T^*RTEd#)|Z5k<}ES($L>fF5RN&? zE4F%jbC#zrdgXDClcs^n5-6KXvi_@BpzXa{|DEG$k73~c+8rV;&ecQWFk*ZkhHN1r zYQYv6&6&pEYgONj)0ra+0z()OFvUkW1_%eu(5}c%VpW98D(FT_|1=AnqtzZP>~tc^ zQj23CrV2n-15LrmiQ4PxZt)D(VVLg6W~|@NG7UVhFvYMfcRC zi36}dYCDzH_5*;gUzu7O zRIa;X!#{}%yLXGIFG>rpzN2DvdWWtVB4nho&m?gh@_b(JgL}WS@A&HMs3R%0u@HG8iOTNEB_U)*-R1(|&!QsKa*T7j!w%k5<+$KIJj z3v=BwgnyiFw~`R|W<`r-EbGM$Z+g%eFq@Zj+G&`S`c)KoQnGiff>1GWNtn_ra{_g* zu{_qo)pyV@SAdmoN6P1XPJ5U`@D{JKK7wU(UP7O^Kvpy)5r67rN9XUaVez;jjfD8q zxZ2hzM58i{@k=&LuwPqCeS}F=N;-uyed^6X(`$n>xQ)#AVYAeW_|)c~sK%1)9d$Hohtl!Hw0H@!b0Ov@l&4!H1TFvOcz;AgPCVZoPkv2Za|&5y>P8|R2!xdWLSfuPtHcj2O~3kjN4EIi={5hFOrwD4)*Cp1>Ts>!saK(Kt&t+FEJ)+#n;I&VXL&5tBB#&xV^U@a z-MXOO%_%2zkB99|3%WqtK4i4fBK2v&-dIuZ-zA`*59eySixROXN}cdWAm#a4IYaxZ z%Ob%&0=!S-8(~i`mkblGjq8g_sG)E>h^`+XeJtnfD@c-`TU*%7Q3~uc#>~TY-jeyy zO^pgk-;oi?5pKQzSWgZa%_p2a|3zKRSCIS3OvCAujYn+bj!*9hM*ho9HJckwNOE1! zWTYer1he*Dfc6{z&a^zrnB8hrYeAsf(%%e{*ObSrt$rr{b{)4x0O>rt{vTrS>WDLY zbDqFN4Z!%K=CUYrk1m*qDWp1}w%zDFcgfR4-@R}v_f+><$fu+&d zoahEp4EZA^Rr623J7B;Awv8}7GBf%iJfJtW7Ip+HIr<8*L?}HwV=Ce|ZG~sI!JX$a z+~nmr^{hLn`>z*GuHp%_@pWzdv1*Sf)0BhU3UYpKz?n80bGSOW=+-Ie<+GN37gvy7 z9TBDRf7vT^yKSQ1H(3{pEAF3aTNQn>O?pEX5EqG`# zN?bZWKZs-Z+p@&`b3K*OC-Jo75M|Mc8-+-pjJI|~tG^ufbLjrmf3VoM+?*M~;#(cu z7Id@R)abg;Biw<|DR7Mr=F4~ zt#tikvH0h##I7WZl|4Jb&T|^ntKUKHo$4M96y#p>alT!_3Aqg`e9QW=>(Zufjhmhy zHG%uNq{b=p;S<-Je(1bU>Eu_pYphz=Y`f3&uU?kGZ|M*WgR@{-B6U8`qi0@XGlT0| zIBIuY<20v5hYb+SdmeUmiTRcuA!e+!*oZKU-prUb;_DyNK@geKa}m6pW9_^wcFGu8 zd=#_jv!c9Rrko&*Q-3A&n_dkWqbaOX$g}Y#KJY!fLeShORYfO2a-RCg?mG>=b^7i= z>wI9!`11zsmIjr#S}ui!qR)_&lb>f8=y2HPKpQPq7q|u#Z)wrIInYpj9u3g}EpHFX z+|bhH7CT3*g!I3!ZHZ+to$M~xi5oOyCmS0*Yz?$icQI=dALOUwCVkp>na?w|+1zPc z(%Sk4Y@ureBx>FYkXc$Knl8Wc3o?|QJM$wrGq8+maUr=*x=wvoplD!eBoACTBXBJu z>3_iucN`LR7|8qhs=w}y=$!Rx5=y%N@<8+p0oE`Hrxf?GcZR3qT?j=q7lMdeJIbY} zXM~JUa)Q|ler9lZbyaFJmnOs!R|vcu{Q?v`=Qc>4Xc8VP>WL1)SCzMaDi6z|;5;lT zyyN-X^&<4Pje*FAB%D6hae&^vw*M+LwAZ<{g9;=*W0%oI7#pVghx=e2A*)%T{K{w&Nq@~@%V<>nTap_Ib93KN6euaONpm? z4=4 z=G(C!_GRbxS_c$24=Nrs7TCnYV{7j$`j!eeB_|8iS%&b4+z!{@M8?Y|R z265?&>4s8Y=04q;y;a0I1LOoY)rV{wB1q`O*)~Su?Fmvr5jU*}-br~q&z}?dc&1v2 z?$3H*S)PGw9kqQ~E{Ga@)tKkwmsc;>qp!C#LTrC(j;Aqa*1stoOkt&A9>p!Sc$1;) zLr8K8aK~Co_#V?f?j|arqK)>)G}uQ@xi59qy^7n!+xhd^TTx`a$S70-7$?$E!`Gj= zDY?skA2p$#1Xe_%y!K4+W-LYX?tH1@R-y(j4|3Ij>~Ksi^beyiqlt3Z+x`}UWuKnuza$)2dHRykk=?ibIz?e%5AWV*>jUt9m7pv-jnD|aBu7|p9T3WFxWMKS3hpI+^BSFpA-g0c78 zKi+Lluq19WhZ_)HAB;~YVgeZ*rY%_=K)3aS=BWc$!a~NLrb_HP<*DHZa!u0^s!j~L zcNupWyrjLI$d`UdIWF&hs#?28mZHD(>EGZp)4NSJS?_%><4k3=G(Es2uIW}nGTj3o zJu0_{c2fmHLP@I7FJIi2E*E2K=18ISj19&Z2T-*dVioiwZ?KpL^N#r64K^V%1FthJWlWOsh86KJ!I%gXLmU5*Jl zj1_H-3XGj{Ay*G4%{AR}$i>4BIj%T6pA7XJ-<2T$Q=P^YdQx87hlGPI&@(10e4-Q= zw~`{Er>GaVi<1KnkiL~*v;u|Y#|J6yvF6J9TTLNa_@VPH*M!iHcNui+>+dd;sC&yY zKV`_olx>29a4$sjW#h3M<{1PlQWY#*^?fN*V-22mEb=z)?;(Kbx0>9KBN13C+|9n9*8OM3SCGBTHr2S|jT- zI+=SAskKeb><{BM{j#Vx(Tw)%4Q053LpOJST&UJ1Zp{ZK3BPXS^m=SH;(6k||3}lS zQGpk{PM}oFo0)tpS&1%Z<}p#X#e0a5hU=K~O;C74-P&K}2X4V2U6!9agIXjZmD7> z2NnrkE_;6u5kFKE<#=H$PV@p>;w6Uh#FUu_m)GK!aoUL+6n7yyWk3VuGPI+#fBrd- z3+eD7v&8eP_g$ofcR_~_wPytA&}QTyXT?o^QB<`WxjyZ66D>U_#L!GY$AI+I(jD(F zFP@$N352Aa6~e)kriSF?q=d9C;O5uVS~gCOk<6QXA_WiXi6r>4e#KK9RROmYBJj() zFJ43RX5Fi)#yktzfK-Fi=59+B?8EJ{1>Ox1cJsnjO+cu^`eQ6DUIoTj)bXBS;jEVvzs-u5%E{fJx(2BQ7 z=^w8C1h>H$NQiVjSpRfP6ni3$@O%n}?QkVoIl%XnckM-jt}l;so~}|K%gPoam(QpEWfXuyi^HAtsJCM6LxPJ zgu`Wjvd4}f!JPWbqU4umz=s)}gBE0xG4Tc-OkzaQ?RB|B^(xVb%Ew)u>N2cs0(+gCpxS$BBy8jiukwJVuZ(!x!9tt7>=K=NelF&0B5pgSnE<-ub>`cmO8z*FiVh0N<~->l|CJu zIUR*AhOkTi49;gD^B{mrfX+8*4);V^mZ*WGC}s>h%oVsCE~-K{u`3}xD<7Z?*)fMa z+An2-0J(YZjR|#&+g0gCucUx5d$+z(*V)PnxFVMEt_CoaiA#FN_@`><|5 z;j7}x2Z|^>Bnb|%8;j8PAb|XsZHu6Av+7$z3KP*9SwdIts_&!0&%oKm zp9=1f8-X-WHa5bDu`AEa%9nv_mC|}d&kQ@m^{&*)J5)%yVmkx4RXsK`TT!-H3*CdV zvnmFloEM$rpV1{%uS+3~PlVNYu0nQ;;9APQod#}w`?4WdSE0#{Mv;NPnMjW3MP`ZWF4~{lgRuNgf&gIF+&R5Cv^iDt<3?(G3zceb# z3^$8L*0(fdIfOX+GAsLIFxg=;dm0n(`HDZ@G&16GL#sxz7ORU-=;X?|ZMJftbxXa< zqgo@2cpU|IZkd2#`E)0Ukkq=oOTi2B;LL~;L9-N(;uidPBI=r7ouQ9Xp}xNUhIfdq z9lZ9Qo@e7Br1N#>Xd>&6xprEiCU8qr%-SR2nxlw1DCP`9Um%8k)F{n{&G-&>ES=-n z-zLhM!?>0nB$d6Ac?2di{w7Vg5+P1q5Hf!-_)U7fJt~v%59bBwfB(&S5vSt$M}7Mv zul_S=-`vxb&354#c(w1oi%IFBnms$A^EZ^W8=MSR%8#zBQEsIUS zksbE`j#m>^T^`e1>OaAi2#TR7XANhY0|cIu%%Lykq3Nm?_mj(&5(K|@!udP;ba)VX}-!TQw+0M zaAIUg8LjkY`Q`KGMCDNr)40AcGO`tu%cBNb6`uEb-zx5L%_gCV=b@JneSol%%u zCSK(+x%OkQ4Iu4Go)36jk3MAU3le61AKyCfUxx>eEN9>=Hj(!&@-GThBavu**Y?Oyr-)8Y0uK2~ zjHl*#Iw{@UmO`lKd_}o*<`TiKb{L3`9OI)z_v6J3n$>3&`z<*E%a< zNm!sN?&S~PwKOGmcb9+lv?(ln=P<{FQweIiD}hk}53{8lD%BWuJy?PvGFj}kAxiBZ zjlx~Bj)AB~59h-)Rt_C)I4U+QX{iYhbSC6qx){W*!69{lJf(p%v-Hetzeb}|+{4tF zOznZWoURvV#zF`gEkb99ZVQ6~Nwj0}aB`WcEG(kK&&hGANd9Aa*=BA?M>;+$+W^yzy=f zI;f|lk*z~;>u;IG+DqBopN?%vsVD2BOVc=N?hH!u7%aG6&N1C!`c-*J(8R~KyXI*D zH(KtwVaa!0@0?uS;>)02?s`5Cn`t>aRC;_6g~WPOJO}?~mJ|wCq#H3WLDJMZ;%ZtN zyz#r|svzfC=#g_wV{s^pE~v3V`PwyD;w~4_x;-y;Ew})n+dG7~)f&ZhUb2~#HgM=_ zdP;zzD30PVK{onwnq0u(^@I@9-jUp6y7n1EX>7-9?c!ZRg_>x0tJ z%Z#3ei0f*28^$}Has}mnQgpr6ts*=zdCRr~DH%1@K4ocD(ZW+9{E!l1Jitcm*8RaGsw1%{90saVKMl9x2X51d@0+P6g6On%jPap}? z&7MzAMmkT}^ng}=b>)id+cZAO7b-s+0%3@?Z^&ur#;lPF8PVq~Vjgraa&RO5OSngZ zm2046_dhFhhvK~K<}n5ZMgNxc5$y? zXKcrJfW?1VV`bdr0!D6Gb@<)w>o@%?Bn0Rz#OvSAQJuT!R@=&DCDhby&qq?#jcz%J{o`=6gLprpoF@NXBKW`CaMCM*peySP2kf}Q z^P-bK_|POsO>T9xV6|mwO??cBkY<02QzyQ{7Jq8aFhpc3tfkq*E8t3F*7ay82F(wA z-~DmDvf#>dFb1sVD;IOSb8n+_(!Od<1$^*u_+e#)FFUO`(fpj7N6ZWm}BI z!&F1T*Bv(WCrfk_q+!RhOiT|9rRG5VALf$dqr{jS;)nS!v$EcP-om*Q&MA{p=p@`^ zhrytsf04d;@_-z%A!4Y_8JL0V1%P8h;t96VZ4>OzJ#ww`CvW-`!3U=Eo@G$YBI*xv z2S&gR48I@#_i7t?KV_GjnfSscy1uc?r-$|f{?{M4RjaS8OYLK{F2_7u?MKI8e@kjS zRi3el`reVkTzh$(yK;Ws)z@$9mjGJIx6k5Kv5-nW%5fCCGp7{;gb`%Dx@$2T^nbqK2RvZrnPRd*Q#I;GrKef8V_{F~&~T6a9c9EF?IM4rv!|yUEBpHip^AygEN} zX6|;nVPBc1wrI&znbh~W(m!NDiLp?i)rOC)rS~_VNJ@TZ!&|hI}WoI$8@n}tFyhO5J?U3btm6L z{3X>kycaZ<+)Lj~_F=Of9_tSy(2&K8!+nKp>aJ+?`lW7lywf0YVmf{%TRLC%?^q^1i(+I~# zYZa8^#A0G4i+>~hfp}(1{FZnUA~aB)=xHb5`yN78@Tjzw3fTUl@-(5^lirPCsnr%x zE`SdS{vA!^sO_8Wsa#7-ONUo$2J#wMl<-Fn>gD%BXpJ~reN%<+#%&OXks|QL_hjgs zu%WE_vpv7YF8Q}g(b$`pq(39WTsQ_yz6+H(Ki4wSnKJr56Q*$0YGFjmE+LS_)d(0Mz!Ee3w zdi}sU9pPPCowpkkjD2vaY(X=yqbfG>vArq*i1s`+(VHU;S@(7mP2k--h_W*NTA*%n zmyv}BAIPHp_UdLnjamT30UL`xM=h9>I?gF$EL}{XxGp8ayeSqr@?L`74me zQDInosmX0y?@-L`)VL^Q|AeLYLY>TmE6O|3WMD&-+vJnhnzy&+^{2F4I67^NQcKQ& zB$MFnFrn?J_bOKf9t<&#;IZxAPtCL$)o}{OGA~T0F@e>xJ2-5?%cNyX*Au0lo{Wvs zrLL#!?`u4f<5{C(raT_Zp0~Ds5U-}Yaa||H4v$|8Pt4M0mO8GS&~4fVBbsZ)z0C+$ zXZjih{GPradGZoFcE}x>8vqWOL1!bRm<&5CN&B%l#N*UnKT^%m(T8>m=!yg{Zg(J4 z&`c9+i^rAb!@nzW)<|@HSvy7Li7V5|jrZ#CzK0Y((Wkimu=TMmx}$%LA6&J`6W_O! z?jYuXFEeu?>Qy4i?gvsLJ272&;G8A0jLe1P!9!(LP1FvIY$vdg(A4q`EPKFWiS`Xx z$6(glP-8VuPH$`!t86G*`zLW&mIn&nE7n+8fVVw*wz1f zpY^Qq#xH`e3Hc!p$?9u4G;8V>+Stiw$$r~z;s}cZzvbpyEbh0EQX zQi^-L!YS)&|Ni4hNk>w;Kyt?;ryp-dwG!@-4EN~UrE<;51IG_q$AR4B6S~?j%Rr`` zP}_^k72gHx367QGSP7?eb(S`TnvsKpX6<3Tlf6dJsHo@aRXUiP3X3_pME^DDZBcuLS*wJ+G{ivHAa(bdU#f7?g?!vuw#@0tsMAv2ZQ85pn3mfOG zaV@7{0}m!FlKbs_!O@gCN!S=?QU2(ha2o-+o$fhv2Uilbv{%Yw^z@^L8IUWtYs_XW zC;xOd+?8f-=we<%E&g|x$B+G3=GB;ymZVBWv`{9(MP^NUDRG2Gq>906^EetmczdWBh z(H-4MsWnV~&)tsfihuEViXad#4PzD9(CjrBFE1Vn+pZ+yKOD6>tPG_YLdRd5h>c@E zo}c|i#AY0V04fAfIRJsf%IGP#9Dob?UE>7EP^h7ijPG#Ar)1 z+61esYrnqD-6BRn{T^yhQ*61|+r8U{hEGmO@KEe_!8C`)6WE7hH6KEpWAT?3GuqYU z02B^q5|mQqteYd!SK!+orv1A&tX!H}ZE=YT!%&O$KfM6EsyroZI*gocL>7o|0uAuk z@*LF^`|>N*b_D6FX-HM49?6a%#n4*$#LeUM{l*6W600ziNqCZjf{}WYe{canpAxQjX z?~omK|4;Y8uqIX0)k^-27Tz+hlFk!-h-wRCMz>nOwldfjgwnj?GOx1a=4gyK-tR2@ z2g~tzK%*^v<;faSlS>oY7eoH#1Mfl!Qmx9a)#VSNo}(Ix=5*@6B08G-&TJB_UQKO& z^-t`Ivnz@H+90@=GpgcczPq_fW(ph{f+vT+&yTc+Yd+BaY|kZE$RZ1G7Mz4ygOF`| z(o;kw!^qkN&CU(^)P`zl`B}j#@MGe7YamlOl15ws=lHpyJffA}T7Eg7Zx#=f+B5R^?cYX0;FHix1+Yd&RYr-E~_(Q_~VcKnOuuYwy@~80X{7n z0Vv0B`4?j`-R0uz9gzx3<+kzk!92^DSXc;g#mQ%70`PH|NyfN_Am6@I>KmyZ))m>L zbGYF=6A|GB@^Bm$A9?j8YY(?p<+^^K>Bm4vCk~5H;buawz<`YQa$r3U?3W+#*b(eR zv!|7>MO0Rwe*d6~`|ukxU?O93?x*~{=Nsa?>;Bh`S6j40T5UbAlofq-od!b#NGP?Q zjhvN^*aA!DS}9ddPCbi@ZZTZTuc-O%y!r>p+1tpVbo6%c=dbi{_0W>+Tmg|8(`iit zR!$_Xj!zmgGU*mt}k&PKl*hkqZHas~O@9A8p-Qj) zGSv0;B=-bR>#nV$>zgYTP@6-zy$Q7FRQo(%UkoHe$S1a>vECCkTOjf&-rg>-cl5>E zHf(cCFxFd}4LFDd{ZM3qQ^P7!Jq`0^n+|b+Ypf7X0tu1kW@t@8?;v#pb#{%fvWb%V z)O8m#ID?(9vh@X0G?4vfW_xK8(&vKDY|P?VadfJlq{wrSIeHfc`UwEew?#AROrL;b8T2a!LpJi~C{`6)D=;J8Ydb12B;GEx zUWZ4T%_z(;)rK>PCVzjcy`Ds=bbJ60Lp!CMv+jr0+0uPW1N>EQju8l!OatedxU303 zok!M-U6|2Et)_#Ha&9Tz?o|UbXLCr0jn~M!&iJ^xM;Y%>LOGfgJC3ZGY|9@Rnzr&S zQ)^UNXX#vg-7ETfKX#9DK9UC_kqm8r_NbJ%=d^-OL*nZx69>3X*F`}bQ?FeTe22y` z)HWy$dWo+Mzw{;;ZH*q^-4Cl=`bDDC~M0@dAQ&P)jfesK0YO%j~|CH_ft^RcDGy({Lwrv=aN_r}FzaIo4%rM(i$_q;-2}`L9GB@6=?z?q|U=M-hD%u|s+l<(GU6 z>8N88z6L;tKc2Y$>WoA6kkRqvf@I>MjUaw->90THz~fWxVUJaUL)a70m+8y1#2O2^ zVhZ5L9@x^=scXJY=c>vO{FL})@LiIw?hEI}=vCFk-uYTrx1s}tCUf9nlx;&#IG2%5dv*o%34d*?FE zbcwCp^V}|=lDFCzEX+-Ybd-+@|8k8|@2WXeN2%UZO1zM)tQHluM=}{cq1vOvoqXY4 zlzhipga6Oe#YEEt?z<%o%B@|r0*816^X>tV2)-po3jtESH4#A7J;{G%h5pDjRh;cETWw zq^|slZFzBr`&K*?;dBYqyj``OEGp(XGO_6{xM%&=c5)Q`?X&3%Oh)H8=-Wq7k`>Ax z*Z||Ld=$Oe#!m;Ws7b)#n!a4erGIkQqXJOe=VSy6X21%)0u6#Uuj~Sx9Xg8_mI>0b zFeY4q4~NCV63Mt*st)khB-)LAMBnocqv)`tKs1Q3F9QL>Z#fVl-`{LI$eChH+Pr563~+Vx9B-5K9@ z>9Aa|L1Rbw&CK#mQv?JyA>azcDWRXp$jIVJqu86jldT0!9BfYBetRDjeRX-iaaFS>LUABVcW-J3A< z?hN_GF297U@z;U=&=)@6(-kK;`n07+eX?6Ezwx`0XokMn_T&R5z~cMo_$=7&VabK& zW7qjFmFip3TZlPwiQ(J`ppilT&dTNk2AZ1EV@609!MNW+v(dq~-+x%XJsj6zV(vwjzX?>ZcM74@Hk^ z9n_li5p-;p`WRLls*ek8l8H8+npF6PZ4^yqov^{F;J$@jO&^n$jRX>n(ohglG&mX*Z$o)uGDD8N|isJP6(K+X`=Atz} z!Z~!$v@TRRgG-sOQJpF7S598OjR*cJa7QUoe7Rl0t!0;(PYo@!Lt09JPAf~hPb0d4 z_&7Mf?RE0~%Ao{l7nCs+ea`ns(Ft#l&ZVYvGKA1mShD}n)T=A^jE~wt=i4>cyLv+! z>gMN{_B!K=PH`VFakUYk6w&oX8l0NTNM?5>-CjRmQokyFn88Df(aUrF@tEtK)q>Cp zv*`g3;Y01q7b|f|y817i&n%vfI(5^VfaAEvWEKmycg?0a1kqWV$)u#SV-{z!a%y}S zHwT1MpOvAONi4ul$i3&^7NY{(Gty9&N$F2Cu4qbT78`BzfRv}_8rd+&A3K@Fy8O!2hx2_K zqv!QJjPqq&FU(Mui@jHznw+{3ezk(m*0FA2ydlAW^NSck>h^CiEh*?$2;I+5gA5!u z1E9rX8)FPM&$Cw(7)cU4heCH+5F*6Jp8!K*GCPY>2Fn9v5na`2p{n&y38F;DlMfV) zF*Fb(Y>%$rcP{Oc&FV;+0~oChY2rG)G9MOny1;bzhiqp}(@$5kIUSn3=fK-4K>SWNnD{O-LAAc z>_nVWtdR?*`P};@sP&pR6-k-OcqLL)h-*?ov&yS zx=1%#x(N7>XaZBMK4o-jRA-aW=E=yAPEJ6uYjEQ~J9hub$u-Gl@ky-fQgex|YX#EU zH~%DEMUs0lX6)wELBWEvdcGUfXbe^ott1>^Ms78Rif5-88ZF6Qt>Q`@Ss4sVc~&J} zMq>pSWb!u0>Oj#O-_dg0-+K@A$lR-h3DHrubMNGh=z17ZC*8FCCqjbyRxVr`H;t8) zjDcyS!M~zmR1I*Qk-~rte_?t6kDU$W%J9_}<8Dicu>uQJz!H&i^UL|b*R)JEb@)ry z03yYlhOEkx{@4FQPdtWO0zHFuCqT|!XsGPv&TtDT!F~O(FeBE66`Ej6^Zy!}zc>ms z&{}j1evlM5?QYM8Z%rJkzH6~|bhlqy&4bgE$I4sKJWdom9@(7D){_{1gH}A5fX7)& zojYIUP`cA+JhmT-x3aUF{+tpvJVD*}+04$Y;QPXUoJwI7`lr^P6mAU~WTjESE8AeP z#I`G@P_F`%jo}-;oKqw#MH=;e_gf59=lh0(N)<{u{Vv@$ph6Sf&EQ()|H4&2PA+7u zn93P6YO2BgY4t8;t+GTE*ix3s%hJ=UzCP%ZAvEBI%C~3I)JR)h*KBoIQ&wtE5_M|@ z{zZ-K;eVK!WS+VQLs4-^4EOvi+RXlo5Gp|PnAI3NBexMS%D~OBs0U-v>JfvM^^HK( z@q%ZBWcfw|)fz(Z6AtnK*db+uWoYx9dm>;0^;d2eLlL*L(xi0FskAOMBv#&p{ax;K zYK&zo%W)u>bfs#)8Xmi4oPNk`zb*Z8C}zccVUrHO_CSE?4*Z4VwT+t_V(bi>kBx z=;q|^1!c__G@k*B*6~05L*>wQxc&Xu!8kwqH0a$z4EK3@r~J zGH~#NWApQ}_e@$BJ?xG_d}@~*1aApB;oul|wzIk4f&JLyf2f*sup->Es z^MlhH{Kuj195Y#?u|)5_RGGl!povU%YX%E@Jwp6pt9F`ocO-+IHlORF2Vw75Yj!Ri zMsj<;jgZBz>wvqCB#)KG!A1uU&GIoyT`A!5zta^=`q-GL`|fH5%WI~4C^Qd!&H3WL z!_{_PipqT+D8!=|rPglsBA|jv2vkM|1Z@BX|K z;}YgIs6drO!{`>oxc2%vt71*2pgQ7KUnVG^>+StjKylluJviulmSpC$Y|xW&?RC2h zr~N$a$^XPuyw%eGm8pKA{_jlH$^uK1#e+e=Y#YlK7WKuBs+C&emJHCCwkcr1Ut5a%gM|XH|(}^E-3AIfq(mX}eu6 zzVxglU03o81|Kn~bpXNhRq~Y_+Gv{?PU2K7Kvm%o)H)FPn|1dbwQm3b3-e#^t5LtL zCIxNi^lF~jjHO;9j#gWE6haS+AZa}+Fi<44jgBX7aXq}r9&8gqs|0W4UXN`m4DvES zekE<5a(H@fbMxV%DeUaVto74qbX|A%0U-t_=pbVtu%4DH7ge1?E>geOA2X1-`X)nz z==u1elYG4k_NTjW0VBEJ$HF%rHnWfA3J(sSbDB=LzdpdjQw%ADFKnb>o`d56_dW`M z9;W-OPa*CCpuPzbvCqGZ=x^g&8nS_V>u+4tDwk7evkvA55uEwo$CM+X?m>u{BMH&V z2zxx=1>IX{s7;y@uJGd|mN%V=Ll(s=B)O9vJ3;e^*&S6T0?uTvNEYh$x{^y2a`Z=A+*UOa@l6=#i&^kYwcF_ylTzrLJ@g z|J@k_|L~c*=kIMl@~|S9O*1idt_asuED@lZJ)bkdjMHzxQX!00X~m@Csjg1=rlGbUIWq>&_}i*B>}@>x&K&BQcF_mM~}9LT-SbH7!3Mm*gm+}e^KTyP5nug_gP(192nfpv8go4sg-JY6+8%xarmOG3eHF| z^TcQmRi^$^4FzR;t9zv;teG+wK4-d7xe|2j8rHo_n<)C_o5g^dePr!Sf*=~yK<>BR z9jR-@&)fLS!AKN)HI4&6q}AG5Ljxkyun3)_5*n?8!c+li_IZ6QmWZ{Ys@1z0D!@lw z>kQ?n5l9cZF{l1u~Zn&ImKXq$Vv{ZY15c@#I;1M2qBLxcIT7QZsX- zm4iH8J+b3k0f@suwWC&!m}Yob+3)vWCdl5!_?|%VK0!U0Y#@8c;Ma+RERSm(} z*{T~uU3How0f4SyEHnF_Bm5j&dgWmYz9G7)e?atsR+BHPYZKE!%z;Qo#$xa-f0QF1 zdNeJDxrHC|%CikR=y%g;COYX?yuR6Z?s(uUO<7qU2e>XZ8A~ zW6YB!a#(^m73PpR_Bib8KDD+Qp8Ii;Lcy-4@}=@=8jeH7%ZTUv`wNk};c{48r1oCg zZwYV(d3j%FOQuv~=0JA|MX68;2hp2dCu~5?aP5T@i-*Y*50Lg8scmp9US*-6{3Yuk z{;t-xHl9k1ulrKRyKgbLhEbl=^7i7rT|ieUhjtTyXt23#blu`8IJm?(7BoT8QJp<@}oky9xgJ z+)zH3ba~2nTjX%EAurD1WZZS5-EeG2t>AIlb0}vPLGBiH*8YyzLizgS&&2`8rhP)T z-ys`*1yP0y0%Dt*;O#%mwspHU)I};}QEC^%_fbwPqHWss1f^6Djd;;^P;u0qNJ-Ih zan$aVa^kUOc`X_4>VA;(A{83yovwv_#h{X`oW=PlaQGdBT)+Y0_HmUY34B#RKBmR+ zx5+88phcCQM!a~0X1ul`m(jd^Tiz!t!aXAuWy^i$eIwr@i1DIsw*({X*E>D}a2 zRwwm8srGDWMvj_u%6cfChsA*~e^>!XGE&1Lc{hlJtcEKYt<6`)g{D9?1uNrzcU^G1 z)RlKlELvV*+(>dp!JLi5gb3g09 zyPv&!J!|jUZ~fk?;$L*j0&MX(J;BPOgvMVekhIySCeAJQ@fc*Pf3#LL7RsKNkuUzW zXmRu{V-!2D-ecp)=XElkb3Nr3vVc(yYML+YRpal!zH17kP1&2;?9!da*OOkb`&d9m z%xy)^V18^8XsS3q3<6$nOL!4BCe73weqXpJL=jw2tZ!P|pOl(oICXImdb@TG&eIN8 zr^;brX1yo=yY5xV`zq<7N@xv|Yg?`{mZM-}^GEXc{FJjSQrvbvt8@f@!_j zlMFK|Lc#;mv%gGMvt--y+Y9Z%3Z4iz~MPAePf=7d3ed&1G0xfsP(_hBU}jF_k)z7oYX)}lqc z`ezb4`qvOs2nu=JyamxlTKSwUtMPk3k!GH6b+9?Qpmve&(bd_9MbtnnDtOfXRP>)$ z_f?-|bYO~9!c1Qj!DTt^v46;n=g;Wq5!44peidBqZQ>c3D9QbAmACUJXr=N(v6%Gz z%U7rL^J5voC{|Gsxn1g%%Efb>x8n_&pD4dP{c6ak8!WI0^wlq_@*pG~`T4_XcvdZw zam4(o$rOIN2#@Z|Q9GZuvoUG@uts;?dm8-N-{hff>6=6rx z^l~XG->8ObO>uOGRVlB&Qx30%VY^Y5$D*~El%D)h2kBmDN%U zsz*jd$Qv@dSVH*9L^f2sfKDgKxI1tf_3QtIP@+`i_IaPnUWRBxB6{xP;mtn&-1du` z4BSRWSWS$LIU=gumfTrvWI=eDkH9IzoL`SCs&95VHHNl#2XSIy8yTt7)RD z8ROMggvJ(yj0B+4npM|rqn7y{{)x(Qc-BIcewziM=rgpH@q;>9;4*%+9$Z7TQAAUyyp1OokT9>_zoi zifg4u$lr^6dqAnO(}~KS56T8Gm_kDISV-$fhN=!!eBz#WKsn(l50(d?3HAPqMF0Q7 zo^ca;QbN~FAfudag5@Rr;MTZ9-gIp>ssBZ_cYFOi)jnzWmRA7IIoL2L(#uD<&C}sK zubNqjU&Izdi1M=N^8`A!KsJkwobtm%*V}d;{hf;3-qk7m38^*!gt}H!0JaG+9uMn(~F!Iky`*XXPzb&8gV`_a+#Vz$DeE!A$CFCh~CzVC_ ztAUd6l<*|j-ung%d6a`vn|P5C9rh&+q_6v?tCQTGzVec9-q5u35ht&eEob(NT3j1 zfLGSW&a?=}b`C)bu%y(y=~IYJ*^E(XK!zl=v*TU-GNkNay2W2xz5R^lD`cOF$;0w4 z{I|DrUZBi3#)kh?CBy8<>SBRVCm7q^ma006@;R-qwN%nFPS@tUykoA}oL2;TdPGSZ zF105!MA=>QssDLCV~v)t!#x`1yA0QGGxyqA&pwZJBme`Eh!pD0HOJ&xqx}~%Y!#^H z4_hphyh=l}5C4?^kVuVyJVzKmc7oYi*T*SS#wLmJ%V?5)zH2&>rDCg&Yw-NvP%Gpw z)XFlLmkBi` z&_`Z}e>SCMSRGADA!~T;oM!2%@WDD|4wMRh4@u6%2eWw_lP?0fri*-LGX!03(a0q& zId4*lu$rjG3MiDgwszJs3hGmRHo;^#h)``cVHaJI>?w#qU z?`vx$dX6gwFVT!-7aS2;#$NZ}hIW%a8=d95(ns6BPVNcDcGTiAp(;TB7uY*ssb1OG!9b$wwmj6qq*Fp>xx^&Ps{!v<@6f6^)?Eh zDQl^qHl#oFe1*5ItT@*{ReX>Vsv)YCK5zk9aFq_zX@{GQ zT*CTGz|Zm0zmV4H43K0)vggQDmciM7Pr|$1AM|kscDOh~pMsEYTw2ko&hOio5A<-` z>WXDxD*!anl&+ZLq&8sI$E|4oux-CHk)T3o6t}gXIGN)8V5&@D~Kyj;>q#|10r-FsL zW9;_jbbGonSp^C?g9nnX^wD{GwC#d4v*)i2T37BQRCqkUk+;>Z%leH*!RbPB2MDaP z{&g}>Yq@E)GgkcPFWaUN{W!4jdOTnB=jau zB-!WXjUR2!NV-^{KrTPm`jaE0y4s-n>l_=2hW%i&jF94>3b-7h8ZU{*dkueBX10xt z3#~iXB+KfbEJRAHc&RlO&?pw9&dtq6krJb3fXf49UFo@=tm=)G9_yjgn&)XSmKR5! zI&h;F@n68=`GZK$MIj3@*KM2{FmY*SX3Mc{&Tz*$^n9cpx`JL5mSCR)kWAMOEhaeI zUh*LPTEQpbs;*dkZMBVsFzZp&r_DCb{yuaA&8>tp1QN82roY{?GvU}s_Q-*LUd_Oe z>X>})m{q3E3ip@zpEfdA@Lyp2AN7B`g58@xNp+TlONIVm3IJ|Zl$z}#Pb_e0t09B4gmfQPtj)gft`4{scf__`JcHQH z*MMwr2n|lT+wyK#Uv`2c361@4BtlF}Xt**F?{bL`Zi*o+aY|amLKbEYR0My7-wlfj zmqW&pjhSg=t^y=__lPde4jz)P$tSw_!lc1Cq;kW3rDscQ9AT9sp za%X=nGSMmxhfJlLV$Kb|ia6AF_esH7Pt@|5BmE5_oCh zF5Hz@k%UMl>A2LyaBNulFbsoER^|3G3W1F)6$AF&{(cYrmP7wz62O_^txC-kAKPTy zt@D&-Ju4EW{h`=f^)i8-3CUj3`j;4*DF7x!y z+%EP`3NY%DKcu>7Tx*krOU~?~PzT?bjC2`%2fq|Wrn%15mEq+WO(}oen<$DSR#7b$ zH-3vxYIahkVt%y`9n?aw8IgI4yz%7HNAk4$E^!qXZ|NUETqRscwj9;N19l{PuKHLA zt&P#lp%);1X?YMBi^>@1DcnODZY-l2y+g$yguY<`tNEGDW7aD zx^!fQ*SW>z_n8TJx>Gnx@5c)I{F@3{nq#Zi@)h_w&_2nI{$C*RpF8QOCde@{gmMIj zvcx-hj%YrAr3O+3|HWtgn+F$@a;Fte5z+?L_Q)bFz$4Pp>LYP* zL>JYIzzm%?{lDb^p}Ag?*s5p;Evj$M7aP+|tMEDP)==ZXABljGOp)R@rmAcv zY1VgUi8KXH@wD&7Bap|Mm%9ttgjAT)Fu}S```twEAel<5K(-Rg7|9_7XIkUs#>OGM z9;Q;bIS|u7aro0-4+=<1w~|U)S`I6q5bKBG>RHO%l@z{z*|7806K(sGpD0UvB4+$ zC8=g&q4D?i*<4$1(8omTqM3{`nfO}rcP}dZ9zB4KmAjkNpDJgh;&=D$KIO>&eqFR< zox70w7_T^n{AzGo)9tCv#-A|!m0(zYR`y!j*>h?e7s8DJ3YjTZ3)j7G$dAsOV$Ob6xx z;cUmoJXS-cHzp!Ro@pmG;r1v~SrN`OW(9aXBeyF;^?;>gIX4QQDTaKfS+mz1(gRR- zKF+fcnqDr`h|~ACB*7sec6KN`YF@avY`g_SaG{dh=E+GE1v9v}LuaR7j2R%DY3E)F z+5Fkp&>t_x%!bhsRW3ELU)L&n(3Mf5T$k<6`4x4~MCu(3Jvq-^vGlFihl3k{Di|e! zl5nS*aH6?g@I}0M^-cpIC<>7ZFp=_dRN143YS)qQ-y{)2j>=#;L&kwaO0L}&R2uNu!Q)a}#a07gcz52tnF_rK zL4Oh%^x!~1QpAr+k@$*4D_Y44l&FpXrCY-5|!;)KSoYdg5G&EDEx?Q zl;Jpxs_G92E7W8P>T2Sf(CE7c;8M%ejbb&_QBmR-(y?$FAS9d11>|rV%#{7en+ps z(Ydh6I$(H1T&%THBfg`zA+spV#gC~h9Ql|JtW{CphSg!PxI?dX-+`y{!lSx;d44T_ zeBDH(AkK?b_EFPyWK9akRGYE|ACn|A$F4=?@UmVEP+0UrhOG`DYxd;?Jhbk^=T^sn zkQT(gN5WmwBG0ZHp&q{jnXhH(g>+!t*YD7V+0e>Vi-05MuO^L_T1i@%;kfP$p17I| zA)xwl@Eu@TB>x>%Bkt>T`c00b?e3YT#+TNg9tzIKf>AWDj@>q8x{{J5fMWwm7>mT9 z_$!a5{f8Z-r=;&uioz=tNk%#3hDvq@BXy9Bi=+$7 z5Y+6|7`Q08dmERb?R)aW0oF?4+@f~|`&w2igiAQx>V?0AVDEQdU)Lg3TD>$np7U4U zVj780sh5%}#wYvXiUn_if&*E%pUNBYNG*C0WN)dfKX>`+N*#u}#vl0+VhRMEBJ>cD z9ENjnrhi1JccSf5@h%>xiQ5y1&uU+=_Bi<%wXN>HqGKuR*qXRulm=O9^7a29hxqaC zwaKI*zJl#-dPpfzG45=8g!dyMkC->)d<4IIzYX*KYk&>X%~zJJb!+yw&YaDf3Zdgb zl;~+dq5Lh*E-Qc~qg~w0QcXK*zIcTB$&qQ&A)_mZbW|I;Laxvy&F+QHpZ=K&(%<#3 z?=gr7q?gizSGBuMZ)}EBei2SI*dtkpE*6tgrRU&P9yY0qF#;3vc&DsL@?(~Jw5r{Z zf#Ln^-in^-GH-<(v-U1;fEQ0+)D^t_nLd=)LRq`>@4AS)rKoXWcq0?d&<8VBCik=T zBv!uhEFVF9yY*!zoYJ6LGeQX!FRfmz3aVCCE2N6S8qMZ|lPn^rt$-v@5eQS%j0L!# zy+kAj8EgpSiO)I@xCuu}m0zY+MbE*jRbH*h&eQiQzxj>2QPMh&5Yrk6lre1$O?A*) zr!BPZ7d>41XE$)tBy5L_O-Uu6c*B8OpmFM^#psl6siE>m0&+e=4R;2)U%Ih5*Od>E z&sBmQ%C25FZ}6iN?30|G+P8wI?jk7-5MjS!{@$)N7bsGXNFt*6Pb+p?0^EOFWQ&t2 zv9U^CCpolq6#hHeV2cC|M=-vfB*>M*`?JIhk^_qsze{qvjE6B6o>as{l9p_YjT7sGC zTcc%qVK(Gj$QwwJaZ4tuMLOMI3`Y-Y*Q`7A5uwww7{dM#I~YKBM?6>^R`NtmnV8BA zlA1zG9lgnkw!7brh5mPYged}N{Zyge0*v&#M zVqThLAr%eKmOgc~@q$3v!xvmnz~W*M01dDW5JufVM0y*Z8A3uvNrp<+L(8DgJ6fI1 z?z$E=HyTFSTmg)H9nSTZtc7P4p#+gOgqF=P#3x$l`%5GWfbX*On%cdj9|`=V1F_sv z$Bnmix>vdzPsP*hM>R!3#m~sT=RYxYrpABi1@L0js~@bR2qP`cvKA9(+*Es8NSXLG=Cj0?9-!yw+)=#JyNO5iR)Ijua+P{-iV94KIdCa&Nqu+I z@uOa-i(+=Izq<@jwJiSpocA+4Jt< zwpdhmc(Iq!JGtIb=&C0j7;o&xD05>(hd*f9jr`?$wdozaUf4uE$;~l+t+3>iURG>A zRvbSn(fMhjhwuK4Khw*dPpJErff$$)j_n^YQ!k9T@ewgsUcU}VJwH>!g~6~c^qtq5 zpK>~zv4Pfz7|I@mH@Rc3u6#J!sne9RLjBo!VAC`|b&tWQ?^984(s2qVdMMYi&qWni z+p7x>=y*AWju9^4`Zh>E$nHSKkN@hEd}h3%KRTrYtu|2Y{#$X95rKogA1>9AXLXCx zVEF!pXohS2ND$jYk^p(5E-joo*PbyU$0__c!irRBR^{R#V!U^loq?X@%RrfS3~0qv zD=|tHj}DdM)c`md1#QS4f1BLV!_0_Ji9!tYmV2!!WcW^LFu7+D1smK_t*EG#H46d2XRP>Flcon)>h(fI$f|! znfi&qk(f7B?Rev{P7@wWr!(##S}S94hscsX+7PjrBELfLHe{fNf?R1`YT$=A#r0vy zn@S7=fAk27d3JV0FcaUe(1Dn!v#-D?w`4 z%+z)~#v$M8rOtCh;7emA7v5VP(3a2?j2)Hlo{l3 zMpCB1Vkt2AFj3E+v|D890KeN_oYPPkTZtxsuu=p6_3rpPK~Qqbsm2KnwGEC$Dq4?z zsP_ql=cR_R8;(S`kgEKBBJDf22|eVR;`7@Z<)R+1+MnQ!)ynheHA~A^<^7lqxMTHK zq#(wUcWubfgHmiBw~UMTc2R1SoVnXkAf7EN4J9DN76G9<3N_+Zoso%*-x;QUp65Xa zWl?ZB9R|jE%N{i;s7G70GbhIlB&Kot$p6yd$*S+Gvrw4x_Pc-l+(Z0+6;w7PR ztBLl9VN>h2HrO!PuH@j1ipM&m4B_8n;(n5s>*BoWo}ypS|e$n&LAJuraCt zd9cog9X!(`K0*9uS^1rja~t*MFlqQ~BgswuNH9VnUhr-NT!POe4#Ama6&d3D+A(=i zN!e5%TXiEh{>*`#y!614i4boCGk4N1>fs)6-L%q6Y&lMFOOeUAj&FwtLVt942t>Z$ zpay%29Cjs80{7{0z?F|aAVe~xa)zsdkW%Wf*Rt`)k|Iq=*+lOVIG>u^8iKScRN zh%53C=6#8v;3Q!~M#o}I54NxyLOOKg1U9T!@S|81<9nM;U}`+$sb4*BPK*u2u)hMI_4Ot6n1aI0HD7}-|R zQz692tKO{xNG(P5+|OIk2ELe>BFkE%Lb7C$=Cj6ko`!(z0+1;BVdoO<#yrz#*F4*3 z=dL3*tu_s`UGEPHz+R68bbwe0=B5xAUYX+S>)smWpx0e^!@D-FDD7|F#2vK^NC{2R zpVJQvi$HxCKjhG zQ)64TS&#Nb>c!!+7iY34uFowJ3-O|eXBQOQEZi(!E|=Te+XG%d{X;y$;!(&q_ZKJ& z^&d#aI%=Z8!in~e2|b069=Lfn{8eT4GbS4(?^6!zojqFedkN1y$3Mulb#uDw1gdPW zMq^?QjqviK=SM&(4v5kHvY@4z0c{tO$WUa5V%$rWd40IkDcSj%ZXCm9(ztANsZQmr zZ*cbF1sp(HOjva~*xt|b{@RKINd3;-8jr=6=`%VHlYi9~+u3$Umjq{F`^G1RT$9y? z6rdv7-k8(zZuwEe`3bo@f#5v{HAmZsXE?{iFMpT!#wvy^X{Lrc9 z8h|~jJ@GGWLIsKOgvGSB{SG{ zZ**VQGHq88lg6lh8JEOWm~iE7pcoG4mb8d`l*FXX!EAc`jJmT={M>mMm&)ZNhg-37 zMzquxJXfF_2i(4L=b9>lx>CZ)Jp65{8A>qt1GYU9|5&;zTc_-*)y3Url}^&dPtE#r zy}n}Hp*y|`zj|Bh6g)vcS-VCsio(#_zPyRq_5S?;q82nbOyX$0tAorJy!uU%YaY21 zN(Xxx%!lTp>ey?gnvw^i*h$e>Yw?FZz7`px=8vEChj|^@=ALWHq7TlL&v$k4B6T}Y zScbBHi=Eh>OX@TH+Lr&ls za9yf7_;vNPekRSWcKaijO{TDwmCtbK9&7J{bf7vz9dG!2wJjaX^BJAMr=g8=x`OZ3 z0Fg^*tHgmfe;oVSF6V$(k@4k^(c<3CY2Iyja4u*~DQo&k3g0n5na1!=kB;WCoX!3m z!AVR|sWn5GX_smf9H$8I(n1TwQT@FAO#oSAfH+?_haj!2swFcz|F{)yRi05xU11RT zG3m=O)wfio&R8mO5?3k0@_Lc-0oEi2@}!Z|Sh!{G`-*KE`Mq>+;)_Qso{HseHsLAL z_*1#0T<<) zv9Tc9`90x2H0p)f$QCqyW!gt%aOLF+U;e5K`;Gb!4<$tIj^>y%kDeM?S?|*$eaT~I zzO#8;fEQ;50-1rtj8PU|?iYwLhvGeH!?3z*hnF9&d)a9Nt_nXZYR8j6xwO{M@|w38 zke`p&?)?Q>V_Nco_W=7rN~Nknzg$aFt!Lk1`BzbEqNX?tdk4o4vKqKpO$KS0n|or8 zPf33q-f1=^g)cfR5(;gRLm%CY24tP&2~+hmdb$&?vc_)M7_=U?w;F9*gN9Dr{F0e@ zg%wfc?;GMYX7H*m`b7>B#Yd`}_%>UUQ_EZZ2h4>$&xr5@_%al&q7Iv~?M5xDx3=E( z%WvY$IToj&vzW}3udgJq6F4g~oOINId!9+k>zm651P(vjHZex2fdmKUNDY*sJvf2- zzxq&?1r9z7tTg(RJrQiGI5nH{D^pFB0WkDZAK40 z-P-gtG&IIF3@SzQT@Sw|3U1|psvM`^an_R#4DDktfT1&qT%g@u#o&{-y!;6FO`1Fw z-{+fio-HhYo%bSnbs$#%dpK|!w6T4RD10|f67C%6<+X@@o5kyl6HA_Q5SF5;4m5}^ k{tn*UrvHejAu`Vh%yklKNleV!FQ6Z3aRsq*5ktTK00t$#1ONa4 literal 0 HcmV?d00001 diff --git a/lib/ultralib/tools/compile_sjis.py b/lib/ultralib/tools/compile_sjis.py new file mode 100755 index 0000000..136bdc7 --- /dev/null +++ b/lib/ultralib/tools/compile_sjis.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import sys, os +from shiftjis_conv import sjis_process + +os.chdir("../../") +WORKING_DIR = os.getcwd() + +fb = [] +original_c_file = [i for i in sys.argv if ".c" in i][0] +CC = [i for i in sys.argv if "-D__CC=" in i][0][7:] +build_dir = [i for i in sys.argv if "-D__BUILD_DIR" in i][0][14:] + +output_c_file = original_c_file + +sys.argv[sys.argv.index(original_c_file)] = output_c_file + +original_c_file = "src/voice/" + original_c_file + +with open(original_c_file) as f: + fb = f.read() + +os.chdir(build_dir + "/src/voice") + +with open(output_c_file, "w+") as outf: + sjis_process(fb, outf) + +os.system("%s %s" % (CC, " ".join(sys.argv[1:]))) diff --git a/lib/ultralib/tools/disassemble_elf.py b/lib/ultralib/tools/disassemble_elf.py new file mode 100755 index 0000000..1fa58a8 --- /dev/null +++ b/lib/ultralib/tools/disassemble_elf.py @@ -0,0 +1,312 @@ +#!/usr/bin/env python3 +# +# ELF disassembler that attempts to be matching +# + +import argparse, struct, sys + +from libelf import * +from mdebug import * +from mips_isa import * +from util import * + +def debug_log(msg): + print(msg, file=sys.stderr) + +class MipsDisasm: + """ + """ + + def __init__(self, elf_file) -> None: + self.elf_file = elf_file + mdebug_section = elf_file.find_section_by_type(SHT_MIPS_DEBUG) + if mdebug_section is not None: + self.mdebug = mdebug_section + self.has_mdebug = True + else: + self.has_mdebug = False + self.cur_file = None + self.comment_section_pos = 1 + self.section_local_labels = {} + + def add_section_local_label(self, section, offset): + if section not in self.section_local_labels: + self.section_local_labels.update({section : set()}) + self.section_local_labels[section].add(offset) + + def advance_file(self): + seen_cur_file = False + for sym in self.elf_file.symtab.symbol_entries: + if sym.type == ST_FILE: + if seen_cur_file or self.cur_file is None: + self.cur_file = sym + break + elif self.cur_file == sym: + seen_cur_file = True + return self.cur_file is not None + + def disassemble_all_sections(self): + print(MipsDisasm.asm_prelude()) + + # debug_log("Name Type Addr Off Size ES Flg Lk Inf Al") + for section in self.elf_file.sections: + local_labels = self.section_local_labels.get(section.name, None) + # debug_log(section) + if section.name in ['', '.strtab', '.shstrtab', '.symtab', '.reginfo', '.comment', '.note', '.options', '.mdebug', '.gptab.data', '.gptab.bss'] or \ + (section.sh_type == SHT_REL or section.sh_type == SHT_RELA): + continue + if section.sh_size == 0: + continue + print("") + print(MipsDisasm.begin_section(section)) + if section.is_executable(): + self.disassemble_exec(section) + elif section.sh_type == SHT_PROGBITS: + # TODO kmc as doesn't support incbin, byte array this + # print(f".incbin \"libultra.a\", 0x{section.sh_offset:08X}, 0x{section.sh_size:X}") + first = True + for i,b in enumerate(section.data): + if local_labels is not None and i in local_labels: + if not first: + print("") + print(f".{section.name[1].upper()}_{i:08X}:") + print(" .byte ", end='') + first = True + elif first: + print(" .byte ", end='') + if not first: + print(", ", end='') + print(f"0x{int(b):02X}", end='') + first = False + print("") + elif section.sh_type == SHT_NOBITS: + print(f".skip 0x{section.sh_size:X}") + else: + assert False, f"Unhandled section: {section.name}" + # debug_log("/// UNHANDLED ///") + + def pass_section(self, section): + pass + + @staticmethod + def asm_prelude(): + return f""".include "macro.inc" +#include "regdef.h" + +// assembler directives +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches""" + + @staticmethod + def begin_section(section): + section_flags = section.flags_str().lower().replace(' ', '') + if section_flags != "": + section_flags = f", \"{section_flags}\"" + section_type = "" + if section.sh_type == SHT_PROGBITS: + section_type = ", @progbits" + elif section.sh_type == SHT_NOBITS: + section_type = ", @nobits" + if section_type != "" and section_flags == "": + section_flags = ", \"\"" + + return f""".section {section.name}{section_flags}{section_type} +.balign {section.sh_addralign} +""" + + def get_label_name(self, addr, pdr=None, optional=False): + if pdr is not None: + sym = pdr.lookup_sym(addr, EcoffSt.LABEL) + if sym is not None: + return sym.name + if not optional: + return f".L{addr:08X}" + else: + return None + + def get_comment_string(self, start): + comment_section = self.elf_file.find_section_by_name(".comment") + end = comment_section.data.find(b'\0', start) + if end == -1: + return None, None + comment = comment_section.data[start:end].decode("ASCII") + return comment, end + 1 + + def print_end(self, vaddr, eof): + ends = eof.get(vaddr, None) + if ends is not None: + for sym in ends: + print(f" .type {sym.name}, @{'function' if sym.type == ST_FUNC else 'object'}") + if sym.st_size != 0: + print(f" .size {sym.name}, . - {sym.name}") + print(f" .end {sym.name}\n") + + def disassemble_exec(self, section): + raw_insns = as_word_list(section.data) + insns = [decode_insn(raw, section.sh_addr + j * 4) for j,raw in enumerate(raw_insns)] + + # enumerate branch labels + branch_labels = set() + + for i,insn in enumerate(insns): + if insn.id in MIPS_BRANCH_INSNS or insn.id == MIPS_INS_J: + branch_labels.add(insn.target if insn.id == MIPS_INS_J else insn.offset) + + eof = {} # vaddr : name + def add_end(vaddr, sym): + if vaddr not in eof: + eof[vaddr] = set() + eof[vaddr].add(sym) + + cur_fdr = None + cur_pdr = None + for i,insn in enumerate(insns): + mnemonic = insn.mnemonic + op_str = insn.op_str + + # Update mdebug info + src_inf = "" + if self.has_mdebug: + # Get new fdr if there is one + fdr = self.mdebug.fdr_foraddr(i * 4, extensions=('.c', '.s')) + if fdr is not None: + # debug_log(fdr.name) + cur_fdr = fdr + + # Get new pdr if there is one + if cur_fdr is not None: + pdr = cur_fdr.pdr_foraddr(i * 4) + if pdr is not None: + # debug_log(pdr) + cur_pdr = pdr + + # Line numbers + if cur_pdr is not None: + asm_line = i - cur_pdr.addr//4 + if asm_line < len(cur_pdr.lines): + src_inf = f" {cur_pdr.lines[asm_line]:4}" + else: + src_inf = " PADDING" + + # Symbols for this address + syms = section.get_sym(i * 4) + # if len(syms) != 0: + # debug_log("\n".join([str(sym) for sym in syms])) + + # Print end + self.print_end(insn.vaddr, eof) + + # Print symbol + for sym in syms: + if sym.name == "gcc2_compiled.": + print(f"// compiler generated") + if self.cur_file is None: + print(f".version \"01.01\"") + if self.advance_file(): + print(f".file 1 \"{self.cur_file.name}\"") + + comment_string = None + while comment_string != "\"GCC: (GNU) 2.7.2\"": + comment_string, self.comment_section_pos = self.get_comment_string(self.comment_section_pos) + if comment_string is None: + break + print(f".ident \"{comment_string}\"") + + if sym.bind == SB_GLOBAL: + print(f"glabel {sym.name}") + else: + print(f"{sym.name}:") + + if sym.st_size != 0: + print(f" .ent {sym.name}") + add_end(insn.vaddr + sym.st_size, sym) + else: + print(f" .type {sym.name}, @{'function' if sym.type == ST_FUNC else 'object'}\n") + + # Print branch labels + lbl = self.get_label_name(insn.vaddr, pdr=cur_pdr, optional=not insn.vaddr in branch_labels) + if lbl is not None: + print(f"{lbl}:") + + # Relocations for this address + rels = section.get_rel(i * 4) + assert len(rels) < 2 # There should never be more than 1 relocation for a single address, right? + # if len(rels) != 0: + # debug_log("\n".join([str(rel) for rel in rels])) + + # Apply relocation + if len(rels) != 0: + rel = rels[0] + if rel.rel_type == R_MIPS_26: + if insn.id == MIPS_INS_JAL: + op_str = rel.relocated_symbol.name + if op_str == ".text" and cur_fdr is not None: + pdr = cur_fdr.pdr_foraddr(insn.target) + if pdr is not None: + op_str = pdr.name + elif insn.id != MIPS_INS_J: # Branch labels for j instructions are also R_MIPS_26 relocations + assert False , f"Got unexpected R_MIPS_26 relocation {insn.id}" + elif rel.rel_type == R_MIPS_HI16: + assert insn.id in [MIPS_INS_LUI] + rel_name = rel.relocated_symbol.name + if rel.relocated_symbol.type == ST_SECTION: + rel_name = f".{rel_name[1].upper()}_00000000" + if cur_fdr is not None: + pass + + op_str = f"{insn.abi.gpr_names[insn.rt]}, %hi({rel_name})" + elif rel.rel_type == R_MIPS_LO16: + # Ideally this should be in the elf code so the relocations don't look identical + addend = insn.imm + rel_name = rel.relocated_symbol.name + if rel.relocated_symbol.type == ST_SECTION: + rel_name = f".{rel_name[1].upper()}_{addend:08X}" + self.add_section_local_label(rel.relocated_symbol.name, addend) + addend = 0 + addend_str = f" + 0x{addend:X}" if addend != 0 else "" + + if insn.id == MIPS_INS_ADDIU: + op_str = f"{insn.abi.gpr_names[insn.rt]}, {insn.abi.gpr_names[insn.rs]}, %lo({rel_name}{addend_str})" + elif insn.id in MIPS_LOAD_STORE_INSNS: + if insn.id in MIPS_FP_LOAD_STORE_INSNS: + op_str = f"{insn.abi.cop1_names[insn.ft]}, " + else: + op_str = f"{insn.abi.gpr_names[insn.rt]}, " + op_str += f"%lo({rel_name}{addend_str})({insn.abi.gpr_names[insn.base]})" + else: + assert False + else: + assert False + + # Apply branch labels + if insn.id in MIPS_BRANCH_INSNS: + op_str_parts = [] + for field in insn.fields: + if field == 'offset': + op_str_parts.append(self.get_label_name(insn.offset, cur_pdr)) + else: + op_str_parts.append(insn.format_field(field)) + op_str = ", ".join(op_str_parts) + elif insn.id == MIPS_INS_J: + op_str = self.get_label_name(insn.target, cur_pdr) + + print(f"/* {section.sh_offset + i * 4:06X} {insn.vaddr:08X} {insn.raw:08X}{src_inf} */ {mnemonic:12}{op_str:35}".rstrip()) + self.print_end(section.sh_addr + section.sh_size, eof) + +def main(): + parser = argparse.ArgumentParser(description="Disassemble relocatable ELF object.") + parser.add_argument("filepath", help="path to the ELF file") + # TODO unimplemented optionals + parser.add_argument("--compiler", help="original compiler that produced the ELF (IDO or GCC, IDO default)", default="IDO") + parser.add_argument("--strenc", help="string encoding, default is EUC-JP for IDO and SJIS for GCC") + args = parser.parse_args() + + elf_file = None + with open(args.filepath, "rb") as elf: + elf_file = ElfFile(bytearray(elf.read())) + + disassembler = MipsDisasm(elf_file) + disassembler.disassemble_all_sections() + +if __name__ == '__main__': + main() diff --git a/lib/ultralib/tools/fix_objfile.py b/lib/ultralib/tools/fix_objfile.py new file mode 100755 index 0000000..52a79bc --- /dev/null +++ b/lib/ultralib/tools/fix_objfile.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# +# Fixes garbage data between sections and optionally rodata section flags +# + +import argparse +from libelf import * + +def fix_section_flags(elf): + for section in elf.sections: + # Unset Alloc flag in .rodata section + if section.name == ".rodata": + section.sh_flags &= ~SHF_ALLOC + +def fix_garbage(elf, original): + # Begin with the original data, and paste header and section data over it + result = original + if len(original) < len(elf.data): + result.extend([0]*(len(elf.data) - len(original))) + else: + result = result[:len(elf.data)] + + # NOTE: This only supports the elf header, program headers, section headers and section data at this time + + # emplace elf header + hdr = elf.elf_header.to_bin() + result[0:len(hdr)] = hdr + + # emplace program headers + for i,proghdr in enumerate(elf.progheaders): + offset = elf.elf_header.e_phoff + i * elf.elf_header.e_phentsize + result[offset:offset+elf.elf_header.e_phentsize] = proghdr.to_bin() + + # emplace section headers and section data + for i,section in enumerate(elf.sections): + offset = elf.elf_header.e_shoff + i * elf.elf_header.e_shentsize + section_header, section_data = section.to_bin() + result[offset:offset+elf.elf_header.e_shentsize] = section_header + if section_data is not None: + result[section.sh_offset:section.sh_offset+section.sh_size] = section_data + + return result + +def main(): + parser = argparse.ArgumentParser(description="Disassemble relocatable ELF object.") + parser.add_argument("compiled", help="path to the compiled ELF file") + parser.add_argument("original", help="path to the original ELF file") + parser.add_argument("--fix-section-flags", help="", action="store_true") + args = parser.parse_args() + + elf = None + with open(args.compiled, "rb") as elf_file: + elf = ElfFile(bytearray(elf_file.read())) + + original = None + with open(args.original, "rb") as original_file: + original = bytearray(original_file.read()) + + if args.fix_section_flags: + fix_section_flags(elf) + + result_data = fix_garbage(elf, original) + + with open(args.compiled, "wb") as elf_file: + elf_file.write(result_data) + +if __name__ == '__main__': + main() diff --git a/lib/ultralib/tools/libdiff.py b/lib/ultralib/tools/libdiff.py new file mode 100755 index 0000000..ac6b139 --- /dev/null +++ b/lib/ultralib/tools/libdiff.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +from typing import Any, Dict, Optional +import json +import logging +import subprocess +import tempfile +import pathlib +import sys +import queue + +import asm_differ.diff as asm_differ + +MAX_FUNC_SIZE_LINES = 5000 + +class AsmDifferWrapper: + @staticmethod + def create_config(arch: asm_differ.ArchSettings) -> asm_differ.Config: + return asm_differ.Config( + arch=arch, + # Build/objdump options + diff_obj=True, + make=False, + source_old_binutils=True, + diff_section=".text", + inlines=False, + max_function_size_lines=MAX_FUNC_SIZE_LINES, + max_function_size_bytes=MAX_FUNC_SIZE_LINES * 4, + # Display options + formatter=asm_differ.AnsiFormatter(column_width=50), + threeway=None, + base_shift=0, + skip_lines=0, + compress=None, + show_branches=True, + show_line_numbers=False, + show_source=False, + stop_jrra=False, + ignore_large_imms=False, + ignore_addr_diffs=False, + algorithm="levenshtein", + ) + + @staticmethod + def run_objdump(target_data: bytes, config: asm_differ.Config, label: Optional[str]) -> Optional[str]: + flags = [ + "--disassemble", + "--disassemble-zeroes", + "--line-numbers", + "--reloc", + ] + + with tempfile.TemporaryDirectory() as tempdir: + target_path = pathlib.Path(tempdir) / "out.s" + target_path.write_bytes(target_data) + + start_addr = 0 + + if label: + nm_command = "mips-linux-gnu-nm" + + if nm_command: + try: + nm_proc = subprocess.run( + [nm_command] + [target_path], + capture_output=True, + universal_newlines=True + ) + except subprocess.CalledProcessError as e: + logger.error(f"Error running nm: {e}") + logger.error(e.stderr) + + if nm_proc.stdout: + for line in nm_proc.stdout.splitlines(): + if label in line: + start_addr = int(line.split()[0], 16) + break + else: + # logger.error(f"No nm command for {platform}") + return None + + flags.append(f"--start-address={start_addr}") + + objdump_command = "mips-linux-gnu-objdump" + cmds = [objdump_command] + config.arch.arch_flags + flags + [target_path] + + try: + objdump_proc = subprocess.run( + [objdump_command] + config.arch.arch_flags + flags + [target_path], + capture_output=True, + universal_newlines=True + ) + except subprocess.CalledProcessError as e: + # logger.error(e) + # logger.error(e.stderr) + return None + + out = objdump_proc.stdout + return out + + @staticmethod + def diff(target_elf: bytes, compiled_elf: bytes, diff_label:Optional[str]) -> Dict[str, Any]: + arch = asm_differ.get_arch("mips") + + config = AsmDifferWrapper.create_config(arch) + + # Base + if len(target_elf) == 0: + print("Base asm empty") + return + + basedump = AsmDifferWrapper.run_objdump(target_elf, config, diff_label) + if not basedump: + print("Error running asm-differ on basedump") + return + + if len(compiled_elf) == 0: + print("Creation of compilation elf_object failed") + return + + mydump = AsmDifferWrapper.run_objdump(compiled_elf, config, diff_label) + if not mydump: + print("Error running asm-differ") + return + + # Preprocess the dumps + basedump = asm_differ.preprocess_objdump_out(None, target_elf, basedump, config) + mydump = asm_differ.preprocess_objdump_out(None, compiled_elf, mydump, config) + + try: + display = asm_differ.Display(basedump, mydump, config) + except Exception: + print("Error running asm-differ") + return + + # Print the output + display.run_sync() + +if __name__ == "__main__": + if len(sys.argv) != 3 and len(sys.argv) != 4: + print(f"Usage: {sys.argv[0]} [path/to/target.o] [path/to/compiled.o] [function name (optional)]") + sys.exit(0) + target = pathlib.Path(sys.argv[1]) + compiled = pathlib.Path(sys.argv[2]) + if len(sys.argv) == 4: + label = sys.argv[3] + else: + label = None + target_bytes = target.read_bytes() + compiled_bytes = compiled.read_bytes() + AsmDifferWrapper.diff(target_bytes, compiled_bytes, label) diff --git a/lib/ultralib/tools/libelf.py b/lib/ultralib/tools/libelf.py new file mode 100755 index 0000000..11c4c03 --- /dev/null +++ b/lib/ultralib/tools/libelf.py @@ -0,0 +1,1181 @@ +#!/usr/bin/env python3 +# +# MIPS ELF library +# + +import struct + +from mdebug import EcoffHDRR, EcoffFdr, EcoffPdr, EcoffLiner, EcoffSymr + +# ===================================================================================================== +# Utility +# ===================================================================================================== + +def align_as(value, align): + if align == 0: + return value + while (value % align != 0): + value += 1 + return value + +# ===================================================================================================== +# ELF Identity +# ===================================================================================================== + +# Offsets into e_ident +EI_MAG0 = 0x00 # Magic char 0 , 0x7F +EI_MAG1 = 0x01 # Magic char 1 , 0x45 +EI_MAG2 = 0x02 # Magic char 2 , 0x4C +EI_MAG3 = 0x03 # Magic char 3 , 0x46 +EI_CLASS = 0x04 # +EI_DATA = 0x05 # +EI_VERSION = 0x06 # +EI_OSABI = 0x07 # +EI_ABIVERSION = 0x08 # +EI_PAD = 0x09 # +EI_NIDENT = 0x10 # + +# Values for e_ident[EI_DATA] +EI_DATA_LE = 1 # little endian +EI_DATA_BE = 2 # big endian + +EI_DATA_V = { + EI_DATA_LE : 'Little Endian', + EI_DATA_BE : 'Big Endian' +} + +# Values for e_ident[EI_CLASS] +EI_CLASS_32 = 1 # 32-bit +EI_CLASS_64 = 2 # 64-bit + +EI_CLASS_V = { + EI_CLASS_32 : 'ELF32', + EI_CLASS_64 : 'ELF64' +} + +# Values for e_ident[EI_OSABI] +EI_OSABI_V = { + 0x00 : 'UNIX / System V', + 0x01 : 'HP-UX', + 0x02 : 'NetBSD', + 0x03 : 'Linux', + 0x04 : 'GNU Hurd', + 0x06 : 'Solaris', + 0x07 : 'AIX', + 0x08 : 'IRIX', + 0x09 : 'FreeBSD', + 0x0A : 'Tru64', + 0x0B : 'Novell Modesto', + 0x0C : 'OpenBSD', + 0x0D : 'OpenVMS', + 0x0E : 'NonStop Kernel', + 0x0F : 'AROS', + 0x10 : 'Fenix OS', + 0x11 : 'CloudABI', + 0x12 : 'Stratus Technologies OpenVOS' +} + +# ===================================================================================================== +# ELF Types +# ===================================================================================================== + +ET_NONE = 0x0000 # +ET_REL = 0x0001 # relocatable +ET_EXEC = 0x0002 # +ET_DYN = 0x0003 # +ET_CORE = 0x0004 # +ET_LOOS = 0xFE00 # +ET_HIOS = 0xFEFF # +ET_LOPROC = 0xFF00 # +ET_HIPROC = 0xFFFF # + +E_TYPE = { + ET_NONE : 'ET_NONE', + ET_REL : 'ET_REL', + ET_EXEC : 'ET_EXEC', + ET_DYN : 'ET_DYN', + ET_CORE : 'ET_CORE', + ET_LOOS : 'ET_LOOS', + ET_HIOS : 'ET_HIOS', + ET_LOPROC : 'ET_LOPROC', + ET_HIPROC : 'ET_HIPROC' +} + +# ===================================================================================================== +# ELF Machines +# ===================================================================================================== + +EM_UNSPECIFIED = 0x00 +EM_ATNT_WE_32100 = 0x01 +EM_SPARC = 0x02 +EM_X86 = 0x03 +EM_MOTOROLA_68000 = 0x04 +EM_MOTOROLA_88000 = 0x05 +EM_INTEL_MCU = 0x06 +EM_INTEL_80860 = 0x07 +EM_MIPS = 0x08 +EM_IBM_SYSTEM_370 = 0x09 +EM_MIPS_RS3000_LE = 0x0A +EM_RESERVED_xB = 0x0B +EM_RESERVED_xC = 0x0C +EM_RESERVED_xD = 0x0D +EM_HEWLETT_PACKARD = 0x0E +EM_RESERVED_xF = 0x0F +EM_INTEL_80960 = 0x13 +EM_POWERPC = 0x14 +EM_POWERPC_64 = 0x15 +EM_5390 = 0x16 +EM_ARM = 0x28 +EM_SUPERH = 0x2A +EM_IA64 = 0x32 +EM_AMD64 = 0x3E +EM_TMS320C6000 = 0x8C +EM_ARM64 = 0xB7 +EM_RISC_V = 0xF3 + +E_MACHINE = { + EM_UNSPECIFIED : 'Unspecified', + EM_ATNT_WE_32100 : 'AT&T WE 32100', + EM_SPARC : 'SPARC', + EM_X86 : 'x86', + EM_MOTOROLA_68000 : 'Motorola 68000 (M68K)', + EM_MOTOROLA_88000 : 'Motorola 88000 (M88K)', + EM_INTEL_MCU : 'Intel MCU', + EM_INTEL_80860 : 'Intel 80860', + EM_MIPS : 'MIPS', + EM_IBM_SYSTEM_370 : 'IBM_System/370', + EM_MIPS_RS3000_LE : 'MIPS RS3000 Little-endian', + EM_RESERVED_xB : 'Reserved', + EM_RESERVED_xC : 'Reserved', + EM_RESERVED_xD : 'Reserved', + EM_HEWLETT_PACKARD : 'Hewlett-Packard PA-RISC', + EM_RESERVED_xF : 'Reserved', + EM_INTEL_80960 : 'Intel 80960', + EM_POWERPC : 'PowerPC', + EM_POWERPC_64 : 'PowerPC (64-bit)', + EM_5390 : 'S390, including S390x', + EM_ARM : 'ARM (up to ARMv7/Aarch32)', + EM_IA64 : 'SuperH', + EM_IA64 : 'IA-64', + EM_AMD64 : 'amd64', + EM_TMS320C6000 : 'TMS320C6000 Family', + EM_ARM64 : 'ARM 64-bits (ARMv8/Aarch64)', + EM_RISC_V : 'RISC-V' +} + +# ===================================================================================================== +# Program Types +# ===================================================================================================== + +PT_NULL = 0x00000000 # Program header table entry unused +PT_LOAD = 0x00000001 # Loadable segment +PT_DYNAMIC = 0x00000002 # Dynamic linking information +PT_INTERP = 0x00000003 # Interpreter information +PT_NOTE = 0x00000004 # Auxiliary information +PT_SHLIB = 0x00000005 # Reserved +PT_PHDR = 0x00000006 # Segment containing the program header table itself +PT_TLS = 0x00000007 # Thread-Local storage template +PT_LOOS = 0x60000000 # Inclusive reserved range for processor-specific semantics +PT_HIOS = 0x6FFFFFFF # ^ +PT_LOPROC = 0x70000000 # Inclusive reserved range for processor-specific semantics +PT_HIPROC = 0x7FFFFFFF # ^ + +P_TYPE = { + PT_NULL : 'PT_NULL' , + PT_LOAD : 'PT_LOAD' , + PT_DYNAMIC : 'PT_DYNAMIC', + PT_INTERP : 'PT_INTERP' , + PT_NOTE : 'PT_NOTE' , + PT_SHLIB : 'PT_SHLIB' , + PT_PHDR : 'PT_PHDR' , + PT_TLS : 'PT_TLS' , + PT_LOOS : 'PT_LOOS' , + PT_HIOS : 'PT_HIOS' , + PT_LOPROC : 'PT_LOPROC' , + PT_HIPROC : 'PT_HIPROC' +} + +# ===================================================================================================== +# Program Flags ( May be platform specific ! ) +# ===================================================================================================== + +PF_E = 1 << 0 # Execute +PF_W = 1 << 1 # Write +PF_R = 1 << 2 # Read + +# ===================================================================================================== +# Symbol Info +# ===================================================================================================== + +# Symbol Types + +ST_NOTYPE = 0 +ST_OBJECT = 1 +ST_FUNC = 2 +ST_SECTION = 3 +ST_FILE = 4 + +SYM_TYPE = { + ST_NOTYPE : 'NOTYPE', + ST_OBJECT : 'OBJECT', + ST_FUNC : 'FUNC', + ST_SECTION : 'SECTION', + ST_FILE : 'FILE' +} + +# Symbol Bind + +SB_LOCAL = 0 +SB_GLOBAL = 1 +SB_WEAK = 2 + +SYM_BIND = { + SB_LOCAL : 'LOCAL', + SB_GLOBAL : 'GLOBAL', + SB_WEAK : 'WEAK' +} + +# Symbol Visibility + +SV_DEFAULT = 0 + +SYM_VIS = { + SV_DEFAULT : 'DEFAULT' +} + +# NDX + +SHN_UND = 0x0000 +SHN_ABS = 0xFFF1 +SHN_COMMON = 0xFFF2 +SHN_XINDEX = 0xFFFF +SHN_LORESERVE = 0xFF00 + +SYM_NDX = { + SHN_UND : 'UND', + SHN_ABS : 'ABS', + SHN_COMMON : 'COMMON', + SHN_XINDEX : 'XINDEX', + SHN_LORESERVE : 'LORESERVE' +} + +# ===================================================================================================== +# Relocation Type +# ===================================================================================================== + +# EM_MIPS +R_MIPS_32 = 2 # Write the 32 bit address of the symbol +R_MIPS_26 = 4 # Write the 26 bit address of the symbol divided by four (for relocating branch instructions). Fail if address won't fit +R_MIPS_HI16 = 5 # Write the high 16 bits of the address of the symbol +R_MIPS_LO16 = 6 # Write the low 16 bits of the address of the symbol + +# EM_POWERPC +R_PPC_NONE = 0 # Do nothing. Skip this entry +R_PPC_ADDR32 = 1 # Write the 32 bit address of the symbol +R_PPC_ADDR24 = 2 # Write the 24 bit address of the symbol divided by four shifted up 2 bits to the 32 bit value (for relocating branch instructions). Fail if address won't fit +R_PPC_ADDR16 = 3 # Write the 16 bit address of the symbol. Fail if address more than 16 bits +R_PPC_ADDR16_LO = 4 # Write the low 16 bits of the address of the symbol +R_PPC_ADDR16_HI = 5 # Write the high 16 bits of the address of the symbol +R_PPC_ADDR16_HA = 6 # Write the high 16 bits of the address of the symbol plus 0x8000 +R_PPC_ADDR14 = 7 # Write the 14 bits of the address of the symbol divided by four shifted up 2 bits to the 32 bit value (for relocating conditional branch instructions). Fail if address won't fit +R_PPC_REL24 = 10 # Write the 24 bit address of the symbol minus the address of the relocation divided by four shifted up 2 bits to the 32 bit value (for relocating relative branch instructions). Fail if address won't fit +R_PPC_REL14 = 11 # Write the 14 bit address of the symbol minus the address of the relocation divided by four shifted up 2 bits to the 32 bit value (for relocating conditional relative branch instructions). Fail if address won't fit +R_PPC_EMB_SDA21 = 109 # Small Data Area + +# Gamecube/Wii custom relocations +R_DOLPHIN_NOP = 201 # Do nothing. Skip this entry. Carry the address of the symbol to the next entry +R_DOLPHIN_SECTION = 202 # Change which section relocations are being applied to. Set the offset into the section to 0 +R_DOLPHIN_END = 203 # Stop parsing the relocation table +R_DOLPHIN_MRKREF = 204 # Unknown + +RELOC_TYPE = { + EM_MIPS : { + R_MIPS_32 : 'R_MIPS_32', + R_MIPS_26 : 'R_MIPS_26', + R_MIPS_HI16 : 'R_MIPS_HI16', + R_MIPS_LO16 : 'R_MIPS_LO16' + }, + EM_POWERPC : { + R_PPC_NONE : 'R_PPC_NONE', + R_PPC_ADDR32 : 'R_PPC_ADDR32', + R_PPC_ADDR24 : 'R_PPC_ADDR24', + R_PPC_ADDR16 : 'R_PPC_ADDR16', + R_PPC_ADDR16_LO : 'R_PPC_ADDR16_LO', + R_PPC_ADDR16_HI : 'R_PPC_ADDR16_HI', + R_PPC_ADDR16_HA : 'R_PPC_ADDR16_HA', + R_PPC_ADDR14 : 'R_PPC_ADDR14', + 8 : 'R_PPC_ADDR14', + 9 : 'R_PPC_ADDR14', + R_PPC_REL24 : 'R_PPC_REL24', + R_PPC_REL14 : 'R_PPC_REL14', + 12 : 'R_PPC_REL14', + 13 : 'R_PPC_REL14', + R_PPC_EMB_SDA21 : 'R_PPC_EMB_SDA21', + R_DOLPHIN_NOP : 'R_DOLPHIN_NOP', + R_DOLPHIN_SECTION : 'R_DOLPHIN_SECTION', + R_DOLPHIN_END : 'R_DOLPHIN_END', + R_DOLPHIN_MRKREF : 'R_DOLPHIN_MRKREF' + } +} + +# ===================================================================================================== +# Section Types +# ===================================================================================================== + +SHT_NULL = 0x00000000 # Section header table entry unused +SHT_PROGBITS = 0x00000001 # Program data +SHT_SYMTAB = 0x00000002 # Symbol table +SHT_STRTAB = 0x00000003 # String table +SHT_RELA = 0x00000004 # Relocation entries with addends +SHT_HASH = 0x00000005 # Symbol hash table +SHT_DYNAMIC = 0x00000006 # Dynamic linking information +SHT_NOTE = 0x00000007 # Notes +SHT_NOBITS = 0x00000008 # Program space with no data (bss) +SHT_REL = 0x00000009 # Relocation entries, no addends +SHT_SHLIB = 0x0000000A # Reserved +SHT_DYNSYM = 0x0000000B # Dynamic linker symbol table +SHT_INIT_ARRAY = 0x0000000E # Array of constructors +SHT_FINI_ARRAY = 0x0000000F # Array of destructors +SHT_PREINIT_ARRAY = 0x00000010 # Array of pre-constructors +SHT_GROUP = 0x00000011 # Section group +SHT_SYMTAB_SHNDX = 0x00000012 # Extended section indices +SHT_NUM = 0x00000013 # Number of defined types. +SHT_LOOS = 0x60000000 # Start OS-specific. + +# MIPS specific +SHT_MIPS_DEBUG = 0x70000005 # .mdebug +SHT_MIPS_REGINFO = 0x70000006 # .reginfo +SHT_MIPS_OPTIONS = 0x7000000D # .options + +SH_TYPE = { + SHT_NULL : 'SHT_NULL', + SHT_PROGBITS : 'SHT_PROGBITS', + SHT_SYMTAB : 'SHT_SYMTAB', + SHT_STRTAB : 'SHT_STRTAB', + SHT_RELA : 'SHT_RELA', + SHT_HASH : 'SHT_HASH', + SHT_DYNAMIC : 'SHT_DYNAMIC', + SHT_NOTE : 'SHT_NOTE', + SHT_NOBITS : 'SHT_NOBITS', + SHT_REL : 'SHT_REL', + SHT_SHLIB : 'SHT_SHLIB', + SHT_DYNSYM : 'SHT_DYNSYM', + SHT_INIT_ARRAY : 'SHT_INIT_ARRAY', + SHT_FINI_ARRAY : 'SHT_FINI_ARRAY', + SHT_PREINIT_ARRAY : 'SHT_PREINIT_ARRAY', + SHT_GROUP : 'SHT_GROUP', + SHT_SYMTAB_SHNDX : 'SHT_SYMTAB_SHNDX', + SHT_NUM : 'SHT_NUM', + SHT_LOOS : 'SHT_LOOS', + + SHT_MIPS_DEBUG : 'SHT_MIPS_DEBUG', + SHT_MIPS_REGINFO : 'SHT_MIPS_REGINFO', + SHT_MIPS_OPTIONS : 'SHT_MIPS_OPTIONS', +} + +# ===================================================================================================== +# Section Flags +# ===================================================================================================== + +SHF_WRITE = 1 << 0 # Writable +SHF_ALLOC = 1 << 1 # Occupies memory during execution +SHF_EXECINSTR = 1 << 2 # Executable +SHF_MERGE = 1 << 4 # Might be merged +SHF_STRINGS = 1 << 5 # Contains null-terminated strings +SHF_INFO_LINK = 1 << 6 # 'sh_info' contains SHT index +SHF_LINK_ORDER = 1 << 7 # Preserve order after combining +SHF_OS_NONCONFORMING = 1 << 8 # Non-standard OS specific handling required +SHF_GROUP = 1 << 9 # Section is member of a group +SHF_TLS = 1 << 10 # Section hold thread-local data + +SHF_MASKOS = 0x0ff00000 # OS-specific +SHF_MASKPROC = 0xf0000000 # Processor-specific +SHF_ORDERED = 0x04000000 # Special ordering requirement (Solaris) +SHF_EXCLUDE = 0x08000000 # Section is excluded unless referenced or allocated (Solaris) + +SH_FLAG = { + SHF_WRITE : 'SHF_WRITE', + SHF_ALLOC : 'SHF_ALLOC', + SHF_EXECINSTR : 'SHF_EXECINSTR', + SHF_MERGE : 'SHF_MERGE', + SHF_STRINGS : 'SHF_STRINGS', + SHF_INFO_LINK : 'SHF_INFO_LINK', + SHF_LINK_ORDER : 'SHF_LINK_ORDER', + SHF_OS_NONCONFORMING : 'SHF_OS_NONCONFORMING', + SHF_GROUP : 'SHF_GROUP', + SHF_TLS : 'SHF_TLS', + SHF_MASKOS : 'SHF_MASKOS', + SHF_MASKPROC : 'SHF_MASKPROC', + SHF_ORDERED : 'SHF_ORDERED', + SHF_EXCLUDE : 'SHF_EXCLUDE' +} + +# ===================================================================================================== +# ELF Header +# ===================================================================================================== + +ELF32_BIG_STRUCT = '>HHIIIIIHHHHHH' +ELF32_LITTLE_STRUCT = 'IIIBBH', data) + assert self.st_shndx != SHN_XINDEX, "too many sections (SHN_XINDEX not supported)" + self.bind = st_info >> 4 + self.type = st_info & 0xF + self.visibility = self.st_other & 3 + self.parent_section = elf_file.sections[self.st_shndx] if self.st_shndx < SHN_LORESERVE else None + + self.name = name + if self.type == ST_SECTION: + self.name = elf_file.shstrtab.lookup_str(self.parent_section.sh_name) + if self.name == None: + self.name = elf_file.symtab.strtab.lookup_str(self.st_name) + + @staticmethod + def from_parts(st_name, st_value, st_size, st_info, st_other, st_shndx, strtab, name): + header = struct.pack('>IIIBBH', st_name, st_value, st_size, st_info, st_other, st_shndx) + return Symbol(header, strtab, name) + + def to_bin(self): + st_info = (self.bind << 4) | self.type + return struct.pack('>IIIBBH', self.st_name, self.st_value, self.st_size, st_info, self.st_other, self.st_shndx) + + def section_offset(self): + return self.st_value - self.parent_section.sh_addr + + def padded_size_n(self, n): + return align_as(self.st_size, n) + + def padded_size(self): + return self.padded_size_n(self.parent_section.sh_addralign) + + def __str__(self): + # Num: Value Size Type Bind Vis Ndx Name + ndx = ' ' + (SYM_NDX[self.st_shndx] if self.st_shndx in SYM_NDX.keys() else self.parent_section.name) + out = f"{self.st_value:08X} {self.st_size:06X} {SYM_TYPE[self.type]:7} {SYM_BIND[self.bind]:6} {SYM_VIS[self.visibility]:7} {ndx:12} {self.name}" + return out + +# ===================================================================================================== +# Relocation +# ===================================================================================================== + +class Relocation: + """ + typedef struct { + Elf32_Word r_offset; + struct { + Elf32_Word sym_index : 24; + Elf32_Word rel_type : 8; + } r_info; + Elf32_Word r_addend; + } Elf32_Reloc; + """ + + def __init__(self, data, elf_file, target_section, sh_type): + self.sh_type = sh_type + if sh_type == SHT_REL: + self.r_offset, self.r_info = struct.unpack('>II', data) + self.r_addend = 0 + else: + self.r_offset, self.r_info, self.r_addend = struct.unpack('>III', data) + self.sym_index = self.r_info >> 8 + self.rel_type = self.r_info & 0xff + self.relocated_symbol = elf_file.symtab.symbol_entries[self.sym_index] + self.elf_machine = elf_file.elf_header.e_machine + self.target_section = target_section + # TODO obtain the addend if the target section is executable + + def to_bin(self): + self.r_info = (self.sym_index << 8) | self.rel_type + if self.sh_type == SHT_REL: + return struct.pack('>II', self.r_offset, self.r_info) + else: + return struct.pack('>III', self.r_offset, self.r_info, self.r_addend) + + def relocated_symbol_in_section(self, symtab, section): + return symtab.lookup_symbol_in_section(symtab.symbol_entries[self.sym_index].st_value, section) + + def __str__(self): + relocated_symbol = self.relocated_symbol + # Offset Info Type Sym.Value Sym. Name + Addend + # 80135560 00091201 R_MY_RELOC_TYPE 800f39e0 ...data.0 + 0 + out = f"{self.r_offset:08X} {self.r_info:08X} {RELOC_TYPE[self.elf_machine][self.rel_type]:17} {relocated_symbol.st_value:08X} {relocated_symbol.name} + 0x{self.r_addend:X}" + return out + +# ===================================================================================================== +# Section +# ===================================================================================================== + +class Section: + """ + Describes a section + + typedef struct { + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; + } Elf32_Shdr; + +x00 x00 4 4 sh_name Offset to string in the .shstrtab section representing this section's name + +x04 x04 4 4 sh_type See SH_TYPE + +x08 x08 4 8 sh_flags See SH_FLAG + +x0C x10 4 8 sh_addr Virtual address of the section in memory (for loaded sections) + +x10 x18 4 8 sh_offset Offset of the section in the file image + +x14 x20 4 8 sh_size Size in bytes of the section in the file image + +x18 x28 4 4 sh_link Contains the section index of an associated section. This field is used for several purposes depending on section type + +x1C x2C 4 4 sh_info Contains extra information about the section. This field is used for several purposes, depending on section type + +x20 x30 4 8 sh_addralign Contains the required alignment of the section. This field must be a power of two + +x24 x38 4 8 sh_entsize Contains the size, in bytes, of each entry, for sections that contain fixed-size entries. Zero otherwise + +x28 x40 END + """ + + def __init__(self, header, elf_file, index): + self.late_init_done = False + self.sh_name, self.sh_type, \ + self.sh_flags, self.sh_addr, \ + self.sh_offset, self.sh_size, \ + self.sh_link, self.sh_info, \ + self.sh_addralign, self.sh_entsize = struct.unpack('>IIIIIIIIII', header) + assert not self.sh_flags & SHF_LINK_ORDER + if self.sh_entsize != 0: + assert self.sh_size % self.sh_entsize == 0 + if self.sh_type in [SHT_NULL, SHT_NOBITS]: + self.data = None + else: + self.data = elf_file.data[self.sh_offset:][:self.sh_size] + self.index = index + self.relocated_by = [] + self.elf_file = elf_file + + def late_init(self): + self.late_init_done = True + + @staticmethod + def from_parts(sh_name, sh_type, sh_flags, sh_link, sh_info, sh_addralign, sh_entsize, sh_addr, sh_offset, data, index): + header = struct.pack('>IIIIIIIIII', sh_name, sh_type, sh_flags, sh_addr, sh_offset, \ + len(data), sh_link, sh_info, sh_addralign, sh_entsize) + return Section(header, data, index) + + def to_bin(self): + if self.sh_type not in [SHT_NULL, SHT_NOBITS]: + self.sh_size = len(self.data) + header = struct.pack('>IIIIIIIIII', self.sh_name, self.sh_type, self.sh_flags, self.sh_addr, self.sh_offset, self.sh_size, self.sh_link, self.sh_info, self.sh_addralign, self.sh_entsize) + return header, self.data + + def get_rel(self, addr): + relocs = [] + for reloc_section in self.relocated_by: + reloc = reloc_section.find_reloc(addr) + if reloc is not None: + relocs.append(reloc) + return relocs + + def get_sym(self, addr): + symtab = self.elf_file.symtab + symbols = [] + for symbol in symtab.symbol_entries: + if symbol.st_value == addr and symbol.st_shndx == self.index and symbol.type != ST_SECTION: + symbols.append(symbol) + return symbols + + def is_rel(self): + return self.sh_type == SHT_REL or self.sh_type == SHT_RELA + + def is_allocable(self): + return (self.sh_flags & SHF_ALLOC) == SHF_ALLOC + + def is_executable(self): + return (self.sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR + + def is_writable(self): + return (self.sh_flags & SHF_WRITE) == SHF_WRITE + + def padded_size(self): + return align_as(self.sh_size, self.sh_addralign) + + def padded_size_4(self): + return align_as(self.sh_size, 4) + + def flags_str(self): + flags = "" + flags += "W" if self.is_writable() else " " + flags += "A" if self.is_allocable() else " " + flags += "X" if self.is_executable() else " " + return flags + + def __str__(self): + s_type = SH_TYPE[self.sh_type].replace('SHT_','') if self.sh_type in SH_TYPE.keys() else str(self.sh_type) + out = f"{self.name:12}{s_type:12} " + out += f"{self.sh_addr:08X} " + out += f"{self.sh_offset:06X} " + out += f"{self.sh_size:06X} " + out += f"{self.sh_entsize:2X} " + out += f"{self.flags_str():3} " + out += f"{self.sh_link:2} " + out += f"{self.sh_info:3} " + out += f"{self.sh_addralign:5X} " + return out + +class SymtabSection(Section): + """ + Symbol Table Section + """ + + def __init__(self, header, elf_file, index): + super().__init__(header, elf_file, index) + assert self.sh_entsize == 16 + + def late_init(self): + if self.late_init_done: + return + super().late_init() + self.strtab = self.elf_file.sections[self.sh_link] + self.symbol_entries = [] + for i in range(0, self.sh_size, self.sh_entsize): + self.symbol_entries.append(Symbol(self.data[i:i+self.sh_entsize], self.elf_file)) + + def to_bin(self): + header, _ = super().to_bin() + data = bytearray() + for sym in self.symbol_entries: + data.extend(sym.to_bin()) + return header, data + + def find_symbol(self, name): + for s in self.symbol_entries: + if s.name == name: + return (s.st_shndx, s.st_value) + return None + + def lookup_symbol(self, vaddr): + found = [] + for s in self.symbol_entries: + if s.st_value == vaddr and s.type != ST_SECTION: + found.append(s) + if len(found) != 0: + found.sort(reverse=True, key=(lambda s : s.type)) + return found[0] + return None + + def lookup_symbol_for_section(self, vaddr, shndx): + found = [] + for s in self.symbol_entries: + if s.st_value == vaddr and s.type != ST_SECTION and s.st_shndx == shndx: + found.append(s) + if len(found) != 0: + found.sort(reverse=True, key=(lambda s : s.type)) + return found[0] + return None + + def lookup_symbol_in_section(self, vaddr, section): + found = [] + for s in self.symbol_entries: + if s.st_value == vaddr and s.type != ST_SECTION and s.st_shndx == section.index: + found.append(s) + if len(found) != 0: + found.sort(reverse=True, key=(lambda s : s.type)) + return found[0] + return None + + def find_symbol_in_section(self, name, section): + pos = self.find_symbol(name) + assert pos is not None + assert pos[0] == section.index + return pos[1] + + def local_symbols(self): + return self.symbol_entries[:self.sh_info] + + def global_symbols(self): + return self.symbol_entries[self.sh_info:] + +class StrtabSection(Section): + """ + String Table Section + """ + def __init__(self, header, data, index): + super().__init__(header, data, index) + + def lookup_str(self, index): + to = self.data.find(b'\0', index) + assert to != -1 + return self.data[index:to].decode('latin1') + +class RelocationSection(Section): + """ + Relocation Section + """ + def __init__(self, header, data, index): + super().__init__(header, data, index) + + def late_init(self): + if self.late_init_done: + return + super().late_init() + self.rel_target = self.elf_file.sections[self.sh_info] + self.rel_target.relocated_by.append(self) + self.relocations = [] + for i in range(0, self.sh_size, self.sh_entsize): + self.relocations.append(Relocation(self.data[i:][:self.sh_entsize], self.elf_file, self.rel_target, self.sh_type)) + + def to_bin(self): + header, _ = super().to_bin() + data = bytearray() + for rel in self.relocations: + data.extend(rel.to_bin()) + return header, data + + def lookup_reloc(self, vaddr): + for r in self.relocations: + if r.r_offset - r.r_offset % 4 == vaddr: + return r + return None + + def find_reloc(self, vaddr): + for r in self.relocations: + if r.r_offset == vaddr: + return r + return None + + def lookup_jtbl_reloc(self, vaddr, symtab): + for r in self.relocations: + r_sym = r.relocated_symbol(symtab) + if r_sym.st_value + r.r_addend == vaddr: + return r + return None + +class MdebugSection(Section): + """ + MIPS Debugging Section + """ + def __init__(self, header, elf_file, index): + super().__init__(header, elf_file, index) + self.parent = self.elf_file + self.hdrr = EcoffHDRR(self.data) + + self.fdrs = [] + for i in range(self.hdrr.ifdMax): + fdr = EcoffFdr.from_binary(self, i) + self.fdrs.append(fdr) + + def late_init(self): + if self.late_init_done: + return + super().late_init() + for fdr in self.fdrs: + fdr.late_init() + + def fdr_forname(self, filename): + for fdr in self.fdrs: + # remove path and file ext + normalized_name = ".".join(fdr.name.split("/")[-1].split(".")[:-1]) + + if normalized_name == filename: + return fdr + return None + + def fdr_foraddr(self, addr, extensions=('.c')): + for fdr in self.fdrs: + if fdr.adr == addr and any((fdr.name.endswith(ext) for ext in extensions)): + return fdr + return None + + def read_string(self, index): + to = self.elf_file.data.find(b'\0', self.hdrr.cbSsOffset + index) + assert to != -1 + return self.elf_file.data[self.hdrr.cbSsOffset + index:to].decode("ASCII") + + def read_ext_string(self, index): + to = self.elf_file.data.find(b'\0', self.hdrr.cbSsExtOffset + index) + assert to != -1 + return self.elf_file.data[self.hdrr.cbSsExtOffset + index:to].decode("ASCII") + +class ReginfoSection(Section): + """ + MIPS Register Information Section + """ + def __init__(self, header, elf_file, index): + super().__init__(header, elf_file, index) + +# ===================================================================================================== +# Elf File +# ===================================================================================================== + +class ElfFile: + def __init__(self, data): + def init_section(i): + offset = self.elf_header.e_shoff + i * self.elf_header.e_shentsize + section_type = struct.unpack(">I", data[offset + 4:][:4])[0] + header_data = data[offset:][:self.elf_header.e_shentsize] + + if section_type == SHT_REL or section_type == SHT_RELA: + return RelocationSection(header_data, self, i) + elif section_type == SHT_SYMTAB: + return SymtabSection(header_data, self, i) + elif section_type == SHT_STRTAB: + return StrtabSection(header_data, self, i) + elif section_type == SHT_MIPS_DEBUG: + return MdebugSection(header_data, self, i) + elif section_type == SHT_MIPS_REGINFO: + return ReginfoSection(header_data, self, i) + else: + return Section(header_data, self, i) + + self.data = data + self.elf_header = ElfHeader(data[0:52]) + + num_progheaders = self.elf_header.e_phnum + num_sections = self.elf_header.e_shnum + + # Init program headers + self.progheaders = [] + for i in range(num_progheaders): + offset = self.elf_header.e_phoff + i * self.elf_header.e_phentsize + self.progheaders.append(ProgramHeader(data[offset:][:self.elf_header.e_phentsize], self.elf_header.e_ident[EI_CLASS])) + + # Init sections + self.sections = [] + for i in range(num_sections): + self.sections.append(init_section(i)) + + # Init shstrtab and name sections + self.shstrtab = self.sections[self.elf_header.e_shstrndx] + assert isinstance(self.shstrtab, StrtabSection) + + for s in self.sections: + s.name = self.shstrtab.lookup_str(s.sh_name) + + # Init symtab + symtab = None + for s in self.sections: + if s.sh_type == SHT_SYMTAB: + assert not symtab , "Found more than one symtab section?" + symtab = s + self.symtab = symtab + if self.symtab is not None: + self.symtab.late_init() + + # Late Init sections + for s in self.sections: + s.late_init() + + def find_section_by_name(self, name): + for s in self.sections: + if s.name == name: + return s + return None + + def find_section_by_type(self, type): + for s in self.sections: + if s.sh_type == type: + return s + return None + +### Tests + +if __name__ == "__main__": + import sys + + elf_file = None + + with open(sys.argv[1], "rb") as elf: + elf_file = ElfFile(bytearray(elf.read())) + + # Header Info Test + print(elf_file.elf_header) + # Program Headers Info Test + print("") + print("Program Headers:") + print(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align") + for phdr in elf_file.progheaders: + print(phdr) + # Section Headers Info Test + print("") + print("Section Headers:") + print(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al") + for i,s in enumerate(elf_file.sections,0): + print(f" [{i:2}] {s}") + # Symbols Info Test + if elf_file.symtab is not None: + print("") + print(f"Symbol table '{elf_file.symtab.name}' contains {len(elf_file.symtab.symbol_entries)} entries") + print(" Num: Value Size Type Bind Vis Ndx Name") + for i,sym in enumerate(elf_file.symtab.symbol_entries,0): + print(f"{i:6}: {sym}") + # Relocations Info Test + print("") + for s in elf_file.sections: + if s.is_rel(): + print(f"\nRelocation section '{s.name}' at offset 0x{s.sh_offset:06X} contains {len(s.relocations)} entries:") + print(" Offset Info Type Sym.Value Sym.Name + Addend") + for reloc in s.relocations: + print(f"{reloc}") + # mdebug Info Test + print("") + mdebug_section = elf_file.find_section_by_type(SHT_MIPS_DEBUG) + if mdebug_section is not None: + """ + for fdr in mdebug_section.fdrs: + print(fdr) + for symr in fdr.symrs: + print(symr) + for pdr in fdr.pdrs: + print(pdr) + for symr in pdr.symrs: + print(symr) + for liner in pdr.lines: + print(liner) + """ + for fdr in mdebug_section.fdrs: + print(fdr.c_str()) diff --git a/lib/ultralib/tools/m2ctx.py b/lib/ultralib/tools/m2ctx.py new file mode 100755 index 0000000..39c5dc5 --- /dev/null +++ b/lib/ultralib/tools/m2ctx.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import argparse +import os +import sys +import subprocess +import tempfile + +script_dir = os.path.dirname(os.path.realpath(__file__)) +root_dir = os.path.abspath(os.path.join(script_dir, "..")) +src_dir = root_dir + "src/" + +# Project-specific +CPP_FLAGS = [ + "-Iinclude", + "-Iinclude/PR", + "-Iinclude/gcc", + "-Isrc", + "-Isrc/libc", + "-Iver/current/build/include", + "-D_LANGUAGE_C", + "-DF3DEX_GBI_2", + "-D_MIPS_SZLONG=32", + "-DSCRIPT(...)={}" + "-D__attribute__(...)=", + "-D__asm__(...)=", + "-ffreestanding", + "-DM2CTX", +] + +def import_c_file(in_file) -> str: + in_file = os.path.relpath(in_file, root_dir) + cpp_command = ["gcc", "-E", "-P", "-dM", *CPP_FLAGS, in_file] + cpp_command2 = ["gcc", "-E", "-P", *CPP_FLAGS, in_file] + + with tempfile.NamedTemporaryFile(suffix=".c") as tmp: + stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-dM", tmp.name], cwd=root_dir, encoding="utf-8") + + out_text = "" + try: + out_text += subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") + out_text += subprocess.check_output(cpp_command2, cwd=root_dir, encoding="utf-8") + except subprocess.CalledProcessError: + print( + "Failed to preprocess input file, when running command:\n" + + cpp_command, + file=sys.stderr, + ) + sys.exit(1) + + if not out_text: + print("Output is empty - aborting") + sys.exit(1) + + for line in stock_macros.strip().splitlines(): + out_text = out_text.replace(line + "\n", "") + return out_text + +def main(): + parser = argparse.ArgumentParser( + description="""Create a context file which can be used for mips_to_c""" + ) + parser.add_argument( + "c_file", + help="""File from which to create context""", + ) + args = parser.parse_args() + + output = import_c_file(args.c_file) + + with open(os.path.join(root_dir, "ctx.c"), "w", encoding="UTF-8") as f: + f.write(output) + + +if __name__ == "__main__": + main() diff --git a/lib/ultralib/tools/mdebug.py b/lib/ultralib/tools/mdebug.py new file mode 100644 index 0000000..6f061ec --- /dev/null +++ b/lib/ultralib/tools/mdebug.py @@ -0,0 +1,938 @@ +#!/usr/bin/env python3 +# +# .mdebug section +# + +""" +References: +https://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf +https://web.archive.org/web/20010628021622/http://reality.sgi.com/davea/objectinfo.html +https://github.com/astrelsky/ghidra_mdebug +https://github.com/Rozelette/print-mdebug/blob/master/print_mdebug.py +https://opensource.apple.com/source/gcc_legacy/gcc_legacy-938/gcc/mips-tdump.c.auto.html +https://github.com/uhhpctools/openuh/blob/master/osprey-gcc-4.2.0/gcc/mips-tdump.c +https://github.com/bminor/binutils-gdb/blob/master/gdb/mdebugread.c + +(stabs docs): +https://sourceware.org/gdb/current/onlinedocs/stabs.html + +(ecoff docs): +https://web.archive.org/web/20160305114748/http://h41361.www4.hp.com/docs/base_doc/DOCUMENTATION/V50A_ACRO_SUP/OBJSPEC.PDF +https://chromium.googlesource.com/native_client/nacl-toolchain/+/refs/tags/gcc-4.4.3/binutils/gas/ecoff.c +https://kernel.googlesource.com/pub/scm/linux/kernel/git/hjl/binutils/+/hjl/secondary/include/coff/sym.h +https://kernel.googlesource.com/pub/scm/linux/kernel/git/hjl/binutils/+/hjl/secondary/include/coff/symconst.h +""" + +from enum import IntEnum +import struct + +class EcoffBt(IntEnum): # Basic Type + NIL = 0 # + ADR = 1 # pointer-sized integer type + CHAR = 2 # char + UCHAR = 3 # unsigned char + SHORT = 4 # short + USHORT = 5 # unsigned short + INT = 6 # int + UINT = 7 # unsigned int + LONG = 8 # long + ULONG = 9 # unsigned long + FLOAT = 10 # float + DOUBLE = 11 # double + STRUCT = 12 # struct + UNION = 13 # union + ENUM = 14 # enum + TYPEDEF = 15 # type definition + RANGE = 16 # subrange of int + SET = 17 # pascal set + COMPLEX = 18 # FORTRAN complex + DCOMPLEX = 19 # FORTRAN double com[plex + INDIRECT = 20 # forward or unnamed typedef + FIXEDDEC = 21 # Fixed point decimal + FLOATDEC = 22 # Floating point decimal + STRING = 23 # Varying length character string + BIT = 24 # Aligned bit tring + PICTURE = 25 # picture + VOID = 26 # void + LONGLONG = 27 # long long int + ULONGLONG = 28 # unsigned long long int + LONG64 = 30 # + ULONG64 = 31 # + LONGLONG64 = 32 # + ULONGLONG64 = 33 # + ADR64 = 34 # + INT64 = 35 # + UINT64 = 36 # + + AGGREGATE = 63 # not a basic type + MAX = 64 # + +class EcoffSc(IntEnum): + NIL = 0 + TEXT = 1 # .text symbol + DATA = 2 # .data symbol + BSS = 3 # .bss symbol + REGISTER = 4 # value of symbol is register number + ABS = 5 # value of symbol is absolute + UNDEFINED = 6 # value of symbol is undefined + CDBLOCAL = 7 # variable value is in se->va.?? + BITS = 8 # variable is a bit field + CDBSYSTEM = 9 # variable value is in cdb address space + REGIMAGE = 10 # register value is saved on stack + INFO = 11 # symbol contains debugger information + USERSTRUCT = 12 # address in struct user for current process + SDATA = 13 # load time only small data + SBSS = 14 # load time only small common + RDATA = 15 # load time only read-only data + VAR = 16 # var parameter (FORTRAN, Pascal) + COMMON = 17 # common variable + SCOMMON = 18 # small common + VARREGISTER = 19 # var parameter in a register + VARIANT = 20 # variant record + SUNDEFINED = 21 # small undefined (external) data + INIT = 22 # .init section symbol + BASEDVAR = 23 # FORTRAN or PL/1 ptr based var + XDATA = 24 # exception handling data + PDATA = 25 # procedure section + FINI = 26 # .fini section + RCONST = 27 # .rconst section + MAX = 32 # + +class EcoffSt(IntEnum): + NIL = 0 # + GLOBAL = 1 # external symbol + STATIC = 2 # static symbol + PARAM = 3 # procedure argument + LOCAL = 4 # local variable + LABEL = 5 # label + PROC = 6 # procedure + BLOCK = 7 # beginning of block + END = 8 # end of something + MEMBER = 9 # member of struct/union/enum/.. + TYPEDEF = 10 # type definition + FILE = 11 # filename + REGRELOC = 12 # register relocation + FORWARD = 13 # forwarding address + STATICPROC = 14 # load time only static procedures + # (CONSTANT and STAPARAM are in different orders between different sources...) + CONSTANT = 15 # constant + STAPARAM = 16 # FORTRAN static parameters + STRUCT = 26 # structure + UNION = 27 # union + ENUM = 28 # enum + INDIRECT = 34 # + +class EcoffTq(IntEnum): # Type qualifier + NIL = 0 # + PTR = 1 # pointer + PROC = 2 # procedure + ARRAY = 3 # array + FAR = 4 # longer addressing + VOL = 5 # volatile + CONST = 6 # constant + MAX = 8 # + + UNK7 = 7 # invalid + UNK9 = 9 # invalid + UNK10 = 10 # invalid + UNK11 = 11 # invalid + UNK12 = 12 # invalid + UNK13 = 13 # invalid + UNK14 = 14 # invalid + UNK = 15 # invalid + +class EcoffLanguageCode(IntEnum): + C = 0 + PASCAL = 1 + FORTRAN = 2 + ASM = 3 + MACHINE = 4 + NIL = 5 + ADA = 6 + PL1 = 7 + COBOL = 8 + STDC = 9 + CPLUSPLUSV2 = 10 + MAX = 11 + +def get_bitrange(value, start, length): + return (value >> start) & ((1 << length) - 1) + +def sign_extend_16(value): + return (value & 0x7FFF) - (value & 0x8000) + +def sign_extend_4(value): + return (value & 0x7) - (value & 0x8) + +class EcoffLiner: + """ + ECOFF Line Numbers Mapping + + typedef struct sLINER { + s32 count : 4; + s32 delta : 4; + } tLINER, *pLINER; + """ + + def __init__(self, data) -> None: + self.count = get_bitrange(data[0], 0, 4) + 1 + self.delta = get_bitrange(data[0], 4, 4) + + if self.delta == 8: + self.is_extended = True + self.delta = sign_extend_16((data[1] << 8) | data[2]) + self.data = data[:3] + else: + self.is_extended = False + self.delta = sign_extend_4(self.delta) + self.data = data[:1] + + def __str__(self) -> str: + return f"""= EcoffLiner ============= +delta = {self.delta} +count = {self.count} +extended = {self.is_extended}""" + +class EcoffTir: + """ + ECOFF Type Information Record + + typedef struct { +#ifdef LITTLE_ENDIAN + u32 tq3 : 4; + u32 tq2 : 4; + u32 tq1 : 4; /* 6 type qualifiers - tqPtr, etc. */ + u32 tq0 : 4; + /* ---- 16 bit boundary ---- */ + u32 tq5 : 4; + u32 tq4 : 4; + u32 bt : 6; /* basic type */ + u32 continued : 1; /* indicates additional TQ info in next AUX */ + u32 fBitfield : 1; /* set if bit width is specified */ +#else + u32 fBitfield : 1; /* set if bit width is specified */ + u32 continued : 1; /* indicates additional TQ info in next AUX */ + u32 bt : 6; /* basic type */ + u32 tq4 : 4; + u32 tq5 : 4; + /* ---- 16 bit boundary ---- */ + u32 tq0 : 4; + u32 tq1 : 4; /* 6 type qualifiers - tqPtr, etc. */ + u32 tq2 : 4; + u32 tq3 : 4; +#endif + } TIR, *pTIR; // size = 4 + """ + SIZE = 4 + + def __init__(self, data, endian) -> None: + if endian == 1: + self.tq3 = EcoffTq(get_bitrange(data, 0, 4)) + self.tq2 = EcoffTq(get_bitrange(data, 4, 4)) + self.tq1 = EcoffTq(get_bitrange(data, 8, 4)) + self.tq0 = EcoffTq(get_bitrange(data, 12, 4)) + self.tq5 = EcoffTq(get_bitrange(data, 16, 4)) + self.tq4 = EcoffTq(get_bitrange(data, 20, 4)) + self.bt = EcoffBt(get_bitrange(data, 24, 6)) + self.continued = get_bitrange(data, 30, 1) + self.fBitfield = get_bitrange(data, 31, 1) + else: + self.fBitfield = get_bitrange(data, 0, 1) + self.continued = get_bitrange(data, 1, 1) + self.bt = EcoffBt(get_bitrange(data, 2, 6)) + self.tq4 = EcoffTq(get_bitrange(data, 8, 4)) + self.tq5 = EcoffTq(get_bitrange(data, 12, 4)) + self.tq0 = EcoffTq(get_bitrange(data, 16, 4)) + self.tq1 = EcoffTq(get_bitrange(data, 20, 4)) + self.tq2 = EcoffTq(get_bitrange(data, 24, 4)) + self.tq3 = EcoffTq(get_bitrange(data, 28, 4)) + self.tqs = (self.tq0, self.tq1, self.tq2, self.tq3, self.tq4, self.tq5) + + def __str__(self) -> str: + return f"""= EcoffTIR ============== +fBitfield = {self.fBitfield} +continued = {self.continued} +bt = {self.bt.name} +tq4 = {self.tq4} +tq5 = {self.tq5} +tq0 = {self.tq0} +tq1 = {self.tq1} +tq2 = {self.tq2} +tq3 = {self.tq3}""" + +class EcoffRNDXR: + """ + typedef struct { +#ifdef LITTLE_ENDIAN + u32 index : 20; /* index int sym/aux/iss tables */ + u32 rfd : 12; /* index into the file indirect table */ +#else + u32 rfd : 12; /* index into the file indirect table */ + u32 index : 20; /* index int sym/aux/iss tables */ +#endif + } RNDXR, *pRNDXR; // size = 4 + """ + SIZE = 4 + + def __init__(self, data, endian) -> None: + if endian == 1: + self.index = get_bitrange(data, 0, 20) + self.rfd = get_bitrange(data, 20, 12) + else: + self.rfd = get_bitrange(data, 0, 12) + self.index = get_bitrange(data, 12, 20) + + def __str__(self) -> str: + return f"""= EcoffRNDXR ============== +index = {self.index} +rfd = {self.rfd}""" + +class EcoffAux: + """ + typedef union __sgi_auxu_u { + TIR ti; /* type information record */ + RNDXR rndx; /* relative index into symbol table */ + long_i dnLow; /* low dimension of array */ + long_i dnHigh; /* high dimension of array */ + long_i isym; /* symbol table index (end of proc) */ + long_i iss; /* index into string space (not used) */ + long_i width; /* width for non-default sized struct fields */ + long_i count; /* count of ranges for variant arm */ + } AUXU, *pAUXU; // size = 4 + """ + SIZE = 4 + + def __init__(self, fdr, data, endian) -> None: + data = struct.unpack((">" if endian == 1 else "<") + "I", data)[0] + self.ti = EcoffTir(data, endian) + self.rndx = EcoffRNDXR(data, endian) + self.dnLow = self.dnHigh = self.isym = self.iss = self.width = self.count = data + self.fdr = fdr + + def __str__(self) -> str: + return f"""= EcoffAux ============== +ti = {{ +{self.ti} +}} +rndx = {{ +{self.rndx} +}} +dnLow = {self.dnLow:04X} +dnHigh = {self.dnHigh:04X} +isym = {self.isym:04X} +iss = {self.iss:04X} +width = {self.width:04X} +count = {self.count:04X}""" + +class EcoffSymr: + """ + ECOFF Local Symbol + + typedef struct sSymr { + s32 iss; /* index into String Space of name */ + s32 value; /* symbol value */ + /* value can be an address, size or frame offset depending on symbol type */ + EcoffSt st : 6; /* symbol type */ + EcoffSc sc : 5; /* storage class - text, data, etc */ + s32 _reserved : 1; /* reserved bit */ + s32 index : 20; /* index into sym/aux table */ + } tSymr, *pSymr; // size = 0xC + """ + SIZE = 0xC + + def __init__(self, parent, idx, data): + self.idx = idx + self.parent = parent # can be either Fdr or Pdr + self.pdr = parent if type(parent) == EcoffPdr else None + self.fdr = self.pdr.parent if self.pdr is not None else parent + + self.data = data[:EcoffSymr.SIZE] + + self.iss, self.value, bits = struct.unpack(">III", self.data) + self.st = EcoffSt(get_bitrange(bits, 26, 6)) + self.sc = EcoffSc(get_bitrange(bits, 21, 5)) + self._reserved = get_bitrange(bits, 20, 1) + self.index = get_bitrange(bits, 0, 20) + + self.name = self.fdr.read_string(self.iss) + self.type_name = None + + self.c_repr = None + + assert self._reserved == 0 # Sanity check + + def link_syms(self): + if self.st == EcoffSt.END: + self.start_sym = self.fdr.symrs[self.index] + elif self.st in [EcoffSt.BLOCK, EcoffSt.FILE, EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: + self.end_sym = self.fdr.symrs[self.index - 1] + elif self.st in [EcoffSt.PROC, EcoffSt.STATICPROC]: + aux = self.fdr.auxs[self.index] + self.end_sym = self.fdr.symrs[aux.isym - 1] + elif self.st in [EcoffSt.GLOBAL, EcoffSt.STATIC, EcoffSt.PARAM, EcoffSt.LOCAL, EcoffSt.MEMBER, EcoffSt.TYPEDEF, EcoffSt.FORWARD]: + pass + + def late_init(self): + if self.st == EcoffSt.END: + """ + END symbols index the associated begin symbol + """ + self.start_sym = self.fdr.symrs[self.index] + if self.start_sym.st == EcoffSt.BLOCK: + self.c_repr = "}" + elif self.start_sym.st == EcoffSt.FILE: + self.c_repr = f"// end of file: \"{self.start_sym.name}\"" + elif self.start_sym.st in [EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: + self.c_repr = "}" + if len(self.start_sym.type_name) != 0: + self.c_repr += " " + self.start_sym.type_name + self.c_repr += f";" + elif self.st in [EcoffSt.BLOCK, EcoffSt.FILE, EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: + """ + These symbols index the first symbol after their associated END symbol + """ + self.end_sym = self.fdr.symrs[self.index - 1] + if self.st == EcoffSt.BLOCK: + self.c_repr = "{" + elif self.st == EcoffSt.FILE: + self.c_repr = f"#line 1 \"{self.name}\"" + elif self.st in [EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.ENUM]: + keyword = "" + self.type_name = "" + next_sym = self.fdr.symrs[self.index] + if next_sym.st == EcoffSt.TYPEDEF: + # possible typedef struct/union/enum + # TODO check this by ensuring the typedef symbol references this symbol + keyword += "typedef " + self.type_name = next_sym.name + + if self.st == EcoffSt.UNION: + keyword += "union" + elif self.st == EcoffSt.ENUM: + keyword += "enum" + else: + keyword += "struct" + + name = self.name + if len(name) != 0: + name = ' ' + name + + self.c_repr = f"{keyword}{name} {{" + elif self.st in [EcoffSt.PROC, EcoffSt.STATICPROC]: + aux1 = self.fdr.auxs[self.index] + self.end_sym = self.fdr.symrs[aux1.isym - 1] + + self.c_repr = "" + if self.st == EcoffSt.STATICPROC: + self.c_repr += "static " + + self.return_type, _ = self.process_type_information(1) + self.c_repr += self.return_type + if len(self.return_type) != 0: + self.c_repr += " " + self.c_repr += self.name + self.c_repr += "()" + elif self.st in [EcoffSt.GLOBAL, EcoffSt.STATIC, EcoffSt.PARAM, EcoffSt.LOCAL, EcoffSt.MEMBER, EcoffSt.FORWARD]: + self.c_repr = "" + if self.st == EcoffSt.MEMBER: + # value of a stMember is the offset in bits + self.c_repr += f"/* 0x{self.value//8:X} */ " + + type_str, bitwidth = self.process_type_information(0) + self.c_repr += type_str + if len(self.c_repr) != 0: + self.c_repr += " " + self.c_repr += f"{self.name}{f' : {bitwidth}' if bitwidth is not None else ''};" + elif self.st == EcoffSt.TYPEDEF: + # TODO the typedef may already be absorbed into a struct or similar, check before emitting + type_str, _ = self.process_type_information(0) + self.c_repr = f"typedef {type_str} {self.name};" + elif self.st == EcoffSt.LABEL: + self.c_repr = f"{self.name}:" + + def process_type_information(self, ind): + c_bt_names = { + EcoffBt.NIL : None, + EcoffBt.ADR : None, + EcoffBt.CHAR : "signed char", + EcoffBt.UCHAR : "char", + EcoffBt.SHORT : "short", + EcoffBt.USHORT : "unsigned short", + EcoffBt.INT : "int", + EcoffBt.UINT : "unsigned int", + EcoffBt.LONG : "long", + EcoffBt.ULONG : "unsigned long", + EcoffBt.FLOAT : "float", + EcoffBt.DOUBLE : "double", + EcoffBt.STRUCT : "struct", + EcoffBt.UNION : "union", + EcoffBt.ENUM : "enum", + EcoffBt.TYPEDEF : "typedef", + EcoffBt.RANGE : None, + EcoffBt.SET : None, + EcoffBt.COMPLEX : "complex", + EcoffBt.DCOMPLEX : "double complex", + EcoffBt.INDIRECT : None, + EcoffBt.FIXEDDEC : None, + EcoffBt.FLOATDEC : None, + EcoffBt.STRING : "const char*", + EcoffBt.BIT : None, + EcoffBt.PICTURE : None, + EcoffBt.VOID : "void", + EcoffBt.LONGLONG : "long long", + EcoffBt.ULONGLONG : "unsigned long long", + EcoffBt.LONG64 : "long", + EcoffBt.ULONG64 : "unsigned long", + EcoffBt.LONGLONG64 : "long long", + EcoffBt.ULONGLONG64 : "unsigned long long", + EcoffBt.ADR64 : None, + EcoffBt.INT64 : None, + EcoffBt.UINT64 : None, + } + c_tq_str = { + EcoffTq.NIL : "", + EcoffTq.PTR : "*", + EcoffTq.PROC : "()", + EcoffTq.ARRAY : "[]", + EcoffTq.FAR : "/* FAR */", + EcoffTq.VOL : "volatile", + EcoffTq.CONST : "const", + } + + if self.index == 0xFFFFF: + # no type info + return "", None + + aux = self.fdr.auxs[self.index + ind] + ind += 1 + type_str = "" + + bit_width = None + if aux.ti.fBitfield == 1: + bit_width = self.fdr.auxs[self.index + ind].isym + ind += 1 + + if aux.ti.bt in [EcoffBt.STRUCT, EcoffBt.UNION, EcoffBt.ENUM, EcoffBt.TYPEDEF]: + type_ref_aux = self.fdr.auxs[self.index + ind] + ind += 1 + + fd_ref_idx = type_ref_aux.rndx.rfd + if fd_ref_idx == 4095: + fd_ref_idx = self.fdr.auxs[self.index + ind].isym + ind += 1 + + fdr_ref = self.fdr.parent.fdrs[fd_ref_idx] + sym_ref = fdr_ref.symrs[type_ref_aux.rndx.index] + # now we have the reference to the stStruct, stUnion, stEnum, or stTypeDef + type_str += f"{sym_ref.type_name if sym_ref.type_name is not None else sym_ref.name}" + else: + type_str += f"{c_bt_names[aux.ti.bt]}" + + # TODO improve emitting qualified types + tqs = "" + for tq in aux.ti.tqs: + if tq == EcoffTq.NIL: + continue + if tq == EcoffTq.ARRAY: + ind += 2 # skips over some info such as the type of index (always int for C) + array_low_aux = self.fdr.auxs[self.index + ind] + array_high_aux = self.fdr.auxs[self.index + ind + 1] + stride_aux = self.fdr.auxs[self.index + ind + 2] + ind += 3 + tqs += "[" + if array_high_aux.dnHigh != 0xFFFFFFFF: + tqs += '%d' % (array_high_aux.dnHigh + 1) + tqs += "]" + else: + tqs += c_tq_str[tq] + tqs += " " + tqs = tqs.strip() + if len(tqs) != 0: + type_str += " " + tqs + + return type_str, bit_width + + def __str__(self) -> str: + return f"""= EcoffSymr ============== {self.idx} +iss = 0x{self.iss:08X} +value = 0x{self.value:08X} +st = st{self.st.name} +sc = sc{self.sc.name} +_reserved = {self._reserved} +index = 0x{self.index:05X} +name = {self.name}""" + +class EcoffPdr: + """ + ECOFF Procedure Descriptor + + typedef struct sPDR { + s32 addr; /* memory address of start of procedure */ + s32 isym; /* start of local symbol entries */ + s32 iline; /* start of line number entries */ + s32 regmask; /* save register mask */ + s32 regoffset; /* save register offset */ + s32 iopt; /* start of optimization symbol entries */ + s32 fregmask; /* save floating point register mask */ + s32 fregoffset; /* save floating point register offset */ + s32 frameoffset; /* frame size */ + u16 framereg; /* frame pointer register */ + u16 pcreg; /* offset or reg of return pc */ + s32 lnLow; /* lowest line in the procedure */ + s32 lnHigh; /* highest line in the procedure */ + s32 cbLineOffset; /* byte offset for this procedure from the fd base */ +#ifdef 64_BIT + // TODO there's a bitfield in here + s32 gpPrologue; /* byte size of GP prologue */ + s32 gpUsed; /* true if the procedure uses GP */ + s32 regFrame; /* true if register frame procedure */ + s32 prof; /* true if compiled with -pg */ + s32 localOffset; /* offset of local variables from vfp */ +#endif + } tPDR, *pPDR; // size = 0x34 + """ + SIZE = 0x34 + + def __init__(self, fdr, data) -> None: + self.parent = fdr + self.data = data[:EcoffPdr.SIZE] + + self.addr, self.isym, self.iline, self.regmask, \ + self.regoffset, self.iopt, self.fregmask, self.fregoffset, \ + self.frameoffset, self.framereg, self.pcreg, self.lnLow, \ + self.lnHigh, self.cbLineOffset = struct.unpack(">IIIIIIIIIHHIII", self.data) + + self.symrs = [] + + i = self.isym + symr = self.parent.symrs[i] + assert symr.st == EcoffSt.PROC or symr.st == EcoffSt.STATICPROC + # Inherit procedure name from procedure symbol + self.name = symr.name + + self.symrs.append(symr) + while not (symr.st == EcoffSt.END and symr.name == self.symrs[0].name): + i += 1 + symr = self.parent.symrs[i] + self.symrs.append(symr) + + assert symr.st == EcoffSt.END and symr.sc == EcoffSc.TEXT + self.size = symr.value # value field of an stEND and scTEXT symbol is the procedure size + assert self.size % 4 == 0 + + # indexed by asm word offset from proc start + self.lines = [] + + # ilineMax = self.parent.parent.hdrr.ilineMax + # cbLine = self.parent.parent.hdrr.cbLine + # cbLineOffset = self.parent.parent.hdrr.cbLineOffset + # ilineBase = self.parent.ilineBase + # cline = self.parent.cline + # cbLineOffset = self.parent.cbLineOffset + # cbLine = self.parent.cbLine + # lnLow = self.lnLow + # lnHigh = self.lnHigh + # iline = self.iline + + elf_data = self.parent.parent.parent.data + + line_no = self.lnLow # first line in the procedure + line_data = self.parent.parent.hdrr.cbLineOffset + self.parent.cbLineOffset + self.cbLineOffset + # line_end = self.parent.parent.hdrr.cbLineOffset + self.parent.cbLineOffset + self.parent.cbLine + + # print(self) + # print(f"{self.name} [{self.lnLow}:{self.lnHigh}]") + # print(self.size//4) + while len(self.lines) < self.size//4: + # assert line_data < line_end , "Overflow in line numbers table" + + liner = EcoffLiner(elf_data[line_data:]) + line_no += liner.delta + # if line_no < self.lnLow or line_no > self.lnHigh: + # break + + # print(liner) + for i in range(liner.count): + # print(f"[{len(self.lines)}] {line_no}") + self.lines.append(line_no) + + line_data += len(liner.data) + + def lookup_sym(self, value, type=-1): + for sym in self.symrs: + if sym.value == value and (type == -1 or type == sym.st): + return sym + return None + + def __str__(self) -> str: + return f"""= EcoffPdr =============== +addr = 0x{self.addr:08X} +isym = 0x{self.isym:08X} +iline = 0x{self.iline:08X} +regmask = 0b{self.regmask:032b} +regoffset = 0x{self.regoffset:08X} +iopt = 0x{self.iopt:08X} +fregmask = 0b{self.fregmask:032b} +fregoffset = 0x{self.fregoffset:08X} +frameoffset = 0x{self.frameoffset:08X} +framereg = ${self.framereg} +pcreg = ${self.pcreg} +lnLow = {self.lnLow} +lnHigh = {self.lnHigh} +cbLineOffset = 0x{self.cbLineOffset:08X} +name = {self.name}""" + +class EcoffFdr: + """ + ECOFF File Descriptor + + typedef struct sFDR { + u32 adr; /* memory address of beginning of file */ + s32 rss; /* file name (of source, if known) */ + s32 issBase; /* file's string space */ + s32 cbSs; /* number of bytes in the ss */ + s32 isymBase; /* beginning of symbols */ + s32 csym; /* count file's of symbols */ + s32 ilineBase; /* file's line symbols */ + s32 cline; /* count of file's line symbols */ + s32 ioptBase; /* file's optimization entries */ + s32 copt; /* count of file's optimization entries */ + u16 ipdFirst; /* start of procedures for this file */ + u16 cpd; /* count of procedures for this file */ + s32 iauxBase; /* file's auxiliary entries */ + s32 caux; /* count of file's auxiliary entries */ + s32 rfdBase; /* index into the file indirect table */ + s32 crfd; /* count file indirect entries */ + EcoffLanguageCode lang : 5; /* language for this file */ + u32 fMerge : 1; /* whether this file can be merged */ + u32 fReadin : 1; /* true if it was read in (not just created) */ + u32 fBigEndian : 1; /* true if AUXU's are big endian */ + u32 glevel : 2; /* level this file was compiled with */ + u32 _reserved : 20; /* reserved bits */ + s32 cbLineOffset; /* byte offset from header for this file ln's */ + s32 cbLine; /* size of lines for this file */ + } tFDR, *pFDR; // size = 0x48 + """ + SIZE = 0x48 + + @staticmethod + def from_binary(mdebug, i): + # Init + if 'init' not in EcoffFdr.from_binary.__dict__: + EcoffFdr.from_binary.cache = {} + EcoffFdr.from_binary.init = True + # Parent Init + if mdebug not in EcoffFdr.from_binary.cache: + EcoffFdr.from_binary.cache[mdebug] = {} + # Cache hit + if i in EcoffFdr.from_binary.cache[mdebug]: + return EcoffFdr.from_binary.cache[mdebug][i] + # Cache miss + cbFdOffset = mdebug.hdrr.cbFdOffset + elf_data = mdebug.parent.data + EcoffFdr.from_binary.cache[mdebug][i] = EcoffFdr(mdebug, elf_data[cbFdOffset+i*EcoffFdr.SIZE:cbFdOffset+(i+1)*EcoffFdr.SIZE]) + return EcoffFdr.from_binary.cache[mdebug][i] + + def __init__(self, mdebug, data) -> None: + self.parent = mdebug + self.data = data[:EcoffFdr.SIZE] + + self.adr, self.rss, self.issBase, self.cbSs, \ + self.isymBase, self.csym, self.ilineBase, self.cline, \ + self.ioptBase, self.copt, self.ipdFirst, self.cpd, \ + self.iauxBase, self.caux, self.rfdBase, self.crfd, \ + bits, self.cbLineOffset, self.cbLine = struct.unpack(">IIIIIIIIIIHHIIIIIII", self.data) + + self.lang = EcoffLanguageCode(get_bitrange(bits, 27, 5)) + self.fMerge = get_bitrange(bits, 26, 1) + self.fReadin = get_bitrange(bits, 25, 1) + self.fBigEndian = get_bitrange(bits, 24, 1) + self.glevel = get_bitrange(bits, 22, 2) + self._reserved = get_bitrange(bits, 2, 20) + + self.name = self.parent.read_string(self.issBase + self.rss) + + # print(self) + + hdrr = self.parent.hdrr + elf_data = self.parent.parent.data + + # Aux Symbols + self.auxs = [] + for i in range(self.caux): + i += self.iauxBase + assert i < hdrr.iauxMax , "Out of bounds in Auxiliary Symbol Table" + aux = EcoffAux(self, elf_data[hdrr.cbAuxOffset+i*EcoffAux.SIZE:][:EcoffAux.SIZE], self.fBigEndian) + self.auxs.append(aux) + + # Symbols + self.symrs = [] + for i in range(self.csym): + j = i + self.isymBase + assert j < hdrr.isymMax , "Out of bounds in Local Symbol Table" + symr = EcoffSymr(self, i, elf_data[hdrr.cbSymOffset+j*EcoffSymr.SIZE:hdrr.cbSymOffset+(j+1)*EcoffSymr.SIZE]) + self.symrs.append(symr) + for symr in self.symrs: + symr.link_syms() + + # PDRs + self.pdrs = [] + for i in range(self.cpd): + i += self.ipdFirst + assert i < hdrr.ipdMax , "Out of bounds in Procedure Descriptor Table" + pdr = EcoffPdr(self, elf_data[hdrr.cbPdOffset+i*EcoffPdr.SIZE:hdrr.cbPdOffset+(i+1)*EcoffPdr.SIZE]) + self.pdrs.append(pdr) + + self.size = sum([pdr.size for pdr in self.pdrs]) + + def late_init(self): + for symr in self.symrs: + symr.late_init() + + def pdr_forname(self, procedure_name): + for pdr in self.pdrs: + if pdr.name == procedure_name: + return pdr + return None + + def pdr_foranyaddr(self, addr): + for pdr in self.pdrs: + if pdr.addr <= addr and pdr.addr + pdr.size > addr: + return pdr + return None + + def pdr_foraddr(self, addr): + for pdr in self.pdrs: + if pdr.addr == addr: + return pdr + return None + + def read_string(self, index): + return self.parent.read_string(self.issBase + index) + + def c_str(self) -> str: + """ + C prettyprint file + """ + def print_symbol(symr): + return f"{symr.st.name} :: {symr.c_repr}" + + indent = 0 + out = f"File: {self.name}\n" + + for symr in self.symrs: + if symr.st in [EcoffSt.END]: + indent -= 2 + + out += " " * indent + out += print_symbol(symr) + out += "\n" + + if symr.st in [EcoffSt.FILE, EcoffSt.STRUCT, EcoffSt.UNION, EcoffSt.PROC, EcoffSt.STATICPROC, EcoffSt.BLOCK]: + indent += 2 + + return out + + def __str__(self) -> str: + return f"""= EcoffFdr =============== +adr = 0x{self.adr:08X} +rss = 0x{self.rss:08X} +issBase = 0x{self.issBase:08X} +cbSs = 0x{self.cbSs:08X} +isymBase = 0x{self.isymBase:08X} +csym = 0x{self.csym:08X} +ilineBase = 0x{self.ilineBase:08X} +cline = 0x{self.cline:08X} +ioptBase = 0x{self.ioptBase:08X} +copt = 0x{self.copt:08X} +ipdFirst = 0x{self.ipdFirst:08X} +cpd = 0x{self.cpd:08X} +iauxBase = 0x{self.iauxBase:08X} +caux = 0x{self.caux:08X} +rfdBase = 0x{self.rfdBase:08X} +crfd = 0x{self.crfd:08X} +lang = {self.lang.name} +fMerge = {bool(self.fMerge)} +fReadin = {bool(self.fReadin)} +fBigEndian = {bool(self.fBigEndian)} +glevel = {self.glevel} +_reserved = {self._reserved} +cbLineOffset = 0x{self.cbLineOffset:08X} +cbLine = 0x{self.cbLine:08X} +name = {self.name}""" + +class EcoffHDRR: + """ + Symbolic Header + + typedef struct sHDRR { + u16 magic; /* 0x7009 */ + u16 vstamp; /* version stamp */ + s32 ilineMax; /* number of line number entries */ + s32 cbLine; /* number of bytes for line number entries */ + s32 cbLineOffset; /* offset to start of line number entries */ + s32 idnMax; /* max index into dense number table */ + s32 cbDnOffset; /* offset to start dense number table */ + s32 ipdMax; /* number of procedures */ + s32 cbPdOffset; /* offset to procedure descriptor table */ + s32 isymMax; /* number of local symbols */ + s32 cbSymOffset; /* offset to start of local symbols */ + s32 ioptMax; /* max index into optimization symbol entries */ + s32 cbOptOffset; /* offset to optimization symbol entries */ + s32 iauxMax; /* number of auxillary symbol entries */ + s32 cbAuxOffset; /* offset to start of auxillary symbol entries */ + s32 issMax; /* max index into local strings */ + s32 cbSsOffset; /* offset to start of local strings */ + s32 issExtMax; /* max index into external strings */ + s32 cbSsExtOffset; /* offset to start of external strings */ + s32 ifdMax; /* number of file descriptor entries */ + s32 cbFdOffset; /* offset to file descriptor table */ + s32 crfd; /* number of relative file descriptor entries */ + s32 cbRfdOffset; /* offset to relative file descriptor table */ + s32 iextMax; /* max index into external symbols */ + s32 cbExtOffset; /* offset to start of external symbol entries */ + } tHDRR, *pHDRR; // size = 0x60 + """ + HDRR_MAGIC = 0x7009 + SIZE = 0x60 + + def __init__(self, data) -> None: + self.data = data[:EcoffHDRR.SIZE] + + self.magic, self.vstamp, self.ilineMax, self.cbLine, \ + self.cbLineOffset, self.idnMax, self.cbDnOffset, self.ipdMax, \ + self.cbPdOffset, self.isymMax, self.cbSymOffset, self.ioptMax, \ + self.cbOptOffset, self.iauxMax, self.cbAuxOffset, self.issMax, \ + self.cbSsOffset, self.issExtMax, self.cbSsExtOffset, self.ifdMax, \ + self.cbFdOffset, self.crfd, self.cbRfdOffset, self.iextMax, \ + self.cbExtOffset = struct.unpack(">HHIIIIIIIIIIIIIIIIIIIIIII", self.data) + + assert self.magic == EcoffHDRR.HDRR_MAGIC , f"Symbolic Header magic value is incorrect. Got 0x{self.magic:04X}, expected 0x{EcoffHDRR.HDRR_MAGIC:04X}" + + def __str__(self) -> str: + return f"""= EcoffHDRR ============== +magic = 0x{self.magic:04X} +vstamp = 0x{self.vstamp:04X} +ilineMax = 0x{self.ilineMax:08X} +cbLine = 0x{self.cbLine:08X} +cbLineOffset = 0x{self.cbLineOffset:08X} +idnMax = 0x{self.idnMax:08X} +cbDnOffset = 0x{self.cbDnOffset:08X} +ipdMax = 0x{self.ipdMax:08X} +cbPdOffset = 0x{self.cbPdOffset:08X} +isymMax = 0x{self.isymMax:08X} +cbSymOffset = 0x{self.cbSymOffset:08X} +ioptMax = 0x{self.ioptMax:08X} +cbOptOffset = 0x{self.cbOptOffset:08X} +iauxMax = 0x{self.iauxMax:08X} +cbAuxOffset = 0x{self.cbAuxOffset:08X} +issMax = 0x{self.issMax:08X} +cbSsOffset = 0x{self.cbSsOffset:08X} +issExtMax = 0x{self.issExtMax:08X} +cbSsExtOffset = 0x{self.cbSsExtOffset:08X} +ifdMax = 0x{self.ifdMax:08X} +cbFdOffset = 0x{self.cbFdOffset:08X} +crfd = 0x{self.crfd:08X} +cbRfdOffset = 0x{self.cbRfdOffset:08X} +iextMax = 0x{self.iextMax:08X} +cbExtOffset = 0x{self.cbExtOffset:08X}""" diff --git a/lib/ultralib/tools/mips_isa.py b/lib/ultralib/tools/mips_isa.py new file mode 100644 index 0000000..d99dcda --- /dev/null +++ b/lib/ultralib/tools/mips_isa.py @@ -0,0 +1,1309 @@ +# TODO enum these constants +from enum import IntEnum, auto + +# Register IDs +class MipsGPReg(IntEnum): + R0 = 0 # 0 + AT = auto() # 1 + V0 = auto() # 2 + V1 = auto() # 3 + A0 = auto() # 4 + A1 = auto() # 5 + A2 = auto() # 6 + A3 = auto() # 7 + T0 = auto() # 8 + T1 = auto() # 9 + T2 = auto() # 10 + T3 = auto() # 11 + T4 = auto() # 12 + T5 = auto() # 13 + T6 = auto() # 14 + T7 = auto() # 15 + S0 = auto() # 16 + S1 = auto() # 17 + S2 = auto() # 18 + S3 = auto() # 19 + S4 = auto() # 20 + S5 = auto() # 21 + S6 = auto() # 22 + S7 = auto() # 23 + T8 = auto() # 24 + T9 = auto() # 25 + K0 = auto() # 26 + K1 = auto() # 27 + GP = auto() # 28 + SP = auto() # 29 + FP = auto() # 30 + RA = auto() # 31 + +class MipsFPReg(IntEnum): + F0 = 0 # 0 + F1 = auto() # 1 + F2 = auto() # 2 + F3 = auto() # 3 + F4 = auto() # 4 + F5 = auto() # 5 + F6 = auto() # 6 + F7 = auto() # 7 + F8 = auto() # 8 + F9 = auto() # 9 + F10 = auto() # 10 + F11 = auto() # 11 + F12 = auto() # 12 + F13 = auto() # 13 + F14 = auto() # 14 + F15 = auto() # 15 + F16 = auto() # 16 + F17 = auto() # 17 + F18 = auto() # 18 + F19 = auto() # 19 + F20 = auto() # 20 + F21 = auto() # 21 + F22 = auto() # 22 + F23 = auto() # 23 + F24 = auto() # 24 + F25 = auto() # 25 + F26 = auto() # 26 + F27 = auto() # 27 + F28 = auto() # 28 + F29 = auto() # 29 + F30 = auto() # 30 + F31 = auto() # 31 + +# Instruction Unique IDs +MIPS_INS_SLL = 0 +MIPS_INS_SRL = 1 +MIPS_INS_SRA = 2 +MIPS_INS_SLLV = 3 +MIPS_INS_SRLV = 4 +MIPS_INS_SRAV = 5 +MIPS_INS_JR = 6 +MIPS_INS_JALR = 7 +MIPS_INS_SYSCALL = 8 +MIPS_INS_BREAK = 9 +MIPS_INS_SYNC = 10 +MIPS_INS_MFHI = 11 +MIPS_INS_MTHI = 12 +MIPS_INS_MFLO = 13 +MIPS_INS_MTLO = 14 +MIPS_INS_DSLLV = 15 +MIPS_INS_DSRLV = 16 +MIPS_INS_DSRAV = 17 +MIPS_INS_MULT = 18 +MIPS_INS_MULTU = 19 +MIPS_INS_DIV = 20 +MIPS_INS_DIVU = 21 +MIPS_INS_DMULT = 22 +MIPS_INS_DMULTU = 23 +MIPS_INS_DDIV = 24 +MIPS_INS_DDIVU = 25 +MIPS_INS_ADD = 26 +MIPS_INS_ADDU = 27 +MIPS_INS_SUB = 28 +MIPS_INS_SUBU = 29 +MIPS_INS_AND = 30 +MIPS_INS_OR = 31 +MIPS_INS_XOR = 32 +MIPS_INS_NOR = 33 +MIPS_INS_SLT = 34 +MIPS_INS_SLTU = 35 +MIPS_INS_DADD = 36 +MIPS_INS_DADDU = 37 +MIPS_INS_DSUB = 38 +MIPS_INS_DSUBU = 39 +MIPS_INS_TGE = 40 +MIPS_INS_TGEU = 41 +MIPS_INS_TLT = 42 +MIPS_INS_TLTU = 43 +MIPS_INS_TEQ = 44 +MIPS_INS_TNE = 45 +MIPS_INS_DSLL = 46 +MIPS_INS_DSRL = 47 +MIPS_INS_DSRA = 48 +MIPS_INS_DSLL32 = 49 +MIPS_INS_DSRL32 = 50 +MIPS_INS_DSRA32 = 51 +MIPS_INS_BLTZ = 52 +MIPS_INS_BGEZ = 53 +MIPS_INS_BLTZL = 54 +MIPS_INS_BGEZL = 55 +MIPS_INS_TGEI = 56 +MIPS_INS_TGEIU = 57 +MIPS_INS_TLTI = 58 +MIPS_INS_TLTIU = 59 +MIPS_INS_TEQI = 60 +MIPS_INS_TNEI = 61 +MIPS_INS_BLTZAL = 62 +MIPS_INS_BGEZAL = 63 +MIPS_INS_BLTZALL = 64 +MIPS_INS_BGEZALL = 65 +MIPS_INS_J = 66 +MIPS_INS_JAL = 67 +MIPS_INS_BEQ = 68 +MIPS_INS_BNE = 69 +MIPS_INS_BLEZ = 70 +MIPS_INS_BGTZ = 71 +MIPS_INS_ADDI = 72 +MIPS_INS_ADDIU = 73 +MIPS_INS_SLTI = 74 +MIPS_INS_SLTIU = 75 +MIPS_INS_ANDI = 76 +MIPS_INS_ORI = 77 +MIPS_INS_XORI = 78 +MIPS_INS_LUI = 79 +MIPS_INS_MFC0 = 80 +MIPS_INS_MTC0 = 81 +MIPS_INS_TLBR = 82 +MIPS_INS_TLBWI = 83 +MIPS_INS_TLBWR = 84 +MIPS_INS_TLBP = 85 +MIPS_INS_ERET = 86 +MIPS_INS_MFC1 = 87 +MIPS_INS_DMFC1 = 88 +MIPS_INS_CFC1 = 89 +MIPS_INS_MTC1 = 90 +MIPS_INS_DMTC1 = 91 +MIPS_INS_CTC1 = 92 +MIPS_INS_BC1F = 93 +MIPS_INS_BC1T = 94 +MIPS_INS_BC1FL = 95 +MIPS_INS_BC1TL = 96 +MIPS_INS_ADD_S = 97 +MIPS_INS_SUB_S = 98 +MIPS_INS_MUL_S = 99 +MIPS_INS_DIV_S = 100 +MIPS_INS_SQRT_S = 101 +MIPS_INS_ABS_S = 102 +MIPS_INS_MOV_S = 103 +MIPS_INS_NEG_S = 104 +MIPS_INS_ROUND_L_S = 105 +MIPS_INS_TRUNC_L_S = 106 +MIPS_INS_CEIL_L_S = 107 +MIPS_INS_FLOOR_L_S = 108 +MIPS_INS_ROUND_W_S = 109 +MIPS_INS_TRUNC_W_S = 110 +MIPS_INS_CEIL_W_S = 111 +MIPS_INS_FLOOR_W_S = 112 +MIPS_INS_CVT_D_S = 113 +MIPS_INS_CVT_W_S = 114 +MIPS_INS_CVT_L_S = 115 +MIPS_INS_C_F_S = 116 +MIPS_INS_C_UN_S = 117 +MIPS_INS_C_EQ_S = 118 +MIPS_INS_C_UEQ_S = 119 +MIPS_INS_C_OLT_S = 120 +MIPS_INS_C_ULT_S = 121 +MIPS_INS_C_OLE_S = 122 +MIPS_INS_C_ULE_S = 123 +MIPS_INS_C_SF_S = 124 +MIPS_INS_C_NGLE_S = 125 +MIPS_INS_C_SEQ_S = 126 +MIPS_INS_C_NGL_S = 127 +MIPS_INS_C_LT_S = 128 +MIPS_INS_C_NGE_S = 129 +MIPS_INS_C_LE_S = 130 +MIPS_INS_C_NGT_S = 131 +MIPS_INS_ADD_D = 132 +MIPS_INS_SUB_D = 133 +MIPS_INS_MUL_D = 134 +MIPS_INS_DIV_D = 135 +MIPS_INS_SQRT_D = 136 +MIPS_INS_ABS_D = 137 +MIPS_INS_MOV_D = 138 +MIPS_INS_NEG_D = 139 +MIPS_INS_ROUND_L_D = 140 +MIPS_INS_TRUNC_L_D = 141 +MIPS_INS_CEIL_L_D = 142 +MIPS_INS_FLOOR_L_D = 143 +MIPS_INS_ROUND_W_D = 144 +MIPS_INS_TRUNC_W_D = 145 +MIPS_INS_CEIL_W_D = 146 +MIPS_INS_FLOOR_W_D = 147 +MIPS_INS_CVT_S_D = 148 +MIPS_INS_CVT_W_D = 149 +MIPS_INS_CVT_L_D = 150 +MIPS_INS_C_F_D = 151 +MIPS_INS_C_UN_D = 152 +MIPS_INS_C_EQ_D = 153 +MIPS_INS_C_UEQ_D = 154 +MIPS_INS_C_OLT_D = 155 +MIPS_INS_C_ULT_D = 156 +MIPS_INS_C_OLE_D = 157 +MIPS_INS_C_ULE_D = 158 +MIPS_INS_C_SF_D = 159 +MIPS_INS_C_NGLE_D = 160 +MIPS_INS_C_SEQ_D = 161 +MIPS_INS_C_NGL_D = 162 +MIPS_INS_C_LT_D = 163 +MIPS_INS_C_NGE_D = 164 +MIPS_INS_C_LE_D = 165 +MIPS_INS_C_NGT_D = 166 +MIPS_INS_CVT_S_W = 167 +MIPS_INS_CVT_D_W = 168 +MIPS_INS_CVT_S_L = 169 +MIPS_INS_CVT_D_L = 170 +MIPS_INS_BEQL = 171 +MIPS_INS_BNEL = 172 +MIPS_INS_BLEZL = 173 +MIPS_INS_BGTZL = 174 +MIPS_INS_DADDI = 175 +MIPS_INS_DADDIU = 176 +MIPS_INS_LDL = 177 +MIPS_INS_LDR = 178 +MIPS_INS_LB = 179 +MIPS_INS_LH = 180 +MIPS_INS_LWL = 181 +MIPS_INS_LW = 182 +MIPS_INS_LBU = 183 +MIPS_INS_LHU = 184 +MIPS_INS_LWR = 185 +MIPS_INS_LWU = 186 +MIPS_INS_SB = 187 +MIPS_INS_SH = 188 +MIPS_INS_SWL = 189 +MIPS_INS_SW = 190 +MIPS_INS_SDL = 191 +MIPS_INS_SDR = 192 +MIPS_INS_SWR = 193 +MIPS_INS_CACHE = 194 +MIPS_INS_LL = 195 +MIPS_INS_LWC1 = 196 +MIPS_INS_LWC2 = 197 +MIPS_INS_LLD = 198 +MIPS_INS_LDC1 = 199 +MIPS_INS_LDC2 = 200 +MIPS_INS_LD = 201 +MIPS_INS_SC = 202 +MIPS_INS_SWC1 = 203 +MIPS_INS_SWC2 = 204 +MIPS_INS_SCD = 205 +MIPS_INS_SDC1 = 206 +MIPS_INS_SDC2 = 207 +MIPS_INS_SD = 208 + +# RSP COP2 +MIPS_INS_VMULF = 209 +MIPS_INS_VMULU = 210 +MIPS_INS_VRNDP = 211 +MIPS_INS_VMULQ = 212 +MIPS_INS_VMUDL = 213 +MIPS_INS_VMUDM = 214 +MIPS_INS_VMUDN = 215 +MIPS_INS_VMUDH = 216 +MIPS_INS_VMACF = 217 +MIPS_INS_VMACU = 218 +MIPS_INS_VRNDN = 219 +MIPS_INS_VMACQ = 220 +MIPS_INS_VMADL = 221 +MIPS_INS_VMADM = 222 +MIPS_INS_VMADN = 223 +MIPS_INS_VMADH = 224 +MIPS_INS_VADD = 225 +MIPS_INS_VSUB = 226 +MIPS_INS_VABS = 227 +MIPS_INS_VADDC = 228 +MIPS_INS_VSUBC = 229 +MIPS_INS_VSAR = 230 +MIPS_INS_VLT = 231 +MIPS_INS_VEQ = 232 +MIPS_INS_VNE = 233 +MIPS_INS_VGE = 234 +MIPS_INS_VCL = 235 +MIPS_INS_VCH = 236 +MIPS_INS_VCR = 237 +MIPS_INS_VMRG = 238 +MIPS_INS_VAND = 239 +MIPS_INS_VNAND = 240 +MIPS_INS_VOR = 241 +MIPS_INS_VNOR = 242 +MIPS_INS_VXOR = 243 +MIPS_INS_VNXOR = 244 +MIPS_INS_VRCP = 245 +MIPS_INS_VRCPL = 246 +MIPS_INS_VRCPH = 247 +MIPS_INS_VMOV = 248 +MIPS_INS_VRSQ = 249 +MIPS_INS_VRSQL = 250 +MIPS_INS_VRSQH = 251 +MIPS_INS_VNOP = 252 +MIPS_INS_LBV = 253 +MIPS_INS_LSV = 254 +MIPS_INS_LLV = 255 +MIPS_INS_LDV = 256 +MIPS_INS_LQV = 257 +MIPS_INS_LRV = 258 +MIPS_INS_LPV = 259 +MIPS_INS_LUV = 260 +MIPS_INS_LHV = 261 +MIPS_INS_LFV = 262 +MIPS_INS_LTV = 263 +MIPS_INS_SBV = 264 +MIPS_INS_SSV = 265 +MIPS_INS_SLV = 266 +MIPS_INS_SDV = 267 +MIPS_INS_SQV = 268 +MIPS_INS_SRV = 269 +MIPS_INS_SPV = 270 +MIPS_INS_SUV = 271 +MIPS_INS_SHV = 272 +MIPS_INS_SFV = 273 +MIPS_INS_SWV = 274 +MIPS_INS_STV = 275 +MIPS_INS_MFC2 = 276 +MIPS_INS_MTC2 = 277 +MIPS_INS_CFC2 = 278 +MIPS_INS_CTC2 = 279 + +# Pseudo-Instruction Unique IDs +MIPS_INS_BEQZ = 280 +MIPS_INS_BNEZ = 281 +MIPS_INS_B = 282 +MIPS_INS_NOP = 283 +MIPS_INS_MOVE = 284 +MIPS_INS_NEGU = 285 +MIPS_INS_NOT = 286 + +# Invalid Instruction Unique ID +MIPS_INS_INVALID = -1 + +# Op IDs +# MIPS_OP_RS = 0 +# MIPS_OP_RT = 0 +# MIPS_OP_RD = 0 +# MIPS_OP_IMM = 0 + +# Instruction Groups + +MIPS_BRANCH_LIKELY_INSNS = [ + MIPS_INS_BEQL, MIPS_INS_BGEZALL, + MIPS_INS_BGEZL, MIPS_INS_BGTZL, + MIPS_INS_BLEZL, MIPS_INS_BLTZALL, + MIPS_INS_BLTZL, MIPS_INS_BNEL, + MIPS_INS_BC1TL, MIPS_INS_BC1FL, +] + +MIPS_BRANCH_INSNS = [ + *MIPS_BRANCH_LIKELY_INSNS, + + MIPS_INS_BEQ, + MIPS_INS_BGEZ, MIPS_INS_BGEZAL, + MIPS_INS_BGTZ, + MIPS_INS_BNE, + MIPS_INS_BLTZ, MIPS_INS_BLTZAL, + MIPS_INS_BLEZ, + MIPS_INS_BC1T, MIPS_INS_BC1F, + + MIPS_INS_BEQZ, + MIPS_INS_BNEZ, + MIPS_INS_B, +] + +MIPS_JUMP_INSNS = [ + MIPS_INS_JAL, MIPS_INS_JALR, MIPS_INS_J, MIPS_INS_JR +] + +MIPS_DELAY_SLOT_INSNS = [ + *MIPS_BRANCH_INSNS, *MIPS_JUMP_INSNS +] + +MIPS_FP_LOAD_INSNS = [ + MIPS_INS_LWC1, MIPS_INS_LDC1 +] + +MIPS_LOAD_INSNS = [ + MIPS_INS_LB, MIPS_INS_LBU, + MIPS_INS_LH, MIPS_INS_LHU, + MIPS_INS_LW, MIPS_INS_LWL, MIPS_INS_LWR, MIPS_INS_LWU, + MIPS_INS_LD, MIPS_INS_LDL, MIPS_INS_LDR, + MIPS_INS_LL, MIPS_INS_LLD, + *MIPS_FP_LOAD_INSNS +] + +MIPS_FP_STORE_INSNS = [ + MIPS_INS_SWC1, MIPS_INS_SDC1 +] + +MIPS_STORE_INSNS = [ + MIPS_INS_SB, + MIPS_INS_SH, + MIPS_INS_SW, MIPS_INS_SWL, MIPS_INS_SWR, + MIPS_INS_SD, MIPS_INS_SDL, MIPS_INS_SDR, + MIPS_INS_SC, MIPS_INS_SCD, + *MIPS_FP_STORE_INSNS +] + +MIPS_LOAD_STORE_INSNS = [ + *MIPS_LOAD_INSNS, + *MIPS_STORE_INSNS, +] + +MIPS_FP_LOAD_STORE_INSNS = [ + *MIPS_FP_LOAD_INSNS, *MIPS_FP_STORE_INSNS +] + +RSP_VECTOR_LOAD_STORES = [ + MIPS_INS_LBV, MIPS_INS_LSV, MIPS_INS_LLV, MIPS_INS_LDV, + MIPS_INS_LQV, MIPS_INS_LRV, MIPS_INS_LPV, MIPS_INS_LUV, + MIPS_INS_LHV, MIPS_INS_LFV, MIPS_INS_LTV, + + MIPS_INS_SBV, MIPS_INS_SSV, MIPS_INS_SLV, MIPS_INS_SDV, + MIPS_INS_SQV, MIPS_INS_SRV, MIPS_INS_SPV, MIPS_INS_SUV, + MIPS_INS_SHV, MIPS_INS_SFV, MIPS_INS_SWV, MIPS_INS_STV, +] + +# Labels + +# These labels can be referenced from pointers/loads/stores/etc. +LABEL_TYPE_FUNC = 0 +LABEL_TYPE_JTBL = 1 +LABEL_TYPE_DATA = 2 +LABEL_TYPE_BRANCH = 3 + +# Unknown +LABEL_TYPE_UNK = 20 + +class MipsLabel: + """ + Label + """ + + def __init__(self, vaddr, name=None, lbl_type=LABEL_TYPE_UNK, is_global=None) -> None: + self.name = name + self.vaddr = vaddr + self.lbl_type = lbl_type + self.is_global = is_global or (False if (lbl_type == LABEL_TYPE_BRANCH) else True) + + def __str__(self): + if self.name is not None: + return self.name + + if self.lbl_type == LABEL_TYPE_FUNC: + return f"func_{self.vaddr:08X}" + elif self.lbl_type == LABEL_TYPE_JTBL: + return f"jtbl_{self.vaddr:08X}" + elif self.lbl_type == LABEL_TYPE_BRANCH: + return f".L{self.vaddr:08X}" + elif (self.lbl_type == LABEL_TYPE_DATA or self.lbl_type == LABEL_TYPE_UNK): + return f"D_{self.vaddr:08X}" + assert False , f"Unimplemented default name for label type {self.lbl_type}" + +# Register Names + +mips_gpr_names = ( + "$zero", + "$at", + "$v0", "$v1", + "$a0", "$a1", "$a2", "$a3", + "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", + "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", + "$t8", "$t9", + "$k0", "$k1", + "$gp", + "$sp", + "$fp", + "$ra", +) + +rsp_gpr_names = ( + "$zero", + "$1", "$2", "$3", "$4", "$5", "$6", + "$7", "$8", "$9", "$10", "$11", "$12", + "$13", "$14", "$15", "$16", "$17", "$18", + "$19", "$20", "$21", "$22", "$23", "$24", + "$25", "$26", "$27", "$28", "$29", "$30", + "$ra", +) + +mips_cop0_names = ( + "Index" , "Random" , "EntryLo0" , "EntryLo1" , + "Context" , "PageMask" , "Wired" , "Reserved07", + "BadVaddr" , "Count" , "EntryHi" , "Compare" , + "Status" , "Cause" , "EPC" , "PRevID" , + "Config" , "LLAddr" , "WatchLo" , "WatchHi" , + "XContext" , "Reserved21", "Reserved22", "Reserved23", + "Reserved24", "Reserved25", "PErr" , "CacheErr" , + "TagLo" , "TagHi" , "ErrorEPC" , "Reserved31", +) + +rsp_cop0_names = ( + "SP_MEM_ADDR", "SP_DRAM_ADDR", "SP_RD_LEN" , "SP_WR_LEN" , + "SP_STATUS" , "SP_DMA_FULL" , "SP_DMA_BUSY" , "SP_SEMAPHORE", + "DPC_START" , "DPC_END" , "DPC_CURRENT" , "DPC_STATUS" , + "DPC_CLOCK" , "DPC_BUFBUSY" , "DPC_PIPEBUSY", "DPC_TMEM" , +) + +mips_cop1_names = ( + "$f0", "$f1", "$f2", "$f3", + "$f4", "$f5", "$f6", "$f7", "$f8", "$f9", "$f10", "$f11", + "$f12", "$f13", "$f14", "$f15", + "$f16", "$f17", "$f18", "$f19", + "$f20", "$f21", "$f22", "$f23", "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", + # Status register + "FpCsr", +) + +rsp_cop2_names = ( + "$v0", "$v1", "$v2", "$v3", "$v4", "$v5", "$v6", "$v7", + "$v8", "$v9", "$v10", "$v11", "$v12", "$v13", "$v14", "$v15", + "$v16", "$v17", "$v18", "$v19", "$v20", "$v21", "$v22", "$v23", + "$v24", "$v25", "$v26", "$v27", "$v28", "$v29", "$v30", "$v31", +) + +rsp_cop2_ctrl_names = ( + '$vco', '$vcc', '$vce' +) + +# Instruction sets + +class MipsAbi: + def __init__(self, name, gpr_names, cop0_names, cop1_names, cop2_names): + self.name = name + self.gpr_names, self.cop0_names, self.cop1_names, self.cop2_names = \ + gpr_names, cop0_names, cop1_names, cop2_names + +ABI_VR4300 = MipsAbi("VR4300", mips_gpr_names, mips_cop0_names, mips_cop1_names, None ) +ABI_RSP = MipsAbi("RSP", rsp_gpr_names, rsp_cop0_names, None, rsp_cop2_names) + +# Instruction field fetching + +def sign_extend_6(value): + if value & (1 << (6 - 1)): + return value - (1 << 6) + return value + +def sign_extend_16(value): + return (value & 0x7FFF) - (value & 0x8000) + +def mask_shift(v, s, w): + return (v >> s) & ((1 << w) - 1) + +mips_get_field = lambda raw,vaddr : mask_shift(raw, 26, 6) +mips_get_special = lambda raw,vaddr : mask_shift(raw, 0, 6) +mips_get_cop0 = lambda raw,vaddr : mask_shift(raw, 21, 5) +mips_get_cop1 = lambda raw,vaddr : mask_shift(raw, 21, 5) +mips_get_cop2 = lambda raw,vaddr : mask_shift(raw, 21, 4) +mips_get_regimm = lambda raw,vaddr : mask_shift(raw, 16, 5) +mips_get_tlb = lambda raw,vaddr : mask_shift(raw, 0, 5) +mips_get_function = lambda raw,vaddr : mask_shift(raw, 0, 6) + +mips_get_cond = lambda raw,vaddr : mask_shift(raw, 0, 4) +mips_get_fd = lambda raw,vaddr : MipsFPReg(mask_shift(raw, 6, 5)) +mips_get_fs = lambda raw,vaddr : MipsFPReg(mask_shift(raw, 11, 5)) +mips_get_ft = lambda raw,vaddr : MipsFPReg(mask_shift(raw, 16, 5)) +mips_get_fmt = lambda raw,vaddr : mask_shift(raw, 21, 5) +mips_get_ndtf = lambda raw,vaddr : mask_shift(raw, 16, 2) + +mips_get_target = lambda raw,vaddr : ((vaddr & 0xFC000000) | (mask_shift(raw, 0, 26) << 2)) +mips_get_offset = lambda raw,vaddr : vaddr + 4 + sign_extend_16(mask_shift(raw, 0, 16)) * 4 +mips_get_imm = lambda raw,vaddr : mask_shift(raw, 0, 16) + +mips_get_base = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 21, 5)) + +mips_get_cd = lambda raw,vaddr : mask_shift(raw, 11, 5) + +mips_get_code = lambda raw,vaddr : (mask_shift(raw, 6, 20) << 6) >> 16 +mips_get_op = lambda raw,vaddr : mask_shift(raw, 16, 5) + +mips_get_sa = lambda raw,vaddr : mask_shift(raw, 6, 5) + +mips_get_rd = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 11, 5)) +mips_get_rs = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 21, 5)) +mips_get_rt = lambda raw,vaddr : MipsGPReg(mask_shift(raw, 16, 5)) + +rsp_load_store_multiplier = { + 0b00000 : 0x01, # lbv, sbv + 0b00001 : 0x02, # lsv, ssv + 0b00010 : 0x04, # llv, slv + 0b00011 : 0x08, # ldv, sdv + 0b00100 : 0x10, # lqv, sqv + 0b00101 : 0x10, # lrv, srv + 0b00110 : 0x08, # lpv, spv + 0b00111 : 0x08, # luv, suv + + 0b01000 : 0x02, # lhv, shv + 0b01001 : 0x04, # lfv, sfv + 0b01010 : 0x10, # swv + 0b01011 : 0x10, # ltv, stv +} + +mips_get_vc = lambda raw,vaddr : mask_shift(raw, 11, 5) +mips_get_vd = lambda raw,vaddr : mask_shift(raw, 6, 5) +mips_get_vs = lambda raw,vaddr : mask_shift(raw, 11, 5) +mips_get_vt = lambda raw,vaddr : mask_shift(raw, 16, 5) +mips_get_elem = lambda raw,vaddr : mask_shift(raw, 21, 4) +mips_get_elemd = lambda raw,vaddr : mask_shift(raw, 7, 4) +mips_get_cop2_func = lambda raw,vaddr : mask_shift(raw, 25, 1) +mips_get_lwc2 = lambda raw,vaddr : mask_shift(raw, 11, 5) +mips_get_swc2 = lambda raw,vaddr : mask_shift(raw, 11, 5) +mips_get_voffset = lambda raw,vaddr : sign_extend_6(mask_shift(raw, 0, 6)) * rsp_load_store_multiplier[mips_get_lwc2(raw,vaddr)] + +# Formatting + +def resolve_pseudo_insn(insn): + # move varies between assemblers + # IDO + move_insn = MIPS_INS_OR + # GCC + # move_insn = MIPS_INS_ADDU + + if insn.id == MIPS_INS_SLL and insn.rd == MipsGPReg.R0 and insn.rt == MipsGPReg.R0 and insn.sa == 0: + return MIPS_INS_NOP, "nop", (), () + elif insn.id == MIPS_INS_BEQ and insn.rs == MipsGPReg.R0 and insn.rt == MipsGPReg.R0: + return MIPS_INS_B, "b", ("offset",), (False,) + elif insn.id == move_insn and insn.rt == MipsGPReg.R0: + return MIPS_INS_MOVE, "move", ("rd","rs"), (True,False) + elif insn.id == MIPS_INS_BEQ and insn.rt == MipsGPReg.R0: + return MIPS_INS_BEQZ, "beqz", ("rs","offset"), (False,False) + elif insn.id == MIPS_INS_BNE and insn.rt == MipsGPReg.R0: + return MIPS_INS_BNEZ, "bnez", ("rs","offset"), (False,False) + elif insn.id == MIPS_INS_SUBU and insn.rs == MipsGPReg.R0: + return MIPS_INS_NEGU, "negu", ("rd","rt"), (True,False) + elif insn.id == MIPS_INS_NOR and insn.rt == MipsGPReg.R0: + return MIPS_INS_NOT, "not", ("rd","rs"), (True,False) + else: + return insn.id, insn.mnemonic, insn.fields, insn.writes + +def format_hex(v, signed, zeros, no_zero): + if abs(v) < 10: + if v == 0 and no_zero: + return "" + return f"{v}" + elif not signed: + return f"0x{v:{f'0{zeros}' if zeros > 0 else ''}x}" + else: + return f"{v:#x}" + +def format_vector_elem(insn, elem): + if insn.id in RSP_VECTOR_LOAD_STORES: + return f"[{elem}]" + elif (elem & 8) == 8: + return f"[{elem & 7}]" + elif (elem & 0xC) == 4: + return f"[{elem & 3}h]" + elif (elem & 0xE) == 2: + return f"[{elem & 1}q]" + else: + return "" + +mips_field_formatters = { + 'code' : (lambda insn : f'{insn.code}' if insn.code != 0 else ''), + 'cd' : (lambda insn : insn.abi.cop0_names[insn.cd]), + 'rd' : (lambda insn : insn.abi.gpr_names[insn.rd]), + 'rs' : (lambda insn : insn.abi.gpr_names[insn.rs]), + 'rt' : (lambda insn : insn.abi.gpr_names[insn.rt]), + 'fd' : (lambda insn : insn.abi.cop1_names[insn.fd]), + 'fs' : (lambda insn : insn.abi.cop1_names[insn.fs]), + 'ft' : (lambda insn : insn.abi.cop1_names[insn.ft]), + 'sa' : (lambda insn : format_hex(insn.sa, True, 0, False)), + 'op' : (lambda insn : format_hex(insn.op, False, 0, False)), + 'imm' : (lambda insn : format_hex(insn.imm, True, 0, False)), + 'offset(base)' : (lambda insn : f'{format_hex(insn.imm, True, 0, True)}({insn.abi.gpr_names[insn.base]})'), + 'offset' : (lambda insn : f'{format_hex(insn.offset, True, 0, False)}'), + 'target' : (lambda insn : f'{format_hex(insn.target, False, 0, False)}'), + 'vd' : (lambda insn : insn.abi.cop2_names[insn.vd]), + 'vs' : (lambda insn : insn.abi.cop2_names[insn.vs]), + 'vt' : (lambda insn : insn.abi.cop2_names[insn.vt]), + 'vt[e]' : (lambda insn : f"{insn.abi.cop2_names[insn.vt]}{format_vector_elem(insn, insn.elem)}"), + 'vt[ed]' : (lambda insn : f"{insn.abi.cop2_names[insn.vt]}{format_vector_elem(insn, insn.elemd)}"), + 'vd[e]' : (lambda insn : f"{insn.abi.cop2_names[insn.vd]}{format_vector_elem(insn, insn.elem)}"), + 'vd[ed]' : (lambda insn : f"{insn.abi.cop2_names[insn.vd]}{format_vector_elem(insn, insn.elemd)}"), + 'voffset' : (lambda insn : f'{format_hex(insn.voffset, True, 0, False)}'), + 'voffset(base)' : (lambda insn : f'{format_hex(insn.voffset, True, 0, True)}({insn.abi.gpr_names[insn.base]})'), + 'vc' : (lambda insn : rsp_cop2_ctrl_names[insn.vc]) +} + +class MipsInsn: + + def __init__(self, abi, raw, vaddr, values): + self.abi = abi + self.raw = raw + self.vaddr = vaddr + + if values is None: + values = MIPS_INS_INVALID, f"/* Invalid Instruction */ .4byte 0x{raw:08X}", (), () + + self.id, self.mnemonic, self.fields, self.writes = values + + # self.code = self.sa = self.op = self.cd = self.rd = self.rs = self.rt = self.fd = self.fs = self.ft = self.imm = self.offset = self.base = self.target = None + + for field in self.fields: + self.set_value(field) + + self.id, self.mnemonic, self.fields, self.writes = resolve_pseudo_insn(self) + + self.op_str = self.format_insn() + + def read_fields(self): + return [field for i,field in enumerate(self.fields) if self.writes[i] == False] + + def write_fields(self): + return [field for i,field in enumerate(self.fields) if self.writes[i] == True] + + def has_field(self, field): + return field in self.fields + + def format_field(self, field): + return mips_field_formatters[field](self) + + def format_insn(self): + return ", ".join([self.format_field(field) for field in self.fields]) + + def __str__(self): + return f"{self.mnemonic:12}{self.op_str}" + + # Field setters + + def set_code(self): + self.code = mips_get_code(self.raw, self.vaddr) + + def set_sa(self): + self.sa = mips_get_sa(self.raw, self.vaddr) + + def set_op(self): + self.op = mips_get_op(self.raw, self.vaddr) + + def set_cd(self): + self.cd = mips_get_cd(self.raw, self.vaddr) + + def set_rd(self): + self.rd = mips_get_rd(self.raw, self.vaddr) + + def set_rs(self): + self.rs = mips_get_rs(self.raw, self.vaddr) + + def set_rt(self): + self.rt = mips_get_rt(self.raw, self.vaddr) + + def set_fd(self): + self.fd = mips_get_fd(self.raw, self.vaddr) + + def set_fs(self): + self.fs = mips_get_fs(self.raw, self.vaddr) + + def set_ft(self): + self.ft = mips_get_ft(self.raw, self.vaddr) + + do_sign_extend = [ + MIPS_INS_ADDIU, MIPS_INS_SLTI, MIPS_INS_ADDI, MIPS_INS_DADDIU, + MIPS_INS_LB, MIPS_INS_LBU, + MIPS_INS_LH, MIPS_INS_LHU, + MIPS_INS_LW, MIPS_INS_LWL, MIPS_INS_LWR, MIPS_INS_LWU, + MIPS_INS_LWC1, + MIPS_INS_LD, MIPS_INS_LDL, MIPS_INS_LDR, + MIPS_INS_LDC1, + MIPS_INS_LL, MIPS_INS_LLD, + MIPS_INS_SB, + MIPS_INS_SH, + MIPS_INS_SW, MIPS_INS_SWL, MIPS_INS_SWR, + MIPS_INS_SWC1, + MIPS_INS_SD, MIPS_INS_SDL, MIPS_INS_SDR, + MIPS_INS_SDC1, + MIPS_INS_SC, MIPS_INS_SCD, + ] + + def set_imm(self): + self.imm = mips_get_imm(self.raw, self.vaddr) + if self.id in MipsInsn.do_sign_extend: # sign extended immediates + self.imm = sign_extend_16(self.imm) + + def set_offset(self): + self.offset = mips_get_offset(self.raw, self.vaddr) + + def set_base(self): + self.base = mips_get_base(self.raw, self.vaddr) + + def set_offset_base(self): + self.set_imm() + self.set_base() + + def set_target(self): + self.target = mips_get_target(self.raw, self.vaddr) + + def set_vd(self): + self.vd = mips_get_vd(self.raw, self.vaddr) + + def set_vs(self): + self.vs = mips_get_vs(self.raw, self.vaddr) + + def set_vt(self): + self.vt = mips_get_vt(self.raw, self.vaddr) + + def set_e(self): + self.elem = mips_get_elem(self.raw, self.vaddr) + + def set_ed(self): + self.elemd = mips_get_elemd(self.raw, self.vaddr) + + def set_vd_e(self): + self.set_vd() + self.set_e() + + def set_vt_ed(self): + self.set_vt() + self.set_ed() + + def set_vt_e(self): + self.set_vt() + self.set_e() + + def set_vd_ed(self): + self.set_vd() + self.set_ed() + + def set_voffset(self): + self.voffset = mips_get_voffset(self.raw, self.vaddr) + + def set_voffset_base(self): + self.set_voffset() + self.set_base() + + def set_vc(self): + self.vc = mips_get_vc(self.raw, self.vaddr) + + field_setters = { + 'code' : set_code, + 'sa' : set_sa, + 'op' : set_op, + 'cd' : set_cd, + 'rd' : set_rd, + 'rs' : set_rs, + 'rt' : set_rt, + 'fd' : set_fd, + 'fs' : set_fs, + 'ft' : set_ft, + 'imm' : set_imm, + 'offset' : set_offset, + 'base' : set_base, + 'offset(base)' : set_offset_base, + 'target' : set_target, + 'vd' : set_vd, + 'vs' : set_vs, + 'vt' : set_vt, + 'vt[e]' : set_vt_e, + 'vt[ed]' : set_vt_ed, + 'vd[e]' : set_vd_e, + 'vd[ed]' : set_vd_ed, + 'voffset' : set_voffset, + 'voffset(base)' : set_voffset_base, + 'vc' : set_vc + } + + def set_value(self, name): + MipsInsn.field_setters[name](self) + + # Field getters + + field_getters = { + 'code' : (lambda insn: insn.code), + 'sa' : (lambda insn: insn.sa), + 'op' : (lambda insn: insn.op), + 'cd' : (lambda insn: insn.cd), + 'rd' : (lambda insn: insn.rd), + 'rs' : (lambda insn: insn.rs), + 'rt' : (lambda insn: insn.rt), + 'fd' : (lambda insn: insn.fd), + 'fs' : (lambda insn: insn.fs), + 'ft' : (lambda insn: insn.ft), + 'imm' : (lambda insn: insn.imm), + 'offset' : (lambda insn: insn.offset), + 'base' : (lambda insn: insn.base), + 'offset(base)' : (lambda insn: (insn.offset, insn.base)), + 'target' : (lambda insn: insn.target), + 'vd' : (lambda insn: insn.vd), + 'vs' : (lambda insn: insn.vs), + 'vt' : (lambda insn: insn.vt), + 'vt[e]' : (lambda insn: (insn.vt, insn.elem)), + 'vt[ed]' : (lambda insn: (insn.vt, insn.elemd)), + 'vd[e]' : (lambda insn: (insn.vd, insn.elem)), + 'vd[ed]' : (lambda insn: (insn.vd, insn.elemd)), + 'voffset' : (lambda insn: insn.voffset), + 'voffset(base)' : (lambda insn: (insn.voffset, insn.base)), + 'vc' : (lambda insn: insn.vc), + } + + def value_forname(self, name): + return MipsInsn.field_getters[name](self) + +def fetch_insn(raw, vaddr, insn_set, func): + insn = insn_set.get(func(raw, vaddr), None) # default none for invalid instruction encoding + + if insn is not None and type(insn[1]) == dict: # extra decoding required + insn = fetch_insn(raw, vaddr, insn[1], insn[0]) + return insn + +def decode_insn(raw, vaddr): + return MipsInsn(ABI_VR4300, raw, vaddr, fetch_insn(raw, vaddr, mips_insns, mips_get_field)) + +def decode_rsp_insn(raw, vaddr): + return MipsInsn(ABI_RSP, raw, vaddr, fetch_insn(raw, vaddr, rsp_insns, mips_get_field)) + +mips_insns = { + 0b000000: (mips_get_special, { + # opcode id mnemonic fields field is written to + 0b000000: (MIPS_INS_SLL, "sll", ("rd","rt","sa"), (True , False, False)), + 0b000010: (MIPS_INS_SRL, "srl", ("rd","rt","sa"), (True , False, False)), + 0b000011: (MIPS_INS_SRA, "sra", ("rd","rt","sa"), (True , False, False)), + 0b000100: (MIPS_INS_SLLV, "sllv", ("rd","rt","rs"), (True , False, False)), + 0b000110: (MIPS_INS_SRLV, "srlv", ("rd","rt","rs"), (True , False, False)), + 0b000111: (MIPS_INS_SRAV, "srav", ("rd","rt","rs"), (True , False, False)), + 0b001000: (MIPS_INS_JR, "jr", ("rs", ), (False, )), + 0b001001: (MIPS_INS_JALR, "jalr", ("rs", ), (False, )), # technically also rd but it's always $ra + 0b001100: (MIPS_INS_SYSCALL, "syscall", ( ), ( )), + 0b001101: (MIPS_INS_BREAK, "break", ("code", ), (False, )), + 0b001111: (MIPS_INS_SYNC, "sync", ( ), ( )), + 0b010000: (MIPS_INS_MFHI, "mfhi", ("rd", ), (True , )), + 0b010001: (MIPS_INS_MTHI, "mthi", ("rs", ), (False, )), + 0b010010: (MIPS_INS_MFLO, "mflo", ("rd", ), (True , )), + 0b010011: (MIPS_INS_MTLO, "mtlo", ("rs", ), (False, )), + 0b010100: (MIPS_INS_DSLLV, "dsllv", ("rd","rt","rs"), (True , False, False)), + 0b010110: (MIPS_INS_DSRLV, "dsrlv", ("rd","rt","rs"), (True , False, False)), + 0b010111: (MIPS_INS_DSRAV, "dsrav", ("rd","rt","rs"), (True , False, False)), + 0b011000: (MIPS_INS_MULT, "mult", ("rs","rt" ), (False, False )), + 0b011001: (MIPS_INS_MULTU, "multu", ("rs","rt" ), (False, False )), + 0b011010: (MIPS_INS_DIV, "div", ("rd","rs","rt"), (False, False, False)), # for some reason gas hates div instructions + 0b011011: (MIPS_INS_DIVU, "divu", ("rd","rs","rt"), (False, False, False)), # with the correct number of operands + 0b011100: (MIPS_INS_DMULT, "dmult", ("rs","rt" ), (False, False )), + 0b011101: (MIPS_INS_DMULTU, "dmultu", ("rs","rt" ), (False, False )), + 0b011110: (MIPS_INS_DDIV, "ddiv", ("rd","rs","rt"), (False, False, False)), + 0b011111: (MIPS_INS_DDIVU, "ddivu", ("rd","rs","rt"), (False, False, False)), + 0b100000: (MIPS_INS_ADD, "add", ("rd","rs","rt"), (True , False, False)), + 0b100001: (MIPS_INS_ADDU, "addu", ("rd","rs","rt"), (True , False, False)), + 0b100010: (MIPS_INS_SUB, "sub", ("rd","rs","rt"), (True , False, False)), + 0b100011: (MIPS_INS_SUBU, "subu", ("rd","rs","rt"), (True , False, False)), + 0b100100: (MIPS_INS_AND, "and", ("rd","rs","rt"), (True , False, False)), + 0b100101: (MIPS_INS_OR, "or", ("rd","rs","rt"), (True , False, False)), + 0b100110: (MIPS_INS_XOR, "xor", ("rd","rs","rt"), (True , False, False)), + 0b100111: (MIPS_INS_NOR, "nor", ("rd","rs","rt"), (True , False, False)), + 0b101010: (MIPS_INS_SLT, "slt", ("rd","rs","rt"), (True , False, False)), + 0b101011: (MIPS_INS_SLTU, "sltu", ("rd","rs","rt"), (True , False, False)), + 0b101100: (MIPS_INS_DADD, "dadd", ("rd","rs","rt"), (True , False, False)), + 0b101101: (MIPS_INS_DADDU, "daddu", ("rd","rs","rt"), (True , False, False)), + 0b101110: (MIPS_INS_DSUB, "dsub", ("rd","rs","rt"), (True , False, False)), + 0b101111: (MIPS_INS_DSUBU, "dsubu", ("rd","rs","rt"), (True , False, False)), + 0b110000: (MIPS_INS_TGE, "tge", ("rs","rt" ), (False, False )), + 0b110001: (MIPS_INS_TGEU, "tgeu", ("rs","rt" ), (False, False )), + 0b110010: (MIPS_INS_TLT, "tlt", ("rs","rt" ), (False, False )), + 0b110011: (MIPS_INS_TLTU, "tltu", ("rs","rt" ), (False, False )), + 0b110100: (MIPS_INS_TEQ, "teq", ("rs","rt" ), (False, False )), + 0b110110: (MIPS_INS_TNE, "tne", ("rs","rt" ), (False, False )), + 0b111000: (MIPS_INS_DSLL, "dsll", ("rd","rt","sa"), (True , False, False)), + 0b111010: (MIPS_INS_DSRL, "dsrl", ("rd","rt","sa"), (True , False, False)), + 0b111011: (MIPS_INS_DSRA, "dsra", ("rd","rt","sa"), (True , False, False)), + 0b111100: (MIPS_INS_DSLL32, "dsll32", ("rd","rt","sa"), (True , False, False)), + 0b111110: (MIPS_INS_DSRL32, "dsrl32", ("rd","rt","sa"), (True , False, False)), + 0b111111: (MIPS_INS_DSRA32, "dsra32", ("rd","rt","sa"), (True , False, False)), + }), + 0b000001: (mips_get_regimm, { + 0b00000: (MIPS_INS_BLTZ, "bltz", ("rs","offset"), (False, False)), + 0b00001: (MIPS_INS_BGEZ, "bgez", ("rs","offset"), (False, False)), + 0b00010: (MIPS_INS_BLTZL, "bltzl", ("rs","offset"), (False, False)), + 0b00011: (MIPS_INS_BGEZL, "bgezl", ("rs","offset"), (False, False)), + 0b01000: (MIPS_INS_TGEI, "tgei", ("rs","imm" ), (False, False)), + 0b01001: (MIPS_INS_TGEIU, "tgeiu", ("rs","imm" ), (False, False)), + 0b01010: (MIPS_INS_TLTI, "tlti", ("rs","imm" ), (False, False)), + 0b01011: (MIPS_INS_TLTIU, "tltiu", ("rs","imm" ), (False, False)), + 0b01100: (MIPS_INS_TEQI, "teqi", ("rs","imm" ), (False, False)), + 0b01110: (MIPS_INS_TNEI, "tnei", ("rs","imm" ), (False, False)), + 0b10000: (MIPS_INS_BLTZAL, "bltzal", ("rs","offset"), (False, False)), + 0b10001: (MIPS_INS_BGEZAL, "bgezal", ("rs","offset"), (False, False)), + 0b10010: (MIPS_INS_BLTZALL, "bltzall", ("rs","offset"), (False, False)), + 0b10011: (MIPS_INS_BGEZALL, "bgezall", ("rs","offset"), (False, False)), + }), + 0b000010: (MIPS_INS_J, "j", ("target", ), (False, )), + 0b000011: (MIPS_INS_JAL, "jal", ("target", ), (False, )), + 0b000100: (MIPS_INS_BEQ, "beq", ("rs","rt","offset"), (False, False, False)), + 0b000101: (MIPS_INS_BNE, "bne", ("rs","rt","offset"), (False, False, False)), + 0b000110: (MIPS_INS_BLEZ, "blez", ("rs","offset" ), (False, False, )), + 0b000111: (MIPS_INS_BGTZ, "bgtz", ("rs","offset" ), (False, False, )), + 0b001000: (MIPS_INS_ADDI, "addi", ("rt","rs","imm" ), (True , False, False)), + 0b001001: (MIPS_INS_ADDIU, "addiu", ("rt","rs","imm" ), (True , False, False)), + 0b001010: (MIPS_INS_SLTI, "slti", ("rt","rs","imm" ), (True , False, False)), + 0b001011: (MIPS_INS_SLTIU, "sltiu", ("rt","rs","imm" ), (True , False, False)), + 0b001100: (MIPS_INS_ANDI, "andi", ("rt","rs","imm" ), (True , False, False)), + 0b001101: (MIPS_INS_ORI, "ori", ("rt","rs","imm" ), (True , False, False)), + 0b001110: (MIPS_INS_XORI, "xori", ("rt","rs","imm" ), (True , False, False)), + 0b001111: (MIPS_INS_LUI, "lui", ("rt","imm" ), (True , False )), + 0b010000: (mips_get_cop0, { + 0b00000: (MIPS_INS_MFC0, "mfc0", ("rt","cd"), (True , False)), + 0b00100: (MIPS_INS_MTC0, "mtc0", ("rt","cd"), (False, True )), + 0b10000: (mips_get_tlb, { + 0b000001: (MIPS_INS_TLBR, "tlbr", (), ()), + 0b000010: (MIPS_INS_TLBWI, "tlbwi", (), ()), + 0b000110: (MIPS_INS_TLBWR, "tlbwr", (), ()), + 0b001000: (MIPS_INS_TLBP, "tlbp", (), ()), + 0b011000: (MIPS_INS_ERET, "eret", (), ()), + }), + }), + 0b010001: (mips_get_cop1, { + 0b00000: (MIPS_INS_MFC1, "mfc1", ("rt","fs"), (True , False)), + 0b00001: (MIPS_INS_DMFC1, "dmfc1", ("rt","fs"), (True , False)), + 0b00010: (MIPS_INS_CFC1, "cfc1", ("rt","fs"), (True , False)), + 0b00100: (MIPS_INS_MTC1, "mtc1", ("rt","fs"), (False, True )), + 0b00101: (MIPS_INS_DMTC1, "dmtc1", ("rt","fs"), (False, True )), + 0b00110: (MIPS_INS_CTC1, "ctc1", ("rt","fs"), (False, True )), + 0b01000: (mips_get_ndtf, { + 0b00: (MIPS_INS_BC1F, "bc1f", ("offset",), (False,)), + 0b01: (MIPS_INS_BC1T, "bc1t", ("offset",), (False,)), + 0b10: (MIPS_INS_BC1FL, "bc1fl", ("offset",), (False,)), + 0b11: (MIPS_INS_BC1TL, "bc1tl", ("offset",), (False,)), + }), + 0b010000: (mips_get_function, { + 0b000000: (MIPS_INS_ADD_S, "add.s", ("fd","fs","ft"), (True , False, False)), + 0b000001: (MIPS_INS_SUB_S, "sub.s", ("fd","fs","ft"), (True , False, False)), + 0b000010: (MIPS_INS_MUL_S, "mul.s", ("fd","fs","ft"), (True , False, False)), + 0b000011: (MIPS_INS_DIV_S, "div.s", ("fd","fs","ft"), (True , False, False)), + 0b000100: (MIPS_INS_SQRT_S, "sqrt.s", ("fd","fs" ), (True , False )), + 0b000101: (MIPS_INS_ABS_S, "abs.s", ("fd","fs" ), (True , False )), + 0b000110: (MIPS_INS_MOV_S, "mov.s", ("fd","fs" ), (True , False )), + 0b000111: (MIPS_INS_NEG_S, "neg.s", ("fd","fs" ), (True , False )), + 0b001000: (MIPS_INS_ROUND_L_S, "round.l.s", ("fd","fs" ), (True , False )), + 0b001001: (MIPS_INS_TRUNC_L_S, "trunc.l.s", ("fd","fs" ), (True , False )), + 0b001010: (MIPS_INS_CEIL_L_S, "ceil.l.s", ("fd","fs" ), (True , False )), + 0b001011: (MIPS_INS_FLOOR_L_S, "floor.l.s", ("fd","fs" ), (True , False )), + 0b001100: (MIPS_INS_ROUND_W_S, "round.w.s", ("fd","fs" ), (True , False )), + 0b001101: (MIPS_INS_TRUNC_W_S, "trunc.w.s", ("fd","fs" ), (True , False )), + 0b001110: (MIPS_INS_CEIL_W_S, "ceil.w.s", ("fd","fs" ), (True , False )), + 0b001111: (MIPS_INS_FLOOR_W_S, "floor.w.s", ("fd","fs" ), (True , False )), + 0b100001: (MIPS_INS_CVT_D_S, "cvt.d.s", ("fd","fs" ), (True , False )), + 0b100100: (MIPS_INS_CVT_W_S, "cvt.w.s", ("fd","fs" ), (True , False )), + 0b100101: (MIPS_INS_CVT_L_S, "cvt.l.s", ("fd","fs" ), (True , False )), + 0b110000: (MIPS_INS_C_F_S, "c.f.s", ("fs","ft" ), (False, False )), + 0b110001: (MIPS_INS_C_UN_S, "c.un.s", ("fs","ft" ), (False, False )), + 0b110010: (MIPS_INS_C_EQ_S, "c.eq.s", ("fs","ft" ), (False, False )), + 0b110011: (MIPS_INS_C_UEQ_S, "c.ueq.s", ("fs","ft" ), (False, False )), + 0b110100: (MIPS_INS_C_OLT_S, "c.olt.s", ("fs","ft" ), (False, False )), + 0b110101: (MIPS_INS_C_ULT_S, "c.ult.s", ("fs","ft" ), (False, False )), + 0b110110: (MIPS_INS_C_OLE_S, "c.ole.s", ("fs","ft" ), (False, False )), + 0b110111: (MIPS_INS_C_ULE_S, "c.ule.s", ("fs","ft" ), (False, False )), + 0b111000: (MIPS_INS_C_SF_S, "c.sf.s", ("fs","ft" ), (False, False )), + 0b111001: (MIPS_INS_C_NGLE_S, "c.ngle.s", ("fs","ft" ), (False, False )), + 0b111010: (MIPS_INS_C_SEQ_S, "c.seq.s", ("fs","ft" ), (False, False )), + 0b111011: (MIPS_INS_C_NGL_S, "c.ngl.s", ("fs","ft" ), (False, False )), + 0b111100: (MIPS_INS_C_LT_S, "c.lt.s", ("fs","ft" ), (False, False )), + 0b111101: (MIPS_INS_C_NGE_S, "c.nge.s", ("fs","ft" ), (False, False )), + 0b111110: (MIPS_INS_C_LE_S, "c.le.s", ("fs","ft" ), (False, False )), + 0b111111: (MIPS_INS_C_NGT_S, "c.ngt.s", ("fs","ft" ), (False, False )), + }), + 0b010001: (mips_get_function, { + 0b000000: (MIPS_INS_ADD_D, "add.d", ("fd","fs","ft"), (True , False, False)), + 0b000001: (MIPS_INS_SUB_D, "sub.d", ("fd","fs","ft"), (True , False, False)), + 0b000010: (MIPS_INS_MUL_D, "mul.d", ("fd","fs","ft"), (True , False, False)), + 0b000011: (MIPS_INS_DIV_D, "div.d", ("fd","fs","ft"), (True , False, False)), + 0b000100: (MIPS_INS_SQRT_D, "sqrt.d", ("fd","fs" ), (True , False )), + 0b000101: (MIPS_INS_ABS_D, "abs.d", ("fd","fs" ), (True , False )), + 0b000110: (MIPS_INS_MOV_D, "mov.d", ("fd","fs" ), (True , False )), + 0b000111: (MIPS_INS_NEG_D, "neg.d", ("fd","fs" ), (True , False )), + 0b001000: (MIPS_INS_ROUND_L_D, "round.l.d", ("fd","fs" ), (True , False )), + 0b001001: (MIPS_INS_TRUNC_L_D, "trunc.l.d", ("fd","fs" ), (True , False )), + 0b001010: (MIPS_INS_CEIL_L_D, "ceil.l.d", ("fd","fs" ), (True , False )), + 0b001011: (MIPS_INS_FLOOR_L_D, "floor.l.d", ("fd","fs" ), (True , False )), + 0b001100: (MIPS_INS_ROUND_W_D, "round.w.d", ("fd","fs" ), (True , False )), + 0b001101: (MIPS_INS_TRUNC_W_D, "trunc.w.d", ("fd","fs" ), (True , False )), + 0b001110: (MIPS_INS_CEIL_W_D, "ceil.w.d", ("fd","fs" ), (True , False )), + 0b001111: (MIPS_INS_FLOOR_W_D, "floor.w.d", ("fd","fs" ), (True , False )), + 0b100000: (MIPS_INS_CVT_S_D, "cvt.s.d", ("fd","fs" ), (True , False )), + 0b100100: (MIPS_INS_CVT_W_D, "cvt.w.d", ("fd","fs" ), (True , False )), + 0b100101: (MIPS_INS_CVT_L_D, "cvt.l.d", ("fd","fs" ), (True , False )), + 0b110000: (MIPS_INS_C_F_D, "c.f.d", ("fs","ft" ), (False, False )), + 0b110001: (MIPS_INS_C_UN_D, "c.un.d", ("fs","ft" ), (False, False )), + 0b110010: (MIPS_INS_C_EQ_D, "c.eq.d", ("fs","ft" ), (False, False )), + 0b110011: (MIPS_INS_C_UEQ_D, "c.ueq.d", ("fs","ft" ), (False, False )), + 0b110100: (MIPS_INS_C_OLT_D, "c.olt.d", ("fs","ft" ), (False, False )), + 0b110101: (MIPS_INS_C_ULT_D, "c.ult.d", ("fs","ft" ), (False, False )), + 0b110110: (MIPS_INS_C_OLE_D, "c.ole.d", ("fs","ft" ), (False, False )), + 0b110111: (MIPS_INS_C_ULE_D, "c.ule.d", ("fs","ft" ), (False, False )), + 0b111000: (MIPS_INS_C_SF_D, "c.sf.d", ("fs","ft" ), (False, False )), + 0b111001: (MIPS_INS_C_NGLE_D, "c.ngle.d", ("fs","ft" ), (False, False )), + 0b111010: (MIPS_INS_C_SEQ_D, "c.seq.d", ("fs","ft" ), (False, False )), + 0b111011: (MIPS_INS_C_NGL_D, "c.ngl.d", ("fs","ft" ), (False, False )), + 0b111100: (MIPS_INS_C_LT_D, "c.lt.d", ("fs","ft" ), (False, False )), + 0b111101: (MIPS_INS_C_NGE_D, "c.nge.d", ("fs","ft" ), (False, False )), + 0b111110: (MIPS_INS_C_LE_D, "c.le.d", ("fs","ft" ), (False, False )), + 0b111111: (MIPS_INS_C_NGT_D, "c.ngt.d", ("fs","ft" ), (False, False )), + }), + 0b010100: (mips_get_function, { + 0b100000: (MIPS_INS_CVT_S_W, "cvt.s.w", ("fd","fs"), (True , False)), + 0b100001: (MIPS_INS_CVT_D_W, "cvt.d.w", ("fd","fs"), (True , False)), + }), + 0b010101: (mips_get_function, { + 0b100000: (MIPS_INS_CVT_S_L, "cvt.s.l", ("fd","fs"), (True , False)), + 0b100001: (MIPS_INS_CVT_D_L, "cvt.d.l", ("fd","fs"), (True , False)), + }), + }), + 0b010100: (MIPS_INS_BEQL, "beql", ("rs","rt","offset" ), (False, False, False)), + 0b010101: (MIPS_INS_BNEL, "bnel", ("rs","rt","offset" ), (False, False, False)), + 0b010110: (MIPS_INS_BLEZL, "blezl", ("rs","offset" ), (False, False )), + 0b010111: (MIPS_INS_BGTZL, "bgtzl", ("rs","offset" ), (False, False )), + 0b011000: (MIPS_INS_DADDI, "daddi", ("rt","rs","imm" ), (True , False, False)), + 0b011001: (MIPS_INS_DADDIU, "daddiu", ("rt","rs","imm" ), (True , False, False)), + 0b011010: (MIPS_INS_LDL, "ldl", ("rt","offset(base)"), (True , False )), + 0b011011: (MIPS_INS_LDR, "ldr", ("rt","offset(base)"), (True , False )), + 0b100000: (MIPS_INS_LB, "lb", ("rt","offset(base)"), (True , False )), + 0b100001: (MIPS_INS_LH, "lh", ("rt","offset(base)"), (True , False )), + 0b100010: (MIPS_INS_LWL, "lwl", ("rt","offset(base)"), (True , False )), + 0b100011: (MIPS_INS_LW, "lw", ("rt","offset(base)"), (True , False )), + 0b100100: (MIPS_INS_LBU, "lbu", ("rt","offset(base)"), (True , False )), + 0b100101: (MIPS_INS_LHU, "lhu", ("rt","offset(base)"), (True , False )), + 0b100110: (MIPS_INS_LWR, "lwr", ("rt","offset(base)"), (True , False )), + 0b100111: (MIPS_INS_LWU, "lwu", ("rt","offset(base)"), (True , False )), + 0b101000: (MIPS_INS_SB, "sb", ("rt","offset(base)"), (False, False )), + 0b101001: (MIPS_INS_SH, "sh", ("rt","offset(base)"), (False, False )), + 0b101010: (MIPS_INS_SWL, "swl", ("rt","offset(base)"), (False, False )), + 0b101011: (MIPS_INS_SW, "sw", ("rt","offset(base)"), (False, False )), + 0b101100: (MIPS_INS_SDL, "sdl", ("rt","offset(base)"), (False, False )), + 0b101101: (MIPS_INS_SDR, "sdr", ("rt","offset(base)"), (False, False )), + 0b101110: (MIPS_INS_SWR, "swr", ("rt","offset(base)"), (False, False )), + 0b101111: (MIPS_INS_CACHE, "cache", ("op","offset(base)"), (False, False, False)), + 0b110000: (MIPS_INS_LL, "ll", ("rt","offset(base)"), (True , False )), + 0b110001: (MIPS_INS_LWC1, "lwc1", ("ft","offset(base)"), (True , False )), + # lwc2 + 0b110100: (MIPS_INS_LLD, "lld", ("rt","offset(base)"), (True , False )), + 0b110101: (MIPS_INS_LDC1, "ldc1", ("ft","offset(base)"), (True , False )), + # ldc2 + 0b110111: (MIPS_INS_LD, "ld", ("rt","offset(base)"), (True , False )), + 0b111000: (MIPS_INS_SC, "sc", ("rt","offset(base)"), (False, False )), + 0b111001: (MIPS_INS_SWC1, "swc1", ("ft","offset(base)"), (False, False )), + # lwc2 + 0b111100: (MIPS_INS_SCD, "scd", ("rt","offset(base)"), (False, False )), + 0b111101: (MIPS_INS_SDC1, "sdc1", ("ft","offset(base)"), (False, False )), + # sdc2 + 0b111111: (MIPS_INS_SD, "sd", ("rt","offset(base)"), (False, False )), +} + +rsp_insns = { + 0b000000: (mips_get_special, { + # opcode id mnemonic fields field is written to + 0b000000: (MIPS_INS_SLL, "sll", ("rd","rt","sa"), (True , False, False)), + 0b000010: (MIPS_INS_SRL, "srl", ("rd","rt","sa"), (True , False, False)), + 0b000011: (MIPS_INS_SRA, "sra", ("rd","rt","sa"), (True , False, False)), + 0b000100: (MIPS_INS_SLLV, "sllv", ("rd","rt","rs"), (True , False, False)), + 0b000110: (MIPS_INS_SRLV, "srlv", ("rd","rt","rs"), (True , False, False)), + 0b000111: (MIPS_INS_SRAV, "srav", ("rd","rt","rs"), (True , False, False)), + 0b001000: (MIPS_INS_JR, "jr", ("rs", ), (False, )), + 0b001001: (MIPS_INS_JALR, "jalr", ("rs", ), (False, )), # technically also rd but it's always $ra + 0b001101: (MIPS_INS_BREAK, "break", ("code", ), (False, )), + 0b100000: (MIPS_INS_ADD, "add", ("rd","rs","rt"), (True , False, False)), + 0b100001: (MIPS_INS_ADDU, "addu", ("rd","rs","rt"), (True , False, False)), + 0b100010: (MIPS_INS_SUB, "sub", ("rd","rs","rt"), (True , False, False)), + 0b100011: (MIPS_INS_SUBU, "subu", ("rd","rs","rt"), (True , False, False)), + 0b100100: (MIPS_INS_AND, "and", ("rd","rs","rt"), (True , False, False)), + 0b100101: (MIPS_INS_OR, "or", ("rd","rs","rt"), (True , False, False)), + 0b100110: (MIPS_INS_XOR, "xor", ("rd","rs","rt"), (True , False, False)), + 0b100111: (MIPS_INS_NOR, "nor", ("rd","rs","rt"), (True , False, False)), + 0b101010: (MIPS_INS_SLT, "slt", ("rd","rs","rt"), (True , False, False)), + 0b101011: (MIPS_INS_SLTU, "sltu", ("rd","rs","rt"), (True , False, False)), + }), + 0b000001: (mips_get_regimm, { + 0b00000: (MIPS_INS_BLTZ, "bltz", ("rs","offset"), (False, False)), + 0b00001: (MIPS_INS_BGEZ, "bgez", ("rs","offset"), (False, False)), + 0b10000: (MIPS_INS_BLTZAL, "bltzal", ("rs","offset"), (False, False)), + 0b10001: (MIPS_INS_BGEZAL, "bgezal", ("rs","offset"), (False, False)), + }), + 0b000010: (MIPS_INS_J, "j", ("target", ), (False, )), + 0b000011: (MIPS_INS_JAL, "jal", ("target", ), (False, )), + 0b000100: (MIPS_INS_BEQ, "beq", ("rs","rt","offset"), (False, False, False)), + 0b000101: (MIPS_INS_BNE, "bne", ("rs","rt","offset"), (False, False, False)), + 0b000110: (MIPS_INS_BLEZ, "blez", ("rs","offset" ), (False, False )), + 0b000111: (MIPS_INS_BGTZ, "bgtz", ("rs","offset" ), (False, False )), + 0b001000: (MIPS_INS_ADDI, "addi", ("rt","rs","imm" ), (True , False, False)), + 0b001001: (MIPS_INS_ADDIU, "addiu", ("rt","rs","imm" ), (True , False, False)), + 0b001010: (MIPS_INS_SLTI, "slti", ("rt","rs","imm" ), (True , False, False)), + 0b001011: (MIPS_INS_SLTIU, "sltiu", ("rt","rs","imm" ), (True , False, False)), + 0b001100: (MIPS_INS_ANDI, "andi", ("rt","rs","imm" ), (True , False, False)), + 0b001101: (MIPS_INS_ORI, "ori", ("rt","rs","imm" ), (True , False, False)), + 0b001110: (MIPS_INS_XORI, "xori", ("rt","rs","imm" ), (True , False, False)), + 0b001111: (MIPS_INS_LUI, "lui", ("rt","imm" ), (True , False )), + 0b010000: (mips_get_cop0, { + 0b00000: (MIPS_INS_MFC0, "mfc0", ("rt","cd"), (True , False)), + 0b00100: (MIPS_INS_MTC0, "mtc0", ("rt","cd"), (False, True )), + }), + 0b010010: (mips_get_cop2_func, { # TODO this encoding got ugly, move to a mask matcher like gnu objdump + 0b0: (mips_get_cop2, { + 0b0000: (MIPS_INS_MFC2, "mfc2", ("rt", "vd[e]"), (True , False)), + 0b0100: (MIPS_INS_MTC2, "mtc2", ("rt", "vd[e]"), (False, True )), + 0b0010: (MIPS_INS_CFC2, "cfc2", ("rt", "vc" ), (True , False)), + 0b0110: (MIPS_INS_CTC2, "ctc2", ("rt", "vc" ), (False, True )), + }), + 0b1: (mips_get_function, { + 0b000000: (MIPS_INS_VMULF, "vmulf", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b000001: (MIPS_INS_VMULU, "vmulu", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b000010: (MIPS_INS_VRNDP, "vrndp", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b000011: (MIPS_INS_VMULQ, "vmulq", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b000100: (MIPS_INS_VMUDL, "vmudl", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b000101: (MIPS_INS_VMUDM, "vmudm", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b000110: (MIPS_INS_VMUDN, "vmudn", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b000111: (MIPS_INS_VMUDH, "vmudh", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001000: (MIPS_INS_VMACF, "vmacf", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001001: (MIPS_INS_VMACU, "vmacu", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001010: (MIPS_INS_VRNDN, "vrndn", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001011: (MIPS_INS_VMACQ, "vmacq", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001100: (MIPS_INS_VMADL, "vmadl", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001101: (MIPS_INS_VMADM, "vmadm", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001110: (MIPS_INS_VMADN, "vmadn", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b001111: (MIPS_INS_VMADH, "vmadh", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b010000: (MIPS_INS_VADD, "vadd", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b010001: (MIPS_INS_VSUB, "vsub", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b010011: (MIPS_INS_VABS, "vabs", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b010100: (MIPS_INS_VADDC, "vaddc", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b010101: (MIPS_INS_VSUBC, "vsubc", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b011101: (MIPS_INS_VSAR, "vsar", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100000: (MIPS_INS_VLT, "vlt", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100001: (MIPS_INS_VEQ, "veq", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100010: (MIPS_INS_VNE, "vne", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100011: (MIPS_INS_VGE, "vge", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100100: (MIPS_INS_VCL, "vcl", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100101: (MIPS_INS_VCH, "vch", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100110: (MIPS_INS_VCR, "vcr", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b100111: (MIPS_INS_VMRG, "vmrg", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b101000: (MIPS_INS_VAND, "vand", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b101001: (MIPS_INS_VNAND, "vnand", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b101010: (MIPS_INS_VOR, "vor", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b101011: (MIPS_INS_VNOR, "vnor", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b101100: (MIPS_INS_VXOR, "vxor", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b101101: (MIPS_INS_VNXOR, "vnxor", ("vd", "vs", "vt[e]"), (True , False, False)), + 0b110000: (MIPS_INS_VRCP, "vrcp", ("vd[ed]", "vt[e]" ), (True , False)), + 0b110001: (MIPS_INS_VRCPL, "vrcpl", ("vd[ed]", "vt[e]" ), (True , False)), + 0b110010: (MIPS_INS_VRCPH, "vrcph", ("vd[ed]", "vt[e]" ), (True , False)), + 0b110011: (MIPS_INS_VMOV, "vmov", ("vd[ed]", "vt[e]" ), (True , False)), + 0b110100: (MIPS_INS_VRSQ, "vrsq", ("vd[ed]", "vt[e]" ), (True , False)), + 0b110101: (MIPS_INS_VRSQL, "vrsql", ("vd[ed]", "vt[e]" ), (True , False)), + 0b110110: (MIPS_INS_VRSQH, "vrsqh", ("vd[ed]", "vt[e]" ), (True , False)), + 0b110111: (MIPS_INS_VNOP, "vnop", ( ), ()), + }), + }), + 0b100000: (MIPS_INS_LB, "lb", ("rt","offset(base)"), (True , False)), + 0b100001: (MIPS_INS_LH, "lh", ("rt","offset(base)"), (True , False)), + 0b100011: (MIPS_INS_LW, "lw", ("rt","offset(base)"), (True , False)), + 0b100100: (MIPS_INS_LBU, "lbu", ("rt","offset(base)"), (True , False)), + 0b100101: (MIPS_INS_LHU, "lhu", ("rt","offset(base)"), (True , False)), + 0b101000: (MIPS_INS_SB, "sb", ("rt","offset(base)"), (False, False)), + 0b101001: (MIPS_INS_SH, "sh", ("rt","offset(base)"), (False, False)), + 0b101011: (MIPS_INS_SW, "sw", ("rt","offset(base)"), (False, False)), + 0b110010: (mips_get_lwc2, { + 0b00000: (MIPS_INS_LBV, "lbv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b00001: (MIPS_INS_LSV, "lsv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b00010: (MIPS_INS_LLV, "llv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b00011: (MIPS_INS_LDV, "ldv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b00100: (MIPS_INS_LQV, "lqv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b00101: (MIPS_INS_LRV, "lrv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b00110: (MIPS_INS_LPV, "lpv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b00111: (MIPS_INS_LUV, "luv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b01000: (MIPS_INS_LHV, "lhv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b01001: (MIPS_INS_LFV, "lfv", ("vt[ed]", "voffset(base)"), (True , False)), + 0b01011: (MIPS_INS_LTV, "ltv", ("vt[ed]", "voffset(base)"), (True , False)), + }), + 0b111010: (mips_get_swc2, { + 0b00000: (MIPS_INS_SBV, "sbv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b00001: (MIPS_INS_SSV, "ssv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b00010: (MIPS_INS_SLV, "slv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b00011: (MIPS_INS_SDV, "sdv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b00100: (MIPS_INS_SQV, "sqv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b00101: (MIPS_INS_SRV, "srv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b00110: (MIPS_INS_SPV, "spv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b00111: (MIPS_INS_SUV, "suv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b01000: (MIPS_INS_SHV, "shv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b01001: (MIPS_INS_SFV, "sfv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b01010: (MIPS_INS_SWV, "swv", ("vt[ed]", "voffset(base)"), (False, False)), + 0b01011: (MIPS_INS_STV, "stv", ("vt[ed]", "voffset(base)"), (False, False)), + }), +} diff --git a/lib/ultralib/tools/patch_ar_meta.py b/lib/ultralib/tools/patch_ar_meta.py new file mode 100755 index 0000000..d831785 --- /dev/null +++ b/lib/ultralib/tools/patch_ar_meta.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# +# Patch metadata in .ar files +# + +import argparse + +def ar_patch(ar, original, new_uid, new_gid, new_filemode): + """ + AR file headers + + Offset Length Name Format + 0 16 File identifier ASCII + 16 12 File modification timestamp (in seconds) Decimal + 28 6 Owner ID Decimal + 34 6 Group ID Decimal + 40 8 File mode (type and permission) Octal + 48 10 File size in bytes Decimal + 58 2 Ending characters 0x60 0x0A + """ + assert len(ar) > 0x24 , "Got empty archive?" + + armap_time1 = None + armap_time2 = None + + i = 8 + while i < len(original): + file_name = original[i:][0:][:16].decode("ASCII") + file_size = int(original[i:][48:][:10].decode("ASCII").strip()) + end = original[i:][58:][:2].decode("ASCII") + + assert end == "`\n" + + if file_name.strip() == "/": + armap_time1 = original[i+16:i+16+12] + elif file_name.strip() == "//": + armap_time2 = original[i+16:i+16+12] + + if file_size % 2 != 0: + file_size += 1 + i += file_size + 60 + + assert armap_time1 is not None + assert armap_time2 is not None + + i = 8 + while i < len(ar): + file_name = ar[i:][0:][:16].decode("ASCII") + file_size = int(ar[i:][48:][:10].decode("ASCII").strip()) + end = ar[i:][58:][:2].decode("ASCII") + + assert end == "`\n" + + if file_name.strip() == "/": + ar[i+16:i+16+12] = armap_time1 + elif file_name.strip() == "//": + ar[i+16:i+16+12] = armap_time2 + else: + ar[i+28:i+28+6] = f"{new_uid:<6}".encode("ASCII")[:6] + ar[i+34:i+34+6] = f"{new_gid:<6}".encode("ASCII")[:6] + ar[i+40:i+40+8] = f"{new_filemode:<8}".encode("ASCII")[:8] + + if file_size % 2 != 0: + file_size += 1 + i += file_size + 60 + +def main(): + parser = argparse.ArgumentParser(description="Patch metadata in .a files.") + parser.add_argument("target", help="path to the ar file to patch") + parser.add_argument("original", help="path to the original ar file") + parser.add_argument("uid", help="new uid") + parser.add_argument("gid", help="new gid") + parser.add_argument("filemode", help="new filemode") + args = parser.parse_args() + + ar = None + with open(args.target, "rb") as ar_file: + ar = bytearray(ar_file.read()) + + original = None + with open(args.original, "rb") as original_ar_file: + original = bytearray(original_ar_file.read()) + + ar_patch(ar, original, args.uid, args.gid, args.filemode) + + with open(args.target, "wb") as ar_file: + ar_file.write(ar) + +if __name__ == '__main__': + main() diff --git a/lib/ultralib/tools/print_mdebug.py b/lib/ultralib/tools/print_mdebug.py new file mode 100755 index 0000000..e0b295a --- /dev/null +++ b/lib/ultralib/tools/print_mdebug.py @@ -0,0 +1,589 @@ +#!/usr/bin/env python3 +''' +Resources: +http://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf +https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/include/coff/sym.h +https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/include/coff/symconst.h +https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/gas/ecoff.c +https://github.com/pathscale/binutils/blob/5c2c133020e41fc4aadd80a99156d2cea4754b96/bfd/ecoff.c +https://github.com/pathscale/absoft/blob/master/svn/trunk/ekopath-gcc/ekopath-gcc-4.2.0/gcc/mips-tdump.c +https://chromium.googlesource.com/native_client/nacl-toolchain/+/refs/tags/gcc-4.4.3/binutils/gas/ecoff.c +https://android.googlesource.com/toolchain/binutils/+/refs/heads/donut/binutils-2.17/bfd/ecofflink.c +https://kernel.googlesource.com/pub/scm/linux/kernel/git/hjl/binutils/+/hjl/secondary/include/coff/symconst.h +https://c0de.pw/bg/binutils-gdb/blob/cdbf20f73486c66e24f322400eba877eb534ae51/gdb/mdebugread.c +''' + +import os +import struct +import collections +import sys + +OFFSET = 0 # TODO why are the offsets in the symbolic header off by some amount? + +indent_level = 0 +is_comment = False + +symbol_type_list = [ + 'stNil', 'stGlobal', 'stStatic', 'stParam', 'stLocal', 'stLabel', 'stProc', 'stBlock', + 'stEnd', 'stMember', 'stTypedef', 'stFile', 'INVALID', 'INVALID', 'stStaticProc', 'stConstant', + 'stStaParam', 'INVALID', 'INVALID', 'INVALID', 'INVALID', 'INVALID', 'INVALID', 'INVALID', + 'INVALID', 'INVALID', 'stStruct', 'stUnion', 'stEnum', 'INVALID', 'INVALID', 'INVALID', + 'INVALID', 'INVALID', 'stIndirect'] +storage_class_list = ['scNil', 'scText', 'scData', 'scBss', 'scRegister', 'scAbs', 'scUndefined', 'reserved', + 'scBits', 'scDbx', 'scRegImage', 'scInfo', 'scUserStruct', 'scSData', 'scSBss', 'scRData', + 'scVar', 'scCommon', 'scSCommon', 'scVarRegister', 'scVariant', 'scUndefined', 'scInit'] +basic_type_c_list = ['nil', 'addr', 'signed char', 'unsigned char', 'short', 'unsigned short', 'int', 'unsigned int', + 'long', 'unsigned long', 'float', 'double', 'struct', 'union', 'enum', 'typedef', + 'range', 'set', 'complex', 'double complex', 'indirect', 'fixed decimal', 'float decimal', 'string', + 'bit', 'picture', 'void', 'long long', 'unsigned long long', 'INVALID', 'long', 'unsigned long', + 'long long', 'unsigned long long', 'addr', 'int64', 'unsigned int64'] + +def increase_indent(): + global indent_level + indent_level += 1 + +def decrease_indent(): + global indent_level + indent_level -= 1 + +def set_is_comment(set_to): + global is_comment + old = is_comment + is_comment = set_to + return old + +def get_indent(): + global indent_level + global is_comment + ret = '//' if is_comment else '' + for i in range(indent_level): + ret += ' ' + return ret + +def check_indent(): + global indent_level + assert indent_level == 0 + +def read_uint32_be(file_data, offset): + return struct.unpack('>I', file_data[offset:offset+4])[0] + +def read_uint16_be(file_data, offset): + return struct.unpack('>H', file_data[offset:offset+2])[0] + +def read_uint8_be(file_data, offset): + return struct.unpack('>B', file_data[offset:offset+1])[0] + +def read_elf_header(file_data, offset): + Header = collections.namedtuple('ElfHeader', + '''e_magic e_class e_data e_version e_osabi e_abiversion e_pad + e_type e_machine e_version2 e_entry e_phoff e_shoff e_flags + e_ehsize e_phentsize e_phnum e_shentsize e_shnum e_shstrndx''') + return Header._make(struct.unpack('>I5B7s2H5I6H', file_data[offset:offset+52])) + +def read_elf_section_header(file_data, offset): + Header = collections.namedtuple('SectionHeader', + '''sh_name sh_type sh_flags sh_addr sh_offset sh_size sh_link + sh_info sh_addralign sh_entsize''') + return Header._make(struct.unpack('>10I', file_data[offset:offset+40])) + +def read_symbolic_header(file_data, offset): + Header = collections.namedtuple('SymbolicHeader', + '''magic vstamp ilineMax cbLine cbLineOffset idnMax cbDnOffset + ipdMax cbPdOffset isymMax cbSymOffset ioptMax cbOptOffset + iauxMax cbAuxOffset issMax cbSsOffset issExtMax cbSsExtOffset + ifdMax cbFdOffset crfd cbRfdOffset iextMax cbExtOffset''') + return Header._make(struct.unpack('>2H23I', file_data[offset:offset+96])) + +# TODO find a better solution for the bitfield +def read_file_descriptor(file_data, offset): + if 'init' not in read_file_descriptor.__dict__: + read_file_descriptor.cache = {} + read_file_descriptor.header = collections.namedtuple('FileDescriptor', + '''adr rss issBase cbSs isymBase csym ilineBase cline ioptBase + copt ipdFirst cpd iauxBase caux rfdBase crfd XXX_bitfield + cbLineOffset cbLine''') + read_file_descriptor.init = True + if offset in read_file_descriptor.cache: + return read_file_descriptor.cache[offset] + read_file_descriptor.cache[offset] = read_file_descriptor.header._make( + struct.unpack('>I2iI6iHh4iI2I', file_data[offset:offset+72])) + return read_file_descriptor.cache[offset] + +def read_procedure_descriptor(file_data, offset): + Header = collections.namedtuple('ProcedureDescriptor', + '''adr isym iline regmask regoffset iopt fregmask fregoffset + frameoffset framereg pcreg lnLow lnHigh cbLineOffset''') + return Header._make(struct.unpack('>I8i2h2iI', file_data[offset:offset+52])) + +def read_symbol(file_data, offset): + if 'init' not in read_symbol.__dict__: + read_symbol.cache = {} + read_symbol.header = collections.namedtuple('Symbol', '''iss value st sc index''') + read_symbol.init = True + if offset in read_symbol.cache: + return read_symbol.cache[offset] + (word0, word1, word2) = struct.unpack('>iiI', file_data[offset:offset+12]) + read_symbol.cache[offset] = read_symbol.header._make(( + word0, word1, (word2 >> 26) & 0x3F, (word2 >> 21) & 0x1F, word2 & 0xFFFFF)) + return read_symbol.cache[offset] + +def read_auxiliary_symbol(file_data, offset): + if 'init' not in read_auxiliary_symbol.__dict__: + read_auxiliary_symbol.cache = {} + read_auxiliary_symbol.header = collections.namedtuple('AuxSymbol', + '''ti rndx dnLow dnHigh isym iss width count''') + read_auxiliary_symbol.type_info = collections.namedtuple('TypeInfo', + '''fBitfield continued bt tq4 tq5 tq0 tq1 tq2 tq3''') + read_auxiliary_symbol.rel_sym = collections.namedtuple('RelativeSymbol', '''rfd index''') + read_auxiliary_symbol.init = True + if offset in read_auxiliary_symbol.cache: + return read_auxiliary_symbol.cache[offset] + word0 = struct.unpack('>I', file_data[offset:offset+4])[0] + read_auxiliary_symbol.cache[offset] = read_auxiliary_symbol.header._make(( + read_auxiliary_symbol.type_info._make(((word0 >> 31) & 1, (word0 >> 30) & 1, (word0 >> 24) & 0x3F, (word0 >> 20) & 0xF, (word0 >> 16) & 0xF, (word0 >> 12) & 0xF, (word0 >> 8) & 0xF, (word0 >> 4) & 0xF, word0 & 0xF)), + read_auxiliary_symbol.rel_sym._make(((word0 >> 20) & 0xFFF, word0 & 0xFFFFF)), + word0, word0, word0, word0, word0, word0)) + return read_auxiliary_symbol.cache[offset] + +def read_string(file_data, offset): + current_offset = 0 + current_string = b'' + while True: + char = struct.unpack('c', file_data[offset+current_offset:offset+current_offset+1])[0] + if char == b'\0': + return current_string.decode('ascii') + else: + current_string += char + current_offset += 1 + +def map_relative_file_descriptor(file_data, fd, symbolic_header, rfd_num): + if fd.crfd == 0: + return rfd_num + + offset = symbolic_header.cbRfdOffset - OFFSET + (fd.rfdBase + rfd_num)*4 + return struct.unpack('>I', file_data[offset:offset+4])[0] + +def get_symbol_name_from_aux(file_data, fd, symbolic_header, aux_num, search_for_typedef): + aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + aux_num)*4) + fd_num = aux.rndx.rfd + next_aux = aux_num+1 + if fd_num == 4095: + aux2 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux)*4) + fd_num = aux2.isym + next_aux = next_aux+1; + fd_num = map_relative_file_descriptor(file_data, fd, symbolic_header, fd_num) + fd2 = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + fd_num*72) + sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (fd2.isymBase + aux.rndx.index)*12) + ret = '' + #print('%r' % (aux,)); + #print('%r' % (aux2,)); + #print('%r' % (sym,)); + if sym.st == 26 or sym.st == 27: #stStruct, stunion + ret = get_struct_or_union_string(file_data, fd2, symbolic_header, fd2.isymBase + aux.rndx.index, search_for_typedef) + elif sym.st == 28: #stEnum: + ret = get_enum_string(file_data, fd2, symbolic_header, fd2.isymBase + aux.rndx.index) + else: + ret = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd2.issBase + sym.iss) + return (ret, next_aux) + +def get_type_string(file_data, fd, symbolic_header, aux_num, name, search_for_typedef): + ret = '' + aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + aux_num)*4) + #print(''); + #print('%r' % (aux,)); + next_aux = aux_num+1 + has_bitfield = aux.ti.fBitfield == 1 + bitwidth = 0 + if has_bitfield: + bit_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux)*4) + bitwidth = bit_aux.isym + next_aux = next_aux+1 + if aux.ti.bt == 12: # btStruct + (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) + elif aux.ti.bt == 13: # btUnion + (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) + elif aux.ti.bt == 15: # btTypedef + (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) + elif aux.ti.bt == 14: # btEnum + (ret, next_aux) = get_symbol_name_from_aux(file_data, fd, symbolic_header, next_aux, search_for_typedef) + else: + if aux.ti.bt >= 36: + print('Error unknow bt: %d' % (aux.ti.bt)) + ret = basic_type_c_list[aux.ti.bt] + + tq_list = (aux.ti.tq0, aux.ti.tq1, aux.ti.tq2, aux.ti.tq3, aux.ti.tq4, aux.ti.tq5) + + # TODO this is very naive and probably does not work in a large amount of cases + last_was_proc = False # if we see a tqProc, assume the next will be a tqPtr + for tq in tq_list: + if tq == 0: # tqNil + break; + elif tq == 1: # tqPtr + if last_was_proc: + last_was_proc = False + continue + ret += '*' + elif tq == 2: # tqProc + last_was_proc = True + name = '(*%s)(/* ECOFF does not store param types */)' % name + elif tq == 3: # tqArray + next_aux += 2 # todo what does this skip over? (Apparantly the type of the index, so always int for C) + array_low_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux)*4) + array_high_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux+1)*4) + stride_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + next_aux+2)*4) + next_aux += 3 + if array_high_aux.dnHigh == 0xFFFFFFFF: + name += '[]' + else: + name += '[%d]' % (array_high_aux.dnHigh + 1) + elif tq == 4: # tqFar + print('ERROR tqFar in get_type_name') + elif tq == 5: # tqVol + ret = 'volatile ' + ret + elif tq == 6: # tqConst + ret = 'const ' + ret + if has_bitfield: + name += ' : %d' % bitwidth + return ret + ' ' + name + +def get_enum_string(file_data, fd, symbolic_header, enum_sym_num): + ret = '' + start_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + enum_sym_num*12) + if start_sym.st != 28: + print('ERROR unknown type in get_enum_string start:%d' % start_sym.st) + return ret + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + start_sym.iss) + if name != '': + name += ' ' + ret += 'enum %s{\n' % name + increase_indent() + sym_num = enum_sym_num + 1 + while sym_num < fd.isymBase + start_sym.index: + sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + if sym.st == 8: # stEnd + decrease_indent() + ret += get_indent() + ret += '}' + elif sym.st == 9: # stMember + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) + ret += get_indent() + ret += '%s = %d,\n' % (name, sym.value) + else: + print('ERROR unknown type in get_enum_string:%d' % sym.st) + break + sym_num += 1 + return ret + +def get_struct_or_union_string(file_data, fd, symbolic_header, union_sym_num, search_for_typedef): + ret = '' + start_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + union_sym_num*12) + if search_for_typedef: + typedef_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (fd.isymBase + start_sym.index)*12) + if typedef_sym.st == 10: # stTypedef + return read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + typedef_sym.iss) + else: + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + start_sym.iss) + if name != '': + return name + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + start_sym.iss) + if name != '': + name += ' ' + if start_sym.st == 26: # stStruct + ret += 'struct %s{\n' % name + increase_indent() + elif start_sym.st == 27: # stUnion + ret += 'union %s{\n' % name + increase_indent() + else: + print('ERROR unknown type in get_struct_or_union_string start:%d' % start_sym.st) + return ret + sym_num = union_sym_num + 1 + while sym_num < fd.isymBase + start_sym.index: + sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + if sym.st == 8: # stEnd + decrease_indent() + ret += get_indent() + ret += '}' + elif sym.st == 9: # stMember + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) + ret += get_indent() + ret += '/* 0x%X */ %s;\n' % (sym.value // 8, get_type_string(file_data, fd, symbolic_header, sym.index, name, True)) + elif sym.st == 26 or sym.st == 27: #stStruct, stUnion + sym_num = fd.isymBase + sym.index + continue + elif sym.st == 34: # stIndirect + # TODO what even is a stIndirect? + sym_num += 1 + else: + print('ERROR unknown type in get_struct_or_union_string:%d' % sym.st) + break + sym_num += 1 + return ret + +def print_typedef_symbols(file_data, fd, symbolic_header, typedef_sym_num): + typedef_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + typedef_sym_num*12) + if typedef_sym.st != 10: # stTypedef + print('ERROR expected stTypedef symbol in print_typedef_symbols, found:%d' % typedef_sym.st) + return + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + typedef_sym.iss) + print('typedef %s;' % get_type_string(file_data, fd, symbolic_header, typedef_sym.index, name, False)) + +def print_procedure(file_data, fd, symbolic_header, proc_sym_num): + proc_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + proc_sym_num*12) + proc_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + proc_sym.iss) + print('%s(' % get_type_string(file_data, fd, symbolic_header, proc_sym.index+1, proc_name, True), end='') + sym_num = proc_sym_num+1 + param_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + first = True + while param_sym.st == 3: # stParam + param_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + param_sym.iss) + print('%s%s' % ('' if first else ', ', + get_type_string(file_data, fd, symbolic_header, param_sym.index, param_name, True)), + end='') + sym_num += 1 + param_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + first = False + + print(');') + + check_indent(); + + comment_old = set_is_comment(True) + while sym_num < fd.isymBase + fd.csym: + sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + sym_num += 1 + if sym.st == 7: # stBlock + print('%s{' % get_indent()) + increase_indent() + elif sym.st == 8: # stEnd + end_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) + if end_name == proc_name: + break + if end_name != '': + # this is a stEnd for something other than the function. Let's back out and return + sym_num -= 1 + break + decrease_indent() + print('%s}' % get_indent()) + elif sym.st == 4: # stLocal + local_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) + is_reg = sym.sc == 4 # scRegister + print('%s%s%s;' % (get_indent(), + 'register ' if is_reg else '', + get_type_string(file_data, fd, symbolic_header, sym.index, local_name, True))) + elif sym.st == 2: # stStatic + static_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) + if sym.index == 0xFFFFF: + print('%sstatic %s; // no type symbol' % (get_indent(),static_name)) + else: + print('%sstatic %s;' % (get_indent(),get_type_string(file_data, fd, symbolic_header, sym.index, static_name, True))) + elif sym.st == 5: # stLabel + label_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) + print('%sLabel: %s @ %d;' % (get_indent(), label_name, sym.value)) + elif sym.st == 6: # stProc + # multiple name for function? + sym_num = print_procedure(file_data, fd, symbolic_header, sym_num-1) + elif sym.st == 26 or sym.st == 27: # stStruct, stUnion + print('%s%s;' % (get_indent(), get_struct_or_union_string(file_data, fd, symbolic_header, sym_num-1, False))) + sym_num = fd.isymBase + sym.index + elif sym.st == 28: # stEnum + print('%s%s;' % (get_indent(), get_enum_string(file_data, fd, symbolic_header, sym_num-1))) + sym_num = fd.isymBase + sym.index + elif sym.st == 34: # stIndirect + # TODO what even is a stIndirect? + indirect_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss) + print('%sTODO Indirect: %s;' % (get_indent(), indirect_name)) + else: + print('ERROR unknown st in print_procedure: %d' % sym.st) + set_is_comment(comment_old) + + check_indent(); + + return sym_num + +def print_symbols(file_data, fd, symbolic_header): + sym_num = fd.isymBase + indirects = [] + typedefs = [] + while sym_num < fd.isymBase + fd.csym: + root_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + if root_sym.st == 10: # stTypedef + aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + root_sym.index)*4) + offset = 0 + if aux.ti.fBitfield == 1: + offset = 1 + if aux.ti.bt == 12 or aux.ti.bt == 13 or aux.ti.bt == 14 or aux.ti.bt == 15: # btStruct, btUnion, btEnum, btTypedef + aux2 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + root_sym.index + 1 + offset)*4) + fd_num = aux2.rndx.rfd + if fd_num == 4095: + fd_num = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + root_sym.index + 2 + offset)*4).isym + fd_num = map_relative_file_descriptor(file_data, fd, symbolic_header, fd_num) + fd2 = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + fd_num*72) + sym2 = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (fd2.isymBase + aux2.rndx.index)*12) + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd2.issBase + sym2.iss) + if name != '': + typedefs.append(name) + elif root_sym.st == 34: # stIndirect + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + root_sym.iss) + indirects.append(name); + sym_num += 1 + sym_num = fd.isymBase + while sym_num < fd.isymBase + fd.csym: + root_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + if root_sym.st == 11: # stFile + file_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + root_sym.iss) + print('// begin file %s\n' % file_name) + sym_num += 1 + leaf_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + while leaf_sym.st != 8: # stEnd + if leaf_sym.st == 26 or leaf_sym.st == 27: # stStruct, stUnion + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss) + if (name != '') and ((name in indirects) or (name not in typedefs)): # TODO + print('%s;\n' % get_struct_or_union_string(file_data, fd, symbolic_header, sym_num, False)) + sym_num = fd.isymBase + leaf_sym.index + elif leaf_sym.st == 28: # stEnum + name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss) + if (name != '') and (name not in typedefs): # TODO + print('%s;\n' % get_enum_string(file_data, fd, symbolic_header, sym_num)) + sym_num = fd.isymBase + leaf_sym.index + elif leaf_sym.st == 10: # stTypedef + # TODO typedef for stIndirect shoulf print the keyword i.e. typdef >struct< THING thing + print_typedef_symbols(file_data, fd, symbolic_header, sym_num) + sym_num += 1 + print('') + elif leaf_sym.st == 6 or leaf_sym.st == 14: # stProc, stStaticProc + # TODO how do stProc and stStaticProc differ? stStaticProc isn't exported? + sym_num = print_procedure(file_data, fd, symbolic_header, sym_num) + print('') + elif leaf_sym.st == 2: # stStatic + static_name = read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss) + if leaf_sym.sc == 2 or leaf_sym.sc == 3 or leaf_sym.sc == 5 or leaf_sym.sc == 15: # scData, scBss, scAbsolute, scRData + if leaf_sym.index != 0xFFFFF: # looks like it's an invalid value for .s files + print('static %s;\n' % get_type_string(file_data, fd, symbolic_header, leaf_sym.index, static_name, True)) + else: + print('static %s;\n' % static_name) + else: + print('ERROR unknown sc for stStatic in print_symbols: %d' % leaf_sym.sc) + sym_num += 1 + elif leaf_sym.st == 34: # stIndirect + # stIndirect is put out when the compiler sees a struct when it is not yet defined + # TODO more info + sym_num += 1 + elif leaf_sym.st == 5: # stLabel + print('// label: %s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss)) + sym_num += 1 + elif leaf_sym.st == 0: # stNil + print('// nil: %s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + leaf_sym.iss)) + sym_num += 1 + else: + print('ERROR unknown st in leaf_sym in print_symbols: %d' % leaf_sym.st) + sym_num += 1 + leaf_sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + sym_num = fd.isymBase + root_sym.index + print('// end file %s' % file_name) + else: + print('ERROR expected st of stFile as only root type in print_symbols:%d' % root_sym.st) + return + +def main(): + global OFFSET + if len(sys.argv) < 2: + return # TODO print usage + + filename = sys.argv[1] + + try: + with open(filename, 'rb') as f: + file_data = f.read() + except IOError: + print('failed to read file ' + filename) + return + + elf_header = read_elf_header(file_data, 0) + section_headers = [] + debug_index = 0xFFFFFFFF + #print('%r' % (elf_header,)) + for i in range(elf_header.e_shnum): + section_headers.append(read_elf_section_header(file_data, elf_header.e_shoff + i*40)) + #print('%r' % (section_headers[i],)) + if section_headers[i].sh_type == 0x70000005: + debug_index = i + + if debug_index != 0xFFFFFFFF: + symbolic_header = read_symbolic_header(file_data, section_headers[debug_index].sh_offset) + file_descriptors = [] + print('%r' % (symbolic_header,)) + # Set offset by assuming that there are no optimization symbols so cbOptOffset points to the start of the symbolic header + #OFFSET = symbolic_header.cbOptOffset - section_headers[debug_index].sh_offset + #print('Using OFFSET of %d' % OFFSET) + #for sym_num in range(symbolic_header.isymMax): + #sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + #print('%d:%r' % (sym_num, (sym,))); + #for aux_num in range(symbolic_header.iauxMax): + #aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + aux_num*4) + #print('%d:%r' % (aux_num, (aux,))); + for file_num in range(symbolic_header.ifdMax): + fd = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + file_num*72) + file_descriptors.append(fd) + for file_num in range(symbolic_header.ifdMax): + fd = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + file_num*72) + print('%r' % (fd,)) + print(' name:%s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + fd.rss)) + + ''' + print(' Relative File Descriptors:') + for rfd_num in range(fd.rfdBase, fd.rfdBase + fd.crfd): + offset = symbolic_header.cbRfdOffset - OFFSET + rfd_num*4 + rfd_index = struct.unpack('>I', file_data[offset:offset+4])[0] + rfd = read_file_descriptor(file_data, symbolic_header.cbFdOffset - OFFSET + rfd_index*72) + print(' %d:%r' % (rfd_index, (rfd,))) + ''' + + ''' + print(' procedures:') + for proc_num in range(fd.ipdFirst, fd.ipdFirst + fd.cpd): + pd = read_procedure_descriptor(file_data, symbolic_header.cbPdOffset - OFFSET + proc_num*52) + print(' %r' % ((pd,))) + ''' + + ''' + print(' symbols:') + for sym_num in range(fd.isymBase, fd.isymBase + fd.csym): + sym = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + sym_num*12) + print(' %r' % ((sym,))) + print(' name:%s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + fd.issBase + sym.iss)) + print(' type:%s(%d)' % (symbol_type_list[sym.st], sym.st)) + print(' storage class:%s(%d)' % (storage_class_list[sym.sc], sym.sc)) + if sym.st == 3 or sym.st == 4 or sym.st == 9 or sym.st == 10 or sym.st == 28: # stParam, stLocal, stMember, stTypedef, stEnum + aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index)*4) + print(' %r' % ((aux,))) + offset = 0 + if aux.ti.fBitfield == 1: + bitfield_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index + 1)*4) + print(' %r' % ((bitfield_aux,))) + offset = 1 + if aux.ti.bt == 12 or aux.ti.bt == 13 or aux.ti.bt == 14 or aux.ti.bt == 15: # btStruct, btUnion, btEnum, btTypedef + aux2 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index + 1 + offset)*4) + print(' %r' % ((aux2,))) + fd_num = aux2.rndx.rfd + if fd_num == 4095: + aux3 = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index + 2 + offset)*4) + print(' %r' % ((aux3,))) + fd_num = aux3.isym + fd_num = map_relative_file_descriptor(file_data, fd, symbolic_header, fd_num) + sym2 = read_symbol(file_data, symbolic_header.cbSymOffset - OFFSET + (file_descriptors[fd_num].isymBase + aux2.rndx.index)*12) + print(' %r' % (sym2,)) + print(' name:%s' % read_string(file_data, symbolic_header.cbSsOffset - OFFSET + file_descriptors[aux3.isym].issBase + sym2.iss)) + if sym.st == 6 or sym.st == 14: # stProc, stStaticProc + # TODO what is the first aux symbol for? + aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index)*4) + type_aux = read_auxiliary_symbol(file_data, symbolic_header.cbAuxOffset - OFFSET + (fd.iauxBase + sym.index+1)*4) + print(' %r' % ((aux,))) + print(' %r' % ((type_aux,))) + ''' + + print(' pretty print:') + print_symbols(file_data, fd, symbolic_header) + + +main() \ No newline at end of file diff --git a/lib/ultralib/tools/set_o32abi_bit.py b/lib/ultralib/tools/set_o32abi_bit.py new file mode 100755 index 0000000..fc22d2c --- /dev/null +++ b/lib/ultralib/tools/set_o32abi_bit.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import argparse, struct, sys + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + + parser.add_argument('file', help='input file') + args = parser.parse_args() + + with open(args.file, 'r+b') as f: + magic = struct.unpack('>I', f.read(4))[0] + if magic != 0x7F454C46: + print('Error: Not an ELF file') + sys.exit(1) + + f.seek(36) + flags = struct.unpack('>I', f.read(4))[0] + # if flags & 0xF0000000 != 0x20000000: # test for mips3 + # print('Error: Architecture not mips3') + # sys.exit(1) + + flags |= 0x00001000 # set EF_MIPS_ABI_O32 + f.seek(36) + f.write(struct.pack('>I', flags)) + diff --git a/lib/ultralib/tools/shiftjis_conv.py b/lib/ultralib/tools/shiftjis_conv.py new file mode 100755 index 0000000..73037d2 --- /dev/null +++ b/lib/ultralib/tools/shiftjis_conv.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +import sys + +# Converts a file with UTF-8 Japanese glyphs in char literals, +# into one that uses u16 constants + +# Follows the layout in the manual page for easier cross reference +sjis_table = { + "ー": 0x815B, "ぜ": 0x82BA, "へ": 0x82D6, "ァ": 0x8340, "ソ": 0x835C, "ペ": 0x8379, + "ぁ": 0x829F, "そ": 0x82BB, "べ": 0x82D7, "ア": 0x8341, "ゾ": 0x835D, "ホ": 0x837A, + "あ": 0x82A0, "ぞ": 0x82BC, "ぺ": 0x82D8, "ィ": 0x8342, "タ": 0x835E, "ボ": 0x837B, + "ぃ": 0x82A1, "た": 0x82BD, "ほ": 0x82D9, "イ": 0x8343, "ダ": 0x835F, "ポ": 0x837C, + "い": 0x82A2, "だ": 0x82BE, "ぼ": 0x82DA, "ゥ": 0x8344, "チ": 0x8360, "マ": 0x837D, + "ぅ": 0x82A3, "ち": 0x82BF, "ぽ": 0x82DB, "ウ": 0x8345, "ヂ": 0x8361, "ミ": 0x837E, + "う": 0x82A4, "ぢ": 0x82C0, "ま": 0x82DC, "ェ": 0x8346, "ッ": 0x8362, "ム": 0x8380, + "ぇ": 0x82A5, "っ": 0x82C1, "み": 0x82DD, "エ": 0x8347, "ツ": 0x8363, "メ": 0x8381, + "え": 0x82A6, "つ": 0x82C2, "む": 0x82DE, "ォ": 0x8348, "ヅ": 0x8364, "モ": 0x8382, + "ぉ": 0x82A7, "づ": 0x82C3, "め": 0x82DF, "オ": 0x8349, "テ": 0x8365, "ャ": 0x8383, + "お": 0x82A8, "て": 0x82C4, "も": 0x82E0, "カ": 0x834A, "デ": 0x8366, "ヤ": 0x8384, + "か": 0x82A9, "で": 0x82C5, "ゃ": 0x82E1, "ガ": 0x834B, "ト": 0x8367, "ュ": 0x8385, + "が": 0x82AA, "と": 0x82C6, "や": 0x82E2, "キ": 0x834C, "ド": 0x8368, "ユ": 0x8386, + "き": 0x82AB, "ど": 0x82C7, "ゅ": 0x82E3, "ギ": 0x834D, "ナ": 0x8369, "ョ": 0x8387, + "ぎ": 0x82AC, "な": 0x82C8, "ゆ": 0x82E4, "ク": 0x834E, "ニ": 0x836A, "ヨ": 0x8388, + "く": 0x82AD, "に": 0x82C9, "ょ": 0x82E5, "グ": 0x834F, "ヌ": 0x836B, "ラ": 0x8389, + "ぐ": 0x82AE, "ぬ": 0x82CA, "よ": 0x82E6, "ケ": 0x8350, "ネ": 0x836C, "リ": 0x838A, + "け": 0x82AF, "ね": 0x82CB, "ら": 0x82E7, "ゲ": 0x8351, "ノ": 0x836D, "ル": 0x838B, + "げ": 0x82B0, "の": 0x82CC, "り": 0x82E8, "コ": 0x8352, "ハ": 0x836E, "レ": 0x838C, + "こ": 0x82B1, "は": 0x82CD, "る": 0x82E9, "ゴ": 0x8353, "バ": 0x836F, "ロ": 0x838D, + "ご": 0x82B2, "ば": 0x82CE, "れ": 0x82EA, "サ": 0x8354, "パ": 0x8370, "ヮ": 0x838E, + "さ": 0x82B3, "ぱ": 0x82CF, "ろ": 0x82EB, "ザ": 0x8355, "ヒ": 0x8371, "ワ": 0x838F, + "ざ": 0x82B4, "ひ": 0x82D0, "ゎ": 0x82EC, "シ": 0x8356, "ビ": 0x8372, "ヰ": 0x8390, + "し": 0x82B5, "び": 0x82D1, "わ": 0x82ED, "ジ": 0x8357, "ピ": 0x8373, "ヱ": 0x8391, + "じ": 0x82B6, "ぴ": 0x82D2, "ゐ": 0x82EE, "ス": 0x8358, "フ": 0x8374, "ヲ": 0x8392, + "す": 0x82B7, "ふ": 0x82D3, "ゑ": 0x82EF, "ズ": 0x8359, "ブ": 0x8375, "ン": 0x8393, + "ず": 0x82B8, "ぶ": 0x82D4, "を": 0x82F0, "セ": 0x835A, "プ": 0x8376, "ヴ": 0x8394, + "せ": 0x82B9, "ぷ": 0x82D5, "ん": 0x82F1, "ゼ": 0x835B, "ヘ": 0x8377, "ヵ": 0x8395, + "ベ": 0x8378, "ヶ": 0x8396, +} + +skipTimer = 0 + +def sjis_process(buf, outfile): + global skipTimer + + for i, char in enumerate(buf): + if skipTimer > 0: + skipTimer -= 1 + continue + if char == "'" and buf[i+1] in sjis_table: + if sjis_table[buf[i+1]] == 0: + print("Error: Please map %s in %s" % (buf[i+1], sys.argv[0])) + exit(1) + outfile.write("0x%X" % sjis_table[buf[i+1]]) + skipTimer = 2 + else: + outfile.write(char) + + diff --git a/lib/ultralib/tools/strip_debug.sh b/lib/ultralib/tools/strip_debug.sh new file mode 100755 index 0000000..4a8be78 --- /dev/null +++ b/lib/ultralib/tools/strip_debug.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +cd $1 + +mkdir -p .cmp + +for f in *.o ; +do + ${CROSS}objcopy -p --strip-debug $f .cmp/${f/.o/.cmp.o} +done diff --git a/lib/ultralib/tools/util.py b/lib/ultralib/tools/util.py new file mode 100644 index 0000000..b6c6155 --- /dev/null +++ b/lib/ultralib/tools/util.py @@ -0,0 +1,44 @@ + +import struct + +def enumerate_stepped(l, start=0, step=1): + p = start + for e in l: + yield p, e + p += step + +def back_align(x, al): + return x - (x % al) + +def forward_align(x, al): + return (x + (al - 1)) & ~(al - 1) + +def as_double(b): + return struct.unpack(">d", b)[0] + +def as_dword(b): + return struct.unpack(">Q", b)[0] + +def as_float(b): + return struct.unpack(">f", b)[0] + +def as_word(b): + return struct.unpack(">I", b)[0] + +def as_hword(b): + return struct.unpack(">H", b)[0] + +def as_double_list(b): + return [i[0] for i in struct.iter_unpack(">d", b)] + +def as_dword_list(b): + return [i[0] for i in struct.iter_unpack(">Q", b)] + +def as_float_list(b): + return [i[0] for i in struct.iter_unpack(">f", b)] + +def as_word_list(b): + return [i[0] for i in struct.iter_unpack(">I", b)] + +def as_hword_list(b): + return [h[0] for h in struct.iter_unpack(">H", b)] From 727bfc8a9fd3b68118b6d19afa24cd287e61941b Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sat, 24 Feb 2024 18:10:53 -0800 Subject: [PATCH 6/6] ultralib fixes --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 68ed40c..6dc9b91 100644 --- a/Makefile +++ b/Makefile @@ -253,8 +253,7 @@ venv: setup: $(MAKE) -C tools -lib: - $(MAKE) -C lib/ultralib VERSION=$(ULTRALIB_VERSION) TARGET=$(ULTRALIB_TARGET) COMPARE=0 CROSS=$(CROSS) CC=../../$(CC_OLD) +lib: $(ULTRALIB_LIB) extract: $(RM) -r asm/$(VERSION) assets/$(VERSION) @@ -306,7 +305,7 @@ $(LIBULTRA_LIB): $(ULTRALIB_LIB) $(LIBDUMP_CMD) $(ULTRALIB_LIB): - $(MAKE) lib + $(MAKE) -C lib/ultralib VERSION=$(ULTRALIB_VERSION) TARGET=$(ULTRALIB_TARGET) FIXUPS=1 CROSS=$(CROSS) CC=../../$(CC_OLD) $(BUILD_DIR)/%.ld: %.ld $(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) $< > $@