Announcement

Collapse
No announcement yet.

Interrupt handler in PB/DOS?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Interrupt handler in PB/DOS?

    Is it possible to use a PowerBASIC SUB as an interrupt handler? That is, is it legal to mix PowerBASIC and assembly _within_ the interrupt-handling section of a PowerBASIC program?

    I have an old program, half 80286 ASM and half Micro$oft FORTRAN, that I very much want to scrap and replace with something more modern. (The original code isn't mine, BTW; this is something that was developed "three engineers ago" ) The main program is in FORTRAN, with some assembly-language subroutines linked to it. Right now, the assembly library contains a routine like this:


    MOV DS, segment pgroup:IHANDL ;DS = segment of new INT 0Ah handler
    MOV AH, 25h ;select service 25h for INT 21h call
    MOV AL, 0Ah ;interrupt 0Ah to be re-vectored
    MOV DX, offset pgroup:IHANDL ;DX = offset of new INT 0Ah handler
    INT 21h ;Invoke DOS service 21/25h
    ;(Set Interrupt Vector)

    which is used to set the interrupt vector table for the appropriate IRQ to point to the interrupt handler. The handler is also an assembly procedure which context-saves the CPU and FPU registers, then CALL's a FORTRAN procedure called IRQ9HAND. When the FORTRAN procedure RETURNs, it goes back to IHANDL, which context-restores the saved CPU and FPU registers and then exits back to the main FORTRAN program, as follows:

    IHANDL PUSH CX ;preserve CX,
    PUSH DX ; DX,
    PUSH SI ; SI,
    PUSH DI ; DI,
    PUSH BP ; BP,
    PUSH ES ; and ES registers
    MOV ES, CS:d_seg ;point ES to our Data segment
    SUB SP, 5Eh ;create 94 storage words for FPU state
    MOV BP, SP ;BP = StackPointer
    FSAVE [BP] ;store FPU's state & re-initialize it
    FWAIT ;wait until FPU completes the save
    STI ;re-enable hardware interrupts

    CALL IRQ9HAND ;invoke the FORTRAN IRQ9HAND procedure

    MOV BP, SP ;BP = StackPointer
    FRSTOR [BP] ;restore the FPU's previous state
    ADD SP, 5Eh ;discard the 94 words of FPU-state storage
    POP ES ;restore ES,
    POP BP ; BP,
    POP DI ; DI,
    POP SI ; SI,
    POP DX ; DX,
    POP CX ; and CX registers
    CLI ;disable hardware interrupts
    IRET ;return from interrupt svc. routine

    Can I pull this same stunt with PowerBASIC, or will the runtime module (if any) crash and burn?

  • #2
    yes, you may intermix some types of pb code with asm in the isr routine... search the source code forum for "isr" and you should find some working example code to get you going.

    footnote: please review http://www.powerbasic.com/support/pb...read.php?t=401 in conjunction with this thread.

    ------------------
    lance
    powerbasic support
    mailto:[email protected][email protected]</a>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Excellent That was pretty much the last thing holding me back to committing to PowerBASIC for this project; with that question settled, I'll be placing my order for a copy of PB 3.5 shortly. Thanks for the quick response!

      ------------------

      Comment

      Working...
      X