level 7
; "Boulder Dash" in 256 bytes; by; James David Chapman ;-----------------------------------------------------------------------------;assembler startup ;assembled with:.MODEL TINY ;TASM BD3.ASM /m2 /uM520 /t >errorsMASM51 ;TLINK BD3.OBJ /3 /x /tQUIRKS ;.286 ;The code of this program is also used.CODE ;as the data for the level maps. So.STARTUP ;any change in the order of the code;is *very* important;-----------------------------------------------------------------------------;setup screen and varsMOV AX,1 ;set screen mode 40*25INT 10H ;call BIOS set screen intPUSH 0B800H ;colour screen segment, change toPOP ES ;B000 for mono graphics cardsPUSH ES ;set/reset DS to CSPOP DSXOR DX,DX ;clear level counterNEXTLEVEL:INC DX ;increase level counterRESTART:XOR DI,DI ;clear screen pointerMOV SI,100H ;set source to start of com file;make the screen mapMAPLOOP:MOV AL,CS:[SI] ;load a byte of the program and use itINC SI ;as the mapdata for the levelMOV CX,DXROR AL,CL ;change map for next level by rotatingMOV CL,AL ;no. increases, so the data is changedOR CL,CLJZ MAPLOOPCALL PRINT4 ;each byte of the programs code givesCALL PRINT4 ;4+4 blocks on the screen, 256*8=2048CMP DI,2000 ;so the program is *just* able toJBE MAPLOOP ;produce enough data for the screen;print level numberMOV AL,30H ;set print value to "0"ADD AL,DL ;add level number to "0"XOR DI,DI ;di points for sides (after level prn)STOSW;print the screen borderXOR SI,SI ;si points for top/bottom rowMOV AX,01DBH ;a blue blockMOV CL,40 ;40 blocks across, and 40 lines down@@: ;(+15 overspill is off the display)ADD DI,76STOSW ;print the left sideSTOSW ;print the left sideMOV [SI+24*80],AX ;print the bottom lineINC SIINC SIMOV [SI],AX ;print the top line (put in after theLOOP @B ;-----------------------------------------------------------------------------;set man posMOV DI,88+06 ;set man position;plot finish squareMOV WORD PTR DS:[956-320],0AE58H;plot a flashing X home square;-----------------------------------------------------------------------------MAINLOOP:;change key press into man offsetMOV AH,8 ;DOS keyboard interrupt, 8 allowsINT 21H ;control-break to end gameOR AL,AL ;if extended key press, go get itJZ MAINLOOPCMP AL," " ;if space bar, reset *current* levelJE RESTART ;ie no increase of dx;clear manMOV BYTE PTR [DI],20H ;in case man is to be moved, clear him;convert keys into man offsetRCR AL,1 ;convert al into offset in BXMOV BX,80 ;assume offset is +80JNC @FSUB BX,78 ;make offset +2@@:CMP AL,26H ;if key is right or down skip negJAE @FNEG BX ;make offset -80 or -2@@:;check new man offset, if block or boulder, don't moveTEST BYTE PTR DS:[DI+BX],1JNZ PLOTMAN ;no move so just plot man againADD DI,BX ;update mans position;if exit go to next levelCMP DI,956-320 ;exit square is wired in as 956 though
2008年05月01日 13点05分