home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI09.ARJ / ictari.09 / ASSEMBLY / MACROS / MACRO_2 / MACRO_V1.I < prev    next >
Text File  |  1994-01-03  |  52KB  |  1,984 lines

  1. *****************
  2. * MACRO LIBRARY *
  3. *  by S.H.Rigby *
  4. *  Version 1.02 *
  5. *    26/06/93   *
  6. *****************
  7.     INCLUDE    equates.i
  8.     INCLUDE    errors.i
  9.     INCLUDE    bios.i
  10.     INCLUDE    xbios.i
  11.     INCLUDE    gemdos.i
  12.     INCLUDE    traps.i
  13.     INCLUDE intmath.i
  14.     
  15. * CHARACTER DEVICE I/O ROUTINES
  16. *******************************
  17. * PRT,AUX,CON,MIDI,KBD,RAW are valid devices 0-5
  18. * Valid operations:
  19. * Operation    PRT AUX CON MIDI KBD RAW
  20. * --------------------------------------
  21. * Bconstat    no  yes yes yes  no  no
  22. * Bconin    yes yes yes yes  no  no
  23. * Bconout    yes yes yes yes  yes yes
  24. * Bcostat    yes yes yes yes  yes no
  25. * Midi has I/O buffer of 80-128 bytes only!
  26. * Keyboard I/O buffer is 128 bytes
  27. * RS-232 I/O buffer is 256 bytes
  28. * KBD is output only for configuring keyboard
  29. * RAW outputs all characters to screen with no interpretation
  30. *
  31. * Note: PARALLEL interrupt available at $100 - see traps.i
  32. *       RS232 Carrier Detect, Clear to Send, TX Error, RX Error, Ring,
  33. *             TX Next char and RX Next char Interrupts are available
  34. *       KBD/MIDI combined interrupt available     
  35. * see traps.i for more info
  36. * see conterm for keyboard functions in equates.i
  37. * see xconstat, xconin, xcostat, xconout vectors in OS variables in equates.i
  38.  
  39. * Read character from device
  40. *    see equates.i for devices
  41. *    waits for input
  42. *    only devices 1-3 valid
  43. *    CON returns IBM compatible scancode in low byte of high word
  44. *    if bit 3 of Conterm is set, returns shift status in high byte
  45. *    of high word. default state is off.
  46. *    All other devices only return the character value
  47. Bconin    MACRO    device
  48.     move.w    \1,-(sp)
  49.     move.w    #bconin,-(sp)
  50.     trap    BIOS
  51.     addq.w    #4,sp
  52.     ENDM    d0.l=[$00/Shift_code][Scan_code][$00][Char]
  53.  
  54. * Write character to device
  55. *    see equates.i for devices
  56. *    Devices 0-4 to send to
  57. *    waits for completion of output before return
  58. *    PRT returns 0 for fail and !0 for success
  59. *    letter is low byte of word
  60. Bconout    MACRO    device.w,letter.b
  61.     clr.w    -(sp)
  62.     move.b    \2,1(sp)
  63.     move.w    \1,-(sp)
  64.     move.w    #bconout,-(sp)
  65.     trap    BIOS
  66.     addq.w    #6,sp
  67.     ENDM
  68.  
  69. * Device ready to read    (true/false)
  70. *    use CON,AUX or MIDI (1,2 or 3)
  71. *    see equates.i for devices
  72. *    MIDI has interrupt driven input buffer of 80 chars
  73. Bconstat    MACRO    device
  74.     move.w    \1,-(sp)
  75.     move.w    #bconstat,-(sp)
  76.     trap    BIOS
  77.     addq.w    #4,sp
  78.     ENDM    d0.l=0 or -1 (no char ready/char ready)
  79.  
  80. * Device ready to write    (true/false)
  81. *    BUG: 3 is KBD, 4 is MIDI - compensated for in code
  82. Bcostat    MACRO    device
  83.     cmp.w    #3,\1
  84.     bne    .a\@
  85.     addq.w    #1,\1    ;MIDI has to be 4
  86.     bra    .b\@
  87. .a\@    cmp.w    #4,\1
  88.     bne    .b\@
  89.     subq.w    #1,\1    ;KBD has to be 3
  90. .b\@    move.w    \1,-(sp)
  91.     move.w    #bcostat,-(sp)
  92.     trap    BIOS
  93.     addq.w    #4,sp
  94.     ENDM    d0.l=0 or -1 (not ready/ready to rcve char)
  95.  
  96. * Reset Keyboard Translation Tables to Power up defaults
  97. *        see Keytbl for setting tables
  98. Bioskeys    MACRO    
  99.     move.w    #bioskeys,-(sp)
  100.     trap    XBIOS
  101.     addq.w    #2,sp
  102.     ENDM    
  103.  
  104. * Read character from serial port (handle 1) - wait if not ready
  105. *    NO FLOW CONTROL ON THIS - USE BCONIN WITH BCONSTAT!
  106. *    else maybe lose received characters
  107. Cauxin    MACRO    
  108.     move.w    #c_auxin,-(sp)
  109.     trap    GEMDOS
  110.     addq.w    #2,sp
  111.     ENDM    d0.b=ASCII
  112.  
  113. * Serial Port ready to read (true/false) (handle 1)
  114. Cauxis    MACRO    
  115.     move.w    #c_auxis,-(sp)
  116.     trap    GEMDOS
  117.     addq.w    #2,sp
  118.     ENDM    d0.l=-1 if key ready, else 0
  119.  
  120. * Serial Port ready to write (true/false) (handle 1)
  121. Cauxos    MACRO    
  122.     move.w    #c_auxos,-(sp)
  123.     trap    GEMDOS
  124.     addq.w    #2,sp
  125.     ENDM    d0.l=-1 if ready for key, else 0
  126.  
  127. * Write character to serial port
  128. *    waits for key to be sent
  129. *    tabs are not expanded
  130. *    NO FLOW CONTROL ON THIS - USE BCONOUT WITH BCOSTAT!
  131. *    else maybe lose transmitted characters
  132. *    Top Byte of char on stack must be zero - so load byte!
  133. Cauxout    MACRO    character
  134.     clr.w    -(sp)
  135.     move.b    \1,1(sp)
  136.     move.w    #c_auxout,-(sp)
  137.     trap    GEMDOS
  138.     addq.w    #4,sp
  139.     ENDM    
  140.  
  141. * Read Console, echo & return value (handle 0)
  142. *    waits for Keypress
  143. *     scancode only available if handle 0 is still console!
  144. *    bits 24-31    shift status (if conterm bit 3 set) or 0
  145. *    bits 16-23    scancode
  146. *    bits 0-7    ascii
  147. *    Does not return indication of EOF & can't tell if file or device
  148. *    ^C does NOT terminate
  149. *    New TOS can now use ALT+NUMPAD to key ascii code 000-255
  150. Cconin    MACRO    
  151.     move.w    #c_conin,-(sp)
  152.     trap    GEMDOS
  153.     addq.w    #2,sp
  154.     ENDM    d0.b=ASCII (swap d0.b)=scancode
  155.  
  156. * Write to Console (handle 0)
  157. *    Tabs are not expanded
  158. *    VT-52 command codes are interpreted as such and hence not printed
  159. *    Top Byte of char word on stack must be zero so stack Byte
  160. Cconout    MACRO    character
  161.     clr.w    -(sp)
  162.     move.b    \1,1(sp)
  163.     move.w    #c_conout,-(sp)
  164.     trap    GEMDOS
  165.     addq.w    #4,sp
  166.     ENDM    
  167.  
  168. * Console ready to read (true/false)
  169. *    Since consoles & files are always ready - check not needed!
  170. *    Unless re-routed!
  171. Cconis    MACRO    
  172.     move.w    #c_conis,-(sp)
  173.     trap    GEMDOS
  174.     addq.w    #2,sp
  175.     ENDM    d0.l=-1 if key ready, else 0
  176.  
  177. * Console ready to send (true/false)
  178. Cconos    MACRO    
  179.     move.w    #c_conos,-(sp)
  180.     trap    GEMDOS
  181.     addq.w    #2,sp
  182.     ENDM    d0.l=-1 if key ready, else 0
  183.  
  184.  
  185. * Read string from console (handle 0)
  186. *    echoes chars to screen
  187. *    buffer[0]=length of buffer (entered by YOU),
  188. *    buffer[1]=string length (entered by it)
  189. *    string non-terminated
  190. *    HANGS ON EOF if file
  191. *    ^M or [RETURN] ends the line (with CR)
  192. *    ^J ends the line (with LF)
  193. *    ^H or [BS] kills last character
  194. *    ^U kills line (skip to next line)
  195. *    ^X kills line (erase to start of line)
  196. *    ^R (skip to next line) retypes line
  197. *    ^C terminates program
  198. *    ^I is a Tab
  199. Cconrs    MACRO    input_buffer
  200.     move.l    \1,-(sp)
  201.     move.w    #c_conrs,-(sp)
  202.     trap    GEMDOS
  203.     addq.w    #6,sp
  204.     ENDM
  205.  
  206. * Write string to Console
  207. *    string is null terminated
  208. *    VT-52 commands are interpreted
  209. Cconws    MACRO    string_address
  210.     move.l    \1,-(sp)
  211.     move.w    #c_conws,-(sp)
  212.     trap    GEMDOS
  213.     addq.w    #6,sp
  214.     ENDM    d0=number of chars printed
  215.  
  216. * Read string from Console, no echo
  217. *    wait for keypress
  218. *    ^s pause output
  219. *    ^q resume output
  220. *    ^c terminate program
  221. *    these control codes may not work on very early TOS's
  222. *    they would then be passed back to program instead
  223. Cnecin    MACRO    
  224.     move.w    #c_necin,-(sp)
  225.     trap    GEMDOS
  226.     addq.w    #2,sp
  227.     ENDM    d0.l=keyvalue (^s,^q,^c active)
  228.  
  229. * Parallel port ready to write (true/false)
  230. Cprnos    MACRO    
  231.     move.w    #c_prnos,-(sp)
  232.     trap    GEMDOS
  233.     addq.w    #2,sp
  234.     ENDM    d0.l=-1 if ready, else 0
  235.  
  236. * Write character to Parallel Port
  237. *    if cannot send, fails after time-out period
  238. *    waits for char to be sent
  239. *    tabs are not expanded
  240. *    Top Byte of char on stack must be zero, so stack byte only
  241. Cprnout    MACRO    character
  242.     clr.w    -(sp)
  243.     move.b    \1,1(sp)
  244.     move.w    #c_prnout,-(sp)
  245.     trap    GEMDOS
  246.     addq.w    #4,sp
  247.     tst.w    d0
  248.     bne    .\@
  249.     Error    Printer_err_msg
  250. .\@    
  251.     ENDM    d0.w=>0=fail,-1=o.k.
  252.  
  253. * Read character from keyboard, no echo (handle 0)
  254. *    wait for keypress
  255. *    passes all control codes to program
  256. *    no EOF indication
  257. Crawcin    MACRO
  258.     move.w    #c_rawcin,-(sp)
  259.     trap    GEMDOS
  260.     addq.w    #2,sp
  261.     ENDM    d0.l=keyvalue (d0.b=char and swap d0.b=scancode)
  262.  
  263. * Raw I/O to/from keyboard/screen (no wait)
  264. *    VT-52 codes are interpreted
  265. *    tabs are not expanded
  266. *    cannot write 255 to screen
  267. *    d0.w=$00 is EOF or NO CHAR ready on input
  268. Crawio    MACRO    character or $00ff to read
  269.     clr.w    -(sp)
  270.     move.b    \1,1(sp)
  271.     move.w    #c_rawio,-(sp)
  272.     trap    GEMDOS
  273.     addq.w    #4,sp
  274.     ENDM    d0.w=keyscan_code/ASCII or 0 for no key - if reading
  275.  
  276. * Set Cursor Blink Mode & Rate
  277. *        See equates.i for Blink Modes
  278. *        Don't need rate for modes 0-3
  279. *        Rate is (Blinks-per-sec * frame-freq)/2
  280. *        Rate set is cursor on time
  281. *        Rate of zero is 256 - Range 0-255
  282. *        Default rate is 30
  283. *        GET_BLINK_RATE puts Current Rate in low byte of d0
  284. Cursconf    MACRO    mode,rate
  285.         IFEQ    NARG-2
  286.         move.w    \2,-(sp)
  287.         ENDC
  288.         move.w    \1,-(sp)
  289.         move.w    #cursconf,-(sp)
  290.         trap    XBIOS
  291.         IFEQ    NARG-2
  292.         addq.w    #6,sp
  293.         ELSE
  294.         addq.w    #4,sp
  295.         ENDC
  296.         ENDM    d0.b = old_rate if mode is GET_BLINK_RATE (5)
  297.             ;otherwise d0.b is junk
  298.  
  299. * Write string to Intelligent Keyboard Controller
  300. *    count is string length-1
  301. Ikbdws    MACRO    count,string_ptr
  302.     move.l    \2,-(sp)
  303.     move.w    \1,-(sp)
  304.     move.w    #ikbdws,-(sp)
  305.     trap    XBIOS
  306.     addq.w    #8,sp
  307.     ENDM
  308.  
  309. * Input (& output) Buffer tables
  310. *    device 0 = RS232
  311. *    device 1 = Console
  312. *    device 2 = MIDI
  313. *    ADDED 1 TO DEVICE TO ALLOW COMPATIBILITY WITH OTHER DEVICE CALLS
  314. *    see equates.i for structure of I/O record
  315. *    rs232 output buffer follows on from input buffer
  316. *    flow control says stop at high water & start at low water
  317. Iorec    MACRO    device
  318.     move.w    \1,-(sp)
  319.     addq.w    #1,(sp)    ;maintain normal device numbers
  320.     move.w    #iorec,-(sp)
  321.     trap    XBIOS
  322.     addq.w    #4,sp
  323.     ENDM    d0.l=input buffer record address
  324.  
  325. * Get/set Keyboard Repeat rate
  326. *    -1 will LEAVE value unchanged
  327. *    times are in system ticks (50Hz)
  328. Kbrate    MACRO    delay_rate, repeat_rate
  329.     move.w    \2,-(sp)
  330.     move.w    \1,-(sp)
  331.     move.w    #kbrate,-(sp)
  332.     trap    XBIOS
  333.     addq.w    #6,sp
  334.     ENDM    d0.w=delay/repeat <high/low byte>
  335.  
  336. * Set/Get keyboard state of shift-keys
  337. *    mode is state to set to or -1 to read
  338. *    see equates.i for bit values
  339. *    shift code result is IBM compatible
  340. Kbshift    MACRO    mode(+ve/-ve)
  341.     move.w    \1,-(sp)
  342.     move.w    #kbshift,-(sp)
  343.     trap    BIOS
  344.     addq.w    #4,sp
  345.     ENDM    d0.l=Shift_code before any changes here
  346.  
  347. * Set Keyboard Translation Tables
  348. *    Each pointer points to 128 byte table 
  349. *    containing ascii number at scancode position
  350. *    see equates.i for table structure returned (list of pointers)
  351. *    restore to default settings with Bioskeys() 
  352. *    Pass -1 to leave a key table as it is
  353. Keytbl    MACRO    key_tbl,shift_key_tbl,caps_key_tbl
  354.     move.l    \3,-(sp)
  355.     move.l    \2,-(sp)
  356.     move.l    \1,-(sp)
  357.     move.w    #keytbl,-(sp)
  358.     trap    XBIOS
  359.     lea    14(sp),sp
  360.     ENDM    d0.l=pointer to table of three pointers
  361.  
  362. * Write string to MIDI Port
  363. *    count is length of string minus one
  364. Midiws    MACRO    count,string_ptr
  365.     move.l    \2,-(sp)
  366.     move.w    \1,-(sp)
  367.     move.w    #midiws,-(sp)
  368.     trap    XBIOS
  369.     addq.w    #8,sp
  370.     ENDM    
  371.  
  372. * Configure RS232 port
  373. *    -1 means don't set parameter
  374. *    see equates.i for speed table from 19200 to 50 baud
  375. *    see equates.i for flow control table (either XON/XOFF or RTS/CTS)
  376. *    ucr,rsr,tsr,scr set the 68901 registers named
  377. *    ucr=parity, stop bits and data bits
  378. *    see equates.i for values
  379. Rsconf    MACRO    speed,flow_control,ucr,rsr,tsr,scr
  380.     move.w    \6,-(sp)
  381.     move.w    \5,-(sp)
  382.     move.w    \4,-(sp)
  383.     move.w    \3,-(sp)
  384.     move.w    \2,-(sp)
  385.     move.w    \1,-(sp)
  386.     move.w    #rsconf,-(sp)
  387.     trap    XBIOS
  388.     addq.w    #4,sp
  389.     ENDM    d0.l=old ucr/rsr/tsr/scr 
  390.  
  391. * Get/Set Printer Configuration
  392. *    Get config if config_word=-1
  393. *    see equates.i for bit structure of config_word
  394. Setprt    MACRO    config_word
  395.     move.w    \1,-(sp)
  396.     move.w    #setprt,-(sp)
  397.     trap    XBIOS
  398.     addq.w    #4,sp
  399.     ENDM    d0.l=Old_config value
  400.  
  401. * DISK DEVICE I/O ROUTINES (also see FILE ROUTINES)
  402. **************************
  403. * Disk Date & Time formats are same as GEMDOS/XBIOS date & time
  404. * Floppy/Hard disk interrupt available - see traps.i
  405. * critical error vector available for file prompts - see equates.i
  406. * memory variables - see flock, seekrate, fverify, bootdev in equates.i
  407. * hard disk - see hdv_init, hdv_bpb, hdv_rw, hdv_boot, hdv_mediach,
  408. * _nflops, _drvbits, _dskbufp, pun_ptr and _cmdload in equates.i
  409. * variable _bufl points to fat and data buffers
  410.  
  411. * Create a Directory
  412. Dcreate    MACRO    pathname_addr
  413.     move.l    \1,-(sp)
  414.     move.w    #d_create,-(sp)
  415.     trap    GEMDOS
  416.     addq.w    #6,sp
  417.     Gemdos_error    
  418.     ENDM
  419.  
  420. * Delete a Directory
  421. *    Directory must be empty
  422. Ddelete    MACRO    pathname_addr
  423.     move.l    \1,-(sp)
  424.     move.w    #d_delete,-(sp)
  425.     trap    GEMDOS
  426.     addq.w    #6,sp
  427.     Gemdos_error    
  428.     ENDM
  429.  
  430. * Free space on drive
  431. *    see equates.i for table contents
  432. *    slow on hard disks
  433. Dfree    MACRO    table.l,drive_num+1
  434.     move.l    \2,-(sp)
  435.     move.w    \1,-(sp)
  436.     move.w    #d_free,-(sp)
  437.     trap    GEMDOS
  438.     addq.w    #8,sp
  439.     ENDM
  440.  
  441. * Get default drive (0=A)
  442. *    supports drives 0-15 (A:-P:)
  443. Dgetdrv    MACRO    
  444.     move.w    #d_getdrv,-(sp)
  445.     trap    GEMDOS
  446.     addq.w    #2,sp
  447.     ENDM    d0.l=Logical Drives (bit set per drive)
  448.  
  449. * Get Path on any drive
  450. *    current drive=0,a=1,etc.
  451. *    path string length has no limit - use 128 bytes or more
  452. Dgetpath    MACRO    path_buffer,drive
  453.     move.w    \2,-(sp)
  454.     move.l    \1,-(sp)
  455.     move.w    #d_getpath,-(sp)
  456.     trap    GEMDOS
  457.     addq.w    #8,sp
  458.     Gemdos_error    
  459.     ENDM
  460.  
  461. * Bitmap of Logical drives
  462. *    result taken from _drvbits ($4c4) - see equates.i
  463. Drvmap    MACRO
  464.     move.w    #drvmap,-(sp)
  465.     trap    BIOS
  466.     addq.w    #2,sp
  467.     ENDM    do.l=Logical Drives (bit set per drive)
  468.  
  469. * Set default drive (0=A)
  470. *    drives 0-15 valid (A:-P:)
  471. *    only returns drives whose directories have been looked at
  472. Dsetdrv    MACRO    drive_number
  473.     move.w    \1,-(sp)
  474.     move.w    #d_setdrv,-(sp)
  475.     trap    GEMDOS
  476.     addq.w    #4,sp
  477.     ENDM    d0.l=Logical Drives (bit set per drive)
  478.  
  479. * Set Path on current drive
  480. *    do not use a drive letter in pathname
  481. Dsetpath    MACRO    pathname_addr
  482.     move.l    \1,-(sp)
  483.     move.w    #d_setpath,-(sp)
  484.     trap    GEMDOS
  485.     addq.w    #6,sp
  486.     Gemdos_error    
  487.     ENDM
  488.  
  489. * Format Track on floppy disk
  490. *    buffer is word aligned and long enough to hold at least one tracks 
  491. *    worth of sectors
  492. *    skewtable is not used on TOS that cannot skew disks (pre-blitter)
  493. *    it is only used if interleave is -1
  494. *    it is a pointer to a table of sector numbers (word length) in the order
  495. *    they are to be put on disk (sectors_per_track*tracks of them)
  496. *    dev_num is 0 or 1 for floppy A or B
  497. *    interleave is (number of sectors between sector numbers)-1
  498. *    usually set to 1 for sector order 1,2,3,etc
  499. *    magic must be $87654321
  500. *    virgin is the value on blank sectors normally $e5e5
  501. *    high nibble of virgin cannot be $f
  502. *    bad sectors are returned in the buffer, sector numbers in words
  503. *    list is null terminated
  504. *    first word in buffer is zero if no bad sectors
  505. *    bad sectors may not be in numerical order
  506. *    media-definately-changed is recorded
  507. *    Bad sectors should be marked in the FATs
  508. *    Bad sectors in the first two tracks mean disk is unuseable
  509. Flopfmt    MACRO    buffer,skewtable,dev_num,sect_per_track,track_num,side_num,interleave,magic,virgin
  510.     move.w    \9,-(sp)
  511.     move.l    \8,-(sp)
  512.     move.w    \7,-(sp)
  513.     move.w    \6,-(sp)    
  514.     move.w    \5,-(sp)
  515.     move.w    \4,-(sp)
  516.     move.w    \3,-(sp)
  517.     move.l    \2,-(sp)    ;unused on pre-blitter TOS
  518.     move.l    \1,-(sp)
  519.     move.w    #flopfmt,-(sp)
  520.     trap    XBIOS
  521.     lea    26(sp),sp
  522.     Gemdos_error
  523.     ENDM    d0.w=0 or bios error
  524.  
  525. * Read Sectors from floppy disk
  526. *    dummy is not used
  527. *    buffer is word aligned and long enough to hold all sectors read
  528. *    dev_num is 0 or 1 for floppy A or B
  529. *    count must be less than or equal to sectors-per-track
  530. Floprd    MACRO    buffer,dummy,dev_num,sect_num,track_num,side_num,count
  531.     move.w    \7,-(sp)
  532.     move.w    \6,-(sp)    
  533.     move.w    \5,-(sp)
  534.     move.w    \4,-(sp)
  535.     move.w    \3,-(sp)
  536.     move.l    \2,-(sp)    ;unused
  537.     move.l    \1,-(sp)
  538.     move.w    #floprd,-(sp)
  539.     trap    XBIOS
  540.     lea    20(sp),sp
  541.     Gemdos_error
  542.     ENDM    d0.w=0 or bios error
  543.  
  544. * Read & Verify Sectors from floppy disk
  545. *    dummy is not used
  546. *    buffer is word aligned and long enough to hold a cluster (1024 normally)
  547. *    dev_num is 0 or 1 for floppy A or B
  548. *    count must be less than or equal to sectors-per-track
  549. *    bad sectors are returned in the buffer, null terminated
  550. *    first word in buffer is zero if no bad sectors
  551. *    bad sectors may not be in numerical order
  552. Flopver    MACRO    buffer,dummy,dev_num,sect_num,track_num,side_num,count
  553.     move.w    \7,-(sp)
  554.     move.w    \6,-(sp)    
  555.     move.w    \5,-(sp)
  556.     move.w    \4,-(sp)
  557.     move.w    \3,-(sp)
  558.     move.l    \2,-(sp)    ;unused
  559.     move.l    \1,-(sp)
  560.     move.w    #flopver,-(sp)
  561.     trap    XBIOS
  562.     lea    20(sp),sp
  563.     Gemdos_error
  564.     ENDM    d0.w=0 or bios error
  565.  
  566. * Write Sectors to floppy disk
  567. *    dummy is not used
  568. *    buffer is word aligned, holding all sectors to write
  569. *    dev_num is 0 or 1 for floppy A or B
  570. *    count must be less than or equal to sectors-per-track
  571. *    writing to sector 1, track 0, side 0 causes media-maybe-changed status
  572. Flopwr    MACRO    buffer,dummy,dev_num,sect_num,track_num,side_num,count
  573.     move.w    \7,-(sp)
  574.     move.w    \6,-(sp)    
  575.     move.w    \5,-(sp)
  576.     move.w    \4,-(sp)
  577.     move.w    \3,-(sp)
  578.     move.l    \2,-(sp)    ;unused
  579.     move.l    \1,-(sp)
  580.     move.w    #flopwr,-(sp)
  581.     trap    XBIOS
  582.     lea    20(sp),sp
  583.     Gemdos_error
  584.     ENDM    d0.w=0 or bios error
  585.  
  586. * Get bios parameter block for drive (0=A)
  587. *    see equates.i for BPB table format
  588. *    see disk_str.txt for details on usage
  589. *    Returns 0.L if no BPB found!
  590. Getbpb    MACRO    Drivenum
  591.     move.w    \1
  592.     move.w    #getbpb,-(sp)
  593.     trap    BIOS
  594.     addq.w    #4,sp
  595.     ENDM    do.l=bpb_ptr (see equates.i)
  596.  
  597. * Has Disk changed? (0=no/1=maybe/2=yes)
  598. Mediach    MACRO    drivenum (0=A, 1=B, etc)
  599.     move.w    \1,-(sp)
  600.     move.w    #mediach,-(sp)
  601.     trap    BIOS
  602.     addq.w    #2,sp
  603.     ENDM    d0=0-no change/1-might have changed/2-changed
  604.     
  605. * Make a Boot Sector in RAM
  606. *    stored on side 0, track 0 , sector 1
  607. *    buffer may contain a boot sector already and is sector sized!
  608. *    e.g. for making executable boot sectors
  609. *    if serial_num=-1, buffer's serial number is not changed
  610. *    if serial_num>=$01000000 Random number is used
  611. *    otherwise number given is used
  612. *    see equates.i for disk types
  613. *    pass -1 for disk type to leave as is in buffer
  614. *    Exec=1 for executable boot sector
  615. *    exec=0 for non-exec, -1 to leave buffer alone
  616. *    write to disk boot sector when finished
  617. Protobt    MACRO    buffer,Serial_num,Disktype,Execflag
  618.     move.w    \4,-(sp)
  619.     move.w    \3,-(sp)
  620.     move.l    \2,-(sp)
  621.     move.l    \1,-(sp)
  622.     move.w    #protobt,-(sp)
  623.     trap    XBIOS
  624.     lea    14(sp),sp
  625.     ENDM
  626.  
  627. * Read/Write Absolute Sectors
  628. *    see equates.i for modes
  629. *    Drive 0=A, 1=B, etc.
  630. *    used by GEMDOS on first access or media change
  631. *    odd buffer address allowed but slow!
  632. *    mode bit 0 - write when set, else read
  633. *    mode bit 1 - do not check or change media changed status if set
  634. *    mode bit 2 - disable retry if set - AHDI >=V3
  635. *    mode bit 3 - physical sector if set, else logical - AHDI >=V3
  636. *    to use sector>32767, start=-1, long start used for sector - AHDI >=V3
  637. *    buffer length needs to be bytes-per-sector (512 normally) * number of sectors
  638. Rwabs    MACRO    mode,buffer,sectors,start,drivenum,(long start)
  639.     IFEQ    6-NARG
  640.     move.l    \6,-(sp)
  641.     ENDC
  642.     move.w    \5,-(sp)
  643.     move.w    \4,-(sp)
  644.     move.w    \3,-(sp)
  645.     move.l    \2,-(sp)
  646.     move.w    \1,-(sp)
  647.     move.w    #rwabs,-(sp)
  648.     trap    BIOS
  649.     IFEQ    6-NARG
  650.     lea    18(sp),sp
  651.     ELSE
  652.     lea    14(sp),sp
  653.     ENDC
  654.     Gemdos_error
  655.     ENDM    
  656.  
  657. * ERROR ROUTINES
  658. ****************
  659. * critical error vector available - see equates.i
  660.  
  661. * Reports any valid Gemdos or Bios error
  662. *    should be long negative but some functions return word negative
  663. *    so test is done for word negative instead
  664. Gemdos_error    MACRO    error_num in d0
  665.     tst.w    d0    ;-ve=gemdos error
  666.     bpl.s    .\@
  667.     move.w    d0,-(sp)
  668.     neg.w    d0
  669.     lsl.w    #2,d0
  670.     move.l    #BIOS_ERRORS,a0
  671.     move.l    (a0,d0.w),a0
  672.     Error    a0
  673.     move.w    (sp)+,d0
  674. .\@
  675.     ENDM
  676.  
  677. * Reports any short message as an error message
  678. Error    MACRO    err_msge_addr
  679.     IFD    Gem_flag
  680.     Form_alert    0,\1
  681.     ELSE
  682.     Tos_alert    \1
  683.     ENDC
  684.     ENDM
  685.  
  686. * Report error and wait for keypress
  687. Tos_alert    MACRO    err_msge_addr
  688.     Cconws    \1
  689.     Crawcin
  690.     ENDM
  691.  
  692. * FILE MANAGEMENT MACROS
  693. ************************
  694. * Legal Drives: A-P or CON: AUX: PRN: for read/write/open/create/close.
  695. * CON: AUX: PRN: have handles -1,-2,-3 (word length)
  696. * Standard handles are 0-5, 6 and above are file handles
  697. * Media change closes all open handles on that disk
  698. * Legal Pathnames: {A:}{\}{path\}<file>{.}{ext},0
  699. * Path may use '.' & ".." for current and parent
  700. * start with slash to start at root of drive
  701. * no drive to use current drive - no \path to use current directory
  702. * Legal Letters in Filenames: A-Z a-z 0-9 _ ! @ # $ % ^ & ( ) + - = ~ ` ; 
  703. *                              ' " , < > | [ ] { }
  704. * Text files end lines with CR-LF and end files with ^Z
  705. * Disk Date & Time formats are same as GEMDOS/XBIOS date & time
  706.  
  707. * Get/Set File Attributes
  708. *    see equates.i for file attributes
  709. *    archive bit does not work on all GEMDOS
  710. Fattrib    MACRO    filename_addr,get(0)/set(1),attributes
  711.     move.w    \3,-(sp)
  712.     move.w    \2,-(sp)
  713.     move.l    \1,-(sp)
  714.     move.w    #f_attrib,-(sp)
  715.     trap    GEMDOS
  716.     lea    #10(sp),sp
  717.     Gemdos_error    
  718.     ENDM    do.w=new attributes
  719.  
  720. * Close a File
  721. *    Note: PRN,CON & AUX should not be closed
  722. Fclose    MACRO    file_handle
  723.     move.w    \1,-(sp)
  724.     move.w    #f_close,-(sp)
  725.     trap    GEMDOS
  726.     addq.w    #4,sp
  727.     Gemdos_error    
  728.     ENDM    
  729.  
  730. * Create a File
  731. *    see equates.i for attributes
  732. *    do not set read_only on creation as file is only opened for writing!
  733. *    only have one volume label per disk - GEMDOS will allow many!
  734. *    Note: PRN,CON & AUX are already open as file handles
  735. *    but they return -ve handles (words) if opened or created.
  736. *    negative longs indicate true errors
  737. Fcreate    MACRO    path&name_addr,attributes
  738.     move.w    \2,-(sp)
  739.     move.l    \1,-(sp)
  740.     move.w    #f_create,-(sp)
  741.     trap    GEMDOS
  742.     addq.w    #8,sp
  743.     Gemdos_error    
  744.     ENDM    d0.w=file handle or error
  745.  
  746. * Get/Set File Date & Time stamp
  747. *    buffer=time.w,date.w
  748. Fdatime    MACRO    date&time_ptr,handle,get(0)/set(1)
  749.     move.w    \3,-(sp)
  750.     move.w    \2,-(sp)
  751.     move.l    \1,-(sp)
  752.     move.w    #f_datime,-(sp)
  753.     trap    GEMDOS
  754.     lea    10(sp),sp
  755.     ENDM    
  756.  
  757. * Delete a File
  758. Fdelete    MACRO    filename_addr
  759.     move.l    \1,-(sp)
  760.     move.w    #f_delete,-(sp)
  761.     trap    GEMDOS
  762.     addq.w    #6,sp
  763.     Gemdos_error    
  764.     ENDM    
  765.  
  766. * Duplicate a File Handle
  767. *    returns an alternative handle for a standard device
  768. *    see Fforce
  769. Fdup    MACRO    std_handle (0-5)
  770.     move.w    \1,-(sp)
  771.     move.w    #f_dup,-(sp)
  772.     trap    GEMDOS
  773.     addq.w    #4,sp
  774.     Gemdos_error    
  775.     ENDM    d0.w=new_handle
  776.  
  777. * Force a Standard File Handle to alternative handle
  778. *    see Fdup
  779. *    used to redirect standard output
  780. Fforce    MACRO    std_handle,alt_handle
  781.     move.w    \2,-(sp)
  782.     move.w    \1,-(sp)
  783.     move.w    #f_force,-(sp)
  784.     trap    GEMDOS
  785.     addq.w    #6,sp
  786.     Gemdos_error    
  787.     ENDM
  788.  
  789. * Get disk transfer address (WORD ALIGNED)
  790. *    see equates.i for 44 byte buffer
  791. Fgetdta    MACRO
  792.     move.w    #f_getdta,-(sp)
  793.     trap    GEMDOS
  794.     addq.w    #2,sp
  795.     ENDM    d0.l=DTA_Address
  796.  
  797. * Get File Length
  798. Flength    MACRO    file_handle
  799.     Fseek    #1,\1,EOF
  800.     ENDM    d0.l=file length
  801.  
  802. * Open a File
  803. *    see equates.i for mode
  804. *    Note: PRN,CON & AUX are already open as file handles
  805. *    but they return -ve words if opened or created.
  806. *    negative longs indicate true errors
  807. Fopen    MACRO    path&name_addr,open_mode
  808.     move.w    \2,-(sp)
  809.     move.l    \1,-(sp)
  810.     move.w    #f_open,-(sp)
  811.     trap    GEMDOS
  812.     addq.w    #8,sp
  813.     Gemdos_error    
  814.     ENDM    d0.w=file handle or error
  815.  
  816. * Read a File
  817. *    Note: PRN,CON & AUX are already open as file handles
  818. *    if you read past end of file, no error - length(d0) <> requested
  819. *    returns 0 on EOF
  820. Fread    MACRO    file_handle,length,buffer_addr
  821.     move.l    \3,-(sp)
  822.     move.l    \2,-(sp)
  823.     move.w    \1,-(sp)
  824.     move.w    #f_read,-(sp)
  825.     trap    GEMDOS
  826.     lea    12(sp),sp
  827.     Gemdos_error    
  828.     ENDM    d0.w=number of bytes read
  829.  
  830. * Rename a File
  831. *    new name must not exist
  832. *    new name may be in another directory!
  833. Frename    MACRO    old_name_ptr,new_name_ptr
  834.     move.l    \2,-(sp)
  835.     move.l    \1,-(sp)
  836.     clr.w    -(sp)
  837.     move.w    #f_rename,-(sp)
  838.     trap    GEMDOS
  839.     lea    12(sp),sp
  840.     Gemdos_error
  841.     ENDM    
  842.  
  843. * Seek a File
  844. *    see equates.i for start_point
  845. *    Note:     seek before BOF returns 0
  846. *        seek after EOF returns length of file
  847. *    -ve position will give -ve offset from start point
  848. Fseek    MACRO    position,file_handle,start_point
  849.     move.w    \3,-(sp)
  850.     move.w    \2,-(sp)
  851.     move.l    \1,-(sp)
  852.     move.w    #f_seek,-(sp)
  853.     trap    GEMDOS
  854.     lea    10(sp),sp
  855.     ENDM    d0.w=position from BOF
  856.  
  857. * Set disk transfer address (WORD ALIGNED)
  858. *    see equates.i for 44 byte buffer
  859. Fsetdta    MACRO    new_dta_addr
  860.     move.l    \1,-(sp)
  861.     move.w    #f_setdta,-(sp)
  862.     trap    GEMDOS
  863.     addq.w    #6,sp
  864.     ENDM
  865.  
  866. * Search a File specification
  867. *    wildcards are allowed in the filename but not the path
  868. *    hidden & system files are included if specified
  869. *    volumes & subdirectories are searched exclusive of other attributes
  870. *    see equates.i for attributes
  871. *    see equates.i for DTA buffer table
  872. Fsfirst    MACRO    filespec_addr,attributes
  873.     move.w    \2,-(sp)
  874.     move.l    \1,-(sp)
  875.     move.w    #f_sfirst,-(sp)
  876.     trap    GEMDOS
  877.     addq.w    #8,sp
  878.     Gemdos_error
  879.     ENDM    d0.w=0 or -33 (file not found)
  880.  
  881. * Search next File specification
  882. *    see equates.i for attributes
  883. *    see equates.i for DTA buffer table
  884. *    DTA contents must remain unaltered between calls
  885. Fsnext    MACRO    
  886.     move.w    #f_snext,-(sp)
  887.     trap    GEMDOS
  888.     addq.w    #2,sp
  889.     Gemdos_error
  890.     ENDM    d0.w=0 or -33 (file not found)
  891.  
  892. * write a File
  893. *    Note: PRN,CON & AUX are already open as file handles
  894. *    if disk full, length(d0) <> requested
  895. Fwrite    MACRO    file_handle,length,buffer_addr
  896.     move.l    \3,-(sp)
  897.     move.l    \2,-(sp)
  898.     move.w    \1,-(sp)
  899.     move.w    #f_write,-(sp)
  900.     trap    GEMDOS
  901.     lea    12(sp),sp
  902.     Gemdos_error    
  903.     ENDM    d0.w=number of bytes written
  904.  
  905. * MEMORY MANAGEMENT MACROS
  906. **************************
  907. * see memvalid, memcntlr, themd, phystop, _membot, _memtop, 
  908. * memval2, memval3 in equates.i
  909.  
  910. * Get System Memory Parameter Block
  911. *    see equates.i for structures
  912. *    used by Gemdos - no other use seen
  913. Getmpb    MACRO    mpb_ptr    ;3 longs as pointers to Memory Descriptors
  914.     move.l    \1,-(sp)
  915.     clr.w    -(sp)
  916.     trap    BIOS
  917.     addq.w    #6,sp
  918.     ENDM
  919.  
  920. * Add Alternative Memory to System (Gemdos>=0.25)
  921. Maddalt    MACRO    address,size
  922.     cmp.w    #25,Gemdos_ver
  923.     bge    .\@
  924.     Error    #Gd_ver_err_msg
  925. .\@    move.l    \2,-(sp)
  926.     move.l    \1,-(sp)
  927.     move.w    #m_addalt,-(sp)
  928.     trap    GEMDOS
  929.     lea    10(sp),sp
  930.     ENDM
  931.  
  932. * Allocate memory (from alternate memory if bit 2 set in program header)
  933. *     pass -1 to return memory available
  934. *    DO NOT EXCEED 20 OPEN MEMORY BLOCKS AT ANY GIVEN TIME!
  935. Malloc    MACRO    memory_required
  936.     move.l    \1,-(sp)
  937.     move.w    #m_alloc,-(sp)
  938.     trap    GEMDOS
  939.     addq.w    #6,sp
  940.     tst.l    d0
  941.     bne    .\@
  942.     Error    Malloc_err_msg
  943. .\@
  944.     ENDM
  945.  
  946. * Move block of memory in bytes,words or longs
  947. *         Uses d0/a0-a1
  948. Mem_move    MACRO    from,to,count
  949.         move.w    \3,d0
  950.         move.l    \1,a0
  951.         move.l    \2,a1
  952. .\@        move.\0    (a0)+,(a1)+
  953.         dbra    d0,.\@
  954.         ENDM
  955.  
  956. * Free allocated memory (normal or alternate)
  957. *    Any memory not returned is freed when program terminates
  958. Mfree    MACRO    memory_to_free
  959.     move.l    \1,-(sp)
  960.     move.w    #m_free,-(sp)
  961.     trap    GEMDOS
  962.     addq.w    #6,sp
  963.     Gemdos_error
  964.     ENDM
  965.  
  966. * Free tail end of memory block back to Gemdos
  967. *    Normal Errors are:
  968. *        -40 Invalid Memory Block Address
  969. *        -67 Memory Block Growth Failure
  970. Mshrink    MACRO    address,new_size
  971.     IFNE    2-NARG
  972.     FAIL    Invalid Number of Parameters!
  973.     ENDC
  974.     move.l    \2,-(sp)
  975.     move.l    \1,-(sp)
  976.     clr.w    -(sp)
  977.     move.w    #m_shrink,-(sp)
  978.     trap    GEMDOS
  979.     lea    12(sp),sp
  980.     Gemdos_error
  981.     ENDM
  982.     
  983. * Allocate memory with preference
  984. *    see equates.i for memory types
  985. *    new for GEMDOS v0.25
  986. *    pass length of -1 for max available of type
  987. *    Do not use alternate memory for screen
  988. Mxalloc    MACRO    length_required,type
  989.     cmp.w    #25,Gemdos_ver
  990.     bge.s    mxa_good.\@        ;no function
  991.     cmp.w    #1,\2            ;no alt memory
  992.     beq.s    mxa_zero\@
  993.     Malloc    \1
  994.     bra.s    mxa_end\@
  995. mxa_good.\@    move.w    \2,-(sp)
  996.     move.l    \1,-(sp)
  997.     move.w    #m_xalloc,-(sp)
  998.     trap    GEMDOS
  999.     addq.w    #8,sp
  1000.     bra.s    mxa_end\@
  1001. mxa_zero\@    clr.l    d0
  1002. mxa_end\@
  1003.     bne    .\@
  1004.     Error    Malloc_err_msg
  1005. .\@
  1006.     ENDM    d0.l=address or 0 to fail or size of largest block
  1007.  
  1008. * Reserve size bytes from top of memory
  1009. *    only works before GEMDOS is initialised!
  1010. Ssbrk    MACRO    size
  1011.     move.l    \1,-(sp)
  1012.     move.w    #ssbrk,-(sp)
  1013.     trap    XBIOS
  1014.     addq.w    #6,sp
  1015.     ENDM    d0.l=start of reserved memory
  1016.  
  1017. * MOUSE MACROS
  1018. **************
  1019.  
  1020. * Initialise mouse packet handler
  1021. *    see equates.i for mouse modes and parameter structure
  1022. *    see XBIOS 34 Kbdvbase for info on KBD subsystem handlers
  1023. Initmouse    MACRO    mode,parameter_ptr,mouse_interrupt_handler_addr
  1024.     move.l    \3,-(sp)
  1025.     move.l    \2,-(sp)
  1026.     move.w    \1,-(sp)
  1027.     move.w    #initmouse,-(sp)
  1028.     trap    XBIOS
  1029.     lea    12(sp),sp
  1030.     ENDM
  1031.  
  1032. * NUMERIC ROUTINES
  1033. ******************
  1034.  
  1035. * Get Random Number
  1036. *    seed=(seed * 3141592621) + 1
  1037. *    random=seed >> 8
  1038. *    Initial value of seed taken from _frclock (frame counter)
  1039. *    bits 24-31 are zero
  1040. *    bit 0 has exact 50% distribution
  1041. Random    MACRO
  1042.     move.w    #random,-(sp)
  1043.     trap    XBIOS
  1044.     addq.w    #2,sp
  1045.     ENDM    d0.l=24 bit Pseudo Random Number
  1046.  
  1047. * PRINTER MACROS
  1048. ****************
  1049.  
  1050. * Get/Set Printer Configuration
  1051. *    Usually used by Install Printer Desk Accessory
  1052. *    Values used by Screen Dump & Desktop File Printing
  1053. *    Screen print doesn't support Epson Colour Printers
  1054. *    or Colour Daisywheels
  1055. *    new_code is 16 bit flag - see equates.i
  1056. Setprt    MACRO    new_code
  1057.     move.w    \1,-(sp)
  1058.     move.w    #setprt,-(sp)
  1059.     trap    XBIOS
  1060.     addq.w    #4,sp
  1061.     ENDM    d0.w = old_code
  1062.     
  1063. * PROGRAM STARTUP & SHUTDOWN MACROS
  1064. ***********************************
  1065. * Program owns files it opens and memory it allocates Exclusively
  1066. * Owned files and memory is cleared when it terminates
  1067. * Vector $102 is called just before program terminates
  1068. * - see etv_term/ETV_TERM in equates.i
  1069. * system reset bailout vector available - see resvalid, resvector in equates.i
  1070. * memory variables - see phystop, membot, memtop and mval2 in equates.i
  1071. * also see _cmdload for auto shell loading
  1072.  
  1073. * Load and/or Execute a Program
  1074. *    DO NOT USE IF YOU ARE AN ACCESSORY!
  1075. *    All parents std_handles are passed as they are
  1076. *    i.e. redirection is passed down the chain
  1077. *    Must terminate child process to return system resources to parent
  1078. *    see equates.i for load modes
  1079. *    see pexec.txt for further details
  1080. *    LOAD_GO,file_name,cmd_lin,env_lin
  1081. *    LOAD,file_name,cmd_lin,env_lin
  1082. *    GO,0.l,basepage,0.l
  1083. *    MAKE_BASEPAGE,0.l,cmd_lin,env_lin
  1084. *    cmd_line=length_byte+string,0
  1085. *    env_line=0 for previous env
  1086. *    env_line=array of null terminated strings + 0 at end
  1087. *    e.g.    "PATH=C:\",0,"LIB=C:\LIB",0,0
  1088. Pexec    MACRO    mode,filename_ptr,cmd_line_ptr,env_ptr
  1089.     move.l    \4,-(sp)
  1090.     move.l    \3,-(sp)
  1091.     move.l    \2,-(sp)
  1092.     move.w    \1,-(sp)
  1093.     move.w    #p_exec,-(sp)
  1094.     trap    GEMDOS
  1095.     lea    16(sp),sp
  1096.     Gemdos_error
  1097.     ENDM    d0.l=various - see above
  1098.  
  1099. * standard exit from program
  1100. Prog_exit    MACRO    <return code>
  1101.     cmp.l    #"BSTK",Stack_end
  1102.     beq.s    .B\@
  1103.     Error    #Stklo_err_msg
  1104. .B\@    
  1105.     cmp.l    #"TSTK",Stack_start
  1106.     beq.s    .T\@
  1107.     Error    #Stkhi_err_msg
  1108. .T\@    
  1109.     IFEQ    NARG
  1110.     Pterm0
  1111.     ELSE
  1112.     Pterm    \1
  1113.     ENDC
  1114.     ENDM    
  1115.  
  1116. * standard startup into program
  1117. *    shrink program to required length
  1118. *    Basepage variable is pointer to program basepage
  1119. *    Stack points to top of stack
  1120. *    Stackend points to bottom of stack
  1121. *    checks against overflow put at top & bottom of stack
  1122. Prog_shrink    MACRO    <stacksize>
  1123.     IFGT    NARG-1
  1124.     FAIL    Too Many Parameters in Prog_shrink!
  1125.     ENDC
  1126.     move.l    4(sp),a0    ;pointer to Basepage
  1127.     move.l    a0,Basepage
  1128.     move.l    $c(a0),d0    ;length of TEXT Section
  1129.     add.l    $14(a0),d0    ;length of DATA Section
  1130.     add.l    $1c(a0),d0    ;length of BSS Section
  1131.     add.l    #$100,d0    ;length of Basepage
  1132.     move.l    a0,d1
  1133.     add.l    d0,d1    ;new hitpa=start of basepage + size
  1134.     move.l    d1,P_hitpa(a0)    ;added for Pexec mode 4 compatability
  1135.     move.l    #Stack,sp    ;in BSS Section
  1136.     move.l    #"BSTK",Stack_end    ;test value
  1137.     move.l    #"TSTK",Stack_start    ;test value
  1138.     Mshrink    a0,d0    ;address,size
  1139.     Sversion        ;store version of Gemdos
  1140.     move.b    d0,Gemdos_ver
  1141.     lsr.w    #8,d0    ;in hi-low format!
  1142.     move.b    d0,Gemdos_ver+1
  1143.     BSS
  1144.     IFEQ    NARG
  1145. Stack_end    ds.l    1024/4    ;default stack of 1K
  1146.     ELSE
  1147. Stack_end    ds.l    \1/4    ;default stack of 1K
  1148.     ENDC
  1149. Stack    ds.l    1
  1150. Stack_start    ds.l    1
  1151.  
  1152. Basepage    ds.l    1
  1153. Gemdos_ver    ds.w    1
  1154.     TEXT
  1155.     ENDM
  1156.  
  1157. * Exit and return error_code
  1158. *     closes all files and releases all allocated memory
  1159. *    return code is -ve for error, +ve for message
  1160. *    Actual Code received is Long -ve for Program Load Error
  1161. *        Word -ve for program indicating error
  1162. Pterm    MACRO    return_code(+ve)
  1163.     TEXT
  1164.     move.w    \1,-(sp)
  1165.     move.w    #p_term,-(sp)
  1166.     trap    GEMDOS
  1167.     ENDM
  1168.  
  1169. * Exit and return 0
  1170. *     closes all files and releases all allocated memory
  1171. Pterm0    MACRO
  1172.     TEXT
  1173.     clr.w    -(sp)
  1174.     trap    GEMDOS
  1175.     ENDM
  1176.     
  1177. * Terminate & Stay Resident
  1178. *    allocated ram is kept
  1179. *    open files are closed
  1180. *    size=basepage($100)+prog[+data][+stack]
  1181. *    exit_code should be +ve (or -ve for error code)
  1182. *    Resident_size includes 256 bytes of Basepage
  1183. Ptermres    MACRO    Resident_size,exit_code
  1184.         move.w    \2,-(sp)
  1185.         move.l    \1,-(sp)
  1186.         move.w    #p_termres,-(sp)
  1187.         trap    GEMDOS
  1188. *        addq.w    #8,sp    ;never returns!
  1189.         ENDM
  1190.  
  1191. * SCREEN ROUTINES
  1192. *****************
  1193. * Monitor Type interrupt available - see traps.i
  1194. * HSYNC interrupt available - see traps.i
  1195. * also see HSYNC.txt to make use of it!
  1196. * OS variables - see palmode, defshiftmd, sshiftmd, v_bas_ad, colorptr,
  1197. * swc_vec and screenpt in equates.i
  1198. * also see _prt_cnt, scr_dump, prv_lsto, prv_lst, prv_auxo, prv_aux
  1199. * for screen dumps
  1200.  
  1201. * Get/Set Blitter Config
  1202. *    Use mode of -1 to leave Blitter in Current State
  1203. *    mode=0 to use Software Blit
  1204. *    mode=1 to use Hardware Blit
  1205. *    returns Bit 0 Set = Hardware Blit
  1206. *    returns Bit 1 Set = Blitter Hardware Present
  1207. Blitmode    MACRO    mode
  1208.         move.w    \1,-(sp)
  1209.         move.w    #blitmode,-(sp)
  1210.         trap    XBIOS
  1211.         addq.w    #4,sp
  1212.         ENDM    do.w = old_mode
  1213.  
  1214. * Get screen resolution 
  1215. *    0,1 or 2 for ST Low/Med/High
  1216. *    7,4 or 6 for TT Low/Med/High
  1217. *    use for open virtual workstation only
  1218. Getrez    MACRO
  1219.     move.w    #getrez,-(sp)
  1220.     trap    XBIOS
  1221.     addq.w    #2,sp
  1222.     ENDM    d0.w=screen mode currently in use
  1223.  
  1224. * Get Logical Screen Address
  1225. *    This is where TOS writes to when told to draw on the screen
  1226. *    Normally the same address as the Physical screen address
  1227. *    To make Screen updates look fast: 
  1228. *        reserve memory the size of the screen
  1229. *        point logbase to reserved memory (see Setscreen)
  1230. *        copy physical screen to logical screen
  1231. *        do all drawing
  1232. *        copy logical screen to physical screen
  1233. *        OR swap screen addresses (log <-> phys)
  1234. *    Physical and Logical Address MUST be Aligned
  1235. *        ST's to 256 byte boundary (last byte of address is 0)
  1236. *        STE's to Word boundary (last bit of address is 0)
  1237. Logbase    MACRO
  1238.     move.w    #logbase,-(sp)
  1239.     trap    XBIOS
  1240.     addq.w    #2,sp
  1241.     ENDM    d0.l=Address of Logical Screen
  1242.  
  1243. * Get Monitor Type
  1244. *    FALCON ONLY
  1245. *    0 - ST Mono Monitor
  1246. *    1 - ST Colour Monitor
  1247. *    2 - VGA Monitor
  1248. *    3 - TV
  1249. *    value returned is from monitor socket pins
  1250. Montype    MACRO
  1251.     move.w    #montype,-(sp)
  1252.     trap    XBIOS
  1253.     addq.w    #2,sp
  1254.     ENDM    d0.w=Monitor Type
  1255.  
  1256. * Get Physical Screen Address
  1257. *    32K long on normal ST's & STE's
  1258. *    Physical and Logical Address MUST be Aligned
  1259. *        ST's to 256 byte boundary (last byte of address is 0)
  1260. *        STE's to Word boundary (last bit of address is 0)
  1261. Physbase    MACRO
  1262.     move.w    #physbase,-(sp)
  1263.     trap    XBIOS
  1264.     addq.w    #2,sp
  1265.     ENDM    d0.l=Address of Physical Screen
  1266.  
  1267. * Print all or part of the screen
  1268. *    prtable is a 30 byte parameter table
  1269. *    see equates.i for structure
  1270. *    Uses Vectors $506,$50a,$50e & $512
  1271. *    printer status/printer_output/RS-232 status/RS-232 output
  1272. Prtblk    MACRO    prtable
  1273.     move.l    \1,-(sp)
  1274.     move.w    #prtblk,-(sp)
  1275.     trap    XBIOS
  1276.     addq.w    #6,sp
  1277.     ENDM
  1278.  
  1279. * Screen Dump
  1280. *    Atari or Epson Compatible only
  1281. *    see Setprt for printer settings used by this routine
  1282. *    Vectored through 1282 ($502) to allow installation of other
  1283. *    screen dump code as TSR's
  1284. *    Standard routine calls Prtblk(prtable)
  1285. Scrdmp    MACRO
  1286.     move.w    #scrdmp,-(sp)
  1287.     trap    XBIOS
  1288.     addq.w    #2,sp
  1289.     ENDM
  1290.  
  1291. * Set the Actual Colour of a Pen
  1292. *    pass negative colour for no change
  1293. *    colour word is xxxx R0321 G0321 B0321 in bits
  1294. *    least significant bit (0) only used on STE and above
  1295. *    pens 0-15 valid in ST/STE Low Res
  1296. Setcolour    MACRO    pen,colour
  1297.         Setcolor    \1,\2
  1298.         ENDM
  1299. Setcolor    MACRO    pen,colour
  1300.         move.w    \2,-(sp)
  1301.         move.w    \1,-(sp)
  1302.         move.w    #setcolour,-(sp)
  1303.         trap    XBIOS
  1304.         addq.w    #6,sp
  1305.         ENDM    d0.w=Old colour
  1306.  
  1307. * Set 16 Colours
  1308. *    pallete_ptr is word aligned
  1309. *    points to table of 16 colour words for the 16 pens
  1310. *    becomes active at next vblank
  1311. *    colour word is xxxx R0321 G0321 B0321
  1312. *    least significant bit only used on STE
  1313. Setpallete    MACRO    pallete_ptr
  1314.     move.l    \1,-(sp)
  1315.     move.w    #setpallete,-(sp)
  1316.     trap    XBIOS
  1317.     addq.w    #6,sp
  1318.     ENDM    
  1319.  
  1320. * Set Screen logical and physical address and screen mode
  1321. *    phys becomes active at next vblank (maybe not on pre-blitter TOS)
  1322. *    To avoid screen glitch on pre-blitter TOS's, 
  1323. *        put new and old phys screens in same 64K block
  1324. *        OR call Vsync before Setscreen
  1325. *    Physical and Logical Address MUST be Aligned
  1326. *        ST's to 256 byte boundary (last byte of address is 0)
  1327. *        STE's to Word boundary (last bit of address is 0)
  1328. *    use -1 for any parameter that should not change
  1329. *    change of rez causes clear screen, home cursor & reset VT52
  1330. *    if log or phys = -1 then they are not changed
  1331. *    If log and phys = 0 then screens are automatically 
  1332. *                    set to correct size - FALCON ONLY
  1333. *    VDI is reinitialised to new rez, AES is not!
  1334. *    if rez=0 then ST Low
  1335. *    if rez=1 then ST Med
  1336. *    if rez=2 then ST High
  1337. *    if rez=3 then mode is modecode for Screen
  1338. *    rez=3 only valid for FALCON
  1339. *    See ModeCode Values in Equates.i
  1340. *    Bits 0-2 = Bits per pixel
  1341. *    Bit    3 = 80 Column if set
  1342. *    Bit    4 = VGA if set
  1343. *    Bit    5 = PAL if set
  1344. *    Bit    6 = Overscan if set (Not VGA)
  1345. *        multiplies X & Y by 1.2
  1346. *    Bit    7 = ST Compatible Mode if Set
  1347. *    Bit    8 = Interlace on if set (double Y pixels)
  1348. Setscreen    MACRO    log,phys,rez (,mode)
  1349.     IFEQ    NARG-4
  1350.     move.w    \4,-(sp)
  1351.     ENDC
  1352.     move.w    \3,-(sp)
  1353.     move.l    \2,-(sp)
  1354.     move.l    \1,-(sp)
  1355.     move.w    #setscreen,-(sp)
  1356.     trap    XBIOS
  1357.     IFEQ    NARG-4
  1358.     lea    14(sp),sp
  1359.     ELSE
  1360.     lea    12(sp),sp
  1361.     ENDC
  1362.     ENDM    d0.l=Address of Physical Screen
  1363.  
  1364. * Get List of Palette Colours starting at pen INDEX for COUNT pens into ARRAY of Longs
  1365. *    FALCON ONLY
  1366. *    ARRAY is filled with Longs of the form xRGB
  1367. VgetRGB    MACRO INDEX,COUNT,ARRAY
  1368.     move.l    \3,-(sp)
  1369.     move.w    \2,-(sp)
  1370.     move.w    \1,-(sp)
  1371.     move.w    #vgetrgb,-(sp)
  1372.     trap    XBIOS
  1373.     lea    10(sp),sp
  1374.     ENDM    
  1375.  
  1376. * Get Memory Size needed by a given type of Screen
  1377. *    FALCON ONLY
  1378. *    See ModeCode Values in Equates.i
  1379. *    Bits 0-2 = Bits per pixel
  1380. *    Bit    3 = 80 Column if set
  1381. *    Bit    4 = VGA if set
  1382. *    Bit    5 = PAL if set
  1383. *    Bit    6 = Overscan if set (Not VGA)
  1384. *        multiplies X & Y by 1.2
  1385. *    Bit    7 = ST Compatible Mode if Set
  1386. *    Bit    8 = Interlace on if set (double Y pixels)
  1387. *    Returns Screen Size in Bytes in d0.l
  1388. VgetSize    MACRO    modecode
  1389.     move.w    \1,-(sp)
  1390.     move.w    #vgetsize,-(sp)
  1391.     trap    XBIOS
  1392.     addq.w    #4,sp
  1393.     ENDM    d0.l=Screen Size (bytes)
  1394.  
  1395. * Set VDI Mask and Overlay Mode
  1396. *    FALCON ONLY
  1397. *    TRUE COLOUR USE ONLY
  1398. * gets/sets the AND/OR masks used by VDI in calculation of vs_colour
  1399. * used to enable/disable the overlay bit in true colour mode
  1400. *    AND = $FFFF    OR = $0000    NO EFFECT
  1401. *    AND = $FFFF    OR = $0020    SET OVERLAY BIT
  1402. *    AND = $FFDF    OR = $0000    CLEAR OVERLAY BIT
  1403. *    OVERLAY = 0 to take system out of Overlay Mode
  1404. *    OVERLAY = Non-Zero to put system into Overlay Mode
  1405. * Possible uses in VDI colour changes by masking and redrawing same colour?
  1406. VsetMask    MACRO    OR_Mask,AND_Mask,Overlay
  1407.     move.w    \3,-(sp)
  1408.     move.w    \2,-(sp)
  1409.     move.w    \1,-(sp)
  1410.     move.w    #vsetmask,-(sp)
  1411.     trap    XBIOS
  1412.     addq.w    #8,sp
  1413.     ENDM
  1414.     
  1415. * Get/Set Video Mode
  1416. *    FALCON ONLY
  1417. *    Setscreen is preferred
  1418. *    DOES NOT CHANGE SCREEN ADDRESS OR ALLOCATE MEMORY OR TELL VDI
  1419. *    IF SCREENSIZE NOW BIGGER, IT WILL CORRUPT UNLESS MOVED FIRST!
  1420. *    If Modecode is -1, returns current state without altering anything
  1421. *    see equates.i for Modecodes
  1422. *    Bits 0-2 = Bits per pixel
  1423. *    Bit    3 = 80 Column if set
  1424. *    Bit    4 = VGA if set
  1425. *    Bit    5 = PAL if set
  1426. *    Bit    6 = Overscan if set (Not VGA)
  1427. *        multiplies X & Y by 1.2
  1428. *    Bit    7 = ST Compatible Mode if Set
  1429. *    Bit    8 = Interlace on if set (double Y pixels)
  1430. *     40 Column 2 Colour Mode not allowed
  1431. *     80 Column True Colour Mode not allowed on VGA
  1432. *     VALIDITY OF CODE NOT CHECKED 
  1433. * Returns Previous value of Screen Mode
  1434. Vsetmode    MACRO    modecode
  1435.     move.w    #\1,-(sp)
  1436.     move.w    #vsetmode,-(sp)
  1437.     trap    XBIOS
  1438.     addq.w    #4,sp
  1439.     ENDM    d0.w = old Modecode
  1440.     
  1441. * Set List of Palette Colours starting at pen INDEX for COUNT pens from ARRAY of Longs
  1442. *    FALCON ONLY
  1443. *    ARRAY should be filled with Longs of the form xRGB
  1444. *    Used by VDI in vs_colour
  1445. VsetRGB    MACRO INDEX,COUNT,ARRAY
  1446.     move.l    \3,-(sp)
  1447.     move.w    \2,-(sp)
  1448.     move.w    \1,-(sp)
  1449.     move.w    #vsetrgb,-(sp)
  1450.     trap    XBIOS
  1451.     lea    10(sp),sp
  1452.     ENDM    
  1453.  
  1454. * Use Setscreen - see associated Info in Setscreen
  1455. *    FALCON ONLY FOR MODE (RES>2)
  1456. Vsetscreen    MACRO    log,phys,res,mode
  1457.         Setscreen \1,\2,\3,\4
  1458.         ENDM
  1459.  
  1460. * Set Video Sync Clocks
  1461. *    FALCON ONLY
  1462. *    see equates.i
  1463. *    Bit 0 - Set for External Clock
  1464. *    Bit 1 - Set for External Vsync
  1465. *    Bit 2 - Set for External Hsync
  1466. Vsetsync    MACRO    Sync_code
  1467.     move.w    \1,-(sp)
  1468.     move.w    #vsetsync,-(sp)
  1469.     trap    XBIOS
  1470.     addq.w    #4,sp
  1471.     ENDM
  1472.  
  1473. * Wait for VBLANK Sync
  1474. Vsync    MACRO
  1475.     move.w    #vsync,-(sp)
  1476.     trap    XBIOS
  1477.     addq.w    #2,sp
  1478.     ENDM
  1479.  
  1480. * SOUND ROUTINES
  1481. ****************
  1482. * All ST's (and up) have Yamaha YM-2149 or General Instruments AY-3-8190
  1483. * Programmable Sound Generator.
  1484. * ST's @ $ffff8800 for register to read/write, $ffff8802 for value of register
  1485. * Should use Giaccess for read/writes
  1486.  
  1487. * Get/Set Play & Record Enable/Disable
  1488. *        FALCON ONLY
  1489. *        see equates.i for Modes
  1490. *        Mode = -1 means get current Mode
  1491. *        Bit 0 - Set for Play Enable
  1492. *        Bit 1 - Set for Play Repeat
  1493. *        Bit 2 - Set for Record Enable
  1494. *        Bit 3 - Set for Record Repeat
  1495. *    Sound system has 32 byte FIFO Buffer
  1496. *    If Software recording and Record Enable Bit not Cleared,
  1497. *    then Clear Bit to Flush Buffer.
  1498. Buffoper    MACRO    mode
  1499.         move.w    \1,-(sp)
  1500.         move.w    #buffoper,-(sp)
  1501.         trap    XBIOS
  1502.         addq.w    #4,sp
  1503.         ENDM    d0.l=0 or Current Mode Settings
  1504.  
  1505. * Get Sound Buffer Pointers
  1506. *        FALCON ONLY
  1507. *        see equates.i
  1508. *        Buffer_Table must have room for 4 longs
  1509. *        These are filled by the call
  1510. *        +$00 Current Play Position
  1511. *        +$04 Current Record Position
  1512. *        +$08 Reserved
  1513. *        +$0C Reserved
  1514. Buffptr        MACRO    Buffer_Table
  1515.         move.l    \1,-(sp)
  1516.         move.w    #buffptr,-(sp)
  1517.         trap    XBIOS
  1518.         addq.w    #6,sp
  1519.         ENDM
  1520.  
  1521. * Configure Sound Switch Matrix
  1522. *        FALCON ONLY
  1523. *        Source=    0 - DMA Playback
  1524. *            1 - DSP Transmit
  1525. *            2 - External Input (DSP Port)
  1526. *            3 - ADC (Microphone Input and/or PSG chip)
  1527. *        Note: Standard ST Sound (PSG) goes through ADC
  1528. *        Dest    Bit 0 - DMA Record
  1529. *            Bit 1 - DSP Receive
  1530. *            Bit 2 - External Output    (DSP Port)
  1531. *            Bit 3 - DAC (Headphones and/or Speaker)
  1532. *        Clock =    0 - Internal 25.175MHz
  1533. *            1 - External Clock (through DSP Port)
  1534. *            2 - Internal 32MHz
  1535. *        Prescale - Table given is for 25.175MHz Clock
  1536. *            32MHz Clock not allowed for CODEC / DMA
  1537. *            Clock is /256 then /(Prescale+1)
  1538. *            * means not allowed for CODEC / DMA and will Mute Codec
  1539. *             0    uses /1280*, /640, /320 or /160 set in Soundcmd()
  1540. *             1    /512    49.170KHz
  1541. *             2    /768    32.780KHz
  1542. *             3    /1024    24.585KHz
  1543. *             4    /1280    19.668KHz
  1544. *             5    /1536    16.390KHz
  1545. *             6    /1792    14.049KHz *
  1546. *             7    /2048    12.292KHz
  1547. *             8    /2304    10.927KHz *
  1548. *             9    /2560     9.834KHz
  1549. *            10    /2816     8.940KHz *
  1550. *            11    /3072     8.195KHz
  1551. *            12    /3328     7.565KHz *
  1552. *            >12 will Mute the CODEC until Reset with Sndstatus()
  1553. *            13         7.14 KHz *
  1554. *            14         6.66 KHz *
  1555. *            15         6.25 KHz *
  1556. *        Protocol = 0    Enable Handshaking
  1557. *                   1    Disable Handshaking
  1558. Devconnect    MACRO    source,dest,clock,prescale,protocol
  1559.         move.w    \5,-(sp)
  1560.         move.w    \4,-(sp)
  1561.         move.w    \3,-(sp)
  1562.         move.w    \2,-(sp)
  1563.         move.w    \1,-(sp)
  1564.         move.w    #devconnect,-(sp)
  1565.         trap    XBIOS
  1566.         lea    12(sp),sp
  1567.         ENDM    d0.l = ?
  1568.  
  1569. * Set Yamaha Sound Chip to Play command stream
  1570. *    Commands $00-$0f,x    Put next byte in sound register 0-15
  1571. *    Command  $80,x        Put next byte in temporary register
  1572. *    Command  $81,x,y,z    Put temp reg into reg x
  1573. *                add signed value of y to temp reg
  1574. *                until temp=z
  1575. *    Commands $82-$ff,x    stop if x=0
  1576. *                else wait for x timer ticks (always 50Hz)
  1577. Dosound    MACRO    command_ptr
  1578.     move.l    \1,-(sp)
  1579.     move.w    #dosound,-(sp)
  1580.     trap    XBIOS
  1581.     addq.w    #6,sp
  1582.     ENDM
  1583.  
  1584. * Isolate DSP Tx/Rx ports from Sound Switch Matrix
  1585. *        1 - Connect Port
  1586. *        0 - Disconnect Port
  1587. Dsptristate    MACRO    Tx_on,Rx_on
  1588.         move.w    \2,-(sp)
  1589.         move.w    \1,-(sp)
  1590.         move.w    #dsptristate,-(sp)
  1591.         trap    XBIOS
  1592.         addq.w    #6,sp
  1593.         ENDM    d0.l=?
  1594.         
  1595. * Read/Write to Yamaha Sound Chip Register
  1596. *    register number is $0-$F to read, add $80 to register_num to write
  1597. *    Note: data is byte sized
  1598. *    Don't use for Register 14, use On/Offgibit
  1599. *    Register 15 is Parallel Port data (I/O)
  1600. Giaccess    MACRO    data, register
  1601.         move.w    \2,-(sp)
  1602.         clr.w    -(sp)
  1603.         move.b    \1,1(sp)
  1604.         move.w    #giaccess,-(sp)
  1605.         trap    XBIOS
  1606.         addq.w    #6,sp        ;and this?
  1607.         ENDM    d0.b=register value
  1608.  
  1609. * SYSTEM ROUTINES
  1610. *****************
  1611. * 200Hz System clock interrupt available - see traps.i
  1612. * timer handoff vector available - see equates.i
  1613. * OS variables - see timer_ms, vblsem, nvbls, vblqueue, vbclock & frclock
  1614. * in equates.i
  1615. * also see savptr, sav_context, _hz_200, the_env, _sysbase, _shell_p
  1616. * end_os and exec_os
  1617. * see Post mortem dump area for system crash info - in equates.i
  1618.  
  1619. * Disable MFP 68901 Interrupt Vector
  1620. *    - for normally disabled, + for normally enabled
  1621. *    Int 0-    Port Bit 0    Parallel Port Busy
  1622. *    Int 1+    Port Bit 1    RS-232 Data Carrier Detect
  1623. *    Int 2+    Port Bit 2    RS-232 Clear To Send
  1624. *    Int 3-    Port Bit 3    Blitter Chip - Operation Finished
  1625. *    Int 4-    Timer D        RS-232 Baud Rate Generator
  1626. *    Int 5+    Timer C        System Clock (200Hz)
  1627. *    Int 6+    Port Bit 4    KBD and MIDI ACIA data request
  1628. *    Int 7-    Port Bit 5    Floppy/DMA port data request
  1629. *    Int 8-    Timer B        HBlank Counter
  1630. *    Int 9+    USART        RS-232 Tx Error
  1631. *    Int 10+    USART        RS-232 Tx Buffer Empty
  1632. *    Int 11+    USART        RS-232 Rx Error
  1633. *    Int 12+    USART        RS-232 Rx Buffer Full
  1634. *    Int 13-    Timer A        Spare (for User Apps)/STE uses this
  1635. *    Int 14-    Port Bit 6    RS-232 Ring Indicator
  1636. *    Int 15-    Port Bit 7    Monochrome Monitor Detect
  1637. Jdisint    MACRO    interrupt_num
  1638.     move.w    \1,-(sp)
  1639.     move.w    #jdisint,-(sp)
  1640.     trap    XBIOS
  1641.     addq.w    #4,sp
  1642.     ENDM    
  1643.  
  1644. * Enable MFP 68901 Interrupt Vector
  1645. *    See Jdisint for info
  1646. Jenabint    MACRO    interrupt_num
  1647.     move.w    \1,-(sp)
  1648.     move.w    #jenabint,-(sp)
  1649.     trap    XBIOS
  1650.     addq.w    #4,sp
  1651.     ENDM    
  1652.  
  1653. * Get Device Vector Table
  1654. *    The addresses of IKBD & MIDI interrupt handlers
  1655. *    see equates.i for structure and purpose
  1656. *    used for any interrupt driven signal - joystick, mouse, midi, etc
  1657. Kbdvbase    MACRO
  1658.     move.w    #kbdvbase,-(sp)
  1659.     trap    XBIOS
  1660.     addq.w    #2,sp
  1661.     ENDM    d0.l=pointer to vector structure
  1662.  
  1663. * Set MFP Interrupt Vector
  1664. *    Interrupt numbers = 0-15
  1665. *    Old Vector address is lost
  1666. Mfpint    MACRO    interrupt_num,Vector_addr
  1667.     move.l    \2,-(sp)
  1668.     move.w    \1,-(sp)
  1669.     move.w    #mfpint,-(sp)
  1670.     trap    XBIOS
  1671.     addq.w    #8,sp
  1672.     ENDM    
  1673.  
  1674. * Clear bit on Yamaha Sound Chip Port A
  1675. *    Bit 0 - Floppy Disk Side 1 Select
  1676. *    Bit 1 - Floppy Disk Drive A Select
  1677. *    Bit 2 - Floppy Disk Drive B Select
  1678. *    Bit 3 - RS-232 RTS
  1679. *    Bit 4 - RS-232 DTR
  1680. *    Bit 5 - Centronics Strobe Line
  1681. *    Bit 6 - General Purpose Output/Used on STE
  1682. *    Bit 7 - Reserved
  1683. Offgibit    MACRO    bit_number
  1684.     move.w    \1,-(sp)
  1685.     move.w    #offgibit,-(sp)
  1686.     trap    XBIOS
  1687.     addq.w    #4,sp    
  1688.     ENDM    
  1689.  
  1690. * Set bit on Yamaha Sound Chip Port A
  1691. *    See Offgibit details
  1692. Ongibit    MACRO    bit_number
  1693.     move.w    \1,-(sp)
  1694.     move.w    #ongibit,-(sp)
  1695.     trap    XBIOS
  1696.     addq.w    #4,sp    
  1697.     ENDM    
  1698.  
  1699. * Throw away AES and free any AES memory
  1700. *    if aes present, throw away & Reboot
  1701. *    else return!
  1702. Puntaes    MACRO
  1703.     move.w    #puntaes,-(sp)
  1704.     trap    XBIOS
  1705.     addq.w    #2,sp
  1706.     ENDM
  1707.  
  1708. * Get/Set exception vector
  1709. *    Vector Address = -1 for get vector address
  1710. *    remember to restore old vector when finished
  1711. *    0-$ff    standard 680x0 exception vectors
  1712. *    $100    System timer vector
  1713. *    $101    Critical Error Handler
  1714. *    $102    Process Termination Handler
  1715. *    $103-107    Reserved
  1716. *    $200-$ffff    reserved for OEM use - not available in BIOS
  1717. Setexec    MACRO    Vector_num,new_addr
  1718.     move.l    \2,-(sp)
  1719.     move.w    \1,-(sp)
  1720.     move.w    #setexec,-(sp)
  1721.     trap    BIOS
  1722.     addq.w    #8,sp
  1723.     ENDM    D0.L=Old Vector Address
  1724.  
  1725. * Run subroutine in SUPER mode
  1726. *    Need to be in Super to Look at Adresses<$800 or >$FF80000
  1727. *    Creates Bus Error otherwise (2 Bombs)
  1728. *    end code with rts
  1729. *    NO BIOS OR GEMDOS CALLS
  1730. Supexec    MACRO    subroutine_address
  1731.     move.l    \1,-(sp)
  1732.     move.w    #supexec,-(sp)
  1733.     trap    XBIOS
  1734.     addq.w    #6,sp
  1735.     ENDM
  1736.  
  1737. * Set User/Supervisor mode
  1738. *    Need to be in Super to Look at Adresses<$800 or >$FF80000
  1739. *    Creates Bus Error otherwise (2 Bombs)
  1740. *    mode=(-)1    returns 0 if in user mode & (-)1 if in super mode
  1741. *    mode=0        switch modes using current stack 
  1742. *            and return old stack of new mode
  1743. *    mode=new_stack  switches modes with new_stack used as super stack
  1744. *            and returns old stack of new mode
  1745. *    when going to super mode, get old super stack
  1746. *    when going to user mode, set mode to old super stack
  1747. *    RESTORE SUPER STACK BEFORE PROCESS TERMINATES
  1748. Super    MACRO    stack or 0 or 1
  1749.     move.l    \1,-(sp)
  1750.     move.w    #super,-(sp)
  1751.     trap    GEMDOS
  1752.     addq.w    #6,sp
  1753.     ENDM    
  1754.  
  1755. * Get GEMDOS version number
  1756. *    $0d00    v 0.13 - disk based
  1757. *    $1300    v 0.19 - ROM & Mega TOS
  1758. *    $1500    v 0.21 - Rainbow & STE TOS
  1759. *    $1700    v 0.23 - STE TOS v1.62
  1760. *    $1900    v 0.25 - MegaSTE & TT TOS
  1761. Sversion    MACRO
  1762.     move.w    #s_version,-(sp)
  1763.     trap    GEMDOS
  1764.     addq.w    #2,sp
  1765.     ENDM    d0.w=version number (low/high)
  1766.  
  1767. * Get system timer tick interval (in milliseconds)
  1768. *    normally 20
  1769. *    compare with system timer actual value passed for
  1770. *    measure of system overload
  1771. Tickcal    MACRO
  1772.     move.w    #tickcal,-(sp)
  1773.     trap    BIOS
  1774.     addq.w    #2,sp
  1775.     ENDM    D0.L=milliseconds/timer tick (20)
  1776.  
  1777. * Set timer registers
  1778. *    Timer A is for user use
  1779. *    Master clock is 2,457,600Hz
  1780. *    timer 0-3 = MFP 68901 timer A-D
  1781. *    control is timer control register setting - see equates.i
  1782. *    data put in timer's data register
  1783. *    vector points to interrupt handler
  1784. *    TIMER A - Used only for applications
  1785. *    TIMER B - Graphics - Hblank, Sync, etc
  1786. *    TIMER C - 200Hz System Timer
  1787. *    TIMER D - RS232 Baud Rate - but interrupt free for use
  1788. Xbtimer    MACRO    timer,control,data,vector
  1789.     move.l    \4,-(sp)
  1790.     move.w    \3,-(sp)
  1791.     move.w    \2,-(sp)
  1792.     move.w    \1,-(sp)
  1793.     move.w    #xbtimer,-(sp)
  1794.     trap    XBIOS
  1795.     lea    12(sp),sp
  1796.     ENDM    
  1797.  
  1798. * TIME AND DATE ROUTINES
  1799. ************************
  1800. *    Time and Date formats are same as on Disks
  1801. *    GEMDOS Clock Runs under Interrupt
  1802. *    XBIOS Clock is Hardware
  1803. *    GEMDOS Clock may Lose Time
  1804. *    GEMDOS Clock updated from XBIOS Clock at end of each program
  1805. *        ONLY IN BLITTER TOS AND LATER
  1806.  
  1807. Day    MACRO    date
  1808.     and.w    #31,\1
  1809.     ENDM
  1810.  
  1811. Hours    MACRO    time
  1812.     lsr.w    #11,\1
  1813.     and.w    #31,\1
  1814.     ENDM
  1815.  
  1816. Minutes    MACRO    time
  1817.     lsr.w    #5,\1
  1818.     and.w    #63,\1
  1819.     ENDM
  1820.  
  1821. Month    MACRO    date
  1822.     lsr.w    #5,\1
  1823.     and.w    #15,\1
  1824.     ENDM
  1825.  
  1826. Seconds    MACRO    time
  1827.     and.w    #31,\1
  1828.     lsl.w    #1,\1
  1829.     ENDM
  1830.  
  1831. Year    MACRO    date
  1832.     lsr.w    #8,\1
  1833.     lsr.w    #1,\1
  1834.     and.w    #$ff,\1
  1835.     add.w    #1980,\1
  1836.     ENDM    
  1837.  
  1838. Set_date    MACRO    DAY.w,MONTH.w,YEAR.w
  1839.     * GEMDOS CLOCK ONLY
  1840.     IFC    'd0','\1'
  1841.     FAIL    SET DATE USES D0
  1842.     ENDC
  1843.     IFC    'd0','\2'
  1844.     FAIL    SET DATE USES D0
  1845.     ENDC
  1846.     IFC    'd0','\3'
  1847.     FAIL    SET DATE USES D0
  1848.     ENDC
  1849.     move.w    \3,d0
  1850.     sub.w    #1980,d0
  1851.     lsl.w    #4,d0
  1852.     and.w    #15,\2
  1853.     or.w    \2,d0
  1854.     lsl.w    #5,d0
  1855.     and.w    #31,\1
  1856.     or.w    \1,d0
  1857.     Tsetdate    d0
  1858.  
  1859. Set_time    MACRO    HOURS.w,MINUTES.w,SECONDS.w
  1860.     * GEMDOS CLOCK ONLY
  1861.     IFC    'd0','\2'
  1862.     FAIL    SET TIME USES D0
  1863.     ENDC
  1864.     IFC    'd0','\3'
  1865.     FAIL    SET TIME USES D0
  1866.     ENDC
  1867.     move.w    \3,d0
  1868.     lsl.w    #6,d0
  1869.     and.w    #63,\2
  1870.     or.w    \2,d0
  1871.     lsl.w    #5,d0
  1872.     lsr.w    #1,\1
  1873.     and.w    #31,\1    ;bi-seconds
  1874.     or.w    \1,d0
  1875.     lsl.w    #1,\1
  1876.     Tsettime    d0
  1877.     ENDM
  1878.  
  1879. * Get KBD time & date (or RTC in Mega's) - Hardware Clock
  1880. *    date in high word
  1881. *    time in low word - DOS Format
  1882. *    bits are yyyyyyymmmmddddd hhhhhmmmmmmsssss
  1883. *    s=seconds/2 (0-29)
  1884. Gettime    MACRO
  1885.     move.w    #gettime,-(sp)
  1886.     trap    XBIOS
  1887.     addq.w    #2
  1888.     ENDM    d0.l=date.w/time.w in DOS format
  1889.  
  1890. * Set KBD time & date (or RTC in mega's) - Hardware Clock
  1891. *    date in high word
  1892. *    time in low word - DOS Format
  1893. *    bits are yyyyyyymmmmddddd hhhhhmmmmmmsssss
  1894. *    s=seconds/2 (0-29)
  1895. Settime    MACRO    date&time
  1896.     move.w    #settime,-(sp)
  1897.     trap    XBIOS
  1898.     addq.w    #2
  1899.     ENDM    
  1900.  
  1901. * Get date - Software Clock
  1902. *    bits 0-4    Day    (1-31)
  1903. *    bits 5-8    Month    (1-12)
  1904. *    bits 9-15    Year-1980 (0-119)
  1905. Tgetdate    MACRO
  1906.     move.w    #t_getdate,-(sp)
  1907.     trap    GEMDOS
  1908.     addq.w    #2,sp
  1909.     ENDM    d0.w=date
  1910.  
  1911. * Get time - Software Clock
  1912. *    bits 0-4    Seconds/2    (0-29)
  1913. *    bits 5-10    Minutes        (0-59)
  1914. *    bits 11-15    Hours        (0-23)
  1915. Tgettime    MACRO
  1916.     move.w    #t_gettime,-(sp)
  1917.     trap    GEMDOS
  1918.     addq.w    #2,sp
  1919.     ENDM    d0.w=time
  1920.  
  1921. * Set date - Software Clock
  1922. *    bits 0-4    Day
  1923. *    bits 5-8    Month
  1924. *    bits 9-15    Year-1980
  1925. *    GEMDOS DOES NOT TELL BIOS THAT DATE HAS CHANGED!
  1926. *    validity of date not checked!
  1927. Tsetdate    MACRO    date
  1928.     move.w    \1,-(sp)
  1929.     move.w    #t_setdate,-(sp)
  1930.     trap    GEMDOS
  1931.     addq.w    #4,sp
  1932.     Gemdos_error
  1933.     ENDM    d0.l=0 or error code
  1934.  
  1935. * Set time - Software Clock
  1936. *    bits 0-4    Seconds/2
  1937. *    bits 5-10    Minutes
  1938. *    bits 11-15    Hours
  1939. *    GEMDOS DOES NOT TELL BIOS THAT TIME HAS CHANGED!
  1940. Tsettime    MACRO    time
  1941.     move.w    \1,-(sp)
  1942.     move.w    #t_settime,-(sp)
  1943.     trap    GEMDOS
  1944.     addq.w    #4,sp
  1945.     Gemdos_error
  1946.     ENDM
  1947.  
  1948. Weekday    MACRO    date
  1949.     move.w    \1,d0
  1950.     move.w    d0,d1
  1951.     move.w    d1,d2
  1952.     Day    d0
  1953.     Month    d1
  1954.     Year    d2
  1955.     cmp.w    #3,d1    ;if month<3 then month=month+12;year=year-1
  1956.     bge.s    .\@
  1957.     add.w    #12,d1
  1958.     subq.w    #1,d2
  1959. .\@    move.w    d1,d3
  1960.     add.w    d1,d3
  1961.     add.w    d1,d3    ;weekday=3*month
  1962.     addq.w    #3,d3    ;+3
  1963.     ext.l    d3
  1964.     divu    #5,d3    ;(3*month+3)/5
  1965.     add.w    d2,d3    ;+year
  1966.     lsr.w    #2,d2    
  1967.     add.w    d2,d3    ;+year/4
  1968.     ext.l    d2
  1969.     divu    #25,d2
  1970.     sub.w    d2,d3    ;-year/100
  1971.     lsr.w    #2,d2
  1972.     add.w    d2,d3    ;+year/400
  1973.     add.w    d0,d3    ;+day
  1974.     lsl.w    #1,d1    
  1975.     add.w    d1,d3    ;+month*2
  1976.     addq.w    #1,d3    ;+2
  1977.     ext.l    d3
  1978.     divu    #7,d3
  1979.     swap    d3
  1980.     addq.w    #1,d3    ;answer=1-7 1=Sunday
  1981.     move.w    d3,d0    ;weekday=weekday%7
  1982.     ENDM    Day of Week (1-7) 1=Sunday
  1983.  
  1984. ə