Added INT 3 breakpoint and INT 1 single-step support
authorRobert Pengelly <robertapengelly@hotmail.com>
Tue, 20 Oct 2026 22:06:40 +0000 (23:06 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Tue, 20 Oct 2026 22:06:40 +0000 (23:06 +0100)
cpu.c
interrupts.c

diff --git a/cpu.c b/cpu.c
index 992c4a0abf55f5cd48f0e1f572258c37e2db8e01..2f9df7813fb37bc81f888f44f68a1d1585132791 100644 (file)
--- a/cpu.c
+++ b/cpu.c
@@ -25,6 +25,7 @@
 #define     FLAG_AF     0x0010          /* Auxiliary Carry Flag (bit 4) */
 #define     FLAG_ZF     0x0040
 #define     FLAG_SF     0x0080
+#define     FLAG_TF     0x0100
 #define     FLAG_IF     0x0200
 #define     FLAG_DF     0x0400          /* Direction Flag (bit 10) */
 #define     FLAG_OF     0x0800          /* Overflow Flag (bit 11) */
@@ -1235,6 +1236,9 @@ static void dump_guest_bytes (CPU8086 *cpu, uint16_t seg, uint16_t off, uint16_t
 
 int cpu_step (CPU8086 *cpu) {
 
+    int trap_inhibit = 0;
+    int trap_pending;
+    
     uint8_t op;
     int old_ip;
     
@@ -1242,6 +1246,8 @@ int cpu_step (CPU8086 *cpu) {
         return 0;
     }
     
+    trap_pending = (cpu->flags & FLAG_TF) != 0;
+    
     cpu->seg_override = 0;
     cpu->has_seg_override = 0;
     
@@ -1563,6 +1569,8 @@ fetch_instruction:
         case 0x17:             /* POP SS */
         
             cpu->ss = pop16 (cpu);
+            
+            trap_inhibit = 1;
             break;
         
         case 0x1E:             /* PUSH DS */
@@ -2452,6 +2460,8 @@ fetch_instruction:
                 case 2:
                 
                     cpu->ss = value;
+                    
+                    trap_inhibit = 1;
                     break;
                 
                 case 3:
@@ -2566,8 +2576,8 @@ fetch_instruction:
         case 0x9D: {           /* POPF */
         
             uint16_t f = pop16 (cpu);
-            cpu->flags = f & (FLAG_CF | FLAG_PF | FLAG_AF | FLAG_ZF | FLAG_SF | FLAG_IF | FLAG_DF | FLAG_OF);
             
+            cpu->flags = (f & (FLAG_CF | FLAG_PF | FLAG_AF | FLAG_ZF | FLAG_SF | FLAG_TF | FLAG_IF | FLAG_DF | FLAG_OF)) | 0x0002;
             break;
         
         }
@@ -4957,6 +4967,10 @@ fetch_instruction:
     
     }
     
+    if (trap_pending && !trap_inhibit && (cpu->flags & FLAG_TF) && !cpu->halted) {
+        handle_interrupt (cpu, 1);
+    }
+    
     return 1;
 
 }
index 1d0a89c3a105c8ddf9ee8130fe25f9ddd78dd320..c9d7943b0af5aa7026f977c7e78293ad65c7d9bf 100644 (file)
@@ -4133,8 +4133,8 @@ static void int_0 (CPU8086 *cpu) {
 
 static void int_1 (CPU8086 *cpu) {
 
-    printf ("Interrupt 1: Single Step Exception\n");
-    cpu->halted = 1;
+    /* With no guest debugger installed, the BIOS default handler returns. */
+    (void) cpu;
 
 }
 
@@ -4147,10 +4147,8 @@ static void int_2 (CPU8086 *cpu) {
 
 static void int_3 (CPU8086 *cpu) {
 
-    printf ("\n*** BREAKPOINT (INT 3) at %04X:%04X ***\n", cpu->cs, cpu->ip);
-    
-    cpu_dump (cpu);                     /* Show registers to see what triggered it */
-    /* cpu->halted = 1; Uncomment if you want the emulator to stop here */
+    /* Guest breakpoints are dispatched through vector 3. */
+    (void) cpu;
 
 }