flat assembler
Message board for the users of flat assembler.
Index
> DOS > How does this code work? |
Author |
|
adroit 13 Mar 2010, 16:03
Hey all, could someone explain to me how does this code works (line-by-line if you could). It was written by Tomasz Grysztar at [content deleted].
It's so cool, that you can draw text from string data, and I want to find how it works. Code: org 100h mov ax,13h int 10h mov ax,1130h mov bh,6 int 10h mov word [font_data],bp mov word [font_data+2],es push 0A000h pop es mov di,320*64+48 mov si,_hello draw_text: lodsb test al,al jz done push ds si lds si,[font_data] xor ah,ah shl ax,4 add si,ax mov bx,16 draw_character: mov dl,[si] mov cx,8 draw_row: shl dl,1 jnc next_point mov ax,cx sub ax,bx and ax,1111b add ax,29 mov byte [es:di+321],al mov byte [es:di],al next_point: add di,2 loop draw_row inc si add di,(320-8)*2 dec bx jnz draw_character sub di,320*2*16-(8+1)*2 pop si ds jmp draw_text done: xor ah,ah int 16h mov ax,3 int 10h ret _hello db 'Hello, World!',0 font_data dd ? N.B: It would be really helpful if you could use comment lines to explain what each line does, and still provide with some information on how the code works. Thanks! _________________ meshnix |
|||
13 Mar 2010, 16:03 |
|
revolution 13 Mar 2010, 16:18
MeshNix: You can use a debugger and follow the code step by step.
|
|||
13 Mar 2010, 16:18 |
|
revolution 13 Mar 2010, 17:00
When debugging we don't have to enter different graphics modes. Just skip over (nop out) the graphics specifics calls and see how the program flow works. We don't have to actually plot the pixels to see how the code works.
|
|||
13 Mar 2010, 17:00 |
|
windwakr 13 Mar 2010, 19:06
I was bored:
Code: ;Interrupt info from Ralph Brown's Interrupt list org 100h ;Make it a .com file mov ax,13h ;Mode 13h, 320x200 256 colors int 10h ;^^^^ mov ax,1130h ;GET FONT INFORMATION (EGA, MCGA, VGA) mov bh,6 ;06h ROM 8x16 font (MCGA, VGA) int 10h ;Return: ES:BP = specified pointer ;Also returned, but not used here: ;CX = bytes/character of on-screen font (not the requested font!) ;DL = highest character row on screen mov word [font_data],bp ;Fill the variable with the pointer to the specified font(8x16). mov word [font_data+2],es ;^^^^^^^^ push 0A000h ;Setup es for writing to the screen(A000h = start of screen buffer). pop es ;^^^^ mov di,320*64+48 ;Start location to start writing pixels. 64 lines down and 48 across. mov si,_hello ;Set si up with location of the "Hello, World!" string. draw_text: lodsb ;Load a byte of the string into al. test al,al ;Is it zero? jz done ;If so, we're done. push ds si ;If not, push ds and si lds si,[font_data] ;Load DS:SI the font data SEGMENT:OFFSET.So now DS points to the font segment, and SI is the offset. xor ah,ah ;zero out the top of ax shl ax,4 ;Multiply the current byte of the string by 16(hint, the font is 8x16, stored as 8 pixels per byte) add si,ax ;Add that to the start offset of the font data. SI now points to the start of the pixel data for the current character. mov bx,16 draw_character: mov dl,[si] mov cx,8 draw_row: shl dl,1 jnc next_point mov ax,cx ;This all just draws it out fancy, I'm too lazy to continue.... sub ax,bx and ax,1111b add ax,29 mov byte [es:di+321],al mov byte [es:di],al next_point: add di,2 loop draw_row inc si add di,(320-8)*2 dec bx jnz draw_character sub di,320*2*16-(8+1)*2 pop si ds jmp draw_text done: xor ah,ah ; int 16h ;Wait for a keypress mov ax,3 ;Set mode 3, the normal console mode int 10h ;^^^^^^^^^^^ ret ;And....exit. _hello db 'Hello, World!',0 font_data dd ? Didn't finish it though, got bored of it. Maybe some non-lazy person could comment the screen printing part. |
|||
13 Mar 2010, 19:06 |
|
Tyler 14 Mar 2010, 01:26
That's not as impressive after you've seen his other stuff. I found the attached somewhere
buried in the os dev forum. It's tetris in the form of a 512b demo os. It ran in Bochs when I tried it, use the arrow keys to rotate and move the pieces.
|
|||||||||||
14 Mar 2010, 01:26 |
|
adroit 14 Mar 2010, 04:01
Thanks windwakr!
Tyler, I ran it on QEMU and it is really remarkable! It's a bootable game!!! |
|||
14 Mar 2010, 04:01 |
|
Flat12 25 Jan 2013, 20:51
Cool but this code is disk image. How convert code to ISA or PCI option ROM. I know that need 55 AA 01 (1*200) Jump to execute code and probably RET - please help.
|
|||
25 Jan 2013, 20:51 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.