'=========================================================================== ' Subject: CHANGE FREQ OF SYSTEM TIMER Date: 07-07-96 (00:00) ' Author: Edward Di Geronimo Jr. Code: QB, QBasic, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: DATETIME.ABC '=========================================================================== 'Here's some almost working code to get more precise timing in 'QuickBasic. It works by changing the internal timer to generate an 'interrupt more often than 18.2 times per second. To use this code, call 'the ChangeTimer function, and to get the desired frequency use this 'formula: ' 1.19318mhz '----------------- 'desired freuqency '18.2 comes about by dividing by 65535 (highest 16bit number). 'If you look at the code, you'll notice there are COUNTER0, 1, and 2 'constants. Counter 0 is the frequency of the system timer (which we 'change), counter 1 is the ram refresh rate (don't change!), and counter '2 is related to the pc speaker (I doubt you should touch it). 'I know this works in C, but I don't know how well it will work in QB. 'It should effect the TIMER value. It would be great for games if we 'could write our own ISR's to accompany this, but QB doesn't have 'pointers, let alone sub/function pointers, so we can't. Oh well. But ON 'TIMER should be effected by this, so I guess we don't need one. I'll 'leave it to you guys to figure it out. 'Code to change the frequency of the 8253 clock chip's interrupt 'generation. Public domain (C) by Edward Di Geronimo Jr. 7/7/96 DEFINT A-Z DECLARE SUB ChangeTimer (NewCount%) CONST CONTROL8253 = &H43 ' the 8253's control register CONST CONTROLWORD = &H3C ' the control word to set mode 2 ' binary least/most CONST COUNTER0 = &H40 ' counter 0 CONST COUNTER1 = &H41 ' counter 1 CONST COUNTER2 = &H42 ' counter 2 CONST TIMER60HZ = &H4DAE ' 60 hz CONST TIMER50HZ = &H5D37 ' 50 hz CONST TIMER40HZ = &H7486 ' 40 hz CONST TIMER30HZ = &H965C ' 30 hz CONST TIMER20HZ = &HE90B ' 20 hz CONST TIMER18HZ = &HFFFF ' 18.2 hz (the standard count and the slowest possible) ChangeTimer TIMER60HZ DO WHILE INKEY$ = "" A# = TIMER PRINT A#, WHILE A# = TIMER: WEND LOOP ChangeTimer TIMER18HZ SUB ChangeTimer (NewCount) ' send the control word, mode 2, binary, least/most load sequence OUT CONTROL8253, CONTROLWORD ' now write the least significant byte to the counter register OUT COUNTER0, NewCount AND &HFF ' LOWBYTE(newcount) ' and now the the most significant byte OUT COUNTER0, (NewCount AND &HFF00) / 256 ' HIGHBYTE(newcount) END SUB