Free Pascal - kompilacja modułu

0

Jak skompilować moduł we Free Pascalu ? W Turbo Pascalu po wciśnięciu Compile wychodzi mi ładny plik z rozszerzeniem .TPU który wrzucam do unitów i mogę z niego korzystać a w FPC wywala mi błędy przy kompilacji. Tym bardziej, że tutaj jak byk pisze, że robi się to podobnie jak w TP: http://www.as.up.krakow.pl/~greg/SOFTWARE/fpc-1.0.4/faq.htm#HowcanIbuildaunit

Kod Unitu wygląda tak:

{$g+}
unit keyboard;
interface

VAR   key             : array[1..127] of boolean; { to store the key-presses }
      AnyPressed      : Boolean;
      KeyDelay        : Word;

Const KeyName : array[1..83] of string[10] = (
           'Esc','1','2','3','4','5','6','7','8','9','0','_','=','BckSpace',
           'Tab','Q','W','E','R','T','Y','U','I','O','P','[',']','Return',
           'Ctrl','A','S','D','F','','H','J','K','L',';','"','`','Left Shift',
           '\','Z','X','C','V','B','N','M',',','.','/','Right Shift','*',
           'AlT','Space','Caps Lock','F1','F2','F3','F4','F5','F6','F7','F8',
           'F9','F10','Num Lock','Scroll Lock','Home','Up','Pg Up','-','Left',
           '5','Right','+','End','Down','Pg Down','Ins','Del');

       EscKey   = 1;      { these are just some constants... }
       Down     = 80;     { the most important keys in games }
       Up       = 72;     { are the arrow keys, and the }
       Left     = 75;     { control+alt keys... }
       Right    = 77;
       CTRL     = 29;
       ALT      = 56;
       RETURN   = 28;

       INSERT    = 82;
       HOME      = 71;
       PAGE_UP   = 73;
       DELETE    = 83;
       END_      = 79;
       PAGE_DOWN = 81;

PROCEDURE InitInt09;
PROCEDURE RestoreInt09 ;
Function KeyRetrace:Boolean;

implementation
uses dos;

VAR OldInt09        : pointer;        { old keyboard interupt             }

Const KeyWait:Integer=0;

PROCEDURE RestoreInt09 ;
BEGIN
  SetIntVec( $09, OldInt09 ) ;
END;

{$f+}
PROCEDURE NewInt09; INTERRUPT;
Begin
ASM
  STI

  xor ch,ch             { set CH to 0, we're using bytes here! }

  mov dx,$60            { set DX to port $60 (keyboard port) }
  in al,dx              { get byte from keyboard }
  mov cl,al             { put it in CL for usage }
  and cl,$7f            { and CL with 127 (MOD 128) }

  mov bx,offset key     { get offset of the KEY array of booleans }
  dec bx
  add bx,cx             { add keyfound to BX }
  mov si,bx             { put calculated offset in DS:[SI] }

  shr al,7              { divide AL with 128 }
  xor al,1
  mov [si],al           { put TRUE or FALSE in array position of keyfound }
  mov anypressed,al     { set ANYPRESSED to TRUE or FALSE }
  mov dx,$61
  in al,dx              { get byte from the port }
  mov cl,al
  or al,$80
  out dx,al
  mov al,cl
  out dx,al
  cli

  mov ax,$20
  mov dx,$20
  out dx,ax
END;
End;
{$f-}

PROCEDURE InitInt09;
VAR n : byte;
BEGIN
  AnyPressed:=False;
  ExitProc := addr( RestoreInt09 ) ;
  GetIntVec( $09, OldInt09 ) ;
  SetIntVec( $09, addr( NewInt09 ) ) ;
  For N := 1 to 127 do Key[ N ] := False ;
END;

Function KeyRetrace:Boolean;
begin
 KeyRetrace:=False;
 if keywait>0 then begin dec(keydelay);exit; End;
 keywait:=KeyDelay;
 KeyRetrace:=True;
end;

begin
 KeyDelay:=1;FillChar(key,sizeof(key),0);
END.

uses keyboard;
var i: integer;
begin
 InitInt09;
 repeat
 until anypressed;
 for i:=1 to 127 do if key[i]=true then writeln(i);
 Restoreint09;
end.
0

Illegal unit name: keyboard

A jeżeli się zapiszę pod tą nazwą, to jest cała lista błędów asm.
Poczytaj i popraw.

PS: Pewnie dlatego, że fpc nie do końca (to tylko spekulacje) obsługuje asm'a (mogę się mylić, więc...)

0

Ja w błędach nie widzę nic takiego jak Illegal unit name: keyboard. Mam 46 błędów typu Error: Unknown identifier i parę innych. Dopiero po zmianie nazwy na np. klawiatura pokazuje się Illegal unit name: klawiatura, co mi oczywiście nic nie daje.

0

Free Pascal kompiluje do 32-bitowego trybu chronionego, a w twoim kodzie jest 16-bitowy asembler i DOS-owe przerwania. Bez poważnego przerobienia kodu (a właściwie napisania od nowa) się nie obejdzie. Na początek, trzeba dodać {$ASMMODE INTEL}, ale samo to na pewno nie wystarczy.

Free Pascal ma wbudowany unit keyboard, który może nie robi tego samego, ale z pewnością jest funkcjonalnie w stanie zastąpić powyższy.

0
{$ASMMODE att}
{$MODE FPC}
{$ASMMODE INTEL}
uses
	go32;

const
	kbdint = $9;

var
	oldint9_handler : tseginfo;
	newint9_handler : tseginfo;

	       backupDS : Word; external name '___v2prt0_ds_alias';

                    key : array [1..127] of boolean;
             AnyPressed : boolean;

procedure int9_handler; assembler;
asm
	cli
	push ds
	push es
	push fs
	push gs
	pushad
	mov ax, cs:[backupDS]
	mov ds, ax
	mov es, ax
	mov ax, dosmemselector
	mov fs, ax

      //sti
        xor ecx, ecx
        mov  dx, $60
         in  al, dx
        mov  cl, al
        and  cl, $7f
        mov ebx, offset key
        dec ebx
        add ebx, ecx
        mov esi, ebx
        shr  al, 7
        xor  al, 1
        mov [esi], al
        mov anypressed, al
        mov  dx, $61
         in  al, dx
        mov  cl, al
         or  al, $80
        out  dx, al
        mov  al, cl
        out  dx, al
          //cli
        mov  ax, $20
        mov  dx, $20
        out  dx, ax
        popad
	pop gs
	pop fs
	pop es
	pop ds
	sti
        iret
end;
procedure int9_dummy; begin end;

procedure install_click;
begin
	lock_data(dosmemselector, sizeof(dosmemselector));
        lock_code(@int9_handler,
        longint(@int9_dummy)-longint(@int9_handler));

	newint9_handler.offset := @int9_handler;
	newint9_handler.segment := get_cs;
	get_pm_interrupt(kbdint, oldint9_handler);
	set_pm_interrupt(kbdint, newint9_handler);
end;

procedure remove_click;
begin
        set_pm_interrupt(kbdint, oldint9_handler);
	unlock_data(dosmemselector, sizeof(dosmemselector));
	unlock_code(@int9_handler,
		longint(@int9_dummy)-longint(@int9_handler));
end;

begin
	install_click;

	while key[1]=false do begin
          write (anypressed);
	end;
	remove_click;
end.

Masz tu gotowca :)

Może jeszcze modulik na VESE (oczywiście z linear frame buffer) ;)
Jakby coć to napisz do mnie na [email protected]

1 użytkowników online, w tym zalogowanych: 0, gości: 1