gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > LPT Port programming help needed

#32243 - ghostils - Mon Dec 20, 2004 12:35 am

I figure most of you folks out there are probably familiar with the Xboo program and xcomms. I'm using my GBA for a remote control (Well thats the idea if I can get some communication working with it and my pc)

What I want to do is control the gba via the xboo cable after my software is loaded either from rom or multi-boot does really matter. I've written a simple test program on the gba to repeatedly send 1 byte of data over the port in polling mode.

I wrote another simple program in C to read the LPT1 port. On the data register 0x378+0 I don't get data, which isn't strange after reading the xboo documentation text file showing what pins are used. (mosly control register pins 0x378 + 2)

I read the status register 0x378+1 and I show that the gba is sending data because when I unplug it the byte value changes.

Now here is where I need the help.

When I try and do any operation on the Control register read/write whatever my code either throws an exception or something else causes it to crash. I'm compiling it in Visual C++ 6.0.

Both data and status register operations work fine, control register access crashes it..

I'll post my code below for the windows app.
(OS Specs: Windows XP SP2)
(Programming IDE MSVC 6.0) compiled as a win32 console app. (which is probably part of the problem)

I may try and work it out in some 16bit asm but that's really rusty hehe.


Code:


#include <stdio.h>




//-old dos.h causes compile errors:
//-ASM routines:
//-Taken from Userport example file for test purposes:
void outportb(unsigned int portid, unsigned char value)
{
  __asm mov edx,portid
  __asm mov al,value
  __asm out dx,al
}


unsigned char inportb(unsigned int portid)
{
  unsigned char value;
 
  __asm mov edx,portid
  __asm in al,dx
  __asm mov value,al
  return value;
}


//-LPT registers for SPP mode:
#define PORTADDR 0x378
#define DATA PORTADDR + 0
#define STATUS PORTADDR + 1
#define CONTROL PORTADDR + 2



void main(void)
{
   unsigned char c = 0x00;               
   while(1)
   {
      inportb(DATA);
      printf("DATA = %c\r\n", c);

      inportb(STATUS);
      printf("STATUS = %c\r\n", c);


      //-FIXME: Crashes program!
      inportb(CONTROL);
      printf("CONTROL = %c\r\n", c);
   }

}







What do you all think?

Thanks,
-ghost[iLs]

#32390 - pan69 - Wed Dec 22, 2004 8:07 am

You can't do this kind of stuff on Windows 'cause Windows runs in protected mode. You should compile your program for DOS where this kind of behaviour is perfectly exceptable. If you still want to read/write IO ports under Windows you will have write a device driver.

You can get a good, the best actually, DOS compiler overhere: www.openwatcom.org

- Pan

#32412 - Lord Graga - Wed Dec 22, 2004 1:44 pm

Or, you could get a program to "open" the ports. By this, I mean programs like GiveIO, UserPort, and some other ones which ain't quite as popular.

#32426 - ghostils - Wed Dec 22, 2004 7:44 pm

I know these are needed in Windows XP, I have Userport running. Its something about how windows works with 16bit code. I can write the same software under linux using ioperm() and its works fine. So I just decided to do that.

-ghost[iLs]