diff --git a/src/libsrc/sane.pla b/src/libsrc/sane.pla index d302af1..0811e89 100644 --- a/src/libsrc/sane.pla +++ b/src/libsrc/sane.pla @@ -22,10 +22,6 @@ export word[7] sane = @fpInit, @fpDefaultHalt, @uninit0, @uninit1, @uninit2, @un // word fp6502 // -// Pointer to Halt handler -// -word hhaddr -// // PLASMA <-> SANE interface routines // asm equates @@ -56,6 +52,7 @@ asm xfpHalt LDX #$F7 end asm fpHalt + STA $C008 TXA LDX ESP STA ESTKL,X @@ -424,7 +421,9 @@ end // Default HALT handler // def fpDefaultHalt(pstatus) + sane[8]() // zpRestore puts("SANE Exception="); puti(pstatus->8); puts("!\n") + sane[7]() // zpSave return pstatus=>4 end // @@ -626,9 +625,7 @@ def fpInit() // // Install AUX HALT handler // - hhaddr = @xfpHalt - (@fixupHLT)=>1 = @sane+2 - xfpOp1($0005, @hhaddr) + xfpOp1($0005, @xfpHalt) else // // Fixup MAIN calls in interface routines @@ -647,14 +644,17 @@ def fpInit() // // Install MAIN HALT handler // - hhaddr = @fpHalt - (@fixupHLT)=>1 = @sane+2 - fpOp1($0005, @hhaddr) + fpOp1($0005, @fpHalt) fin sane[5] = @elemsLoad1 sane[6] = @elemsLoad2 fin - sane[1] = @fpDefaultHalt + (@fixupHLT)=>1 = @sane+2 + sane[1] = @fpDefaultHalt + // + // Reset environment word + // + sane[3]($0001, $0000) end // // Uninitialized placeholders of API diff --git a/src/samplesrc/sanity.pla b/src/samplesrc/sanity.pla index 67742c0..2048e0f 100644 --- a/src/samplesrc/sanity.pla +++ b/src/samplesrc/sanity.pla @@ -10,6 +10,7 @@ word iA, iB, iC, zero, fpEnv byte xT[t_extended] def myException(pstatus) + sane:zpRestore() puts("Floating point exception:") if pstatus->8 & FBINVALID; puts(" INVALID"); fin if pstatus->8 & FBUFLOW; puts(" UNDERFLOW"); fin @@ -17,6 +18,7 @@ def myException(pstatus) if pstatus->8 & FBDIVZER; puts(" DIV_BY_ZERO"); fin if pstatus->8 & FBINEXACT; puts(" INEXACT"); fin putln + sane:zpSave() return pstatus=>4 end @@ -51,8 +53,14 @@ sane:fpOp2(FFINT|FOX2Z, @iC, @xT) // Convert ext T to int C sane:zpRestore() puti(iA); putc('/'); puti(iB); putc('='); puti(iC); putc('\n') sane:zpSave() +// +// Hook custom HALT exception handler and divide by zero :-) +// sane:fpHalt = @myException fpEnv = sane:fpOp0(FOGETENV) +// +// Enable all exceptions +// sane:fpOp1(FOSETENV, fpEnv | FBINVALID | FBUFLOW | FBOFLOW | FBDIVZER | FBINEXACT) sane:fpOp2(FFINT|FOZ2X, @xT, @iA) // Convert int A to ext T sane:fpOp2(FFINT|FODIV, @xT, @zero) // Div ZERO into ext T