Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;cpu 8086 ; no shl ax, n :((
- cpu 186
- org 100h
- %define _START_ANGLE (32 - 1)
- %define _HALF_ROTATION 32 ; These costants are doubled to account for
- %define _FULL_ROTATION 64 ; WORD adjustment with pointers
- %define _QUART_ROTATION 16
- %define _SCREEN_WIDTH 320
- %define _X_CENTER 160
- %define _Y_CENTER 100
- %define _RADIUS 75
- start:
- MOV AX, 0013h ; Screen 13h
- INT 10h
- MOV CX, _START_ANGLE
- NextAngle:
- MOV DI, cosTable ; Set DI to start of cos table
- MOV AX, CX ; Set AX to current angle
- SHL AX, 1 ; angle*2 because table is WORDs
- CalcCos:
- ADD DI, AX
- MOV AX, _RADIUS ; Set AX to radius of circle
- MOV DX, [DI] ; read cos(x) into DX
- IMUL DX ; x-component = (radius*cos(x)) >> 6
- SAR AX, 6 ; Need to preserve the sign
- MOV BX, AX ; Store x-component in BX
- SetSinPtr:
- ADD DI, _QUART_ROTATION ; sin(x) = cos(PI/2 + x)
- ; Make sure we don't overrun the table
- CMP DI, cosTable+(_FULL_ROTATION-1)
- JG .FixOverrun
- JMP CalcSin
- .FixOverrun:
- SUB DI, _FULL_ROTATION ; Adjust angle so it's within table
- CalcSin:
- MOV AX, _RADIUS ; Set AX to radius of circle
- MOV DX, [DI] ; Read sin(x) into DX
- IMUL DX ; y-component = (radius*sin(x)) >> 6
- SHR AX, 6
- DrawPoint:
- MOV DX, 0A000h ; Screen is ES:SI
- MOV ES, DX
- ADD AX, _Y_CENTER ; y-coord = (y_center + y-component)
- ADD BX, _X_CENTER ; x-coord = (x_center + x-component)
- MOV SI, AX ; SI = AX*256 + AX*64 [30 cycles]
- SHL AX, 6 ; AX*64
- SHL SI, 8 ; AX*256
- ADD SI, AX ; Store result (SI = Y*320)
- ADD SI, BX ; X + (Y*320)
- ;MOV DX, 320 ; ScreenPtr = X + (Y*320) [83 cycles]
- ;MUL DX ; (Y*320)
- ;ADD AX, BX ; X + (Y*320)
- ;MOV SI, AX ; used for mul method
- MOV [ES:SI], BYTE 0Ah
- DEC CX ; Done point, decrement counter
- JL end ; If counter less than 0, goto quit
- JMP NextAngle ; Not at cos(0), draw next point
- end:
- ret
- cosTable: incbin "cosTable.bin"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement