/* * JR-IDE Project * - (c) 2017 Alan Hightower * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "pimount.h" #include "jride.h" #pragma data_seg("_TEXT", "CODE"); #pragma code_seg("_TEXT", "CODE"); volatile uint16_t far *ide_sector; volatile uint8_t far *ide_window; extern void _xfer_in (uint16_t far *dst, uint16_t words); #pragma aux _xfer_in = \ "push ds" \ "lds si, dword ptr ide_sector" \ "cld" \ "rep movsw" \ "pop ds" \ parm [di es] [cx] \ modify [si es di cx]; extern void _xfer_out (uint16_t far *src, uint16_t words); #pragma aux _xfer_out = \ "les di, dword ptr ide_sector" \ "push ds" \ "mov ds, dx" \ "cld" \ "rep movsw" \ "pop ds" \ parm [si dx] [cx] \ modify [si es di cx]; extern uint16_t get_ds (void); #pragma aux get_ds = \ "mov ax,ds" \ value [ax]; /* * Due to issues in the FIFO code atm, partial sector transfers * are not working. So always transfer-in a full sector and * trasfer out of the scratch buffer as needed */ int _redir_pull (uint8_t subcmd) { ide_window[IDE_REG_SEC_COUNT] = 1; ide_window[IDE_REG_FEATURE] = subcmd; ide_window[IDE_REG_COMMAND] = IDE_CMD_REDIRECTOR; while (ide_window[IDE_REG_STATUS] & 0x80); // busy if (ide_window[IDE_REG_STATUS] & 1) // error bit return -1; while (!(ide_window[IDE_REG_STATUS] & 0x08)); _xfer_in (MK_FP(get_ds(), &ctx.scratch), 256); ctx.prev_pull = subcmd; return 0; } int _redir_push (uint8_t subcmd) { ide_window[IDE_REG_SEC_COUNT] = 1; ide_window[IDE_REG_FEATURE] = subcmd; ide_window[IDE_REG_COMMAND] = IDE_CMD_REDIRECTOR; while (ide_window[IDE_REG_STATUS] & 0x80); // busy if (ide_window[IDE_REG_STATUS] & 1) // error bit return -1; while (!(ide_window[IDE_REG_STATUS] & 0x08)); _xfer_out (MK_FP(get_ds(), &ctx.scratch), 256); // On OUT transfers, wait for data to be consumed by Pi while (!(ide_window[IDE_REG_STATUS] & 0x40)); // ready return 0; }