• Welcome to Dark Bit Factory & Gravity.
 

Fast Text Routine

Started by rain_storm, March 06, 2007

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

rain_storm

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.

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


Challenge Trophies Won:

Clyde

Any chance of adding a .com or exe please dude?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

rain_storm

its now attached to the first post

Challenge Trophies Won:

Shockwave

Nice one mate :)
Well done.
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

rdc


Agent Smith

#6
This way might be faster (assembles to a 27 byte .com with Tasm/Tlink)

.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

rain_storm

#7
Excellent Thanks Smith :cheers: Much faster and it will compile with fasm without too much bother

'rep  stosw' <- really gotta start using that

Challenge Trophies Won:

Shockwave

Wahey cheers Mr. Smith :) Have some good Karma.
Shockwave ^ Codigos
Challenge Trophies Won:

Jim


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
Challenge Trophies Won:

Agent Smith

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:
  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! ;)






mike_g

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

rain_storm

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

Challenge Trophies Won:

mike_g

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 :)