Replace invalid characters with HTML entities
— with — ’ with ’ + with + × with x ç with ç “ with “ ” with ” ‘ with ‘ • with • – with - µ with µ † with † Fix C++ θ with θ Yen symbol instead of times Fix broken apos Bullet again E-circumflex
This commit is contained in:
parent
9e52de9586
commit
500e7f5654
353 changed files with 5091 additions and 5091 deletions
28
01-01.html
28
01-01.html
File diff suppressed because one or more lines are too long
36
01-02.html
36
01-02.html
File diff suppressed because one or more lines are too long
30
01-03.html
30
01-03.html
File diff suppressed because one or more lines are too long
30
01-04.html
30
01-04.html
File diff suppressed because one or more lines are too long
38
01-05.html
38
01-05.html
File diff suppressed because one or more lines are too long
28
01-06.html
28
01-06.html
File diff suppressed because one or more lines are too long
10
02-01.html
10
02-01.html
File diff suppressed because one or more lines are too long
14
02-02.html
14
02-02.html
File diff suppressed because one or more lines are too long
16
02-03.html
16
02-03.html
File diff suppressed because one or more lines are too long
20
03-01.html
20
03-01.html
File diff suppressed because one or more lines are too long
50
03-02.html
50
03-02.html
|
|
@ -70,10 +70,10 @@
|
|||
;
|
||||
; Note: These routines can introduce slight inaccuracies into the
|
||||
; system clock count for each code section timed even if
|
||||
; timer 0 doesn’t overflow. If timer 0 does overflow, the
|
||||
; timer 0 doesn’t overflow. If timer 0 does overflow, the
|
||||
; system clock can become slow by virtually any amount of
|
||||
; time, since the system clock can’t advance while the
|
||||
; precison timer is timing. Consequently, it’s a good idea
|
||||
; time, since the system clock can’t advance while the
|
||||
; precison timer is timing. Consequently, it’s a good idea
|
||||
; to reboot at the end of each timing session. (The
|
||||
; battery-backed clock, if any, is not affected by the Zen
|
||||
; timer.)
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
; in when ZTimerOn was called.
|
||||
;
|
||||
|
||||
Code segment word public ‘CODE’
|
||||
Code segment word public ‘CODE’
|
||||
assumecs: Code, ds:nothing
|
||||
public ZTimerOn, ZTimerOff, ZTimerReport
|
||||
|
||||
|
|
@ -95,11 +95,11 @@ BASE_8253equ40h
|
|||
;
|
||||
; The address of the timer 0 count registers in the 8253.
|
||||
;
|
||||
TIMER_0_8253 equBASE_8253 + 0
|
||||
TIMER_0_8253 equBASE_8253 + 0
|
||||
;
|
||||
; The address of the mode register in the 8253.
|
||||
;
|
||||
MODE_8253 equBASE_8253 + 3
|
||||
MODE_8253 equBASE_8253 + 3
|
||||
;
|
||||
; The address of Operation Command Word 3 in the 8259 Programmable
|
||||
; Interrupt Controller (PIC) (write only, and writable only when
|
||||
|
|
@ -131,9 +131,9 @@ p2: push cs ; construct far return address to
|
|||
; can respond to both accesses even on a very fast PC.
|
||||
;
|
||||
DELAY macro
|
||||
jmp $+2
|
||||
jmp $+2
|
||||
jmp $+2
|
||||
jmp $+2
|
||||
jmp $+2
|
||||
jmp $+2
|
||||
endm
|
||||
|
||||
OriginalFlags db ? ; storage for upper byte of
|
||||
|
|
@ -150,28 +150,28 @@ OverflowFlag db ? ; used to indicate whether the
|
|||
; String printed to report results.
|
||||
;
|
||||
OutputStr label byte
|
||||
db 0dh, 0ah, ‘Timed count: ‘, 5 dup (?)
|
||||
db 0dh, 0ah, ‘Timed count: ‘, 5 dup (?)
|
||||
ASCIICountEnd labelbyte
|
||||
db ‘ microseconds’, 0dh, 0ah
|
||||
db ‘$’
|
||||
db ‘ microseconds’, 0dh, 0ah
|
||||
db ‘$’
|
||||
;
|
||||
; String printed to report timer overflow.
|
||||
;
|
||||
OverflowStr label byte
|
||||
db 0dh, 0ah
|
||||
db ‘****************************************************’
|
||||
db ‘****************************************************’
|
||||
db 0dh, 0ah
|
||||
db ‘* The timer overflowed, so the interval timed was *’
|
||||
db ‘* The timer overflowed, so the interval timed was *’
|
||||
db 0dh, 0ah
|
||||
db ‘* too long for the precision timer to measure. *’
|
||||
db ‘* too long for the precision timer to measure. *’
|
||||
db 0dh, 0ah
|
||||
db ‘* Please perform the timing test again with the *’
|
||||
db ‘* Please perform the timing test again with the *’
|
||||
db0dh, 0ah
|
||||
db ‘* long-period timer. *’
|
||||
db ‘* long-period timer. *’
|
||||
db 0dh, 0ah
|
||||
db ‘****************************************************’
|
||||
db ‘****************************************************’
|
||||
db 0dh, 0ah
|
||||
db ‘$’
|
||||
db ‘$’
|
||||
|
||||
; ********************************************************************
|
||||
; * Routine called to start timing. *
|
||||
|
|
@ -193,7 +193,7 @@ ZTimerOn proc near
|
|||
; to 0
|
||||
push ax
|
||||
;
|
||||
; Turn on interrupts, so the timer interrupt can occur if it’s
|
||||
; Turn on interrupts, so the timer interrupt can occur if it’s
|
||||
; pending.
|
||||
;
|
||||
sti
|
||||
|
|
@ -206,7 +206,7 @@ ZTimerOn proc near
|
|||
mov al,00110100b ;mode 2
|
||||
out MODE_8253,al
|
||||
;
|
||||
; Set the timer count to 0, so we know we won’t get another
|
||||
; Set the timer count to 0, so we know we won’t get another
|
||||
; timer interrupt right away.
|
||||
; Note: this introduces an inaccuracy of up to 54 ms in the system
|
||||
; clock count each time it is executed.
|
||||
|
|
@ -224,7 +224,7 @@ ZTimerOn proc near
|
|||
; delay time will be more than long enough even on a very fast PC.
|
||||
;
|
||||
rept 10
|
||||
jmp $+2
|
||||
jmp $+2
|
||||
endm
|
||||
;
|
||||
; Disable interrupts to get an accurate count.
|
||||
|
|
@ -308,9 +308,9 @@ ZTimerOff proc near
|
|||
call ReferenceZTimerOff
|
||||
loop RefLoop
|
||||
sti
|
||||
add cs:[ReferenceCount],8; total + (0.5 * 16)
|
||||
add cs:[ReferenceCount],8; total + (0.5 * 16)
|
||||
mov cl,4
|
||||
shr cs:[ReferenceCount],cl; (total) / 16 + 0.5
|
||||
shr cs:[ReferenceCount],cl; (total) / 16 + 0.5
|
||||
;
|
||||
; Restore original interrupt state.
|
||||
;
|
||||
|
|
@ -453,7 +453,7 @@ PrintGoodCount:
|
|||
CTSLoop:
|
||||
sub dx, dx
|
||||
div bx
|
||||
add dl,’0’
|
||||
add dl,’0’
|
||||
mov [si],dl
|
||||
dec si
|
||||
loop CTSLoop
|
||||
|
|
|
|||
16
03-03.html
16
03-03.html
File diff suppressed because one or more lines are too long
18
03-04.html
18
03-04.html
File diff suppressed because one or more lines are too long
18
03-05.html
18
03-05.html
File diff suppressed because one or more lines are too long
18
03-06.html
18
03-06.html
File diff suppressed because one or more lines are too long
102
03-07.html
102
03-07.html
File diff suppressed because one or more lines are too long
16
03-08.html
16
03-08.html
File diff suppressed because one or more lines are too long
14
03-09.html
14
03-09.html
File diff suppressed because one or more lines are too long
30
03-10.html
30
03-10.html
File diff suppressed because one or more lines are too long
28
04-01.html
28
04-01.html
File diff suppressed because one or more lines are too long
16
04-02.html
16
04-02.html
File diff suppressed because one or more lines are too long
30
04-03.html
30
04-03.html
File diff suppressed because one or more lines are too long
22
04-04.html
22
04-04.html
File diff suppressed because one or more lines are too long
16
04-05.html
16
04-05.html
File diff suppressed because one or more lines are too long
26
04-06.html
26
04-06.html
File diff suppressed because one or more lines are too long
20
04-07.html
20
04-07.html
File diff suppressed because one or more lines are too long
20
04-08.html
20
04-08.html
File diff suppressed because one or more lines are too long
16
04-09.html
16
04-09.html
File diff suppressed because one or more lines are too long
12
04-10.html
12
04-10.html
File diff suppressed because one or more lines are too long
22
05-01.html
22
05-01.html
File diff suppressed because one or more lines are too long
28
05-02.html
28
05-02.html
File diff suppressed because one or more lines are too long
44
05-03.html
44
05-03.html
|
|
@ -50,7 +50,7 @@
|
|||
#include <alloc.h> /* alloc.h for Borland compilers,
|
||||
malloc.h for Microsoft compilers */
|
||||
|
||||
#define BLOCK_SIZE 0x4000 /* we’ll process the file in 16K blocks */
|
||||
#define BLOCK_SIZE 0x4000 /* we’ll process the file in 16K blocks */
|
||||
|
||||
/* Searches the specified number of sequences in the specified
|
||||
buffer for matches to SearchString of SearchStringLength. Note
|
||||
|
|
@ -77,19 +77,19 @@ int SearchForString(unsigned char *Buffer, int SearchLength,
|
|||
also matches */
|
||||
if ( SearchStringLength == 1 ) {
|
||||
return(1); /* That one matching character was the whole
|
||||
search string, so we’ve got a match */
|
||||
search string, so we’ve got a match */
|
||||
}
|
||||
else {
|
||||
/* Check whether the remaining characters match */
|
||||
if ( !memcmp(PotentialMatch + 1, SearchString + 1,
|
||||
if ( !memcmp(PotentialMatch + 1, SearchString + 1,
|
||||
SearchStringLength - 1) ) {
|
||||
return(1); /* We’ve got a match */
|
||||
return(1); /* We’ve got a match */
|
||||
}
|
||||
}
|
||||
/* The string doesn’t match; keep going by pointing past the
|
||||
/* The string doesn’t match; keep going by pointing past the
|
||||
potential match location we just rejected */
|
||||
SearchLength -= PotentialMatch - Buffer + 1;
|
||||
Buffer = PotentialMatch + 1;
|
||||
SearchLength -= PotentialMatch - Buffer + 1;
|
||||
Buffer = PotentialMatch + 1;
|
||||
}
|
||||
|
||||
return(0); /* No match found */
|
||||
|
|
@ -114,13 +114,13 @@ main(int argc, char *argv[]) {
|
|||
|
||||
/* Check for the proper number of arguments */
|
||||
if ( argc != 3 ) {
|
||||
printf(“usage: search filename search-string\n”);
|
||||
printf(“usage: search filename search-string\n”);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Try to open the file to be searched */
|
||||
if ( (Handle = open(argv[1], O_RDONLY | O_BINARY)) == -1 ) {
|
||||
printf(“Can’t open file: %s\n”, argv[1]);
|
||||
printf(“Can’t open file: %s\n”, argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
/* Calculate the length of text to search for */
|
||||
|
|
@ -128,7 +128,7 @@ main(int argc, char *argv[]) {
|
|||
SearchStringLength = strlen(SearchString);
|
||||
/* Try to get memory in which to buffer the data */
|
||||
if ( (WorkingBlock = malloc(BLOCK_SIZE)) == NULL ) {
|
||||
printf(“Can’t get enough memory\n”);
|
||||
printf(“Can’t get enough memory\n”);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ main(int argc, char *argv[]) {
|
|||
NextLoadPtr = WorkingBlock;
|
||||
NextLoadCount = BLOCK_SIZE;
|
||||
Done = 0; /* Not done with search yet */
|
||||
Found = 0; /* Assume we won’t find a match */
|
||||
Found = 0; /* Assume we won’t find a match */
|
||||
/* Search the file in BLOCK_SIZE chunks */
|
||||
do {
|
||||
/* Read in however many bytes are needed to fill out the block
|
||||
|
|
@ -145,10 +145,10 @@ main(int argc, char *argv[]) {
|
|||
the rest of the bytes in the file, whichever is less */
|
||||
if ( (WorkingLength = read(Handle, NextLoadPtr,
|
||||
NextLoadCount)) == -1 ) {
|
||||
printf(“Error reading file %s\n”, argv[1]);
|
||||
printf(“Error reading file %s\n”, argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
/* If we didn’t read all the bytes we requested, we’re done
|
||||
/* If we didn’t read all the bytes we requested, we’re done
|
||||
after this block, whether we find a match or not */
|
||||
if ( WorkingLength != NextLoadCount ) {
|
||||
Done = 1;
|
||||
|
|
@ -156,7 +156,7 @@ main(int argc, char *argv[]) {
|
|||
|
||||
/* Account for any bytes we copied from the end of the last
|
||||
block in the total length of this block */
|
||||
WorkingLength += NextLoadPtr - WorkingBlock;
|
||||
WorkingLength += NextLoadPtr - WorkingBlock;
|
||||
/* Calculate the number of bytes in this block that could
|
||||
possibly be the start of a matching sequence that lies
|
||||
entirely in this block (sequences that run off the end of
|
||||
|
|
@ -164,10 +164,10 @@ main(int argc, char *argv[]) {
|
|||
when that block is searched)
|
||||
*/
|
||||
if ( (BlockSearchLength =
|
||||
WorkingLength - SearchStringLength + 1) <= 0 ) {
|
||||
WorkingLength - SearchStringLength + 1) <= 0 ) {
|
||||
Done = 1; /* Too few characters in this block for
|
||||
there to be any possible matches, so this
|
||||
is the final block and we’re done without
|
||||
is the final block and we’re done without
|
||||
finding a match
|
||||
*/
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ main(int argc, char *argv[]) {
|
|||
/* Search this block */
|
||||
if ( SearchForString(WorkingBlock, BlockSearchLength,
|
||||
SearchString, SearchStringLength) ) {
|
||||
Found = 1; /* We’ve found a match */
|
||||
Found = 1; /* We’ve found a match */
|
||||
Done = 1;
|
||||
}
|
||||
else {
|
||||
|
|
@ -184,22 +184,22 @@ main(int argc, char *argv[]) {
|
|||
the end of the block over to the next block */
|
||||
if ( SearchStringLength > 1 ) {
|
||||
memcpy(WorkingBlock,
|
||||
WorkingBlock+BLOCK_SIZE - SearchStringLength + 1,
|
||||
WorkingBlock+BLOCK_SIZE - SearchStringLength + 1,
|
||||
SearchStringLength - 1);
|
||||
}
|
||||
/* Set up to load the next bytes from the file after the
|
||||
bytes copied from the end of the current block */
|
||||
NextLoadPtr = WorkingBlock + SearchStringLength - 1;
|
||||
NextLoadCount = BLOCK_SIZE - SearchStringLength + 1;
|
||||
NextLoadPtr = WorkingBlock + SearchStringLength - 1;
|
||||
NextLoadCount = BLOCK_SIZE - SearchStringLength + 1;
|
||||
}
|
||||
}
|
||||
} while ( !Done );
|
||||
|
||||
/* Report the results */
|
||||
if ( Found ) {
|
||||
printf(“String found\n”);
|
||||
printf(“String found\n”);
|
||||
} else {
|
||||
printf(“String not found\n”);
|
||||
printf(“String not found\n”);
|
||||
}
|
||||
exit(Found); /* Return the found/not found status as the
|
||||
DOS errorlevel */
|
||||
|
|
|
|||
16
05-04.html
16
05-04.html
File diff suppressed because one or more lines are too long
16
05-05.html
16
05-05.html
File diff suppressed because one or more lines are too long
36
06-01.html
36
06-01.html
File diff suppressed because one or more lines are too long
34
06-02.html
34
06-02.html
File diff suppressed because one or more lines are too long
28
07-01.html
28
07-01.html
File diff suppressed because one or more lines are too long
22
07-02.html
22
07-02.html
File diff suppressed because one or more lines are too long
32
07-03.html
32
07-03.html
File diff suppressed because one or more lines are too long
44
07-04.html
44
07-04.html
File diff suppressed because one or more lines are too long
30
07-05.html
30
07-05.html
File diff suppressed because one or more lines are too long
26
08-01.html
26
08-01.html
File diff suppressed because one or more lines are too long
26
08-02.html
26
08-02.html
File diff suppressed because one or more lines are too long
50
08-03.html
50
08-03.html
File diff suppressed because one or more lines are too long
56
08-04.html
56
08-04.html
File diff suppressed because one or more lines are too long
48
08-05.html
48
08-05.html
File diff suppressed because one or more lines are too long
48
09-01.html
48
09-01.html
File diff suppressed because one or more lines are too long
24
09-02.html
24
09-02.html
File diff suppressed because one or more lines are too long
36
09-03.html
36
09-03.html
File diff suppressed because one or more lines are too long
50
09-04.html
50
09-04.html
|
|
@ -67,15 +67,15 @@ Parmsends
|
|||
.code
|
||||
public _FindString
|
||||
_FindStringprocnear
|
||||
push bp ;preserve caller’s stack frame
|
||||
push bp ;preserve caller’s stack frame
|
||||
mov bp,sp ;point to our stack frame
|
||||
push si ;preserve caller’s register variables
|
||||
push si ;preserve caller’s register variables
|
||||
push di
|
||||
cld ;make string instructions increment pointers
|
||||
mov si,[bp+SearchString] ;pointer to string to search for
|
||||
mov cx,[bp+SearchStringLength] ;length of string
|
||||
mov si,[bp+SearchString] ;pointer to string to search for
|
||||
mov cx,[bp+SearchStringLength] ;length of string
|
||||
jcxz FindStringNotFound ;no match if string is 0 length
|
||||
mov dx,[bp+BufferLength] ;length of buffer
|
||||
mov dx,[bp+BufferLength] ;length of buffer
|
||||
sub dx,cx ;difference between buffer and search
|
||||
; lengths
|
||||
jc FindStringNotFound ;no match if search string is
|
||||
|
|
@ -85,11 +85,11 @@ _FindStringprocnear
|
|||
; locations to check in the buffer)
|
||||
mov di,ds
|
||||
mov es,di
|
||||
mov di,[bp+Buffer] ;point ES:DI to buffer to search thru
|
||||
mov bx,[bp+ScanCharOffset] ;offset in string of character
|
||||
mov di,[bp+Buffer] ;point ES:DI to buffer to search thru
|
||||
mov bx,[bp+ScanCharOffset] ;offset in string of character
|
||||
; on which to scan
|
||||
add di,bx ;point ES:DI to first buffer byte to scan
|
||||
mov al,[si+bx] ;put the scan character in AL
|
||||
mov al,[si+bx] ;put the scan character in AL
|
||||
inc bx ;set BX to the offset back to the start of the
|
||||
; potential full match after a scan match,
|
||||
; accounting for the 1-byte overrun of
|
||||
|
|
@ -97,7 +97,7 @@ _FindStringprocnear
|
|||
FindStringLoop:
|
||||
mov cx,dx ;put remaining buffer search length in CX
|
||||
repnz scasb ;scan for the scan byte
|
||||
jnz FindStringNotFound ;not found, so there’s no match
|
||||
jnz FindStringNotFound ;not found, so there’s no match
|
||||
;found, so we have a potential match-check the
|
||||
; rest of this candidate location
|
||||
push di ;remember the address of the next byte to scan
|
||||
|
|
@ -105,18 +105,18 @@ FindStringLoop:
|
|||
; the buffer
|
||||
sub di,bx ;point back to the potential start of the
|
||||
; match in the buffer
|
||||
mov si,[bp+SearchString] ;point to the start of the string
|
||||
mov cx,[bp+SearchStringLength] ;string length
|
||||
mov si,[bp+SearchString] ;point to the start of the string
|
||||
mov cx,[bp+SearchStringLength] ;string length
|
||||
shr cx,1 ;convert to word for faster search
|
||||
jnc FindStringWord ;do word search if no odd byte
|
||||
cmpsb ;compare the odd byte
|
||||
jnz FindStringNoMatch ;odd byte doesn’t match, so we
|
||||
; haven’t found the search string here
|
||||
jnz FindStringNoMatch ;odd byte doesn’t match, so we
|
||||
; haven’t found the search string here
|
||||
FindStringWord:
|
||||
jcxz FindStringFound ;if the string is only 1 byte long,
|
||||
; we’ve found a match
|
||||
; we’ve found a match
|
||||
repz cmpsw ;check the rest of the string a word at a time
|
||||
jz FindStringFound ;it’s a match
|
||||
jz FindStringFound ;it’s a match
|
||||
FindStringNoMatch:
|
||||
pop di ;get back pointer to the next byte to scan
|
||||
and dx,dx ;is there anything left to check?
|
||||
|
|
@ -129,9 +129,9 @@ FindStringFound:
|
|||
sub ax,bx ; string was found (earlier we pushed the
|
||||
; address of the byte after the scan match)
|
||||
FindStringDone:
|
||||
pop di ;restore caller’s register variables
|
||||
pop di ;restore caller’s register variables
|
||||
pop si
|
||||
pop bp ;restore caller’s stack frame
|
||||
pop bp ;restore caller’s stack frame
|
||||
ret
|
||||
_FindStringendp
|
||||
end
|
||||
|
|
@ -148,26 +148,26 @@ _FindStringendp
|
|||
extern unsigned char * FindString(unsigned char *, unsigned int,
|
||||
unsigned char *, unsigned int, unsigned int);
|
||||
void main(void);
|
||||
static unsigned char TestBuffer[] = “When, in the course of human \
|
||||
static unsigned char TestBuffer[] = “When, in the course of human \
|
||||
events, it becomes necessary for one people to dissolve the \
|
||||
political bands which have connected them with another, and to \
|
||||
assume among the powers of the earth the separate and equal station \
|
||||
to which the laws of nature and of nature’s God entitle them...”;
|
||||
to which the laws of nature and of nature’s God entitle them...”;
|
||||
void main() {
|
||||
static unsigned char TestString[] = “equal”;
|
||||
unsigned char TempBuffer[DISPLAY_LENGTH+1];
|
||||
static unsigned char TestString[] = “equal”;
|
||||
unsigned char TempBuffer[DISPLAY_LENGTH+1];
|
||||
unsigned char *MatchPtr;
|
||||
/* Search for TestString and report the results */
|
||||
if ((MatchPtr = FindString(TestBuffer,
|
||||
(unsigned int) strlen(TestBuffer), TestString,
|
||||
(unsigned int) strlen(TestString), 1)) == NULL) {
|
||||
/* TestString wasn’t found */
|
||||
printf(“\”%s\“ not found\n”, TestString);
|
||||
/* TestString wasn’t found */
|
||||
printf(“\”%s\“ not found\n”, TestString);
|
||||
} else {
|
||||
/* TestString was found. Zero-terminate TempBuffer; strncpy
|
||||
won’t do it if DISPLAY_LENGTH characters are copied */
|
||||
won’t do it if DISPLAY_LENGTH characters are copied */
|
||||
TempBuffer[DISPLAY_LENGTH] = 0;
|
||||
printf(“\”%s\“ found. Next %d characters at match:\n\”%s\“\n”,
|
||||
printf(“\”%s\“ found. Next %d characters at match:\n\”%s\“\n”,
|
||||
TestString, DISPLAY_LENGTH,
|
||||
strncpy(TempBuffer, MatchPtr, DISPLAY_LENGTH));
|
||||
}
|
||||
|
|
|
|||
10
09-05.html
10
09-05.html
File diff suppressed because one or more lines are too long
30
09-06.html
30
09-06.html
File diff suppressed because one or more lines are too long
28
09-07.html
28
09-07.html
File diff suppressed because one or more lines are too long
22
10-01.html
22
10-01.html
File diff suppressed because one or more lines are too long
28
10-02.html
28
10-02.html
File diff suppressed because one or more lines are too long
26
10-03.html
26
10-03.html
File diff suppressed because one or more lines are too long
30
10-04.html
30
10-04.html
File diff suppressed because one or more lines are too long
28
11-01.html
28
11-01.html
File diff suppressed because one or more lines are too long
18
11-02.html
18
11-02.html
File diff suppressed because one or more lines are too long
32
11-03.html
32
11-03.html
File diff suppressed because one or more lines are too long
20
11-04.html
20
11-04.html
File diff suppressed because one or more lines are too long
28
11-05.html
28
11-05.html
File diff suppressed because one or more lines are too long
20
11-06.html
20
11-06.html
File diff suppressed because one or more lines are too long
16
11-07.html
16
11-07.html
File diff suppressed because one or more lines are too long
18
11-08.html
18
11-08.html
File diff suppressed because one or more lines are too long
26
12-01.html
26
12-01.html
File diff suppressed because one or more lines are too long
24
12-02.html
24
12-02.html
File diff suppressed because one or more lines are too long
24
12-03.html
24
12-03.html
File diff suppressed because one or more lines are too long
26
12-04.html
26
12-04.html
File diff suppressed because one or more lines are too long
24
13-01.html
24
13-01.html
File diff suppressed because one or more lines are too long
18
13-02.html
18
13-02.html
File diff suppressed because one or more lines are too long
14
13-03.html
14
13-03.html
File diff suppressed because one or more lines are too long
16
13-04.html
16
13-04.html
File diff suppressed because one or more lines are too long
30
14-01.html
30
14-01.html
File diff suppressed because one or more lines are too long
18
14-02.html
18
14-02.html
File diff suppressed because one or more lines are too long
18
14-03.html
18
14-03.html
File diff suppressed because one or more lines are too long
60
14-04.html
60
14-04.html
File diff suppressed because one or more lines are too long
70
14-05.html
70
14-05.html
|
|
@ -63,16 +63,16 @@ parms ends
|
|||
public _FindString
|
||||
_FindString proc near
|
||||
cld
|
||||
push bp ;preserve caller’s stack frame
|
||||
push bp ;preserve caller’s stack frame
|
||||
mov bp,sp ;point to our stack frame
|
||||
push si ;preserve caller’s register variables
|
||||
push si ;preserve caller’s register variables
|
||||
push di
|
||||
sub sp,256*2 ;allocate space for SkipTable
|
||||
; Create the table of distances by which to skip ahead on mismatches
|
||||
; for every possible byte value. First, initialize all skips to the
|
||||
; pattern length; this is the skip distance for bytes that don’t
|
||||
; pattern length; this is the skip distance for bytes that don’t
|
||||
; appear in the pattern.
|
||||
mov ax,[bp+PatternLength]
|
||||
mov ax,[bp+PatternLength]
|
||||
and ax,ax ;return an instant match if the pattern is
|
||||
jz InstantMatch ;0-length
|
||||
mov di,ds
|
||||
|
|
@ -81,23 +81,23 @@ _FindString proc near
|
|||
mov cx,256
|
||||
rep stosw
|
||||
dec ax ;from now on, we only need
|
||||
mov [bp+PatternLength],ax ; PatternLength - 1
|
||||
mov [bp+PatternLength],ax ; PatternLength - 1
|
||||
; Point to last (rightmost) byte of first potential pattern match
|
||||
; location in buffer.
|
||||
add [bp+BufferPtr],ax
|
||||
add [bp+BufferPtr],ax
|
||||
; Reject if buffer is too small, and set the count of the number of
|
||||
; potential pattern match locations in the buffer.
|
||||
sub [bp+BufferLength],ax
|
||||
sub [bp+BufferLength],ax
|
||||
jbe NoMatch
|
||||
; Set the skip values for the bytes that do appear in the pattern to
|
||||
; the distance from the byte location to the end of the pattern.
|
||||
; When there are multiple instances of the same byte, the rightmost
|
||||
; instance’s skip value is used. Note that the rightmost byte of the
|
||||
; pattern isn’t entered in the skip table; if we get that value for
|
||||
; instance’s skip value is used. Note that the rightmost byte of the
|
||||
; pattern isn’t entered in the skip table; if we get that value for
|
||||
; a mismatch, we know for sure that the right end of the pattern has
|
||||
; already passed the mismatch location, so this is not a relevant byte
|
||||
; for skipping purposes.
|
||||
mov si,[bp+PatternPtr] ;point to start of pattern
|
||||
mov si,[bp+PatternPtr] ;point to start of pattern
|
||||
and ax,ax ;are there any skips to set?
|
||||
jz SetSkipDone ;no
|
||||
mov di,sp ;point to SkipBuffer
|
||||
|
|
@ -106,57 +106,57 @@ SetSkipLoop:
|
|||
mov bl,[si] ;get the next pattern byte
|
||||
inc si ;advance the pattern pointer
|
||||
shl bx,1 ;prepare for word lookup
|
||||
mov [di+bx],ax ;set the skip value when this byte value is
|
||||
mov [di+bx],ax ;set the skip value when this byte value is
|
||||
; the mismatch value in the buffer
|
||||
dec ax
|
||||
jnz SetSkipLoop
|
||||
SetSkipDone:
|
||||
mov dl,[si] ;DL=rightmost pattern byte from now on
|
||||
dec si ;point to next-to-rightmost byte of pattern
|
||||
mov [bp+PatternPtr],si ; from now on
|
||||
mov [bp+PatternPtr],si ; from now on
|
||||
; Search the buffer.
|
||||
std ;for backward REPZ CMPSB
|
||||
mov di,[bp+BufferPtr] ;point to first search location
|
||||
mov cx,[bp+BufferLength] ;# of match locations to check
|
||||
mov di,[bp+BufferPtr] ;point to first search location
|
||||
mov cx,[bp+BufferLength] ;# of match locations to check
|
||||
SearchLoop:
|
||||
mov si,sp ;point SI to SkipTable
|
||||
; Skip through until there’s a match for the rightmost pattern byte.
|
||||
; Skip through until there’s a match for the rightmost pattern byte.
|
||||
QuickSearchLoop:
|
||||
mov bl,[di] ;rightmost buffer byte at this location
|
||||
cmp dl,bl ;does it match the rightmost pattern byte?
|
||||
jz FullCompare ;yes, so keep going
|
||||
sub bh,bh ;convert to a word
|
||||
add bx,bx ;prepare for look-up in SkipTable
|
||||
mov ax,[si+bx] ;get skip value from skip table for this
|
||||
mov ax,[si+bx] ;get skip value from skip table for this
|
||||
; mismatch value
|
||||
add di,ax ;BufferPtr += Skip;
|
||||
add di,ax ;BufferPtr += Skip;
|
||||
sub cx,ax ;BufferLength -= Skip;
|
||||
ja QuickSearchLoop ;continue if any buffer left
|
||||
jmp short NoMatch
|
||||
; Return a pointer to the start of the buffer (for 0-length pattern).
|
||||
align 2
|
||||
InstantMatch:
|
||||
mov ax,[bp+BufferPtr]
|
||||
mov ax,[bp+BufferPtr]
|
||||
jmp short Done
|
||||
; Compare the pattern and the buffer location, searching from high
|
||||
; memory toward low (right to left).
|
||||
align 2
|
||||
FullCompare:
|
||||
mov [bp+BufferPtr],di ;save the current state of
|
||||
mov [bp+BufferLength],cx ; the search
|
||||
mov cx,[bp+PatternLength] ;# of bytes yet to compare
|
||||
mov [bp+BufferPtr],di ;save the current state of
|
||||
mov [bp+BufferLength],cx ; the search
|
||||
mov cx,[bp+PatternLength] ;# of bytes yet to compare
|
||||
jcxz Match ;done if only one character
|
||||
mov si,[bp+PatternPtr] ;point to next-to-rightmost bytes
|
||||
mov si,[bp+PatternPtr] ;point to next-to-rightmost bytes
|
||||
dec di ; of buffer location and pattern
|
||||
repz cmpsb ;compare the rest of the pattern
|
||||
jz Match ;that’s it; we’ve found a match
|
||||
; It’s a mismatch; let’s see what we can learn from it.
|
||||
jz Match ;that’s it; we’ve found a match
|
||||
; It’s a mismatch; let’s see what we can learn from it.
|
||||
inc di ;compensate for 1-byte overrun of REPZ CMPSB;
|
||||
; point to mismatch location in buffer
|
||||
; # of bytes that did match.
|
||||
mov si,[bp+BufferPtr]
|
||||
mov si,[bp+BufferPtr]
|
||||
sub si,di
|
||||
; If, based on the mismatch character, we can’t even skip ahead as far
|
||||
; If, based on the mismatch character, we can’t even skip ahead as far
|
||||
; as where we started this particular comparison, then just advance by
|
||||
; 1 to the next potential match; otherwise, skip ahead from this
|
||||
; comparison location by the skip distance for the mismatch character,
|
||||
|
|
@ -166,18 +166,18 @@ FullCompare:
|
|||
add bx,bx ;prepare for word look-up
|
||||
add bx,sp ;SP points to SkipTable
|
||||
mov cx,[bx] ;get the skip value for this mismatch
|
||||
mov ax,1 ;assume we’ll just advance to the next
|
||||
mov ax,1 ;assume we’ll just advance to the next
|
||||
; potential match location
|
||||
sub cx,si ;is the skip far enough to be worth taking?
|
||||
jna MoveAhead ;no, go with the default advance of 1
|
||||
mov ax,cx ;yes; this is the distance to skip ahead from
|
||||
; the last potential match location checked
|
||||
MoveAhead:
|
||||
; Skip ahead and perform the next comparison, if there’s any buffer
|
||||
; Skip ahead and perform the next comparison, if there’s any buffer
|
||||
; left to check.
|
||||
mov di,[bp+BufferPtr]
|
||||
add di,ax ;BufferPtr += Skip;
|
||||
mov cx,[bp+BufferLength]
|
||||
mov di,[bp+BufferPtr]
|
||||
add di,ax ;BufferPtr += Skip;
|
||||
mov cx,[bp+BufferLength]
|
||||
sub cx,ax ;BufferLength -= Skip;
|
||||
ja SearchLoop ;continue if any buffer left
|
||||
; Return a NULL pointer for no match.
|
||||
|
|
@ -188,14 +188,14 @@ NoMatch:
|
|||
; Return start of match in buffer (BufferPtr - (PatternLength - 1)).
|
||||
align 2
|
||||
Match:
|
||||
mov ax,[bp+BufferPtr]
|
||||
sub ax,[bp+PatternLength]
|
||||
mov ax,[bp+BufferPtr]
|
||||
sub ax,[bp+PatternLength]
|
||||
Done:
|
||||
cld ;restore default direction flag
|
||||
add sp,256*2 ;deallocate space for SkipTable
|
||||
pop di ;restore caller’s register variables
|
||||
pop di ;restore caller’s register variables
|
||||
pop si
|
||||
pop bp ;restore caller’s stack frame
|
||||
pop bp ;restore caller’s stack frame
|
||||
ret
|
||||
_FindString endp
|
||||
end
|
||||
|
|
|
|||
68
14-06.html
68
14-06.html
File diff suppressed because one or more lines are too long
20
15-01.html
20
15-01.html
File diff suppressed because one or more lines are too long
22
15-02.html
22
15-02.html
File diff suppressed because one or more lines are too long
18
15-03.html
18
15-03.html
File diff suppressed because one or more lines are too long
52
15-04.html
52
15-04.html
File diff suppressed because one or more lines are too long
44
16-01.html
44
16-01.html
File diff suppressed because one or more lines are too long
62
16-02.html
62
16-02.html
File diff suppressed because one or more lines are too long
40
16-03.html
40
16-03.html
File diff suppressed because one or more lines are too long
28
16-04.html
28
16-04.html
File diff suppressed because one or more lines are too long
30
16-05.html
30
16-05.html
|
|
@ -106,7 +106,7 @@
|
|||
COMMENT $
|
||||
|
||||
How it works
|
||||
——————
|
||||
——————
|
||||
The idea is to go through the buffer fetching each letter-pair (words
|
||||
rather than bytes). The carry flag indicates whether we are
|
||||
currently in a (text) word or not. The letter-pair fetched from the
|
||||
|
|
@ -127,7 +127,7 @@ repeated. Finally, the carry flag is saved to indicate the final
|
|||
in-a-word/not-in-a-word status. The count register is masked to
|
||||
remove the high bit and the count of words remains in the count
|
||||
register.
|
||||
Sound complicated? You’re right! But it’s fast!
|
||||
Sound complicated? You’re right! But it’s fast!
|
||||
|
||||
The beauty of this method is that no jumps are required, the
|
||||
operations are fast, it requires only one table and the process can
|
||||
|
|
@ -139,14 +139,14 @@ jumping.
|
|||
.code
|
||||
|
||||
Test1 macro x,y ;9 or 10 bytes
|
||||
Addr&x: mov di,[bp+y] ;3 or 4 bytes
|
||||
Addr&x: mov di,[bp+y] ;3 or 4 bytes
|
||||
adc di,di
|
||||
or ax,si
|
||||
add al,[di]
|
||||
endm
|
||||
|
||||
Test2 macro x,y ;7 or 8 bytes
|
||||
Addr&x: mov di,[bp+y] ;3 or 4 bytes
|
||||
Addr&x: mov di,[bp+y] ;3 or 4 bytes
|
||||
adc di,di
|
||||
add ah,[di]
|
||||
endm
|
||||
|
|
@ -165,18 +165,18 @@ jumping.
|
|||
push di
|
||||
|
||||
xor cx,cx
|
||||
mov si,[bp+Buffer] ;si = text buffer
|
||||
mov ax,[bp+BufferLength] ;dx = length in bytes
|
||||
mov si,[bp+Buffer] ;si = text buffer
|
||||
mov ax,[bp+BufferLength] ;dx = length in bytes
|
||||
shr ax,1 ;dx = length in words
|
||||
jnz NormalBuf
|
||||
OneByteBuf:
|
||||
mov ax,seg WordTable
|
||||
mov es,ax
|
||||
|
||||
mov di,[bp+CharFlag]
|
||||
mov di,[bp+CharFlag]
|
||||
mov bh,[di] ;bh = old CharFlag
|
||||
mov bl,[si] ;bl = character
|
||||
add bh,‘A’-1 ;make bh into character
|
||||
add bh,‘A’-1 ;make bh into character
|
||||
add bx,bx ;prepare to index
|
||||
mov al,es:[bx]
|
||||
cbw ;get hi bit in ah (then bh)
|
||||
|
|
@ -203,7 +203,7 @@ jumping.
|
|||
mov di,LoopEntry[bx] ;...address in di
|
||||
xchg dx,ax ;dx is the loop counter
|
||||
xor cx,cx ;total word count
|
||||
mov bx,[bp+CharFlag]
|
||||
mov bx,[bp+CharFlag]
|
||||
mov bl,[bx] ;bl = old CharFlag
|
||||
mov bp,seg WordTable
|
||||
mov ds,bp
|
||||
|
|
@ -218,12 +218,12 @@ jumping.
|
|||
n = 0
|
||||
rept Scan/2
|
||||
Test1 %n,%n*2
|
||||
Test2 %n+1,%n*2+2
|
||||
n = n+2
|
||||
Test2 %n+1,%n*2+2
|
||||
n = n+2
|
||||
endm
|
||||
EndCount:
|
||||
sbb bx,bx ;save carry
|
||||
if Scan ge 128 ;because al+ah may equal 128!
|
||||
if Scan ge 128 ;because al+ah may equal 128!
|
||||
or ax,si
|
||||
add al,ah
|
||||
mov ah,0
|
||||
|
|
@ -250,11 +250,11 @@ jumping.
|
|||
pop ds
|
||||
pop bp ;(1)
|
||||
CleanUp:
|
||||
mov si,[bp+WordCount]
|
||||
mov si,[bp+WordCount]
|
||||
add [si],cx
|
||||
adc word ptr [si+2],0
|
||||
adc word ptr [si+2],0
|
||||
and bh,1 ;save only the carry flag
|
||||
mov si,[bp+CharFlag]
|
||||
mov si,[bp+CharFlag]
|
||||
mov [si],bh
|
||||
pop di
|
||||
pop si
|
||||
|
|
|
|||
12
16-06.html
12
16-06.html
File diff suppressed because one or more lines are too long
20
16-07.html
20
16-07.html
File diff suppressed because one or more lines are too long
46
16-08.html
46
16-08.html
File diff suppressed because one or more lines are too long
16
17-01.html
16
17-01.html
File diff suppressed because one or more lines are too long
60
17-02.html
60
17-02.html
|
|
@ -39,9 +39,9 @@
|
|||
<P><B>LISTING 17.1 L17-1.CPP</B></P>
|
||||
<!-- CODE //-->
|
||||
<PRE>
|
||||
/* C++ Game of Life implementation for any mode for which mode set
|
||||
/* C++ Game of Life implementation for any mode for which mode set
|
||||
and draw pixel functions can be provided.
|
||||
Tested with Borland C++ in the small model. */
|
||||
Tested with Borland C++ in the small model. */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream.h>
|
||||
|
|
@ -100,30 +100,30 @@ void main()
|
|||
cellmap next_map(cellmap_height, cellmap_width);
|
||||
|
||||
// Get the seed; seed randomly if 0 entered
|
||||
cout << “Seed (0 for random seed): ”;
|
||||
cout << “Seed (0 for random seed): ”;
|
||||
cin >> seed;
|
||||
if (seed == 0) seed = (unsigned) time(NULL);
|
||||
|
||||
// Randomly initialize the initial cell map
|
||||
cout << “Initializing...”;
|
||||
cout << “Initializing...”;
|
||||
srand(seed);
|
||||
init_length = (cellmap_height * cellmap_width) / 2;
|
||||
do {
|
||||
x = random(cellmap_width);
|
||||
y = random(cellmap_height);
|
||||
next_map.set_cell(x, y);
|
||||
} while (—init_length);
|
||||
} while (—init_length);
|
||||
current_map.copy_cells(next_map); // put init map in current_map
|
||||
|
||||
enter_display_mode();
|
||||
|
||||
// Keep recalculating and redisplaying generations until a key
|
||||
// is pressed
|
||||
show_text(0, MSG_LINE, “Generation: ”);
|
||||
show_text(0, MSG_LINE, “Generation: ”);
|
||||
start_bios_time = _bios_timeofday(_TIME_GETCLOCK, &bios_time);
|
||||
do {
|
||||
generation++;
|
||||
sprintf(gen_text, “%10lu”, generation);
|
||||
generation++;
|
||||
sprintf(gen_text, “%10lu”, generation);
|
||||
show_text(1, GENERATION_LINE, gen_text);
|
||||
// Recalculate and draw the next generation
|
||||
current_map.next_generation(next_map);
|
||||
|
|
@ -139,15 +139,15 @@ void main()
|
|||
} while (!kbhit());
|
||||
getch(); // clear keypress
|
||||
exit_display_mode();
|
||||
cout << “Total generations: ” << generation << “\nSeed: ” <<
|
||||
seed << “\n”;
|
||||
cout << “Total generations: ” << generation << “\nSeed: ” <<
|
||||
seed << “\n”;
|
||||
}
|
||||
|
||||
/* cellmap constructor. */
|
||||
cellmap::cellmap(unsigned int h, unsigned int w)
|
||||
{
|
||||
width = w;
|
||||
width_in_bytes = (w + 7) / 8;
|
||||
width_in_bytes = (w + 7) / 8;
|
||||
height = h;
|
||||
length_in_bytes = width_in_bytes * h;
|
||||
cells = new unsigned char[length_in_bytes]; // cell storage
|
||||
|
|
@ -160,7 +160,7 @@ cellmap::~cellmap(void)
|
|||
delete[] cells;
|
||||
}
|
||||
|
||||
/* Copies one cellmap’s cells to another cellmap. Both cellmaps are
|
||||
/* Copies one cellmap’s cells to another cellmap. Both cellmaps are
|
||||
assumed to be the same size. */
|
||||
void cellmap::copy_cells(cellmap &sourcemap)
|
||||
{
|
||||
|
|
@ -171,7 +171,7 @@ void cellmap::copy_cells(cellmap &sourcemap)
|
|||
void cellmap::set_cell(unsigned int x, unsigned int y)
|
||||
{
|
||||
unsigned char *cell_ptr =
|
||||
cells + (y * width_in_bytes) + (x / 8);
|
||||
cells + (y * width_in_bytes) + (x / 8);
|
||||
|
||||
*(cell_ptr) |= 0x80 >> (x & 0x07);
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ void cellmap::set_cell(unsigned int x, unsigned int y)
|
|||
void cellmap::clear_cell(unsigned int x, unsigned int y)
|
||||
{
|
||||
unsigned char *cell_ptr =
|
||||
cells + (y * width_in_bytes) + (x / 8);
|
||||
cells + (y * width_in_bytes) + (x / 8);
|
||||
|
||||
*(cell_ptr) &= ~(0x80 >> (x & 0x07));
|
||||
}
|
||||
|
|
@ -192,15 +192,15 @@ int cellmap::cell_state(int x, int y)
|
|||
unsigned char *cell_ptr;
|
||||
|
||||
#if WRAP_EDGES
|
||||
while (x < 0) x += width; // wrap, if necessary
|
||||
while (x < 0) x += width; // wrap, if necessary
|
||||
while (x >= width) x -= width;
|
||||
while (y < 0) y += height;
|
||||
while (y < 0) y += height;
|
||||
while (y >= height) y -= height;
|
||||
#else
|
||||
if ((x < 0) || (x >= width) || (y < 0) || (y >= height))
|
||||
return 0; // return 0 for off edges if no wrapping
|
||||
#endif
|
||||
cell_ptr = cells + (y * width_in_bytes) + (x / 8);
|
||||
cell_ptr = cells + (y * width_in_bytes) + (x / 8);
|
||||
return (*cell_ptr & (0x80 >> (x & 0x07))) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
|
@ -210,13 +210,13 @@ void cellmap::next_generation(cellmap& next_map)
|
|||
{
|
||||
unsigned int x, y, neighbor_count;
|
||||
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
// Figure out how many neighbors this cell has
|
||||
neighbor_count = cell_state(x-1, y-1) + cell_state(x, y-1) +
|
||||
cell_state(x+1, y-1) + cell_state(x-1, y) +
|
||||
cell_state(x+1, y) + cell_state(x-1, y+1) +
|
||||
cell_state(x, y+1) + cell_state(x+1, y+1);
|
||||
neighbor_count = cell_state(x-1, y-1) + cell_state(x, y-1) +
|
||||
cell_state(x+1, y-1) + cell_state(x-1, y) +
|
||||
cell_state(x+1, y) + cell_state(x-1, y+1) +
|
||||
cell_state(x, y+1) + cell_state(x+1, y+1);
|
||||
if (cell_state(x, y) == 1) {
|
||||
// The cell is on; does it stay on?
|
||||
if ((neighbor_count != 2) && (neighbor_count != 3)) {
|
||||
|
|
@ -239,7 +239,7 @@ void cellmap::next_generation(cellmap& next_map)
|
|||
<!-- CODE //-->
|
||||
<PRE>
|
||||
/* VGA mode 13h functions for Game of Life.
|
||||
Tested with Borland C++. */
|
||||
Tested with Borland C++. */
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include <dos.h>
|
||||
|
|
@ -260,12 +260,12 @@ void draw_pixel(unsigned int x, unsigned int y, unsigned int color)
|
|||
|
||||
FP_SEG(screen_ptr) = SCREEN_SEGMENT;
|
||||
FP_OFF(screen_ptr) =
|
||||
y * magnifier * SCREEN_WIDTH_IN_BYTES + x * magnifier;
|
||||
for (i=0; i<magnifier; i++) {
|
||||
for (j=0; j<magnifier; j++) {
|
||||
*(screen_ptr+j) = color;
|
||||
y * magnifier * SCREEN_WIDTH_IN_BYTES + x * magnifier;
|
||||
for (i=0; i<magnifier; i++) {
|
||||
for (j=0; j<magnifier; j++) {
|
||||
*(screen_ptr+j) = color;
|
||||
}
|
||||
screen_ptr += SCREEN_WIDTH_IN_BYTES;
|
||||
screen_ptr += SCREEN_WIDTH_IN_BYTES;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ void exit_display_mode()
|
|||
screen. */
|
||||
void show_text(int x, int y, char *text)
|
||||
{
|
||||
gotoxy(TEXT_X_OFFSET + x, y);
|
||||
gotoxy(TEXT_X_OFFSET + x, y);
|
||||
puts(text);
|
||||
}
|
||||
</PRE>
|
||||
|
|
|
|||
20
17-03.html
20
17-03.html
File diff suppressed because one or more lines are too long
60
17-04.html
60
17-04.html
File diff suppressed because one or more lines are too long
52
17-05.html
52
17-05.html
File diff suppressed because one or more lines are too long
20
17-06.html
20
17-06.html
File diff suppressed because one or more lines are too long
74
17-07.html
74
17-07.html
|
|
@ -39,12 +39,12 @@
|
|||
<P><B>LISTING 17.5 L17-5.CPP</B></P>
|
||||
<!-- CODE //-->
|
||||
<PRE>
|
||||
/* C++ Game of Life implementation for any mode for which mode set
|
||||
/* C++ Game of Life implementation for any mode for which mode set
|
||||
and draw pixel functions can be provided. The cellmap stores the
|
||||
neighbor count for each cell as well as the state of each cell;
|
||||
this allows very fast next-state determination. Edges always wrap
|
||||
in this implementation.
|
||||
Tested with Borland C++. To run, link with Listing 17.2
|
||||
Tested with Borland C++. To run, link with Listing 17.2
|
||||
in the large model. */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -111,11 +111,11 @@ void main()
|
|||
|
||||
// Keep recalculating and redisplaying generations until any key
|
||||
// is pressed
|
||||
show_text(0, MSG_LINE, “Generation: ”);
|
||||
show_text(0, MSG_LINE, “Generation: ”);
|
||||
start_bios_time = _bios_timeofday(_TIME_GETCLOCK, &bios_time);
|
||||
do {
|
||||
generation++;
|
||||
sprintf(gen_text, “%10lu”, generation);
|
||||
generation++;
|
||||
sprintf(gen_text, “%10lu”, generation);
|
||||
show_text(1, GENERATION_LINE, gen_text);
|
||||
// Recalculate and draw the next generation
|
||||
current_map.next_generation();
|
||||
|
|
@ -130,8 +130,8 @@ void main()
|
|||
|
||||
getch(); // clear keypress
|
||||
exit_display_mode();
|
||||
cout << “Total generations: ” << generation << “\nSeed: ” <<
|
||||
seed << “\n”;
|
||||
cout << “Total generations: ” << generation << “\nSeed: ” <<
|
||||
seed << “\n”;
|
||||
}
|
||||
|
||||
/* cellmap constructor. */
|
||||
|
|
@ -143,7 +143,7 @@ cellmap::cellmap(unsigned int h, unsigned int w)
|
|||
cells = new unsigned char[length_in_bytes]; // cell storage
|
||||
temp_cells = new unsigned char[length_in_bytes]; // temp cell storage
|
||||
if ( (cells == NULL) || (temp_cells == NULL) ) {
|
||||
printf(“Out of memory\n”);
|
||||
printf(“Out of memory\n”);
|
||||
exit(1);
|
||||
}
|
||||
memset(cells, 0, length_in_bytes); // clear all cells, to start
|
||||
|
|
@ -162,7 +162,7 @@ void cellmap::set_cell(unsigned int x, unsigned int y)
|
|||
{
|
||||
unsigned int w = width, h = height;
|
||||
int xoleft, xoright, yoabove, yobelow;
|
||||
unsigned char *cell_ptr = cells + (y * w) + x;
|
||||
unsigned char *cell_ptr = cells + (y * w) + x;
|
||||
|
||||
// Calculate the offsets to the eight neighboring cells,
|
||||
// accounting for wrapping around at the edges of the cell map
|
||||
|
|
@ -184,14 +184,14 @@ void cellmap::set_cell(unsigned int x, unsigned int y)
|
|||
yobelow = w;
|
||||
|
||||
*(cell_ptr) |= 0x01;
|
||||
*(cell_ptr + yoabove + xoleft) += 2;
|
||||
*(cell_ptr + yoabove) += 2;
|
||||
*(cell_ptr + yoabove + xoright) += 2;
|
||||
*(cell_ptr + xoleft) += 2;
|
||||
*(cell_ptr + xoright) += 2;
|
||||
*(cell_ptr + yobelow + xoleft) += 2;
|
||||
*(cell_ptr + yobelow) += 2;
|
||||
*(cell_ptr + yobelow + xoright) += 2;
|
||||
*(cell_ptr + yoabove + xoleft) += 2;
|
||||
*(cell_ptr + yoabove) += 2;
|
||||
*(cell_ptr + yoabove + xoright) += 2;
|
||||
*(cell_ptr + xoleft) += 2;
|
||||
*(cell_ptr + xoright) += 2;
|
||||
*(cell_ptr + yobelow + xoleft) += 2;
|
||||
*(cell_ptr + yobelow) += 2;
|
||||
*(cell_ptr + yobelow + xoright) += 2;
|
||||
}
|
||||
|
||||
/* Turns an on-cell off, decrementing the on-neighbor count for the
|
||||
|
|
@ -200,7 +200,7 @@ void cellmap::clear_cell(unsigned int x, unsigned int y)
|
|||
{
|
||||
unsigned int w = width, h = height;
|
||||
int xoleft, xoright, yoabove, yobelow;
|
||||
unsigned char *cell_ptr = cells + (y * w) + x;
|
||||
unsigned char *cell_ptr = cells + (y * w) + x;
|
||||
|
||||
// Calculate the offsets to the eight neighboring cells,
|
||||
// accounting for wrapping around at the edges of the cell map
|
||||
|
|
@ -222,14 +222,14 @@ void cellmap::clear_cell(unsigned int x, unsigned int y)
|
|||
yobelow = w;
|
||||
|
||||
*(cell_ptr) &= ~0x01;
|
||||
*(cell_ptr + yoabove + xoleft) -= 2;
|
||||
*(cell_ptr + yoabove ) -= 2;
|
||||
*(cell_ptr + yoabove + xoright) -= 2;
|
||||
*(cell_ptr + xoleft) -= 2;
|
||||
*(cell_ptr + xoright) -= 2;
|
||||
*(cell_ptr + yobelow + xoleft) -= 2;
|
||||
*(cell_ptr + yobelow) -= 2;
|
||||
*(cell_ptr + yobelow + xoright) -= 2;
|
||||
*(cell_ptr + yoabove + xoleft) -= 2;
|
||||
*(cell_ptr + yoabove ) -= 2;
|
||||
*(cell_ptr + yoabove + xoright) -= 2;
|
||||
*(cell_ptr + xoleft) -= 2;
|
||||
*(cell_ptr + xoright) -= 2;
|
||||
*(cell_ptr + yobelow + xoleft) -= 2;
|
||||
*(cell_ptr + yobelow) -= 2;
|
||||
*(cell_ptr + yobelow + xoright) -= 2;
|
||||
}
|
||||
|
||||
/* Returns cell state (1=on or 0=off). */
|
||||
|
|
@ -237,7 +237,7 @@ int cellmap::cell_state(int x, int y)
|
|||
{
|
||||
unsigned char *cell_ptr;
|
||||
|
||||
cell_ptr = cells + (y * width) + x;
|
||||
cell_ptr = cells + (y * width) + x;
|
||||
return *cell_ptr & 0x01;
|
||||
}
|
||||
|
||||
|
|
@ -254,21 +254,21 @@ void cellmap::next_generation()
|
|||
|
||||
// Process all cells in the current cell map
|
||||
cell_ptr = temp_cells; // first cell in cell map
|
||||
for (y=0; y<h; y++) { // repeat for each row of cells
|
||||
for (y=0; y<h; y++) { // repeat for each row of cells
|
||||
// Process all cells in the current row of the cell map
|
||||
x = 0;
|
||||
do { // repeat for each cell in row
|
||||
// Zip quickly through as many off-cells with no
|
||||
// neighbors as possible
|
||||
while (*cell_ptr == 0) {
|
||||
cell_ptr++; // advance to the next cell
|
||||
if (++x >= w) goto RowDone;
|
||||
cell_ptr++; // advance to the next cell
|
||||
if (++x >= w) goto RowDone;
|
||||
}
|
||||
// Found a cell that’s either on or has on-neighbors,
|
||||
// Found a cell that’s either on or has on-neighbors,
|
||||
// so see if its state needs to be changed
|
||||
count = *cell_ptr >> 1; // # of neighboring on-cells
|
||||
if (*cell_ptr & 0x01) {
|
||||
// Cell is on; turn it off if it doesn’t have
|
||||
// Cell is on; turn it off if it doesn’t have
|
||||
// 2 or 3 neighbors
|
||||
if ((count != 2) && (count != 3)) {
|
||||
clear_cell(x, y);
|
||||
|
|
@ -282,8 +282,8 @@ void cellmap::next_generation()
|
|||
}
|
||||
}
|
||||
// Advance to the next cell
|
||||
cell_ptr++; // advance to the next cell byte
|
||||
} while (++x < w);
|
||||
cell_ptr++; // advance to the next cell byte
|
||||
} while (++x < w);
|
||||
RowDone:
|
||||
}
|
||||
}
|
||||
|
|
@ -294,14 +294,14 @@ void cellmap::init()
|
|||
unsigned int x, y, init_length;
|
||||
|
||||
// Get the seed; seed randomly if 0 entered
|
||||
cout << “Seed (0 for random seed): ”;
|
||||
cout << “Seed (0 for random seed): ”;
|
||||
cin >> seed;
|
||||
if (seed == 0) seed = (unsigned) time(NULL);
|
||||
|
||||
// Randomly initialize the initial cell map to 50% on-pixels
|
||||
// (actually generally fewer, because some coordinates will be
|
||||
// randomly selected more than once)
|
||||
cout << “Initializing...”;
|
||||
cout << “Initializing...”;
|
||||
srand(seed);
|
||||
init_length = (height * width) / 2;
|
||||
do {
|
||||
|
|
@ -310,7 +310,7 @@ void cellmap::init()
|
|||
if (cell_state(x, y) == 0) {
|
||||
set_cell(x, y);
|
||||
}
|
||||
} while (—init_length);
|
||||
} while (—init_length);
|
||||
}
|
||||
</PRE>
|
||||
<!-- END CODE //-->
|
||||
|
|
|
|||
22
17-08.html
22
17-08.html
File diff suppressed because one or more lines are too long
18
18-01.html
18
18-01.html
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue