|
|
1.1 ! root 1: /* ! 2: Hatari ! 3: ! 4: Bios Handler (Trap #13) ! 5: ! 6: We intercept and direct some Bios calls to handle input/output to RS-232 or the printer etc... ! 7: */ ! 8: ! 9: #include "main.h" ! 10: #include "debug.h" ! 11: #include "decode.h" ! 12: #include "floppy.h" ! 13: #include "m68000.h" ! 14: #include "misc.h" ! 15: #include "printer.h" ! 16: #include "rs232.h" ! 17: #include "stMemory.h" ! 18: ! 19: ! 20: /*-----------------------------------------------------------------------*/ ! 21: /* ! 22: BIOS Return input device status ! 23: Call 1 ! 24: */ ! 25: BOOL Bios_Bconstat(unsigned long Params) ! 26: { ! 27: unsigned short Dev; ! 28: ! 29: Dev = STMemory_ReadWord(Params+SIZE_WORD); ! 30: switch(Dev) { ! 31: case 0: /* PRT: Centronics */ ! 32: Regs[REG_D0] = 0; /* No characters ready(cannot read from printer) */ ! 33: return(TRUE); ! 34: case 1: /* AUX: RS-232 */ ! 35: if (RS232_GetStatus()) ! 36: Regs[REG_D0] = -1; /* Chars waiting */ ! 37: else ! 38: Regs[REG_D0] = 0; ! 39: return(TRUE); ! 40: } ! 41: ! 42: return(FALSE); ! 43: } ! 44: ! 45: /*-----------------------------------------------------------------------*/ ! 46: /* ! 47: BIOS Read character from device ! 48: Call 2 ! 49: */ ! 50: BOOL Bios_Bconin(unsigned long Params) ! 51: { ! 52: unsigned short Dev; ! 53: unsigned char Char; ! 54: ! 55: Dev = STMemory_ReadWord(Params+SIZE_WORD); ! 56: switch(Dev) { ! 57: case 0: /* PRT: Centronics */ ! 58: Regs[REG_D0] = 0; /* Force NULL character(cannot read from printer) */ ! 59: return(TRUE); ! 60: case 1: /* AUX: RS-232 */ ! 61: RS232_ReadBytes(&Char,1); ! 62: Regs[REG_D0] = Char; ! 63: return(TRUE); ! 64: } ! 65: ! 66: return(FALSE); ! 67: } ! 68: ! 69: /*-----------------------------------------------------------------------*/ ! 70: /* ! 71: BIOS Write character to device ! 72: Call 3 ! 73: */ ! 74: BOOL Bios_Bconout(unsigned long Params) ! 75: { ! 76: unsigned short Dev; ! 77: unsigned char Char; ! 78: ! 79: Dev = STMemory_ReadWord(Params+SIZE_WORD); ! 80: Char = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD); ! 81: switch(Dev) { ! 82: case 0: /* PRT: Centronics */ ! 83: Printer_TransferByteTo(Char); ! 84: return(TRUE); ! 85: case 1: /* AUX: RS-232 */ ! 86: RS232_TransferBytesTo(&Char,1); ! 87: return(TRUE); ! 88: } ! 89: ! 90: return(FALSE); ! 91: } ! 92: ! 93: /*-----------------------------------------------------------------------*/ ! 94: /* ! 95: BIOS Read/Write disc sector ! 96: Call 4 ! 97: */ ! 98: BOOL Bios_RWabs(unsigned long Params) ! 99: { ! 100: #ifdef DEBUG_TO_FILE ! 101: char *pBuffer; ! 102: unsigned short int RWFlag,Number,RecNo,Dev; ! 103: ! 104: /* Read details from stack */ ! 105: RWFlag = STMemory_ReadWord(Params+SIZE_WORD); ! 106: pBuffer = (char *)STMemory_ReadLong(Params+SIZE_WORD+SIZE_WORD); ! 107: Number = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD+SIZE_LONG); ! 108: RecNo = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD+SIZE_LONG+SIZE_WORD); ! 109: Dev = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD+SIZE_LONG+SIZE_WORD+SIZE_WORD); ! 110: ! 111: Debug_FDC("RWABS %s,%d,0x%X,%d,%d\n",EmulationDrives[Dev].szFileName,RWFlag,(char *)STRAM_ADDR(pBuffer),RecNo,Number); ! 112: #endif ! 113: ! 114: return(FALSE); ! 115: } ! 116: ! 117: /*-----------------------------------------------------------------------*/ ! 118: /* ! 119: BIOS Return output device status ! 120: Call 8 ! 121: */ ! 122: BOOL Bios_Bcostat(unsigned long Params) ! 123: { ! 124: unsigned short Dev; ! 125: ! 126: Dev = STMemory_ReadWord(Params+SIZE_WORD); ! 127: switch(Dev) { ! 128: case 0: /* PRT: Centronics */ ! 129: Regs[REG_D0] = -1; /* Device ready */ ! 130: return(TRUE); ! 131: case 1: /* AUX: RS-232 */ ! 132: Regs[REG_D0] = -1; /* Device ready */ ! 133: return(TRUE); ! 134: } ! 135: ! 136: return(FALSE); ! 137: } ! 138: ! 139: /*-----------------------------------------------------------------------*/ ! 140: /* ! 141: BIOS Media change ! 142: Call 9 ! 143: */ ! 144: BOOL Bios_Mediach(unsigned long Params) ! 145: { ! 146: unsigned short int Dev,ImageChanged=0; ! 147: ! 148: /* Read details from stack */ ! 149: Dev = STMemory_ReadWord(Params+SIZE_WORD); ! 150: ! 151: /* Check we are trying to access a floppy drive? */ ! 152: if (Dev<2) { ! 153: /* Have we inserted a new disc image into this drive? */ ! 154: if (EmulationDrives[Dev].bMediaChanged) { ! 155: EmulationDrives[Dev].bMediaChanged = FALSE; ! 156: ImageChanged = 2; /* We did change disc image */ ! 157: } ! 158: } ! 159: ! 160: /* Set 0 if was not changed or 2 if was */ ! 161: Regs[REG_D0] = ImageChanged; ! 162: ! 163: return(TRUE); ! 164: } ! 165: ! 166: /*-----------------------------------------------------------------------*/ ! 167: /* ! 168: Check Bios call and see if we need to re-direct to our own routines ! 169: Return TRUE if we've handled the exception, else return FALSE to let TOS attempt it ! 170: */ ! 171: BOOL Bios(void) ! 172: { ! 173: unsigned long Params; ! 174: unsigned short int BiosCall; ! 175: ! 176: /* Get call */ ! 177: Params = Regs[REG_A7]; ! 178: BiosCall = STMemory_ReadWord(Params); ! 179: // Debug_File("BIOS %d\n",BiosCall); ! 180: ! 181: /* Intercept? */ ! 182: switch(BiosCall) { ! 183: case 0x1: ! 184: return(Bios_Bconstat(Params)); ! 185: case 0x2: ! 186: return(Bios_Bconin(Params)); ! 187: case 0x3: ! 188: return(Bios_Bconout(Params)); ! 189: case 0x4: ! 190: return(Bios_RWabs(Params)); ! 191: case 0x8: ! 192: return(Bios_Bcostat(Params)); ! 193: case 0x9: ! 194: return(Bios_Mediach(Params)); ! 195: ! 196: default: /* Call as normal! */ ! 197: return(FALSE); ! 198: } ! 199: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.