今天刚学完王爽汇编
学完了以后,感觉更想探索16位DOS系统的编程了,尤其是DOS中的图形编程,求各位高手分享DOS下的图形编程的书籍,最好是关于DOS开发游戏的
StepRange equ 20 X_Range equ 32 Y_Range equ 32 XLimit equ 320 - X_Range YLimit equ 200 - Y_Range DelayTime equ 1 Unit equ 3 ;-------------------------------------------------------------------- data segment starx dw 320/2 - (X_Range/2) stary dw 200/2 StepCount dw 10 Direction dw 0 handle dw 0ffffh Flydata db 1024 dup (?) FlyFile db 'flybmp.dat',0 BufferSeg dw 0 RandomMove label byte db 1*Unit,0,1*Unit,1*Unit,0,1*Unit,-1*Unit,1*Unit db -1*Unit,0,-1*Unit,-1*Unit,0,-1*Unit,1*Unit,-1*Unit ;8 direction data ends ;-------------------------------------------------------------------- code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov bx,offset End_offset + 4096 add bx,15 ;add mcb mov cl,4 shr bx,cl ; / 16 mov ah,4ah ;adjust memory int 21H mov bx,1000h ;64k for data buffer mov ah,48h int 21h jc exit mov BufferSeg,ax mov dx,offset flyFile mov ax,3d00h int 21h jc exit mov handle,ax mov bx,handle mov ah,3fh mov cx,1024 mov dx,offset Flydata int 21h ; Read one line into the buffer. jc exit cld mov ax,0013h int 10h call Movefly mov ax,0003h int 10h exit: mov ax,4c00h ;结束 int 21h ;-------------------------------------------------------------------- Movefly: call Random mov bx,8 ;0-8 ? xor dx,dx div bx shl dx,1 ;byte to word mov direction,dx call Random mov di,StepRange ;0-10 ? xor dx,dx div di inc dx mov StepCount,dx ;min = 1 Ms10: mov ax,DelayTime call Delay mov ah,1 int 16h jnz Mx ;quit call DrawStar ; mov bx,direction mov al,RandomMove[bx] cbw ;byte to word add ax,StarX cmp ax,XLimit ja @f mov StarX,ax @@: xor ax,ax mov al,RandomMove[bx+1] cbw ;byte to word add ax,StarY cmp ax,YLimit ja @f mov StarY,ax @@: dec StepCount jnz Ms10 jmp short Movefly Mx: ret ;-------------------------------------------------------------------- DrawStar: push ds mov ax,BufferSeg mov es,ax mov cx,320*200 /2 xor ax,ax xor di,di rep stosw mov ax,StarY mov bx,320 mul bx add ax,StarX mov di,ax mov cx,Y_Range mov si,offset FlyData Ds10: push di push cx mov cx,X_Range rep movsb pop cx pop di add di,320 ;1 line loop Ds10 mov di,0 mov si,0 mov ax,BufferSeg mov ds,ax mov ax,0A000h mov es,ax mov cx,320*200/2 rep movsw pop ds ret ;-------------------------------------------------------------------- Delay: ;迟延 ax/18秒的子程序 push es push dx mov dx,40h mov es,dx mov dx,es:[006ch] ;40:6ch..每1/18累加一次 add dx,ax ;目前累计时数+迟延数=目的迟延数 delay10: cmp es:[006ch],dx ;是否到达目的迟延数 jbe delay10 ;还没 delayx: pop dx pop es ret ;-------------------------------------------------------------------- ; dos / 16 bit 取乱数子程序 ; cpu每5ns累加一次,用RDTSC读取,放EDX:EAX ; 因为某些编译器不懂RDTSC, 0fh,31h是机器码植入 Random: ; (Return AX : 0 - 32bit EAX) db 0fh,31h ;RDTSC ret ;-------------------------------------------------------------------- End_offset: code ends end start
[此贴子已经被作者于2020-3-13 19:58编辑过]