SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 1 Wed Nov 10 2004 27 SUBTITLE CLEAR -- find screen size and initialize board to DEAD 109 SUBTITLE SETUP -- set the initial configuration 209 SUBTITLE SHOWIT -- display the board 300 SUBTITLE UPDATE -- update one board generation 378 SUBTITLE SHIFT -- finish update by shifting cells over 457 SUBTITLE MAIN -- main program for game of life SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 2 Wed Nov 10 2004 1 TITLE MP4 main program by Douglas Jones 2 ; ---------------------------------- 3 ; Conway's game of Life, generalized 4 ; Started, October 25, 2004 5 ; Finished, October 29, 2004 as MP3 6 ; Started, November 9, 2004 7 ; 8 ; Note: the main program is at the end, subroutines are 9 ; listed in a define-before use order. 10 ; 11 ; Also note, the update rules of Life do not apply to the 12 ; outermost rows and columns of the game board in this version; 13 ; these rows keep their original values forever. 14 ; ---------------------------------- 15 16 USE "hawk.macs" 17 USE "monitor.h" +000000:+00000000 18 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 19 USE "life.h" ; declarations on which game depends +000030:+00000000 20 21 EXT INIT ; initialization vector used by SETUP +000034:+00000000 22 PINIT: W INIT 23 EXT RULES ; rules of the game called by UPDATE +000038:+00000000 24 PRULES: W RULES 25 26 ; ---------------------------------- SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 3 CLEAR -- find screen size Wed Nov 10 2004 27 SUBTITLE CLEAR -- find screen size and initialize board to DEAD 28 29 ; Initialization uses two nested loops visiting entire board by rows, 30 ; bottom to top because this simplifies the code just a bit. 31 ; ---------------------------------- 32 ; activation record structure 33 34 RA = 0 35 ARSIZE = 4 36 37 ; receiving sequence assumptions 38 CLEAR: 39 ; expects R1 = return address 40 ; uses R3-R7 41 ; returns nothing 42 STORES R1,R2 +00003C: F1A2 43 ADDI R2,ARSIZE +00003E: F262 0004 44 45 ; initialize display and get board dimensions 46 LOAD R1,PDSPINI +000042: F150 FFBE 47 JSRS R1,R1 ; initialize the display +000046: F1B1 48 ; returns R3 = columns 49 ; returns R4 = rows 50 51 ; check that board dimensions are within bounds 52 CMPI R3,WIDTH ; if columns > width +000048: F063 FF80 53 BLE CLWIDX +00004C: 0602 54 LIL R3,WIDTH ; columns = width +00004E: E300 0080 55 CLWIDX: 56 CMPI R4,HEIGHT ; if rows > height +000052: F064 FFC0 57 BLE CLHEIX +000056: 0602 58 LIL R3,HEIGHT ; rows = height +000058: E300 0040 59 CLHEIX: 60 61 ; add gutter around the edge 62 ADDSI R3,GUTTER<<1 ; rows = rows + 2*gutter +00005C: 13C2 63 ADDSI R4,GUTTER<<1 ; columns = columns + 2*gutter +00005E: 14C2 64 65 ; save board dimensions 66 LOAD R5,PBINFO +000060: F550 FFCC 67 STORE R3,R5,BWIDTH ; bwidth = columns +000064: F325 0000 68 STORE R4,R5,BHEIGHT ; bheight = rows +000068: F425 0004 69 70 ; clear the board 71 CLOLOOP: ; while (true) do 72 ; here, R1 is free 73 ; here, R3 is free 74 ; here, R4 is the row number 75 ; here, R5 points to the info block 76 ADDSI R4,-1 ; rows = rows - 1 +00006C: 14CF 77 BLT CLOLQT ; if (rows < 0) break +00006E: 050D 78 79 LEA R6,R5,BBOARD +000070: F675 0008 80 MOVESL R7,R4,LOG2WID +000074: B747 81 ADD R6,R6,R7 ; pcell = bboard + (rows * width) SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 4 CLEAR -- find screen size Wed Nov 10 2004 +000076: 3667 82 83 LOAD R3,R5,BWIDTH ; columns = width +000078: F355 0000 84 CLILOOP: ; while (true) do { 85 ; here, R1 is free 86 ; here, R3 is the column number 87 ; here, R4 is the row number 88 ; here, R5 points to the info block 89 ; here, R6 points to the current cell 90 ; here, R7 is free 91 ADDSI R4,-1 ; columns = columns - 1 +00007C: 14CF 92 BLT CLILQT ; if (columns < 0) break +00007E: 05F6 93 94 LOADS R1,R6 +000080: F1D6 95 STUFFB R1,R0,R6 +000082: 7106 96 STORES R1,R6 ; *pcell = 0 +000084: F1A6 97 ADDSI R6,1 ; pcell++ +000086: 16C1 98 99 BR CLILOOP +000088: 00F9 100 101 CLILQT = CLOLOOP ; } -- equiv to CLIQT: BR BLOLOOP 102 CLOLQT: ; } 103 104 ADDI R2,-ARSIZE +00008A: F262 FFFC 105 LOADS R1,R2 +00008E: F1D2 106 JUMPS R1 ; return +000090: F0B1 107 108 ; ---------------------------------- SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 5 SETUP -- set the initial c Wed Nov 10 2004 109 SUBTITLE SETUP -- set the initial configuration 110 111 ; This walks through the setup vector, reading successive 112 ; coordinate pairs and setting the indicated cell to alive, 113 ; until it finds an out-of-bounds value. 114 115 ; The sectup vector is externally provided, with the name INIT 116 ; it consists of deltaX,deltaY pairs, with 0,0 marking the end; 117 ; 0,0 is permitted as the first element, where it is not the 118 ; end. All deltas are measured from the previous coordinate, 119 ; where the starting point is the board center 120 ; ---------------------------------- 121 ; activation record structure 122 RA = 0 123 R8SV = 4 124 R9SV = 8 125 R10SV = 12 126 ARSIZE = 16 127 ; receiving sequence assumptions 128 SETUP: 129 ; expects R1 = return address 130 ; uses R3-R7 131 ; saves R8-R10 132 STORES R1,R2 +000092: F1A2 133 STORE R8,R2,R8SV +000094: F822 0004 134 STORE R9,R2,R9SV +000098: F922 0008 135 STORE R10,R2,R10SV +00009C: FA22 000C 136 137 ; get board information 138 LOAD R3,PBINFO +0000A0: F350 FF8C 139 LOAD R4,R3,BHEIGHT ; rows = bheight +0000A4: F453 0004 140 LOAD R5,R3,BWIDTH ; columns = bwidth +0000A8: F553 0000 141 LEA R6,R3,BBOARD ; pboard = bboard +0000AC: F673 0008 142 LOAD R7,PINIT ; ptr = setvec +0000B0: F750 FF80 143 LIS R8,LIVE +0000B4: D801 144 145 ; find board center 146 MOVE R9,R5 +0000B6: F9F5 147 SR R9,1 ; x = columns / 2 +0000B8: 9901 148 MOVE R10,R4 +0000BA: FAF4 149 SR R10,1 ; y = rows / 2 +0000BC: 9A01 150 151 ; get first set of deltas 152 LOADS R1,R7 +0000BE: F1D7 153 EXTB R1,R1,R7 ; deltax = *ptr +0000C0: 5117 154 ADDSI R7,1 ; ptr++ +0000C2: 17C1 155 LOADS R3,R7 +0000C4: F3D7 156 EXTB R3,R3,R7 ; deltay = *ptr +0000C6: 5337 157 ADDSI R7,1 ; ptr++ +0000C8: 17C1 158 159 SETLOOP: ; while (true) { 160 ; here R1 is deltax 161 ; here R3 is deltay 162 ; here R4 is rows 163 ; here R5 is columns SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 6 SETUP -- set the initial c Wed Nov 10 2004 164 ; here R6 is pboard 165 ; here R7 is setvec 166 ; here R8 is live 167 ; here R9 is x 168 ; here R10 is y 169 170 SXT R1,8 +0000CA: 11E8 171 ADD R9,R9,R1 ; x = x + deltax (sign extended) +0000CC: 3991 172 SXT R3,8 +0000CE: 13E8 173 ADD R10,R10,R3 ; y = y + deltay (sign extended) +0000D0: 3AA3 174 ; don't need deltas anymore 175 176 CMP R9,R5 +0000D2: 2095 177 BGTU SETLQT ; if (x > columns) exit +0000D4: 0F12 178 CMP R10,R4 +0000D6: 20A4 179 BGTU SETLQT ; if (y > rows) exit +0000D8: 0F10 180 181 MOVESL R3,R10,LOG2WID +0000DA: B3A7 182 ADD R3,R6,R3 +0000DC: 3363 183 ADD R3,R3,R9 ; pcell = pboard + (width*y) + x +0000DE: 3339 184 185 LOADS R1,R3 +0000E0: F1D3 186 STUFFB R1,R8,R3 +0000E2: 7183 187 STORES R1,R3 ; *pcell = alive +0000E4: F1A3 188 189 LOADS R1,R7 +0000E6: F1D7 190 EXTB R1,R1,R7 ; deltax = *ptr +0000E8: 5117 191 ADDSI R7,1 ; ptr++ +0000EA: 17C1 192 LOADS R3,R7 +0000EC: F3D7 193 EXTB R3,R3,R7 ; deltay = *ptr +0000EE: 5337 194 ADDSI R7,1 ; ptr++ +0000F0: 17C1 195 196 TESTR R1 +0000F2: F0E1 197 BZR SETLOOP +0000F4: 0AEA 198 TESTR R3 +0000F6: F0E3 199 BZR SETLOOP ; if ((deltax == 0)&&(deltay == 0)) break +0000F8: 0AE8 200 SETLQT: ; } 201 202 LOAD R8,R2,R8SV +0000FA: F852 0004 203 LOAD R9,R2,R9SV +0000FE: F952 0008 204 LOAD R10,R2,R10SV +000102: FA52 000C 205 LOADS R1,R2 +000106: F1D2 206 JUMPS R1 ; return +000108: F0B1 207 208 ; ---------------------------------- SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 7 SHOWIT -- display the boar Wed Nov 10 2004 209 SUBTITLE SHOWIT -- display the board 210 211 ; Displays the board, by rows, bottom to top because this is a 212 ; bit simpler. Within each row, the display is left to right 213 ; so that the screen coordinates need only be set once. 214 ; ---------------------------------- 215 ; activation record structure 216 217 RA = 0 218 R8SV = 4 219 R9SV = 8 220 R10SV = 12 221 R11SV = 16 222 R12SV = 20 223 ARSIZE = 24 224 225 ; receiving sequence assumptions 226 SHOWIT: 227 ; expects R1 = return address 228 ; uses R3-R7 229 ; saves and restores R8-10 230 ; returns nothing 231 STORES R1,R2 +00010A: F1A2 232 STORE R8,R2,R8SV +00010C: F822 0004 233 STORE R9,R2,R9SV +000110: F922 0008 234 STORE R10,R2,R10SV +000114: FA22 000C 235 STORE R11,R2,R11SV +000118: FB22 0010 236 STORE R12,R2,R12SV +00011C: FC22 0014 237 ADDI R2,ARSIZE +000120: F262 0018 238 239 ; get board information 240 LOAD R8,PBINFO +000124: F850 FF08 241 LOAD R9,R8,BHEIGHT +000128: F958 0004 242 ADDSI R9,-GUTTER ; rows = bheight - gutter +00012C: 19CF 243 SHOOLP: ; while (true) { 244 ; here, R8 points to info block 245 ; here, R9 is the row number 246 ADDSI R9,-1 ; rows = rows - 1 +00012E: 19CF 247 CMPI R9,GUTTER +000130: F069 FFFF 248 BLT SHOOLQ ; if (rows < gutter) break +000134: 051D 249 250 LIS R3,0 +000136: D300 251 MOVE R4,R9 +000138: F4F9 252 ADDSI R4,-GUTTER ; -- note, we don't display the gutter +00013A: 14CF 253 LOAD R1,PDSPAT +00013C: F150 FEC8 254 JSRS R1,R1 ; dspat( 0, rows - gutter ) +000140: F1B1 255 256 LEA R11,R8,BBOARD +000142: FB78 0008 257 MOVESL R12,R9,LOG2WID +000146: BC97 258 ADD R11,R11,R12 +000148: 3BBC 259 ADDSI R11,GUTTER ; pcell = bboard + (rows * width) + gutter +00014A: 1BC1 260 261 LOAD R10,R8,BWIDTH +00014C: FA58 0000 262 ADDSI R10,-GUTTER ; colunns = bwidth - gutter +000150: 1ACF 263 SHOILP: ; while (true) { SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 8 SHOWIT -- display the boar Wed Nov 10 2004 264 ; here, R8 points to info block 265 ; here, R9 is the row number 266 ; here, R10 is the column number 267 ; here, R11 is the cell pointer 268 ; here, R12 is spare 269 ADDSI R10,-1 ; columns = columns - 1 +000152: 1ACF 270 CMPI R10,GUTTER ; columns = columns - 1 +000154: F06A FFFF 271 BLT SHOILQ ; if (columns < gutter) break +000158: 05EA 272 273 LOADS R3,R11 +00015A: F3DB 274 EXTB R3,R3,R11 ; char = *pcell +00015C: 533B 275 BZS SHODED ; if (char != 0) +00015E: 0202 276 LIS R3,'X' ; char = 'X' +000160: D358 277 BR SHOIT ; else +000162: 0001 278 SHODED: LIS R3,' ' ; char = ' ' +000164: D320 279 SHOIT: 280 LOAD R1,PDSPCH +000166: F150 FEA2 281 JSRS R1,R1 ; dspch( char ) +00016A: F1B1 282 283 ADDSI R11,1 ; pcell++ +00016C: 1BC1 284 285 BR SHOILP +00016E: 00F1 286 SHOILQ = SHOOLP ; } -- equiv to SHOILQ: BR SHOOLP 287 288 SHOOLQ: ; } 289 290 ADDI R2,-ARSIZE +000170: F262 FFE8 291 LOAD R8,R2,R8SV +000174: F852 0004 292 LOAD R9,R2,R9SV +000178: F952 0008 293 LOAD R10,R2,R10SV +00017C: FA52 000C 294 LOAD R11,R2,R11SV +000180: FB52 0010 295 LOAD R12,R2,R12SV +000184: FC52 0014 296 LOADS R1,R2 +000188: F1D2 297 JUMPS R1 ; return +00018A: F0B1 298 299 ; ---------------------------------- SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 9 UPDATE -- update one board Wed Nov 10 2004 300 SUBTITLE UPDATE -- update one board generation 301 302 ; visits all cells except on the edges of the board (these never change) 303 ; using two nested loops, bottom to top, applying the RULES operation 304 ; to each cell. 305 ; ---------------------------------- 306 ; activation record structure 307 308 RA = 0 309 R8SV = 4 310 R9SV = 8 311 R10SV = 12 312 R11SV = 16 313 R12SV = 20 314 ARSIZE = 24 315 316 ; receiving sequence assumptions 317 UPDATE: 318 ; expects R1 = return address 319 ; uses R3-R7 320 ; saves and restores R8-10 321 ; returns nothing 322 STORES R1,R2 +00018C: F1A2 323 STORE R8,R2,R8SV +00018E: F822 0004 324 STORE R9,R2,R9SV +000192: F922 0008 325 STORE R10,R2,R10SV +000196: FA22 000C 326 STORE R11,R2,R11SV +00019A: FB22 0010 327 STORE R12,R2,R12SV +00019E: FC22 0014 328 ADDI R2,ARSIZE +0001A2: F262 0018 329 330 ; get board information 331 LOAD R8,PBINFO +0001A6: F850 FE86 332 LOAD R9,R8,BHEIGHT +0001AA: F958 0004 333 ADDSI R9,-GUTTER ; rows = bheight - gutter +0001AE: 19CF 334 UPDOLP: ; while (true) { -- outer loop 335 ; here, R8 points to info block 336 ; here, R9 is the row number 337 ADDSI R9,-1 ; rows = rows - 1 +0001B0: 19CF 338 CMPI R9,GUTTER +0001B2: F069 FFFF 339 BLT UPDOLQ ; if (rows < gutter) break +0001B6: 0512 340 341 LEA R11,R8,BBOARD +0001B8: FB78 0008 342 MOVESL R12,R9,LOG2WID +0001BC: BC97 343 ADD R11,R11,R12 +0001BE: 3BBC 344 ADDSI R11,GUTTER ; pcell = bboard + (rows * width) + gutter +0001C0: 1BC1 345 346 LOAD R10,R8,BWIDTH +0001C2: FA58 0000 347 ADDSI R10,-GUTTER ; columns = bwidth - gutter +0001C6: 1ACF 348 UPDILP: ; while (true) { -- inner loop 349 ; here, R8 points to info block 350 ; here, R9 is the row number 351 ; here, R10 is the column number 352 ; here, R11 is the cell pointer 353 ; here, R12 is spare 354 ADDSI R10,-1 ; columns = columns - 1 SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 10 UPDATE -- update one board Wed Nov 10 2004 +0001C8: 1ACF 355 CMPI R10,GUTTER +0001CA: F06A FFFF 356 BLT UPDILQ ; if (columns < gutter) break +0001CE: 05F0 357 358 MOVE R3,R11 +0001D0: F3FB 359 LOAD R1,PRULES +0001D2: F150 FE62 360 JSRS R1,R1 ; rules( pcell ) +0001D6: F1B1 361 362 ADDSI R11,1 ; pcell++ +0001D8: 1BC1 363 BR UPDILP +0001DA: 00F6 364 UPDILQ = UPDOLP ; } -- equiv to UPDILQ: BR UPDOLP 365 366 UPDOLQ: ; } -- end outer loop 367 368 ADDI R2,-ARSIZE +0001DC: F262 FFE8 369 LOAD R8,R2,R8SV +0001E0: F852 0004 370 LOAD R9,R2,R9SV +0001E4: F952 0008 371 LOAD R10,R2,R10SV +0001E8: FA52 000C 372 LOAD R11,R2,R11SV +0001EC: FB52 0010 373 LOAD R12,R2,R12SV +0001F0: FC52 0014 374 LOADS R1,R2 +0001F4: F1D2 375 JUMPS R1 ; return +0001F6: F0B1 376 377 ; ---------------------------------- SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 11 SHIFT -- finish update by Wed Nov 10 2004 378 SUBTITLE SHIFT -- finish update by shifting cells over 379 380 ; visit every cell on the board, except on the borders, and shift it 381 ; over to the next generation. Two nexted loops, bottom to top. 382 ; ---------------------------------- 383 ; activation record structure 384 385 RA = 0 ; note: the entire code of this 386 R8SV = 4 ; is cribbed from UPDATE 387 R9SV = 8 ; with just the inner loop changed 388 R10SV = 12 389 R11SV = 16 390 R12SV = 20 391 ARSIZE = 24 392 393 ; receiving sequence assumptions 394 SHIFT: 395 ; expects R1 = return address 396 ; uses R3-R7 397 ; saves and restores R8-10 398 ; returns nothing 399 STORES R1,R2 +0001F8: F1A2 400 STORE R8,R2,R8SV +0001FA: F822 0004 401 STORE R9,R2,R9SV +0001FE: F922 0008 402 STORE R10,R2,R10SV +000202: FA22 000C 403 STORE R11,R2,R11SV +000206: FB22 0010 404 STORE R12,R2,R12SV +00020A: FC22 0014 405 ADDI R2,ARSIZE +00020E: F262 0018 406 407 ; get board information 408 LOAD R8,PBINFO +000212: F850 FE1A 409 LOAD R9,R8,BHEIGHT +000216: F958 0004 410 ADDSI R9,-GUTTER ; rows = bheight - gutter +00021A: 19CF 411 SHIOLP: ; while (true) { -- outer loop 412 ; here, R8 points to info block 413 ; here, R9 is the row number 414 ADDSI R9,-1 ; rows = rows - 1 +00021C: 19CF 415 CMPI R9,GUTTER +00021E: F069 FFFF 416 BLT SHIOLQ ; if (rows < gutter) break +000222: 0513 417 418 LEA R11,R8,BBOARD +000224: FB78 0008 419 MOVESL R12,R9,LOG2WID +000228: BC97 420 ADD R11,R11,R12 +00022A: 3BBC 421 ADDSI R11,GUTTER ; pcell = bboard + (rows * width) + gutter +00022C: 1BC1 422 423 LOAD R10,R8,BWIDTH +00022E: FA58 0000 424 ADDSI R10,-GUTTER ; columns = bwidth - gutter +000232: 1ACF 425 SHIILP: ; while (true) { -- inner loop 426 ; here, R8 points to info block 427 ; here, R9 is the row number 428 ; here, R10 is the column number 429 ; here, R11 is the cell pointer 430 ; here, R12 is spare 431 ADDSI R10,-1 ; columns = columns - 1 +000234: 1ACF 432 CMPI R10,GUTTER SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 12 SHIFT -- finish update by Wed Nov 10 2004 +000236: F06A FFFF 433 BLT SHIILQ ; if (columns < gutter) break +00023A: 05F0 434 435 LOADS R3,R11 +00023C: F3DB 436 EXTB R4,R3,R11 ; cell = *pcell +00023E: 543B 437 SRU R4,GENSHIFT ; cell = cell >> genshift +000240: 8404 438 STUFFB R3,R4,R11 +000242: 734B 439 STORES R3,R11 ; *pcell = cell +000244: F3AB 440 441 ADDSI R11,1 ; pcell++ +000246: 1BC1 442 BR SHIILP +000248: 00F5 443 SHIILQ = SHIOLP ; } -- equiv to UPDILQ: BR UPDOLP 444 445 SHIOLQ: ; } -- end outer loop 446 447 ADDI R2,-ARSIZE +00024A: F262 FFE8 448 LOAD R8,R2,R8SV +00024E: F852 0004 449 LOAD R9,R2,R9SV +000252: F952 0008 450 LOAD R10,R2,R10SV +000256: FA52 000C 451 LOAD R11,R2,R11SV +00025A: FB52 0010 452 LOAD R12,R2,R12SV +00025E: FC52 0014 453 LOADS R1,R2 +000262: F1D2 454 JUMPS R1 ; return +000264: F0B1 455 456 ; ---------------------------------- SMAL32 (rev 9/03) MP4 main program by Dougla 11:30:40 Page 13 MAIN -- main program for g Wed Nov 10 2004 457 SUBTITLE MAIN -- main program for game of life 458 ; ---------------------------------- 459 460 ALIGN 4 461 COMMON STACK,#1000 +000268:+00000000 462 PSTACK: W STACK 463 464 S MAIN 465 MAIN: 466 LOAD R2,PSTACK +00026C: F250 FFF8 467 468 JSR R1,CLEAR ; clear the board +000270: F130 FDC8 469 JSR R1,SETUP ; set the initial config +000274: F130 FE1A 470 471 MAINLP: ; while (true) { 472 JSR R1,SHOWIT ; show the board +000278: F130 FE8E 473 JSR R1,UPDATE ; update the board +00027C: F130 FF0C 474 JSR R1,SHIFT ; shift to next generation +000280: F130 FF74 475 BR MAINLP ; } +000284: 00F9 476 477 END no errors