delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/12/08:27:27

Xref: news2.mv.net comp.os.msdos.djgpp:8541
Newsgroups: comp.os.msdos.djgpp
From: Nick Collier <ntcollie AT midway DOT uchicago DOT edu>
Subject: Inline ASM Problem
Message-ID: <32378E9E.499F@midway.uchicago.edu>
Sender: news AT midway DOT uchicago DOT edu (News Administrator)
Organization: University of Chicago -- Academic Computing Services
Mime-Version: 1.0
Date: Thu, 12 Sep 1996 04:16:30 GMT
Lines: 107
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I re-wrote my joystick reading routine in extended inline ASM (more as
an exercise in learning extended inline asm than anything else) but it
doesn't seem able to read the x value at all now and only returns zero. 

The x value should be loaded into 4(%%edi) and the y value into
8(%%edi); the y returns the appropriate value, and the x value can be
read into the y, that is, when "adcl $0, 4(%%edi)\n" becomes adcl$0,
8(%%edi)\n, an x value is returned. I tried setting the value of
4(%%edi) manually with something like movl $5, 4(%%edi) but it still
returned zero. It is getting swallowed up or never getting loaded into
4(%%edi) at all. The four and eight refer to offsets from the beg. of
the joystick structure - js.

I'm not much of an asm expert (though I'd like to play one on tv) so the
mistake is no doubt something stupid (like not being able to use edi for
this sort of thing.)

Any help is of course appreciated. The source follows.

Nick


/* joystick routines - reading, calibrating etc. */

#include <stdio.h>
#include "joystick.h"

int jx_center, jy_center, jx_min, jy_min, jx_max, jy_max;

void Read_joy(joystick_state * js)
{

    asm (
        "movw $0x201, %%dx\n"               /* joystick port */
        "xorl %%eax, %%eax\n"                /* zero out eax */
        "outb %%al, %%dx\n"                  /* write to the port: start
timers */
        "movl %%eax, 4(%%edi)\n"
        "movl %%eax, 8(%%edi)\n"
        "movl $10000, %%ecx\n"              /* set the timer to a high
value */

     "jloop:\n"
        "inb %%dx, %%al\n"
        "movl %%eax, %%ebx\n"

        "shrl $1, %%ebx\n"
        "adcl $0, 4(%%edi)\n"                  
                                      
        "shrl $1, %%ebx\n"
        "adcl $0, 8(%%edi)\n"
        "loop jloop\n"

 "loop_end:\n"
        "notb %%al\n"
        "movl %%eax, %%edx\n"
        "andl $0x10, %%edx\n"             /* button_status & 0x10 */
        "movl %%edx, 1(%%edi)\n"           /* button_status & 0x20 */
        "andl $0x20, %%eax\n"
        "movl %%eax, 2(%%edi)"
        : : "D" (js) \
        : "%edi", "%eax", "%ebx", "%edx", "%ecx", "memory");
    
     
}

/* configure joystick */
void Config_joystick(joystick_state * js)
{
        /* clear the values */
    js->js_button_1 = js->js_button_2 = js->js_x = js->js_y = 0;

    printf("Joystick configuration.\n");
    printf("Center the joystick and press a button.\n");

    do {
        Read_joy(js);
    } while (!(js->js_button_1 || js->js_button_2));       /* absorbs
the bounce */

    jx_center = js->js_x;
    jy_center = js->js_y;

    do {
        Read_joy(js);
    } while (js->js_button_1 || js->js_button_2);
    
    
    printf("Push joystick to upper left corner and press a button.\n");
    do {
        Read_joy(js);
    } while (!(js->js_button_1 || js->js_button_2));
    jx_min = js->js_x;
    jy_min = js->js_y;

    do {
        Read_joy(js);
    } while (js->js_button_1 || js->js_button_2);

    printf("Push joystick to lower right corner and press a button.\n");
    do {
        Read_joy(js);
    } while (!(js->js_button_1 || js->js_button_2));
    jx_max = js->js_x;
    jy_max = js->js_y;
 
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019