Dark Bit Factory & Gravity

PROGRAMMING => Other languages => ASM => Topic started by: rain_storm on March 06, 2007

Title: Fast Text Routine
Post by: rain_storm on March 06, 2007
Basically what this does is write a char to the text buffer (offset 0B800h) in text mode only the charictors ascii is held in cl and the colour is held in ch then we store cx to whatever address (which is in si) you want. updating the address by 2 bytes with each write (colour & ascii). this meathod is about ten times faster than using interrupts. I have the routine down to about 34 bytes i think. it will compile with FASM and emu8086.
Code: [Select]
org 100h
mov  al, 03h ; enter text mode
int  10h        ; do it ya lazy bios!
push 0B800h     ; text buffer offset
pop  ds         ; point ds to offset
mov  cl, 58h ; ascii char
call text

text:
  mov [si], cx  ; write colour and char
  add si, 02h   ; update cursor
  inc ch        ; update colour
  cmp si, 0FA0h ; check for screen limit
  jb  text      ; loop if necessary

  inc ch        ; scroll colours
  xor si, si    ; reset cursor
  mov ah, 01h   ; get keyboard input
  int 16h       ; ahem
  jz  text      ; loop if necessary
  ret           ; lets get outta here
Title: Re: Fast Text Routine
Post by: Clyde on March 06, 2007
Any chance of adding a .com or exe please dude?
Title: Re: Fast Text Routine
Post by: rain_storm on March 06, 2007
its now attached to the first post
Title: Re: Fast Text Routine
Post by: Shockwave on March 06, 2007
Nice one mate :)
Well done.
Title: Re: Fast Text Routine
Post by: Clyde on March 06, 2007
Nice going dude :)
Title: Re: Fast Text Routine
Post by: rdc on March 06, 2007
Cool stuff.
Title: Re: Fast Text Routine
Post by: Agent Smith on March 16, 2007
This way might be faster (assembles to a 27 byte .com with Tasm/Tlink)

Code: [Select]
.MODEL tiny
.CODE
 ORG  100h
entry:
 mov  ax, 3       ; set 80x25 text mode (16 colors)
 int  10h         ; BIOS video services
 mov  ax, 0b800h  ; address of color screen
 mov  es, ax      ; ES holds destination segment
 xor  di, di      ; zero offset to start of buffer
 mov  ah, 15      ; color attribute (white on black)
 mov  al, 'X'     ; ASCII character to display
 mov  cx, 2000    ; number of words to store
 cld              ; auto-increment DI
 rep  stosw       ; store AX to ES:DI, CX times
 mov  ax, 4c00h   ; terminate with return code 0
 int  21h         ; call DOS
 END  entry
Title: Re: Fast Text Routine
Post by: rain_storm on March 16, 2007
Excellent Thanks Smith :cheers: Much faster and it will compile with fasm without too much bother

'rep  stosw' <- really gotta start using that
Title: Re: Fast Text Routine
Post by: Shockwave on March 16, 2007
Wahey cheers Mr. Smith :) Have some good Karma.
Title: Re: Fast Text Routine
Post by: Jim on March 16, 2007
Code: [Select]
mov  ah, 4ch     ; end process
 int  21h         ; call DOS
If you're writing a .com file, you can just use ret instead of this.

Jim
Title: Re: Fast Text Routine
Post by: Agent Smith on March 17, 2007
That's correct, the OS pushes a zero word onto the stack before jumping to the start of the program, so a near return will pass control back to PSP:0000, which always contains int 20h (Program terminate). This is actually a remnant from MS-DOS version 1.0, which was closely modelled on CP/M.

But exiting via int 21h, AH = 4C (Terminate with return code) became the officially 'approved' method from version 2 onwards.
My code should have really been:
Code: [Select]
  mov ax, 4c00h
  int 21h
  as the contents of AL are passed back as the return code.
As my code stands at the moment, 88 is passed back as the return value (i.e. ASCII code for 'X').

Oops  :-[ I hope this doesn't mean I'll have to forfeit my Karma  :'(
Shame on you all for not spotting my deliberate error! ;)





Title: Re: Fast Text Routine
Post by: mike_g on March 17, 2007
Thats right, hand it back mr Smith...

No seriously I dont know anything about assembler, but I do know that rain_storm is very good at what he does. So if you can improve on his code then you must be very good at what you do so you can have some karma from me :) Cos I know you hate it really :P
Title: Re: Fast Text Routine
Post by: rain_storm on March 17, 2007
Im just learnin the ropes still in my first 1/2 year of assembler but I have picked up a lot relevent to graphics n stuff this place is full of great coders and Im glad to see other ways to skin a cat
Title: Re: Fast Text Routine
Post by: mike_g on March 17, 2007
Yeah I'd like to have a go at learning assembler some time, just a matter of getting round to it. Anyway, keep it up guys :)