Files
TempleOS-Rijn/LT/OSMain/OSEnd.CPZ
T
2018-09-08 21:45:20 +02:00

391 lines
9.4 KiB
Plaintext

void InitSysGlbls()
{
sys_timer=0;
sys_jiffies=0;
rnd_SEED = 93186752;
time_stamp_freq=2676302000; //give reasonable value
time_stamp_kHz_freq=time_stamp_freq/1000;
sys_cur_focus_task=Fs;
sys_update_screen_tss=NULL;
MemSet(sema_irqs,0,NUM_IRQ_SEMAS*sizeof(sema));
MemSet(sema_irq_busy,0,NUM_IRQ_SEMAS*sizeof(sema));
num_spawned_users=0;
compiled_lines=0;
compiled_functions=0;
ext[EXT_IRQ00]=&SimpleTimerIrq;
StrCpy(sys_temp_filename,"HOME/Temp.TXZ");
sys_macro_queue.next=&sys_macro_queue;
sys_macro_queue.last=&sys_macro_queue;
mouse_evt_time=0;
kbd_evt_time=0;
kbdmouse_fifo=NewU1Fifo(128);
MemSet(&sys_put_key_queue,0,sizeof(KeyDevStruct));
sys_put_key_queue.next=&sys_put_key_queue;
sys_put_key_queue.last=&sys_put_key_queue;
AddKeyDev(&InputFilterPutKey,&InputFilterPutS,0x40000000);
AddKeyDev(&RawCrtPutKey,&RawCrtPutS,0x60000000);
macro_util_tss=NULL;
ip_inhibit_win_operations=FALSE;
local_time_offset=0;
ltcd_base=NULL;
ltdc_hash_table=NULL;
sysdbg0=0; sysdbg1=0;
sysdbg2=0; sysdbg3=0;
progress1=0; progress2=0;
progress3=0; progress4=0;
default_iso_name="::/Temp/CDDVD.ISO";
#exe {
I1 *buf;
LTDate ltdt;
buf=PmtStr("Start-up Accnt(ENTER will prompt):","");
ExePrintF("sys_startup_account=\"%s\";\r\n",buf);
Free(buf);
ltdt=GetCurTimeLTDate;
ExePrintF("sys_compile_time=0x%X;\r\n",ltdt);
buf=PmtStr("Disk Cache Size, gets rounded-up funny, (ENTER will use default of %s Bytes):","0x8000000");
ExePrintF("LTDCInitCache(%s);",buf);
Free(buf);
}
}
void AddModuleHash(I1 *name,U8 base)
{
SysHashEntry *temph;
temph=MAllocZ(sizeof(SysHashEntry));
temph->type=HTT_MODULE|HTT_PUBLIC;
temph->use_cnt=0;
temph->user_data0=base;
temph->source_link=NULL;
temph->str=NewStr(name);
AddSysHashEntry(temph,Fs->hash_table);
}
void AddOsMapSymbols()
{
SysHashEntry *temph;
I1 *sptr;
U1 *ptr;
U4 *dd;
U8 type;
I8 i,code;
code=sys_boot_base;
AddModuleHash("/LT/OSMain/OS",code);
ptr=sys_boot_header_base;
while ((type=*ptr++)!=EIE_END) { //PASS 1
dd=ptr;
ptr+=4;
i=*dd;
sptr=ptr;
ptr+=StrLen(sptr)+1;
if (type<=EIE_LIT_EXPORT) {
temph=MAllocZ(sizeof(SysHashEntry));
temph->type=HTT_SYS_SYMBOL;
temph->use_cnt=0;
temph->user_data0=i+code;
temph->source_link=NULL;
temph->str=NewStr(sptr);
AddSysHashEntry(temph,Fs->hash_table);
} else if (type<EIE_MAIN) {
} else if (type==EIE_MAIN) {
} else if (type==EIE_ABSOLUTE_ADDRESS) {
ptr+=i*sizeof(U4);
}
}
}
U1 *Load(I1 *filename,BoolU4 no_abs=FALSE)
{
I1 *fbuf;
U1 *code,*ptr,etype,*bb;
I1 *sptr,*absname;
U2 *ww;
U4 *dd;
U8 *qq,size,cnt;
BinFileHeaderStruct *bfh;
I8 i,j,n;
SysHashEntry *temph,*saved_hash_ptr=NULL;
ClassStruct *tempc;
GlblVarStruct *tempg;
fbuf=DefaultExtension(filename,"BIZ");
if (!(bfh=ReadFile(fbuf,&size))) {
Free(fbuf);
return NULL;
}
code=bfh+sizeof(BinFileHeaderStruct);
if (ArcCheckSum(bfh,bfh->file_size)!=LT_XSUM)
throw(EXCEPT_ARC_XSUM);
absname=AbsoluteFileName(fbuf);
Free(fbuf);
fbuf=NewStr(absname);
RemoveLastSeg(fbuf,".");
if (fbuf[1]==':' && StrLen(fbuf)>2)
AddModuleHash(fbuf+2,code);
Free(fbuf);
ptr=bfh+bfh->header_offset;
while ((etype=*ptr++)!=EIE_END) { //PASS 1
dd=ptr;
ptr+=sizeof(U4);
i=*dd;
sptr=ptr;
ptr+=StrLen(sptr)+1;
if (etype<=EIE_LIT_EXPORT) {
temph=MAllocZ(sizeof(SysHashEntry));
temph->str=NewStr(sptr);
temph->type=HTT_SYS_SYMBOL;
temph->use_cnt=0;
n=StrLen(absname);
temph->source_link=MAlloc(n+4);
StrCpy(temph->source_link,"FI:");
StrCat(temph->source_link,absname);
if (etype==EIE_LIT_EXPORT)
temph->user_data0=i;
else
temph->user_data0=i+code;
AddSysHashEntry(temph,Fs->hash_table);
} else if (etype<EIE_MAIN) {
if (*sptr)
saved_hash_ptr=FindLocalHash(sptr,HTT_ALL);
if (!saved_hash_ptr)
coutln SysText("ST_UNRESOLVED_REFERENCE"),sptr;
else {
bb=code+i;
ww=code+i;
dd=code+i;
qq=code+i;
if (saved_hash_ptr->type & HTT_FUNCTION) {
tempc=saved_hash_ptr;
if (etype & 1)
i=tempc->executable_address;
else
i=tempc->executable_address-code;
} else if (saved_hash_ptr->type & HTT_GLBL_VAR) {
tempg=saved_hash_ptr;
if (etype & 1)
i=tempg->data_address;
else
i=tempg->data_address-code;
} else {
if (etype & 1)
i=saved_hash_ptr->user_data0;
else
i=saved_hash_ptr->user_data0-code;
}
if (etype<=EIE_LIT_U1)
*bb=i+*bb;
else if (etype<=EIE_LIT_U2)
*ww=i+*ww;
else if (etype<=EIE_LIT_U4)
*dd=i+*dd;
else if (etype<=EIE_LIT_U8)
*qq=i+*qq;
}
} else if (etype==EIE_ABSOLUTE_ADDRESS) {
if (no_abs)
ptr+=i*sizeof(U4);
else {
cnt=i;
for (j=0;j<cnt;j++) {
dd=ptr;
ptr+=sizeof(U4);
dd=code+*dd;
*dd+=code;
}
}
}
}
ptr=bfh+bfh->header_offset;
while ((etype=*ptr++)!=EIE_END) { //PASS 2
dd=ptr;
ptr+=sizeof(U4);
i=*dd;
sptr=ptr;
ptr+=StrLen(sptr)+1;
if (etype<=EIE_LIT_EXPORT) {
} else if (etype<EIE_MAIN) {
} else if (etype==EIE_MAIN) {
Call(i+code);
} else if (etype==EIE_ABSOLUTE_ADDRESS) {
ptr+=sizeof(U4)*i;
}
}
Free(absname);
return bfh;
}
void InitTimer()
{
OutP(0x43,0x34);
OutP(0x40,SYS_TIMER0_PERIOD);
OutP(0x40,SYS_TIMER0_PERIOD>>8);
}
void InitIrqs()
{ //Init 8259
OutP(0x20,0x11); //IW1
OutP(0xA0,0x11); //IW1
PortNop;
OutP(0x21,0x20); //IW2
OutP(0xA1,0x28); //IW2
PortNop;
OutP(0x21,0x04); //IW3
OutP(0xA1,0x02); //IW3
PortNop;
OutP(0x21,0x0D); //IW4
OutP(0xA1,0x09); //IW4
PortNop;
OutP(0x21,0x24); //Mask
OutP(0xA1,0x37);
PortNop;
}
GrBitMap *GrBitMapNew(U8 type,U8 width,U8 height,TssStruct *tss=NULL)
{ //This only allows widths which are divisible by 8
GrBitMap *result;
if (!tss) tss=Fs;
result=MAllocZ(sizeof(GrBitMap),tss);
result->win_tss=tss;
result->mem_tss=tss;
result->type=type;
result->width=width;
result->internal_width=(width+7)&~7;
result->height=height;
result->left_margin=0;
result->right_margin=width;
result->top_margin=0;
result->bottom_margin=height;
switch (type) {
case BMT_COLOR4:
result->plane_size=(result->internal_width*result->height)>>3;
result->body=MAllocZ(result->plane_size<<2,tss);
break;
case BMT_MONO:
result->plane_size=(result->internal_width*result->height)>>3;
result->body=MAllocZ(result->plane_size,tss);
break;
default:
throw(EXCEPT_GRAPHICS,1);
}
result->pen_width=1;
result->r=MAllocZ(16<<3,tss);
result->r[0].u4[1]=1;
result->r[5].u4[1]=1;
result->r[10].u4[1]=1;
result->r[15].u4[1]=1;
result->speedline_scale=0.04;
result->bitmap_signature=BMS_SIGNATURE;
return result;
}
void InitGraphics()
{
dc_col=0;
dc_flags=0;
dc_cursor_blink=0;
grfont=sys_font_8x8;
//TODO free old allocated stuff
grbase2=GrBitMapNew(BMT_COLOR4,GR_WIDTH+128,GR_HEIGHT+32);
grbase2->left_margin=64;
grbase2->right_margin=GR_WIDTH+grbase2->left_margin;
grbase2->top_margin=16;
grbase2->bottom_margin=grbase2->height-16;
grbase2->flags|=BMF_SCREEN_BITMAP;
vga_image=MAlloc(GR_WIDTH*GR_HEIGHT>>1);
textbase=MAlloc(GR_WIDTH/FONT_WIDTH*(GR_HEIGHT/FONT_HEIGHT)<<2);
Gs->grbase=GrBitMapNew(BMT_COLOR4,GR_WIDTH,GR_HEIGHT);
Gs->grbase->flags|=BMF_SCREEN_BITMAP;
GrClear2(Gs->grbase);
gr_merge_base=GrBitMapNew(BMT_COLOR4,GR_WIDTH,GR_HEIGHT);
gr_merge_base->flags|=BMF_SCREEN_BITMAP;
OutP(VGA_SC_INDEX,VGA_MAP_MASK);
OutP(VGA_SC_DATA,0x0F);
MemSet(0xA0000,0,GR_HEIGHT*GR_WIDTH>>3);
}
asm {CP_REBOOT:}
void Reboot()
{
U2 *d=0x472;
Cli;
if (mp_cnt>1) {
MPHalt;
BusyWait(100);
}
*d=0;
OutP(0x70,0x8F);
OutP(0x71,0x00);
OutP(0x70,0x00);
OutP(0x92,InP(0x92)|1);
Hlt;
}
asm {CP_OS_MAIN:}
void OsMain()
{
U8 i,j;
adam_tss=Fs;
StrCpy(Fs->task_descriptor2,"Adam Task CPU#0");
StrCpy(Fs->task_descriptor,Fs->task_descriptor2);
reverse_bits_table=MAllocZ(256);
for (i=0;i<256;i++)
for (j=0;j<8;j++)
if (Bt(&i,7-j))
Bts(reverse_bits_table+i,j);
set_bits_table=MAllocZ(256);
for (i=0;i<256;i++)
for (j=0;j<8;j++)
if (Bt(&i,j))
set_bits_table[i]++;
ext=MAllocZ(EXT_TABLE_SIZE*sizeof(void *));
ctrl_alt_letter_routines=MAllocZ(26*sizeof(void *));
InitGraphics();
InitSysTask;
AddOsMapSymbols;
InitSysGlbls;
//Before this point use $LK,"Sound","MN:Sound"$() and $LK,"BusyWait","MN:BusyWait"$()
//to debug. After this point, use $LK,"DbgNum","MN:DbgNum"$()
LoadSysStrs;
MPInit;
InitTimer;
InitIrqs;
coutln "Enable IRQ's";
SetFlags(SYS_NORMAL_RFLAGS);
Preempt(ON);
time_stamp_start=GetTimeStamp;
sys_timer_start=ReadSysTimer;
coutln "InitAllBlkDevs";
InitAllBlkDevs;
coutln "Select Default Drive";
SelectDefaultDrive;
cout "Loading Compiler...";
Cd("/LT/Compiler");
Load("Compiler");
coutln "Done";
CallExtStr("AdamStartUpFile");
//Continues here $LK,"AdamStartUpFile","FF:::/LT/Compiler/CmpMain.CPZ,AdamStartUpFile"$
ContinueServantTask; //Never to return
}
asm { ALIGN 16,0x90
SYS_CS_SIZE::}