Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to PIT (?) IO ports 44h and 46h - what do those ports do?

I was disassembling an MS-DOS .com application and came across some port access which I don't understand. More precisely, via the IN instruction, values are read from the following ports.

40h
44h
46h

The documentation found here mentions ports 40h-47h belong to the 'Programmable Interval Timer', but the details elaborate only on ports 40h-43h.

From the disassembled context I would guess that the input is then used as pseudorandom numbers.

I also found this reference (in German) which does not mention the 4 other ports. Does anybody know the exact function of these ports, ideally with a reference?

Edit: To provide more context, the part of the disassembled application looks as follows.

in  al, 46h
mov cl, 03h
div cl
mov bl, ah

in  al, 44h
div cl
mov bh, ah

mov dx, 40h
in  al, dx
div cl

The application is this tiny effect; the read values are used to set the VGA palette RGB values to be colorful at best, interesting at worst.

like image 213
Codor Avatar asked Aug 23 '21 14:08

Codor


1 Answers

Your guess seems right. The code tries to set random colors. As it is part of a 256-byte intro, the focus is primarily on code size, not on portability or quality of the random numbers. Possibly this executable was originally meant for a PS/2 or EISA system, and timers 0, 3 and 5 (channel 0 and 2 of the second chip) were free-running. In case you don't have an EISA system, often aliasing will access timers 0, 0 again and 2. This program doesn't enable sound, so timer 2 would be stuck. Furthermore, the code clobbers AH as generated by the DIV instruction at 1BE by executing a MUL instruction at 1CA, so the value read from port 40h isn't used.

To undestand more than this educated guesswork, you would need to contact the author of that code. Considering the bug that AH is clobbered, it seems the code has been created at a demo party under time pressure, and not a lot of "design" went into it. It seems more like "it works well enough".

like image 121
Michael Karcher Avatar answered Sep 25 '22 00:09

Michael Karcher