OPERATING SYSTEM calls: ======================= BIOS, XBIOS, CONOUT Escape Sequences, system variables, error numbers, GEMDOS. BIOS Calls (TRAP #13) ===================== These listings of the operating system calls first state the function/call number in brackets, followed by the C function name, followed by a brief description of the function. This is followed by the C calling parameters and format, and any other information and finally by an assembly language example or assembly language format. Many of these traps are examined in detail in the book. (0) getmpb Get Memory Pointer Block void getmpb(pointer) long pointer; move.l #buffer,-(sp) ; buffer address move #0,-(sp) ; function number trap #13 addq.l #6,sp buffer: ds.b 12 Result long Pointer to memory free list memory descripter (md) long Pointer to memory allocated list md long Pointer to roving md Note: I have never used this, and have never come across its use in any example assembler source code. (1) bconstat WORD bconstat(dev) WORD dev; Return character-device input status, D0.L will be $0000 if no characters available, or $ffff if (at least one) character is available. 'dev' can be one of: 0 PRT: (printer, the parallel port) 1 AUX: (aux device, the RS232 port) 2 CON: (console, the screen) 3 MIDI port 4 KBD keyboard Legal operations on character devices are: (0) (1) (2) (3) (4) Operation PRT AUX CON MIDI KBD --------- ---- ---- ---- ---- ---- bconstat() no yes yes yes no bconin() yes yes yes yes no bconout() yes yes yes yes yes bcostat() yes yes yes yes yes Example assembler wait: move #2,-(sp) ; con move #1,-(sp) ; bconstat trap #13 tst d0 ; result in d0 beq wait (2) bconin (or conin) Read character from device WORD bconin(dev) WORD dev; 'dev' is the character device number described in function 1. Does not return until a character has been input. It returns the character value in D0.L, with the high word zero. For the console (CON:, device 2) it returns the IBM-PC compatible scancode in the low byte of the upper word, and the Ascii character in the low byte of the low word. Example move dev,-(sp) move #2,-(sp) bconin trap #13 addq.l #4,sp (3) bconout Write character to device VOID bconout(dev, c) WORD dev, c; 'dev' is the character device number described in function 1. Output character 'c' to the device. Does not return until the character has been written. Example move #65,-(sp) ; 'A' move dev,-(sp) move #3,-(sp) ; bconout trap #13 add.l #6,sp See chapter 2 (4) rwabs Read and write disk sector LONG rwabs(rwflag, buf, count, recno, dev) WORD rwflag; LONG buf; WORD count, recno, dev; Read or write logical sectors on a device. 'rwflag' is one of: 0 read 1 write 2 read, do not affect media-change 3 write, do not affect media-change 'buf' points to a buffer to read or write to (unaligned transfers -- on odd boundaries -- are permitted, but they are slow). 'count' is the number of sectors to transfer. 'recno' is the logical sector number to start the transfer at. 'dev' is the device number, and on the ST is one of: 0 Floppy drive A: 1 Floppy drive B: (or "logical" drive A: on single-disk systems). 2+ Hard disks, networks, etc. On return, 0L indicates a successful operation. Any negative number indicates an error condition. (It is the responsibility of the BIOS to detect media changes, and return the appropriate error code). Modes 2 and 3 force a physical disk operation that will NOT affect media change, nor result in one (this allows the GEMDOS disk formatter, for instance, to read and write logical sectors after formatting a disk, and still allow the BIOS to recognize a media change on the volume just for- matted). Example move #0,-(sp) ; drive a move #10,-(sp) ; start at logical sector 10 move #2,-(sp) ; read 2 sectors move.l #buffer,-(sp) ; address of buffer move #0,-(sp) ; read sectors move #4,-(sp) ; rwabs trap #13 add.l #14,sp buffer: ds.b 1024 (5) setexc Set exception vectors LONG setexc(vecnum, vec) WORD vecnum; LONG vec; 'vecnum' is the number of the vector to get or set. 'vec' is the address to setup in the vector slot; no set is done if 'vec' is -1L. The vector's previous value is returned. Vectors $00 through $FF are reserved for the 68000. Logical vectors $100 through $1FF are reserved for GEMDOS. Vectors currently implemented are: $100 System timer interrupt $101 Critical error handler $102 Process terminate hook $103..$107: Currently unused, reserved Logical vectors $200 through $FFFF are reserved for OEM use. The ST BIOS makes no provision for these. Example move.l #vec_addr,-(sp) ; address of new vector, -1 read current move.l #vec_num,-(sp) ; number of vector to change or read move #5,-(sp) trap #13 addq.l #8,sp d0 returns old vector address wich should be restored before exiting. (6) tickcal LONG tickcal() Returns a system-timer calibration value, to the nearest millisecond. Example move #6,-(sp) trap #13 addq.l #2,sp (7) *getbpb Get Bios parameter block BPB *getbpb(dev) WORD dev; 'dev' is a device number (0 for drive A, etc.) Returns a pointer to the BIOS Parameter Block for the specified drive, or 0L if (for some reason) the BPB cannot be determined. The bpb is constructed as follows: word sector size in bytes (512) word cluster size in sectors (should be 2) word cluster size in bytes (should be 1024) word directory length in sectors word FAT size in sectors word sector number of the 2nd FAT word sector number of the first data cluster word number of data clusters on the disk word miscellaneous flags; bit 0 when set 16 bit FAT entries. Example move #0,-(sp) ; drive a move #7,-(sp) trap #13 addq.l #4,sp (8) bcostat Return output device status LONG bcostat(dev) 'dev' is a character device number, as in func- tion 1. Returns character output status: -1 Device is ready to send (no waiting on next device-output call). 0 Device is not ready to send. Example move #0,sp ; is printer ready move #8,-(sp) ; bcostat trap #13 addq.l #4,sp (9) mediach Inquire media change LONG mediach(dev) WORD dev; 'dev' is a drive number. Returns one of (in d0): 0 Media definitely has not changed 1 Media /might/ have changed 2 Media definitely has changed GEMDOS will respond to a return value of '1' with a read operation. If the BIOS detects an abso- lute media change, it will return a "media change" error at that time. Example move #0,-(sp) ; drive a move #9,-(sp) trap #13 addq.l #4,sp (10) drvmap LONG drvmap() Returns (in d0) a bit-vector that contains a '1' in a bit position (0 .. 31) when a drive is available for that bit, or a 0 if there is no drive available for the bit. Example move #10,-(sp) trap #13 addq.l #2,sp (11) kbshift LONG kbshift(mode) WORD mode; If 'mode' is non-negative, sets the keyboard shift bits accordingly and returns the old shift bits. If 'mode' is less than zero, returns the IBM-PC compatible state of the shift keys on the keyboard, as a bit-vector in the low byte of D0. Bit assignments are: 0 Right shift key 1 Left shift key 2 Control key 3 ALT key 4 Caps-lock 5 Right mouse button (CLR/HOME) 6 Left mouse button (INSERT) 7 (reserved, currently zero) Example move mode,-(sp) move #11,-(sp) trap #1 addq.l #4,sp Extended BIOS Functions (XBIOS) ============================== These functions are available through trap 14. The calling conventions are the same as for trap 13. (0) initmous VOID initmous(type, param, vec) WORD type; LONG param, vec; Initialize mouse packet handler. 'type' is one of: type Action 0 disable mouse 1 enable mouse, in relative mode 2 enable mouse, in absolute mode 3 (unused) 4 enable mouse, in keycode mode 'vec' points to a mouse interrupt handler; see extended function number 34, 'kbdvbase', for further information about ikbd subsystem handlers. example move.l vec,-(sp) move.l params,-(sp) move #type,-(sp) move #0,-(sp) trap #14 add.l #12,sp 'vec' is a pointer to new mouse packet interupt handler. 'params' is a 12 byte data block: Byte offset 0 origin of y position 0= y origin at bottom 1= y origin at top 1 paramter for IKBD set mouse buttons 2 relative mode= x threshold absouloute mode= x scale keycode mode = x delta 3 relative mode= y threshold absoulute mode= y scale keycode mode = y delta 4 max x pos 6 max y pos 8 initial x pos 10 initial y pos (1) ssbrk LONG ssbrk(amount) WORD amount; Reserve 'amount' bytes from the top of memory. Returns a long pointing to the base of the allo- cated memory. This function MUST be called before the OS is initialized. 'ssbrk' is actually pretty useless. It DOES NOT work after GEMDOS has been brought up, since the TPA has already been set up. (2) _physBase LONG _physBase() Get the screen's physical base address (at the beginning of the next vblank). Returned in d0 Example move #2,-(sp) trap #14 addq.l #2,sp move.l d0,phys_base phys_base: ds.l 1 (3) _logBase LONG _logBase() Get the screen's logical base, right away. This is the location that GEM uses when drawing to the screen. Returned in D0. This can be changed to update a graphics display without it being seen. Example move #3,-(sp) trap #14 addq.l #2,sp move.l d0,log_base log_base: ds.l 1 (4) _getRez WORD _getRez() Get the screen's current resolution (returning 0, 1 or 2 in d0). 0 = low, 1 =med, 2 = high. Example move #4,-(sp) trap #14 addq.l #2,sp move d0,res res: ds.w 1 (5) _setScreen VOID _setScreen(logLoc, physLoc, rez) LONG logLoc, physLoc; WORD rez; Set the logical screen location (logLoc), the physical screen location (physLoc), and the phy- sical screen resolution. Negative parameters are ignored (making it possible, for instance, to set screen resolution without changing anything else). The logical screen location changes immediately. The physical screen location hardware register is changed immediately, but the new screen location will take effect after the next vertical retrace. When resolution is changed, the screen is cleared, the cursor is homed, and the VT52 termi- nal emulator state is reset. Can only be used on TOS programs. Example move #-1,-(sp) ; retain res move.l phy_base,-(sp) ; got from Xbios 2 move.l log_base,-(sp) ; got from Xbios 3 move #5,-(sp) trap #14 add.l #12,sp (6) _setPallete VOID _setPallete(palettePtr) LONG palettePtr; Set the contents of the hardware palette register (all 16 color entries) from the 16 words pointed to by 'palettePtr'. 'paletteptr' MUST be on a word boundary. The palette assignment takes place at the beginning of the next vertical blank interrupt. Example- See book (7) _setColor WORD _setColor(colorNum, color) WORD colorNum, color; Set the palette number 'colorNum' in the hardware palette table to the given color. Return the old color in D0.W. If 'color' is negative, the hardware register is not changed but is returned in d0. Example move #$777,-(sp) ; white move #1,-(sp) ; register 1 move #7,-(sp) trap #14 addq.l #6,sp (8) _floprd Read disk sector WORD _floprd(buf, filler, devno, sectno, trackno, sideno, count) LONG buf, filler; WORD devno, sectno, trackno, sideno, count; Read one or more sectors from a floppy disk. 'filler' is an unused longword. 'buf' must point to a word-aligned buffer large enough to contain the number of sectors requested. 'devno' is the floppy number (0 or 1). 'sectno' is the sector number to start reading from (usually 1 through 9). 'trackno' is the track number to seek to. 'sideno' is the side number to select. 'count' is the number of sectors to read (which must be less than or equal to the number of sectors per track). On return, D0 contains a status code. If D0 is zero, the operation succeeded. If D0 is nonzero, the operation failed (and D0 contains an error number). Example move #1,-(sp) ; read 1 sector move #0,-(sp) ; s/s disk move #0,-(sp) ; track 0 move #1,-(sp) ; sector 1 move #1,-(sp) ; drive B clr.l -(sp) ; unused long move.l #buffer,-(sp) ; buffer for a sector move #8,-(sp) trap #14 add.l #20,sp tst d0 ; did an error occur bmi error_routine buffer: ds.b 512 (9) _flopwr Write disk sector WORD _flopwr(buf, filler, devno, sectno, trackno, sideno, count) LONG buf, filler; WORD devno, sectno, trackno, sideno, count; Write one or more sectors to a floppy disk. 'buf' must point to a word-aligned buffer. 'filler' is an unused longword. 'devno' is the floppy number (0 or 1). 'sectno' is the sector number to start writing to (usually 1 through 9). 'trackno' is the track number to seek to. 'sideno' is the side number to select. 'count' is the number of sectors to write (which must be less than or equal to the number of sectors per track). On return, D0 contains a status code. If D0 is zero, the operation succeeded. If D0 is nonzero, the operation failed (and D0 contains an error number). Example move #2,-(sp) ; write 1 sector move #0,-(sp) ; s/s disk move #2,-(sp) ; track 2 move #1,-(sp) ; sector 1 move #1,-(sp) ; drive B clr.l -(sp) ; unused long move.l #buffer,-(sp) ; buffer for a sector move #9,-(sp) trap #14 add.l #20,sp tst d0 ; did an error occur bmi error_routine buffer: ds.b 1024 (10) _flopfmt Format a disk WORD _flopfmt(buf, filler, devno, spt, trackno, sideno, interlv, magic, virgin) LONG buf, filler; WORD devno, spt, trackno, sideno, interlv, virgin; LONG magic; Format a track on a floppy disk. 'buf' must point to a word-aligned buffer large enough to hold an entire track image (8K for 9 sectors- per-track). 'filler' is an unused longword. 'devno' is the floppy drive number (0 or 1). 'spt' is the number of sectors-per-track to for- mat (usually 9). 'trackno' is the track number to format (usually 0 to 79). 'sideno' is the side number to format (0 or 1). 'interlv' is the sector-interleave factor (usually 1). 'magic' is a magic number that MUST be the value $87654321. 'virgin' is a word fill value for new sectors. On return, D0 contains a status code. If D0 is zero, the operation succeeded. If D0 is nonzero, the operation failed (and D0 contains an error number). The format function can soft-fail when it finds bad sectors during the verify pass. The caller has the choice of attempting to re-format the media, or recording the bad sectors so they will not be included in the file system. A null-terminated (0.W) list of bad sector numbers is returned in the buffer. They are not necessarily in numerical order. (If there were no bad sectors, the first word in the buffer will be zero.) A good value for 'virgin' is $E5E5. The high nibble of each byte in the 'virgin' parameter must not be equal to $F. Resist the temptation to format a disk with sectors initialized to zero. Example move #$e5e5,-(sp) move.l #$87654321,-(sp) ; magic move #1,-(sp) ; interleave flag move #0,-(sp) ; side 0 move #79,-(sp) ; track number to be * formatted move #9,-(sp) ; sectors per track move #0,-(sp) clr.l -(sp) ; unused long move.l #buffer,-(sp) ; 8k buffer move #10,-(sp) trap #14 add.l #26,sp tst d0 bmi error_routine buffer ds.b $2000 (12) midiws write astring to MIDI port VOID midiws(cnt, ptr) WORD cnt; LONG ptr; Writes a string to the MIDI port. 'cnt' is the number of characters to write, minus one. 'ptr' points to a vector of characters to write. Example move.l #buffer,-(sp) move #3,-(sp) move #12,-(sp) trap #14 addq.l #8,sp buffer dc.b 'data',0 (13) _mfpint VOID _mfpint(interno, vector) WORD interno; LONG vector; Set the MFP interrupt number 'interno' (0 to 15) to 'vector'. The old vector is written over (and thus unrecoverable). move.l vector,-(sp) move number,(sp) trap #13 addq.l #8,sp (14) iorec Get i/o buffer record LONG iorec(devno) WORD devno; Returns a pointer to a serial device's input buffer record. 'devno' is one of: devno Device ----- -------- 0 RS232 1 Keyboard 2 MIDI For RS-232, an output-buffer record immediately follows the input-buffer record. The format of the output-buffer record is identical. 'ibuf' points to the device's buffer. 'ibufsiz' is the buffer's size. 'ibufhi' is the buffer's high-water mark. 'ibuflow' is the buffer's low- water mark. If flow control is enabled and the number of characters in the buffer reaches the high-water mark, the ST requests (according to the flow- control protocol) the sender to stop sending characters. When the number of characters in the buffer drops below the low-water mark, the ST tells the sender to resume transmission. The flow-control operation is similar for the RS-232 output record. Result in d0 contains 14 bytes of data: Bytes 0-3 address of input buffer 4-5 size in bytes of input buffer 6-7 next write position (index to head) 8-9 next read pos (index to tail) 10-11 low water mark 12-13 high water mark Example move #2,-(sp) ; MIDI move #14,-(sp) trap #14 addq.l #4,sp (15) rsconf configure RS-232 port VOID rsconf(speed, flowctl, ucr, rsr, tsr, scr) WORD speed, flowctl, ucr, rsr, tsr, scr; Configure RS-232 port. If any parameter is -1 ($FFFF), the corresponding hardware register is not set. 'speed' sets the port's baud rate, as per: speed Rate (bps) ----- ---------- 0 19,200 1 9600 2 4800 3 3600 4 2400 5 2000 6 1800 7 1200 8 600 9 300 10 200 11 150 12 134 13 110 14 75 15 50 'flow' sets the flow control, as per: flow Flavor ----- --------- 0 No flow control [powerup default] 1 XON/XOFF (^S/^Q) 2 RTS/CTS 3 XON/XOFF and RTS/CTS [is this useful?] 'ucr', 'rsr', 'tsr', and 'scr' set the appropri- ate 68901 registers. scr= Synchronous character register tsr= transmitter status reg rsr= receiver status reg ucr= USART control reg Example move #-1,-(sp) ; scr move #-1,-(sp) ; tsr move #-1,-(sp) ; rsr move #-1,-(sp) ; ucr move #-1,-(sp) ; flow move #9,-(sp) ; 300 baud move #15,-(sp) trap #14 add.l #14,sp ucr bit settings Bit 0 not used 1 parity 0= odd, 1= even 2 parity enable 0=off 3 start and stopbits 0= no start/stop bits; 1= 1 start bit 1 stop bit; 2= 1 start bit 1 1/2 stop bits; 3= 1 start bit 2 stop bits. 5-6 data bits per word 0= 8 bits; 1= 7bits; 2 = 6bits; 3= 5 bits. 7 clock 0= synchronous transfer 1= divide clock frequency by 16 (16) keytbl Get or set keyboard table LONG keytbl(unshift, shift, capslock) LONG unshift, shift, capslock; Sets pointers to the keyboard translation tables for unshifted keys, shifted keys, and keys in caps-lock mode. Returns the address of 3 keyboard tables in d0. Byte 0-3 address of unshifted table; 4-7 address of shift table; 8-11 adddress of caps lock table. Passing -1 uses current table. Example move.l #-1,-(sp) ; keep caps lock table move.l #shift_table,-(sp) ; address of new shift * table, 128 bytes in size move.l #-1,-(sp) ; keep table without shift trap #14 add.l #14,sp shift_table: ............... (17) _random LONG _random() Returns a 24-bit psuedo-random number in D0.L. Bits 24..31 will be zero. The sequence /should/ be different each time the system is turned on. [The algorithm is from vol. 2 of Knuth: S = [S * C] + K where K = 1, C = 3141592621, and S is the seed. S >> 8 is returned. The initial value of S is taken from the frame-counter '_frclock'.] The function's behavior is surprisingly good, except that bit 0 has an /exact/ distribution of 50%. Therefore it is probably not a good idea to test individual bits and expect them to be well behaved. Example move #17,-(sp) trap #14 addq.l #2.sp (18) _protobt produce a boot sector VOID _protobt(buf, serialno, disktype, execflag) LONG buf, serialno; WORD disktype, execflag; Prototype an image of a boot sector. Once the boot sector image has been constructed with this function, write it to the volume's boot sector. 'buf' points to a 512-byte buffer (which may con- tain garbage, or already contain a boot sector image). 'serialno' is a serial number to stamp into the boot sector. If 'serialno' is -1, the boot sector's serial number is not changed. If 'seri- alno' is greater than or equal to $01000000, a random serial number is generated and placed in the boot sector. 'disktype' is either -1 (to leave the disk type information alone) or one of the following: 0: 40 tracks, single sided (180K) 1: 40 tracks, double sided (360K) 2: 80 tracks, single sided (360K) 3: 80 tracks, double sided (720K) If 'execflag' is 1, the boot sector is made exe- cutable. If 'execflag' is 0, the boot sector is made non-executable. If 'execflag' is -1, the boot sector remains executable or non-executable depending on the way it was originally. A boot sector is located at track 0, sector 1, side 0. Use flopwr to write boot sector. Example move #-1,-(sp) ; execfalg move #3,-(sp) ; disktype = 80 tracks d/s move #-1,-(sp) ; serial num, don't alter move.l #buf,-(sp) move #18,-(sp) trap #14 add.l #14,sp buf ds.b 512 (19) _flopver Verift disk sector WORD _flopver(buf, filler, devno, sectno, trackno, sideno, count) LONG buf, filler; WORD devno, sectno, trackno, sideno, count; Verify (by simply reading) one or more sectors from a floppy disk. 'buf' must point to a word- aligned 1024-byte buffer. 'filler' is an unused longword. 'devno' is the floppy number (0 or 1). 'sectno' is the sector number to start reading from (usually 1 through 9). 'trackno' is the track number to seek to. 'sideno' is the side number to select. 'count' is the number of sectors to verify (which must be less than or equal to the number of sectors per track). On return, D0 contains a status code. If D0 is zero, the operation succeeded. If D0 is nonzero, the operation failed (and D0 contains an error number). A null-terminated (0.W) list of bad sector numbers is returned in the buffer. They are not necessarily in numerical order. (If there were no bad sectors, the first word in the buffer will be zero.) Example move #1,-(sp) ; number of sectors to verify move #0,-(sp) ; side 0 move #26,-(sp) ; track 26 move #2,-(sp) ; sector 2 move #0,-(sp) ; drive A clr.l -(sp) move.l #buf,-(sp) move #19,-(sp) trap #16 add.l #14,sp tst d0 bmi error_rountine buf ds.b 1024 (20) scrdmp Output screen dump VOID scrdmp() Dump screen to printer. Example move #20 trap #14 addq.l #2,sp (21) cursconf Configure text cursor WORD cursconf(function, newrate) WORD function, newrate; Configure the "glass terminal" (text) cursor. The 'function' code is one of the following: 0 Hide cursor 1 Show cursor 2 Cursor set to blink 3 Cursor set not to blink 4 Set cursor blink timer to 'operand' 5 Return cursor blink timer value The cursor blink rate is based on the video scan rate (60hz for color, 70hz for monochrome, 50hz for PAL). The 'rate' parameter is equal to one- half the cycle time. D0 returns current blink rate when function is 5 move #newrate,-(sp) move #function,-(sp) move #21,-(sp) trap #14 addq.l #6,sp (22) settime Set system time and date VOID settime(datetime) LONG datetime; Sets the intelligent keyboard's idea of the time and date. 'datetime' is a 32-bit DOS-format date and time (time in the low word, date in the high word). move.l #datetime,-(sp) move #22,-(sp) trap #14 addq.l #6,sp 'datetime' is a 32 bit long word. Lower word contains time, upper word conatins date and is set as follows: Bits 0-4 seconds in 2 sec increments 5-10 minutes 11-15 hour 16-20 day 21-24 month 25-31 year (minus 1980) (23) gettime Get system time and date LONG gettime() Interrogates the intelligent keyboard's idea of the time and date, and returns that value (in DOS format) as a 32-bit word in d0. (Time in the low word, date in the high word). Bit settings as above (24) bioskeys Restore default keyboard table VOID bioskeys() Restores the powerup settings of the keyboard translation tables. Example move #24,-(sp) trap #14 addq.l #2,sp (25) ikbdws Write string to intelligent keyboard VOID ikbdws(cnt, ptr) WORD cnt; LONG ptr; Writes a string to the intelligent keyboard. 'cnt' is the number of characters to write, minus one. 'ptr' points to a vector of characters to write. move.l #buffer-(sp) ; address of buffer that has * character string move bytes,-(sp) ; number of bytes in string -1 move #25-(sp) trap #14 addq.l #8,sp (26) jdisint Disable an MFP interrupt VOID jdisint(intno) WORD intno; Disable interrupt number 'intno' on the 68901. move intno,-(sp) move #26,-(sp) trap #14 addq.l #4,sp (27) jenabint Enable an MFP interrupt VOID jenabint(intno) WORD intno; Enable interrupt number 'intno' on the 68901. move intno,-(sp) move #27,-(sp) trap #14 addq.l #4,sp (28) giaccess Access sound chip BYTE giaccess(data, regno) BYTE data; WORD regno; Read or write a register on the sound chip. 'regno' is the register number: $00 to read $80 to write 'data' is a byte to write to the register. Bit 7 of the register number determines whether the register will be written to, or read to: Bit 7 0:read 1:read Example move #$80+4,-(sp) ; write register 4 move #$40,-(sp) ; value to write move #28,-(sp) trap #14 addq.l #6,sp (29) offgibit Reset port A Gi sound chip VOID offgibit(bitno) WORD bitno; Atomically set a bit in the PORT A register to zero. Port A is an 8 bit output port with the bits as follows: bit 0 select disk side 0/side 1 1 select drive A: 2 select drive B: 3 RS-232 RTS 4 RS-232 DTR 5 Centronics strobe 6 general purpose output 7 not used Example move #4,-(sp) ; DTR move #29,-(sp) trap #14 addq.l #4,sp (30) ongibit clear port A of GI sound chip VOID ongibit(bitno) WORD bitno; Atomically set a bit in the PORT A register to one. Example move #4,-(sp) ; DTR move #30,-(sp) trap #14 addq.l #4,sp (31) xbtimer Set MFP timer VOID xbtimer(timer, control, data, vec) WORD timer, control, data; LONG vec; 'timer' is the timer number (0, 1, 2, 3 corresponding to 68901 timers A, B, C and D). 'control' is the timer's control-register set- ting. 'data' is a byte shoved into the timer's data register. 'vec' is a pointer to an inter- rupt handler. Timers are allocated: Timer Usage A Reserved for end-users and applications B Reserved for graphics (hblank sync, etc.) C System timer (200hz) D RS-232 baud-rate control (this timer's interrupt vector is available to anyone). move.l #vector,-(sp) ; interrupt routine move data,-(sp) move vector,-(sp) move timer,-(sp) move #31,-(sp) trap #14 addq.l #12,sp (32) dosound Set sound parameters VOID dosound(ptr) LONG ptr; 'ptr' points to a set of commands organized as bytes. This function enable an interrupt driven routine so music or sound effects can play in the background. Command numbers $00 through $0F take a one byte argument to be shoved into a sound chip register. (Command $00 shoves the byte into register 0, command 1 shoves the byte into register 1...) Command $80 takes a one byte argument which is shoved into a temporary register. Command $81 takes three one-byte arguments. The first argument is a register number to load, using the temp register. The second argument is a 2's complement value to be added to the temp register. The third argument is the termination value. The instruction is executed (once on each update) until the temp register equals the termi- nation value. Commands $82 through $FF take a one-byte argument. If the argument is zero, the sound is terminated. Otherwise the argument reflects the number of system-timer ticks (at 50hz) until the next update. move.l #ptr,-(sp) move #32,-(sp) trap #14 addq.l #6,sp (33) setprt Configure dot matrix printer WORD setprt(config) WORD config; Set/get printer configuration byte. If 'config' is -1 ($FFFF) return the current printer confi- guration byte. Otherwise set the byte and return it's old value. Bits currently defined are: Bit# When 0 When 1 ---- ------------- --------------- 0 Dot matrix Daisy wheel 1 Color device Monochrome device 2 Atari printer "Epson" printer 3 Draft mode Final mode 4 Parallel port RS232 port 5 Form-feed Single sheet 6 reserved 7 reserved 8 reserved 9 reserved 10 reserved 11 reserved 12 reserved 13 reserved 14 reserved 15 Must be zero Example move #%000100,-(sp) Epson comaptible printer move #33,-(sp) trap #14 addq.l #4,sp (34) kbdvbase Get keyboard vector table LONG kbdvbase() D0 returns a pointer to interrupt routines that handle input routines with vector structure like this: 0 LONG midivec MIDI-input 4 LONG vkbderr keyboard error 8 LONG vmiderr MIDI error 12 LONG statvec ikbd status packet 16 LONG mousevec mouse packet 20 LONG clockvec clock packet 24 LONG joyvec joystick packet 24 LONG midisys system MIDI vector 32 LONG ikbdsys system IKBD vector 'midivec' is initialized to point to a buffering routine in the BIOS. D0.B will contain a charac- ter read from the MIDI port. 'vkbderr' and 'vmiderr' are called whenever an overrun condition is detected on the keyboard or MIDI 6850s. 'statvec', 'mousevec', 'clockvec', and 'joyvec' point to ikbd status, mouse, real-time clock, and joystick packet handlers. The packet handlers are passed a pointer to the packet received in A0, and on the stack as a LONG. GEM/GSX uses the mouse vector. Handlers should return with an RTS, and should not spend more than 1ms handling the interrupt. The 'midisys' and 'ikbdsys' vectors are called when characters are available on the appropriate 6850. Initially they point to default routines (the MIDI handler indirects through 'midivec', and the ikbd handler parses-out ikbd packets and calls the appropriate subsystem vectors). Example move #34,-(sp) trap #14 addq.l #2,sp (35) kbrate Set keyboard repeat rate WORD kbrate(initial, repeat) WORD initial, repeat; Get/set the keyboard's repeat rate. 'initial' governs the initial delay (before key-repeat starts). 'repeat' governs the rate at which key-repeats are generated. If a parameter is -1 ($FFFF) it is not changed. Times are based on system ticks (50hz). Returns the old key-repeat values, with 'initial' in the high byte of the low word and 'repeat' in the low byte of the low word. Example move #-1,-(sp) move #-1,-(sp) move #35,-(sp) trap #14 addq.l #2,sp (36) _prtblk Print graphics block to printer VOID _prtblk() Prtblk() To use this the system variable 'prtcnt' must be set to 1. When 'prtblk' is finished the 'prtcnt' will = -1. 'prtcnt' can only be altered in suervisor mode. 'prtblk' is a pointer to a structure with the following format: long address of screen RAM word bit offset from start above address (4) word width in pixels word height in pixels word left margin word right margin word source res word printer res (0 draft, 1 final) long address of colour palette word printer type (0 =Atari mono dmp, 1= Atari daisy 2= atari col dmp 4= Epson comapatible dmp word printer port 0 = parallel 1= RS 232 long address of half-tone table. 0= use ROM based tables (37) vsync VOID vsync() Waits until the next vertical-blank interrupt and returns. Useful for synchronizing graphics operations with vblank. Example move #37,-(sp) trap #14 addq.l #2,sp (38) supexec VOID supexec(codeptr) LONG codeptr; 'codeptr' points to a piece of code, ending in an RTS, that is executed in supervisor mode. The code cannot perform BIOS or GEMDOS calls. This function is meant to allow programs to hack hardware and protected locations without having to fiddle with GEMDOS get/set supervisor mode call. move.l #subroutine,-(sp) move #38,-(sp) trap #14 addq.l #6,sp (39) puntaes VOID puntaes() Throws away the AES, freeing up any memory it used. If the AES is still resident, it will be discarded and the system will reboot. If the AES is not resident (if it was discarded earlier) the function will return. There is NO way to throw away the AES and return -- the reboot MUST be performed. CONOUT Escape Sequences These are the escape functions interpreted by the BIOS' conout() function. For the most part they emulate a VT-52 terminal. There are extensions to hack screen colors, con- trol screen wrap, and a few other simple functions. ESC A Cursor Up This sequence moves the cursor up one line. If the cursor is already on the top line of the screen, this sequence has no effect. ESC B Cursor Down This moves the cursor down one line. If the cursor is already on the last line of the screen, this escape sequence has no effect. ESC C Cursor Forward This moves the cursor one position to the right. If this function would move the cursor off the screen, this sequence has no effect. ESC D Cursor Backward This move the cursor one position to the left. This is a non- destructive move because the character over which the cursor now rests is not replaced by a blank. If the cursor is already in column O, this escape sequence has no effect. ESC E Clear Screen (and Home Cursor) This moves the cursor to column O, row I (the top left-hand corner of the screen), and clears all charac- ters from the screen. ESC H Home Cursor This move the cursor to column O, row O. The screen is NOT cleared. ESC I Reverse Index Moves the cursor to the same horizontal position on the preceding lines. If the cursor is on the top line, a scroll down is performed. ESC J Erase to End of Page Erases all the information from cursor (including cur- sor position) to the end of the page. ESC K Clear to End of Line This sequence clears the line from the current cursor position to the end of the line. ESC L Insert Line Inserts a new blank line by moving the line that cursor is on, end all following lines, down one line. Then, the cursor is moved to the beginning of the new blank line. ESC M Delete Line Deletes the contents of the line that the cursor is on, places the cursor at the beginning of the line, moves all the following lines up one line, and adds a blank line at the bottom. ESC Y Position Cursor The two characters that follow the "Y" specify the row and column to which the cursor is to be moved. The first character specifies the row, the second specifies the colum. Rows and columns number from 1 up. ESC b Set Foreground Color The Foreground Color is the color in which the charac- ter is displayed. Escape-b must be followed by a color selection charac- ter. Only the four least significant bits of the color character are used: Bit Pattern of Control Byte: 7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----+-----+-----+-----+ | | | | | | | X | X | X | X | color index | | | | | | | +-----+-----+-----+-----+-----+-----+-----+-----+ (X = "don't care") ESC c Set Background Color This function selects Background Color, the color of the cell that contains the characters. Escape-c must be followed by a color selection charac- ter. Only the four least significant bits of the color character are used. (See diagram for ESC-b function) ESC d Erase Beginning of Display This sequence erases from beginning of the display to the cursor position. The cursor position is erased also. ESC e Enable Cursor This sequence causes the cursor to be invisible. The cursor may still be moved about on the display, using escape sequence defined in this appendix. ESC f Disable Cursor This sequence causes the cursor to be invisible. The cursor may still be moved about on the display, using escape sequences defined in this appendix. ESC j Save Cursor Position This sequence preserves the current cursor position. You can restore the cursor to the previously saved position with ESC-k. ESC k Restore Cursor Position This sequence restores the cursor to a previously saved position. If you use this sequence without having pre- viously saved the cursor position, then the cursor is moved to the home position, the top left-hand corner of the screen. ESC l Erase Entire Line This sequence erases an entire line and moves the cur- sor to the leftmost column. ESC o Erase Beginning of Line Erases from the beginning of the line to the cursor and includes the cursor position. ESC p Enter Reverse Video Mode Enters the reverse video mode so that characters are displayed as background color characters on a fore- ground colored cell. ESC q Exit Reverse Video Mode Exits the reverse video mode. ESC v Wrap at End of Line This sequence causes the first character past the last displayable position on a line to be automatically placed in the first character position on the next line. The page scrolls up if necessary. ESC w Discard at End of Line Following invocation of this sequence, after the last displayable character on a line has been reached, the characters overprint. Therefore, only the last charac- ter received is displayed in the last column position. Traps, Interrupts and Interrupt Vectors The ST makes use of four of the sixteen TRAP vectors pro- vided by the 68000. All other traps are available for applications. Trap Use ---- ---- 0 (none) 1 GEMDOS interface 2 DOS extensions (GEM, GSX) 3 (none) 4 (none) 5 (none) 6 (none) 7 (none) 8 (none) 9 (none) 10 (none) 11 (none) 12 (none) 13 BIOS 14 Atari BIOS extensions 15 (none) 68901 interrupts are based at $100. The sixteen longwords at this location are bound by the hardware to: Vector Function $100 (disabled) Parallel port int. $104 (disabled) RS232 Carrier Detect $108 (disabled) RS232 Clear-To-Send $10c (disabled) $110 (disabled) $114 200hz System clock $118 Keyboard/MIDI [6850] $11c (disabled) Polled FDC/HDC $120 HSync (initially disabled) $124 RS232 transmit error $128 RS232 transmit buffer emtpy $12c RS232 receive error $130 RS232 receive buffer full $134 (disabled) $138 (disabled) RS232 ring indicator $13c (disabled) Polled monitor type The divide-by-zero vector is pointed at an RTE. All other traps (Bus Error, et al) are pointed at a handler that dumps the processor state and attempts to terminate the current process. [See: System Initialization] The Line 1010 ("Line Aye") vector is used as a short-circuit around the VDI to the ST's graphics primitives. It is a powerful and useful interface; see the `Line A' document for further information. The Line 1111 ("Line Eff") trap is currently being used internally to the system. If you fiddle with this vector the AES will break. System Variables This is a list of variables in the ST BIOS that have been "cast in concrete". Their locations and meanings in future revisions of the ST BIOS are guarenteed not to change. Any other variables in RAM, routines in the ROM, or vec- tors below $400 that are not documented here are almost certain to change. It is important not to depend on undocumented variables or ROM locations. etv_timer (long) $400 Timer handoff vector (logical vector $100). etv_critic (long) $404 Critical error handoff vector (logical vector $101). etv_term (long) $408 Process-terminate handoff vector (logical vector $102). etv_xtra (longs) $40c Space for logical vectors $103 through $107). memvalid (long) $420 Contains the magic number $752019F3, which (together with 'memval2') validates 'memcntlr' and indicates a successful coldstart. memcntlr (byte) $424 Contains memory controller configuration nibble (the low nibble). For the full story, see the hardware manual. Some popular values are: Memory size Value 128K 0 512K 4 256K (2 banks) 0 1MB (2 banks) 5 resvalid (long) $426 If 'resvalid' is the magic number $31415926 on system RESET, the system will jump though 'resvector'. resvector (long) $42a System-RESET bailout vector, valid if 'resvalid' is a magic number. Called early-on in system initializa- tion (before /any/ hardware registers, including the memory controller configuration register, have been touched). A return address will be loaded into A6. Both stack pointers will contain garbage. phystop (long) $42e Physical top of RAM. Contains a pointer to the first unusable byte (i.e. $80000 on a 512K machine). _membot (long) $432 Bottom of available memory. The 'getmpb' BIOS func- tion uses this value as the start of the GEMDOS TPA. _memtop (long) $436 Top of available memory. The 'getmpb' BIOS function uses this value as the end of the GEMDOS TPA. memval2 (long) $43a Contains the magic number $237698AA which (together with 'memvalid') validates 'memcntlr' and indicates a successful coldstart. flock (word) $43e Used to lock usage of the DMA chip. Should be nonzero to ensure that the OS does not touch the DMA chip registers during vertical blank. Device-driver writers TAKE NOTE: this variable MUST be nonzero in order to make use of the DMA bus. seekrate (word) $440 Default floppy seek rate. Bits zero and one contain the default floppy disk seek rate for both drives: 00 6ms 01 12ms 10 2ms 11 3ms [default] _timr_ms (word) $442 System timer calibration (in ms). Should be $14 (20 decimal), since the timer handoff vector is called at 50hz. Returned by BIOS function '_tickcal', and passed on the stack to the timer handoff vector. _fverify (word) $444 Floppy verify flag. When nonzero, all writes to floppies are read-verified. When zero, no write- verifies take place. The default state (after system-reset) is to verify. _bootdev (word) $446 Contains the device number the system was booted from. The BIOS constructs an enviroment string from this variable before bringing up the desktop. palmode (word) $448 When nonzero, indicates the system is in PAL (50hz video) mode. When zero, indicates the system is in NTSC (60hz video) mode. defshiftmd (byte) $44a Default video resolution. If the system is forced to change from monochrome mode to a color resolution, 'defshiftmd' contains the resolution the system will switch to. sshiftmd (word) $44c Contains shadow for 'shiftmd' hardware register: 0 320x200x4 (low resolution) 1 640x200x2 (medium rez) 2 640x400x1 (high rez / "monochrome") _v_bas_ad (long) $44e Pointer to base of screen memory. Always on a 512- byte boundary. Always points to 32K of contiguous memory. vblsem (word) $452 Semaphore to enforce mutual exclusion in vertical- blank interrupt handler. Should be '1' to enable vblank processing, nvbls (word) $454 Number of longwords that '_vblqueue' points to. (On RESET, defaults to 8). _vblqueue (long) $456 Pointer to a vector of pointers to vblank handlers. colorptr (long) $45a Pointer to a vector of 16 words to load into the hardware palette registers on the next vblank. If NULL, the palettes are not loaded. 'colorptr' is zeroed after the palettes are loaded. screenpt (long) $45e Pointer to the base of screen memory, to be setup on the next vblank. If NULL, the screen base is not changed. _vbclock (long) $462 Count of vertical-blank interrupts. _frclock (long) $466 Count of vertical-blank interrupts that were pro- cessed (not blocked by 'vblsem'). hdv_init (long) $46a Vector to hard disk initialization. NULL if unused. swv_vec (long) $46e The system follows this vector when it detects a transition on the "monochrome monitor detect" input (from low to high rez, or visa-versa). 'swv_vec' initially points to the system reset handler; there- fore the system will reset if the user changes moni- tors. hdv_bpb (long) $472 Vector to routine to return a hard disk's Bios Param- eter Block (BPB). Same calling conventions as the BIOS function for GETBPB. NULL if unused. hdv_rw (long) $476 Vector to routine to read or write on a hard disk. Same calling conventions as the BIOS function for RWABS. NULL if unused. hdv_boot (long) $47a Vector to routine to boot from hard disk. NULL if unused. hdv_mediach (long) $47e Vector to routine to return a hard disk's media change mode. Same as BIOS binding for floppies. NULL if unused. _cmdload (word) $482 When nonzero an attempt is made to load and execute COMMAND.PRG from the boot device. (Load a shell or an application in place of the desktop). Can be set to nonzero by a boot sector. conterm (byte) $484 Contains attribute bits for the console system: Bit Function 0 nonzero: enable bell when ^G is written to CON: 1 nonzero: enable key-repeat 2 nonzero: enable key-click 3 nonzero: on BIOS conin() function, return the current value of 'kbshift' in bits 24..31 of D0.L. zero: leave bits 24..31 alone... themd (long) $48e Filled in by the BIOS on a 'getmpb' call; indicates to GEMDOS the limits of the TPA. savptr (long) $4a2 Pointer to register save area for BIOS functions. _nflops (word) $4a6 Number of floppy disks actually attached to the sys- tem (0, 1, or 2). sav_context (long) $4ae Pointer to saved processor context (more on this later). _bufl (long) $4b4 Two (GEMDOS) buffer-list headers. The first list buffers data sectors, the second list buffers FAT and directory sectors. Each of these pointers points to a BCB (Buffer Control Block). _hz_200 (long) $4bc Raw 200hz system timer tick. Used to divide-by-four for a 50hz system timer. the_env (byte[4]) $4be The default enviroment string. Four bytes of $00.... _drvbits (long) $4c4 32-bit vector, returned by the "DRIVEMAP" BIOS func- tion (#10), of "live" block devices. If any floppies are attached, this value is 3. _dskbufp (long) $4c6 Points to a 1024-byte disk buffer somewhere in the system's BSS. The buffer is ALSO used for some GSX graphics operations, and should not be used by inter- rupt routines. _prt_cnt (word) $4ee Initialized to -1. Pressing the ALT-HELP key incre- ments this. The screen dump code checks for $0000 to start imaging the screen to the printer, and checks for nonzero to abort the screen print. _sysbase (long) $4f2 Points to the base of the OS (in ROM or RAM). _shell_p (long) $4f6 Points to shell-specific context. end_os (long) $4fa Points just past the last byte of low RAM used by the operating system. This is used as the start of the TPA (end_os is copied into _membot). exec_os (long) $4fe This points to the shell that gets exec'd by the BIOS after system initialization is complete. Normally this points to the first byte of the AES' text seg- ment. If a diagnostic cartridge is not inserted, all "unused" interrupt vectors are pointed to a handler in the BIOS that saves the processor's state in low memory (see below) and displays a number of icons in the middle of the screen. The handler attempts to restart the system after the crash -- it is not always (honestly: it isn't very often) successful. The processor state is saved in an area of memory that is NOT touched by a system reset. Therefore it is possible to examine a post-mortem dump after resetting the system to reboot. *+ * Post-mortem dump area; * processor state saved here on uncaught exception: * *- proc_lives equ $380 ; $12345678 iff valid proc_dregs equ $384 ; saved D0-D7 proc_aregs equ $3a4 ; saved A0-A6, supervisor A7 (SSP) proc_enum equ $3c4 ; first byte is exception # proc_usp equ $3c8 ; saved user A7 proc_stk equ $3cc ; sixteen words popped from SSP If the longword at $380 is the magic number $12345678, then the following information is valid (unless it's been stepped on by another crash). D0-D7, A0-A6, and the supervisor A7 are copied to loca- tions $384 to $3c0. The exception number (2 for bus error, etc.) is recorded in the byte at $3c4. The user A7 is copied to $3c8. The first sixteen words at the supervisor A7 are copied to the sixteen words starting at $3cc. ERROR NUMBERS Error numbers are returned by certain BIOS and most GEM- DOS functions. Note that some GEMDOS functions return WORD error numbers instead of LONG ones (that is, bits 16..31 of D0.L are garbage). 0 (OK) Successful action (the anti-error). -1 (ERROR) All-purpose error. -2 (DRIVE_NOT_READY) Device was not ready, or was not attached, or has been busy for a long time. -3 (UNKNOWN_CMD) Device didn't know about a command. -4 (CRC_ERROR) Soft error while reading a sector. -5 (BAD_REQUEST) Device couldn't handle a command (the command might be valid in other contexts). Command parameters may be bad. -6 (SEEK_ERROR) Drive couldn't seek. -7 (UNKNOWN_MEDIA) Attempt to read foriegn media (usually means a cor- rupted or zero boot sector). -8 (SECTOR_NOT_FOUND) Sector could not be located. -9 (NO_PAPER) Printer is out of paper (this cannot happen on disks, right?) -10 (WRITE_FAULT) Failure on a write operation. -11 (READ_FAULT) Failure on a read operation. -12 (GENERAL_MISHAP) Reserved for future catastrophes. [This seems to be a useless error right now.] -13 (WRITE_PROTECT) Attempt to write on write-protected or write-only media. -14 (MEDIA_CHANGE) Media changed since last write -- the operation (read or write) did NOT take place. (This is more a mes- sage to the file system than a real error). -15 (UNKNOWN_DEVICE) Operation specified a device the BIOS doesn't know anything about. -16 (BAD_SECTORS) Format operation succeeded (for the most part) but yielded bad sectors. -17 (INSERT_DISK) Ask user to insert a disk (this is more a message to the shell -- GEM or COMMAND.PRG -- to start a dialogue with the user). GEMDOS CALLS Functions are available through trap #1. The first number is the trap number (first word on the stack when the trap is made). The function's name is next, along with the named arguments. The number in brackets is the number of bytes that must be cleaned up off the stack after the call is made. The argument declarations (if any) follow the first line. Then a short description of the function is given. In general, GEMDOS calls return LONGs in D0. However, there are exceptions. When testing for error returns, it is best to examine D0.W only. In addition, GEMDOS may occasionally return BIOS error numbers (that is, between -1 and -31). In C literature STDIN usually refers to console, STDOUT usually refers to screen, or console. $00 Pterm0() [2] Terminate process (with return code of $0). But use pterm #$4c in preference. $01 Cconin() [2] Return character from keyboard. $02 Cconout(chr) [4] char chr; Write character to console. $03 Cauxin() [2] Return character from RS 232. $04 Cauxout(chr) [4] char chr; Write character to RS 232. $05 Cprnout(chr) [4] char chr; Write character to PRINTER. $06 Crawio(wrd) [4] WORD wrd; If (wrd equals 0x00ff) return char from KEYBOARD If (wrd does not equal 0x00ff) print it on SCREEN; Importnat feature of this function is that it does not wait for a key press. EXAMPLE: start: move #$ff,-(sp) move #5,-(sp) trap #1 addq.l #4,sp tst d0 beq start ; go to start if keyboard has not been used $07 Crawcin() [2] Return character from keyboard (without echo). Character is not shown on screen. $08 Cnecin() [2] Read char from keyboard without echo. Control characters (^S, ^Q, ^C) are interpreted and have effect. $09 Cconws(str) [6] char *str; Write null-terminated string to screen. $0a Cconrs(buf) [6] char *buf; Read edited string from keyboard. On entry, buf[0] contains size of data part of buf[]. On exit, buf[1] contains number of characters in data part of buf[]. The data part of buf[] starts at buf[2]. $0b Cconis() [2] Return -1 [nonzero] if character is available in keyboard buffer, 0 otherwise. $0e Dsetdrv(drv) [4] WORD drv; Select current drive (0=A:, 1=B:, etc.). Returns a bitmap of drives in the system (bit 0 = A, ....) in register d0. $10 Cconos() [2] Returns -1 [nonzero] if console is ready to receive a character, 0 if it is "unavailable." $11 Cprnos() [2] Returns -1 [nonzero] if parallel printer is ready to receive a character, 0 if it is "unavailable." $12 Cauxis() [2] Returns -1 [nonzero] if char is available on RS 232, 0 otherwise. $13 Cauxos() [2] Returns -1 [nonzero] if RS 232 is ready to receive a character, 0 if it is "unavailable." $19 Dgetdrv() [2] Returns number of current drive (0=A:, etc.) $1a Fsetdta(ptr) [6] LONG ptr; Set disk transfer address (used by Fsfirst()). This is the address of a 44 byte buffer. $20 Super(stack) [6] LONG stack; Hack processor privelege mode. If 'stack' is -1L, return 0 or 1 (processor is in user or supervisor mode). If in user mode, switch to supervisor mode and use 'stack' as the supervi- sor stack (or the value from USP if 'stack' is NULL). If in supervisor mode, switch to user mode and use 'stack' as the supervisor stack. Return the old supervisor stack value. Example clr.l -(sp) move #$20,-(sp) trap #1 addq.l #6,sp move.l d0,save_sp * do some stuff in supervisor mode * restore old stack pointer move.l save_sp,-(sp) move #$20,-(sp) trap #1 addq.l #6,sp $2a Tgetdate() [2] Returns date: bits 0..4 day 1..31 5..8 month 1..12 9..15 year 0..119 since 1980 $2b Tsetdate(date) [4] WORD date; Set date in the format described above. $2c Tgettime() [2] Return time in the format: bits 0..4 second 0..59 (2-second resolution) 5..10 minute 0..59 11..15 hour 0..23 $2d Tsettime(time) [4] WORD time; Set time in the format described above. $2f Fgetdta() [2] Return current DTA. $30 Sversion() [2] Return current version number. $31 Ptermres(keep, ret) [8] LONG keep; WORD ret; Terminate and stay resident. 'keep' has number of bytes to keep in the process descriptor. 'ret' is the process' return code. $36 Dfree(buf, drv) [] LONG buf; WORD drv; Return information about allocation on drive 'drv' (0=current, 1=A:, 2=B:, etc.). 'buf' points to a structure where stuff will be returned: LONG b_free; #free clusters on drive LONG b_total; total #clusters on drive LONG b_secsiz; #bytes in a sector LONG b_clsiz; #sectors in a cluster $39 Dcreate(path) [6] char *path; Create a directory. $3a Ddelete(path) [6] char *path; Delete a directory. $3b Dsetpath(path) [6] char *path; Set current directory. $3c Fcreate(name, attr) [8] char *name; WORD attr; Create a file with the given pathname. Returns a handle or a (negative) error#. Bits in the attribute word are: $01 set to read only $02 hidden from directory search $04 system file, hidden from dir search $08 volume label (first 11 bytes of name) $3d Fopen(name, mode) [8] char *name;; WORD mode; Open a file. Mode is 0, 1 or 2 for read, write, and read/write. Returns a handle or a (negative) error. $3e Fclose(handle) [4] WORD handle; Close the file with handle from open. $3f Fread(handle, count, buf) [12] WORD handle; LONG count; char *buf; Read bytes from a file. Return count read, or a negative error. $40 Fwrite(handle, count, buf) [12] WORD handle; LONG count; char *buf; Write bytes to a file. Return count written, or a negative error. $41 Fdelete(name) [6] char *name; Delete the file. $42 Fseek(offset, handle, mode) [10] LONG offset; WORD handle; WORD mode; Seek within the file (handle). 'offset' is the (signed) number of bytes to seek by. Mode is one of: 0 from beginning of file 1 from current position 2 from end of file $43 Fattrib(path, mode, mode) [10] Get file attributes if 'mode' is 0, set them if 'mode' is 1. Bits are: $01 read only $02 hidden $04 system (hidden hidden) $08 volume label $10 subdirectory $20 written to and closed $45 Fdup(stdhandle) [4] WORD stdhandle; Returns non-standard handle that refers to the same file. $46 Fforce(stdhandle, nonstdhandle) [6] WORD stdhandle; WORD nonstdhandle; Force standard handle to point to same file or dev as the nonstandard handle. $47 Dgetpath(pathbuf, drv) [8] char *pathbuf; WORD drv; Return current directory for drive 'drv' (0=default, 1=A:, etc.) in the buffer. Buffer must be at least 64 bytes long. $48 Malloc(amount) [6] LONG amount; 'amount' contains # bytes to allocate (or -1, which returns maximum available memory). Return pointer to block (on word boundary) of 'amount' bytes, or zero on allocation failure. $49 Mfree(addr) [6] char *addr; Free a block of memory. Nonzero return on failure. $4a Mshrink(zero, mem, size) [12] WORD zero; LONG mem; LONG size; 'zero' must be a word containing 0. 'mem' con- tains beginning of memory block. 'size' is the the amount of memory to RETAIN in the block. Nonzero return on failure. $4b Pexec(mode, path, commandline, enviroment) [16] WORD mode; char *path; char *commandline; char *enviroment; 'mode' is one of: 0 load and go 3 just load 4 create basepage 5 just go 'commandline' is the command tail, which is copied into the basepage. 'enviroment' is the enviroment string; if NULL, the parent process' enviroment string is inheirited. For mode 0, the return code is the child's return code, or a negative (OS) error. If the load or create-basepage fails, a negative error number is returned. $4c Pterm(code) [4] WORD code; Terminate current process, returning 'code' to the parent. This should be used in preference to pterm0. $4e Fsfirst(spec, attr) [8] char *spec; WORD attr; 'attr' is a set of attributes to match (see function #43 for details). 'spec' may contain wildcard characters in the filename, but not in the pathname. Returns 0 if a file is found, EFILNF if no file was found. Dumps stuff into the DTA: bytes 0..20 junk 21 file attributes 22-23 file time stamp 24-25 file date stamp 26-29 file size (longword) 30-43 name+extension of found file $4f Fsnext() [2] Continue with with Fsfirst(). $56 Frename(zero, old, new) [12] WORD zero; char *old; char *new; Change the name of a file from 'old' to 'new'. 'zero' is reserved, and must be 0. $57 Fdatime(handle, buf, set) [10] WORD handle; char *buf; WORD set; 'buf' points to buffer containing file date and time information. 'handle' is a handle to the file. If 'set' is zero, get the time and date. If 'set' is 1, set the file time and date. * End of file