ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/TECH
Revision: 1.1
Committed: 1999-10-03T14:16:25Z (24 years, 7 months ago) by cebix
Branch: MAIN
Branch point for: cebix
Log Message:
Initial revision

File Contents

# Content
1 BASILISK II TECHNICAL MANUAL
2 ============================
3
4 0. Table of Contents
5 --------------------
6
7 1. Introduction
8 2. Modes of operation
9 3. Memory access
10 4. Calling native routines from 68k mode and vice-versa
11 5. Interrupts
12 6. Parts of Basilisk II
13 7. Porting Basilisk II
14
15 1. Introduction
16 ---------------
17
18 Basilisk II can emulate two kind of Macs, depending on the ROM being used:
19
20 1. A Mac Classic
21 2. A Mac II series computer ("Mac II series" here means all 68020/30/40
22 based Macs with 32-bit clean ROMs (this excludes the original Mac II,
23 the IIx/IIcx and the SE/030), except PowerBooks; in the following,
24 "Mac II" is used as an abbreviation of "Mac II series computer", as
25 defined above)
26
27 More precisely spoken, MacOS under Basilisk II behaves like on a Mac Classic
28 or Mac II because, apart from the CPU, the RAM and the ROM, absolutely no Mac
29 hardware is emulated. Rather, Basilisk II provides replacements (usually in
30 the form of MacOS drivers) for the parts of MacOS that access hardware. As
31 there are practically no Mac applications that access hardware directly (this
32 is also due to the fact that the hardware of different Mac models is sometimes
33 as different as, say, the hardware of an Atari ST and an Amiga 500), both the
34 compatibility and speed of this approach are very high.
35
36 2. Modes of operation
37 ---------------------
38
39 Basilisk II is designed to run on many different hardware platforms and on
40 many different operating systems. To provide optimal performance under all
41 environments, it can run in three different modes, depending on the features
42 of the underlying environment (the modes are selected with the REAL_ADDRESSING
43 and EMULATED_68K defines in "sysdeps.h"):
44
45 1. Emulated CPU, "virtual" addressing (EMULATED_68K = 1, REAL_ADDRESSING = 0):
46 This mode is designed for non-68k or little-endian systems or systems that
47 don't allow accessing RAM at 0x0000..0x1fff. This is also the only mode that
48 allows 24-bit addressing, and thus the only mode that allows Mac Classic
49 emulation. The 68k processor is emulated with the UAE CPU engine and two
50 memory areas are allocated for Mac RAM and ROM. The memory map seen by the
51 emulated CPU and the host CPU are different. Mac RAM starts at address 0
52 for the emulated 68k, but it may start at a different address for the host
53 CPU. All memory accesses of the CPU emulation go through memory access
54 functions (do_get_mem_long() etc.) that translate addresses. This slows
55 down the emulator, of course.
56
57 2. Emulated CPU, "real" addressing (EMULATED_68K = 1, REAL_ADDRESSING = 0):
58 This mode is intended for big-endian non-68k systems that do allow access to
59 RAM at 0x0000..0x1fff. As in the virtual addressing mode, the 68k processor
60 is emulated with the UAE CPU engine and two areas are set up for RAM and ROM
61 but the emulated CPU lives in the same address space as the host CPU.
62 This means that if something is located at a certain address for the 68k,
63 it is located at the exact same address for the host CPU. Mac addresses
64 and host addresses are the same. The memory accesses of the CPU emulation
65 still go through access functions but the address translation is no longer
66 needed, and if the host CPU uses big-endian data layout and can handle
67 unaligned accesses like the 68k, the memory access functions are replaced
68 by direct, inlined memory accesses, making for the fastest possible speed
69 of the emulator.
70 A usual consequence of the real addressing mode is that the Mac RAM doesn't
71 any longer begin at address 0 for the Mac and that the Mac ROM also is not
72 located where it usually is on a real Mac. But as the Mac ROM is relocatable
73 and the available RAM is defined for MacOS by the start of the system zone
74 (which is relocated to the start of the allocated RAM area) and the MemTop
75 variable (which is also set correctly) this is not a problem. There is,
76 however, one RAM area that must lie in a certain address range. This area
77 contains the Mac "Low Memory Globals" which (on a Mac II) are located at
78 0x0000..0x1fff and which cannot be moved to a different address range.
79 The Low Memory Globals constitute of many important MacOS and application
80 global variables (e.g. the above mentioned "MemTop" variable which is
81 located at 0x0108). For the real addressing mode to work, the host CPU
82 needs access to 0x0000..0x1fff. Under most operating systems, this is a
83 big problem. On some systems, patches (like PrepareEmul on the Amiga or
84 the sheep_driver under BeOS) can be installed to "open up" this area. On
85 other systems, it might be possible to use access exception handlers to
86 emulate accesses to this area. But if the Low Memory Globals area cannot
87 be made available, using the real addressing mode is not possible.
88
89 3. Native CPU (EMULATED_68K = 0, this also requires REAL_ADDRESSING = 1)
90 This mode is designed for systems that use a 68k (68020 or better) processor
91 as host CPU and is the technically most difficult mode to handle. The Mac
92 CPU is no longer emulated (the UAE CPU emulation is not needed) but MacOS
93 and Mac applications run natively on the existing 68k CPU. This means that
94 the emulator has its maximum possible speed (very close to that of a real
95 Mac with the same CPU). As there is no control over the memory accesses of
96 the CPU, real addressing mode is implied, and so the Low Memory area must
97 be accessible (an MMU might be used to set up different address spaces for
98 the Mac and the host, but this is not implemented in Basilisk II). The
99 native CPU mode has some possible pitfalls that might make its
100 implementation difficult on some systems:
101 a) Implied real addressing (this also means that Mac programs that go out
102 of control can crash the emulator or the whole system)
103 b) MacOS and Mac applications assume that they always run in supervisor
104 mode (more precisely, they assume that they can safely use certain
105 priviledged instructions, mostly for interrupt control). So either
106 the whole emulator has to be run in supervisor mode (which usually is
107 not possible on multitasking systems) or priviledged instructions have
108 to be trapped and emulated. The Amiga version of Basilisk II uses the
109 latter approach (it is possible to run supervisor mode tasks under
110 the AmigaOS multitasking kernel (ShapeShifter does this) but it
111 requires modifying the task switcher and makes the emulator more
112 unstable).
113 c) On multitasking systems, interrupts can usually not be handled as on
114 a real Mac (or with the UAE CPU). The interrupt levels of the host
115 will not be the same as on a Mac, and the operating systems might not
116 allow installing hardware interrupt handlers or the interrupt handlers
117 might have different stack frames and run-time environments than 68k
118 hardware interrupts. The usual solution is to use some sort of software
119 interrupts or signals to interrupt the main emulation process and to
120 manually call the Mac 68k interrupt handler with a faked stack frame.
121 d) 68060 systems are a small problem because there is no Mac that ever
122 used the 68060 and MacOS doesn't know about this processor. Basilisk II
123 reports the 68060 as being a 68040 to the MacOS and patches some places
124 where MacOS makes use of certain 68040-specific features such as the
125 FPU state frame layout or the PTEST instruction. Also, Basilisk II
126 requires that all of the Motorola support software for the 68060 to
127 emulate missing FPU and integer instructions and addressing modes is
128 provided by the host operating system (this also applies to the 68040).
129 e) The "EMUL_OP" mechanism described below requires the interception and
130 handling of certain emulator-defined instructions.
131
132 3. Memory access
133 ----------------
134
135 There is often a need to access Mac RAM and ROM inside the emulator. As
136 Basilisk II may run in "real" or "virtual" addressing mode on many different
137 architectures, big-endian or little-endian, certain platform-independent
138 data types and functions are provided:
139
140 a) "sysdeps.h" defines the types int8, uint8, int16, uint16, int32 and uint32
141 for numeric quantities of a certain signedness and bit length
142 b) "cpu_emulation.h" defines the ReadMacInt*() and WriteMacInt*() functions
143 which should always be used to read from or write to Mac RAM or ROM
144 c) "cpu_emulation.h" also defines the Mac2HostAddr() function that translates
145 a Mac memory address to a (uint8 *) in host address space. This allows you
146 to access larger chunks of Mac memory directly, without going through the
147 read/write functions for every access. But doing so you have to perform
148 any needed endianess conversion of the data yourself by using the ntohs()
149 etc. macros which are available on most systems or defined in "sysdeps.h".
150
151 4. Calling native routines from 68k mode and vice-versa
152 -------------------------------------------------------
153
154 An emulator like Basilisk II requires two kinds of cross-platform function
155 calls:
156
157 a) Calling a native routine from the Mac 68k context
158 b) Calling a Mac 68k routine from the native context
159
160 Situation a) arises in nearly all Basilisk drivers and system patches while
161 case b) is needed for the invocation of Mac call-back or interrupt routines.
162 Basilisk II tries to solve both problems in a way that provides the same
163 interface whether it is running on a 68k or a non-68k system.
164
165 4.1. The EMUL_OP mechanism
166 --------------------------
167
168 Calling native routines from the Mac 68k context requires breaking out of the
169 68k emulator or interrupting the current instruction flow and is done via
170 unimplemented 68k opcodes (called "EMUL_OP" opcodes). Basilisk II uses opcodes
171 of the form 0x71xx (these are invalid MOVEQ opcodes) which are defined in
172 "emul_op.h". When such an opcode is encountered, whether by the emulated CPU
173 or a real 68k, the execution is interrupted, all CPU registers saved and the
174 EmulOp() function from "emul_op.cpp" is called. EmulOp() decides which opcode
175 caused the interrupt and performs the required actions (mostly by calling other
176 emulator routines). The EMUL_OP handler routines have access to nearly all of
177 the 68k user mode registers (exceptions being the PC, A7 and SR). So the
178 EMUL_OP opcodes can be thought of as extensions to the 68k instruction set.
179 Some of these opcodes are used to implement ROM or resource patches because
180 they only occupy 2 bytes and there is sometimes not more room for a patch.
181
182 4.2. Execute68k()
183 -----------------
184
185 "cpu_emulation.h" declares the functions Execute68k() and Execute68kTrap() to
186 call Mac 68k routines or MacOS system traps from inside an EMUL_OP handler
187 routine. They allow setting all 68k user mode registers (except PC and SR)
188 before the call and examining all register contents after the call has
189 returned. EMUL_OP and Execute68k() may be nested, i.e. a routine called with
190 Execute68k() may contain EMUL_OP opcodes and the EMUL_OP handlers may in turn
191 call Execute68k() again.
192
193 5. Interrupts
194 -------------
195
196 Various parts of Basilisk II (such as the Time Manager and the serial driver)
197 need an interrupt facility to trigger asynchronous events. The MacOS uses
198 different 68k interrupt levels for different events, but for simplicity
199 Basilisk II only uses level 1 and does it's own interrupt dispatching. The
200 "InterruptFlags" contains a bit mask of the pending interrupts. These are the
201 currently defined interrupt sources (see main.h):
202
203 INTFLAG_60HZ - MacOS 60Hz interrupt (unlike a real Mac, we also handle
204 VBL interrupts, ADB events and the Time Manager here)
205 INTFLAG_SERIAL - Interrupt for serial driver I/O completion
206 INTFLAG_ETHER - Interrupt for Ethernet driver I/O completion and packet
207 reception
208 INTFLAG_AUDIO - Interrupt for audio "next block" requests
209 INTFLAG_TIMER - Reserved for a future implementation of a more precise
210 Time Manager (currently not used)
211
212 An interrupt is triggered by calling SetInterruptFlag() with the desired
213 interrupt flag constant and then TriggerInterrupt(). When the UAE 68k
214 emulator is used, this will signal a hardware interrupt to the emulated 680x0.
215 On a native 68k machine, some other method for interrupting the MacOS thread
216 has to be used (e.g. on AmigaOS, a signal exception is used). Care has to be
217 taken because with the UAE CPU, the interrupt will only occur when Basilisk II
218 is executing MacOS code while on a native 68k machine, the interrupt could
219 occur at any time (e.g. inside an EMUL_OP handler routine). In any case, the
220 MacOS thread will eventually end up in the level 1 interrupt handler which
221 contains an M68K_EMUL_OP_IRQ opcode. The opcode handler in emul_op.cpp will
222 then look at InterruptFlags and decide which routines to call.
223
224 6. Parts of Basilisk II
225 -----------------------
226
227 The conception of Basilisk II is quite modular and consists of many parts
228 which are relatively independent from each other:
229
230 - UAE CPU engine ("uae_cpu/*", not needed on all systems)
231 - ROM patches ("rom_patches.cpp", "slot_rom.cpp" and "emul_op.cpp")
232 - resource patches ("rsrc_patches.cpp" and "emul_op.cpp")
233 - PRAM Utilities replacement ("xpram.cpp")
234 - ADB Manager replacement ("adb.cpp")
235 - Time Manager replacement ("timer.cpp")
236 - SCSI Manager replacement ("scsi.cpp")
237 - video driver ("video.cpp")
238 - audio component ("audio.cpp")
239 - floppy driver ("sony.cpp")
240 - disk driver ("disk.cpp")
241 - CD-ROM driver ("cdrom.cpp")
242 - serial drivers ("serial.cpp")
243 - Ethernet driver ("ether.cpp")
244 - system-dependant device access ("sys_*.cpp")
245 - user interface strings ("user_strings.cpp")
246 - preferences management ("prefs.cpp" and "prefs_editor_*.cpp")
247
248 Most modules consist of a platform-independant part (such as video.cpp) and a
249 platform-dependant part (such as video_beos.cpp). The "dummy" directory
250 contains generic "do-nothing" versions of some of the platform-dependant
251 parts to aid in testing and porting.
252
253 6.1. UAE CPU engine
254 -------------------
255
256 All files relating to the UAE 680x0 emulation are kept in the "uae_cpu"
257 directory. The "cpu_emulation.h" header file defines the link between the
258 UAE CPU and the rest of Basilisk II, and "basilisk_glue.cpp" implements the
259 link. It should be possible to replace the UAE CPU with a different 680x0
260 emulation by creating a new "xxx_cpu" directory with an appropriate
261 "cpu_emulation.h" header file (for the inlined memory access functions) and
262 writing glue code between the functions declared in "cpu_emulation.h" and
263 those provided by the 680x0 emulator.
264
265 6.2. ROM and resource patches
266 -----------------------------
267
268 As described above, instead of emulating custom Mac hardware, Basilisk II
269 provides replacements for certain parts of MacOS to redirect input, output
270 and system control functions of the Mac hardware to the underlying operating
271 systems. This is done by applying patches to the Mac ROM ("ROM patches") and
272 the MacOS system file ("resource patches", because nearly all system software
273 is contained in MacOS resources). Unless resources are written back to disk,
274 the system file patches are not permanent (it would cause many problems if
275 they were permanent, because some of the patches vary with different
276 versions of Basilisk II or even every time the emulator is launched).
277
278 ROM patches are contained in "rom_patches.cpp" and resource patches are
279 contained in "rsrc_patches.cpp". The ROM patches are far more numerous because
280 nearly all the software needed to run MacOS is contained in the Mac ROM (the
281 system file itself consists mainly of ROM patches, in addition to pictures and
282 text). One part of the ROM patches involves the construction of a NuBus slot
283 declaration ROM (in "slot_rom.cpp") which is used to add the video and Ethernet
284 drivers. Apart from the CPU emulation, the ROM and resource patches contain
285 most of the "logic" of the emulator.
286
287 6.3. PRAM Utilities
288 -------------------
289
290 MacOS stores certain nonvolatile system parameters in a 256 byte battery
291 backed-up CMOS RAM area called "Parameter RAM", "PRAM" or "XPRAM" (which refers
292 to "Extended PRAM" because the earliest Mac models only had 20 bytes of PRAM).
293 Basilisk II patches the ClkNoMem() MacOS trap which is used to access the XPRAM
294 (apart from some routines which are only used early during system startup)
295 and the real-time clock. The XPRAM is emulated in a 256 byte array which is
296 saved to disk to preserve the contents for the next time Basilisk is launched.
297
298 6.4. ADB Manager
299 ----------------
300
301 For emulating a mouse and a keyboard, Basilisk II patches the ADBOp() MacOS
302 trap. Platform-dependant code reports mouse and keyboard events with the
303 ADBMouseDown() etc. functions which are queued and sent to MacOS inside the
304 ADBInterrupt() function (which is called as a part of the 60Hz interrupt
305 handler) by calling the ADB mouse and keyboard handlers with Execute68k().
306
307 6.5. Time Manager
308 -----------------
309
310 Basilisk II completely replaces the Time Manager (InsTime(), RmvTime(),
311 PrimeTime() and Microseconds() traps). A "TMDesc" structure is associated with
312 each Time Manager task, that contains additional data. The tasks are executed
313 in the TimerInterrupt() function which is currently called inside the 60Hz
314 interrupt handler, thus limiting the resolution of the Time Manager to 16.6ms.
315
316 6.6. SCSI Manager
317 -----------------
318
319 The (old-style) SCSI Manager is also completely replaced and the MacOS
320 SCSIDispatch() trap redirected to the routines in "scsi.cpp". Under the MacOS,
321 programs have to issue multiple calls for all the different phases of a
322 SCSI bus interaction (arbitration, selection, command transfer etc.).
323 Basilisk II maps this API to an atomic API which is used by most modern
324 operating systems. All action is deferred until the call to SCSIComplete().
325 The TIB (Transfer Instruction Block) mini-programs used by the MacOS are
326 translated into a scatter/gather list of data blocks. Operating systems that
327 don't support scatter/gather SCSI I/O will have to use buffering if more than
328 one data block is being transmitted. Some more advanced (but rarely used)
329 aspects of the SCSI Manager (like messaging and compare operations) are not
330 emulated.
331
332 6.7. Video driver
333 -----------------
334
335 The NuBus slot declaration ROM constructed in "slot_rom.cpp" contains a driver
336 definition for a video driver. The Control and Status calls of this driver are
337 implemented in "video.cpp". Run-time video mode and depth switching are
338 currently not supported.
339
340 The host-side initialization of the video system is done in VideoInit().
341 This function must provide access to a frame buffer for MacOS and supply
342 its address, resolution and color depth in a video_desc structure (there
343 is currently only one video_desc structure, called VideoMonitor; this is
344 going to change once multiple displays are supported). In real addressing
345 mode, this frame buffer must be in a MacOS compatible layout (big-endian
346 and 1, 2, 4 or 8 bits paletted chunky pixels, RGB 5:5:5 or xRGB 8:8:8:8).
347 In virtual addressing mode, the frame buffer is located at address
348 0xa0000000 on the Mac side and you have to supply the host address, size
349 and layout (BasiliskII will do an automatic pixel format conversion in
350 virtual addressing mode) in the variables MacFrameBaseHost, MacFrameSize
351 and MacFrameLayout.
352
353 6.8. Audio component
354 --------------------
355
356 Basilisk II provides a Sound Manager 3.x audio component for sound output.
357 Earlier Sound Manager versions that don't use components but 'snth' resources
358 are not supported. Nearly all component functions are implemented in
359 "audio.cpp". The system-dependant modules ("audio_*.cpp") handle the
360 initialization of the audio hardware/driver, volume controls, and the actual
361 sound output.
362
363 The mechanism of sound output varies depending on the platform but usually
364 there will be one "streaming thread" (either a thread that continuously writes
365 data buffers to the audio device or a callback function that provides the
366 next data buffer) that reads blocks of sound data from the MacOS Sound Manager
367 and writes them to the audio device. To request the next data buffer, the
368 streaming thread triggers the INTFLAG_AUDIO interrupt which will cause the
369 MacOS thread to eventually call AudioInterrupt(). Inside AudioInterrupt(),
370 the next data block will be read and the streaming thread is signalled that
371 new audio data is available.
372
373 6.9. Floppy, disk and CD-ROM drivers
374 ------------------------------------
375
376 Basilisk II contains three MacOS drivers that implement floppy, disk and CD-ROM
377 access ("sony.cpp", "disk.cpp" and "cdrom.cpp"). They rely heavily on the
378 functionality provided by the "sys_*.cpp" module. BTW, the name ".Sony" of the
379 MacOS floppy driver comes from the fact that the 3.5" floppy drive in the first
380 Mac models was custom-built for Apple by Sony (this was one of the first
381 applications of the 3.5" floppy format which was also invented by Sony).
382
383 6.10. Serial drivers
384 --------------------
385
386 Similar to the disk drivers, Basilisk II contains replacement serial drivers
387 for the emulation of Mac modem and printer ports. To avoid duplicating code,
388 both ports are handled by the same set of routines. The SerialPrime() etc.
389 functions are mostly wrappers that determine which port is being accessed.
390 All the real work is done by the "SERDPort" class which is subclassed by the
391 platform-dependant code. There are two instances (for port A and B) of the
392 subclasses.
393
394 Unlike the disk drivers, the serial driver must be able to handle asynchronous
395 operations. Calls to SerialPrime() will usually not actually transmit or receive
396 data but delegate the action to an independant thread. SerialPrime() then
397 returns "1" to indicate that the I/O operation is not yet completed. The
398 completion of the I/O request is signalled by calling the MacOS trap "IODone".
399 However, this can't be done by the I/O thread because it's not in the right
400 run-time environment to call MacOS functions. Therefore it will trigger the
401 INTFLAG_SERIAL interrupt which causes the MacOS thread to eventually call
402 SerialInterrupt(). SerialInterrupt(), in turn, will not call IODone either but
403 install a Deferred Task to do the job. The Deferred Task will be called by
404 MacOS when it returns to interrupt level 0. This mechanism sounds complicated
405 but is necessary to ensure stable operation of the serial driver.
406
407 6.11. Ethernet driver
408 ---------------------
409
410 A driver for Ethernet networking is also contained in the NuBus slot ROM.
411 Only one ethernet card can be handled by Basilisk II. For Ethernet to work,
412 Basilisk II must be able to send and receive raw Ethernet packets, including
413 the 14-byte header (destination and source address and type/length field),
414 but not including the 4-byte CRC. This may not be possible on all platforms
415 or it may require writing special net drivers or add-ons or running with
416 superuser priviledges to get access to the raw packets.
417
418 Writing packets works as in the serial drivers. The ether_write() routine may
419 choose to send the packet immediately (e.g. under BeOS) and return noErr or to
420 delegate the sending to a separate thread (e.g. under AmigaOS) and return "1" to
421 indicate that the operation is still in progress. For the latter case, a
422 Deferred Task structure is provided in the ether_data area to call IODone from
423 EtherInterrupt() when the packet write is complete (see above for a description
424 of the mechanism).
425
426 Packet reception is a different story. First of all, there are two methods
427 provided by the MacOS Ethernet driver API to read packets, one of which (ERead/
428 ERdCancel) is not supported by Basilisk II. Basilisk II only supports reading
429 packets by attaching protocol handlers. This shouldn't be a problem because
430 the only network code I've seen so far that uses ERead is some Apple sample
431 code. AppleTalk, MacTCP, MacIPX, OpenTransport etc. all use protocol handlers.
432 By attaching a protocol handler, the user of the Ethernet driver supplies a
433 handler routine that should be called by the driver upon reception of Ethernet
434 packets of a certain type. 802.2 packets (type/length field of 0..1500 in the
435 packet header) are a bit special: there can be only one protocol handler attached
436 for 802.2 packets (by specifying a packet type of "0"). The MacOS LAP Manager
437 will attach a 802.2 handler upon startup and handle the distribution of 802.2
438 packets to sub-protocol handlers, but the Basilisk II Ethernet driver is not
439 concerned with this.
440
441 When the driver receives a packet, it has to look up the protocol handler
442 installed for the respective packet type (if any has been installed at all)
443 and call the packet handler routine. This must be done with Execute68k() from
444 the MacOS thread, so an interrupt (INTFLAG_ETHER) is triggered upon reception
445 of a packet so the EtherInterrupt() routine can call the protocol handler.
446 Before calling the handler, the Ethernet packet header has to be copied to
447 MacOS RAM (the "ed_RHA" field of the ether_data structure is provided for this).
448 The protocol handler will read the packet data by means of the ReadPacket/ReadRest
449 routines supplied by the Ethernet driver. Both routines will eventually end up
450 in EtherReadPacket() which copies the data to Mac address space. EtherReadPacket()
451 requires the host address and length of the packet to be loaded to a0 and d1
452 before calling the protocol handler.
453
454 Does this sound complicated? You are probably right. Here is another description
455 of what happens upon reception of a packet:
456 1. Ethernet card receives packet and notifies some platform-dependant entity
457 inside Basilisk II
458 2. This entity will store the packet in some safe place and trigger the
459 INTFLAG_ETHER interrupt
460 3. The MacOS thread will execute the EtherInterrupt() routine and look for
461 received packets
462 4. If a packet was received of a type to which a protocol handler had been
463 attached, the packet header is copied to ed_RHA, a0/d1 are loaded with
464 the host address and length of the packet data, a3 is loaded with the
465 Mac address of the first byte behing ed_RHA and a4 is loaded with the
466 Mac address of the ed_ReadPacket code inside ether_data, and the protocol
467 handler is called with Execute68k()
468 5. The protocol handler will eventually try to read the packet data with
469 a "jsr (a4)" or "jsr 2(a4)"
470 6. This will execute an M68K_EMUL_OP_ETHER_READ_PACKET opcode
471 7. The EtherReadPacket() opcode handling routine will copy the requested
472 part of the packet data to Mac RAM using the pointer and length which are
473 still in a0/d1
474
475 For a more detailed description of the Ethernet driver, see "Inside AppleTalk".
476
477 6.12. System-dependant device access
478 ------------------------------------
479
480 The method for accessing floppy drives, hard disks, CD-ROM drives and files
481 vary greatly between different operating systems. To make Basilisk II easily
482 portable, all device I/O is made via the functions declared in "sys.h" and
483 implemented by the (system-dependant) "sys_*.cpp" modules which provides a
484 standard, Unix-like interface to all kinds of devices.
485
486 6.13. User interface strings
487 ----------------------------
488
489 To aid in localization, all user interface strings of Basilisk II are collected
490 in "user_strings.cpp" and accessed via the GetString() function. This way,
491 Basilisk II may be easily translated to different languages.
492
493 6.14. Preferences management
494 ----------------------------
495
496 The module "prefs.cpp" handles user preferences in a system-independant way.
497 Preferences items are accessed with the PrefsAdd*(), PrefsReplace*() and
498 PrefsFind*() functions and stored in human-readable and editable text files
499 on disk. There are two lists of available preferences items. The first one,
500 common_prefs_items, defines the items which are available on all systems.
501 The second one, platform_prefs_items, is defined in prefs_*.cpp and lists
502 the prefs items which are specific to a certain platform.
503
504 The "prefs_editor_*.cpp" module provides a graphical user interface for
505 setting the preferences so users won't have to edit the preferences file
506 manually.
507
508 7. Porting Basilisk II
509 ----------------------
510
511 Porting Basilisk II to a new platform should not be hard. These are the steps
512 involved in the process:
513
514 1. Create a new directory inside the "src" directory for your platform. If
515 your platform comes in several "flavours" that require adapted files, you
516 should consider creating subdirectories inside the platform directory.
517 All files needed for your port must be placed inside the new directory.
518 Don't scatter platform-dependant files across the "src" hierarchy.
519 2. Decide in which mode (virtual addressing, real addressing or native CPU)
520 Basilisk II will run.
521 3. Create a "sysdeps.h" file which defines the mode and system-dependant
522 data types and memory access functions. Things which are used in Basilisk
523 but missing on your platform (such as endianess macros) should also be
524 defined here.
525 4. Implement the system-specific parts of Basilisk:
526 main_*.cpp, sys_*.cpp, prefs_*.cpp, prefs_editor_*.cpp, xpram_*.cpp,
527 timer_*.cpp, audio_*.cpp, video_*.cpp, serial_*.cpp, ether_*.cpp,
528 scsi_*.cpp and clip_*.cpp
529 You may want to take the skeleton implementations in the "dummy" directory
530 as a starting point and look at the implementation for other platforms
531 before writing your own.
532 5. Important things to remember:
533 - Use the ReadMacInt*() and WriteMacInt*() functions from "cpu_emulation.h"
534 to access Mac memory
535 - Use the ntohs() etc. macros to convert endianess when accessing Mac
536 memory directly
537 - Don't modify any source files outside of your platform directory unless
538 you really, really have to. Instead of adding "#ifdef PLATFORM" blocks
539 to one of the platform-independant source files, you should contact me
540 so that we may find a more elegant and more portable solution.
541 6. Coding style: indent -kr -ts4
542
543
544 Christian Bauer
545 <Christian.Bauer@uni-mainz.de>