home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / CODE.DOC < prev    next >
Text File  |  1993-01-09  |  13KB  |  277 lines

  1.  
  2. Intro crap:
  3. -----------
  4.  
  5.   Hello coder... This is Tran typing... What have you got here??? Well, the
  6. ASM files that were so conveniently included with this doc, are most of the
  7. stuff you will need to begin coding in full protected mode of the 386+...
  8. Included are file routines, getting command line argumets, a low level
  9. keyboard handler, of course the protected mode header, and a little utility -
  10. CBTMEM - that you use on your EXEs to give them the ability to reboot any
  11. system infested with evil memory managers and the like so that your superior
  12. protected mode program may run undaunted by their lameness...
  13.  
  14.   I coded all this stuff for my own personal use, but give this now to you
  15. so that you may enjoy the total coding freedom of flat memory, totally under
  16. your control... The hardest thing of course, was the header itself - START32.
  17. There is almost no info out there on the mundane little things that you need
  18. to do to set the system up for protected mode ... Like enabling the A20, or
  19. reprogramming the IRQ handlers... Even now, the info I have is incomplete. But
  20. it is good enough to run on almost all systems.
  21.  
  22.  
  23. Protected mode:
  24. ---------------
  25.  
  26.   I find it sad that protected mode should be limited to technical things
  27. like "QEMM" or "Windows"... Anyone with a 386+ and good old regular DOS can
  28. take advantage of all that pmode has to offer... And thats what this code
  29. will help you to do... With this code, you can write full 32bit pmode crap,
  30. with nothing like the 64k, 640k, or 1M barriers to hinder you. If you don't
  31. code in assembler however, go no further, because this code will do you no
  32. good unless you are fluent in (and of course you have love of) assembly...
  33. And if you have never used the 386 instruction set before, then youre in for
  34. a treat. I suggest however that you get yourself a good book on the 386,
  35. because this doc can't explain everything for you...
  36.  
  37.  
  38. Files included:
  39. ---------------
  40.  
  41.   START32.ASM  - Header code for getting in and out of, and handling protected
  42.                  mode.
  43.   START32.INC  - All extrns and macros you need to access various features
  44.                  of START32 from your module.
  45.   START32.DOC  - Old doc on technicalities of START32.
  46.   FILE32.ASM   - Library of some file functions.
  47.   FILE32.INC   - All extrns for FILE32.
  48.   ARGC32.ASM   - Three functions for getting command line parameters.
  49.   ARGC32.INC   - All extrns thereof (or whateverin, or howevercrap,
  50.           or something).
  51.   KB32.ASM     - Low level keyboard driver.
  52.   KB32.INC     - Extrns, and one solitary 1 instruction macro.
  53.   H.ASM        - Blank generic header file thing.
  54.   EXAMPLE?.ASM - Bunch of example programs.
  55.   *.RT         - Misc routines you can use.
  56.   CBTMEM.EXE   - Turns your EXEs into self-rebooting-then-running-again
  57.          thingys so that people dont have to mess with their configs
  58.          themselves.
  59.  
  60.   and various other little annoying pieces of propaganda for any and all
  61.   boardz this file has been through. (Except of course for our own propaganda,
  62.   which is OK).
  63.  
  64.  
  65. Ok, now what?:
  66. --------------
  67.  
  68.   First thing's zeroth... Read START32.DOC, its a doc from the old released
  69.   START32, with minor changes for time. If you are interested here are the
  70.   annoying little bugs that were in that old release:
  71.  
  72.     ) The A20 enabling was far from perfect.
  73.     ) There was no permission bitmap in the TSS for ports above 400h.
  74.     ) A really really really stupid typo in the _getmem function.
  75.     ) Problems with EXEs over 64K
  76.     ) I forget what else...
  77.  
  78.  
  79. Now that you read that:
  80. -----------------------
  81.  
  82.   I suggest you boot into a clean configuration (no memory managers or crap),
  83. then compile EXAMPLE0 and START32. Compile with multiple passes and case
  84. sensitivity on symbols (I'm assuming youre using TASM and TLINK). Then link
  85. and run the program you just created, if only to make sure it runs on your
  86. system.
  87.  
  88.   I don't know how much experience you've had with TASM or TLINK, so just in
  89. case you don't know, heres how you would do this:
  90.  
  91.   TASM /ML /M2 /Q START32
  92.   TASM /ML /M2 /Q EXAMPLE0
  93.   TLINK /3 /X START32 EXAMPLE0, EXAMPLE0
  94.  
  95.  
  96. I'm assuming it ran:
  97. --------------------
  98.  
  99.   And if it didn't... It's not my fault... Cuz it runs here...
  100.  
  101.  
  102. Anyways... now:
  103. ---------------
  104.  
  105.   To use the libraries, you would compile them, and link them in with your
  106. module and START32. You would also include the .INC files of the libraries
  107. you will be using in your module to make its functions and data areas
  108. available to your program.
  109.  
  110.  
  111. ------------------------------------------------------------------------------
  112. FILE32:
  113. -------
  114.  
  115.   This is a basic library of some file functions. They are:
  116.  
  117.     _openfile   - I think this is self-explanatory.
  118.     _readfile   - ditto.
  119.     _writefile  - gee... what could this possibly be???
  120.     _createfile - I don't know...
  121.     _deletefile - summons the devil...
  122.     _findfile   - ok, this one is the same as DOS int 21h functions 4eh, and
  123.                   4fh (AL specifies which one upon entry).
  124.     _lseekfile  - same as int 21h function 42h.
  125.     _filesize   - returns the size of and opened file.
  126.     _filecopy   - copies ECX bytes from one open file to another.
  127.     _closefile  - guess...
  128.  
  129.   To get a slightly better understanding of these functions, check out FILE32
  130. itself, and check out some of the example programs that use FILE32.
  131.  
  132.   Most of the functions will work immediately, without any setting up of
  133. anything by your program. However ... If you wish to read to a memory address
  134. physically above 1M, or write from there, you will have to set up an
  135. intermediate file buffer somewhere below 1M for FILE32 to use (Remember, plain
  136. DOS can't talk to memory above 1M)... Also, '_filecopy' always requires this
  137. buffer. But this is no problem, setting up this buffer is easy. There are two
  138. variables that specify the location and size of this buffer. '_filebufloc' is
  139. a pointer to the buffer area somewhere in low memory, your program must
  140. initialize this pointer, but you may modify it to point to a default area
  141. within your code. But why would you possibly want to do this? '_filebuflen' is
  142. the length of this buffer. 4000h bytes by default, but you may change it at
  143. compile time and run time.
  144.  
  145.   One thing to note. At the top of FILE32, there are several lines commented
  146. out. If you wish to use a function other than '_closefile', you must uncomment
  147. that file's token string in FILE32 before compiling it. This is merely because
  148. I don't like to waste code space, and include only what has to be included.
  149. If you don't want to bother, simply uncomment all these lines, and leave it
  150. like that, and all these functions be available without you having to edit
  151. FILE32 every time you want to use it.
  152.  
  153.  
  154. ------------------------------------------------------------------------------
  155. ARGC32:
  156. -------
  157.  
  158.   This lets you check command line argumets and switches. There are three
  159. functions.
  160.  
  161.     _cchekswitch - Checks for the presence of character AL preceeded by either
  162.                    a '-' or a '/' on the command line. This function is case
  163.                    sensitive, '_cchekswitchnc' is the same function, except
  164.                    that it is NOT case sensitive.
  165.     _cchekstr    - Gets a string from the command line. AL specifies which
  166.                    string, 0 is the first, 1 is the second, etc...
  167.     _ccheksstr   - check for the presence of a string IMMEDIATELY following
  168.                    a switch (such as '-ftest.doc'). This function is case
  169.                    sensitive on the switch.
  170.  
  171.   This little library also has token strings at the top for specifying wether
  172. to compile the functions or not.
  173.  
  174.  
  175. ------------------------------------------------------------------------------
  176. KB32:
  177. -----
  178.  
  179.   This is my low level keyboard interface thing. It replaces the BIOS int 16h
  180. keyboard handler (You can use the BIOS if you prefer... but WHY???). This
  181. thing ignores the CTRL-ALT-DEL sequence, and any other annoying little
  182. keypresses that the BIOS uses... But the best thing is, it allows you to
  183. specify your own handler for raw keyboard input. KB32 will handle talking
  184. to the keyboard controller, and can pass the value it reads on to your own
  185. routine.
  186.  
  187.   '_kbhand' is a pointer to the routine which will recieve the keyboard data.
  188. It points to a function in KB32 by default. That function processes the key
  189. code, and allows you access to the data like the BIOS. With the macro '@kbhit'
  190. you can check to see if a key was hit, and the function '_getch' returns
  191. the most recent keystroke (There is no keyboard buffering, (why bother)).
  192. One advantage of this handler over the BIOS, is that it returns the shift
  193. states along with the keypress. AL is the key pressed, and AH is the shift
  194. state returned (check out KB32.INC for bit assignments). The character recieved
  195. which is returned in AL, is not case adjusted. That is, if SHIFT is being held
  196. down, and you hit 'a', lower case 'a' will be returned, and not 'A'.
  197.  
  198.   If you do replace the default handler pointed to by '_kbhand' (You can do
  199. that at run time or compile time). Your must observe these rules in your
  200. handler:
  201.  
  202.   ) Your handler is being called out of an IRQ handler.
  203.   ) DS and ES are set to their appropriate values, but FS and GS are not.
  204.   ) AL contains the raw keyboard code.
  205.   ) You may destroy EAX,EBX,ECX,EDX,ESI,EDI,EBP,DS,ES,FS, and GS.
  206.  
  207. Before using the keyboard handler, you must initialize it with the function
  208. '_init_kb'. And before your program quits to DOS, you must call '_reset_kb'.
  209.  
  210. If you set your own handler through '_kbhand', and you want to restore the
  211. default KB32 handler, use the function '_reset_hand'.
  212.  
  213.  
  214. ------------------------------------------------------------------------------
  215. *.RT:
  216. -----
  217.  
  218.   There are a bunch of filez with the extention '.RT'... These are just misc
  219. routines you can include in your module to do little things. If ya want to
  220. know what they do load 'em up and check 'em out... Some of the example programs
  221. put them to some use.
  222.  
  223.  
  224. ------------------------------------------------------------------------------
  225. CBTMEM:
  226. -------
  227.  
  228.   As a consequence of being a full-fledged protected mode program, the EXEs
  229. you create cannot run under any other memory managers that run the system in
  230. protected mode. Thus was born CBTMEM. You use this program on your .EXE files.
  231. CBTMEM puts a special header into them. This header detects if the system is
  232. running under the control of some other protected mode program. If the system
  233. is under the control of a memory manager, or something more evil, the user
  234. will be asked if he/she/it wants to try a clean boot. If they select yes,
  235. AUTOEXEC.BAT and CONFIG.SYS will be backed up on the root directory of the
  236. boot drive, and replaced with something k00ler. Then the system will reboot.
  237. The FIRST thing that is done after the reboot, is that the AUTOEXEC.BAT and
  238. CONFIG.SYS are restored ... Thus minimizing the possibility of any unnice
  239. things happening. Then the system will switch to the drive and directory of
  240. the program that was run, and it will be ran again. The command line arguments
  241. are not preserved however. After the program terminates, the user will be
  242. asked if he/she/it wants to reboot back into their original configuration.
  243.  
  244.   There are three things you put on the command line of CBTMEM.
  245.  
  246.     1) The EXE you want to make self-booting (with the .EXE extention).
  247.     2) The minimum amount of low memory needed to run the EXE.
  248.     3) The minimum amount of extended memory needed.
  249.  
  250.   The low memory is there for this reason: Whenever people run things, their
  251. system is usually full of useless crap which just hogs memory, and if they
  252. dont have enough memory to run a program, they usually have to reboot anyway.
  253. You can have your EXE reboot for them if they don't have enough memory. If you
  254. don't want to reboot for that reason, simply set this number to 0. If you
  255. do want this 'feature', put the amount of free memory your program needs
  256. (minus its own code) in paragraphs in hex.
  257.  
  258.   The extended memory is the minimum amount of extended memory your program
  259. needs. If not enough extended memory is found, the program is not run. The
  260. means of checking is int 15h function 88h, which means that if you have any
  261. disk-caches or anything that is using that memory for something, it will
  262. not be corrupted. If you specified an amount higher than 0k, and an XMS driver
  263. is detected, the person will be given the choice to reboot. This number is
  264. also in hex, but is in K, not paragraphs like the low memory value.
  265.  
  266.  
  267. ------------------------------------------------------------------------------
  268. Well, thats that:
  269. -----------------
  270.  
  271.   Hope you like 32bit protected mode... And I hope there aren't too many typos
  272. in this doc...
  273.  
  274.  
  275. L8r... Tran...
  276.  
  277.