Merge branch 'master' of https://github.com/CrashOveride95/ultrasm64
This commit is contained in:
commit
2255f8da0f
10 files changed
+27
-27
No files matched your search
@@ -0,0 +1,56 @@
|
||||
# assembler directives
|
||||
.set noat # allow manual use of $at
|
||||
.set noreorder # don't insert nops after branches
|
||||
.set gp=64
|
||||
|
||||
.include "macros.inc"
|
||||
|
||||
|
||||
.section .text, "ax"
|
||||
|
||||
# This file is handwritten.
|
||||
|
||||
glabel decompress
|
||||
lw $a3, 8($a0)
|
||||
lw $t9, 0xc($a0)
|
||||
lw $t8, 4($a0)
|
||||
add $a3, $a3, $a0
|
||||
add $t9, $t9, $a0
|
||||
move $a2, $zero
|
||||
addi $a0, $a0, 0x10
|
||||
add $t8, $t8, $a1
|
||||
.L802772C0:
|
||||
bnel $a2, $zero, .L802772D8
|
||||
slt $t1, $t0, $zero
|
||||
lw $t0, ($a0)
|
||||
li $a2, 32
|
||||
addi $a0, $a0, 4
|
||||
slt $t1, $t0, $zero
|
||||
.L802772D8:
|
||||
beql $t1, $zero, .L802772F8
|
||||
lhu $t2, ($a3)
|
||||
lb $t2, ($t9)
|
||||
addi $t9, $t9, 1
|
||||
addi $a1, $a1, 1
|
||||
b .L80277324
|
||||
sb $t2, -1($a1)
|
||||
lhu $t2, ($a3)
|
||||
.L802772F8:
|
||||
addi $a3, $a3, 2
|
||||
srl $t3, $t2, 0xc
|
||||
andi $t2, $t2, 0xfff
|
||||
sub $t1, $a1, $t2
|
||||
addi $t3, $t3, 3
|
||||
.L8027730C:
|
||||
lb $t2, -1($t1)
|
||||
addi $t3, $t3, -1
|
||||
addi $t1, $t1, 1
|
||||
addi $a1, $a1, 1
|
||||
bnez $t3, .L8027730C
|
||||
sb $t2, -1($a1)
|
||||
.L80277324:
|
||||
sll $t0, $t0, 1
|
||||
bne $a1, $t8, .L802772C0
|
||||
addi $a2, $a2, -1
|
||||
jr $ra
|
||||
nop
|
||||
+526
@@ -0,0 +1,526 @@
|
||||
#include <ultra64.h>
|
||||
#include <PR/os_system.h>
|
||||
#include <PR/os_vi.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sm64.h"
|
||||
#include "audio/external.h"
|
||||
#include "game/game_init.h"
|
||||
#include "game/memory.h"
|
||||
#include "game/sound_init.h"
|
||||
#include "game/profiler.h"
|
||||
#include "buffers/buffers.h"
|
||||
#include "segments.h"
|
||||
#include "game/main.h"
|
||||
#include "game/rumble_init.h"
|
||||
#include "game/version.h"
|
||||
#ifdef UNF
|
||||
#include "usb/usb.h"
|
||||
#include "usb/debug.h"
|
||||
#endif
|
||||
#include "puppyprint.h"
|
||||
|
||||
// Message IDs
|
||||
#define MESG_SP_COMPLETE 100
|
||||
#define MESG_DP_COMPLETE 101
|
||||
#define MESG_VI_VBLANK 102
|
||||
#define MESG_START_GFX_SPTASK 103
|
||||
#define MESG_NMI_REQUEST 104
|
||||
|
||||
OSThread D_80339210; // unused?
|
||||
OSThread gIdleThread;
|
||||
OSThread gMainThread;
|
||||
OSThread gGameLoopThread;
|
||||
OSThread gSoundThread;
|
||||
|
||||
OSIoMesg gDmaIoMesg;
|
||||
OSMesg gMainReceivedMesg;
|
||||
|
||||
OSMesgQueue gDmaMesgQueue;
|
||||
OSMesgQueue gSIEventMesgQueue;
|
||||
OSMesgQueue gPIMesgQueue;
|
||||
OSMesgQueue gIntrMesgQueue;
|
||||
OSMesgQueue gSPTaskMesgQueue;
|
||||
|
||||
OSMesg gDmaMesgBuf[1];
|
||||
OSMesg gPIMesgBuf[32];
|
||||
OSMesg gSIEventMesgBuf[1];
|
||||
OSMesg gIntrMesgBuf[16];
|
||||
OSMesg gUnknownMesgBuf[16];
|
||||
|
||||
OSViMode VI;
|
||||
|
||||
struct VblankHandler *gVblankHandler1 = NULL;
|
||||
struct VblankHandler *gVblankHandler2 = NULL;
|
||||
struct VblankHandler *gVblankHandler3 = NULL;
|
||||
struct SPTask *gActiveSPTask = NULL;
|
||||
struct SPTask *sCurrentAudioSPTask = NULL;
|
||||
struct SPTask *sCurrentDisplaySPTask = NULL;
|
||||
struct SPTask *sNextAudioSPTask = NULL;
|
||||
struct SPTask *sNextDisplaySPTask = NULL;
|
||||
s8 sAudioEnabled = TRUE;
|
||||
u32 gNumVblanks = 0;
|
||||
s8 gResetTimer = 0;
|
||||
s8 gNmiResetBarsTimer = 0;
|
||||
s8 gDebugLevelSelect = FALSE;
|
||||
|
||||
s8 gShowProfiler = FALSE;
|
||||
s8 gShowDebugText = FALSE;
|
||||
|
||||
// unused
|
||||
void handle_debug_key_sequences(void) {
|
||||
static u16 sProfilerKeySequence[] = {
|
||||
U_JPAD, U_JPAD, D_JPAD, D_JPAD, L_JPAD, R_JPAD, L_JPAD, R_JPAD
|
||||
};
|
||||
static u16 sDebugTextKeySequence[] = { D_JPAD, D_JPAD, U_JPAD, U_JPAD,
|
||||
L_JPAD, R_JPAD, L_JPAD, R_JPAD };
|
||||
static s16 sProfilerKey = 0;
|
||||
static s16 sDebugTextKey = 0;
|
||||
if (gPlayer3Controller->buttonPressed != 0) {
|
||||
if (sProfilerKeySequence[sProfilerKey++] == gPlayer3Controller->buttonPressed) {
|
||||
if (sProfilerKey == ARRAY_COUNT(sProfilerKeySequence)) {
|
||||
sProfilerKey = 0, gShowProfiler ^= 1;
|
||||
}
|
||||
} else {
|
||||
sProfilerKey = 0;
|
||||
}
|
||||
|
||||
if (sDebugTextKeySequence[sDebugTextKey++] == gPlayer3Controller->buttonPressed) {
|
||||
if (sDebugTextKey == ARRAY_COUNT(sDebugTextKeySequence)) {
|
||||
sDebugTextKey = 0, gShowDebugText ^= 1;
|
||||
}
|
||||
} else {
|
||||
sDebugTextKey = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup_mesg_queues(void) {
|
||||
osCreateMesgQueue(&gDmaMesgQueue, gDmaMesgBuf, ARRAY_COUNT(gDmaMesgBuf));
|
||||
osCreateMesgQueue(&gSIEventMesgQueue, gSIEventMesgBuf, ARRAY_COUNT(gSIEventMesgBuf));
|
||||
osSetEventMesg(OS_EVENT_SI, &gSIEventMesgQueue, NULL);
|
||||
|
||||
osCreateMesgQueue(&gSPTaskMesgQueue, gUnknownMesgBuf, ARRAY_COUNT(gUnknownMesgBuf));
|
||||
osCreateMesgQueue(&gIntrMesgQueue, gIntrMesgBuf, ARRAY_COUNT(gIntrMesgBuf));
|
||||
osViSetEvent(&gIntrMesgQueue, (OSMesg) MESG_VI_VBLANK, 1);
|
||||
|
||||
osSetEventMesg(OS_EVENT_SP, &gIntrMesgQueue, (OSMesg) MESG_SP_COMPLETE);
|
||||
osSetEventMesg(OS_EVENT_DP, &gIntrMesgQueue, (OSMesg) MESG_DP_COMPLETE);
|
||||
osSetEventMesg(OS_EVENT_PRENMI, &gIntrMesgQueue, (OSMesg) MESG_NMI_REQUEST);
|
||||
}
|
||||
|
||||
void alloc_pool(void) {
|
||||
void *start = (void *) SEG_POOL_START;
|
||||
void *end = (void *) (SEG_POOL_START + POOL_SIZE);
|
||||
|
||||
main_pool_init(start, end);
|
||||
gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT);
|
||||
}
|
||||
|
||||
void create_thread(OSThread *thread, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri) {
|
||||
thread->next = NULL;
|
||||
thread->queue = NULL;
|
||||
osCreateThread(thread, id, entry, arg, sp, pri);
|
||||
}
|
||||
|
||||
#ifdef VERSION_SH
|
||||
extern void func_sh_802f69cc(void);
|
||||
#endif
|
||||
|
||||
void handle_nmi_request(void) {
|
||||
gResetTimer = 1;
|
||||
gNmiResetBarsTimer = 0;
|
||||
stop_sounds_in_continuous_banks();
|
||||
sound_banks_disable(SEQ_PLAYER_SFX, SOUND_BANKS_BACKGROUND);
|
||||
fadeout_music(90);
|
||||
#ifdef VERSION_SH
|
||||
func_sh_802f69cc();
|
||||
#endif
|
||||
}
|
||||
|
||||
void receive_new_tasks(void) {
|
||||
struct SPTask *spTask;
|
||||
|
||||
while (osRecvMesg(&gSPTaskMesgQueue, (OSMesg *) &spTask, OS_MESG_NOBLOCK) != -1) {
|
||||
spTask->state = SPTASK_STATE_NOT_STARTED;
|
||||
switch (spTask->task.t.type) {
|
||||
case 2:
|
||||
sNextAudioSPTask = spTask;
|
||||
break;
|
||||
case 1:
|
||||
sNextDisplaySPTask = spTask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sCurrentAudioSPTask == NULL && sNextAudioSPTask != NULL) {
|
||||
sCurrentAudioSPTask = sNextAudioSPTask;
|
||||
sNextAudioSPTask = NULL;
|
||||
}
|
||||
|
||||
if (sCurrentDisplaySPTask == NULL && sNextDisplaySPTask != NULL) {
|
||||
sCurrentDisplaySPTask = sNextDisplaySPTask;
|
||||
sNextDisplaySPTask = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void start_sptask(s32 taskType) {
|
||||
UNUSED s32 pad; // needed to pad the stack
|
||||
|
||||
if (taskType == M_AUDTASK) {
|
||||
gActiveSPTask = sCurrentAudioSPTask;
|
||||
} else {
|
||||
gActiveSPTask = sCurrentDisplaySPTask;
|
||||
}
|
||||
|
||||
osSpTaskLoad(&gActiveSPTask->task);
|
||||
osSpTaskStartGo(&gActiveSPTask->task);
|
||||
gActiveSPTask->state = SPTASK_STATE_RUNNING;
|
||||
}
|
||||
|
||||
void interrupt_gfx_sptask(void) {
|
||||
if (gActiveSPTask->task.t.type == M_GFXTASK) {
|
||||
gActiveSPTask->state = SPTASK_STATE_INTERRUPTED;
|
||||
osSpTaskYield();
|
||||
}
|
||||
}
|
||||
|
||||
void start_gfx_sptask(void) {
|
||||
if (gActiveSPTask == NULL && sCurrentDisplaySPTask != NULL
|
||||
&& sCurrentDisplaySPTask->state == SPTASK_STATE_NOT_STARTED) {
|
||||
profiler_log_gfx_time(TASKS_QUEUED);
|
||||
#if PUPPYPRINT_DEBUG
|
||||
rspDelta = osGetTime();
|
||||
#endif
|
||||
start_sptask(M_GFXTASK);
|
||||
}
|
||||
}
|
||||
|
||||
void pretend_audio_sptask_done(void) {
|
||||
gActiveSPTask = sCurrentAudioSPTask;
|
||||
gActiveSPTask->state = SPTASK_STATE_RUNNING;
|
||||
osSendMesg(&gIntrMesgQueue, (OSMesg) MESG_SP_COMPLETE, OS_MESG_NOBLOCK);
|
||||
}
|
||||
|
||||
void handle_vblank(void) {
|
||||
|
||||
gNumVblanks++;
|
||||
#ifdef VERSION_SH
|
||||
if (gResetTimer > 0 && gResetTimer < 100) {
|
||||
gResetTimer++;
|
||||
}
|
||||
#else
|
||||
if (gResetTimer > 0) {
|
||||
gResetTimer++;
|
||||
}
|
||||
#endif
|
||||
|
||||
receive_new_tasks();
|
||||
|
||||
// First try to kick off an audio task. If the gfx task is currently
|
||||
// running, we need to asynchronously interrupt it -- handle_sp_complete
|
||||
// will pick up on what we're doing and start the audio task for us.
|
||||
// If there is already an audio task running, there is nothing to do.
|
||||
// If there is no audio task available, try a gfx task instead.
|
||||
if (sCurrentAudioSPTask != NULL) {
|
||||
if (gActiveSPTask != NULL) {
|
||||
interrupt_gfx_sptask();
|
||||
} else {
|
||||
profiler_log_vblank_time();
|
||||
if (sAudioEnabled) {
|
||||
start_sptask(M_AUDTASK);
|
||||
} else {
|
||||
pretend_audio_sptask_done();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (gActiveSPTask == NULL && sCurrentDisplaySPTask != NULL
|
||||
&& sCurrentDisplaySPTask->state != SPTASK_STATE_FINISHED) {
|
||||
profiler_log_gfx_time(TASKS_QUEUED);
|
||||
#if PUPPYPRINT_DEBUG
|
||||
rspDelta = osGetTime();
|
||||
#endif
|
||||
start_sptask(M_GFXTASK);
|
||||
}
|
||||
}
|
||||
#if ENABLE_RUMBLE
|
||||
rumble_thread_update_vi();
|
||||
#endif
|
||||
|
||||
// Notify the game loop about the vblank.
|
||||
if (gVblankHandler1 != NULL) {
|
||||
osSendMesg(gVblankHandler1->queue, gVblankHandler1->msg, OS_MESG_NOBLOCK);
|
||||
}
|
||||
if (gVblankHandler2 != NULL) {
|
||||
osSendMesg(gVblankHandler2->queue, gVblankHandler2->msg, OS_MESG_NOBLOCK);
|
||||
}
|
||||
if (gVblankHandler3 != NULL) {
|
||||
osSendMesg(gVblankHandler3->queue, gVblankHandler3->msg, OS_MESG_NOBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_sp_complete(void) {
|
||||
struct SPTask *curSPTask = gActiveSPTask;
|
||||
|
||||
gActiveSPTask = NULL;
|
||||
|
||||
if (curSPTask->state == SPTASK_STATE_INTERRUPTED) {
|
||||
// handle_vblank tried to start an audio task while there was already a
|
||||
// gfx task running, so it had to interrupt the gfx task. That interruption
|
||||
// just finished.
|
||||
if (osSpTaskYielded(&curSPTask->task) == 0) {
|
||||
// The gfx task completed before we had time to interrupt it.
|
||||
// Mark it finished, just like below.
|
||||
curSPTask->state = SPTASK_STATE_FINISHED;
|
||||
#if PUPPYPRINT_DEBUG
|
||||
profiler_update(rspGenTime, rspDelta);
|
||||
#endif
|
||||
profiler_log_gfx_time(RSP_COMPLETE);
|
||||
}
|
||||
|
||||
// Start the audio task, as expected by handle_vblank.
|
||||
profiler_log_vblank_time();
|
||||
if (sAudioEnabled) {
|
||||
start_sptask(M_AUDTASK);
|
||||
} else {
|
||||
pretend_audio_sptask_done();
|
||||
}
|
||||
} else {
|
||||
curSPTask->state = SPTASK_STATE_FINISHED;
|
||||
if (curSPTask->task.t.type == M_AUDTASK) {
|
||||
// After audio tasks come gfx tasks.
|
||||
profiler_log_vblank_time();
|
||||
if (sCurrentDisplaySPTask != NULL
|
||||
&& sCurrentDisplaySPTask->state != SPTASK_STATE_FINISHED) {
|
||||
if (sCurrentDisplaySPTask->state != SPTASK_STATE_INTERRUPTED) {
|
||||
profiler_log_gfx_time(TASKS_QUEUED);
|
||||
}
|
||||
start_sptask(M_GFXTASK);
|
||||
}
|
||||
sCurrentAudioSPTask = NULL;
|
||||
if (curSPTask->msgqueue != NULL) {
|
||||
osSendMesg(curSPTask->msgqueue, curSPTask->msg, OS_MESG_NOBLOCK);
|
||||
}
|
||||
} else {
|
||||
// The SP process is done, but there is still a Display Processor notification
|
||||
// that needs to arrive before we can consider the task completely finished and
|
||||
// null out sCurrentDisplaySPTask. That happens in handle_dp_complete.
|
||||
#if PUPPYPRINT_DEBUG
|
||||
profiler_update(rspGenTime, rspDelta);
|
||||
#endif
|
||||
profiler_log_gfx_time(RSP_COMPLETE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handle_dp_complete(void) {
|
||||
// Gfx SP task is completely done.
|
||||
if (sCurrentDisplaySPTask->msgqueue != NULL) {
|
||||
osSendMesg(sCurrentDisplaySPTask->msgqueue, sCurrentDisplaySPTask->msg, OS_MESG_NOBLOCK);
|
||||
}
|
||||
profiler_log_gfx_time(RDP_COMPLETE);
|
||||
sCurrentDisplaySPTask->state = SPTASK_STATE_FINISHED_DP;
|
||||
sCurrentDisplaySPTask = NULL;
|
||||
}
|
||||
extern void crash_screen_init(void);
|
||||
|
||||
void thread3_main(UNUSED void *arg) {
|
||||
setup_mesg_queues();
|
||||
alloc_pool();
|
||||
load_engine_code_segment();
|
||||
#ifndef UNF
|
||||
crash_screen_init();
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
osSyncPrintf("Super Mario 64\n");
|
||||
osSyncPrintf("Built by: %s\n", __username__);
|
||||
osSyncPrintf("Date : %s\n", __datetime__);
|
||||
osSyncPrintf("Compiler: %s\n", __compiler__);
|
||||
osSyncPrintf("Linker : %s\n", __linker__);
|
||||
#endif
|
||||
|
||||
create_thread(&gSoundThread, 4, thread4_sound, NULL, gThread4Stack + 0x2000, 20);
|
||||
osStartThread(&gSoundThread);
|
||||
|
||||
create_thread(&gGameLoopThread, 5, thread5_game_loop, NULL, gThread5Stack + 0x2000, 10);
|
||||
osStartThread(&gGameLoopThread);
|
||||
|
||||
while (TRUE) {
|
||||
OSMesg msg;
|
||||
|
||||
osRecvMesg(&gIntrMesgQueue, &msg, OS_MESG_BLOCK);
|
||||
switch ((uintptr_t) msg) {
|
||||
case MESG_VI_VBLANK:
|
||||
handle_vblank();
|
||||
break;
|
||||
case MESG_SP_COMPLETE:
|
||||
handle_sp_complete();
|
||||
break;
|
||||
case MESG_DP_COMPLETE:
|
||||
handle_dp_complete();
|
||||
break;
|
||||
case MESG_START_GFX_SPTASK:
|
||||
start_gfx_sptask();
|
||||
break;
|
||||
case MESG_NMI_REQUEST:
|
||||
handle_nmi_request();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_vblank_handler(s32 index, struct VblankHandler *handler, OSMesgQueue *queue, OSMesg *msg) {
|
||||
handler->queue = queue;
|
||||
handler->msg = msg;
|
||||
|
||||
switch (index) {
|
||||
case 1:
|
||||
gVblankHandler1 = handler;
|
||||
break;
|
||||
case 2:
|
||||
gVblankHandler2 = handler;
|
||||
break;
|
||||
case 3:
|
||||
gVblankHandler3 = handler;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void send_sp_task_message(OSMesg *msg) {
|
||||
osWritebackDCacheAll();
|
||||
osSendMesg(&gSPTaskMesgQueue, msg, OS_MESG_NOBLOCK);
|
||||
}
|
||||
|
||||
void dispatch_audio_sptask(struct SPTask *spTask) {
|
||||
if (sAudioEnabled && spTask != NULL) {
|
||||
osWritebackDCacheAll();
|
||||
osSendMesg(&gSPTaskMesgQueue, spTask, OS_MESG_NOBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
void exec_display_list(struct SPTask *spTask) {
|
||||
if (spTask != NULL) {
|
||||
osWritebackDCacheAll();
|
||||
spTask->state = SPTASK_STATE_NOT_STARTED;
|
||||
if (sCurrentDisplaySPTask == NULL) {
|
||||
sCurrentDisplaySPTask = spTask;
|
||||
sNextDisplaySPTask = NULL;
|
||||
osSendMesg(&gIntrMesgQueue, (OSMesg) MESG_START_GFX_SPTASK, OS_MESG_NOBLOCK);
|
||||
} else {
|
||||
sNextDisplaySPTask = spTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void turn_on_audio(void) {
|
||||
sAudioEnabled = TRUE;
|
||||
}
|
||||
|
||||
void turn_off_audio(void) {
|
||||
sAudioEnabled = FALSE;
|
||||
while (sCurrentAudioSPTask != NULL) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void change_vi(OSViMode *mode, int width, int height){
|
||||
|
||||
mode->comRegs.width = width;
|
||||
mode->comRegs.xScale = (width*512)/320;
|
||||
if(height > 240)
|
||||
{
|
||||
mode->comRegs.ctrl |= 0x40;
|
||||
mode->fldRegs[0].origin = width*2;
|
||||
mode->fldRegs[1].origin = width*4;
|
||||
mode->fldRegs[0].yScale = 0x2000000|((height*1024)/240);
|
||||
mode->fldRegs[1].yScale = 0x2000000|((height*1024)/240);
|
||||
mode->fldRegs[0].vStart = mode->fldRegs[1].vStart-0x20002;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode->fldRegs[0].origin = width*2;
|
||||
mode->fldRegs[1].origin = width*4;
|
||||
mode->fldRegs[0].yScale = ((height*1024)/240);
|
||||
mode->fldRegs[1].yScale = ((height*1024)/240);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize hardware, start main thread, then idle.
|
||||
*/
|
||||
void thread1_idle(UNUSED void *arg) {
|
||||
|
||||
osCreateViManager(OS_PRIORITY_VIMGR);
|
||||
switch ( osTvType ) {
|
||||
case OS_TV_NTSC:
|
||||
// NTSC
|
||||
//osViSetMode(&osViModeTable[OS_VI_NTSC_LAN1]);
|
||||
VI = osViModeTable[OS_VI_NTSC_LAN1];
|
||||
break;
|
||||
case OS_TV_MPAL:
|
||||
// MPAL
|
||||
//osViSetMode(&osViModeTable[OS_VI_MPAL_LAN1]);
|
||||
VI = osViModeTable[OS_VI_MPAL_LAN1];
|
||||
break;
|
||||
case OS_TV_PAL:
|
||||
// PAL
|
||||
//osViSetMode(&osViModeTable[OS_VI_PAL_LAN1]);
|
||||
VI = osViModeTable[OS_VI_PAL_LAN1];
|
||||
break;
|
||||
}
|
||||
change_vi(&VI, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
osViSetMode(&VI);
|
||||
osViBlack(TRUE);
|
||||
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);
|
||||
osViSetSpecialFeatures(OS_VI_GAMMA_OFF);
|
||||
osCreatePiManager(OS_PRIORITY_PIMGR, &gPIMesgQueue, gPIMesgBuf, ARRAY_COUNT(gPIMesgBuf));
|
||||
#ifdef UNF
|
||||
debug_initialize();
|
||||
#endif
|
||||
create_thread(&gMainThread, 3, thread3_main, NULL, gThread3Stack + 0x2000, 100);
|
||||
osStartThread(&gMainThread);
|
||||
|
||||
osSetThreadPri(NULL, 0);
|
||||
|
||||
// halt
|
||||
while (TRUE) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#if CLEARRAM
|
||||
void ClearRAM(void)
|
||||
{
|
||||
bzero(_mainSegmentEnd, (size_t)osMemSize - (size_t)OS_K0_TO_PHYSICAL(_mainSegmentEnd));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ISVPRINT
|
||||
extern u32 gISVDbgPrnAdrs;
|
||||
extern u32 gISVFlag;
|
||||
|
||||
void osInitialize_fakeisv() {
|
||||
/* global flag to skip `__checkHardware_isv` from being called. */
|
||||
gISVFlag = 0x49533634; // 'IS64'
|
||||
|
||||
/* printf writes go to this address, cen64(1) has this hardcoded. */
|
||||
gISVDbgPrnAdrs = 0x13FF0000;
|
||||
|
||||
/* `__printfunc`, used by `osSyncPrintf` will be set. */
|
||||
__osInitialize_isv();
|
||||
}
|
||||
#endif
|
||||
|
||||
void main_func(void) {
|
||||
#if CLEARRAM
|
||||
ClearRAM();
|
||||
#endif
|
||||
__osInitialize_common();
|
||||
#ifdef ISVPRINT
|
||||
osInitialize_fakeisv();
|
||||
#endif
|
||||
|
||||
create_thread(&gIdleThread, 1, thread1_idle, NULL, gIdleThreadStack + 0x800, 100);
|
||||
osStartThread(&gIdleThread);
|
||||
}
|
||||
@@ -0,0 +1,690 @@
|
||||
#include <PR/ultratypes.h>
|
||||
|
||||
#include "sm64.h"
|
||||
|
||||
#define INCLUDED_FROM_MEMORY_C
|
||||
|
||||
#include "buffers/buffers.h"
|
||||
#include "slidec.h"
|
||||
#include "game/game_init.h"
|
||||
#include "game/main.h"
|
||||
#include "game/memory.h"
|
||||
#include "segment_symbols.h"
|
||||
#include "segments.h"
|
||||
#ifdef GZIP
|
||||
#include <gzip.h>
|
||||
#endif
|
||||
#if defined(RNC1) || defined(RNC2)
|
||||
#include <rnc.h>
|
||||
#endif
|
||||
#ifdef UNF
|
||||
#include "usb/usb.h"
|
||||
#include "usb/debug.h"
|
||||
#endif
|
||||
#include "puppyprint.h"
|
||||
|
||||
|
||||
// round up to the next multiple
|
||||
#define ALIGN4(val) (((val) + 0x3) & ~0x3)
|
||||
#define ALIGN8(val) (((val) + 0x7) & ~0x7)
|
||||
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
|
||||
|
||||
struct MainPoolState {
|
||||
u32 freeSpace;
|
||||
struct MainPoolBlock *listHeadL;
|
||||
struct MainPoolBlock *listHeadR;
|
||||
struct MainPoolState *prev;
|
||||
};
|
||||
|
||||
struct MainPoolBlock {
|
||||
struct MainPoolBlock *prev;
|
||||
struct MainPoolBlock *next;
|
||||
};
|
||||
|
||||
struct MemoryBlock {
|
||||
struct MemoryBlock *next;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct MemoryPool {
|
||||
u32 totalSpace;
|
||||
struct MemoryBlock *firstBlock;
|
||||
struct MemoryBlock freeList;
|
||||
};
|
||||
|
||||
extern uintptr_t sSegmentTable[32];
|
||||
extern u32 sPoolFreeSpace;
|
||||
extern u8 *sPoolStart;
|
||||
extern u8 *sPoolEnd;
|
||||
extern struct MainPoolBlock *sPoolListHeadL;
|
||||
extern struct MainPoolBlock *sPoolListHeadR;
|
||||
|
||||
|
||||
/**
|
||||
* Memory pool for small graphical effects that aren't connected to Objects.
|
||||
* Used for colored text, paintings, and environmental snow and bubbles.
|
||||
*/
|
||||
struct MemoryPool *gEffectsMemoryPool;
|
||||
|
||||
uintptr_t sSegmentTable[32];
|
||||
u32 sPoolFreeSpace;
|
||||
u8 *sPoolStart;
|
||||
u8 *sPoolEnd;
|
||||
struct MainPoolBlock *sPoolListHeadL;
|
||||
struct MainPoolBlock *sPoolListHeadR;
|
||||
|
||||
|
||||
static struct MainPoolState *gMainPoolState = NULL;
|
||||
|
||||
uintptr_t set_segment_base_addr(s32 segment, void *addr) {
|
||||
sSegmentTable[segment] = (uintptr_t) addr & 0x1FFFFFFF;
|
||||
return sSegmentTable[segment];
|
||||
}
|
||||
|
||||
void *get_segment_base_addr(s32 segment) {
|
||||
return (void *) (sSegmentTable[segment] | 0x80000000);
|
||||
}
|
||||
|
||||
#ifndef NO_SEGMENTED_MEMORY
|
||||
void *segmented_to_virtual(const void *addr) {
|
||||
size_t segment = (uintptr_t) addr >> 24;
|
||||
size_t offset = (uintptr_t) addr & 0x00FFFFFF;
|
||||
|
||||
return (void *) ((sSegmentTable[segment] + offset) | 0x80000000);
|
||||
}
|
||||
|
||||
void *virtual_to_segmented(u32 segment, const void *addr) {
|
||||
size_t offset = ((uintptr_t) addr & 0x1FFFFFFF) - sSegmentTable[segment];
|
||||
|
||||
return (void *) ((segment << 24) + offset);
|
||||
}
|
||||
|
||||
void move_segment_table_to_dmem(void) {
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
gSPSegment(gDisplayListHead++, i, sSegmentTable[i]);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void *segmented_to_virtual(const void *addr) {
|
||||
return (void *) addr;
|
||||
}
|
||||
|
||||
void *virtual_to_segmented(u32 segment, const void *addr) {
|
||||
return (void *) addr;
|
||||
}
|
||||
|
||||
void move_segment_table_to_dmem(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize the main memory pool. This pool is conceptually a pair of stacks
|
||||
* that grow inward from the left and right. It therefore only supports
|
||||
* freeing the object that was most recently allocated from a side.
|
||||
*/
|
||||
void main_pool_init(void *start, void *end) {
|
||||
sPoolStart = (u8 *) ALIGN16((uintptr_t) start) + 16;
|
||||
sPoolEnd = (u8 *) ALIGN16((uintptr_t) end - 15) - 16;
|
||||
sPoolFreeSpace = sPoolEnd - sPoolStart;
|
||||
|
||||
sPoolListHeadL = (struct MainPoolBlock *) (sPoolStart - 16);
|
||||
sPoolListHeadR = (struct MainPoolBlock *) sPoolEnd;
|
||||
sPoolListHeadL->prev = NULL;
|
||||
sPoolListHeadL->next = NULL;
|
||||
sPoolListHeadR->prev = NULL;
|
||||
sPoolListHeadR->next = NULL;
|
||||
#if PUPPYPRINT_DEBUG
|
||||
mempool = sPoolFreeSpace;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a block of memory from the pool of given size, and from the
|
||||
* specified side of the pool (MEMORY_POOL_LEFT or MEMORY_POOL_RIGHT).
|
||||
* If there is not enough space, return NULL.
|
||||
*/
|
||||
void *main_pool_alloc(u32 size, u32 side) {
|
||||
struct MainPoolBlock *newListHead;
|
||||
void *addr = NULL;
|
||||
|
||||
size = ALIGN16(size) + 16;
|
||||
if (size != 0 && sPoolFreeSpace >= size) {
|
||||
sPoolFreeSpace -= size;
|
||||
if (side == MEMORY_POOL_LEFT) {
|
||||
newListHead = (struct MainPoolBlock *) ((u8 *) sPoolListHeadL + size);
|
||||
sPoolListHeadL->next = newListHead;
|
||||
newListHead->prev = sPoolListHeadL;
|
||||
newListHead->next = NULL;
|
||||
addr = (u8 *) sPoolListHeadL + 16;
|
||||
sPoolListHeadL = newListHead;
|
||||
} else {
|
||||
newListHead = (struct MainPoolBlock *) ((u8 *) sPoolListHeadR - size);
|
||||
sPoolListHeadR->prev = newListHead;
|
||||
newListHead->next = sPoolListHeadR;
|
||||
newListHead->prev = NULL;
|
||||
sPoolListHeadR = newListHead;
|
||||
addr = (u8 *) sPoolListHeadR + 16;
|
||||
}
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a block of memory that was allocated from the pool. The block must be
|
||||
* the most recently allocated block from its end of the pool, otherwise all
|
||||
* newer blocks are freed as well.
|
||||
* Return the amount of free space left in the pool.
|
||||
*/
|
||||
u32 main_pool_free(void *addr) {
|
||||
struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 16);
|
||||
struct MainPoolBlock *oldListHead = (struct MainPoolBlock *) ((u8 *) addr - 16);
|
||||
|
||||
if (oldListHead < sPoolListHeadL) {
|
||||
while (oldListHead->next != NULL) {
|
||||
oldListHead = oldListHead->next;
|
||||
}
|
||||
sPoolListHeadL = block;
|
||||
sPoolListHeadL->next = NULL;
|
||||
sPoolFreeSpace += (uintptr_t) oldListHead - (uintptr_t) sPoolListHeadL;
|
||||
} else {
|
||||
while (oldListHead->prev != NULL) {
|
||||
oldListHead = oldListHead->prev;
|
||||
}
|
||||
sPoolListHeadR = block->next;
|
||||
sPoolListHeadR->prev = NULL;
|
||||
sPoolFreeSpace += (uintptr_t) sPoolListHeadR - (uintptr_t) oldListHead;
|
||||
}
|
||||
return sPoolFreeSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize a block of memory that was allocated from the left side of the pool.
|
||||
* If the block is increasing in size, it must be the most recently allocated
|
||||
* block from the left side.
|
||||
* The block does not move.
|
||||
*/
|
||||
void *main_pool_realloc(void *addr, u32 size) {
|
||||
void *newAddr = NULL;
|
||||
struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 16);
|
||||
|
||||
if (block->next == sPoolListHeadL) {
|
||||
main_pool_free(addr);
|
||||
newAddr = main_pool_alloc(size, MEMORY_POOL_LEFT);
|
||||
}
|
||||
return newAddr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the size of the largest block that can currently be allocated from the
|
||||
* pool.
|
||||
*/
|
||||
u32 main_pool_available(void) {
|
||||
return sPoolFreeSpace - 16;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push pool state, to be restored later. Return the amount of free space left
|
||||
* in the pool.
|
||||
*/
|
||||
u32 main_pool_push_state(void) {
|
||||
struct MainPoolState *prevState = gMainPoolState;
|
||||
u32 freeSpace = sPoolFreeSpace;
|
||||
struct MainPoolBlock *lhead = sPoolListHeadL;
|
||||
struct MainPoolBlock *rhead = sPoolListHeadR;
|
||||
|
||||
gMainPoolState = main_pool_alloc(sizeof(*gMainPoolState), MEMORY_POOL_LEFT);
|
||||
gMainPoolState->freeSpace = freeSpace;
|
||||
gMainPoolState->listHeadL = lhead;
|
||||
gMainPoolState->listHeadR = rhead;
|
||||
gMainPoolState->prev = prevState;
|
||||
return sPoolFreeSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore pool state from a previous call to main_pool_push_state. Return the
|
||||
* amount of free space left in the pool.
|
||||
*/
|
||||
u32 main_pool_pop_state(void) {
|
||||
sPoolFreeSpace = gMainPoolState->freeSpace;
|
||||
sPoolListHeadL = gMainPoolState->listHeadL;
|
||||
sPoolListHeadR = gMainPoolState->listHeadR;
|
||||
gMainPoolState = gMainPoolState->prev;
|
||||
return sPoolFreeSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a DMA read from ROM. The transfer is split into 4KB blocks, and this
|
||||
* function blocks until completion.
|
||||
*/
|
||||
void dma_read(u8 *dest, u8 *srcStart, u8 *srcEnd) {
|
||||
u32 size = ALIGN16(srcEnd - srcStart);
|
||||
#if PUPPYPRINT_DEBUG
|
||||
OSTime first = osGetTime();
|
||||
#endif
|
||||
|
||||
osInvalDCache(dest, size);
|
||||
while (size != 0) {
|
||||
u32 copySize = (size >= 0x1000) ? 0x1000 : size;
|
||||
|
||||
osPiStartDma(&gDmaIoMesg, OS_MESG_PRI_NORMAL, OS_READ, (uintptr_t) srcStart, dest, copySize,
|
||||
&gDmaMesgQueue);
|
||||
osRecvMesg(&gDmaMesgQueue, &gMainReceivedMesg, OS_MESG_BLOCK);
|
||||
|
||||
dest += copySize;
|
||||
srcStart += copySize;
|
||||
size -= copySize;
|
||||
}
|
||||
#if PUPPYPRINT_DEBUG
|
||||
dmaTime[perfIteration] += osGetTime()-first;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a DMA read from ROM, allocating space in the memory pool to write to.
|
||||
* Return the destination address.
|
||||
*/
|
||||
void *dynamic_dma_read(u8 *srcStart, u8 *srcEnd, u32 side, u32 alignment, u32 bssLength) {
|
||||
void *dest;
|
||||
u32 size = ALIGN16(srcEnd - srcStart);
|
||||
u32 offset = 0;
|
||||
|
||||
if (alignment && side == MEMORY_POOL_LEFT)
|
||||
{
|
||||
offset = ALIGN((uintptr_t)sPoolListHeadL + 16, alignment) - ((uintptr_t)sPoolListHeadL + 16);
|
||||
}
|
||||
|
||||
dest = main_pool_alloc(offset + size + bssLength, side);
|
||||
if (dest != NULL) {
|
||||
dma_read((u8 *)dest + offset, srcStart, srcEnd);
|
||||
if (bssLength)
|
||||
bzero((u8 *)dest + offset + size, bssLength);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define TLB_PAGE_SIZE 4096 //Blocksize of TLB transfers. Larger values can be faster to transfer, but more wasteful of RAM.
|
||||
s32 gTlbEntries = 0;
|
||||
u8 gTlbSegments[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
void mapTLBPages(uintptr_t virtualAddress, uintptr_t physicalAddress, s32 length, s32 segment)
|
||||
{
|
||||
while (length > 0)
|
||||
{
|
||||
if (length > TLB_PAGE_SIZE)
|
||||
{
|
||||
osMapTLB(gTlbEntries++, OS_PM_4K, (void *)virtualAddress, physicalAddress, physicalAddress + TLB_PAGE_SIZE, -1);
|
||||
virtualAddress += TLB_PAGE_SIZE;
|
||||
physicalAddress += TLB_PAGE_SIZE;
|
||||
length -= TLB_PAGE_SIZE;
|
||||
gTlbSegments[segment]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
osMapTLB(gTlbEntries++, OS_PM_4K, (void *)virtualAddress, physicalAddress, -1, -1);
|
||||
gTlbSegments[segment]++;
|
||||
}
|
||||
virtualAddress += TLB_PAGE_SIZE;
|
||||
physicalAddress += TLB_PAGE_SIZE;
|
||||
length -= TLB_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_SEGMENTED_MEMORY
|
||||
/**
|
||||
* Load data from ROM into a newly allocated block, and set the segment base
|
||||
* address to this block.
|
||||
*/
|
||||
void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u32 side, u8 *bssStart, u8 *bssEnd) {
|
||||
void *addr;
|
||||
|
||||
if (bssStart != NULL && side == MEMORY_POOL_LEFT)
|
||||
{
|
||||
addr = dynamic_dma_read(srcStart, srcEnd, side, TLB_PAGE_SIZE, (uintptr_t)bssEnd - (uintptr_t)bssStart);
|
||||
if (addr != NULL) {
|
||||
u8 *realAddr = (u8 *)ALIGN((uintptr_t)addr, TLB_PAGE_SIZE);
|
||||
set_segment_base_addr(segment, realAddr);
|
||||
mapTLBPages(segment << 24, VIRTUAL_TO_PHYSICAL(realAddr), (srcEnd - srcStart) + ((uintptr_t)bssEnd - (uintptr_t)bssStart), segment);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addr = dynamic_dma_read(srcStart, srcEnd, side, 0, 0);
|
||||
if (addr != NULL) {
|
||||
set_segment_base_addr(segment, addr);
|
||||
}
|
||||
}
|
||||
#if PUPPYPRINT_DEBUG
|
||||
ramsizeSegment[segment+nameTable-2] = (s32)srcEnd- (s32)srcStart;
|
||||
#endif
|
||||
return addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a block of memory starting at destAddr and ending at the end of
|
||||
* the memory pool. Then copy srcStart through srcEnd from ROM to this block.
|
||||
* If this block is not large enough to hold the ROM data, or that portion
|
||||
* of the pool is already allocated, return NULL.
|
||||
*/
|
||||
void *load_to_fixed_pool_addr(u8 *destAddr, u8 *srcStart, u8 *srcEnd) {
|
||||
void *dest = NULL;
|
||||
u32 srcSize = ALIGN16(srcEnd - srcStart);
|
||||
u32 destSize = ALIGN16((u8 *) sPoolListHeadR - destAddr);
|
||||
|
||||
if (srcSize <= destSize) {
|
||||
dest = main_pool_alloc(destSize, MEMORY_POOL_RIGHT);
|
||||
if (dest != NULL) {
|
||||
bzero(dest, destSize);
|
||||
osWritebackDCacheAll();
|
||||
dma_read(dest, srcStart, srcEnd);
|
||||
osInvalICache(dest, destSize);
|
||||
osInvalDCache(dest, destSize);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress the block of ROM data from srcStart to srcEnd and return a
|
||||
* pointer to an allocated buffer holding the decompressed data. Set the
|
||||
* base address of segment to this address.
|
||||
*/
|
||||
void *load_segment_decompress(s32 segment, u8 *srcStart, u8 *srcEnd) {
|
||||
void *dest = NULL;
|
||||
|
||||
#ifdef GZIP
|
||||
u32 compSize = (srcEnd - 4 - srcStart);
|
||||
#else
|
||||
u32 compSize = ALIGN16(srcEnd - srcStart);
|
||||
#endif
|
||||
u8 *compressed = main_pool_alloc(compSize, MEMORY_POOL_RIGHT);
|
||||
#ifdef GZIP
|
||||
// Decompressed size from end of gzip
|
||||
u32 *size = (u32 *) (compressed + compSize);
|
||||
#else
|
||||
// Decompressed size from header (This works for non-mio0 because they also have the size in same place)
|
||||
u32 *size = (u32 *) (compressed + 4);
|
||||
#endif
|
||||
if (compressed != NULL) {
|
||||
#ifdef UNCOMPRESSED
|
||||
dest = main_pool_alloc(compSize, MEMORY_POOL_LEFT);
|
||||
dma_read(dest, srcStart, srcEnd);
|
||||
#else
|
||||
dma_read(compressed, srcStart, srcEnd);
|
||||
dest = main_pool_alloc(*size, MEMORY_POOL_LEFT);
|
||||
#endif
|
||||
if (dest != NULL) {
|
||||
osSyncPrintf("start decompress\n");
|
||||
#ifdef GZIP
|
||||
expand_gzip(compressed, dest, compSize, (u32)size);
|
||||
#elif RNC1
|
||||
Propack_UnpackM1(compressed, dest);
|
||||
#elif RNC2
|
||||
Propack_UnpackM2(compressed, dest);
|
||||
#elif YAY0
|
||||
slidstart(compressed, dest);
|
||||
#elif MIO0
|
||||
decompress(compressed, dest);
|
||||
#endif
|
||||
osSyncPrintf("end decompress\n");
|
||||
set_segment_base_addr(segment, dest);
|
||||
main_pool_free(compressed);
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
#if PUPPYPRINT_DEBUG
|
||||
ramsizeSegment[segment+nameTable-2] = (s32)srcEnd - (s32)srcStart;
|
||||
#endif
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *load_segment_decompress_heap(u32 segment, u8 *srcStart, u8 *srcEnd) {
|
||||
UNUSED void *dest = NULL;
|
||||
|
||||
#ifdef GZIP
|
||||
u32 compSize = (srcEnd - 4 - srcStart);
|
||||
#else
|
||||
u32 compSize = ALIGN16(srcEnd - srcStart);
|
||||
#endif
|
||||
u8 *compressed = main_pool_alloc(compSize, MEMORY_POOL_RIGHT);
|
||||
#ifdef GZIP
|
||||
// Decompressed size from end of gzip
|
||||
u32 *size = (u32 *) (compressed + compSize);
|
||||
#endif
|
||||
if (compressed != NULL) {
|
||||
#ifdef UNCOMPRESSED
|
||||
dma_read(gDecompressionHeap, srcStart, srcEnd);
|
||||
#else
|
||||
dma_read(compressed, srcStart, srcEnd);
|
||||
#endif
|
||||
#ifdef GZIP
|
||||
expand_gzip(compressed, gDecompressionHeap, compSize, (u32)size);
|
||||
#elif RNC1
|
||||
Propack_UnpackM1(compressed, gDecompressionHeap);
|
||||
#elif RNC2
|
||||
Propack_UnpackM2(compressed, gDecompressionHeap);
|
||||
#elif YAY0
|
||||
slidstart(compressed, gDecompressionHeap);
|
||||
#elif MIO0
|
||||
decompress(compressed, gDecompressionHeap);
|
||||
#endif
|
||||
set_segment_base_addr(segment, gDecompressionHeap);
|
||||
main_pool_free(compressed);
|
||||
} else {
|
||||
}
|
||||
return gDecompressionHeap;
|
||||
}
|
||||
|
||||
void load_engine_code_segment(void) {
|
||||
void *startAddr = (void *) _engineSegmentStart;
|
||||
u32 totalSize = _engineSegmentEnd - _engineSegmentStart;
|
||||
UNUSED u32 alignedSize = ALIGN16(_engineSegmentRomEnd - _engineSegmentRomStart);
|
||||
|
||||
bzero(startAddr, totalSize);
|
||||
osWritebackDCacheAll();
|
||||
dma_read(startAddr, _engineSegmentRomStart, _engineSegmentRomEnd);
|
||||
osInvalICache(startAddr, totalSize);
|
||||
osInvalDCache(startAddr, totalSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allocate an allocation-only pool from the main pool. This pool doesn't
|
||||
* support freeing allocated memory.
|
||||
* Return NULL if there is not enough space in the main pool.
|
||||
*/
|
||||
struct AllocOnlyPool *alloc_only_pool_init(u32 size, u32 side) {
|
||||
void *addr;
|
||||
struct AllocOnlyPool *subPool = NULL;
|
||||
|
||||
size = ALIGN4(size);
|
||||
addr = main_pool_alloc(size + sizeof(struct AllocOnlyPool), side);
|
||||
if (addr != NULL) {
|
||||
subPool = (struct AllocOnlyPool *) addr;
|
||||
subPool->totalSpace = size;
|
||||
subPool->usedSpace = 0;
|
||||
subPool->startPtr = (u8 *) addr + sizeof(struct AllocOnlyPool);
|
||||
subPool->freePtr = (u8 *) addr + sizeof(struct AllocOnlyPool);
|
||||
}
|
||||
return subPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate from an allocation-only pool.
|
||||
* Return NULL if there is not enough space.
|
||||
*/
|
||||
void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size) {
|
||||
void *addr = NULL;
|
||||
|
||||
size = ALIGN4(size);
|
||||
if (size > 0 && pool->usedSpace + size <= pool->totalSpace) {
|
||||
addr = pool->freePtr;
|
||||
pool->freePtr += size;
|
||||
pool->usedSpace += size;
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize an allocation-only pool.
|
||||
* If the pool is increasing in size, the pool must be the last thing allocated
|
||||
* from the left end of the main pool.
|
||||
* The pool does not move.
|
||||
*/
|
||||
struct AllocOnlyPool *alloc_only_pool_resize(struct AllocOnlyPool *pool, u32 size) {
|
||||
struct AllocOnlyPool *newPool;
|
||||
|
||||
size = ALIGN4(size);
|
||||
newPool = main_pool_realloc(pool, size + sizeof(struct AllocOnlyPool));
|
||||
if (newPool != NULL) {
|
||||
pool->totalSpace = size;
|
||||
}
|
||||
return newPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a memory pool from the main pool. This pool supports arbitrary
|
||||
* order for allocation/freeing.
|
||||
* Return NULL if there is not enough space in the main pool.
|
||||
*/
|
||||
struct MemoryPool *mem_pool_init(u32 size, u32 side) {
|
||||
void *addr;
|
||||
struct MemoryBlock *block;
|
||||
struct MemoryPool *pool = NULL;
|
||||
|
||||
size = ALIGN4(size);
|
||||
addr = main_pool_alloc(size + sizeof(struct MemoryPool), side);
|
||||
if (addr != NULL) {
|
||||
pool = (struct MemoryPool *) addr;
|
||||
|
||||
pool->totalSpace = size;
|
||||
pool->firstBlock = (struct MemoryBlock *) ((u8 *) addr + sizeof(struct MemoryPool));
|
||||
pool->freeList.next = (struct MemoryBlock *) ((u8 *) addr + sizeof(struct MemoryPool));
|
||||
|
||||
block = pool->firstBlock;
|
||||
block->next = NULL;
|
||||
block->size = pool->totalSpace;
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate from a memory pool. Return NULL if there is not enough space.
|
||||
*/
|
||||
void *mem_pool_alloc(struct MemoryPool *pool, u32 size) {
|
||||
struct MemoryBlock *freeBlock = &pool->freeList;
|
||||
void *addr = NULL;
|
||||
|
||||
size = ALIGN4(size) + sizeof(struct MemoryBlock);
|
||||
while (freeBlock->next != NULL) {
|
||||
if (freeBlock->next->size >= size) {
|
||||
addr = (u8 *) freeBlock->next + sizeof(struct MemoryBlock);
|
||||
if (freeBlock->next->size - size <= sizeof(struct MemoryBlock)) {
|
||||
freeBlock->next = freeBlock->next->next;
|
||||
} else {
|
||||
struct MemoryBlock *newBlock = (struct MemoryBlock *) ((u8 *) freeBlock->next + size);
|
||||
newBlock->size = freeBlock->next->size - size;
|
||||
newBlock->next = freeBlock->next->next;
|
||||
freeBlock->next->size = size;
|
||||
freeBlock->next = newBlock;
|
||||
}
|
||||
break;
|
||||
}
|
||||
freeBlock = freeBlock->next;
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a block that was allocated using mem_pool_alloc.
|
||||
*/
|
||||
void mem_pool_free(struct MemoryPool *pool, void *addr) {
|
||||
struct MemoryBlock *block = (struct MemoryBlock *) ((u8 *) addr - sizeof(struct MemoryBlock));
|
||||
struct MemoryBlock *freeList = pool->freeList.next;
|
||||
|
||||
if (pool->freeList.next == NULL) {
|
||||
pool->freeList.next = block;
|
||||
block->next = NULL;
|
||||
} else {
|
||||
if (block < pool->freeList.next) {
|
||||
if ((u8 *) pool->freeList.next == (u8 *) block + block->size) {
|
||||
block->size += freeList->size;
|
||||
block->next = freeList->next;
|
||||
pool->freeList.next = block;
|
||||
} else {
|
||||
block->next = pool->freeList.next;
|
||||
pool->freeList.next = block;
|
||||
}
|
||||
} else {
|
||||
while (freeList->next != NULL) {
|
||||
if (freeList < block && block < freeList->next) {
|
||||
break;
|
||||
}
|
||||
freeList = freeList->next;
|
||||
}
|
||||
if ((u8 *) freeList + freeList->size == (u8 *) block) {
|
||||
freeList->size += block->size;
|
||||
block = freeList;
|
||||
} else {
|
||||
block->next = freeList->next;
|
||||
freeList->next = block;
|
||||
}
|
||||
if (block->next != NULL && (u8 *) block->next == (u8 *) block + block->size) {
|
||||
block->size = block->size + block->next->size;
|
||||
block->next = block->next->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *alloc_display_list(u32 size) {
|
||||
void *ptr = NULL;
|
||||
|
||||
size = ALIGN8(size);
|
||||
if (gGfxPoolEnd - size >= (u8 *) gDisplayListHead) {
|
||||
gGfxPoolEnd -= size;
|
||||
ptr = gGfxPoolEnd;
|
||||
} else {
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static struct DmaTable *load_dma_table_address(u8 *srcAddr) {
|
||||
struct DmaTable *table = dynamic_dma_read(srcAddr, srcAddr + sizeof(u32),
|
||||
MEMORY_POOL_LEFT, 0, 0);
|
||||
u32 size = table->count * sizeof(struct OffsetSizePair) +
|
||||
sizeof(struct DmaTable) - sizeof(struct OffsetSizePair);
|
||||
main_pool_free(table);
|
||||
|
||||
table = dynamic_dma_read(srcAddr, srcAddr + size, MEMORY_POOL_LEFT, 0, 0);
|
||||
table->srcAddr = srcAddr;
|
||||
return table;
|
||||
}
|
||||
|
||||
void setup_dma_table_list(struct DmaHandlerList *list, void *srcAddr, void *buffer) {
|
||||
if (srcAddr != NULL) {
|
||||
list->dmaTable = load_dma_table_address(srcAddr);
|
||||
}
|
||||
list->currentAddr = NULL;
|
||||
list->bufTarget = buffer;
|
||||
}
|
||||
|
||||
s32 load_patchable_table(struct DmaHandlerList *list, s32 index) {
|
||||
s32 ret = FALSE;
|
||||
struct DmaTable *table = list->dmaTable;
|
||||
|
||||
if ((u32)index < table->count) {
|
||||
u8 *addr = table->srcAddr + table->anim[index].offset;
|
||||
s32 size = table->anim[index].size;
|
||||
|
||||
if (list->currentAddr != addr) {
|
||||
dma_read(list->bufTarget, addr, addr + size);
|
||||
list->currentAddr = addr;
|
||||
ret = TRUE;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Executable
+415
@@ -0,0 +1,415 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
* PROPACK Unpack Source Code - Sony PSX, Method 1
|
||||
*
|
||||
* Copyright (c) 1991-96 Rob Northen Computing, U.K. All Rights Reserved.
|
||||
*
|
||||
* Conversion from 68000 by Brian Watson, Iguana Entertainment Limited.
|
||||
* Converted to compile with SGI 'as' 10/31/96 by Biscuit
|
||||
*
|
||||
* File: rnc1.s
|
||||
*
|
||||
* Date: 10.21.96
|
||||
*------------------------------------------------------------------------------
|
||||
*/
|
||||
/*------------------------------------------------------------------------------
|
||||
* Equates
|
||||
*------------------------------------------------------------------------------
|
||||
*/
|
||||
#define HEADER_LEN 18
|
||||
#define crc_poly 0xa001
|
||||
|
||||
#define RAW_TABLE 0
|
||||
#define POS_TABLE (RAW_TABLE+16*8)
|
||||
#define LEN_TABLE (POS_TABLE+16*8)
|
||||
#define BUFSIZE (16*8*3)
|
||||
|
||||
#define ra $31 /* ra */
|
||||
#define d0 $8 /* t0 */
|
||||
#define d1 $9 /* t1 */
|
||||
#define d2 $10 /* t2 */
|
||||
#define d3 $11 /* t3 */
|
||||
#define d4 $12 /* t4 */
|
||||
#define d5 $13 /* t5 */
|
||||
#define d6 $14 /* t6 */
|
||||
#define d7 $15 /* t7 */
|
||||
|
||||
#define xa0 $16 /* s0 */
|
||||
#define xa1 $17 /* s1 */
|
||||
#define xa2 $18 /* s2 */
|
||||
#define xa3 $19 /* s3 */
|
||||
#define xa4 $20 /* s4 */
|
||||
#define xa5 $21 /* s5 */
|
||||
#define xa6 $22 /* s6 */
|
||||
#define xa7 $23 /* s7 */
|
||||
|
||||
#define TEMP $2 /* v1 */
|
||||
#define input xa3 /* s3 */
|
||||
#define output xa4 /* s4 */
|
||||
#define output_hi xa5 /* s5 */
|
||||
|
||||
#define counts d4 /* t4 */
|
||||
#define bit_buffer d6 /* t6 */
|
||||
#define bit_count d7 /* t7 */
|
||||
|
||||
|
||||
#define zero $0 /* zero */
|
||||
#define tmp $1 /* at */
|
||||
#define tmp2 $2 /* v0 */
|
||||
#define const_ff $3 /* v1 */
|
||||
#define const_ff000000 $4 /* a0 */
|
||||
#define const_80000000 $5 /* a1 */
|
||||
#define const_ffffff00 $6 /* a2 */
|
||||
#define const_8000 $7 /* a3 */
|
||||
#define a0 $4
|
||||
#define a1 $5
|
||||
/*------------------------------------------------------------------------------
|
||||
* Macros
|
||||
*------------------------------------------------------------------------------
|
||||
*/
|
||||
#define pop(reg) lw reg,0($sp) ; add $sp,$sp,8
|
||||
|
||||
#define dbra reg,dest bne reg,zero,dest ; sub reg,reg,1
|
||||
/*------------------------------------------------------------------------------
|
||||
* PROPACK Unpack Routine (Compact Version) - MC68000, Method 1
|
||||
*
|
||||
* on entry,
|
||||
* a0.l = start address of packed file
|
||||
* a1.l = start address to unpack file
|
||||
* (note: a1 cannot be equal to a0)
|
||||
* stack space required: $1DC bytes
|
||||
*
|
||||
* all other registers are preserved
|
||||
* Note:
|
||||
* lines with a comment beginning with '*' are delay slot instructions
|
||||
* beware the delay slot, it can really screw you up!
|
||||
*------------------------------------------------------------------------------
|
||||
*/
|
||||
.text
|
||||
.set noreorder
|
||||
.option pic0
|
||||
.set noat
|
||||
|
||||
.globl Propack_UnpackM1
|
||||
.ent Propack_UnpackM1 2
|
||||
Propack_UnpackM1:
|
||||
.frame $sp, 0, $31
|
||||
/*
|
||||
Save any registers required here
|
||||
*/
|
||||
sub $sp, $sp, 88
|
||||
sw $4, 0($sp)
|
||||
sw $5, 4($sp)
|
||||
sw $6, 8($sp)
|
||||
sw $7, 12($sp)
|
||||
sw $8, 16($sp)
|
||||
sw $9, 20($sp)
|
||||
sw $10,24($sp)
|
||||
sw $11,28($sp)
|
||||
sw $12,32($sp)
|
||||
sw $13,36($sp)
|
||||
sw $14,40($sp)
|
||||
sw $15,44($sp)
|
||||
sw $16,48($sp)
|
||||
sw $17,52($sp)
|
||||
sw $18,56($sp)
|
||||
sw $19,60($sp)
|
||||
sw $20,64($sp)
|
||||
sw $21,68($sp)
|
||||
sw $22,72($sp)
|
||||
sw $23,76($sp)
|
||||
sw $31,80($sp)
|
||||
/* Set up entry parameters, the RNC code always uses a0, a1 for */
|
||||
/* the I/O datastream and we must use R3K registers A0,A1 */
|
||||
move xa0,a0 /* move input,a0 */
|
||||
jal pp_Unpack /* bsr pp_Unpack */
|
||||
move xa1,a1 /* move output,a1 */
|
||||
|
||||
/*
|
||||
Restore previously saved registers here
|
||||
*/
|
||||
lw $4, 0($sp)
|
||||
lw $5, 4($sp)
|
||||
lw $6, 8($sp)
|
||||
lw $7, 12($sp)
|
||||
lw $8, 16($sp)
|
||||
lw $9, 20($sp)
|
||||
lw $10,24($sp)
|
||||
lw $11,28($sp)
|
||||
lw $12,32($sp)
|
||||
lw $13,36($sp)
|
||||
lw $14,40($sp)
|
||||
lw $15,44($sp)
|
||||
lw $16,48($sp)
|
||||
lw $17,52($sp)
|
||||
lw $18,56($sp)
|
||||
lw $19,60($sp)
|
||||
lw $20,64($sp)
|
||||
lw $21,68($sp)
|
||||
lw $22,72($sp)
|
||||
lw $23,76($sp)
|
||||
lw $31,80($sp)
|
||||
|
||||
j ra /* rts */
|
||||
add $sp, $sp, 88
|
||||
pp_Unpack:
|
||||
sub const_ff,zero,1 /* Set up constant 0xff */
|
||||
and const_ff,const_ff,0x00ff
|
||||
sll const_ff000000,const_ff,24 /* Set up constant 0xff000000 */
|
||||
sll const_80000000,const_ff,31 /* Set up constant 0x80000000 */
|
||||
srl const_8000,const_80000000,16 /* Set up constant 0x8000 */
|
||||
nor const_ffffff00,zero,const_ff /* Set up constant 0xffffff00 */
|
||||
|
||||
sub $sp,$sp,8+BUFSIZE /* sub.w #bufsize,sp, store link address */
|
||||
add xa2,$sp,8 /* move.w sp,a2 */
|
||||
sw ra,($sp)
|
||||
lw d0, 4(xa0) /* get uncomp'd length */
|
||||
add xa0,xa0,8 /* skip past comp'd and uncomp'd lengths */
|
||||
add input,xa0,HEADER_LEN-8 /* lea HEADER_LEN-8(a0),input (skip past rest of header) */
|
||||
move output,xa1 /* move.l a1,output */
|
||||
lbu bit_buffer,1(input) /* move.b 1(input),bit_buffer */
|
||||
lbu tmp,0(input) /* move.b 0(input),bit_buffer (after bit_buffer is rotated) */
|
||||
move bit_count,zero /* moveq.l #0,bit_count */
|
||||
sll bit_buffer,bit_buffer,8 /* " " rotate high byte into position */
|
||||
or bit_buffer,bit_buffer,tmp /* " " and or it in to the bit_buffer */
|
||||
add output_hi,output,d0 /* lea (output,d0.l),output_hi */
|
||||
add d0,zero,2 /* moveq.l #2,d0 */
|
||||
jal input_bits /* bsr input_bits */
|
||||
add d1,zero,2 /* moveq.l #2,d1 */
|
||||
unpack2:
|
||||
/* */
|
||||
/* Fill the hufftables with a set value so we can see if they work */
|
||||
/* */
|
||||
jal make_huftable /* bsr make_huftable */
|
||||
move xa0,xa2 /* move.l a2,a0 */
|
||||
jal make_huftable /* bsr make_huftable */
|
||||
add xa0,xa2,POS_TABLE /* lea POS_TABLE(a2),a0 */
|
||||
jal make_huftable /* bsr make_huftable */
|
||||
add xa0,xa2,LEN_TABLE /* lea LEN_TABLE(a2),a0 */
|
||||
add d0,zero,-1 /* moveq.l #-1,d0 */
|
||||
jal input_bits /* bsr input_bits */
|
||||
add d1,zero,16 /* moveq.l #16,d1 */
|
||||
move counts,d0 /* move.w d0,counts */
|
||||
sub tmp,zero,1
|
||||
srl tmp,tmp,16
|
||||
sub counts,counts,1 /* subq.w #1,counts */
|
||||
j unpack5 /* bra.s unpack5 */
|
||||
and counts,tmp,counts
|
||||
unpack3:
|
||||
add xa0,xa2,POS_TABLE /* lea POS_TABLE(a2),a0 */
|
||||
jal input_value /* bsr.s input_value */
|
||||
move d0,zero /* moveq.l #0,d0 */
|
||||
subu d0,zero,d0 /* neg.l d0 */
|
||||
add xa1,output,d0 /* lea -1(output,d0.l),a1 */
|
||||
add xa1,xa1,-1 /* " " */
|
||||
jal input_value /* bsr.s input_value */
|
||||
add xa0,xa2,LEN_TABLE /* lea LEN_TABLE(a2),a0 */
|
||||
add output,output,1 /* move.b (a1)+,(output)+ */
|
||||
lbu tmp,(xa1) /* " " */
|
||||
add xa1,xa1,1 /* " " */
|
||||
sb tmp,-1(output) /* " " */
|
||||
addu tmp2,xa1,d0
|
||||
.global unpack4
|
||||
unpack4:
|
||||
add output,output,1 /* move.b (a1)+,(output)+ */
|
||||
lbu tmp,(xa1) /* " " */
|
||||
sb tmp,-1(output) /* " " */
|
||||
bne xa1,tmp2,unpack4 /* dbra d0,unpack4 */
|
||||
add xa1,xa1,1
|
||||
unpack5:
|
||||
jal input_value /* bsr.s input_value */
|
||||
move xa0,xa2 /* move.l a2,a0 */
|
||||
sub d0,d0,1 /* subq.w #1,d0 */
|
||||
bltz d0,unpack6 /* bmi.s unpack6 */
|
||||
nop
|
||||
jal getrawREP /* getrawREP */
|
||||
nop
|
||||
lbu tmp,1(input) /* move.b 1(input),d0 */
|
||||
lbu d0,0(input) /* move.b (input),d0 */
|
||||
sll tmp,tmp,8 /* rol.w #8,d0 */
|
||||
or d0,tmp,d0 /* " " */
|
||||
|
||||
sll d0,d0,bit_count /* lsl.l bit_count,d0 */
|
||||
add d1,zero,1 /* moveq.l #1,d1 */
|
||||
sll d1,d1,bit_count /* lsl.w bit_count,d1 */
|
||||
subu d1,d1,1 /* subq.w #1,d1 */
|
||||
and bit_buffer,bit_buffer,d1 /* and.l d1,bit_buffer */
|
||||
or bit_buffer,d0,bit_buffer /* or.l d0,bit_buffer */
|
||||
unpack6:
|
||||
bne counts,zero,unpack3 /* dbra counts,unpack3 */
|
||||
sub counts,counts,1
|
||||
sub tmp,output,output_hi /* cmp.l output_hi,output */
|
||||
bltz tmp,unpack2 /* bcs.s unpack2 */
|
||||
nop /* " " */
|
||||
lw ra,($sp) /* Restore from linked jumps */
|
||||
jr ra /* rts */
|
||||
add $sp, $sp, 8 + BUFSIZE /* lea BUFSIZE(sp),sp */
|
||||
input_value:
|
||||
lhu d0,0(xa0) /* move.w (a0)+,d0 */
|
||||
and d0,d0,bit_buffer /* and.w bit_buffer,d0 */
|
||||
lhu tmp,2(xa0) /* move.w (a0)+,d0 */
|
||||
sub d0,d0,tmp /* " " */
|
||||
bne d0,zero,input_value /* bne.s input_value */
|
||||
add xa0,xa0,4 /* " " */
|
||||
lbu d1,16*4-4(xa0) /* move.b 16*4-4(a0),d1 */
|
||||
sub bit_count,bit_count,d1 /* sub.b d1,bit_count */
|
||||
bgezl bit_count,input_value2 /* bge.s input_value2 */
|
||||
srl bit_buffer,bit_buffer,d1 /* lsr.l d1,bit_buffer */
|
||||
sw ra,-8($sp)
|
||||
jal input_bits3 /* bsr.s input_bits3 */
|
||||
sub $sp,$sp,8 /* Preserve link address for return*/
|
||||
lw ra,($sp) /* Restore from linked jumps */
|
||||
add $sp,$sp,8
|
||||
input_value2:
|
||||
lbu d0,16*4-3(xa0) /* move.b 16*4-3(a0),d0 */
|
||||
sub tmp,d0,2 /* cmp.b #2,d0 */
|
||||
bltz tmp,input_value4 /* blt.s input_value4 */
|
||||
nop
|
||||
sub d0,d0,1 /* subq.b #1,d0 */
|
||||
move d1,d0 /* move.b d0,d1 */
|
||||
move d2,d0 /* move.b d0,d2 */
|
||||
lhu d0,16*4-2(xa0) /* move.w 16*4-2(a0),d0 */
|
||||
sub bit_count,bit_count,d1 /* sub.b d1,bit_count */
|
||||
and d0,d0,bit_buffer /* and.w bit_buffer,d0 */
|
||||
add tmp,zero,1
|
||||
sll tmp,tmp,d2 /* bset d2,d0 */
|
||||
bltz bit_count,input_bits3 /* bge.s input_value3 */
|
||||
or d0,tmp,d0 /* " " */
|
||||
srl bit_buffer,bit_buffer,d1 /* lsr.l d1,bit_buffer */
|
||||
input_value4:
|
||||
jr ra
|
||||
nop /*(Delay Slot) */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
/ input_bits - Entry:
|
||||
// D0 - Mask to and output data with
|
||||
// D1 - Number of bits to fetch
|
||||
// Exit:
|
||||
// D0 - Value read from buffer
|
||||
//------------------------------------------------------------------------------
|
||||
*/
|
||||
input_bits:
|
||||
sub bit_count,bit_count,d1 /* sub.b d1,bit_count */
|
||||
bgez bit_count,input_bits_ret /* bge.s input_bits2 */
|
||||
and d0,bit_buffer,d0 /* and.w bit_buffer,d0 */
|
||||
input_bits3:
|
||||
add bit_count,bit_count,d1 /* Make sure we have correct # of bits left in buffer */
|
||||
srl bit_buffer,bit_buffer,bit_count /* lsr.l bit_count,bit_buffer */
|
||||
|
||||
add input,input,2 /* jump passed our data for some odd reason */
|
||||
lbu tmp,0(input) /* Get our new word to add into bit buffer */
|
||||
lbu tmp2,1(input) /* byte at a time..... */
|
||||
sll tmp,tmp,16 /* shift this into the right place */
|
||||
sll tmp2,tmp2,24
|
||||
or bit_buffer,bit_buffer,tmp2 /* OR in the 2 new bytes read to the bit buffer */
|
||||
or bit_buffer,bit_buffer,tmp
|
||||
|
||||
sub d1,d1,bit_count /* sub.b bit_count,d1 */
|
||||
add bit_count,zero,16 /* moveq.l #16,bit_count */
|
||||
sub bit_count,bit_count,d1 /* sub.b d1,bit_count */
|
||||
input_bits_ret:
|
||||
jr ra /* rts */
|
||||
srl bit_buffer,bit_buffer,d1 /*(Delay Slot)lsr.l d1,bit_buffer */
|
||||
/*------------------------------------------------------------------------------
|
||||
// Make_HufTable - Builds huffman decode table
|
||||
//------------------------------------------------------------------------------
|
||||
*/
|
||||
make_huftable:
|
||||
sub $sp,$sp,8 /* Preserve link address for return*/
|
||||
sw ra,0($sp)
|
||||
add d0,zero,0x1f /* moveq.l #$1f,d0 */
|
||||
jal input_bits /* bsr.s input_bits */
|
||||
add d1,zero,0x5 /* moveq.l #5,d1 */
|
||||
lw ra,($sp) /* Restore from linked jumps */
|
||||
|
||||
sub d0,d0,1 /* subq.w #1,d0 */
|
||||
bltz d0,make_huftable8 /* bmi.s make_huftable8 */
|
||||
add $sp,$sp,8
|
||||
move d2,d0 /* move.w d0,d2 */
|
||||
move d3,d0 /* move.w d0,d3 */
|
||||
sub $sp,$sp,24 /* lea -16(sp),sp */
|
||||
add xa1,$sp,8 /* move.l sp,a1 */
|
||||
sw ra,0($sp) /* Preserve link address for return*/
|
||||
make_huftable3:
|
||||
add d0,zero,15 /* moveq.l #$f,d0 */
|
||||
jal input_bits /* bsr.s input_bits */
|
||||
add d1,zero,4 /* moveq.l #4,d1 */
|
||||
sb d0,(xa1) /* move.b d0,(a1)+ */
|
||||
add xa1,xa1,1 /* " " */
|
||||
bne d2,zero,make_huftable3 /* dbra d2,make_huftable3 */
|
||||
sub d2,d2,1
|
||||
lw ra,($sp) /* Restore from linked jumps */
|
||||
move d0,const_80000000 /* moveq.l #1,d0 (with shift == 0x8000000) */
|
||||
add d1,zero,1 /* moveq.l #1,d1 */
|
||||
move d2,zero /* moveq.l #0,d2 */
|
||||
sub $sp,$sp,8 /* movem.l d5-d7,-(sp) */
|
||||
sw d5,0($sp) /* " " */
|
||||
sw d6,4($sp) /* " " */
|
||||
sw d7,8($sp) /* " " */
|
||||
make_huftable4:
|
||||
move d4,d3 /* move.w d3,d4 */
|
||||
add xa1,$sp,16 /* lea 12(sp),a1 */
|
||||
make_huftable5:
|
||||
lbu tmp,0(xa1) /* cmp.b (a1)+,d1 */
|
||||
bne d1,tmp,make_huftable7 /* bne.s make_huftable7 */
|
||||
add xa1,xa1,1 /* " " */
|
||||
add d5,zero,1 /* moveq.l #1,d5 */
|
||||
sll d5,d5,d1 /* lsl.w d1,d5 */
|
||||
sub d5,d5,1 /* subq.w #1,d5 */
|
||||
sh d5,0(xa0) /* move.w d5,(a0)+ */
|
||||
add xa0,xa0,2 /* " " */
|
||||
move d5,d2 /* move.l d2,d5 */
|
||||
sll tmp,d5,16 /* swap d5 */
|
||||
srl d5,d5,16 /* " " */
|
||||
or d5,d5,tmp /* " " */
|
||||
move d7,d1 /* move.w d1,d7 */
|
||||
sub d7,d7,1 /* subq.w #1,d7 */
|
||||
make_huftable6:
|
||||
sub tmp,zero,1
|
||||
srl tmp,tmp,16
|
||||
and d6,tmp,d6
|
||||
and tmp,d5,const_8000 /* roxl.w #1,d5 */
|
||||
sll d5,d5,1 /* " " */
|
||||
beq tmp,zero,make_ht6_1 /* roxr.w #1,d6 */
|
||||
srl d6,d6,1 /* " " */
|
||||
or d6,d6,const_8000 /* " " */
|
||||
make_ht6_1: bne d7,zero,make_huftable6 /* dbra d7,make_huftable6 */
|
||||
sub d7,d7,1
|
||||
add d5,zero,16 /* moveq.l #16,d5 */
|
||||
sub d5,d5,d1 /* sub.b d1,d5 */
|
||||
srl d6,d6,d5 /* lsr.w d5,d6 */
|
||||
sh d6,0(xa0) /* move.w d6,(a0)+ */
|
||||
add xa0,xa0,2 /* " " */
|
||||
sb d1,16*4-4(xa0) /* move.b d1,16*4-4(a0) */
|
||||
move d5,d3 /* move.b d3,d5 */
|
||||
subu d5,d5,d4 /* sub.b d4,d5 */
|
||||
sb d5,16*4-3(xa0) /* move.b d5,16*4-3(a0) */
|
||||
add d6,zero,1 /* moveq.l #1,d6 */
|
||||
subu d5,d5,1 /* subq.b #1,d5 */
|
||||
sll d6,d6,d5 /* lsl.w d5,d6 */
|
||||
subu d6,d6,1 /* subq.w #1,d6 */
|
||||
sh d6,16*4-2(xa0) /* move.w d6,16*4-2(a0) */
|
||||
addu d2,d2,d0 /* add.l d0,d2 */
|
||||
make_huftable7:
|
||||
bne d4,zero,make_huftable5 /* dbra d4,make_huftable5 */
|
||||
sub d4,d4,1
|
||||
srl d0,d0,1 /* lsr.l #1,d0 */
|
||||
add d1,d1,1 /* addq.b #1,d1 */
|
||||
add tmp,zero,17 /* cmp.b #17,d1 */
|
||||
bne d1,tmp,make_huftable4 /* bne.s make_huftable4 */
|
||||
lw d5,0($sp) /* movem.l (sp)+,d5-d7 */
|
||||
lw d6,4($sp) /* " " */
|
||||
lw d7,8($sp) /* " " */
|
||||
jr ra
|
||||
add $sp,$sp,32 /* lea 16(sp),sp */
|
||||
getrawREP:
|
||||
lbu tmp,0(input)
|
||||
sb tmp,0(output)
|
||||
add output,output,1
|
||||
add input,input,1
|
||||
bne d0,zero,getrawREP /* dbra d0,getrawREP */
|
||||
sub d0,d0,1
|
||||
make_huftable8:
|
||||
jr ra
|
||||
nop /*(Delay Slot) */
|
||||
|
||||
.end
|
||||
Executable
+673
@@ -0,0 +1,673 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
* PROPACK Unpack Source Code - Sony PSX, Method 2
|
||||
*
|
||||
* Copyright (c) 1991-95 Rob Northen Computing, U.K. All Rights Reserved.
|
||||
*
|
||||
* Conversion from 68000 by Chris Kirby, Iguana Entertainment Limited.
|
||||
* Converted to compile with SGI as, 9/13/96 Biscuit
|
||||
* Beware the commentless void.........
|
||||
*
|
||||
* File: rnc2.s
|
||||
*
|
||||
* Date: 16.03.95
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#define header_len 18
|
||||
#define crc_poly 0xa001
|
||||
|
||||
#define r0 $0
|
||||
#define r4 $4
|
||||
#define r5 $5
|
||||
|
||||
#define input $3
|
||||
#define input_hi $4
|
||||
#define output $5
|
||||
#define output_hi $6
|
||||
#define len $8
|
||||
#define pos $9
|
||||
#define bitbuf $10
|
||||
#define xsp $11
|
||||
#define temp $12
|
||||
#define xd0 $13
|
||||
#define xa0 $14
|
||||
#define ext $15
|
||||
#define xd1 $16
|
||||
#define xa1 $17
|
||||
#define temp2 $18
|
||||
#define postop $19
|
||||
#define ra $31
|
||||
#define retval $2
|
||||
|
||||
.text
|
||||
.set noreorder
|
||||
.option pic0
|
||||
|
||||
.globl Propack_UnpackM2
|
||||
.ent Propack_UnpackM2 2
|
||||
Propack_UnpackM2:
|
||||
|
||||
.frame $sp, 0, $31
|
||||
|
||||
sub $sp, $sp, 72
|
||||
sw $4, 0($sp)
|
||||
sw $5, 4($sp)
|
||||
sw $6, 8($sp)
|
||||
sw $7, 12($sp)
|
||||
sw $8, 16($sp)
|
||||
sw $9, 20($sp)
|
||||
sw $10, 24($sp)
|
||||
sw $11, 28($sp)
|
||||
sw $12, 32($sp)
|
||||
sw $13, 36($sp)
|
||||
sw $14, 40($sp)
|
||||
sw $15, 44($sp)
|
||||
sw $16, 48($sp)
|
||||
sw $17, 52($sp)
|
||||
sw $18, 56($sp)
|
||||
sw $19, 60($sp)
|
||||
sw $31, 64($sp)
|
||||
la temp, __PPUnpack
|
||||
nop
|
||||
jalr temp
|
||||
nop
|
||||
|
||||
lw $4, 0($sp)
|
||||
lw $5, 4($sp)
|
||||
lw $6, 8($sp)
|
||||
lw $7, 12($sp)
|
||||
lw $8, 16($sp)
|
||||
lw $9, 20($sp)
|
||||
lw $10, 24($sp)
|
||||
lw $11, 28($sp)
|
||||
lw $12, 32($sp)
|
||||
lw $13, 36($sp)
|
||||
lw $14, 40($sp)
|
||||
lw $15, 44($sp)
|
||||
lw $16, 48($sp)
|
||||
lw $17, 52($sp)
|
||||
lw $18, 56($sp)
|
||||
lw $19, 60($sp)
|
||||
lw $31, 64($sp)
|
||||
|
||||
add $sp, $sp, 72
|
||||
jr ra
|
||||
|
||||
__PPUnpack:
|
||||
/* addi r4,r4,9 - what the hell was this for?*/
|
||||
move xa0,r4 /* source */
|
||||
move xa1,r5 /* dest */
|
||||
li xd0,0
|
||||
|
||||
la xsp,mystack
|
||||
#if 0
|
||||
lbu temp,0(xa0)
|
||||
nop
|
||||
seq xa0,temp, "R"
|
||||
beq xa0,0, RNC_Error
|
||||
|
||||
lbu temp,1(xa0)
|
||||
nop
|
||||
seq xa0,temp, "N"
|
||||
beq xa0,0, RNC_Error
|
||||
|
||||
lbu temp,2(xa0)
|
||||
nop
|
||||
seq xa0,temp, "C"
|
||||
beq xa0,0, RNC_Error
|
||||
|
||||
lbu temp,3(xa0)
|
||||
nop
|
||||
seq xa0, temp, 2
|
||||
beq xa0, 0, RNC_BadFormat
|
||||
#endif
|
||||
|
||||
|
||||
addiu xa0,xa0,4
|
||||
lbu xd0,0(xa0)
|
||||
lbu temp,1(xa0)
|
||||
lbu temp2,2(xa0)
|
||||
lbu ext,3(xa0)
|
||||
sll xd0,xd0,24
|
||||
sll temp,temp,16
|
||||
sll temp2,temp2,8
|
||||
or xd0,xd0,temp
|
||||
or xd0,xd0,temp2
|
||||
or xd0,xd0,ext
|
||||
|
||||
addiu xa0,xa0,4
|
||||
|
||||
sw xd0,0(xsp)
|
||||
move input,xa0
|
||||
addi input,input,header_len-8
|
||||
|
||||
move output,xa1
|
||||
move output_hi,output
|
||||
addu output_hi,output_hi,xd0
|
||||
|
||||
lbu xd0,0(xa0)
|
||||
lbu temp,1(xa0)
|
||||
lbu temp2,2(xa0)
|
||||
lbu ext,3(xa0)
|
||||
sll xd0,xd0,24
|
||||
sll temp,temp,16
|
||||
sll temp2,temp2,8
|
||||
or xd0,xd0,temp
|
||||
or xd0,xd0,temp2
|
||||
or xd0,xd0,ext
|
||||
|
||||
|
||||
addu xa0,xa0,4
|
||||
|
||||
move input_hi,input
|
||||
add input_hi,input_hi,xd0
|
||||
|
||||
sub xsp,xsp,2
|
||||
sh r0,0(xsp)
|
||||
|
||||
|
||||
unpack7:
|
||||
lui bitbuf,0xffff
|
||||
ori bitbuf,0xff00
|
||||
|
||||
li ext,1
|
||||
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
|
||||
j xloop
|
||||
andi ext,ext,1
|
||||
|
||||
RNC_Error:
|
||||
li retval, -1 /* Error Bad Header */
|
||||
j ra
|
||||
nop
|
||||
|
||||
RNC_BadFormat:
|
||||
li retval, -2 /* Error Unknown format */
|
||||
j ra
|
||||
nop
|
||||
|
||||
fetch0:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back0
|
||||
andi ext,ext,1
|
||||
fetch1:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back1
|
||||
andi ext,ext,1
|
||||
fetch2:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back2
|
||||
andi ext,ext,1
|
||||
fetch3:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back3
|
||||
andi ext,ext,1
|
||||
fetch4:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back4
|
||||
andi ext,ext,1
|
||||
fetch5:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back5
|
||||
andi ext,ext,1
|
||||
fetch6:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back6
|
||||
andi ext,ext,1
|
||||
fetch7:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back7
|
||||
andi ext,ext,1
|
||||
|
||||
|
||||
raw:
|
||||
li len,3
|
||||
|
||||
x4bits:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch0
|
||||
nop
|
||||
|
||||
|
||||
back0:
|
||||
addu pos,pos,pos
|
||||
addu pos,pos,ext
|
||||
srl ext,pos,16
|
||||
andi ext,ext,1
|
||||
|
||||
sub len,len,1
|
||||
bgez len,x4bits
|
||||
nop
|
||||
addi pos,pos,2
|
||||
|
||||
getrawrep2:
|
||||
lbu temp,0(input)
|
||||
lbu temp2,1(input)
|
||||
sb temp,0(output)
|
||||
sb temp2,1(output)
|
||||
|
||||
lbu temp,2(input)
|
||||
lbu temp2,3(input)
|
||||
sb temp,2(output)
|
||||
sb temp2,3(output)
|
||||
|
||||
|
||||
|
||||
addiu input,input,4
|
||||
sub pos,pos,1
|
||||
|
||||
bgez pos,getrawrep2
|
||||
addi output,output,4
|
||||
|
||||
j xloop
|
||||
nop
|
||||
|
||||
getlen:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch1
|
||||
nop
|
||||
back1:
|
||||
addu len,len,len
|
||||
addu len,len,ext
|
||||
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch2
|
||||
nop
|
||||
|
||||
|
||||
back2:
|
||||
beq r0,ext,copy
|
||||
nop
|
||||
sub len,len,1
|
||||
add bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch3
|
||||
nop
|
||||
|
||||
back3:
|
||||
addu len,len,len
|
||||
addu len,len,ext
|
||||
srl ext,len,16
|
||||
andi ext,ext,1
|
||||
|
||||
sub temp,len,9
|
||||
beq r0,temp,raw
|
||||
nop
|
||||
|
||||
|
||||
copy:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch4
|
||||
nop
|
||||
|
||||
|
||||
back4:
|
||||
beq r0,ext,bytedisp2
|
||||
nop
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch5
|
||||
nop
|
||||
|
||||
back5:
|
||||
addu pos,pos,pos
|
||||
addu pos,pos,ext
|
||||
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch6
|
||||
nop
|
||||
|
||||
back6:
|
||||
bne r0,ext,bigdisp
|
||||
nop
|
||||
bne r0,pos,bytedisp
|
||||
nop
|
||||
addi pos,pos,1
|
||||
|
||||
another:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch7
|
||||
nop
|
||||
|
||||
back7:
|
||||
addu pos,pos,pos
|
||||
addu pos,pos,ext
|
||||
srl ext,pos,16
|
||||
andi ext,ext,1
|
||||
|
||||
bytedisp:
|
||||
sll temp,pos,8
|
||||
andi temp,temp,0xff00
|
||||
srl pos,pos,8
|
||||
or pos,pos,temp
|
||||
|
||||
|
||||
bytedisp2:
|
||||
andi postop,pos,0xff00
|
||||
|
||||
lbu pos,0(input)
|
||||
|
||||
addiu input,input,1
|
||||
or pos,pos,postop
|
||||
move xa0,output
|
||||
sub xa0,xa0,pos
|
||||
sub xa0,xa0,1
|
||||
andi ext,len,1
|
||||
srl len,len,1
|
||||
beq r0,ext,bytedisp3
|
||||
nop
|
||||
|
||||
lbu temp,0(xa0)
|
||||
addi xa0,xa0,1
|
||||
sb temp,0(output)
|
||||
addi output,output,1
|
||||
|
||||
|
||||
bytedisp3:
|
||||
sub len,len,1
|
||||
bne r0,pos,bytedisp5
|
||||
nop
|
||||
|
||||
andi postop,pos,0xff00
|
||||
lbu pos,0(xa0)
|
||||
nop
|
||||
or pos,pos,postop
|
||||
bytedisp4:
|
||||
sb pos,0(output)
|
||||
sub len,len,1
|
||||
sb pos,1(output)
|
||||
|
||||
bgez len,bytedisp4
|
||||
addi output,output,2
|
||||
|
||||
j xloop
|
||||
nop
|
||||
bytedisp5:
|
||||
lbu temp2,1(xa0)
|
||||
lbu temp,0(xa0)
|
||||
sb temp2,1(output)
|
||||
sb temp,0(output)
|
||||
|
||||
addi xa0,xa0,2
|
||||
|
||||
sub len,len,1
|
||||
bgez len,bytedisp5
|
||||
addi output,output,2
|
||||
|
||||
j xloop
|
||||
nop
|
||||
|
||||
|
||||
getbits:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
bne r0,ext,string
|
||||
nop
|
||||
|
||||
xbyte:
|
||||
lbu temp,0(input)
|
||||
addi input,input,1
|
||||
sb temp,0(output)
|
||||
addi output,output,1
|
||||
|
||||
|
||||
xloop:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
bne r0,ext,chkz
|
||||
nop
|
||||
|
||||
lbu temp,0(input)
|
||||
addi input,input,1
|
||||
sb temp,0(output)
|
||||
addi output,output,1
|
||||
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
beq r0,ext,xbyte
|
||||
nop
|
||||
chkz:
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,getbits
|
||||
nop
|
||||
|
||||
|
||||
string:
|
||||
li len,2
|
||||
li pos,0
|
||||
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch8
|
||||
nop
|
||||
|
||||
|
||||
back8:
|
||||
beq r0,ext,getlen
|
||||
nop
|
||||
|
||||
smalls:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch9
|
||||
nop
|
||||
|
||||
back9:
|
||||
|
||||
beq r0,ext,bytedisp2
|
||||
nop
|
||||
addi len,len,1
|
||||
add bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch10
|
||||
nop
|
||||
|
||||
back10:
|
||||
beq r0,ext,copy
|
||||
nop
|
||||
|
||||
lbu len,0(input)
|
||||
addi input,input,1
|
||||
nop
|
||||
beq r0,len,overnout
|
||||
addi len,len,8
|
||||
j copy
|
||||
nop
|
||||
|
||||
bigdisp:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch11
|
||||
nop
|
||||
|
||||
back11:
|
||||
addu pos,pos,pos
|
||||
addu pos,pos,ext
|
||||
srl ext,pos,16
|
||||
andi ext,ext,1
|
||||
ori pos,pos,4
|
||||
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
|
||||
andi bitbuf,bitbuf,0xff
|
||||
beq r0,bitbuf,fetch12
|
||||
nop
|
||||
|
||||
back12:
|
||||
bne r0,ext,bytedisp
|
||||
nop
|
||||
j another
|
||||
nop
|
||||
|
||||
fetch8:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back8
|
||||
andi ext,ext,1
|
||||
fetch9:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back9
|
||||
andi ext,ext,1
|
||||
fetch10:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back10
|
||||
andi ext,ext,1
|
||||
fetch11:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back11
|
||||
andi ext,ext,1
|
||||
fetch12:
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
j back12
|
||||
andi ext,ext,1
|
||||
|
||||
overnout:
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
andi bitbuf,bitbuf,0xff
|
||||
bne r0,bitbuf,check4end
|
||||
nop
|
||||
|
||||
lbu bitbuf,0(input)
|
||||
addi input,input,1
|
||||
addu bitbuf,bitbuf,bitbuf
|
||||
addu bitbuf,bitbuf,ext
|
||||
srl ext,bitbuf,8
|
||||
andi ext,ext,1
|
||||
|
||||
check4end:
|
||||
bne r0,ext,xloop
|
||||
nop
|
||||
|
||||
lhu xd0,0(xsp)
|
||||
addi xsp,xsp,2
|
||||
beq r0,xd0,unpack9
|
||||
nop
|
||||
|
||||
unpack8:
|
||||
lh xd1,0(xsp)
|
||||
addi xsp,xsp,2
|
||||
sb xd1,0(output)
|
||||
addi output,output,1
|
||||
sub xd0,xd0,1
|
||||
bne r0,xd0,unpack8
|
||||
nop
|
||||
|
||||
unpack9:
|
||||
j unpack11
|
||||
nop
|
||||
unpack10:
|
||||
sw xd1,0(xsp)
|
||||
|
||||
unpack11:
|
||||
li retval,0
|
||||
jr ra
|
||||
nop
|
||||
|
||||
.data
|
||||
.align 4
|
||||
|
||||
.word 0,0,0,0,0,0,0,0,0,0,0,0
|
||||
mystack:
|
||||
.word 0
|
||||
|
||||
.end
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef SLIDEC_H
|
||||
#define SLIDEC_H
|
||||
|
||||
void slidstart(unsigned char*, unsigned char *);
|
||||
|
||||
void decompress(void *mio0, void *dest);
|
||||
|
||||
#endif // SLIDEC_H
|
||||
@@ -0,0 +1,61 @@
|
||||
/******************************
|
||||
* Data Decompress Ver1.10 *
|
||||
* Programmed By Melody-Yoshi *
|
||||
******************************/
|
||||
/* How to use this function.
|
||||
void slidstart(unsigned char *,unsigned char *);
|
||||
first argument is top address of compress data.(align 4)
|
||||
next argument is top address of decompress.
|
||||
*/
|
||||
# assembler directives
|
||||
.set noat # allow manual use of $at
|
||||
.set gp=64
|
||||
.include "macros.inc"
|
||||
|
||||
.align 4
|
||||
|
||||
.text
|
||||
glabel slidstart
|
||||
|
||||
/* ===== START! ===== */
|
||||
slidstart: lw $24,4($4) ## R24=Output size
|
||||
lw $7,8($4)
|
||||
lw $25,12($4)
|
||||
move $6,$0 ## flags=0
|
||||
add $24,$5
|
||||
add $7,$4
|
||||
add $25,$4
|
||||
add $4,16
|
||||
/* ===== MAIN LOOP ===== */
|
||||
slidemain2: bne $6,$0,codecheck2
|
||||
lw $8,($4)
|
||||
li $6,32
|
||||
add $4,4
|
||||
codecheck2: slt $9,$8,$0 ## Check MSB
|
||||
beq $9,$0,pressdata2
|
||||
lb $10,($25)
|
||||
add $25,1
|
||||
sb $10,($5)
|
||||
add $5,1
|
||||
b loopend2
|
||||
pressdata2: lhu $10,($7)
|
||||
add $7,2
|
||||
srl $11,$10,12
|
||||
and $10,0xfff
|
||||
sub $9,$5,$10 ## R9=DIST
|
||||
beq $11,$0,pressloop3
|
||||
add $11,2
|
||||
pressloop2: lb $10,-1($9)
|
||||
sub $11,1
|
||||
add $9,1
|
||||
sb $10,($5)
|
||||
add $5,1
|
||||
bne $11,$0,pressloop2
|
||||
loopend2: sll $8,1
|
||||
sub $6,1
|
||||
bne $5,$24,slidemain2
|
||||
jr $31
|
||||
pressloop3: lbu $11,($25)
|
||||
add $25,1
|
||||
add $11,18
|
||||
b pressloop2
|
||||
Reference in new issue
Block a user