home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / apple2 / 26233 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  22.0 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!news.udel.edu!bach.udel.edu!lecates
  2. From: lecates@bach.udel.edu (Roy LeCates)
  3. Newsgroups: comp.sys.apple2
  4. Subject: Re: GS id
  5. Message-ID: <C07FLy.5Jz@news.udel.edu>
  6. Date: 2 Jan 93 02:15:34 GMT
  7. References: <JOHNP.93Jan1172507@silver.lcs.mit.edu>
  8. Sender: usenet@news.udel.edu
  9. Organization: University of Delaware
  10. Lines: 543
  11. Nntp-Posting-Host: bach.udel.edu
  12.  
  13. In article <JOHNP.93Jan1172507@silver.lcs.mit.edu> johnp@silver.lcs.mit.edu (John Palaima) writes:
  14. >I am interested in telling WHAT machine a program is running on to activate app
  15. >ropriate title screens text coloring etc on the GS and //e and i need the addre
  16. >sses to poke.. I trie both $fbb3 and $fbc0 on my //e and my friends GS and THE\
  17. >Y MATCH.. i was told there are a total of 4 bytes i need to check..where are the other 2...
  18.  
  19. That information is located in the Apple II Miscellaneous Tech Notes.
  20. Just for convenience, here it is!
  21.  
  22. ------------------------------------------------------------
  23.  
  24. Apple II
  25. Technical Notes
  26. _____________________________________________________________________________
  27.                                                   Developer Technical Support
  28.  
  29.  
  30. Apple II Miscellaneous
  31. #2:    Apple II Family Identification Routines 2.2
  32.  
  33. Revised by:    Jim Luther    May 1991
  34. Revised by:    Matt Deatherage & Keith Rollin    November 1988
  35. Revised by:    Pete McDonald    January 1986
  36.  
  37. This Technical Note presents a new version of the Apple II Family 
  38. Identification Routine, a sample piece of code which shows how to identify 
  39. various Apple II computers and their memory configurations.
  40.  
  41. Changes since November 1988:  Converted the identification routine from Apple 
  42. II Assembler/Editor (EDASM) source code to Apple IIgs Programmer's Workshop 
  43. (APW) Assembler source code.  Added the Apple IIe Card for the Macintosh LC 
  44. to the identification routine's lookup table and memory check routine.  Made 
  45. minor corrections to text.
  46. _____________________________________________________________________________
  47.  
  48.  
  49. Why Identification Routines?
  50.  
  51. Although we present the Apple II family identification bytes in Apple II 
  52. Miscellaneous Technical Note #7, many people would prefer a routine they can 
  53. simply plug into their own program and call.  In addition, this routine 
  54. serves as a small piece of sample code, and there is no reason for you to 
  55. reinvent the wheel.
  56.  
  57. Most of the interesting part of the routine consists of identifying the 
  58. memory configuration of the machine.  On an Apple IIe, the routine moves code 
  59. into the zero page to test for the presence of auxiliary memory.  (A IIe with 
  60. a non-extended 80-column card is a configuration still found in many schools 
  61. throughout the country.)
  62.  
  63. The actual identification is done by a table-lookup method.
  64.  
  65.  
  66. What the Routine Returns
  67.  
  68. This version (2.2) of the identification routine returns several things:
  69.  
  70. o   A machine byte, containing one of seven values:
  71.     $00 = Unknown machine
  72.     $01 = Apple ][
  73.     $02 = Apple ][+
  74.     $03 = Apple /// in emulation mode
  75.     $04 = Apple IIe
  76.     $05 = Apple IIc
  77.     $06 = Apple IIe Card for the Macintosh LC
  78.  
  79.     In addition, if the high bit of the byte is set, the machine is a IIgs or 
  80.     equivalent.  For all current Apple IIgs computers, the value returned in 
  81.     machine is $84 (high bit set to signify Apple IIgs and $04 because it 
  82.     matches the ID bytes of an enhanced Apple IIe).
  83. o   A ROMlevel byte, indicating the revision of the firmware in the machine.  
  84.     For example, there are currently five revisions of the IIc, two of the 
  85.     IIe (unenhanced and enhanced), and three versions of the IIgs ROM (there 
  86.     will always be some owners who have not yet upgraded from ROM 00 to ROM 
  87.     01).  These versions are identified starting at $01 for the earliest.  
  88.     Therefore, the current IIc will return ROMlevel = $05, the current IIgs 
  89.     will return ROMlevel = $03, etc.  The routine will also return correct 
  90.     values for future versions of the IIgs, as a convention has been 
  91.     established for future ROM versions of that machine.
  92. o   A memory byte, containing the amount of memory in the machine.  This byte 
  93.     only has four values--0 (undefined), 48, 64, and 128.  Extra memory in an 
  94.     Apple IIgs, or extra memory in an Apple IIe or IIc Memory Expansion card, 
  95.     is not included.  Programs must take special considerations to use that 
  96.     memory (if available), beyond those considerations required to use the 
  97.     normal 128K of today's IIe and IIc.
  98. o   If running on an Apple IIgs, three word-length fields are also returned.  
  99.     These are the contents of the registers as returned by the ID routine in 
  100.     the IIgs ROM, and they indicate several things about the machine.  See 
  101.     Apple II Miscellaneous Technical Note #7 for more details.
  102.  
  103. In addition to these features, most of the addressing done in the routine is 
  104. by label.  If you wish things to be stored in different places, simply 
  105. changing the labels will often do it.
  106.  
  107.  
  108. Limitations and Improvements
  109.  
  110. As sample code, you might have already guessed that this is not the most 
  111. compact, efficient way of identifying these machines.  Some improvements you 
  112. might incorporate if using these routines include:
  113.  
  114. o    If you are running under ProDOS, you can remove the section that 
  115.      determines how much memory is in the machine (starting at exit, line 
  116.      127), since the MACHID byte (at $BF98) in ProDOS already contains this 
  117.      information for you.  This change would cut the routine down to less 
  118.      than one page of memory.
  119. o    If you know the ROM is switched in when you call the routine, you can 
  120.      remove the sections which save and restore the language card state.  Be 
  121.      careful in doing so, however, because the memory-determination routines 
  122.      switch out the ROM to see if a language card exists.
  123. o    If you need to know if a IIe is a 64K machine with a non-extended 
  124.      80-column card, you may put your own identifying routines in after line 
  125.      284.  NoAux is only reached if there is an 80-column card but only 64K 
  126.      of memory.
  127.  
  128.  
  129.  
  130. How It Works
  131.  
  132. The identification routine does the following things:
  133.  
  134. o    Disables interrupts
  135. o    Saves four bytes from the language card areas so they may be restored 
  136.      later
  137. o    Identifies all machines by a table look-up procedure
  138. o    Calls 16-bit ID routine to distinguish IIgs from other machines of any 
  139.      kind, and returns values in appropriate locations if IIgs ID routine 
  140.      returns any useful information in the registers
  141. o    Identifies memory configuration:
  142. o    If Apple /// emulation, there is 48K
  143. o    If Apple ][ or ][+, tests for presence of language card and returns 64K 
  144.      if present, otherwise, returns 48K
  145. o    If Apple IIc or IIgs, returns 128K
  146. o    If Apple IIe, tries to identify auxiliary memory
  147. o    If reading auxiliary memory, it must be there
  148. o    If reading alternate zero page, auxiliary memory is present
  149. o    If none of this is conclusive:
  150. o    Exchanges a section of the zero page with a section of code that 
  151.      switches memory banks.  The code executes in the zero page and does not 
  152.      get switched out when we attempt to switch in the auxiliary RAM.
  153. o    Jumps to relocated code on page zero:
  154. o    Switches in auxiliary memory for reading and writing
  155. o    Stores a value at $800 and sees if the same value appears at $C00.  If   
  156.      so, no auxiliary memory is present (the non-extended 80-column card has 
  157.      sparse memory mapping which causes $800 and $C00 to be the same 
  158.      location).
  159. o    Changes value at $C00 and sees if the value at $800 changes as well.  If 
  160.      so, no auxiliary memory.  If not, then there is 128K available
  161. o    Switches main memory back in for reading and writing
  162. o    Puts the zero page back like we found it
  163. o    Returns memory configuration found (either 64K or 128K)
  164. o    Restores language card and ROM state from four saved bytes
  165. o    Restores interrupt status
  166. o    Returns to caller
  167.  
  168.  
  169.            keep ID2.2
  170.  
  171.            list on
  172.  
  173.            org $2000
  174.  
  175.            longa off
  176.            longi off
  177.  
  178. *********************************************
  179. *                                           *
  180. *  Apple II Family Identification Program   *
  181. *                                           *
  182. *               Version 2.2                 *
  183. *                                           *
  184. *               March, 1990                 *
  185. *                                           *
  186. *  Includes support for the Apple IIe Card  *
  187. *  for the Macintosh LC.                    *
  188. *                                           *
  189. *********************************************
  190.  
  191.  
  192. ;  First, some global equates for the routine:
  193.  
  194. PROGRAM    start
  195.  
  196. IIplain    equ $01          ;Apple II
  197. IIplus     equ $02          ;Apple II+
  198. IIIem      equ $03          ;Apple /// in emulation mode
  199. IIe        equ $04          ;Apple IIe
  200. IIc        equ $05          ;Apple IIc
  201. IIeCard    equ $06          ;Apple IIe Card for the Macintosh LC
  202.  
  203. safe       equ $0001        ;start of code relocated to zp
  204. location   equ $06          ;zero page location to use
  205.  
  206. test1      equ $AA          ;test byte #1
  207. test2      equ $55          ;lsr of test1
  208. test3      equ $88          ;test byte #3
  209. test4      equ $EE          ;test byte #4
  210.  
  211. begpage1   equ $400         ;beginning of text page 1
  212. begpage2   equ $800         ;beginning of text page 2
  213. begsprse   equ $C00         ;byte after text page 2
  214.  
  215. clr80col   equ $C000        ;disable 80-column store
  216. set80col   equ $C001        ;enable 80-column store
  217. rdmainram  equ $C002        ;read main ram
  218. rdcardram  equ $C003        ;read aux ram
  219. wrmainram  equ $C004        ;write main ram
  220. wrcardram  equ $C005        ;write aux ram
  221. rdramrd    equ $C013        ;are we reading aux ram?
  222. rdaltzp    equ $C016        ;are we reading aux zero page?
  223. rd80col    equ $C018        ;are we using 80-columns?
  224. rdtext     equ $C01A        ;read if text is displayed
  225. rdpage2    equ $C01C        ;read if page 2 is displayed
  226. txtclr     equ $C050        ;switch in graphics
  227. txtset     equ $C051        ;switch in text
  228. txtpage1   equ $C054        ;switch in page 1
  229. txtpage2   equ $C055        ;switch in page 2
  230. ramin      equ $C080        ;read LC bank 2, write protected
  231. romin      equ $C081        ;read ROM, 2 reads write enable LC
  232. lcbank1    equ $C08B        ;LC bank 1 enable
  233.  
  234. lc1        equ $E000        ;bytes to save for LC
  235. lc2        equ $D000        ;save/restore routine
  236. lc3        equ $D400
  237. lc4        equ $D800
  238.  
  239. idroutine  equ $FE1F        ;IIgs id routine
  240.  
  241. ;  Start by saving the state of the language card banks and
  242. ;  by switching in main ROM.
  243.  
  244. strt       php              ;save the processor state
  245.            sei              ;before disabling interrupts
  246.            lda lc1          ;save four bytes from
  247.            sta save         ;ROM/RAM area for later
  248.            lda lc2          ;restoring of RAM/ROM
  249.            sta save+1       ;to original condition
  250.            lda lc3
  251.            sta save+2
  252.            lda lc4
  253.            sta save+3
  254.            lda $C081        ;read ROM
  255.            lda $C081
  256.            lda #0           ;start by assuming unknown machine
  257.            sta machine
  258.            sta romlevel
  259.  
  260. IdStart    lda location     ;save zero page locations
  261.            sta save+4       ;for later restoration
  262.            lda location+1
  263.            sta save+5
  264.            lda #$FB         ;all ID bytes are in page $FB
  265.            sta location+1   ;save in zero page as high byte
  266.            ldx #0           ;init pointer to start of ID table
  267. loop       lda IDTable,x    ;get the machine we are testing for
  268.            sta machine      ;and save it
  269.            lda IDTable+1,x  ;get the ROM level we are testing for
  270.            sta romlevel     ;and save it
  271.            ora machine      ;are both zero?
  272.            beq matched      ;yes - at end of list - leave
  273.  
  274. loop2      inx              ;bump index to loc/byte pair to test
  275.            inx
  276.            lda IDTable,x    ;get the byte that should be in ROM
  277.            beq matched      ;if zero, we're at end of list
  278.            sta location     ;save in zero page
  279.  
  280.            ldy #0           ;init index for indirect addressing
  281.            lda IDTable+1,x  ;get the byte that should be in ROM
  282.            cmp (Location),y ;is it there?
  283.            beq loop2        ;yes, so keep on looping
  284.  
  285. loop3      inx              ;we didn't match. Scoot to the end of the
  286.            inx              ;line in the ID table so we can start
  287.            lda IDTable,x    ;checking for another machine
  288.            bne loop3
  289.            inx              ;point to start of next line
  290.            bne loop         ;should always be taken
  291.  
  292. matched    anop
  293.  
  294. ;  Here we check the 16-bit ID routine at idroutine ($FE1F).  If it
  295. ;  returns with carry clear, we call it again in 16-bit
  296. ;  mode to provide more information on the machine.
  297.  
  298. idIIgs     sec              ;set the carry bit
  299.            jsr idroutine    ;Apple IIgs ID Routine
  300.            bcc idIIgs2      ;it's a IIgs or equivalent
  301.            jmp IIgsOut      ;nope, go check memory
  302. idIIgs2    lda machine      ;get the value for machine
  303.            ora #$80         ;and set the high bit
  304.            sta machine      ;put it back
  305.            clc              ;get ready to switch into native mode
  306.            xce
  307.            php              ;save the processor status
  308.            rep #$30         ;sets 16-bit registers
  309.            longa on
  310.            longi on
  311.            jsr idroutine    ;call the ID routine again
  312.            sta IIgsA        ;16-bit store!
  313.            stx IIgsX        ;16-bit store!
  314.            sty IIgsY        ;16-bit store!
  315.            plp              ;restores 8-bit registers
  316.            xce              ;switches back to whatever it was before
  317.            longa off
  318.            longi off
  319.  
  320.            ldy IIgsY        ;get the ROM vers number (starts at 0)
  321.            cpy #$02         ;is it ROM 01 or 00?
  322.            bcs idIIgs3      ;if not, don't increment
  323.            iny              ;bump it up for romlevel
  324. idIIgs3    sty romlevel     ;and put it there
  325.            cpy #$01         ;is it the first ROM?
  326.            bne IIgsOut      ;no, go on with things
  327.            lda IIgsY+1      ;check the other byte too
  328.            bne IIgsOut      ;nope, it's a IIgs successor
  329.            lda #$7F         ;fix faulty ROM 00 on the IIgs
  330.            sta IIgsA
  331. IIgsOut    anop
  332.  
  333. ******************************************
  334. * This part of the code checks for the   *
  335. * memory configuration of the machine.   *
  336. * If it's a IIgs, we've already stored   *
  337. * the total memory from above.  If it's  *
  338. * a IIc or a IIe Card, we know it's      *
  339. * 128K; if it's a ][+, we know it's at   *
  340. * least 48K and maybe 64K.  We won't     *
  341. * check for less than 48K, since that's  *
  342. * a really rare circumstance.            *
  343. ******************************************
  344.  
  345. exit       lda machine      ;get the machine kind
  346.            bmi exit128      ;it's a 16-bit machine (has 128K)
  347.            cmp #IIc         ;is it a IIc?
  348.            beq exit128      ;yup, it's got 128K
  349.            cmp #IIeCard     ;is it a IIe Card?
  350.            beq exit128      ;yes, it's got 128K
  351.            cmp #IIe         ;is it a IIe?
  352.            bne contexit     ;yes, go muck with aux memory
  353.            jmp muckaux
  354. contexit   cmp #IIIem       ;is it a /// in emulation?
  355.            bne exitII       ;nope, it's a ][ or ][+
  356.            lda #48          ;/// emulation has 48K
  357.            jmp exita
  358. exit128    lda #128         ;128K
  359. exita      sta memory
  360. exit1      lda lc1          ;time to restore the LC
  361.            cmp save         ;if all 4 bytes are the same
  362.            bne exit2        ;then LC was never on so
  363.            lda lc2          ;do nothing
  364.            cmp save+1
  365.            bne exit2
  366.            lda lc3
  367.            cmp save+2
  368.            bne exit2
  369.            lda lc4
  370.            cmp save+3
  371.            beq exit6
  372. exit2      lda $C088        ;no match! so turn first LC
  373.            lda lc1          ;bank on and check
  374.            cmp save
  375.            beq exit3
  376.            lda $C080
  377.            jmp exit6
  378. exit3      lda lc2
  379.            cmp save+1       ;if all locations check
  380.            beq exit4        ;then do more more else
  381.            lda $C080        ;turn on bank 2
  382.            jmp exit6
  383. exit4      lda lc3          ;check second byte in bank 1
  384.            cmp save+2
  385.            beq exit5
  386.            lda $C080        ;select bank 2
  387.            jmp exit6
  388. exit5      lda lc4          ;check third byte in bank 1
  389.            cmp save+3
  390.            beq exit6
  391.            lda $C080        ;select bank 2
  392. exit6      plp              ;restore interrupt status
  393.            lda save+4       ;put zero page back
  394.            sta location
  395.            lda save+5       ;like we found it
  396.            sta location+1
  397.            rts              ;and go home.
  398.  
  399. exitII     lda lcbank1      ;force in language card
  400.            lda lcbank1      ;bank 1
  401.            ldx lc2          ;save the byte there
  402.            lda #test1       ;use this as a test byte
  403.            sta lc2
  404.            eor lc2          ;if the same, should return zero
  405.            bne noLC
  406.            lsr lc2          ;check twice just to be sure
  407.            lda #test2       ;this is the shifted value
  408.            eor lc2          ;here's the second check
  409.            bne noLC
  410.            stx lc2          ;put it back!
  411.            lda #64          ;there's 64K here
  412.            jmp exita
  413. noLC       lda #48          ;no restore - no LC!
  414.            jmp exita        ;and get out of here
  415.  
  416. muckaux    ldx rdtext       ;remember graphics in X
  417.            lda rdpage2      ;remember current video display
  418.            asl A            ;in the carry bit
  419.            lda #test3       ;another test character
  420.            bit rd80col      ;remember video mode in N
  421.            sta set80col     ;enable 80-column store
  422.            php              ;save N and C flags
  423.            sta txtpage2     ;set page two
  424.            sta txtset       ;set text
  425.            ldy begpage1     ;save first character
  426.            sta begpage1     ;and replace it with test character
  427.            lda begpage1     ;get it back
  428.            sty begpage1     ;and put back what was there
  429.            plp
  430.            bcs muck2        ;stay in page 2
  431.            sta txtpage1     ;restore page 1
  432. muck1      bmi muck2        ;stay in 80-columns
  433.            sta $c000        ;turn off 80-columns
  434. muck2      tay              ;save returned character
  435.            txa              ;get graphics/text setting
  436.            bmi muck3
  437.            sta txtclr       ;turn graphics back on
  438. muck3      cpy #test3       ;finally compare it
  439.            bne nocard       ;no 80-column card!
  440.            lda rdramrd      ;is aux memory being read?
  441.            bmi muck128      ;yup, there's 128K!
  442.            lda rdaltzp      ;is aux zero page used?
  443.            bmi muck128      ;yup!
  444.            ldy #done-start
  445. move       ldx start-1,y    ;swap section of zero page
  446.            lda |safe-1,y    ;code needing safe location during
  447.            stx safe-1,y     ;reading of aux mem
  448.            sta start-1,Y
  449.            dey
  450.            bne move
  451.            jmp |safe        ;jump to safe ground
  452. back       php              ;save status
  453.            ldy #done-start  ;move zero page back
  454. move2      lda start-1,y
  455.            sta |safe-1,y
  456.            dey
  457.            bne move2
  458.            pla
  459.            bcs noaux
  460. isaux      jmp muck128      ;there is 128K
  461.  
  462. *  You can put your own routine at "noaux" if you wish to
  463. *  distinguish between 64K without an 80-column card and
  464. *  64K with an 80-column card.
  465.  
  466. noaux      anop
  467. nocard     lda #64          ;only 64K
  468.            jmp exita
  469. muck128    jmp exit128      ;there's 128K
  470.  
  471. *  This is the routine run in the safe area not affected
  472. *  by bank-switching the main and aux RAM.
  473.  
  474. start      lda #test4       ;yet another test byte
  475.            sta wrcardram    ;write to aux while on main zero page
  476.            sta rdcardram    ;read aux ram as well
  477.            sta begpage2     ;check for sparse memory mapping
  478.            lda begsprse     ;if sparse, these will be the same
  479.            cmp #test4       ;value since they're 1K apart
  480.            bne auxmem       ;yup, there's 128K!
  481.            asl begsprse     ;may have been lucky so we'll
  482.            lda begpage2     ;change the value and see what happens
  483.            cmp begsprse
  484.            bne auxmem
  485.            sec              ;oops, no auxiliary memory
  486.            bcs goback
  487. auxmem     clc
  488. goback     sta wrmainram    ;write main RAM
  489.            sta rdmainram    ;read main RAM
  490.            jmp back         ;continue with program in main mem
  491. done       nop              ;end of relocated program marker
  492.  
  493.  
  494. *  The storage locations for the returned machine ID:
  495.  
  496. machine    ds  1            ;the type of Apple II
  497. romlevel   ds  1            ;which revision of the machine
  498. memory     ds  1            ;how much memory (up to 128K)
  499. IIgsA      ds  2            ;16-bit field
  500. IIgsX      ds  2            ;16-bit field
  501. IIgsY      ds  2            ;16-bit field
  502. save       ds  6            ;six bytes for saved data
  503.  
  504. IDTable    dc  I1'1,1'      ;Apple ][
  505.            dc  H'B3 38 00'
  506.  
  507.            dc  I1'2,1'      ;Apple ][+
  508.            dc  H'B3 EA 1E AD 00'
  509.  
  510.            dc  I1'3,1'      ;Apple /// (emulation)
  511.            dc  H'B3 EA 1E 8A 00'
  512.  
  513.            dc  I1'4,1'      ;Apple IIe (original)
  514.            dc  H'B3 06 C0 EA 00'
  515.  
  516. ;  Note: You must check for the Apple IIe Card BEFORE you
  517. ;  check for the enhanced Apple IIe since the first
  518. ;  two identification bytes are the same.
  519.  
  520.            dc  I1'6,1'      ;Apple IIe Card for the Macintosh LC (1st 
  521. release)
  522.            dc  H'B3 06 C0 E0 DD 02 BE 00 00'
  523.  
  524.            dc  I1'4,2'      ;Apple IIe (enhanced)
  525.            dc  H'B3 06 C0 E0 00'
  526.  
  527.            dc  I1'5,1'      ;Apple IIc (original)
  528.            dc  H'B3 06 C0 00 BF FF 00'
  529.  
  530.            dc  I1'5,2'      ;Apple IIc (3.5 ROM)
  531.            dc  H'B3 06 C0 00 BF 00 00'
  532.  
  533.            dc  I1'5,3'      ;Apple IIc (Mem. Exp)
  534.            dc  H'B3 06 C0 00 BF 03 00'
  535.  
  536.            dc  I1'5,4'      ;Apple IIc (Rev. Mem. Exp.)
  537.            dc  H'B3 06 C0 00 BF 04 00'
  538.  
  539.            dc  I1'5,5'      ;Apple IIc Plus
  540.            dc  H'B3 06 C0 00 BF 05 00'
  541.  
  542.            dc  I1'0,0'      ;end of table
  543.  
  544.            end
  545.  
  546.  
  547. Further Reference
  548. _____________________________________________________________________________
  549.   o  Apple II Miscellaneous Technical Note #7, Apple II Family Identification
  550.  
  551. -- 
  552. ------------------------------------------------------------------
  553. Roy M. LeCates       EE Undergraduate        lecates@bach.udel.edu
  554. University of Delaware Electrical Engineering and Computer Science
  555. ------------------------------------------------------------------
  556.