int8 hio_read8s(HIO_HANDLE *h) { if (HIO_HANDLE_TYPE(h) == HIO_HANDLE_TYPE_FILE) { return read8s(h->f); } else { if (CAN_READ(h) >= 1) return *(int8 *)(h->start + h->pos++); else return EOF; } }
int8 hio_read8s(HIO_HANDLE *h) { switch (HIO_HANDLE_TYPE(h)) { case HIO_HANDLE_TYPE_FILE: return read8s(h->handle.file); case HIO_HANDLE_TYPE_MEMORY: return mread8s(h->handle.mem); default: return 0; } }
static int gtk_load(struct module_data *m, FILE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int i, j, k; uint8 buffer[40]; int rows, bits, c2spd, size; int ver, patmax; LOAD_INIT(); fread(buffer, 4, 1, f); ver = buffer[3]; fread(mod->name, 32, 1, f); set_type(m, "Graoumf Tracker GTK v%d", ver); fseek(f, 160, SEEK_CUR); /* skip comments */ mod->ins = read16b(f); mod->smp = mod->ins; rows = read16b(f); mod->chn = read16b(f); mod->len = read16b(f); mod->rst = read16b(f); MODULE_INFO(); D_(D_INFO "Instruments : %d ", mod->ins); INSTRUMENT_INIT(); for (i = 0; i < mod->ins; i++) { mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); fread(buffer, 28, 1, f); copy_adjust(mod->xxi[i].name, buffer, 28); if (ver == 1) { read32b(f); mod->xxs[i].len = read32b(f); mod->xxs[i].lps = read32b(f); size = read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; read16b(f); read16b(f); mod->xxi[i].sub[0].vol = 0x40; mod->xxi[i].sub[0].pan = 0x80; bits = 1; c2spd = 8363; } else { fseek(f, 14, SEEK_CUR); read16b(f); /* autobal */ bits = read16b(f); /* 1 = 8 bits, 2 = 16 bits */ c2spd = read16b(f); c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxs[i].len = read32b(f); mod->xxs[i].lps = read32b(f); size = read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; mod->xxi[i].sub[0].vol = read16b(f) / 4; read8(f); mod->xxi[i].sub[0].fin = read8s(f); } mod->xxi[i].nsm = !!mod->xxs[i].len; mod->xxi[i].sub[0].sid = i; mod->xxs[i].flg = size > 2 ? XMP_SAMPLE_LOOP : 0; if (bits > 1) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } D_(D_INFO "[%2X] %-28.28s %05x%c%05x %05x %c " "V%02x F%+03d %5d", i, mod->xxi[i].name, mod->xxs[i].len, bits > 1 ? '+' : ' ', mod->xxs[i].lps, size, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, mod->xxi[i].sub[0].fin, c2spd); }
static int med3_load(struct xmp_context *ctx, FILE *f, const int start) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i, j; uint32 mask; int transp, sliding; LOAD_INIT(); read32b(f); strcpy(m->type, "MED3 (MED 2.00)"); m->xxh->ins = m->xxh->smp = 32; INSTRUMENT_INIT(); /* read instrument names */ for (i = 0; i < 32; i++) { uint8 c, buf[40]; for (j = 0; j < 40; j++) { c = read8(f); buf[j] = c; if (c == 0) break; } copy_adjust(m->xxih[i].name, buf, 32); m->xxi[i] = calloc(sizeof(struct xxm_instrument), 1); } /* read instrument volumes */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { m->xxi[i][0].vol = mask & MASK ? read8(f) : 0; m->xxi[i][0].pan = 0x80; m->xxi[i][0].fin = 0; m->xxi[i][0].sid = i; } /* read instrument loops */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { m->xxs[i].lps = mask & MASK ? read16b(f) : 0; } /* read instrument loop length */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { uint32 lsiz = mask & MASK ? read16b(f) : 0; m->xxs[i].len = m->xxs[i].lps + lsiz; m->xxs[i].lpe = m->xxs[i].lps + lsiz; m->xxs[i].flg = lsiz > 1 ? WAVE_LOOPING : 0; } m->xxh->chn = 4; m->xxh->pat = read16b(f); m->xxh->trk = m->xxh->chn * m->xxh->pat; m->xxh->len = read16b(f); fread(m->xxo, 1, m->xxh->len, f); m->xxh->tpo = read16b(f); if (m->xxh->tpo > 10) { m->xxh->bpm = 125 * m->xxh->tpo / 33; m->xxh->tpo = 6; } transp = read8s(f); read8(f); /* flags */ sliding = read16b(f); /* sliding */ read32b(f); /* jumping mask */ fseek(f, 16, SEEK_CUR); /* rgb */ /* read midi channels */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (mask & MASK) read8(f); } /* read midi programs */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (mask & MASK) read8(f); } MODULE_INFO(); reportv(ctx, 0, "Sliding : %d\n", sliding); reportv(ctx, 0, "Play transpose : %d semitones\n", transp); if (sliding == 6) m->quirk |= XMP_QRK_VSALL | XMP_QRK_PBALL; for (i = 0; i < 32; i++) m->xxi[i][0].xpo = transp; PATTERN_INIT(); /* Load and convert patterns */ reportv(ctx, 0, "Stored patterns: %d ", m->xxh->pat); for (i = 0; i < m->xxh->pat; i++) { uint32 *conv; uint8 b, tracks; uint16 convsz; PATTERN_ALLOC(i); m->xxp[i]->rows = 64; TRACK_ALLOC(i); tracks = read8(f); b = read8(f); convsz = read16b(f); conv = calloc(1, convsz + 16); assert(conv); if (b & M0F_LINEMSK00) *conv = 0L; else if (b & M0F_LINEMSK0F) *conv = 0xffffffff; else *conv = read32b(f); if (b & M0F_LINEMSK10) *(conv + 1) = 0L; else if (b & M0F_LINEMSK1F) *(conv + 1) = 0xffffffff; else *(conv + 1) = read32b(f); if (b & M0F_FXMSK00) *(conv + 2) = 0L; else if (b & M0F_FXMSK0F) *(conv + 2) = 0xffffffff; else *(conv + 2) = read32b(f); if (b & M0F_FXMSK10) *(conv + 3) = 0L; else if (b & M0F_FXMSK1F) *(conv + 3) = 0xffffffff; else *(conv + 3) = read32b(f); fread(conv + 4, 1, convsz, f); unpack_block(ctx, i, (uint8 *)conv); free(conv); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); /* Load samples */ reportv(ctx, 0, "Instruments : %d ", m->xxh->ins); reportv(ctx, 1, "\n Instrument name Len LBeg LEnd L Vol"); mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (~mask & MASK) continue; m->xxs[i].len = read32b(f); if (read16b(f)) /* type */ continue; m->xxih[i].nsm = !!(m->xxs[i].len); reportv(ctx, 1, "\n[%2X] %-32.32s %04x %04x %04x %c V%02x ", i, m->xxih[i].name, m->xxs[i].len, m->xxs[i].lps, m->xxs[i].lpe, m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ', m->xxi[i][0].vol); xmp_drv_loadpatch(ctx, f, m->xxi[i][0].sid, m->c4rate, 0, &m->xxs[m->xxi[i][0].sid], NULL); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); return 0; }
void draw_tile(gb_short control) { gb_long tileMem = 0; gb_long bgMem = 0; gb_short scrollY = read8(SCROLLY); gb_short scrollX = read8(SCROLLX); gb_short windowY = read8(WINDOWY); gb_short windowX = read8(WINDOWX) - 7; int usingWindow = 0; // boolean - whether or not the window is in use int unsig = 1; // boolean - whether or not tile set data is signed or unsigned if(control & WIN_DISP_ENABLE) { // Check if current window is within LCD Y position if(windowY <= read8(LCDY)) { usingWindow = 1; // printf("usingWindow!\n"); } } // Choose Tile Data to Use if(control & WIN_BG_TILEDATA) { tileMem = TILE_SET_1U; } else { tileMem = TILE_SET_1S; unsig = 0; } // printf("tileMem = %x\n", tileMem); if(!usingWindow) { // Choose Background Tile Set To Use bgMem = (control & BG_TILE_MAP_SEL) ? (TILE_SET_BG_1) : (TILE_SET_BG_0); } else { // Choose Window Tile Set To Use bgMem = (control & WIN_TILE_SELECT) ? (TILE_SET_BG_1) : (TILE_SET_BG_0); } // printf("bgMem = %x\n", bgMem); // Which of the 32 vertical tiles is the current scanline is drawing gb_short yPos = usingWindow ? (read8(LCDY) - windowY) : (scrollY + read8(LCDY)); // Choose which of the 8 vertical pixels of the current tile the scanline is on gb_long tileRow = (((gb_short)(yPos/8))*32); // Draw horizontal pixels for this scanline gb_short xPos; for(int px = 0; px < 160; px++) { xPos = px+scrollX; if(usingWindow && (px >= windowX)) xPos = px - windowX; gb_long tileCol = (xPos/8); gb_long_s tileNum; // Get the signed or unsigned tile identity number gb_long tileAddr = bgMem+tileRow+tileCol; if(unsig) { tileNum = read8(tileAddr); } else { tileNum = read8s(tileAddr); } // Find the tile in memory gb_long tileLoc = tileMem; if(unsig) tileLoc += (tileNum * 16); else tileLoc += ((tileNum+128)*16); // Find data from the correct vertical line of the current tile gb_short line = yPos % 8; line *= 2; // each vertical line takes up two bytes of memory gb_short data1 = read8(tileLoc + line); gb_short data2 = read8(tileLoc + line + 1); // Pixel 0 in the tile is bit 7 of data1 and data2 int cBit = xPos % 8; cBit -= 7; cBit *= -1; // Combine data1 and data2 to get color id for this pixel int cNum; cNum = (!!(data2 & (1 << cBit)) << 1) | (!!(data1 & (1 << cBit))); // Double check this is being done correctly // Get actual color from background color palette // color c = get_color(cNum, (gb_long)BGPAL); color c; switch(cNum) { case 0: c = WHITE; break; case 1: c = LGRAY; break; case 2: c = DGRAY; break; case 3: c = BLACK; break; default: c = LGRAY; } // if(goodloop) printf("cnum=%d\n",cNum); int finalY = read8(LCDY); // Check To Be Within Bounds if ((finalY<0) || (finalY>143) || (px<0) || (px>159)) { continue; } else { } gl_draw_pixel(px, finalY, c); // printf("drawing tile pixel x=%d, finalY=%d, c =%x\n", px, finalY, c); } }