Author Topic: Fast Text Routine  (Read 6339 times)

0 Members and 1 Guest are viewing this topic.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Fast Text Routine
« 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
« Last Edit: March 06, 2007 by rain_storm »

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Fast Text Routine
« Reply #1 on: March 06, 2007 »
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:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Fast Text Routine
« Reply #2 on: March 06, 2007 »
its now attached to the first post

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Fast Text Routine
« Reply #3 on: March 06, 2007 »
Nice one mate :)
Well done.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Fast Text Routine
« Reply #4 on: March 06, 2007 »
Nice going dude :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Fast Text Routine
« Reply #5 on: March 06, 2007 »
Cool stuff.

Offline Agent Smith

  • ZX 81
  • *
  • Posts: 24
  • Karma: 3
    • View Profile
Re: Fast Text Routine
« Reply #6 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
« Last Edit: March 17, 2007 by Agent Smith »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Fast Text Routine
« Reply #7 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
« Last Edit: March 16, 2007 by rain_storm »

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Fast Text Routine
« Reply #8 on: March 16, 2007 »
Wahey cheers Mr. Smith :) Have some good Karma.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Fast Text Routine
« Reply #9 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
Challenge Trophies Won:

Offline Agent Smith

  • ZX 81
  • *
  • Posts: 24
  • Karma: 3
    • View Profile
Re: Fast Text Routine
« Reply #10 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! ;)






Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Fast Text Routine
« Reply #11 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

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Fast Text Routine
« Reply #12 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

Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Fast Text Routine
« Reply #13 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 :)