//Every block has the following header: // 0 - compressed size includeing header (word) // 2 - CRC-16 (word) // 4 - block type // 6 - uncompressed size (word) // 8 .. (compressed size + 5) - compressed data (byte array) dword CompressTFD (byte *pSrc, dword SourceBufferSize, byte *pDest, word TFDType, word SysID, void *pPercentFinishedCallback) { word OrigSize, CompSize; dword OutBufferSize, NrBlocks = 0, FullSize = SourceBufferSize; byte *FileHeader; //PercentFinishedCallback is called for every block. PercentFinished contains a number between 0 and 100 void (*PercentFinishedCallback) (dword PercentFinished) = pPercentFinishedCallback; //Build the tfd file header FileHeader = pDest; if (pDest) { STORE_WORD (pDest , 0x0008); STORE_WORD (pDest + 4, SysID); STORE_WORD (pDest + 6, 0x0001); pDest += 10; } OutBufferSize = 10; while (SourceBufferSize) { if (PercentFinishedCallback) PercentFinishedCallback ((FullSize - SourceBufferSize) * 100 / FullSize); NrBlocks++; OrigSize = (SourceBufferSize > 0x7ffa) ? 0x7ffa : SourceBufferSize; if (pDest) { CompSize = CompressBlock (pSrc, OrigSize, pDest + 8); //Build the block header STORE_WORD (pDest , CompSize + 6); STORE_WORD (pDest + 4, TFDType); STORE_WORD (pDest + 6, OrigSize); STORE_WORD (pDest + 2, CRC16 (0, pDest + 4, 4 + CompSize)); pDest += CompSize + 8; } else CompSize = CompressBlock (pSrc, OrigSize, NULL); OutBufferSize += CompSize + 8; SourceBufferSize -= OrigSize; pSrc += OrigSize; } if (FileHeader) { STORE_WORD (FileHeader + 8, NrBlocks); STORE_WORD (FileHeader + 2, CRC16 (0, FileHeader + 4, 6)); } if (PercentFinishedCallback) PercentFinishedCallback (100); return OutBufferSize; }
/* ColdReset: * Simule un dé/rebranchement du TO7-70. */ void to7_ColdReset(void) { /* initialisation du PIA 6846 système */ mc6846_Init(&mc6846, 0, 0x81, 0x7D); SetNoCapsLed(0); /* initialisation du PIA 6821 système */ mc6821_Init(&pia_int.porta, 0, 0xFF); /* les bits 3-7 sont à 1 en entrée */ mc6821_Init(&pia_int.portb, 0, 0xFC); /* initialisation du PIA 6821 musique et jeux */ mc6821_Init(&pia_ext.porta, 0xC0, 0xFF); mc6821_Init(&pia_ext.portb, 0xC0, 0xCF); /* initialisation des pages mémoire */ mempager.cart.page = 0; mempager.cart.update(); mempager.screen.page = 1; mempager.screen.update(); mempager.system.page = 1; mempager.system.update(); mempager.data.page = 2; mempager.data.update(); mempager.mon.page = 0; mempager.mon.update(); /* initialisation du logic gate array */ memset(&lga, 0, sizeof(struct GATE_ARRAY)); /* initialisation du contrôleur de disquettes */ memset(&disk_ctrl, 0, sizeof(struct DISK_CTRL)); /* checksum application */ STORE_BYTE(0x60D1, 0); /* flag de reset à froid */ STORE_WORD(0x60FE, 0); mc6809_Reset(); }
void process_instructions(void) { if(njumps <= ++ilevel) { jumps = realloc(jumps, ++njumps * sizeof *jumps); if(jumps == NULL) die("unable to allocate memory for jump buffer"); } switch(setjmp(jumps[ilevel])) { case 1: /* Normal break from interrupt. */ return; case 2: /* Special break: a restart was requested. */ { /* §6.1.3: Flags2 is preserved on a restart. */ uint16_t flags2 = WORD(0x10); process_story(); STORE_WORD(0x10, flags2); } break; } while(1) { uint8_t opcode; #if defined(ZTERP_GLK) && defined(ZTERP_GLK_TICK) glk_tick(); #endif ZPC(pc); opcode = BYTE(pc++); /* long 2OP */ if(opcode < 0x80) { znargs = 2; if(opcode & 0x40) zargs[0] = variable(BYTE(pc++)); else zargs[0] = BYTE(pc++); if(opcode & 0x20) zargs[1] = variable(BYTE(pc++)); else zargs[1] = BYTE(pc++); op_call(TWO, opcode & 0x1f); } /* short 1OP */ else if(opcode < 0xb0) { znargs = 1; if(opcode < 0x90) /* large constant */ { zargs[0] = WORD(pc); pc += 2; } else if(opcode < 0xa0) /* small constant */ { zargs[0] = BYTE(pc++); } else /* variable */ { zargs[0] = variable(BYTE(pc++)); } op_call(ONE, opcode & 0x0f); } /* short 0OP (plus EXT) */ else if(opcode < 0xc0) { znargs = 0; op_call(ZERO, opcode & 0x0f); } /* variable 2OP */ else if(opcode < 0xe0) { znargs = 0; decode_var(BYTE(pc++)); op_call(TWO, opcode & 0x1f); } /* Double variable VAR */ else if(opcode == 0xec || opcode == 0xfa) { uint8_t types1, types2; znargs = 0; types1 = BYTE(pc++); types2 = BYTE(pc++); decode_var(types1); decode_var(types2); op_call(VAR, opcode & 0x1f); } /* variable VAR */ else { znargs = 0; read_pc = pc - 1; decode_var(BYTE(pc++)); op_call(VAR, opcode & 0x1f); } } }
/* * the 32 attribute flags parent sibling child properties * ---32 bits in 4 bytes--- ---3 bytes------------------ ---2 bytes-- * * the 48 attribute flags parent sibling child properties * ---48 bits in 6 bytes--- ---3 words, i.e. 6 bytes---- ---2 bytes-- */ static void SET_OBJECT(uint16_t obj1, uint16_t obj2, int offset) { if(zversion <= 3) STORE_BYTE(OBJECT(obj1) + offset, obj2); else STORE_WORD(OBJECT(obj1) + offset, obj2); }