flat assembler
Message board for the users of flat assembler.
Index
> DOS > Write colored strings into console =D |
Author |
|
Tomasz Grysztar 07 Jun 2006, 12:50
There was also this thread about similar topic: http://board.flatassembler.net/topic.php?t=5075
|
|||
07 Jun 2006, 12:50 |
|
saigon 07 Jun 2006, 14:03
Hi Tomasz!
I think I missed that topic, but as for a beginner like me in assembly, it's quite impressive that I did the code as it's advanced stuff to use DOS interrupts etc. Also, I think I'm the first member in this forum who wrote code from scratch to do this job, but I might be wrong (didn't find anything through forum search). Anyway, I think this might help new users to understand the DOS interrupts more. I just hope I commented the code so that new users would understand what the program is doing. Have a nice day! |
|||
07 Jun 2006, 14:03 |
|
vid 07 Jun 2006, 14:11
and as next lesson, you could rewrite it to procedure.
Because with macro, you will have this whole code assembled in source each time you use the macro. |
|||
07 Jun 2006, 14:11 |
|
saigon 07 Jun 2006, 17:03
I know for what macros are. For example, this source:
Code: macro dosomething { ; Do something } dosomething dosomething dosomething will be assembled as: Code: ; Do something ; Do something ; Do something Last edited by saigon on 07 Jun 2006, 18:39; edited 1 time in total |
|||
07 Jun 2006, 17:03 |
|
Dex4u 07 Jun 2006, 18:02
Maybe something like this:
Code: call dosomething Code: dosomething: ; Do somethingret |
|||
07 Jun 2006, 18:02 |
|
saigon 07 Jun 2006, 18:39
Oh yes, ofcourse. I was not at my main work computer, so I typed from my mind. I perhaps was playing with HLL, that's why I wrote 'proc'.
|
|||
07 Jun 2006, 18:39 |
|
ChrisLeslie 07 Jun 2006, 22:52
Hi saigon
Just two comments from me: 1) you should make your labels as local so that you can repeat the macro without getting duplication errors. e.g. put "local WriteChar" and "local WriteDone" lines at the start. 2) you might as well preserve all registers since you are not interested in returning any. "pushad" at the start and "popad" at the end is one way to do that. Regards Chris |
|||
07 Jun 2006, 22:52 |
|
rugxulo 07 Jun 2006, 23:39
It's always good to have several versions of a routine since none is (usually) best for all circumstances.
Having said that, though, please take a look at this (from Ralf Brown's interrupt list): Code: INT 10 - VIDEO - WRITE STRING (AT and later,EGA) AH = 13h AL = write mode bit 0: update cursor after writing bit 1: string contains alternating characters and attributes bits 2-7: reserved (0) BH = page number BL = attribute if string contains only characters CX = number of characters in string DH,DL = row,column at which to start writing ES:BP -> string to write Return: nothing Notes: recognizes CR, LF, BS, and bell; for the ET4000 BIOS, scrolling, backspace, and CR only take place in the active page also available PC or XT with EGA or higher HP 95LX only supports write mode 00h IBM documents AL=10h,11h,20h,21h as "private" rather than "reserved" with PhysTechSoft's PTS ROM-DOS the AL,BH,BL,DH, and DL values are ignored on entry. BUG: on the IBM VGA Adapter, any scrolling which may occur is performed on the active page rather than the requested page SeeAlso: AH=09h,AH=0Ah,AH=13h"DOS/V" |
|||
07 Jun 2006, 23:39 |
|
saigon 08 Jun 2006, 08:10
@ChrisLeslie: As I said, my code might need optimizing, and what you're suggesting is exactly that. I am new to assembly, so please give me a lesson and tell me everything I need to have optimized sources.
Thanks! @RugXulo: I saw the Ralph's list of interrupts, but what I didn't notice was that the interrupt didn't reposition the cursor, so I had to write my own routine. |
|||
08 Jun 2006, 08:10 |
|
rugxulo 08 Jun 2006, 22:05
This ...
Code: xor ch, ch ; Reset starting line mov cl, ch ; Set ending line to starting line inc cl ; Increment ending line should probably be ... Code: mov cx,1 |
|||
08 Jun 2006, 22:05 |
|
ChrisLeslie 09 Jun 2006, 08:36
This should be little improvement with some of the suggestions and put into a complete little program. Lots more could be done:
Code: org 100h macro WriteStringEx String, Color { local WriteChar,newLine,WriteDone pushad mov si, String ; Move string to ds:si xor bh, bh ; Reset bh register (page) mov bl, Color ; Set text color WriteChar: lodsb ; Load a byte from ds:si to al or al, al ; Or al jz WriteDone ; Jump away if writing is done mov ah, 9 mov cx,1 int 10h ; Write a colored character mov ah, 3 ; int 10h ; Get the cursor position cmp dl,79 je newLine mov ah, 2 inc dl ; Increment cursor's x position int 10h ; Reposition cursor jmp WriteChar ; Repeat to write the next character newLine: mov ah,2 mov dl,0 inc dh int 21h jmp WriteChar WriteDone: ; We are done, let's head back popad } WriteStringEx str1,1 WriteStringEx str2,2 mov ax,4C00h int 21h str1 db "Hellooooooooooooooooooooooooooooooooooooooooo",0 str2 db " Wooooooooooooooooooooooooooooooooooooooooooooooooooorld",0 Regards |
|||
09 Jun 2006, 08:36 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.