|
|
1.1 root 1: /*
1.1.1.2 root 2: Hatari - bios.c
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
1.1 root 6:
7: Bios Handler (Trap #13)
8:
1.1.1.2 root 9: We intercept and direct some Bios calls to handle input/output to RS-232
10: or the printer etc...
1.1 root 11: */
1.1.1.6 ! root 12: const char Bios_rcsid[] = "Hatari $Id: bios.c,v 1.10 2007/01/16 18:42:59 thothy Exp $";
1.1 root 13:
14: #include "main.h"
1.1.1.2 root 15: #include "configuration.h"
1.1 root 16: #include "floppy.h"
1.1.1.3 root 17: #include "log.h"
1.1 root 18: #include "m68000.h"
19: #include "misc.h"
20: #include "printer.h"
21: #include "rs232.h"
22: #include "stMemory.h"
1.1.1.2 root 23: #include "bios.h"
1.1 root 24:
25:
1.1.1.3 root 26: #define BIOS_DEBUG 0
27:
28:
1.1 root 29: /*-----------------------------------------------------------------------*/
1.1.1.6 ! root 30: /**
! 31: * BIOS Return input device status
! 32: * Call 1
! 33: */
1.1.1.3 root 34: static BOOL Bios_Bconstat(Uint32 Params)
1.1 root 35: {
1.1.1.3 root 36: Uint16 Dev;
1.1 root 37:
1.1.1.3 root 38: Dev = STMemory_ReadWord(Params+SIZE_WORD);
1.1.1.2 root 39:
1.1.1.3 root 40: switch(Dev)
41: {
42: case 0: /* PRT: Centronics */
43: if (ConfigureParams.Printer.bEnablePrinting)
44: {
45: Regs[REG_D0] = 0; /* No characters ready (cannot read from printer) */
46: return TRUE;
47: }
48: else
49: {
50: return FALSE;
51: }
52: break;
53: case 1: /* AUX: RS-232 */
54: if (ConfigureParams.RS232.bEnableRS232)
55: {
56: if (RS232_GetStatus())
57: Regs[REG_D0] = -1; /* Chars waiting */
58: else
59: Regs[REG_D0] = 0;
60: return TRUE;
61: }
62: else
63: {
64: return FALSE;
65: }
66: break;
67: }
1.1 root 68:
1.1.1.3 root 69: return FALSE;
1.1 root 70: }
71:
1.1.1.2 root 72:
1.1 root 73: /*-----------------------------------------------------------------------*/
1.1.1.6 ! root 74: /**
! 75: * BIOS Read character from device
! 76: * Call 2
! 77: */
1.1.1.3 root 78: static BOOL Bios_Bconin(Uint32 Params)
1.1 root 79: {
1.1.1.3 root 80: Uint16 Dev;
81: unsigned char Char;
1.1 root 82:
1.1.1.3 root 83: Dev = STMemory_ReadWord(Params+SIZE_WORD);
1.1.1.2 root 84:
1.1.1.3 root 85: switch(Dev)
86: {
87: case 0: /* PRT: Centronics */
88: if (ConfigureParams.Printer.bEnablePrinting)
89: {
90: Regs[REG_D0] = 0; /* Force NULL character (cannot read from printer) */
91: return TRUE;
92: }
93: else
94: {
95: return FALSE;
96: }
97: break;
98: case 1: /* AUX: RS-232 */
99: if (ConfigureParams.RS232.bEnableRS232)
100: {
101: RS232_ReadBytes(&Char, 1);
102: Regs[REG_D0] = Char;
103: return TRUE;
104: }
105: else
106: {
107: return FALSE;
108: }
109: break;
110: }
1.1 root 111:
1.1.1.3 root 112: return FALSE;
1.1 root 113: }
114:
1.1.1.2 root 115:
1.1 root 116: /*-----------------------------------------------------------------------*/
1.1.1.6 ! root 117: /**
! 118: * BIOS Write character to device
! 119: * Call 3
! 120: */
1.1.1.3 root 121: static BOOL Bios_Bconout(Uint32 Params)
1.1 root 122: {
1.1.1.3 root 123: Uint16 Dev;
124: unsigned char Char;
1.1 root 125:
1.1.1.3 root 126: Dev = STMemory_ReadWord(Params+SIZE_WORD);
127: Char = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD);
1.1.1.2 root 128:
1.1.1.3 root 129: switch(Dev)
130: {
131: case 0: /* PRT: Centronics */
132: if (ConfigureParams.Printer.bEnablePrinting)
133: {
134: Printer_TransferByteTo(Char);
135: return TRUE;
136: }
137: else
138: {
139: return FALSE;
140: }
141: break;
142: case 1: /* AUX: RS-232 */
143: if (ConfigureParams.RS232.bEnableRS232)
144: {
145: RS232_TransferBytesTo(&Char, 1);
146: return TRUE;
147: }
148: else
149: {
150: return FALSE;
151: }
152: break;
153: }
1.1 root 154:
1.1.1.3 root 155: return FALSE;
1.1 root 156: }
157:
1.1.1.2 root 158:
1.1 root 159: /*-----------------------------------------------------------------------*/
1.1.1.6 ! root 160: /**
! 161: * BIOS Read/Write disk sector
! 162: * Call 4
! 163: */
1.1.1.3 root 164: static BOOL Bios_RWabs(Uint32 Params)
1.1 root 165: {
1.1.1.3 root 166: #if BIOS_DEBUG
167: Uint32 pBuffer;
168: Uint16 RWFlag, Number, RecNo, Dev;
169:
170: /* Read details from stack */
171: RWFlag = STMemory_ReadWord(Params+SIZE_WORD);
172: pBuffer = STMemory_ReadLong(Params+SIZE_WORD+SIZE_WORD);
173: Number = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD+SIZE_LONG);
174: RecNo = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD+SIZE_LONG+SIZE_WORD);
175: Dev = STMemory_ReadWord(Params+SIZE_WORD+SIZE_WORD+SIZE_LONG+SIZE_WORD+SIZE_WORD);
1.1 root 176:
1.1.1.3 root 177: Log_Printf(LOG_DEBUG, "RWABS %s,%d,0x%X,%d,%d\n", EmulationDrives[Dev].szFileName,RWFlag, (char *)STRAM_ADDR(pBuffer), RecNo, Number);
1.1 root 178: #endif
179:
1.1.1.3 root 180: return FALSE;
1.1 root 181: }
182:
1.1.1.2 root 183:
1.1 root 184: /*-----------------------------------------------------------------------*/
1.1.1.6 ! root 185: /**
! 186: * BIOS Return output device status
! 187: * Call 8
! 188: */
1.1.1.3 root 189: static BOOL Bios_Bcostat(Uint32 Params)
1.1 root 190: {
1.1.1.3 root 191: Uint16 Dev;
1.1 root 192:
1.1.1.3 root 193: Dev = STMemory_ReadWord(Params+SIZE_WORD);
1.1.1.2 root 194:
1.1.1.3 root 195: switch(Dev)
196: {
197: case 0: /* PRT: Centronics */
198: if (ConfigureParams.Printer.bEnablePrinting)
199: {
200: Regs[REG_D0] = -1; /* Device ready */
201: return TRUE;
202: }
203: else
204: {
205: return FALSE;
206: }
207: break;
208: case 1: /* AUX: RS-232 */
209: if (ConfigureParams.RS232.bEnableRS232)
210: {
211: Regs[REG_D0] = -1; /* Device ready */
212: return TRUE;
213: }
214: else
215: {
216: return FALSE;
217: }
218: break;
219: }
1.1 root 220:
1.1.1.3 root 221: return FALSE;
1.1 root 222: }
223:
224:
225: /*-----------------------------------------------------------------------*/
1.1.1.6 ! root 226: /**
! 227: * Check Bios call and see if we need to re-direct to our own routines
! 228: * Return TRUE if we've handled the exception, else return FALSE to let TOS attempt it
! 229: */
1.1 root 230: BOOL Bios(void)
231: {
1.1.1.3 root 232: Uint32 Params;
233: Uint16 BiosCall;
1.1 root 234:
1.1.1.3 root 235: /* Get call */
236: Params = Regs[REG_A7];
237: BiosCall = STMemory_ReadWord(Params);
238:
239: /* Debug_File("BIOS %d\n",BiosCall); */
240:
241: /* Intercept? */
242: switch(BiosCall)
243: {
244: case 0x1:
245: return Bios_Bconstat(Params);
246: case 0x2:
247: return Bios_Bconin(Params);
248: case 0x3:
249: return Bios_Bconout(Params);
250: case 0x4:
251: return Bios_RWabs(Params);
252: case 0x8:
253: return Bios_Bcostat(Params);
254: default: /* Call as normal! */
255: return FALSE;
256: }
1.1 root 257: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.