level 13
dwing
楼主
;2006年新年公开我写的471字节俄罗斯方块汇编程序源代码及详细注释!;471 bytes GAME! By Dwing;Only for DOS/Win9x/WinME/DosBox(注意不能直接在Win2000以上系统运行).model tiny.386.code$shape equ 008h$backg equ 0dbh$up equ 72$left equ 75$right equ 77$down equ 80 org 100hstart: int 10h ;设置显示模式0(40*25*16色字符模式) push 0b800h ;字符缓冲区段=b800h pop ds ;ds=b800h push ds pop es ;es=b800h xchg ax,di ;di=0000h mov ax,0700h+$backg ;开始画边框,ax=字符(0dbh)及属性(灰色) mov cx,ax ;cx=数量 rep stosw ;覆盖全屏 mov ax,0e30h ;开始画数码框,ax=字符('0')及属性(黄色) mov cl,6 ;cl=数字个数(6) mov di,2*(40*23+17) ;di=数字显示屏幕偏移位置 rep stosw ;显示数码 xor ax,ax ;开始画中间空框,ax=空字符 mov di,2*(40*2+15) ;di=空框第一行屏幕偏移位置@nextbl:mov cl,10 ;cl=每行块数(10) rep stosw ;画一行空格 add di,2*(15+15) ;计算下一行屏幕偏移位置 cmp di,2*(40*22+15) ;判断是否画完最后一行(共20行) jb short @nextbl ;没画完则循环@rernd: in al,40h ;开始随机选择方块类型,al=时间随机值 and al,0111b ;al只取0-7 jz short @rernd ;如果是0则重新选择(只选1-7,共7种) dec ax ;1-7变为0-6 mov bx,2*(40*2+15+4) ;方块起始屏幕偏移位置 jnz short @t ;如果不是0(长条形方块需特殊处理)则跳转 mov bx,2*(40+15+4) ;长条形方块的起始屏幕偏移位置上移一行@t: xchg ax,
bp
;bp=方块起始屏幕偏移位置 call @isok ;判断新产生的方块能否放置 jz short @goon ;能放置则跳转@end: call @dispb ;不能放置情况:先显示方块 push cs pop ds ;ds=当前程序段 lea dx,msg1 ;dx="GAMEOVER"信息地址 mov ah,9 ;ah=9(显示字符串) int 21h ;显示"GAMEOVER"@esc: in al,60h ;读键盘 dec al ;"ESC"扫描码=1 jnz short @esc ;如果没有按"ESC"则跳回继续读键盘 mov ax,3 ;ax=DOS默认显示模式(3) int 10h ;设置显示模式3(80*25*16色字符模式) retn ;退出@goon: mov cl,0ffh ;新方块能放置情况:先进入延时状态 cmp cl,40h ;cl=循环等待次数 jae short @wait ;确认cl不小于40 mov cl,40h@wait: call @dispb ;显示当前新方块 push cx ;进入等待状态 xor cx,cx ;cx=等待时间(微秒)低字 mov dx,1000 ;dx=等待时间(微秒)高字 mov ah,86h int 15h ;等待 pop cx ;退出等待状态@t4: mov ah,1 int 16h ;判断键盘缓冲区是否有字符
2006年01月02日 15点01分
1
bp
;bp=方块起始屏幕偏移位置 call @isok ;判断新产生的方块能否放置 jz short @goon ;能放置则跳转@end: call @dispb ;不能放置情况:先显示方块 push cs pop ds ;ds=当前程序段 lea dx,msg1 ;dx="GAMEOVER"信息地址 mov ah,9 ;ah=9(显示字符串) int 21h ;显示"GAMEOVER"@esc: in al,60h ;读键盘 dec al ;"ESC"扫描码=1 jnz short @esc ;如果没有按"ESC"则跳回继续读键盘 mov ax,3 ;ax=DOS默认显示模式(3) int 10h ;设置显示模式3(80*25*16色字符模式) retn ;退出@goon: mov cl,0ffh ;新方块能放置情况:先进入延时状态 cmp cl,40h ;cl=循环等待次数 jae short @wait ;确认cl不小于40 mov cl,40h@wait: call @dispb ;显示当前新方块 push cx ;进入等待状态 xor cx,cx ;cx=等待时间(微秒)低字 mov dx,1000 ;dx=等待时间(微秒)高字 mov ah,86h int 15h ;等待 pop cx ;退出等待状态@t4: mov ah,1 int 16h ;判断键盘缓冲区是否有字符