: Here I converted to C but it crashes:
:
:
: #include "p2c.h"
: #include "extra.h"
:
: #define TIMER_G
: #include "timer.h"
:
:
:
: #define MaxRate 1193180L
:
:
: void interrupt(__far *OldInt08)();//Static _PROCEDURE OldInt08, OldInt1C;
: void interrupt(__far *OldInt1C)();
: Static unsigned short IntCount08, Trigger;
: Static boolean TimerAlreadySet;
: Static unsigned short Frequency;
:
:
: Static Void IrqOn()
: {
: /* p2c: timer1.pas, line 37:
: * Note: Inline assembly language encountered [254] */
: asm{sti;}//asm(" inline $FB");
: }
:
:
: Static Void IrqOff()
: {
: /* p2c: timer1.pas, line 40:
: * Note: Inline assembly language encountered [254] */
: asm{sti;}//asm(" inline $FA");
: }
: /* p2c: timer1.pas, line 43: Note: Ignoring INTERRUPT keyword [258] */
:
:
: /*$F+*/
: void interrupt NewInt1C()//Static Void NewInt1C()
: {
: ClockTicks++;
: }
: /* p2c: timer1.pas, line 50: Note: Ignoring INTERRUPT keyword [258] */
:
:
: /*$F-*/
:
: /*$F+*/
: void interrupt NewInt08()//Static Void NewInt08()
: {
: IrqOff();
: /* p2c: timer1.pas, line 53:
: * Note: Inline assembly language encountered [254] */
: asm{int 1Ch;}//asm(" inline $CD");
: //asm(" inline $1C"); /*Generate INT 1Ch instruction to call interrupt 1Ch*/
: if (IntCount08 == Trigger) {
: IntCount08 = 0;
: /* p2c: timer1.pas, line 57:
: * Note: Inline assembly language encountered [254] */
: asm{pushf;}//asm(" inline $9C");
: /*if (OldInt08.link != NULL)
: (*(Void(*) PP((Anyptr _link)))OldInt08.proc)(OldInt08.link);
: else
: (*(Void(*) PV())OldInt08.proc)();*/
: } else
: IntCount08++;
: outp( 0x20, 0x20 );//PORT(0x20) = 0x20; /*Sends non-specific EOI to the PIC*/
: /* p2c: timer1.pas, line 64: Note: Reference to PORT [191] */
: /* p2c: timer1.pas, line 64: Warning: Invalid assignment [168] */
: IrqOn();
: }
:
:
: /*$F-*/
:
: Void TimerOn(Freq)
: long Freq;
: {
: LONGINT Temp = MaxRate;
: unsigned short Count;
: _PROCEDURE TEMP1;
:
: if (TimerAlreadySet)
: return;
: ClockTicks = 0;
: IntCount08 = 0;
: Frequency = Freq;
: Trigger = (long)(Freq / 18.2);
: Temp = (long)((double)Temp / Freq);
: Count = Temp;
: GetIntVec(0x8, OldInt08);
: TEMP1.proc = (Anyptr)NewInt08;
: TEMP1.link = (Anyptr)NULL;
: /* p2c: timer1.pas, line 83:
: * Warning: Symbol 'GETINTVEC' is not defined [221] */
: SetIntVec(0x8, NewInt08);//SetIntVec(0x8, TEMP1);
: /* p2c: timer1.pas, line 84:
: * Warning: Symbol 'SETINTVEC' is not defined [221] */
: GetIntVec(0x1c, OldInt1C);
: TEMP1.proc = (Anyptr)NewInt1C;
: TEMP1.link = (Anyptr)NULL;
: /* p2c: timer1.pas, line 85:
: * Warning: Symbol 'GETINTVEC' is not defined [221] */
: SetIntVec(0x1c, NewInt1C);//SetIntVec(0x1c, TEMP1);
: /* p2c: timer1.pas, line 86:
: * Warning: Symbol 'SETINTVEC' is not defined [221] */
: outp( 0x43, 0xb6);
: /* p2c: timer1.pas, line 87: Note: Reference to PORT [191] */
: /* p2c: timer1.pas, line 87: Warning: Invalid assignment [168] */
: outp( 0x40, Count & 255);
: /* p2c: timer1.pas, line 88: Note: Reference to PORT [191] */
: /* p2c: timer1.pas, line 88: Warning: Invalid assignment [168] */
: outp( 0x40, Count >> 8);
: /* p2c: timer1.pas, line 89: Note: Reference to PORT [191] */
: /* p2c: timer1.pas, line 89: Warning: Invalid assignment [168] */
: TimerAlreadySet = true;
: }
:
:
: Void TimerOff()
: {
: if (!TimerAlreadySet)
: return;
: outp( 0x43, 0xb6);
: /* p2c: timer1.pas, line 98: Note: Reference to PORT [191] */
: /* p2c: timer1.pas, line 98: Warning: Invalid assignment [168] */
: outp( 0x40, 0xff);
: /* p2c: timer1.pas, line 99: Note: Reference to PORT [191] */
: /* p2c: timer1.pas, line 99: Warning: Invalid assignment [168] */
: outp( 0x40, 0xff);
: /* p2c: timer1.pas, line 100: Note: Reference to PORT [191] */
: /* p2c: timer1.pas, line 100: Warning: Invalid assignment [168] */
: SetIntVec(0x8, OldInt08);
: /* p2c: timer1.pas, line 101:
: * Warning: Symbol 'SETINTVEC' is not defined [221] */
: SetIntVec(0x1c, OldInt1C);
: /* p2c: timer1.pas, line 102:
: * Warning: Symbol 'SETINTVEC' is not defined [221] */
: TimerAlreadySet = false;
: }
:
:
: Void ResetTimer()
: {
: ClockTicks = 0;
: }
:
:
: double TimeElapsed()
: {
: return ((double)ClockTicks / Frequency);
: }
:
:
: void _Timer_init()
: {
: static int _was_initialized = 0;
: if (_was_initialized++)
: return;
: TimerAlreadySet = false;
: }
: /* p2c: Note: Remember to call _Timer_init() in main program [215] */
:
:
:
: /* End. */
:
: void main()
: {
: _Timer_init();
: }
:
: :
:
It is not possible to change a procedure in a method, and then use it as a callback function. Callback functions always have very specific signatures, and any deviation from that will cause the code to fail.
SetIntVec($08,Addr(NewInt08));
is not the same as
SetIntVec(0x8, NewInt08);
since the first gives the pointer to the entry point of NewInt08() to the IntVec, while the latter gives the entry point itself (or perhaps the result of) NewInt08() to the IntVec.
Also where is the call to the OldInt08()?