home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI05.ARJ / ictari.05 / ASSEMBLY / WHATTOS2 / WHATTOS2.S next >
Text File  |  1993-06-17  |  9KB  |  342 lines

  1. ;WhichTos2 - Amended by PoshPaws (S.H.R.) for general interest
  2. ;Hope you don't mind the alterations T.S.C.!
  3.  
  4. ; Thanks to the Untouchables for the cart detect etc.
  5. ; The TOS version finder was in the book 'Introducing Atari ST Machine
  6. ; Code'   I hope they don't mind us nicking it! (I re-wrote it a bit).
  7.  
  8. ; This code finds out :-    which TOS you have
  9. ;            if the sys_base is valid
  10. ;            if you have an STE,ST,TT or Falcon
  11. ;            how much memory you have
  12. ;            if there are cartridges and what they are called
  13.  
  14. ; This code is just an example of how to find some system settings.
  15.  
  16. ; Note:-  you can only detect user carts like the Ultimate Ripper if
  17. ; they are switched on.
  18. ; I do not know how to find out the memory config properly so someone
  19. ; else will have to show you. - Use _phystop - S.H.R.
  20. ; Errm...   thats it.        T.S.C.
  21.  
  22.     text
  23.             pea    0.w        supervisor mode
  24.             move.w      #$20,-(sp)
  25.             trap        #1
  26.             addq.l       #6,sp
  27.             move.l      d0,oldsp
  28.  
  29.     bss        ;must be in bss or data segment else executed!
  30. oldsp    ds.l    1
  31.     
  32.     text
  33.     bsr    ste_hard        run all checks
  34.     bsr.s    checkmeg
  35.     bsr.s    carty
  36.     bsr    tos_check
  37.     
  38. cont    bsr    wait
  39.  
  40.     pea    oldsp        back to user mode
  41.             move.w      #$20,-(sp)
  42.             trap        #1
  43.             addq.w       #6,sp
  44.  
  45.     clr.w    -(sp)        quit - don't use pea - it pushes the Contents of 0.w!
  46.     trap    #1      
  47.  
  48. ***************************************************************************
  49. * Check for some carts
  50. **********************
  51. * Diagnostics cartridges contain code at $fa0004 that is executed almost
  52. * immediately after the reset button is pressed. - S.H.R.
  53. * I have no cartridges with code in so this needs checking - 
  54. *    it should return all application names in the cartridge
  55.  
  56. carty    cmp.l    #$fa52255f,$fa0000    diagnostix cartridge?
  57.                     ;SHR - note: 5f not 3f as it was!
  58.     bne.s    nextbit
  59.     lea    nostix,a0
  60.     bsr    print
  61.     bra.s    honda
  62. nextbit    move.l    #$fa0000,a5        use 'safe' register
  63.     cmp.l    #$abcdef42,(a5)+    user cartridge? (rippers etc)
  64.     bne.s    kein_cart
  65.     lea    ripper,a0
  66.     bsr    print
  67.     lea    rip2,a0
  68.     bsr    print
  69. app_plus    lea    rip3,a0
  70.     bsr    print
  71.     lea    $14(a5),a0    ;cartridge app name
  72.     bsr    print
  73.     lea    crlf,a0
  74.     bsr    print
  75.     lea    (a5),a5    ;pointer to next cart app header
  76.     move.l    a5,d0
  77.     tst.l    d0
  78.     bne.s    app_plus    ;loop for next app names
  79.     bra.s    honda
  80. kein_cart    lea    cartless,a0
  81.     bsr    print
  82. honda    rts
  83.  
  84. ***************************************************************************
  85. * One way of checking for a meg of memory! - could write over a program!
  86. * SHR - Use the _phystop variable - multitos would stop you from writing
  87. * into (potentially) some other program's memory and falcons no longer
  88. * appear to use the memory configuration registers ($ff8004 or $424)
  89. * _phystop is at $42e and contains the address of the first unuseable
  90. * byte of memory.
  91. checkmeg    
  92.     move.l    #memmsg1,a0
  93.     bsr    print
  94.     move.l    $42e.w,d0
  95.     lsr.l    #8,d0    ;get it in K's
  96.     lsr.l    #2,d0    ;i.e. divide by 2^10=1024
  97.     move.l    #memsize,a0
  98.     bsr.s    long_val
  99.     move.l    #memsize,a0
  100.     bsr    print
  101.     move.l    #memmsg2,a0
  102.     bsr    print
  103.     rts
  104.  
  105. long_val    move.l    a0,a1
  106.     move.b    #$30,(a0)
  107. lv_1    addq.b    #1,(a0)
  108.     sub.l    #1000000000,d0
  109.     bge.s    lv_1
  110.     cmp.b    #$31,(a0)    ;zero answer
  111.     bne.s    lv_1x    ;if not, carry on
  112.     cmp.l    a0,a1    ;leading zero
  113.     beq.s    lv_1y    ;if so, write over it
  114. lv_1x    subq.b    #1,(a0)+
  115. lv_1y    add.l    #1000000000,d0
  116.     move.b    #$30,(a0)
  117. lv_2    addq.b    #1,(a0)
  118.     sub.l    #100000000,d0
  119.     bge.s    lv_2
  120.     cmp.b    #$31,(a0)    ;zero answer
  121.     bne.s    lv_2x    ;if not, carry on
  122.     cmp.l    a0,a1    ;leading zero
  123.     beq.s    lv_2y    ;if so, write over it
  124. lv_2x    subq.b    #1,(a0)+
  125. lv_2y    add.l    #100000000,d0
  126.     move.b    #$30,(a0)
  127. lv_3    addq.b    #1,(a0)
  128.     sub.l    #10000000,d0
  129.     bge.s    lv_3
  130.     cmp.b    #$31,(a0)    ;zero answer
  131.     bne.s    lv_3x    ;if not, carry on
  132.     cmp.l    a0,a1    ;leading zero
  133.     beq.s    lv_3y    ;if so, write over it
  134. lv_3x    subq.b    #1,(a0)+
  135. lv_3y    add.l    #10000000,d0
  136.     move.b    #$30,(a0)
  137. lv_4    addq.b    #1,(a0)
  138.     sub.l    #1000000,d0
  139.     bge.s    lv_4
  140.     cmp.b    #$31,(a0)    ;zero answer
  141.     bne.s    lv_4x    ;if not, carry on
  142.     cmp.l    a0,a1    ;leading zero
  143.     beq.s    lv_4y    ;if so, write over it
  144. lv_4x    subq.b    #1,(a0)+
  145. lv_4y    add.l    #1000000,d0
  146.     move.b    #$30,(a0)
  147. lv_5    addq.b    #1,(a0)
  148.     sub.l    #100000,d0
  149.     bge.s    lv_5
  150.     cmp.b    #$31,(a0)    ;zero answer
  151.     bne.s    lv_5x    ;if not, carry on
  152.     cmp.l    a0,a1    ;leading zero
  153.     beq.s    lv_5y    ;if so, write over it
  154. lv_5x    subq.b    #1,(a0)+
  155. lv_5y    add.l    #100000,d0
  156.     move.b    #$30,(a0)
  157. lv_6    addq.b    #1,(a0)
  158.     sub.l    #10000,d0
  159.     bge.s    lv_6
  160.     cmp.b    #$31,(a0)    ;zero answer
  161.     bne.s    lv_6x    ;if not, carry on
  162.     cmp.l    a0,a1    ;leading zero
  163.     beq.s    lv_6y    ;if so, write over it
  164. lv_6x    subq.b    #1,(a0)+
  165. lv_6y    add.l    #10000,d0
  166.     move.b    #$30,(a0)
  167. lv_7    addq.b    #1,(a0)
  168.     sub.l    #1000,d0
  169.     bge.s    lv_7
  170.     cmp.b    #$31,(a0)    ;zero answer
  171.     bne.s    lv_7x    ;if not, carry on
  172.     cmp.l    a0,a1    ;leading zero
  173.     beq.s    lv_7y    ;if so, write over it
  174. lv_7x    subq.b    #1,(a0)+
  175. lv_7y    add.l    #1000,d0
  176.     move.b    #$30,(a0)
  177. lv_8    addq.b    #1,(a0)
  178.     sub.l    #100,d0
  179.     bge.s    lv_8
  180.     cmp.b    #$31,(a0)    ;zero answer
  181.     bne.s    lv_8x    ;if not, carry on
  182.     cmp.l    a0,a1    ;leading zero
  183.     beq.s    lv_8y    ;if so, write over it
  184. lv_8x    subq.b    #1,(a0)+
  185. lv_8y    add.l    #100,d0
  186.     move.b    #$30,(a0)
  187. lv_9    addq.b    #1,(a0)
  188.     sub.l    #10,d0
  189.     bge.s    lv_9
  190.     cmp.b    #$31,(a0)    ;zero answer
  191.     bne.s    lv_9x    ;if not, carry on
  192.     cmp.l    a0,a1    ;leading zero
  193.     beq.s    lv_9y    ;if so, write over it
  194. lv_9x    subq.b    #1,(a0)+
  195. lv_9y    add.l    #10,d0
  196.     move.b    #$30,(a0)
  197. lv_A    addq.b    #1,(a0)
  198.     subq.l    #1,d0
  199.     bge.s    lv_A
  200.     subq.b    #1,(a0)+
  201.     addq.l    #1,d0
  202.     clr.b    (a0)+
  203.     rts
  204.     
  205. ***************************************************************************
  206. * All this bit checks for valid system base and finds TOS number
  207.  
  208. tos_check    move.l      $4f2.w,a0        get system base address, _sysbase
  209.             move.l      a0,sys_base       save for later use
  210.             lea       $14(a0),a0           add $14 to get '_os_magic' value 
  211.             move.l      (a0),a1
  212.             move.l      (a1),d0
  213.  
  214. *  should be 'magic' number #$87654321 in d0. This should be tested
  215. *  to confirm that we have a valid sys_base. Assume ok (not anymore!).
  216.  
  217.     bsr    base_ok?
  218.  
  219.             clr.l       d0
  220.             move.l      sys_base,a4    ;safe register
  221.             addq.l       #2,a4     ;add 2 to get actual TOS versions
  222.     move.l    #tosver,a0
  223.     bsr    print
  224.             move.b      (a4)+,d0
  225.     move.l    #memsize,a0
  226.     bsr.s    byte_val    
  227.     move.l    #memsize,a0
  228.     bsr    print
  229.     move.l    #tosrev,a0
  230.     bsr    print
  231.     move.b    (a4),d0    ;frigged - want hex not decimal
  232.     lsr.b    #4,d0    ;1st hex digit
  233.     move.l    #memsize,a0
  234.     bsr.s    byte_val
  235.     move.b    (a4),d0
  236.     and.b    #15,d0    ;2nd hex digit
  237.     move.l    #memsize+1,a0
  238.     bsr.s    byte_val
  239.     move.l    #memsize,a0
  240.     bsr    print
  241.     move.l    #crlf,a0
  242.     bsr    print
  243.     rts
  244.     
  245. byte_val    ext.w    d0
  246.     ext.l    d0
  247.     move.l    a0,a1
  248.     divu    #100,d0
  249.     move.b    #$30,(a0)
  250.     cmp.b    #0,d0    ;leading zero?
  251.     bne.s    bv_1x
  252.     cmp.l    a0,a1
  253.     beq.s    bv_1y
  254. bv_1x    add.b    d0,(a0)+
  255. bv_1y    swap    d0    ;remainder
  256.     ext.l    d0
  257.     divu    #10,d0
  258.     move.b    #$30,(a0)
  259.     cmp.b    #0,d0    ;leading zero?
  260.     bne.s    bv_2x
  261.     cmp.l    a0,a1
  262.     beq.s    bv_2y
  263. bv_2x    add.b    d0,(a0)+
  264. bv_2y    swap    d0    ;remainder
  265.     move.b    #$30,(a0)
  266.     add.b    d0,(a0)+
  267.     clr.b    (a0)+
  268.     rts
  269. ; sys_base check by T.S.C.
  270. ; We really only need to check one part of d0 for the valid sys_base but 
  271. ; lets do both anyway.
  272.  
  273. base_ok?    cmp.l    #$87654321,d0        check _sysbase
  274.     beq.s    itsok        ok?  so its a valid sys_base
  275. badnews    lea    bad_base,a0
  276.     bsr.s    print
  277.     bra    cont        exit cos invalid sys_base
  278. itsok    lea    ok_base,a0
  279.     bsr.s    print
  280.     rts
  281. ***************************************************************************
  282. * Check for STE - should use cookie jar! - assuming it exists!
  283.  
  284. ste_hard    lea    $5a0.w,a4
  285.     tst.l    $5a0.w
  286.     beq.s    notcookie
  287.     move.l    (a4),a4
  288. nxt_cookie    move.l    (a4)+,d0    ;cookie
  289.     move.l    (a4)+,d1    ;value
  290.     tst.l    d0
  291.     beq.s    ian    ;end of cookies    
  292.     cmp.l    #"_MCH",d0
  293.     bne.s    nxt_cookie
  294.     swap    d1    ;high word contains machine type
  295.     lsl.w    #2,d1    ;index to messages
  296.     move.l    #mch_types,a0
  297.     move.l    (a0,d1.w),a0
  298.     bsr.s    print
  299.     rts
  300. notcookie    move.l    #no_e_in_it,a0
  301.     bsr.s    print
  302. ian    rts
  303.  
  304. ***************************************************************************
  305. print    move.l      a0,-(sp)      print message
  306.            move.w      #9,-(sp)  
  307.            trap        #1
  308.            addq.l      #6,sp     
  309.     rts
  310. wait    move.w    #7,-(sp)        wait for a key
  311.     trap    #1
  312.     addq.l    #2,sp
  313.     rts
  314.  
  315.     bss
  316. sys_base    ds.l    1
  317. memsize    ds.b    12    ;room for 32 bit number
  318.     data
  319. mch_types    dc.l    stfm,ste,tt,falc
  320. stfm    dc.b    "This is a vanilla flavour ST",13,10,0
  321. ste    dc.b    "This is an STE",13,10,0
  322. tt    dc.b    "This is the Infamous TT",13,10,0
  323. falc    dc.b    "This Lucky Sod has a falcon!",13,10,0
  324. bad_base    dc.b    "Invald System Base!!!",0
  325. ok_base    dc.b    "Valid System Base",13,10,0
  326. tosver    dc.b    "TOS Version ",0
  327. tosrev    dc.b    " Revision ",0
  328. no_e_in_it    dc.b    "This Is An Old TOS with NO COOKIES!",13,10,0
  329. nostix    dc.b    "There Is A Diagnostic Cartridge Plugged In",13,10,0
  330. ripper    dc.b    "There Is A User Cartridge Plugged In And Active",13,10,0
  331. rip2    dc.b    "Containing: ",13,10,0
  332. rip3    dc.b    "            ",0
  333. crlf    dc.b    13,10,0
  334. cartless    dc.b    "No Cartridges Detected/Active",13,10,0
  335. memmsg1    dc.b    "There is ",0
  336. memmsg2    dc.b    "K of system RAM present",13,10,0
  337.     even
  338.  
  339.  
  340.  
  341.  
  342.