uint8 DreamGenContext::printslow(const uint8 *string, uint16 x, uint16 y, uint8 maxWidth, bool centered) { data.byte(kPointerframe) = 1; data.byte(kPointermode) = 3; const Frame* charSet = (const Frame *)segRef(data.word(kCharset1)).ptr(0, 0); do { uint16 offset = x; uint16 charCount = getnumber(charSet, string, maxWidth, centered, &offset); do { uint8 c0 = string[0]; uint8 c1 = string[1]; uint8 c2 = string[2]; c0 = engine->modifyChar(c0); printboth(charSet, &offset, y, c0, c1); if ((c1 == 0) || (c1 == ':')) { return 0; } if (charCount != 1) { c1 = engine->modifyChar(c1); data.word(kCharshift) = 91; uint16 offset2 = offset; printboth(charSet, &offset2, y, c1, c2); data.word(kCharshift) = 0; for (int i=0; i<2; ++i) { uint16 mouseState = waitframes(); if (mouseState == 0) continue; if (mouseState != data.word(kOldbutton)) { return 1; } } } ++string; --charCount; } while (charCount); y += 10; } while (true); }
void enumerate_device(void) { static BYTE HR,iCONFIG,iMFG,iPROD,iSERIAL; static WORD TotalLen,ix; static BYTE len,type,adr,pktsize; // SETUP bytes for the requests we'll send to the device static BYTE Set_Address_to_7[8] = {0x00,0x05,0x07,0x00,0x00,0x00,0x00,0x00}; static BYTE Get_Descriptor_Device[8] = {0x80,0x06,0x00,0x01,0x00,0x00,0x00,0x00}; // code fills in length field static BYTE Get_Descriptor_Config[8] = {0x80,0x06,0x00,0x02,0x00,0x00,0x00,0x00}; static BYTE str[8] = {0x80,0x06,0x00,0x03,0x00,0x00,0x40,0x00}; // Get_Descriptor-String template. Code fills in idx at str[2]. // Issue a USB bus reset printf("\r\nIssuing USB bus reset"); Hwreg(rHCTL,bmBUSRST); // initiate the 50 msec bus reset while(Hrreg(rHCTL) & bmBUSRST); // Wait for the bus reset to complete // Wait some frames before programming any transfers. This allows the device to recover from // the bus reset. waitframes(200); // Get the device descriptor. maxPacketSize = 8; // only safe value until we find out Hwreg(rPERADDR,0); // First request goes to address 0 Get_Descriptor_Device[6]=8; // wLengthL Get_Descriptor_Device[7]=0; // wLengthH printf("\r\nFirst 8 bytes of Device Descriptor "); HR = CTL_Read(Get_Descriptor_Device); // Get device descriptor into XfrData[] if(print_error(HR)) return; // print_error() does nothing if HRSL=0, returns the 4-bit HRSL. printf("\r\n(%u/%u NAKS)",IN_nak_count,HS_nak_count); // Show NAK count for data stage/status stage maxPacketSize = XfrData[7]; for (ix=0; ix<last_transfer_size;ix++) //printf("%02X ",(BYTE*)XfrData[ix]); printf("\r\nEP0 maxPacketSize is %02u bytes",maxPacketSize); // Issue another USB bus reset printf("\r\nIssuing USB bus reset"); Hwreg(rHCTL,bmBUSRST); // initiate the 50 msec bus reset while(Hrreg(rHCTL) & bmBUSRST); // Wait for the bus reset to complete waitframes(200); // Set_Address to 7 (Note: this request goes to address 0, already set in PERADDR register). printf("\r\nSetting address to 0x07"); HR = CTL_Write_ND(Set_Address_to_7); // CTL-Write, no data stage if(print_error(HR)) return; waitframes(30); // Device gets 2 msec recovery time Hwreg(rPERADDR,7); // now all transfers go to addr 7 // Get the device descriptor at the assigned address. Get_Descriptor_Device[6]=0x12; // fill in the real device descriptor length printf("\nDevice Descriptor "); HR = CTL_Read(Get_Descriptor_Device); // Get device descriptor into XfrData[] if(print_error(HR)) return; printf("\r\n(%u/%u NAKS)\n",IN_nak_count,HS_nak_count); printf ("-----------------\n"); VID = XfrData[8] + 256*XfrData[9]; PID = XfrData[10]+ 256*XfrData[11]; iMFG = XfrData[14]; iPROD = XfrData[15]; iSERIAL = XfrData[16]; for (ix=0; ix<last_transfer_size;ix++) //printf("%02X ",(BYTE*)XfrData[ix]); printf("\n"); printf("\r\nThis device has %u configuration\n",XfrData[17]); printf("\r\nVendor ID is 0x%04X\n",VID); printf("\r\nProduct ID is 0x%04X\n",PID); // str[2]=0; // index 0 is language ID string str[4]=0; // lang ID is 0 str[5]=0; str[6]=4; // wLengthL str[7]=0; // wLengthH HR = CTL_Read(str); // Get lang ID string if (!HR) // Check for ACK (could be a STALL if the device has no strings) { printf("\r\nLanguage ID String Descriptor is "); for (ix=0; ix<last_transfer_size;ix++) //printf("%02X ",(BYTE*)XfrData[ix]); str[4]=XfrData[2]; // LangID-L str[5]=XfrData[3]; // LangID-H str[6]=255; // now request a really big string } if(iMFG) { str[2]=iMFG; // fill in the string index from the device descriptor HR = CTL_Read(str); // Get Manufacturer ID string printf("\r\nManuf. string is \""); for (ix=2; ix<last_transfer_size;ix+=2) //printf("%c",(BYTE*)XfrData[ix]); printf("\"\n"); } else printf("\r\nThere is no Manuf. string\n"); if(iPROD) { str[2]=iPROD; HR = CTL_Read(str); // Get Product ID string printf("\r\nProduct string is \""); for (ix=2; ix<last_transfer_size;ix+=2) //printf("%c",(BYTE*)XfrData[ix]); printf("\"\n"); } else printf("\r\nThere is no Product string\n"); if(iSERIAL) { str[2]=iSERIAL; HR = CTL_Read(str); // Get Serial Number ID string printf("\r\nS/N string is \""); for (ix=2; ix<last_transfer_size;ix+=2) //printf("%c",(BYTE*)XfrData[ix]); printf("\"\n"); } else printf("There is no Serial Number"); // Get the 9-byte configuration descriptor printf("\n\nConfiguration Descriptor "); Get_Descriptor_Config[6]=9; // fill in the wLengthL field Get_Descriptor_Config[7]=0; // fill in the wLengthH field HR = CTL_Read(Get_Descriptor_Config); // Get config descriptor into XfrData[] if(print_error(HR)) return; printf("\r\n(%u/%u NAKS)\n",IN_nak_count,HS_nak_count); printf ("------------------------\n"); for (ix=0; ix<last_transfer_size;ix++) //printf("%02X ",(BYTE*)XfrData[ix]); // Now that the full length of all descriptors (Config, Interface, Endpoint, maybe Class) // is known we can fill in the correct length and ask for the full boat. Get_Descriptor_Config[6]=XfrData[2]; // LengthL Get_Descriptor_Config[7]=XfrData[3]; // LengthH HR = CTL_Read(Get_Descriptor_Config); // Get config descriptor into XfrData[] printf("\r\nFull Configuration Data"); for (ix=0; ix<last_transfer_size;ix++) { if((ix&0x0F)==0) printf("\n"); // CR every 16 numbers //printf("%02X ",(BYTE*)XfrData[ix]); } iCONFIG = XfrData[6]; // optional configuration string printf("\r\nConfiguration %01X has %01X interface",XfrData[5],XfrData[4]); if (XfrData[4]>1) printf("s"); printf("\r\nThis device is "); if(XfrData[7] & 0x40) printf("self-powered\n"); else printf("bus powered and uses %03u milliamps\n",XfrData[8]*2); // // Parse the config+ data for interfaces and endpoints. Skip over everything but // interface and endpoint descriptors. // TotalLen=last_transfer_size; ix=0; do { len=XfrData[ix]; // length of first descriptor (the CONFIG descriptor) type=XfrData[ix+1]; adr=XfrData[ix+2]; pktsize=XfrData[ix+4]; if(type==0x04) // Interface descriptor? printf("\r\nInterface %u, Alternate Setting %u has:\n",XfrData[ix+2],XfrData[ix+3]); else if(type==0x05) // check for endpoint descriptor type { printf("\r\n--Endpoint %u",(adr&0x0F)); if (XfrData[ix+2]&0x80) printf("-IN "); else printf("-OUT "); printf("\r\n(%02u) is type ",(BYTE)pktsize); switch(XfrData[ix+3]&0x03) { case 0x00: printf("\r\nCONTROL\n"); break; case 0x01: printf("\r\nISOCHRONOUS\n"); break; case 0x02: printf("BULK\n"); break; case 0x03: printf("\r\nINTERRUPT with a polling interval of %u msec.\n",XfrData[ix+6]); } } ix += len; // point to next descriptor } while (ix<TotalLen); // if(iCONFIG) { str[2]=iCONFIG; HR = CTL_Read(str); // Get Config string printf("\r\nConfig string is \""); for (ix=2; ix<last_transfer_size;ix+=2) //printf("%c",(BYTE*)XfrData[ix]); printf("\"\n"); } else printf("\r\nThere is no Config string"); }
void MAX_Process(void){ detect_device(); waitframes(200); // Some devices require this enumerate_device(); }