home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / MEMORY2.ASM < prev    next >
Assembly Source File  |  1994-11-29  |  12KB  |  411 lines

  1.     PAGE    66,132
  2. ;****************************** MEMORY2.ASM *********************************
  3. ;
  4. ;----------------------------------------------------------------------------
  5. LIBSEG           segment byte public "LIB"
  6.         assume cs:LIBSEG , ds:nothing
  7.  
  8. ;----------------------------------------------------------------------------
  9. .xlist
  10.     include  mac.inc
  11.     include  common.inc
  12.     extrn     word_crc1:far
  13.     extrn     find_cpu_type:far
  14. .list
  15. ;----------------------------------------------------------------------------
  16. ;
  17. ; structure of cmos
  18. ;
  19. ; To find fixed disk drive type information, look at locaton cm12.  The high
  20. ; nibble describes disk 1 and the low nibble describes disk 2.  If either
  21. ; nibble contains 'f' then look at locations 19h (disk 1) or location 1ah
  22. ; (disk 2) for drive type.  If either nibble is less than 'F' then it is
  23. ; the drive type.
  24. ;
  25. ; For PS/2 computers disk 1 type is stored at cm11 and disk 2 type at cm12.
  26. ; This information has not been verified accurate 100% of time.
  27. ;
  28. ; The bios uses cmos location cm12 on an AT to determine number of drives
  29. ; and type.  The PS/2 must use cmos locations cm11 & cm12 to find number
  30. ; of drives.
  31. ; IBM and most clones use the same method to determine number of drives
  32. ; and types, The cmos formats are identical.  Older IBM bios's only
  33. ; used location cm12 without extended drives, but new bios's allow the
  34. ; extended drive types stored at locations 19h & 1ah.
  35. ;
  36. cmos    struc
  37.  cm0    db    0    ;0  seconds
  38.  cm1    db    0    ;1  seconds alarm
  39.  cm2    db    0    ;2  minutes
  40.  cm3    db    0    ;3  minutes alarm
  41.  cm4    db    0    ;4  hours
  42.  cm5    db    0    ;5  hours of alarm
  43.  cm6    db    0    ;6  day of week
  44.  cm7    db    0    ;7  day of month
  45.  cm8    db    0    ;8  month
  46.  cm9    db    0    ;9  year
  47.  cm0a    db    0    ;0a status a
  48.  cm0b    db    0    ;0b status b (alarm)
  49.  cm0c    db    0    ;0c status c (flags)
  50.  cm0d    db    0    ;0d status d (battery)
  51.  cm0e    db    0    ;0e post diag status results
  52.  cm0f    db    0    ;0f shutdown status
  53.  cm10    db    0    ;10 diskette drive type            checksumed
  54.  cm11    db    0    ;11 (PS/2 fixed disk 1 type)       checksumed
  55.  cm12    db    0    ;12 fixed disk type (PS/2 disk 2)  checksumed
  56.  cm13    db    0    ;13                                checksumed
  57.  cm14    db    0    ;14 equip word low byte            checksumed
  58.  cm15    db    0    ;15 low byte base memory size      checksumed
  59.  cm16    db    0    ;16 high byte base memory size     checksumed
  60.  cm17    db    0    ;17 low byte expansion memory      checksumed
  61.  cm18    db    0    ;18 high byte expansion memory     checksumed
  62.  cm19    db    0    ;19 fixed disk type "c"            checksumed
  63.  cm1a    db    0    ;1a fixed disk type "d"            checksumed
  64.  cm1b    db    0       ;1b                                checksumed
  65.  cm1c    db    0       ;1c                                checksumed
  66.  cm1d    db    0       ;1d                                checksumed
  67.  cm1e    db    0       ;1e                                checksumed
  68.  cm1f    db    0       ;1f                                checksumed
  69.  cm20    db    0       ;20                                checksumed
  70.  cm21    db    0       ;21                                checksumed
  71.  cm22    db    0       ;22                                checksumed
  72.  cm23    db    0       ;23                                checksumed
  73.  cm24    db    0       ;24                                checksumed
  74.  cm25    db    0       ;25                                checksumed
  75.  cm26    db    0       ;26                                checksumed
  76.  cm27    db    0       ;27                                checksumed
  77.  cm28    db    0       ;28                                checksumed
  78.  cm29    db    0       ;29                                checksumed
  79.  cm2a    db    0       ;2a                                checksumed
  80.  cm2b    db    0       ;2b                                checksumed
  81.  cm2c    db    0       ;2c                                checksumed
  82.  cm2d    db    0       ;1d                                checksumed
  83.  cm2e    db    0    ;2e checksum high                  checksumed
  84.  cm2f    db    0    ;2f checksum low                   checksumed
  85.  cm30    db    0    ;30 usable mem above 1meg (low)
  86.  cm31    db    0    ;31 usable mem above 1meg (high)
  87.  cm32    db    0    ;32 century (bcd)
  88.  cm33    db    0    ;33 128k info. (status byte)
  89.  cm34    db    0    ;34 reserved
  90. cmos    ends
  91.  
  92. comment !
  93.   00h         Seconds
  94.   01h         Second Alarm
  95.   02h         Minutes
  96.   03h         Minute Alarm
  97.   04h         Hours
  98.   05h         Hour Alarm
  99.   06h         Day of the Week
  100.   07h         Day of the Month
  101.   08h         Month
  102.   09h         Year
  103.   0Ah         Status Register A
  104.   0Bh         Status Register B
  105.   0Ch         Status Register C
  106.   0Dh         Status Register D
  107.   0Eh         Diagnostic Status Byte
  108.   0Fh         Shutdown Status Byte
  109.   10h         Disk Drive Type for Drives A: and B:
  110.               The drive-type bytes use bits 0:3 for the first
  111.               drive and 4:7 for the other disk drive types.
  112.   00h         no drive present
  113.   01h         double sided 360k
  114.   02h         high capacity (1.2 meg)
  115.   03h-0Fh     reserved
  116.   11h         (AT):Reserved    (PS/2):drive type for hard disk C:
  117.   12h         (PS/2):drive type for hard disk D:
  118.               (AT, XT/286):hard disk type for drives C: and D:
  119.   Format of drive-type entry for AT, XT/286:
  120.   0       number of cyls in drive (0-1023 allowed)
  121.   2       number of heads per drive (0-15 allowed)
  122.   3       starting reduced write compensation (not used on AT)
  123.   5       starting cylinder for write compensation
  124.   7       max. ECC data burst length, XT only
  125.   8       control byte
  126.   Bit
  127.   7       disable disk-access retries
  128.   6       disable ECC retries
  129.   5-4     reserved, set to zero
  130.   3       more than 8 heads
  131.   2-0     drive option on XT (not used by AT)
  132.   9       timeout value for XT (not used by AT)
  133.   12      landing zone cylinder number
  134.   14      number of sectors per track (default 17, 0-17 allowed)
  135.   13h         Reserved
  136.   14h         Equipment Byte (corresponds to sw. 1 on PC and XT)
  137.   15h-16h     Base Memory Size      (low,high)
  138.   17h-18h     Expansion Memory Size (low,high)
  139.   19h-20h     Reserved
  140.           (PS/2) POS information Model 50 (60 and 80 use a 2k
  141.           CMOS RAM that is not accessible through software)
  142.   21h-2Dh     Reserved (not checksumed)
  143.   2Eh-2Fh     Checksum of Bytes 10 Through 20  (low,high)
  144.   30h-31h     Exp. Memory Size as Det. by POST (low,high)
  145.   32h         Date Century Byte
  146.   33h         Information Flags (set during power-on)
  147.   34h-3Fh     Reserved 
  148. !
  149.  
  150. comment 
  151. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  152. CMOS_TYPE - check cmos type
  153. ;  inputs: none
  154. ;  outputs: dl = 0 standart AT cmos
  155. ;                1 ps/2 style cmos
  156. ;               0ffh cmos is bad, checksum fails
  157. ;
  158. ;* * * * * * * * * * * * * *
  159. 
  160.     public    CMOS_TYPE
  161. CMOS_TYPE    proc    far
  162.     push    ax
  163.     call    find_cpu_type
  164.     cmp    al,1
  165.     jbe    bad_cmos
  166.     mov    dl,0                ;set AT style cmos
  167.     call    CMOS_CHECKSUM
  168.     cmp    al,0
  169.     je    cmos_exit
  170.     mov    dl,1                ;set ps/2 stlye cmos
  171.     call    CMOS_CHECKSUM
  172.     je    cmos_exit
  173. bad_cmos:
  174.     mov    dl,0ffh
  175. cmos_exit:
  176.     pop    ax
  177.     retf
  178.     
  179. CMOS_TYPE    endp
  180.  
  181.  
  182. comment 
  183. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  184. CMOS_CHECKSUM - checksum a block of cmos memory
  185. ;  inputs:  dl = cmos type,  0(at) 1(ps/2)
  186. ;  outputs: bx = cmos crc calculation
  187. ;           al = 0 (checksum ok)  1 (checkusm bad)
  188. ;
  189. ;  note:  The computed checksum is compared to the one stored in
  190. ;         cmos and if bad the -al- register is set to 1.
  191. ;
  192. ;* * * * * * * * * * * * * *
  193. 
  194.     public    CMOS_CHECKSUM
  195. CMOS_CHECKSUM    proc    far
  196.     sub    bx,bx
  197.     sub    cx,cx
  198.     mov    cl,cm10            ;diskette byte offset
  199.     mov    ch,cm2e            ;checksum high byte
  200.     cmp    dl,1            ;check if ps2
  201.     jne    cmos2
  202.     mov    bx,-1            ;init crc to -1
  203.     mov    ch,cm34            ;ps2 end point
  204.  
  205. cmos2:    mov    ah,cl
  206.  
  207.     push    ax
  208.     call    CMOS_READ_BYTE
  209.     add    sp,2        ;fix stack
  210.     
  211.     cmp    dl,1        ;check if ps2
  212.     jne    norm_cksm
  213. ;
  214. ; ps2 crc calc     al=raw data  bx=crc so far
  215. ;
  216.     call    word_crc1
  217.     jmp    norm_ck_cont
  218. norm_cksm:
  219.     xor    ah,ah
  220.     add    bx,ax
  221. norm_ck_cont:
  222.     inc    cl
  223.     cmp    ch,cl
  224.     jnz    cmos2
  225.     cmp    dl,1        ;check if ps/2
  226.     jne    normal_checksum
  227.     or    bx,bx
  228.     jnz    bad_checksum
  229. ;
  230. ; check  ps/2 checksum
  231. ;
  232.     mov    ah,cm32        ;address checksum high
  233.     
  234.     call    CMOS_READ_WORD
  235.     xchg    al,ah
  236.     mov    bx,ax
  237.     sub    ax,ax
  238.     jmp    cmos_ck_exit
  239.  
  240. normal_checksum:
  241.     mov    ah,cm2e        ;address checksum high
  242.     call    CMOS_READ_WORD
  243.     xchg    al,ah        ;fix checksum    
  244.     cmp    ax,bx
  245.     jne    bad_checksum
  246.     sub    ax,ax
  247.     jmp    cmos_ck_exit
  248. bad_checksum:
  249.     mov    al,1
  250. cmos_ck_exit:
  251.     ret
  252. CMOS_CHECKSUM    endp
  253.  
  254.  
  255. comment 
  256. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  257. CMOS_READ_BYTE - read one char from cmos memory
  258. ;  inputs:  ah = address
  259. ;  outputs: al = cmos data read
  260. ;
  261. ;* * * * * * * * * * * * * *
  262. 
  263.     public    CMOS_READ_BYTE
  264. CMOS_READ_BYTE    proc    far
  265.     pushf
  266.     mov    al,ah
  267.     rol    al,1
  268.     stc
  269.     rcr    al,1
  270.     cli
  271.     out    70h,al            ;output address
  272.     nop
  273.     nop
  274.     nop
  275.     in    al,71h            ;read data port
  276.     push    ax
  277.     mov    al,1ah            ;get default address
  278.     rcr    al,1            ;add in nmi bit
  279.     out    70h,al            ;select default loc
  280. ;
  281. ; dummy read for reported problem with PS/2 computers
  282. ;
  283.     in    al,71h            ;read cmos
  284.     
  285.     sti
  286.     pop    ax            ;restore data read
  287.     push    cs
  288.     call    popf_sub
  289.     retf
  290. ;
  291. ; this code restores flags, and nmi state
  292. ;
  293. popf_sub:
  294.     iret
  295. CMOS_READ_BYTE    endp
  296.  
  297. comment 
  298. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  299. CMOS_READ_WORD - read one word from cmos memory
  300. ;  inputs:  ah = address
  301. ;  outputs: ax = cmos data read
  302. ;
  303. ;* * * * * * * * * * * * * *
  304. 
  305.     public    CMOS_READ_WORD
  306. CMOS_READ_WORD    proc    far
  307.     push    bx
  308.     call    CMOS_READ_BYTE
  309.     mov    bl,al
  310.     inc    ah
  311.     call    CMOS_READ_BYTE
  312.     mov    ah,bl
  313.     xchg    al,ah
  314.     pop    bx
  315.     retf
  316. CMOS_READ_WORD    endp
  317.  
  318.  
  319. comment 
  320. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  321. CMOS_READ_BLOCK - read block of data from cmos memory
  322. ;  inputs:  ah = starting cmos address
  323. ;         es:di = storage location
  324. ;            cx = number of bytes to read
  325. ;  outputs: none
  326. ;
  327. ;* * * * * * * * * * * * * *
  328. 
  329.     public    CMOS_READ_BLOCK
  330. CMOS_READ_BLOCK    proc    far
  331.     cld
  332.     apush    ax,cx
  333. crb1:    call    CMOS_READ_BYTE
  334.     stosb
  335.     inc    ah
  336.     loop    crb1
  337.     apop    cx,ax
  338.     retf
  339. CMOS_READ_BLOCK    endp
  340.  
  341.  
  342. comment 
  343. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  344. CMOS_WRITE_BYTE - write one char to cmos memory
  345. ;  inputs:  ah = address
  346. ;           al = data to write
  347. ;  outputs: none
  348. ;
  349. ;* * * * * * * * * * * * * *
  350. 
  351.     public    CMOS_WRITE_BYTE
  352. CMOS_WRITE_BYTE    proc    far
  353.     out    70h,al            ;select address
  354.     jmp    $+2            ;delay
  355.     jmp    $+2            ;delay
  356.     xchg    al,ah
  357.     out    71h,al
  358.     xchg    al,ah
  359.     retf
  360. CMOS_WRITE_BYTE    endp
  361.  
  362. comment 
  363. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  364. CMOS_WRITE_WORD - write one word to cmos memory
  365. ;  inputs:  bl = cmos address to write
  366. ;           ax = data to write
  367. ;  outputs: none
  368. ;
  369. ;* * * * * * * * * * * * * *
  370. 
  371.     public    CMOS_WRITE_WORD
  372. CMOS_WRITE_WORD    proc    far
  373.     apush    ax,ax
  374.     mov    ah,bl
  375.     call    CMOS_WRITE_BYTE
  376.     pop    ax
  377.     xchg    al,ah
  378.     mov    ah,bl
  379.     inc    ah
  380.     call    CMOS_WRITE_BYTE
  381.     pop    ax
  382.     retf
  383. CMOS_WRITE_WORD    endp
  384.  
  385.  
  386. comment 
  387. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  388. CMOS_WRITE_BLOCK - write block of data to cmos memory
  389. ;  inputs:  ah = cmos address to start writing
  390. ;           ds:si = data to write
  391. ;           cx = length of write
  392. ;
  393. ;* * * * * * * * * * * * * *
  394. 
  395.     public    CMOS_WRITE_BLOCK
  396. CMOS_WRITE_BLOCK    proc    far
  397.     cld
  398.     apush    ax,cx
  399. cwb1:    lodsb
  400.     call    CMOS_WRITE_BYTE
  401.     inc    ah
  402.     loop    cwb1
  403.     apop    cx,ax
  404.     retf
  405. CMOS_WRITE_BLOCK    endp
  406.  
  407.  
  408.  
  409. LIBSEG    ENDS
  410. ;;    end
  411.