flat assembler
Message board for the users of flat assembler.
Index
> Main > Seeking alternate methods... Goto page 1, 2 Next |
Author |
|
revolution 04 May 2009, 08:46
So imul doesn't work for you then?
Code: imul cx,cx,320 |
|||
04 May 2009, 08:46 |
|
bitshifter 04 May 2009, 08:51
Yes, but why take all the fun out of it?
_________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
04 May 2009, 08:51 |
|
revolution 04 May 2009, 09:19
bitshifter wrote: ... buffer is at es:di. |
|||
04 May 2009, 09:19 |
|
bitshifter 04 May 2009, 09:32
Is that ok if es = cs = ds...
Or should i use mov byte[es:di],al |
|||
04 May 2009, 09:32 |
|
revolution 04 May 2009, 09:48
bitshifter wrote: Is that ok if es = cs = ds... bitshifter wrote:
|
|||
04 May 2009, 09:48 |
|
bitshifter 04 May 2009, 10:18
Ok thanks.
I guess i need to read up on segment registers more. (I thought .com file entry sets all those to the same 0x100) PS: <> means 'not equal to' correct? _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
04 May 2009, 10:18 |
|
revolution 04 May 2009, 10:47
bitshifter wrote: Ok thanks. bitshifter wrote: PS: <> means 'not equal to' correct? |
|||
04 May 2009, 10:47 |
|
bitshifter 04 May 2009, 11:52
First off, thanks for being so kind revolution :P
I am unsure about translation of your last post so maybe you take a look at what i have here... Code: ;------------------------------------------------ ; ;------------------------------------------------ use16 org 0x100 ;---------------------------------------- ; enter graphics mode ;---------------------------------------- mov ax,0x0013 int 0x10 mloop: ;---------------------------------------- ; clear buffer to desired color ;---------------------------------------- mov ax,0x0707 ; bk-fg pixel color (twice) mov cx,0x7D00 ; 64k buffer bytes / 2 mov di,g_buffer ; destination pointer cld ; set direction for incrementing DI rep stosw ; stores word at AX into DI and increments DI ;---------------------------------------- ; set color of buffer pixel ;---------------------------------------- mov al,0x01 ; bk-fg pixel color mov bx,1 ; x position (column) mov cx,1 ; y position (row) mov di,g_buffer ; destination pointer call SetPixel ;---------------------------------------- ; wait for vertical reset ;---------------------------------------- mov dx,0x03DA vend: in al,dx test al,0x08 jz vend vres: in al,dx test al,0x08 jnz vres ;---------------------------------------- ; copy buffer into video memory ;---------------------------------------- push es mov ax,0xA000 ; video memory segment mov es,ax xor di,di mov si,g_buffer mov cx,0x7D00 ; 64k video memory bytes / 2 cld rep movsw pop es ;---------------------------------------- ; check for keypress ;---------------------------------------- mov ah,0x01 int 0x16 jz mloop ;---------------------------------------- ; enter text mode ;---------------------------------------- mov ax,0x0003 int 0x10 ;---------------------------------------- ; return to operating system ;---------------------------------------- int 0x20 ret ;--------------------------------------------- ; ; al: color ; bx: x ; cx: y ; di: buffer ; ; offset = y * 320 + x ; so... ; offset = (y << 6) + (y << 8) + x ; ;--------------------------------------------- SetPixel: pusha mov dx,cx shl cx,6 shl dx,8 add di,bx add di,cx add di,dx mov byte[es:di],al popa ret ;------------------------------------------------ ; ;------------------------------------------------ g_buffer rb 64000 _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. Last edited by bitshifter on 04 May 2009, 15:57; edited 1 time in total |
|||
04 May 2009, 11:52 |
|
revolution 04 May 2009, 12:00
That code only works because the total size is less than 0x500 bytes and uses almost no stack. Any code of substantial size will force g_buffer higher than 0x600 (or into your stack) and then you will get many problems.
|
|||
04 May 2009, 12:00 |
|
bitshifter 04 May 2009, 12:12
So i need to use...
Code: mov byte[es:di],al But do i need to change ES also? If so, where to? _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
04 May 2009, 12:12 |
|
revolution 04 May 2009, 14:18
bitshifter wrote: But do i need to change ES also? If so, where to? Code: mov ax,es add ax,1 shl 12 mov es,ax |
|||
04 May 2009, 14:18 |
|
bitshifter 04 May 2009, 15:52
Nice revolution, thanks.
That works ok if my code plus my data are less than 4096 bytes, right? I was blind to this type of problem since i was mostly writing win32 apps, which have data and code sections. Maybe i need to look into fasm and see how these work. (doesnt it align these sections on 1024 byte boundary and pad the rest) _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
04 May 2009, 15:52 |
|
revolution 04 May 2009, 15:58
Segment registers are shift 4 places (x16) before adding to the address. So "1 shl 12" moves es up by 64kB.
|
|||
04 May 2009, 15:58 |
|
bitshifter 04 May 2009, 16:04
Oh yeah, i forget the segments are unique every 16, duh...
_________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
04 May 2009, 16:04 |
|
r22 04 May 2009, 17:26
Code: SetPixel: pusha shl cx,6 ; x*64 lea dx,[cx+cx*4] ; (x*64) + (x*64) * 4 = x*320 ;;;;;;lea cx,[cx+cx*4] ; dont even use dx add di,bx add di,dx ;;;;;;add di,cx ; dont even use dx mov byte[es:di],al popa ret In short, I'd use LEA instead of the MOV, SHL, ADD |
|||
04 May 2009, 17:26 |
|
Goplat 04 May 2009, 19:58
You can't use that kind of addressing with 16-bit registers. "lea dx,[ecx+ecx*4]" would work, although it would require a 386 or higher.
|
|||
04 May 2009, 19:58 |
|
bitRAKE 04 May 2009, 21:40
Code: SetPixel: pusha add di,bx shl cx,6 add di,cx ; +64y shl cx,2 add di,cx ; +256y stosb ; mov [es:di],al popa ret Code: SetPixel: pusha add bh,cl ; +256y shl cx,6 add di,cx ; +64y mov [es:di+bx],al popa ret Maybe, you've already seen Michael Abrash's Graphics Programming Black Book Special Edition. Imagine the buffer is zero indexed from ES, and DI is used for X value: then IMUL/MOV is sufficient, destroying only a single register, BX. Code: ; ES - screen buffer ; DI = X-coordinate ; CX = Y-coordinate ; AL = color imul bx,cx,320 mov [es:di+bx],al |
|||
04 May 2009, 21:40 |
|
bitshifter 05 May 2009, 06:15
How can i make a data section and point ES and DS to it?
I think that the LES and LDS instructions may be what i need to set ES and DS to there but i never had used them before. Maybe by using a label at the beginning of my data? Then i can set ES and DS to that segment with LES and LDS? Then DI would be zero based? I am so confused now EDIT: I have tried the snippet that revolution has provided for setting ES and for some reason it does not work correctly... The program did not explode in my face, but the display was incorrect. |
|||
05 May 2009, 06:15 |
|
bitRAKE 05 May 2009, 15:37
Say the (linear) address of the buffer is $43210 then ES would be $4321 to point at this buffer.
Code: push $4321
pop es $4321:$0000 and $4000:$3210 are the same address - keep rereading the above until this is understood. Code: ; COM assumptions: ; AX BX = 0000 ; CX = 00FF ; DX CS DS ES SS = .... (same unknown value) ; SI = 0100 ; DI = FFFE ; BP = 09.. ; SP = FFFE ; IP = 0100 |
|||
05 May 2009, 15:37 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.