"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
-<!-- 2025-07-29 ti 16:07 -->
+<!-- 2025-07-29 ti 17:15 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mouse driver for QBasic programs</title>
<body>
<div id="content" class="content">
<h1 class="title">Mouse driver for QBasic programs</h1>
+<div id="table-of-contents" role="doc-toc">
+<h2>Table of Contents</h2>
+<div id="text-table-of-contents" role="doc-toc">
+<ul>
+<li><a href="#org6da62e5">1. Overview</a>
+<ul>
+<li><a href="#orgf629f52">1.1. Terminate and Stay Resident module</a></li>
+<li><a href="#org75f72a4">1.2. QBasic demonstration program</a></li>
+</ul>
+</li>
+</ul>
+</div>
+</div>
+
+<div id="outline-container-org6da62e5" class="outline-2">
+<h2 id="org6da62e5"><span class="section-number-2">1.</span> Overview</h2>
+<div class="outline-text-2" id="text-1">
+<p>
+QBasic, a popular programming language in the DOS era, lacks native
+mouse support. This limitation can be a hurdle for developers looking
+to create interactive applications. To bridge this gap, I developed a
+solution that involves a Terminate and Stay Resident (TSR) program
+written in x86 assembly and a QBasic demonstration program.
+</p>
+
+
+<p>
+The solution comprises two main components:
+</p>
+</div>
+
+
+<div id="outline-container-orgf629f52" class="outline-3">
+<h3 id="orgf629f52"><span class="section-number-3">1.1.</span> Terminate and Stay Resident module</h3>
+<div class="outline-text-3" id="text-1-1">
+<p>
+A DOS TSR program that hooks into the system's interrupt mechanism to
+regularly read mouse input and store it in a dedicated memory
+location.
+</p>
+
+<p>
+Files:
+</p>
+<ul class="org-ul">
+<li><a href="qbext.asm">qbext.asm - x86 Assembly source code</a></li>
+<li><a href="qbext.com">qbext.com - binary COM executable for DOS</a></li>
+</ul>
+</div>
+</div>
+
+
+<div id="outline-container-org75f72a4" class="outline-3">
+<h3 id="org75f72a4"><span class="section-number-3">1.2.</span> QBasic demonstration program</h3>
+<div class="outline-text-3" id="text-1-2">
+<p>
+A QBasic program that reads mouse data from the memory location
+populated by the TSR and demonstrates mouse movement and button
+clicks.
+</p>
+
+
+
+<div id="orgbb53e8f" class="figure">
+<p><a href="mousedrv.bas" class="responsive-img"><img src="screenshot.png" alt="screenshot.png" class="responsive-img" /></a>
+</p>
+</div>
+
<p>
-This TSR written in x86 assembler, allows QBasic programs to use
-mouse, by writing mouse movement and button press info to memory,
-referenced by INT 79h. Afterwards QBasic programs can read mouse
-cursor position directly from RAM by using PEEK command.
+<a href="mousedrv.bas">mousedrv.bas - source code</a>
</p>
</div>
+</div>
+</div>
+</div>
<div id="postamble" class="status">
-<p class="date">Created: 2025-07-29 ti 16:07</p>
+<p class="date">Created: 2025-07-29 ti 17:15</p>
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
#+OPTIONS: H:20 num:20\r
#+OPTIONS: author:nil\r
\r
-This TSR written in x86 assembler, allows QBasic programs to use\r
-mouse, by writing mouse movement and button press info to memory,\r
-referenced by INT 79h. Afterwards QBasic programs can read mouse\r
-cursor position directly from RAM by using PEEK command.\r
+* Overview\r
+\r
+QBasic, a popular programming language in the DOS era, lacks native\r
+mouse support. This limitation can be a hurdle for developers looking\r
+to create interactive applications. To bridge this gap, I developed a\r
+solution that involves a Terminate and Stay Resident (TSR) program\r
+written in x86 assembly and a QBasic demonstration program.\r
+\r
+\r
+The solution comprises two main components:\r
+\r
+\r
+** Terminate and Stay Resident module\r
+\r
+A DOS TSR program that hooks into the system's interrupt mechanism to\r
+regularly read mouse input and store it in a dedicated memory\r
+location.\r
+\r
+Files:\r
+- [[file:qbext.asm][qbext.asm - x86 Assembly source code]]\r
+- [[file:qbext.com][qbext.com - binary COM executable for DOS]]\r
+\r
+\r
+** QBasic demonstration program\r
+\r
+A QBasic program that reads mouse data from the memory location\r
+populated by the TSR and demonstrates mouse movement and button\r
+clicks.\r
+\r
+\r
+#+attr_html: :class responsive-img\r
+#+attr_latex: :width 1000px\r
+[[file:mousedrv.bas][file:screenshot.png]]\r
+\r
+[[file:mousedrv.bas][mousedrv.bas - source code]]\r
cy = 100 ' Initial y-coordinate\r
maxmove = 50 ' Maximum movement in one step\r
frm = 0 ' Frame counter\r
- 1\r
+1\r
frm = frm + 1 ' Increment frame counter\r
' Check for user input on keyboard and exit if any key is pressed\r
IF INKEY$ <> "" THEN SYSTEM\r
\r
' Print the current coordinates and frame number.\r
LOCATE 1, 1\r
- PRINT cx, cy ' Print current x and y coordinates\r
- PRINT frm ' Print current frame number\r
+ PRINT "X: " + STR$(cx) + " Y:" + STR$(cy) + " " ' Print current x and y coordinates\r
+ PRINT "Frame #" + STR$(frm) ' Print current frame number\r
\r
' Erase circle at the old mouse position by drawing black circle\r
CIRCLE (cx, cy), 10, 0\r
' This subroutine stores a word (2 bytes) at the specified address in RAM.\r
b$ = HEX$(dat) ' Convert data to hexadecimal\r
\r
- 2\r
+2\r
IF LEN(b$) < 4 THEN b$ = "0" + b$: GOTO 2 ' Ensure four digits\r
\r
' Split the word into two bytes.\r
' Retrieve mouse data table address within TSR as pointed by interrupt 79h\r
extSEG = PEEK(&H79 * 4 + 3) * 256\r
extSEG = extSEG + PEEK(&H79 * 4 + 2)\r
- PRINT "Segment is: " + HEX$(extSEG) ' Print segment address\r
\r
' Retrieve the offset address of the mouse driver.\r
extADDR = PEEK(&H79 * 4 + 1) * 256\r
extADDR = extADDR + PEEK(&H79 * 4 + 0)\r
- PRINT "relative address is:"; extADDR ' Print offset address\r
DEF SEG = extSEG ' Set segment for memory access\r
\r
' Check if the mouse driver is loaded by verifying the magic number (1983).\r
SYSTEM ' Exit program if mouse driver is not loaded\r
END IF\r
END SUB\r
+\r