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

  1. * STE Controller Port Tester
  2. * Copyright c.1991 Adam Greenwood
  3. * Feel free to change and use this code
  4. * This program displays the current state of all the 
  5. * controller port registers om the screen
  6. * Effects such as inverse video are achieved using VT52 emulation
  7. * ie by writing escape codes to the screen.
  8. * Written with/for Devpac 2
  9.  
  10. * Constants
  11.  
  12. * Controller Port Registers
  13.  
  14. joy_fire    equ    $ff9200        Fire Buttons
  15. joy_udlr    equ    $ff9202        Directions
  16. pad0_x    equ    $ff9210        Paddle 0 X
  17. pad0_y    equ    $ff9212        Paddle 0 Y
  18. pad1_x    equ    $ff9214        Paddle 1 X
  19. pad1_y    equ    $ff9216        Paddle 1 Y
  20. light_x    equ    $ff9220        Light Pen/Gun X
  21. light_y    equ    $ff9222        Light Pen/Gun Y
  22.  
  23. * start of code
  24.  
  25. start    move.l    a7,a5
  26.     addq    #4,a7
  27.     move.l    4(a5),a5        get basepage
  28.     move.l    $c(a5),d0        get legth of text segment
  29.     add.l    $14(a5),d0    add length of data segment
  30.     add.l    $1c(a5),d0    add length of uninit BSS
  31.     add.l    #$100,d0        add length of basepage
  32.     move.l    d0,-(a7)        push length to reserve
  33.     move.l    a5,-(a7)        start address to modify
  34.     move.w    #0,-(a7)        zero
  35.     move.w    #$4a,-(a7)    shrink memory
  36.     trap    #1
  37.     add.l    #$c,a7
  38.  
  39.     clr.l    -(a7)        set supervisor mode
  40.     move.w    #32,-(a7)
  41.     trap    #1
  42.     addq    #6,a7
  43.     lea    stk,a6        save value of old stack
  44.     move.l    d0,(a6)
  45.  
  46.     move.l    #screen,a0    display main screen
  47.     jsr    prnt_strn        print whole screen as string
  48.  
  49.     move.l    #reverse,a0    escape code reverse video
  50.     jsr    prnt_strn        write escape code
  51.  
  52. .loop    move.w    #37,-(a7)        Vsync call
  53.     trap    #1        waits for vblank to 
  54.     addq    #2,a7        synchronise
  55.  
  56.     move.l    #set_fire,a0    escape code to set cursor
  57.     jsr    prnt_strn        position for fire register
  58.     move.w    joy_fire,d0    value of fire register
  59.     jsr    nib_bin        print nibble in binary
  60.     
  61.     move.l    #set_d3,a0    cursor position for direction
  62.     jsr    prnt_strn        direction
  63.     move.w    joy_udlr,d7    direction register
  64.     move.w    #3,d6        loop 4 times
  65. .print    rol.w    #4,d7        get nibble
  66.     move.b    d7,d0        
  67.     jsr    nib_bin        print nibble in binary
  68.     cmp.w    #0,d6        check for last
  69.     beq.s    .dec        no | on last nibble
  70.     move.w    #$7c,d0        | symbol
  71.     jsr    prnt_char
  72. .dec    dbra    d6,.print
  73.  
  74.     move.l    #set_0x,a0    position for paddle 0 X
  75.     jsr    prnt_strn
  76.     move.w    pad0_x,d0        value of paddle 0 X reg
  77.     and.w    #$ff,d0        only low byte valid
  78.     jsr    decimal        print as three digit no.
  79.  
  80.     move.l    #set_0y,a0    position for paddle 0 Y
  81.     jsr    prnt_strn        
  82.     move.w    pad0_y,d0        value of paddle 0 Y reg
  83.     and.w    #$ff,d0        only low byte valid
  84.     jsr    decimal        print as 3 digit no.
  85.  
  86.     move.l    #set_1x,a0    cursor for paddle 1 X
  87.     jsr    prnt_strn
  88.     move.w    pad1_x,d0        value of paddle 1 X
  89.     and.w    #$ff,d0        low byte only
  90.     jsr    decimal        print
  91.  
  92.     move.l    #set_1y,a0    cursor pos for pad 1 Y
  93.     jsr    prnt_strn        
  94.     move.w    pad1_y,d0        value of register
  95.     and.w    #$ff,d0        low byte    
  96.     jsr    decimal        print to screen
  97.  
  98.     move.l    #set_Lx,a0    Light Gun X position
  99.     jsr    prnt_strn        set cursor position
  100.     move.w    light_x,d0    value of light gun X
  101.     and.w    #$3ff,d0        lowest 10 bits
  102.     jsr    decimal        print as 3 digit no.
  103.  
  104.     move.l    #set_Ly,a0    Y position
  105.     jsr    prnt_strn        set cursor
  106.     move.w    light_y,d0    register value
  107.     and.w    #$3ff,d0        lowest 10 bits only
  108.     jsr    decimal        print to screen
  109.  
  110.     jsr    get_key        Check for key press
  111.     cmp.w    #0,d0        if no press loop
  112.     beq    .loop
  113.     
  114.     move.l    #normal,a0    Normal video
  115.     jsr    prnt_strn        write escape code
  116.     
  117.     bra    fin
  118.  
  119. * Routine to print a four bit nibble in binary
  120. * lowest four bits of d0 printed
  121.  
  122. nib_bin    movem.l    d0-d7/a0-a4,-(a7)
  123.     move.b    d0,d6
  124.  
  125.     move.w    #3,d7
  126.     rol.b    #5,d6        get bit 3 to bit 0
  127.     
  128. .loop    move.b    d6,d5
  129.     and.b    #1,d5        bit 0
  130.     move.w    #48,d0        ASCII 0
  131.     add.b    d5,d0        add 0 or 1 to ASCII 0
  132.     jsr    prnt_char        print
  133.     rol.b    d6        next bit
  134.     dbra    d7,.loop
  135.     
  136.     movem.l    (a7)+,d0-d7/a0-a4
  137.     rts
  138.     
  139. * Routine to print a word as a three digit decimal
  140. * number. The word must therefore be less than 999
  141. * in: d0 = word to print
  142.  
  143. decimal    movem.l    d5-d7,-(a7)
  144.     move.w    d0,d7
  145.  
  146.     ext.l    d7
  147.     divu    #10,d7        divide by 10
  148.     move.l    d7,d6        
  149.     swap    d6        d6 = 1s
  150.     ext.l    d7
  151.     divu    #10,d7        divide again
  152.     move.l    d7,d5        d7 = 100s
  153.     swap    d5        d5 = 10s
  154.     
  155.     add.w    #48,d7        convert to chars
  156.     add.w    #48,d6
  157.     add.w    #48,d5
  158.     move.w    d7,d0        print to screen
  159.     jsr    prnt_char
  160.     move.w    d5,d0
  161.     jsr    prnt_char
  162.     move.w    d6,d0
  163.     jsr    prnt_char
  164.     
  165.     movem.l    (a7)+,d5-d7
  166.     rts
  167.  
  168. * routine to print a null terminated string to screen
  169. * a0 = address of string
  170.  
  171. prnt_strn    movem.l    d0-d4/a0-a4,-(a7)
  172.  
  173.     move.l    a0,-(a7)        address of string
  174.     move.w    #9,-(a7)        print string
  175.     trap    #1
  176.     addq    #6,a7    
  177.     
  178.     movem.l    (a7)+,d0-d4/a0-a4
  179.     rts
  180.  
  181. * routine to print a character to the screen
  182. * d0.w = character 
  183.     
  184. prnt_char    movem.l    d0-d4/a0-a4,-(a7)
  185.  
  186.     move.w    d0,-(a7)        character
  187.     move.w    #2,-(a7)        print character
  188.     trap    #1
  189.     addq    #4,a7
  190.     
  191.     movem.l    (a7)+,d0-d4/a0-a4
  192.     rts
  193.  
  194. * routine to get key press
  195. * returns value in d0.w, 0 = no key
  196.  
  197. get_key    movem.l    d1-d4/a0-a4,-(a7)
  198.  
  199.     move.w    #255,-(a7)    read character
  200.     move.w    #6,-(a7)        c_rawio
  201.     trap    #1
  202.     addq    #4,a7
  203.     
  204.     movem.l    (a7)+,d1-d4/a0-a4
  205.     rts
  206.  
  207. * Return to user mode and exit
  208.  
  209. fin    lea    stk,a6        get value of original stack
  210.     move.l    (a6),-(a7)
  211.     move.w    #32,-(a7)
  212.     trap    #1        Return to user mode
  213.     addq    #6,a7
  214.     
  215.  
  216.     move.w    #0,-(a7)
  217.     trap    #1
  218.     addq    #2,a7
  219.  
  220.  
  221.     section    BSS
  222.  
  223. stk    ds.l    1
  224.  
  225.  
  226.     section    DATA
  227.     
  228. * The following is all one string, including carriage returns
  229. * etc, which can be printed in one go
  230.  
  231. screen    dc.b    27,'E',27,'f',' STE Controller Port Display Program',13,10
  232.     dc.b    ' Copyright ',189,'1991 A Greenwood',13,10,13,10
  233.     dc.b    ' .---------------------------------------.',13,10
  234.     dc.b    ' |                      3120             |',13,10
  235.     dc.b    ' | $ff9200 Fire Buttons                  |',13,10
  236.     dc.b    ' |                                       |',13,10
  237.     dc.b    ' |---------------------------------------|',13,10
  238.     dc.b    ' |                   UDLR UDLR UDLR UDLR |',13,10
  239.     dc.b    ' | $ff9202 Direction                     |',13,10
  240.     dc.b    ' |                   Joy3 Joy2 Joy1 Joy0 |',13,10
  241.     dc.b    ' |---------------------------------------|',13,10
  242.     dc.b    ' | $ff9210 Paddle 0 x                    |',13,10
  243.     dc.b    ' | $ff9212 Paddle 0 y                    |',13,10
  244.     dc.b    ' |---------------------------------------|',13,10
  245.     dc.b    ' | $ff9214 Paddle 1 x                    |',13,10
  246.     dc.b    ' | $ff9216 Paddle 1 y                    |',13,10
  247.     dc.b    ' |---------------------------------------|',13,10
  248.     dc.b    ' | $ff9220 Light Pen x                   |',13,10
  249.     dc.b    ' | $ff9222 Light Pen y                   |',13,10
  250.     dc.b    ' ',39,'---------------------------------------',39,13,10,0
  251.  
  252. * The following are the escape code sequences to set 
  253. * the cursor to the correct screen position to print
  254. * the contents of the various registers
  255. * The characters and numbers after the Y are coordinates, 
  256. * but in the form that the VT52 recognises.
  257. * To work out which character to use take coord and add
  258. * 32. This gives ASCII value of character. eg for 3
  259. * use character 35, ie #
  260.  
  261. set_fire    dc.b    27,'Y%8',0    
  262. set_d3    dc.b    27,'Y)5',0    
  263. set_0x    dc.b    27,'Y,6',0
  264. set_0y    dc.b    27,'Y-6',0
  265. set_1x    dc.b    27,'Y/6',0
  266. set_1y    dc.b    27,'Y06',0
  267. set_Lx    dc.b    27,'Y27',0
  268. set_Ly    dc.b    27,'Y37',0
  269.  
  270. * Escape code sequences for reverse and normal video
  271.  
  272. reverse    dc.b    27,'p',0
  273. normal    dc.b    27,'q',0
  274.     
  275.     end