Guest User

TilEm debugger guide (Qwen)

a guest
Aug 18th, 2026
74
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.04 KB | None | 0 0
  1. TilEm Debugger Guide
  2. ### USER
  3. How do I use TilEm's debugger? Official documentation: http://lpg.ticalc.org/prj_tilem/doc/user_manual.pdf
  4. Assume that I have a decent knowledge of how a Ti-83(+) works, like the stack, registers, flags, etc.
  5.  
  6. ### ASSISTANT
  7. Given your background in TI-83+ assembly and Z80 architecture, you can skip the basics of what registers and the stack are and focus on how TilEm (specifically TilEm2) exposes and manipulates these internal states.
  8.  
  9. Based on the official user manual, here is a comprehensive guide to utilizing the debugger features.
  10.  
  11. ### 1. Entering and Exiting the Debugger
  12. * **Pause:** To open the debugger, you must pause the emulator. You can do this by pressing **`ESC`**, clicking the **Pause** button on the toolbar, or selecting **Pause** from the right-click context menu.
  13. * **Run/Resume:** Press **`F5`** to resume execution and deactivate the debugger interface.
  14.  
  15. ### 2. Debugger Interface & Views
  16. The debugger window is divided into several synchronized widgets:
  17.  
  18. #### Disassembly View
  19. * **Function:** Displays Z80 mnemonics and tracks the Program Counter (PC).
  20. * **Navigation:**
  21. * **`Ctrl+L` (Go to Address):** Jump to a specific memory address.
  22. * **`Alt+Home`:** Jump directly to the current PC.
  23. * **`Alt+PageUp` / `Alt+PageDown`:** This is a unique navigation feature. It allows you to step through the **stack** entries. When you select a stack entry, pressing these shortcuts will jump the Disassembly View to the specific instruction that pushed or modified that stack value.
  24. * **Quick Breakpoints:** You can right-click any instruction in this view and select **"Breakpoint Here"** to toggle a breakpoint instantly.
  25.  
  26. #### Register View
  27. * **Function:** Displays all standard Z80 registers (A, B, C, D, E, H, L) and their shadow counterparts (AF', BC', DE', HL').
  28. * **Special Registers:** It explicitly shows `IX`, `IY`, `SP`, `PC`, Interrupt Mode (`IM`), Interrupt Vector (`I`), and the Interrupt Enable flag (`EI`).
  29. * **Flags:** The F register is broken down into individual flags: **S Z Y H X P N C**.
  30. * **Editing:** You can edit register values on the fly by clicking on them and typing a new hexadecimal value.
  31.  
  32. #### Stack View
  33. * **Function:** visualizes the stack as a list of `Address: Value` pairs (growing downwards from `FFFF`).
  34. * **Usage:** Select an entry in this view and use the "Go" menu (or `Alt+PageUp`/`Alt+PageDown`) to find the source code that manipulated that stack position.
  35.  
  36. #### Memory View
  37. * **Function:** A standard hexadecimal dump of the calculator's memory map.
  38. * **Editing:** You can click and edit bytes in RAM. Attempts to edit ROM pages will generally be ignored or rejected.
  39.  
  40. ### 3. Execution Control (Stepping)
  41. The toolbar provides standard debugging controls:
  42. * **Step:** Executes a single Z80 instruction (equivalent to F11 in many IDEs).
  43. * **Step Over:** Executes the next instruction but runs through subroutines (like `CALL`) entirely, stopping at the instruction immediately following the call.
  44. * **Finish Subroutine:** Runs execution until the current subroutine returns (exiting the current `CALL` or `RST` frame).
  45.  
  46. ### 4. Breakpoints (`Ctrl+B`)
  47. Access the advanced Breakpoint dialog via **Debug > Breakpoints** or by pressing **`Ctrl+B`**. TilEm supports several breakpoint types that are highly specific to Z80 development:
  48.  
  49. * **Memory Address:** Break when the PC reaches a specific address. You can configure this to break on **Reading**, **Writing**, or **Executing**. You can also specify a **Range** of addresses (useful for catching out-of-bounds variable access).
  50. * **Z80 Instruction:** Break on a specific opcode in hex.
  51. * *Example:* Entering `C9` will pause execution every time a `RET` instruction is encountered.
  52. * **I/O Port:** Break when the Z80 interacts with specific hardware ports.
  53. * *Example:* Set to **Read** on Port `01` to catch direct keyboard scanning operations.
  54. * **Global/Edge Cases:**
  55. * **Break on invalid instructions:** Useful for catching corrupted PC pointers.
  56. * **Break on undocumented instructions:** Useful if you are relying on specific Z80 quirks or want to avoid them.
  57.  
  58. ### 5. Workflow Integration (Assembler Labels)
  59. Since TilEm deals in raw hex addresses, debugging is difficult if you don't know where your labels reside in memory.
  60. * **The Solution:** Configure your assembler (e.g., SPASM) to generate a listing file (`.lst`) using the `-T` flag (or equivalent).
  61. * **Usage:** This file maps your assembly labels (like `DrawGbuf` or `MainLoop`) to the exact hex addresses that TilEm displays, allowing you to set breakpoints precisely (e.g., setting a breakpoint at `9E4F` knowing it corresponds to `DrawGbuf`).
  62.  
  63. ### 6. Additional Hardware Tools
  64. * **Keypad Matrix (`View > Keypad`):** Opens a widget that visualizes the hardware key matrix. It shows exactly which Z80 port bit and group corresponds to each physical key on the calculator, which is essential for debugging custom input routines.
  65. * **Address Notation:** You can toggle between logical and absolute addressing in the debugger settings to match your project's memory paging configuration.
  66.  
  67. ### USER
  68. Make an example of this program:
  69. .nolist
  70. #include "ti83plus.inc"
  71. .list
  72. .org userMem-2
  73. .db $BB,$6D
  74.  
  75. programStart:
  76. ;leading section copied verbatim from prior entry in the thread being responded to
  77. res 5,(iy+0) ;No "Done"
  78. res 0,(iy+$12) ;No run indicator
  79. res 5,(iy+$44) ;MathPrint is turned off
  80. bcall(_ClrLCDFull)
  81. call setRandSeed
  82. ;ld hl,$0001
  83. ;ld (appbackupscreen),hl
  84. ld b,100
  85. _:
  86. call rand
  87. push bc
  88. bcall(_DispHL)
  89. bcall(_NewLine)
  90. pop bc
  91. djnz -_
  92. ret
  93.  
  94. setRandSeed:
  95. ld hl,(appbackupscreen)
  96. ld a,r
  97. ld e,a
  98. ld a,r ;probably not the best way to do this given limited spread of r across so short a span.
  99. ld d,a
  100. adc hl,de
  101. jr nz,$+3
  102. inc hl ;ensure hl is nonzero
  103. ld (appbackupscreen),hl
  104. ret
  105.  
  106. ;implements
  107. ; x ^= x << 7
  108. ; x ^= x >> 9
  109. ; x ^= x << 8
  110. ;
  111. rand:
  112. ld hl,(appbackupscreen)
  113. ;x ^ (x << 7)
  114. ;note: in the op, we lose most of H. H0 moves to H7 and L1:7 moves to H0:6
  115. ; H7 H6 H5 H4 H3 H2 H1 H0 | L7 L6 L5 L4 L3 L2 L1 L0
  116. ; H0 L7 L6 L5 L4 L3 L2 L1 | L0 -- -- -- -- -- -- --
  117. ld a,h
  118. rra ;move H0 to carry, discard accumulator.
  119. ld a,L ;move L0:7 to accumulator.
  120. rra ;move CA to A7, L1:7 to A0:6, discarding L0
  121. xor h
  122. ld h,a ;apply H
  123. ld a,L
  124. and %00000001 ;isolate A0
  125. rrca ;move to A7
  126. xor L ;this op clears carry, nothing else sets it
  127. ld L,a ;apply L
  128. ; x ^ (x >> 9)
  129. ;note: in this op, we lose all of L and the low bit of H for the temp shift
  130. ld a,h
  131. rra ;relies on carry being cleared, as is above.
  132. xor a,L
  133. ld L,a ;apply H to L
  134. ; x ^ (x << 8)
  135. ld a,L
  136. xor a,H
  137. ld H,a ;eh?
  138. ld (appbackupscreen),hl
  139. ret
  140. .end
  141. .end
  142.  
  143. ### ASSISTANT
  144. Here is a practical, step-by-step walkthrough of how you would debug this specific program using TilEm’s features.
  145.  
  146. ### Phase 1: Preparation and Breakpoints
  147. Because TilEm only displays raw hex addresses, you first need to know where your labels live in memory.
  148. 1. **Compile with a Listing File:** Assemble your code using a flag that generates a listing file (e.g., `spasm -T myprog.asm myprog.8xp`).
  149. 2. **Find your Addresses:** Open the `.lst` file to find the hex addresses for your labels. For this example, let's assume:
  150. * `programStart` = `$9D95`
  151. * `rand` = `$9DD3`
  152. * `appbackupscreen` = `$8452` (Standard TI-83+ RAM location)
  153.  
  154. **Setting the Trap:**
  155. 1. Run the program in TilEm. It will start printing numbers.
  156. 2. Press **`ESC`** to pause the emulator and open the Debugger.
  157. 3. In the **Disassembly View**, scroll up to your main loop until you find the `call rand` instruction.
  158. 4. Right-click that `call rand` instruction and select **"Breakpoint Here"**.
  159. 5. Press **`F5`** to resume. The emulator will run through the current iteration, finish the loop, and automatically pause right before entering the `rand` subroutine for the next number.
  160.  
  161. ### Phase 2: Verifying Bitwise Logic (Register & Flag View)
  162. Now that you are paused at `call rand`, you want to verify that your xorshift math is actually doing what you think it's doing.
  163.  
  164. 1. **Enter the Subroutine:** Click the **Step** button on the toolbar. The PC will move to the first instruction of `rand` (`ld hl,(appbackupscreen)`).
  165. 2. **Watch the Seed:** Look at the **Register View**. `H` and `L` should now contain the current seed value.
  166. 3. **Trace the Shifts:** Keep clicking **Step** to move through the `x ^= x << 7` block.
  167. * Watch the **A** register fill with bits.
  168. * Pay close attention to the **Flags** section at the bottom of the Register View. When you hit `rra` or `rrca`, watch the **C** (Carry) flag toggle.
  169. 4. **Verify Assumptions:** In your code comments, you noted: `note: in this op, we lose all of L... relies on carry being cleared`.
  170. * When you step down to the `x ^= x >> 9` block, look at the **C** flag *before* the first `rra`. If it is `1` instead of `0`, you have found a bug in your bitwise logic!
  171.  
  172. ### Phase 3: Stack Inspection and OS Calls
  173. Once you have verified the math inside `rand`, you want to get back to the main loop without stepping through hundreds of instructions.
  174.  
  175. 1. **Exit the Subroutine:** Click **Finish Subroutine** on the toolbar. TilEm will execute the rest of `rand` and pause exactly on the instruction *after* the `call rand` in your main loop.
  176. 2. **Step Over ROM Calls:** You are now at `push bc`. Click **Step Over**.
  177. * *Note: If you click "Step" on the `bcall(_DispHL)`, you will dive deep into the TI-OS ROM. Always use **Step Over** for `bcall` or `call` unless you specifically want to debug the OS.*
  178. 3. **Inspect the Stack:** Click **Step Over** on `bcall(_DispHL)` and `bcall(_NewLine)`.
  179. 4. **The Stack View Trick:**
  180. * Look at the **Stack View** widget. You should see the value of your `B` register (which was pushed earlier) sitting at the top of the stack.
  181. * Click on that stack entry with your mouse.
  182. * Press **`Alt+PageUp`**. The **Disassembly View** will instantly jump back to the exact `push bc` instruction that placed that value on the stack, allowing you to verify your loop logic at a glance.
  183. 5. Press **Step Over** on `pop bc` and verify in the **Register View** that `B` has been successfully restored before the `djnz` loop check.
  184.  
  185. ### Phase 4: Verifying Memory Persistence
  186. Finally, you want to ensure that `rand` is actually saving the new seed back to RAM so the sequence doesn't repeat.
  187.  
  188. 1. **Navigate to RAM:** In the **Memory View** widget, scroll down (or use the address jump feature if available in your specific version's UI) to `$8452` (`appbackupscreen`).
  189. 2. **Observe the Bytes:** Note the two bytes currently sitting at `$8452` and `$8453`.
  190. 3. **Run and Pause:** Press **`F5`** to let the calculator run for a second, then press **`ESC`** to pause it again.
  191. 4. **Verify:** Look at `$8452` in the Memory View. The hex values should have changed, confirming that your `ld (appbackupscreen),hl` instruction at the end of `rand` successfully persisted the new state for the next loop iteration.
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment