diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index cd8bd3a2c..d0df04b98 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)cdrom.c 1.0.18 2017/10/15 + * Version: @(#)cdrom.c 1.0.19 2017/10/22 * * Author: Miran Grca, * @@ -845,7 +845,7 @@ void cdrom_init(int id, int cdb_len_setting) cdrom[id].sense[0] = 0xf0; cdrom[id].sense[7] = 10; cdrom_drives[id].bus_mode = 0; - if (cdrom_drives[id].bus_type > CDROM_BUS_ATAPI_PIO_AND_DMA) + if (cdrom_drives[id].bus_type >= CDROM_BUS_ATAPI_PIO_AND_DMA) { cdrom_drives[id].bus_mode |= 2; } @@ -890,6 +890,7 @@ int cdrom_current_mode(int id) } if (cdrom_supports_pio(id) && !cdrom_supports_dma(id)) { + cdrom_log("CD-ROM %i: Drive does not support DMA, setting to PIO\n", id); return 1; } if (!cdrom_supports_pio(id) && cdrom_supports_dma(id)) @@ -898,6 +899,7 @@ int cdrom_current_mode(int id) } if (cdrom_supports_pio(id) && cdrom_supports_dma(id)) { + cdrom_log("CD-ROM %i: Drive supports both, setting to %s\n", id, (cdrom[id].features & 1) ? "DMA" : "PIO", id); return (cdrom[id].features & 1) ? 2 : 1; } @@ -1366,6 +1368,8 @@ uint32_t cdrom_mode_sense(uint8_t id, uint8_t *buf, uint32_t pos, uint8_t type, void cdrom_update_request_length(uint8_t id, int len, int block_len) { + uint32_t bt; + /* For media access commands, make sure the requested DRQ length matches the block length. */ switch (cdrom[id].current_cdb[0]) { @@ -1378,17 +1382,11 @@ void cdrom_update_request_length(uint8_t id, int len, int block_len) { cdrom[id].request_length = block_len; } - /* Make sure we respect the limit of how many blocks we can transfer at once. */ - if (cdrom[id].requested_blocks > cdrom_drives[id].max_blocks_at_once) + bt = (cdrom[id].requested_blocks * block_len); + if (len > bt) { - cdrom[id].requested_blocks = cdrom_drives[id].max_blocks_at_once; + len = bt; } - cdrom[id].block_total = (cdrom[id].requested_blocks * block_len); - if (len > cdrom[id].block_total) - { - len = cdrom[id].block_total; - } - break; default: cdrom[id].packet_len = len; break; @@ -1406,21 +1404,6 @@ void cdrom_update_request_length(uint8_t id, int len, int block_len) return; } -static int cdrom_is_media_access(uint8_t id) -{ - switch (cdrom[id].current_cdb[0]) - { - case 0x08: - case 0x28: - case 0xa8: - case 0xb9: - case 0xbe: - return 1; - default: - return 0; - } -} - static void cdrom_command_common(uint8_t id) { cdrom[id].status = BUSY_STAT; @@ -1489,6 +1472,11 @@ static int cdrom_request_length_is_zero(uint8_t id) return 0; } +/* id = Current CD-ROM device ID; + len = Total transfer length; + block_len = Length of a single block (why does it matter?!); + alloc_len = Allocated transfer length; + direction = Transfer direction (0 = read from host, 1 = write to host). */ static void cdrom_data_command_finish(uint8_t id, int len, int block_len, int alloc_len, int direction) { cdrom_log("CD-ROM %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", id, cdrom[id].current_cdb[0], len, block_len, alloc_len, direction, cdrom[id].request_length); @@ -2547,15 +2535,9 @@ cdrom_readtoc_fallback: } max_len = cdrom[id].sector_len; - /* if (cdrom_drives[id].bus_type == CDROM_BUS_SCSI) */ - if (cdrom_current_mode(id) == 2) - { - cdrom[id].requested_blocks = max_len; - } - else - { - cdrom[id].requested_blocks = 1; - } + cdrom[id].requested_blocks = max_len; /* If we're reading all blocks in one go for DMA, why not also for PIO, it should NOT + matter anyway, this step should be identical and only the way the read dat is + transferred to the host should be different. */ cdrom[id].packet_len = max_len * alloc_length; cdrom_buf_alloc(id, cdrom[id].packet_len); @@ -2566,27 +2548,13 @@ cdrom_readtoc_fallback: return; } - if (cdrom_current_mode(id) == 2) - { - cdrom[id].requested_blocks = max_len; - cdrom[id].packet_len = alloc_length; - } - else - { - cdrom[id].requested_blocks = 1; - cdrom[id].packet_len = max_len * alloc_length; - } + cdrom[id].requested_blocks = max_len; + cdrom[id].packet_len = alloc_length; cdrom_set_buf_len(id, BufLen, &cdrom[id].packet_len); - if (cdrom[id].requested_blocks > 1) - { - cdrom_data_command_finish(id, alloc_length, alloc_length / cdrom[id].requested_blocks, alloc_length, 0); - } - else - { - cdrom_data_command_finish(id, alloc_length, alloc_length, alloc_length, 0); - } + cdrom_data_command_finish(id, alloc_length, alloc_length / cdrom[id].requested_blocks, alloc_length, 0); + cdrom[id].all_blocks_total = cdrom[id].block_total; if (cdrom[id].packet_status != CDROM_PHASE_COMPLETE) { @@ -3434,63 +3402,6 @@ atapi_out: /* cdrom_log("CD-ROM %i: Phase: %02X, request length: %i\n", cdrom[id].phase, cdrom[id].request_length); */ } -/* This is for block reads. */ -int cdrom_block_check(uint8_t id) -{ - uint32_t alloc_length = 0; - int ret = 0; - - /* If this is a media access command, and we hit the end of the block but not the entire length, - read the next block. */ - if (cdrom_is_media_access(id)) - { - /* We have finished the current block. */ - cdrom_log("CD-ROM %i: %i bytes total read, %i bytes all total\n", id, cdrom[id].total_read, cdrom[id].all_blocks_total); - if (cdrom[id].total_read >= cdrom[id].all_blocks_total) - { - cdrom_log("CD-ROM %i: %i bytes read, current block finished\n", id, cdrom[id].total_read); - /* Read the next block. */ - ret = cdrom_read_blocks(id, &alloc_length, 0); - if (ret == -1) - { - /* Return value is -1 - there are no further blocks to read. */ - cdrom_log("CD-ROM %i: %i bytes read, no further blocks to read\n", id, cdrom[id].total_read); - cdrom[id].status = BUSY_STAT; - cdrom_buf_free(id); - return 1; - } - else if (ret == 0) - { - /* Return value is 0 - an error has occurred. */ - cdrom_log("CD-ROM %i: %i bytes read, error while reading blocks\n", id, cdrom[id].total_read); - cdrom[id].status = BUSY_STAT | (cdrom[id].status & ERR_STAT); - cdrom_buf_free(id); - return 0; - } - else - { - /* Return value is 1 - sectors have been read successfully. */ - cdrom[id].pos = 0; - cdrom[id].all_blocks_total += cdrom[id].block_total; - cdrom_log("CD-ROM %i: %i bytes read, next block(s) read successfully, %i bytes are still left\n", id, cdrom[id].total_read, cdrom[id].all_blocks_total - cdrom[id].total_read); - return 1; - } - } - else - { - /* Blocks not exhausted, tell the host to check for buffer length. */ - cdrom_log("CD-ROM %i: Blocks not yet finished\n", id); - return 1; - } - } - else - { - /* Not a media access command, ALWAYS do the callback. */ - cdrom_log("CD-ROM %i: Not a media access command\n", id); - return 1; - } -} - /* This is the general ATAPI callback. */ void cdrom_callback(uint8_t id) /* Callback for non-Read CD commands */ { @@ -3831,7 +3742,6 @@ uint32_t cdrom_read(uint8_t channel, int length) uint8_t id = atapi_cdrom_drives[channel]; uint32_t temp = 0; - int ret = 0; if (id > CDROM_NUM) { @@ -3844,20 +3754,23 @@ uint32_t cdrom_read(uint8_t channel, int length) if (!cdbufferb) return 0; + /* Make sure we return a 0 and don't attempt to read from the buffer if we're transferring bytes beyond it, + which can happen when issuing media access commands with an allocated length below minimum request length + (which is 1 sector = 2048 bytes). */ switch(length) { case 1: - temp = cdbufferb[cdrom[id].pos]; + temp = (cdrom[id].pos < cdrom[id].packet_len) ? cdbufferb[cdrom[id].pos] : 0; cdrom[id].pos++; cdrom[id].request_pos++; break; case 2: - temp = cdbufferw[cdrom[id].pos >> 1]; + temp = (cdrom[id].pos < cdrom[id].packet_len) ? cdbufferw[cdrom[id].pos >> 1] : 0; cdrom[id].pos += 2; cdrom[id].request_pos += 2; break; case 4: - temp = cdbufferl[cdrom[id].pos >> 2]; + temp = (cdrom[id].pos < cdrom[id].packet_len) ? cdbufferl[cdrom[id].pos >> 2] : 0; cdrom[id].pos += 4; cdrom[id].request_pos += 4; break; @@ -3867,26 +3780,12 @@ uint32_t cdrom_read(uint8_t channel, int length) if (cdrom[id].packet_status == CDROM_PHASE_DATA_IN) { - cdrom[id].total_read += length; - ret = cdrom_block_check(id); - /* If the block check has returned 0, this means all the requested blocks have been read, therefore the command has finished. */ - if (ret) + if (cdrom[id].request_pos >= cdrom[id].request_length) { - cdrom_log("CD-ROM %i: Return value is 1 (request length: %i)\n", id, cdrom[id].request_length); - if (cdrom[id].request_pos >= cdrom[id].request_length) - { - /* Time for a DRQ. */ - cdrom_log("CD-ROM %i: Issuing read callback\n", id); - cdrom_callback(id); - } - else - { - cdrom_log("CD-ROM %i: Doing nothing\n", id); - } - } - else - { - cdrom_log("CD-ROM %i: Return value is 0\n", id); + /* Time for a DRQ. */ + cdrom_log("CD-ROM %i: Issuing read callback\n", id); + cdrom[id].total_read += cdrom[id].request_length; + cdrom_callback(id); } cdrom_log("CD-ROM %i: Returning: %02X (buffer position: %i, request position: %i, total: %i)\n", id, temp, cdrom[id].pos, cdrom[id].request_pos, cdrom[id].total_read); return temp; diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index e234da639..2300e67b3 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -10,7 +10,7 @@ * made by Adaptec, Inc. These controllers were designed for * the ISA bus. * - * Version: @(#)scsi_aha154x.c 1.0.31 2017/10/19 + * Version: @(#)scsi_aha154x.c 1.0.32 2017/10/22 * * Authors: Fred N. van Kempen, * Original Buslogic version by SA1988 and Miran Grca. @@ -547,15 +547,15 @@ aha_mca_write(int port, uint8_t val, void *priv) * pos[2]=111xxxxx = 7 * pos[2]=000xxxxx = 0 */ - dev->HostID = (dev->pos_regs[2] >> 5) & 0x07; + dev->HostID = (dev->pos_regs[4] >> 5) & 0x07; /* * SYNC mode is pos[2]=xxxx1xxx. * * SCSI Parity is pos[2]=xxx1xxxx. */ - dev->sync = (dev->pos_regs[2] >> 3) & 1; - dev->parity = (dev->pos_regs[2] >> 4) & 1; + dev->sync = (dev->pos_regs[4] >> 3) & 1; + dev->parity = (dev->pos_regs[4] >> 4) & 1; /* * The PS/2 Model 80 BIOS always enables a card if it finds one, diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index 5df57fdc8..d5a66965e 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -11,7 +11,7 @@ * 1 - BT-545S ISA; * 2 - BT-958D PCI * - * Version: @(#)scsi_buslogic.c 1.0.24 2017/10/16 + * Version: @(#)scsi_buslogic.c 1.0.25 2017/10/22 * * Authors: TheCollector1995, * Miran Grca, @@ -1295,12 +1295,16 @@ buslogic_mca_write(int port, uint8_t val, void *priv) x54x_io_remove(dev, dev->Base); /* Get the new assigned I/O base address. */ - dev->Base = dev->pos_regs[1] << 8; - dev->Base |= ((dev->pos_regs[0] & 0x10) ? 4 : 0); + if (dev->pos_regs[3]) { + dev->Base = dev->pos_regs[3] << 8; + dev->Base |= ((dev->pos_regs[2] & 0x10) ? 4 : 0); + } else { + dev->Base = 0x0000; + } /* Save the new IRQ and DMA channel values. */ - dev->Irq = ((dev->pos_regs[0] >> 1) & 0x07) + 8; - dev->DmaChannel = dev->pos_regs[3] & 0x0f; + dev->Irq = ((dev->pos_regs[2] >> 1) & 0x07) + 8; + dev->DmaChannel = dev->pos_regs[5] & 0x0f; /* Extract the BIOS ROM address info. */ if (dev->pos_regs[0] & 0xe0) switch(dev->pos_regs[0] & 0xe0) { @@ -1347,7 +1351,7 @@ buslogic_mca_write(int port, uint8_t val, void *priv) * pos[2]=111xxxxx = 7 * pos[2]=000xxxxx = 0 */ - dev->HostID = (dev->pos_regs[2] >> 5) & 0x07; + dev->HostID = (dev->pos_regs[4] >> 5) & 0x07; /* * SYNC mode is pos[2]=xxxxxx1x. @@ -1358,14 +1362,14 @@ buslogic_mca_write(int port, uint8_t val, void *priv) */ /* Parity. */ HALR->structured.autoSCSIData.uSCSIConfiguration &= ~2; - HALR->structured.autoSCSIData.uSCSIConfiguration |= (dev->pos_regs[2] & 2); + HALR->structured.autoSCSIData.uSCSIConfiguration |= (dev->pos_regs[4] & 2); /* Sync. */ - HALR->structured.autoSCSIData.u16SynchronousPermittedMask = (dev->pos_regs[2] & 0x10) ? 0xffff : 0x0000; + HALR->structured.autoSCSIData.u16SynchronousPermittedMask = (dev->pos_regs[4] & 0x10) ? 0xffff : 0x0000; /* DOS Disk Space > 1GBytes */ HALR->structured.autoSCSIData.uBIOSConfiguration &= ~4; - HALR->structured.autoSCSIData.uBIOSConfiguration |= (dev->pos_regs[2] & 8) ? 4 : 0; + HALR->structured.autoSCSIData.uBIOSConfiguration |= (dev->pos_regs[4] & 8) ? 4 : 0; /* * The PS/2 Model 80 BIOS always enables a card if it finds one, diff --git a/src/sio_pc87306.c b/src/sio_pc87306.c index 8186514e2..9a6c8a7d4 100644 --- a/src/sio_pc87306.c +++ b/src/sio_pc87306.c @@ -179,7 +179,7 @@ void pc87306_write(uint16_t port, uint8_t val, void *priv) { val = 0x4b; } - if (pc87306_curreg <= 28) valxor = val ^ pc87306_regs[pc87306_curreg]; + valxor = val ^ pc87306_regs[pc87306_curreg]; tries = 0; if ((pc87306_curreg == 0x19) && !(pc87306_regs[0x1B] & 0x40)) { diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index 8a52723aa..d6742e337 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -8,7 +8,7 @@ * * Emulation of the old and new IBM CGA graphics cards. * - * Version: @(#)vid_cga.c 1.0.7 2017/10/18 + * Version: @(#)vid_cga.c 1.0.8 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -411,7 +411,7 @@ void cga_poll(void *p) if (cga->composite) video_blit_memtoscreen(0, cga->firstline - 4, 0, (cga->lastline - cga->firstline) + 8, xsize, (cga->lastline - cga->firstline) + 8); else - video_blit_memtoscreen_8(0, cga->firstline - 4, xsize, (cga->lastline - cga->firstline) + 8); + video_blit_memtoscreen_8(0, cga->firstline - 4, 0, (cga->lastline - cga->firstline) + 8, xsize, (cga->lastline - cga->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_colorplus.c b/src/video/vid_colorplus.c index fb3cdceba..337058c8a 100644 --- a/src/video/vid_colorplus.c +++ b/src/video/vid_colorplus.c @@ -8,7 +8,7 @@ * * Plantronics ColorPlus emulation. * - * Version: @(#)vid_colorplus.c 1.0.3 2017/10/18 + * Version: @(#)vid_colorplus.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -327,7 +327,7 @@ void colorplus_poll(void *p) if (colorplus->cga.composite) video_blit_memtoscreen(0, colorplus->cga.firstline - 4, 0, (colorplus->cga.lastline - colorplus->cga.firstline) + 8, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); else - video_blit_memtoscreen_8(0, colorplus->cga.firstline - 4, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); + video_blit_memtoscreen_8(0, colorplus->cga.firstline - 4, 0, (colorplus->cga.lastline - colorplus->cga.firstline) + 8, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index 9c7098e33..a6524fb09 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -8,7 +8,7 @@ * * MDSI Genius VHR emulation. * - * Version: @(#)vid_genius.c 1.0.3 2017/10/18 + * Version: @(#)vid_genius.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -562,7 +562,7 @@ void genius_poll(void *p) if (video_force_resize_get()) video_force_resize_set(0); } - video_blit_memtoscreen_8(0, 0, xsize, ysize); + video_blit_memtoscreen_8(0, 0, 0, ysize, xsize, ysize); frames++; /* Fixed 728x1008 resolution */ diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index 35da6f4ae..b97399b04 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -8,7 +8,7 @@ * * Hercules emulation. * - * Version: @(#)vid_hercules.c 1.0.4 2017/10/18 + * Version: @(#)vid_hercules.c 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -295,7 +295,7 @@ void hercules_poll(void *p) if (video_force_resize_get()) video_force_resize_set(0); } - video_blit_memtoscreen_8(0, hercules->firstline, xsize, ysize); + video_blit_memtoscreen_8(0, hercules->firstline, 0, ysize, xsize, ysize); frames++; if ((hercules->ctrl & 2) && (hercules->ctrl2 & 1)) { diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 691c6bd07..eb729cd77 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -8,7 +8,7 @@ * * MDA emulation. * - * Version: @(#)vid_mda.c 1.0.4 2017/10/18 + * Version: @(#)vid_mda.c 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -254,7 +254,7 @@ void mda_poll(void *p) if (video_force_resize_get()) video_force_resize_set(0); } - video_blit_memtoscreen_8(0, mda->firstline, xsize, mda->lastline - mda->firstline); + video_blit_memtoscreen_8(0, mda->firstline, 0, ysize, xsize, ysize); frames++; video_res_x = mda->crtc[1]; video_res_y = mda->crtc[6]; diff --git a/src/video/vid_olivetti_m24.c b/src/video/vid_olivetti_m24.c index d5d38df99..6e936c343 100644 --- a/src/video/vid_olivetti_m24.c +++ b/src/video/vid_olivetti_m24.c @@ -8,7 +8,7 @@ * * Olivetti M24 video emulation- essentially double-res CGA. * - * Version: @(#)vid_olivetti_m24.c 1.0.3 2017/10/18 + * Version: @(#)vid_olivetti_m24.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -416,7 +416,7 @@ void m24_poll(void *p) video_force_resize_set(0); } - video_blit_memtoscreen_8(0, m24->firstline - 8, xsize, (m24->lastline - m24->firstline) + 16); + video_blit_memtoscreen_8(0, m24->firstline - 8, 0, (m24->lastline - m24->firstline) + 16, xsize, (m24->lastline - m24->firstline) + 16); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_pc1512.c b/src/video/vid_pc1512.c index 0e8ef21c8..d0ca4ca85 100644 --- a/src/video/vid_pc1512.c +++ b/src/video/vid_pc1512.c @@ -15,7 +15,7 @@ * time as between 12 and 46 cycles. We currently always use * the lower number. * - * Version: @(#)vid_pc1512.c 1.0.3 2017/10/18 + * Version: @(#)vid_pc1512.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -425,7 +425,7 @@ static void pc1512_poll(void *p) video_force_resize_set(0); } - video_blit_memtoscreen_8(0, pc1512->firstline - 4, xsize, (pc1512->lastline - pc1512->firstline) + 8); + video_blit_memtoscreen_8(0, pc1512->firstline - 4, 0, (pc1512->lastline - pc1512->firstline) + 8, xsize, (pc1512->lastline - pc1512->firstline) + 8); video_res_x = xsize - 16; video_res_y = ysize; diff --git a/src/video/vid_pcjr.c b/src/video/vid_pcjr.c index 938202a20..6e810533a 100644 --- a/src/video/vid_pcjr.c +++ b/src/video/vid_pcjr.c @@ -8,7 +8,7 @@ * * Video emulation for IBM PCjr. * - * Version: @(#)vid_pcjr.c 1.0.3 2017/10/18 + * Version: @(#)vid_pcjr.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -518,7 +518,7 @@ void pcjr_poll(void *p) if (pcjr->composite) video_blit_memtoscreen(0, pcjr->firstline-4, 0, (pcjr->lastline - pcjr->firstline) + 8, xsize, (pcjr->lastline - pcjr->firstline) + 8); else - video_blit_memtoscreen_8(0, pcjr->firstline-4, xsize, (pcjr->lastline - pcjr->firstline) + 8); + video_blit_memtoscreen_8(0, pcjr->firstline-4, 0, (pcjr->lastline - pcjr->firstline) + 8, xsize, (pcjr->lastline - pcjr->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_tandy.c b/src/video/vid_tandy.c index e4625836f..6a09822d7 100644 --- a/src/video/vid_tandy.c +++ b/src/video/vid_tandy.c @@ -8,7 +8,7 @@ * * Emulation of the Tandy Model 1000 video. * - * Version: @(#)vid_tandy.c 1.0.2 2017/10/18 + * Version: @(#)vid_tandy.c 1.0.3 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -555,7 +555,7 @@ void tandy_poll(void *p) if (tandy->composite) video_blit_memtoscreen(0, tandy->firstline-4, 0, (tandy->lastline - tandy->firstline) + 8, xsize, (tandy->lastline - tandy->firstline) + 8); else - video_blit_memtoscreen_8(0, tandy->firstline-4, xsize, (tandy->lastline - tandy->firstline) + 8); + video_blit_memtoscreen_8(0, tandy->firstline-4, 0, (tandy->lastline - tandy->firstline) + 8, xsize, (tandy->lastline - tandy->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_tandysl.c b/src/video/vid_tandysl.c index db317e3e0..6ae2ded61 100644 --- a/src/video/vid_tandysl.c +++ b/src/video/vid_tandysl.c @@ -8,7 +8,7 @@ * * Emulation of the Tandy Model 1000/SL video. * - * Version: @(#)vid_tandysl.c 1.0.3 2017/10/18 + * Version: @(#)vid_tandysl.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -621,7 +621,7 @@ static void tandysl_poll(void *p) video_force_resize_set(0); } - video_blit_memtoscreen_8(0, tandy->firstline-4, xsize, (tandy->lastline - tandy->firstline) + 8); + video_blit_memtoscreen_8(0, tandy->firstline-4, 0, (tandy->lastline - tandy->firstline) + 8, xsize, (tandy->lastline - tandy->firstline) + 8); frames++; video_res_x = xsize - 16; diff --git a/src/video/vid_wy700.c b/src/video/vid_wy700.c index 9add7225d..f8887f4e4 100644 --- a/src/video/vid_wy700.c +++ b/src/video/vid_wy700.c @@ -8,7 +8,7 @@ * * Wyse-700 emulation. * - * Version: @(#)vid_wy700.c 1.0.3 2017/10/18 + * Version: @(#)vid_wy700.c 1.0.4 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -871,7 +871,7 @@ void wy700_poll(void *p) if (video_force_resize_get()) video_force_resize_set(0); } - video_blit_memtoscreen_8(0, 0, xsize, ysize); + video_blit_memtoscreen_8(0, 0, 0, ysize, xsize, ysize); frames++; /* Fixed 1280x800 resolution */ diff --git a/src/video/video.c b/src/video/video.c index 4c1dacefd..9a666aba0 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -40,7 +40,7 @@ * W = 3 bus clocks * L = 4 bus clocks * - * Version: @(#)video.c 1.0.4 2017/10/18 + * Version: @(#)video.c 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -179,7 +179,7 @@ PALETTE cgapal_mono[6] = { static struct { - int x, y, y1, y2, w, h, blit8; + int x, y, y1, y2, w, h; int busy; int buffer_in_use; @@ -191,7 +191,6 @@ static struct { static void (*blit_func)(int x, int y, int y1, int y2, int w, int h); -static void (*blit8_func)(int x, int y, int w, int h); static @@ -201,10 +200,7 @@ void blit_thread(void *param) thread_wait_event(blit_data.wake_blit_thread, -1); thread_reset_event(blit_data.wake_blit_thread); - if (blit_data.blit8) - blit8_func(blit_data.x, blit_data.y, blit_data.w, blit_data.h); - else - blit_func(blit_data.x, blit_data.y, blit_data.y1, blit_data.y2, blit_data.w, blit_data.h); + blit_func(blit_data.x, blit_data.y, blit_data.y1, blit_data.y2, blit_data.w, blit_data.h); blit_data.busy = 0; thread_set_event(blit_data.blit_complete); @@ -213,10 +209,9 @@ void blit_thread(void *param) void -video_setblit(void(*blit8)(int,int,int,int),void(*blit)(int,int,int,int,int,int)) +video_setblit(void(*blit)(int,int,int,int,int,int)) { blit_func = blit; - blit8_func = blit8; } @@ -262,27 +257,28 @@ video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) blit_data.y2 = y2; blit_data.w = w; blit_data.h = h; - blit_data.blit8 = 0; thread_set_event(blit_data.wake_blit_thread); } void -video_blit_memtoscreen_8(int x, int y, int w, int h) +video_blit_memtoscreen_8(int x, int y, int y1, int y2, int w, int h) { + int yy, xx; + if (h <= 0) return; - video_wait_for_blit(); + for (yy = 0; yy < h; yy++) + { + if ((y + yy) >= 0 && (y + yy) < buffer->h) + { + for (xx = 0; xx < w; xx++) + *(uint32_t *) &(buffer32->line[y + yy][(x + xx) << 2]) = pal_lookup[buffer->line[y + yy][x + xx]]; + } + } - blit_data.busy = 1; - blit_data.x = x; - blit_data.y = y; - blit_data.w = w; - blit_data.h = h; - blit_data.blit8 = 1; - - thread_set_event(blit_data.wake_blit_thread); + video_blit_memtoscreen(x, y, y1, y2, w, h); } diff --git a/src/video/video.h b/src/video/video.h index 4fff657b4..13fa9bb5c 100644 --- a/src/video/video.h +++ b/src/video/video.h @@ -90,10 +90,9 @@ extern char *video_get_internal_name(int card); extern int video_get_video_from_internal_name(char *s); -extern void video_setblit(void(*blit8)(int,int,int,int), - void(*blit)(int,int,int,int,int,int)); +extern void video_setblit(void(*blit)(int,int,int,int,int,int)); extern void video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -extern void video_blit_memtoscreen_8(int x, int y, int w, int h); +extern void video_blit_memtoscreen_8(int x, int y, int y1, int y2, int w, int h); extern void video_blit_complete(void); extern void video_wait_for_blit(void); extern void video_wait_for_buffer(void); diff --git a/src/win/win_d3d.cc b/src/win/win_d3d.cc index 91f6897cb..964485962 100644 --- a/src/win/win_d3d.cc +++ b/src/win/win_d3d.cc @@ -8,7 +8,7 @@ * * Direct3D 9 rendererer and screenshots taking. * - * Version: @(#)win_d3d.cc 1.0.4 2017/10/13 + * Version: @(#)win_d3d.cc 1.0.5 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -33,7 +33,6 @@ void d3d_init_objects(void); void d3d_close_objects(void); static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -static void blit_memtoscreen_8(int x, int y, int w, int h); static LPDIRECT3D9 d3d = NULL; static LPDIRECT3DDEVICE9 d3ddev = NULL; @@ -101,7 +100,7 @@ int d3d_init(HWND h) d3d_init_objects(); - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return 1; } @@ -327,101 +326,6 @@ static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0); } -static void blit_memtoscreen_8(int x, int y, int w, int h) -{ - VOID* pVoid; - D3DLOCKED_RECT dr; - RECT r; - int yy, xx; - HRESULT hr = D3D_OK; - - if (h == 0) - { - video_blit_complete(); - return; /*Nothing to do*/ - } - - r.top = 0; - r.left = 0; - r.bottom = h; - r.right = 2047; - - hr = d3dTexture->LockRect(0, &dr, &r, 0); - if (hr == D3D_OK) - { - for (yy = 0; yy < h; yy++) - { - uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch)); - if ((y + yy) >= 0 && (y + yy) < buffer->h) - { - for (xx = 0; xx < w; xx++) - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - video_blit_complete(); - - d3dTexture->UnlockRect(0); - } - else - video_blit_complete(); - - d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0;//0.5 / 2048.0; - d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0;//0.5 / 2048.0; - d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0; - d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0; - d3d_verts[0].color = d3d_verts[1].color = d3d_verts[2].color = - d3d_verts[3].color = d3d_verts[4].color = d3d_verts[5].color = - d3d_verts[6].color = d3d_verts[7].color = d3d_verts[8].color = - d3d_verts[9].color = d3d_verts[10].color = d3d_verts[11].color = 0xffffff; - - GetClientRect(d3d_hwnd, &r); - d3d_verts[0].x = d3d_verts[2].x = d3d_verts[3].x = -0.5; - d3d_verts[0].y = d3d_verts[3].y = d3d_verts[4].y = -0.5; - d3d_verts[1].x = d3d_verts[4].x = d3d_verts[5].x = (r.right - r.left) - 0.5; - d3d_verts[1].y = d3d_verts[2].y = d3d_verts[5].y = (r.bottom - r.top) - 0.5; - d3d_verts[6].x = d3d_verts[8].x = d3d_verts[9].x = (r.right - r.left) - 40.5; - d3d_verts[6].y = d3d_verts[9].y = d3d_verts[10].y = 8.5; - d3d_verts[7].x = d3d_verts[10].x = d3d_verts[11].x = (r.right - r.left) - 8.5; - d3d_verts[7].y = d3d_verts[8].y = d3d_verts[11].y = 14.5; - - if (hr == D3D_OK) - hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer - if (hr == D3D_OK) - memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); // copy the vertices to the locked buffer - if (hr == D3D_OK) - hr = v_buffer->Unlock(); // unlock the vertex buffer - - if (hr == D3D_OK) - hr = d3ddev->BeginScene(); - - if (hr == D3D_OK) - { - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, d3dTexture); - - if (hr == D3D_OK) - hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); - - if (hr == D3D_OK) - hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); - - if (hr == D3D_OK) - hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); - - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, NULL); - - if (hr == D3D_OK) - hr = d3ddev->EndScene(); - } - - if (hr == D3D_OK) - hr = d3ddev->Present(NULL, NULL, d3d_hwnd, NULL); - - if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) - PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0); -} - void d3d_take_screenshot(wchar_t *fn) { LPDIRECT3DSURFACE9 d3dSurface = NULL; diff --git a/src/win/win_d3d_fs.cc b/src/win/win_d3d_fs.cc index 7e10b4fc5..dd3b1d958 100644 --- a/src/win/win_d3d_fs.cc +++ b/src/win/win_d3d_fs.cc @@ -8,7 +8,7 @@ * * Direct3D 9 full-screen rendererer. * - * Version: @(#)win_d3d_fs.cc 1.0.6 2017/10/13 + * Version: @(#)win_d3d_fs.cc 1.0.7 2017/10/22 * * Authors: Sarah Walker, * Miran Grca, @@ -36,7 +36,6 @@ extern "C" void d3d_fs_take_screenshot(wchar_t *fn); static void d3d_fs_init_objects(void); static void d3d_fs_close_objects(void); static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -static void blit_memtoscreen_8(int x, int y, int w, int h); static LPDIRECT3D9 d3d = NULL; @@ -130,7 +129,7 @@ int d3d_fs_init(HWND h) d3d_fs_init_objects(); - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return 1; } @@ -416,124 +415,6 @@ static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) PostMessage(hwndMain, WM_RESETD3D, 0, 0); } -static void blit_memtoscreen_8(int x, int y, int w, int h) -{ - HRESULT hr = D3D_OK; - VOID* pVoid; - D3DLOCKED_RECT dr; - RECT window_rect; - int xx, yy; - double l = 0, t = 0, r = 0, b = 0; - - if (!h) - { - video_blit_complete(); - return; /*Nothing to do*/ - } - - if (hr == D3D_OK) - { - RECT lock_rect; - - lock_rect.top = 0; - lock_rect.left = 0; - lock_rect.bottom = 2047; - lock_rect.right = 2047; - - hr = d3dTexture->LockRect(0, &dr, &lock_rect, 0); - if (hr == D3D_OK) - { - for (yy = 0; yy < h; yy++) - { - uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch)); - if ((y + yy) >= 0 && (y + yy) < buffer->h) - { - for (xx = 0; xx < w; xx++) - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - video_blit_complete(); - d3dTexture->UnlockRect(0); - } - else - { - video_blit_complete(); - return; - } - } - else - video_blit_complete(); - - d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0; - d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0; - d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0; - d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0; - d3d_verts[0].color = d3d_verts[1].color = d3d_verts[2].color = - d3d_verts[3].color = d3d_verts[4].color = d3d_verts[5].color = - d3d_verts[6].color = d3d_verts[7].color = d3d_verts[8].color = - d3d_verts[9].color = d3d_verts[10].color = d3d_verts[11].color = 0xffffff; - - GetClientRect(d3d_device_window, &window_rect); - d3d_fs_size(window_rect, &l, &t, &r, &b, w, h); - - d3d_verts[0].x = l; - d3d_verts[0].y = t; - d3d_verts[1].x = r; - d3d_verts[1].y = b; - d3d_verts[2].x = l; - d3d_verts[2].y = b; - d3d_verts[3].x = l; - d3d_verts[3].y = t; - d3d_verts[4].x = r; - d3d_verts[4].y = t; - d3d_verts[5].x = r; - d3d_verts[5].y = b; - d3d_verts[6].x = d3d_verts[8].x = d3d_verts[9].x = r - 40.5; - d3d_verts[6].y = d3d_verts[9].y = d3d_verts[10].y = t + 8.5; - d3d_verts[7].x = d3d_verts[10].x = d3d_verts[11].x = r - 8.5; - d3d_verts[7].y = d3d_verts[8].y = d3d_verts[11].y = t + 14.5; - - if (hr == D3D_OK) - hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); - if (hr == D3D_OK) - memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); - if (hr == D3D_OK) - hr = v_buffer->Unlock(); - - if (hr == D3D_OK) - hr = d3ddev->BeginScene(); - - if (hr == D3D_OK) - { - if (hr == D3D_OK) - d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0, 0); - - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, d3dTexture); - - if (hr == D3D_OK) - hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); - - if (hr == D3D_OK) - hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); - - if (hr == D3D_OK) - hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); - - if (hr == D3D_OK) - hr = d3ddev->SetTexture(0, NULL); - - if (hr == D3D_OK) - hr = d3ddev->EndScene(); - } - - if (hr == D3D_OK) - hr = d3ddev->Present(NULL, NULL, d3d_device_window, NULL); - - if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) - PostMessage(hwndMain, WM_RESETD3D, 0, 0); -} - void d3d_fs_take_screenshot(wchar_t *fn) { diff --git a/src/win/win_ddraw.cc b/src/win/win_ddraw.cc index ce02b4fa4..5b1fdfe5b 100644 --- a/src/win/win_ddraw.cc +++ b/src/win/win_ddraw.cc @@ -236,70 +236,6 @@ blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) } -static void -blit_memtoscreen_8(int x, int y, int w, int h) -{ - RECT r_src; - RECT r_dest; - int xx, yy; - POINT po; - uint32_t *p; - HRESULT hr; - - if (lpdds_back == NULL) { - video_blit_complete(); - return; /*Nothing to do*/ - } - - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - - hr = lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - if (hr == DDERR_SURFACELOST) { - lpdds_back->Restore(); - lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - device_force_redraw(); - } - if (!ddsd.lpSurface) { - video_blit_complete(); - return; - } - - for (yy = 0; yy < h; yy++) { - if ((y + yy) >= 0 && (y + yy) < buffer->h) { - p = (uint32_t *) &(((uint8_t *) ddsd.lpSurface)[yy * ddsd.lPitch]); - for (xx = 0; xx < w; xx++) - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - p = &(((uint32_t *) ddsd.lpSurface)[4 * ddsd.lPitch]); - lpdds_back->Unlock(NULL); - video_blit_complete(); - - po.x = po.y = 0; - ClientToScreen(ddraw_hwnd, &po); - GetClientRect(ddraw_hwnd, &r_dest); - OffsetRect(&r_dest, po.x, po.y); - - r_src.left = 0; - r_src.top = 0; - r_src.right = w; - r_src.bottom = h; - - hr = lpdds_back2->Blt(&r_src, lpdds_back, &r_src, DDBLT_WAIT, NULL); - if (hr == DDERR_SURFACELOST) { - lpdds_back2->Restore(); - lpdds_back2->Blt(&r_src, lpdds_back, &r_src, DDBLT_WAIT, NULL); - } - - hr = lpdds_pri->Blt(&r_dest, lpdds_back2, &r_src, DDBLT_WAIT, NULL); - if (hr == DDERR_SURFACELOST) { - lpdds_pri->Restore(); - hr = lpdds_pri->Blt(&r_dest, lpdds_back2, &r_src, DDBLT_WAIT, NULL); - } -} - - int ddraw_init(HWND h) { @@ -361,7 +297,7 @@ ddraw_init(HWND h) ddraw_hwnd = h; - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return(1); } diff --git a/src/win/win_ddraw_fs.cc b/src/win/win_ddraw_fs.cc index 5604def7b..f2804ee8c 100644 --- a/src/win/win_ddraw_fs.cc +++ b/src/win/win_ddraw_fs.cc @@ -31,7 +31,6 @@ extern void ddraw_common_take_screenshot(wchar_t *fn, IDirectDrawSurface7 *pDDSu static void blit_memtoscreen(int, int, int, int, int, int); -static void blit_memtoscreen_8(int, int, int, int); int ddraw_fs_init(HWND h) @@ -92,7 +91,7 @@ int ddraw_fs_init(HWND h) pclog("DDRAW_INIT complete\n"); ddraw_hwnd = h; - video_setblit(blit_memtoscreen_8, blit_memtoscreen); + video_setblit(blit_memtoscreen); return 1; } @@ -244,77 +243,6 @@ static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) } } -static void blit_memtoscreen_8(int x, int y, int w, int h) -{ - RECT r_src; - RECT r_dest; - RECT window_rect; - int xx, yy; - HRESULT hr; - DDBLTFX ddbltfx; - - if (lpdds_back == NULL) - { - video_blit_complete(); - return; /*Nothing to do*/ - } - - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - - hr = lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - - if (hr == DDERR_SURFACELOST) - { - lpdds_back->Restore(); - lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - device_force_redraw(); - } - if (!ddsd.lpSurface) - { - video_blit_complete(); - return; - } - for (yy = 0; yy < h; yy++) - { - if ((y + yy) >= 0 && (y + yy) < buffer->h) - { - uint32_t *p = (uint32_t *) &(((uint8_t *) ddsd.lpSurface)[yy * ddsd.lPitch]); - for (xx = 0; xx < w; xx++) - { - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; - } - } - } - video_blit_complete(); - lpdds_back->Unlock(NULL); - - window_rect.left = 0; - window_rect.top = 0; - window_rect.right = ddraw_w; - window_rect.bottom = ddraw_h; - ddraw_fs_size(window_rect, &r_dest, w, h); - - r_src.left = 0; - r_src.top = 0; - r_src.right = w; - r_src.bottom = h; - - ddbltfx.dwSize = sizeof(ddbltfx); - ddbltfx.dwFillColor = 0; - - lpdds_back2->Blt(&window_rect, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); - - hr = lpdds_back2->Blt(&r_dest, lpdds_back, &r_src, DDBLT_WAIT, NULL); - if (hr == DDERR_SURFACELOST) - { - lpdds_back2->Restore(); - lpdds_back2->Blt(&r_dest, lpdds_back, &r_src, DDBLT_WAIT, NULL); - } - - lpdds_pri->Flip(NULL, DDFLIP_NOVSYNC); -} - int ddraw_fs_pause(void)