home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1992 / USERJA92.MSA / INSIDE.STE_COOKIE.S < prev    next >
Text File  |  2006-02-01  |  7KB  |  303 lines

  1. * Cookie Example Program 
  2. * Display the contents of cookie jar, and the meaning of cookies
  3. * if known
  4. * copyright c.1991 Adam Greenwood
  5. * Written with/for Devpac 2
  6.  
  7. * constants
  8.  
  9. * cookie jar pointer (p_cookies)
  10.  
  11. cookies    equ    $5a0        address of cookie pointer
  12.  
  13. * The names of the official Atari cookies so far
  14.  
  15. _cpu    equ    '_CPU'        processor cookie
  16. _vdo    equ    '_VDO'        video cookie
  17. _mch    equ    '_MCH'        machine cookie
  18. _snd    equ    '_SND'        sound chip cookie
  19. _swi    equ    '_SWI'        configuration switch cookie
  20. _frb    equ    '_FRB'        fast RAM buffer cookie    
  21.  
  22. * start of code
  23.  
  24. start    move.l    a7,a5
  25.     addq    #4,a7
  26.     move.l    4(a5),a5        get basepage
  27.     move.l    $c(a5),d0        get legth of text segment
  28.     add.l    $14(a5),d0    add length of data segment
  29.     add.l    $1c(a5),d0    add length of uninit BSS
  30.     add.l    #$100,d0        add length of basepage
  31.     move.l    d0,-(a7)        push length to reserve
  32.     move.l    a5,-(a7)        start address to modify
  33.     move.w    #0,-(a7)        zero
  34.     move.w    #$4a,-(a7)    shrink memory
  35.     trap    #1
  36.     add.l    #$c,a7
  37.  
  38.     clr.l   -(a7)        set supervisor mode
  39.     move.w  #32,-(a7)
  40.     trap    #1
  41.     addq    #6,a7
  42.     move.l  d0,stk        save old value of stack
  43.  
  44.     move.l    #intr_mess,a1    display intro message
  45.     jsr    prnt_str
  46.  
  47.     move.l    cookies,a0    address of cookie jar
  48.     beq    .no_jar        if 0 no cookie jar
  49.  
  50. * now loop round reading each pair of longwords until
  51. * the empty longword is reached
  52.  
  53. .loop    move.l    (a0)+,d0        cookie name
  54.     move.l    (a0)+,d1        cookie value 
  55.     cmp.l    #0,d0        check for empty longword
  56.     beq    .out        if empty finished
  57.  
  58.     jsr    prnt_cook        print cookie & value
  59.  
  60.     cmp.l    #_cpu,d0        check for _cpu cookie
  61.     bne.s    .2    
  62.     jsr    cook_cpu        evaluate cookie
  63.     
  64. .2    cmp.l    #_vdo,d0        check for _vdo cookie
  65.     bne.s    .3
  66.     jsr    cook_vdo        evaluate cookie
  67.     
  68. .3    cmp.l    #_mch,d0        check for _mch cookie
  69.     bne.s    .4
  70.     jsr    cook_mch        evaluate cookie
  71.  
  72. .4    cmp.l    #_snd,d0        check for _snd cookie
  73.     bne.s    .5
  74.     jsr    cook_snd        evaluate cookie
  75.  
  76. .5    move.l    #return,a1    leave a line between cookies
  77.     jsr    prnt_str
  78.  
  79.     bra    .loop        get next cookie
  80.     
  81. .no_jar    move.l    #err_mess,a1    display message
  82.     jsr    prnt_str
  83.  
  84. .out    jsr    wait_key        wait for key press
  85.  
  86.     bra    fin        done
  87.  
  88.  
  89. * routine to print name and value of cookie
  90. * in : d0.l = name of cookie
  91. *      d1.l = value of cookie
  92.  
  93. prnt_cook    movem.l    d0-d3/a1,-(a7)
  94.     
  95.     move.l    #cook_mess,a1    print 'cookie: '
  96.     jsr    prnt_str
  97.     
  98.     move.w    #3,d3        4 characters
  99.     move.l    d0,d2        
  100. .loop    rol.l    #8,d2        starting with high byte
  101.     moveq    #0,d0        clear        
  102.     move.b    d2,d0        
  103.     jsr    prnt_char        print character
  104.     dbra    d3,.loop        
  105.     
  106.     move.l    #val_mess,a1    print 'value: '
  107.     jsr    prnt_str    
  108.     
  109.     move.w    #'$',d0        print hex symbol
  110.     jsr    prnt_char
  111.     
  112.     move.w    #7,d3        8 hex characters
  113.     move.l    d1,d2        
  114. .loop2    rol.l    #4,d2        start with high
  115.     move.l    d2,d0
  116.     and.l    #$f,d0        4 bits
  117.     cmp.b    #9,d0        if <=9, number 0-9
  118.     bgt.s    .letter        else letter a-f
  119.     add.b    #48,d0        convert to number
  120.     bra    .print
  121. .letter    add.b    #87,d0        convert to letter
  122. .print    jsr    prnt_char        print character
  123.     dbra    d3,.loop2        next number
  124.  
  125.     move.l    #return,a1    next line
  126.     jsr    prnt_str
  127.     
  128.     movem.l    (a7)+,d0-d3/a1
  129.     rts
  130.  
  131. * routine to evaluate _cpu cookie
  132. * in: d1 = value
  133. * _cpu cookie is a decimal number, 00, 10, 20, 30, 40
  134. * so we first divide by 10, then use the resulting no.
  135. * 0-3 to select the correct message
  136.  
  137. cook_cpu    movem.l    d0-d1/a1,-(a7)
  138.  
  139.     move.l    #cpu_mess0,a1    first message
  140.     divu    #10,d1        divide value by 10
  141.     bra    .test        go to loop
  142.     
  143. .loop    move.b    (a1)+,d0        find end of message
  144.     bne.s    .loop        
  145. .test    dbra    d1,.loop        skip d1 messages
  146.  
  147.     jsr    prnt_str        print correct message
  148.     move.l    #return,a1    next line
  149.     jsr    prnt_str
  150.     
  151.     movem.l    (a7)+,d0-d1/a1
  152.     rts
  153.  
  154. * routine to evaluate _vdo cookie
  155. * in: d1 = cookie value
  156. * The information is in the high byte, so first we swap
  157. * then skip to the correct message.
  158.  
  159. cook_vdo    movem.l    d0-d1/a1,-(a7)
  160.  
  161.     move.l    #vdo_mess0,a1    first message
  162.     swap    d1        cookie value
  163.     bra    .test        go to loop
  164. .loop    move.b    (a1)+,d0        find end of message
  165.     bne.s    .loop
  166. .test    dbra    d1,.loop        skip d1 messages
  167.  
  168.     jsr    prnt_str        print correct message
  169.     move.l    #return,a1    next line
  170.     jsr    prnt_str
  171.  
  172.     movem.l    (a7)+,d0-d1/a1
  173.     rts
  174.  
  175. * routine to evaluate _mch cookie
  176. * This works in much the same way as for _VDO
  177.  
  178. cook_mch    movem.l    d0-d1/a1,-(a7)
  179.  
  180.     move.l    #mch_mess0,a1    first message
  181.     swap    d1        value of cookie
  182.     bra    .test        go to loop
  183. .loop    move.b    (a1)+,d0        find end of message
  184.     bne.s    .loop        
  185. .test    dbra    d1,.loop        skip d1 messages
  186.     jsr    prnt_str        print correct message
  187.     move.l    #return,a1    next line
  188.     jsr    prnt_str
  189.  
  190.     movem.l    (a7)+,d0-d1/a1
  191.     rts
  192.     
  193. * routine to evaluate _snd cookie
  194. * In this case the information is in the bits, so we test for them
  195. * in turn
  196.  
  197. cook_snd    move.l    a1,-(a7)
  198.  
  199.     btst    #0,d1        test for yamaha chip
  200.     beq.s    .dma        
  201.     move.l    #snd_mess0,a1    print message
  202.     jsr    prnt_str
  203.     move.l    #return,a1    next line
  204.     jsr    prnt_str
  205. .dma    btst    #1,d1        test for DMA chip
  206.     beq.s    .out
  207.     move.l    #snd_mess1,a1    print message
  208.     jsr    prnt_str
  209.     move.l    #return,a1    next line
  210.     jsr    prnt_str
  211.  
  212. .out    move.l    (a7)+,a1
  213.     rts
  214.  
  215. * routine to print a null terminated string to screen
  216. * a1 = address of string
  217.  
  218. prnt_str    movem.l    d0-d4/a0-a4,-(a7)
  219.  
  220.     move.l    a1,-(a7)        address of string
  221.     move.w    #9,-(a7)        print string
  222.     trap    #1
  223.     addq    #6,a7    
  224.     
  225.     movem.l    (a7)+,d0-d4/a0-a4
  226.     rts
  227.  
  228. * routine to print a character to the screen
  229. * d0.w = character 
  230.     
  231. prnt_char    movem.l    d0-d4/a0-a4,-(a7)
  232.  
  233.     move.w    d0,-(a7)        character
  234.     move.w    #2,-(a7)        print character
  235.     trap    #1
  236.     addq    #4,a7
  237.     
  238.     movem.l    (a7)+,d0-d4/a0-a4
  239.     rts
  240.  
  241. * routine to print message and wait for key press
  242.  
  243. wait_key    movem.l    d0-d4/a0-a4,-(a7)
  244.  
  245.     move.l    #key_mess,a1    print message
  246.     jsr    prnt_str
  247.  
  248.     move.w    #7,-(a7)        wait for key press
  249.     trap    #1
  250.     addq    #2,a7
  251.     
  252.     movem.l    (a7)+,d0-d4/a0-a4
  253.     rts
  254.  
  255. * Return to user mode and exit
  256.  
  257. fin    lea    stk,a6        get value of original stack
  258.     move.l    (a6),-(a7)
  259.     move.w    #32,-(a7)
  260.     trap    #1        Return to user mode
  261.     addq    #6,a7
  262.     
  263.  
  264.     move.w    #0,-(a7)
  265.     trap    #1
  266.     addq    #2,a7
  267.  
  268.  
  269.     section    BSS
  270.  
  271. stk    ds.l    1
  272.  
  273.     section    DATA
  274.     
  275. intr_mess    dc.b    'Cookie Display Program',13,10
  276.     dc.b    'Copyright ',189,'1991 A Greenwood',13,10,13,10,0
  277. err_mess    dc.b    'No Cookie Jar',13,10,0
  278. cook_mess    dc.b    'Cookie: ',0
  279. val_mess    dc.b    '  Value: ',0
  280.  
  281. return    dc.b    13,10,0
  282.  
  283. cpu_mess0    dc.b    '  68000 Processor',0
  284. cpu_mess1    dc.b    '  68010 Processor',0
  285. cpu_mess2    dc.b    '  68020 Processor',0
  286. cpu_mess3    dc.b    '  68030 Processor',0
  287. cpu_mess4    dc.b    '  68040 Processor',0
  288.  
  289. vdo_mess0    dc.b    '  Standard Video Shifter',0
  290. vdo_mess1    dc.b    '  Improved Video Shifter',0
  291. vdo_mess2    dc.b    '  TT Graphics Chip',0
  292.  
  293. mch_mess0    dc.b    '  Machine is a Standard ST',0
  294. mch_mess1    dc.b    '  Machine is an STE',0
  295. mch_mess2    dc.b    '  Machine is a Mega ST',0
  296. mch_mess3    dc.b    '  Machine is a TT',0
  297.  
  298. snd_mess0    dc.b    '  Yamaha Sound Chip Present',0
  299. snd_mess1    dc.b    '  DMA Sound Chip Present',0
  300.  
  301. key_mess    dc.b    'Press any key',0
  302.     
  303.     end