News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Not printing proper message

Started by zak100, December 13, 2009, 03:23:50 PM

Previous topic - Next topic

zak100

Hi,
I am tying to print a mesg using my kernel. I got this from this forum but I have modified the code. I am not using bios but
I am trying to print directly on screen. The code is given below:


.MODEL  TINY
        .CODE

;----------------------------------------------------------------------------------

LoadOfs EQU     0               ;must match the value in the bootloader source file

;----------------------------------------------------------------------------------

;---------------------- initialize ES segment register

        ORG     0

Start:  push    cs
        pop     ds
       
;-----------clear screen
mov ax, 3
int 10h

   
;---------------------- writing a message on screen at startup, character by character- we can't use int 21h
overdata:
        xor di, di
        mov ax, 0B800h
        mov es, ax
        mov si, offset msg0
       
msgloop:
        lodsb; loads al with a byte of data pted by ds:si
        or al, al
        jz Halt0
        stosw; transfers the contents of al to mem location ptd by es:di
        jmp msgloop
       

;---------------------- done - halt

Halt0: hlt
jmp     Halt0

;---------------------- data area in code segment

Msg0    db      "We be bootin234!"

;----------------------------------------------------------------------------------

        END     Start



The boot sector code is also given below which I again got from this forum:



.MODEL  TINY
        .CODE

;----------------------------------------------------------------------------------

LoadOfs EQU     0
LoadSeg EQU     1000h

;----------------------------------------------------------------------------------

;---------------------- branch to executable code

        ORG     0

Boot0:  jmp short Boot1
nop
;---------------------- OEM identifier

        ORG     3

        DB      "Zulfi OS"

;---------------------- BIOS parameter block for 1.44 Mb floppy disk

        ORG     0Bh

bpbBytesPerSector    DW 512
bpbSectorsPerCluster DB 2; 1
bpbReservedSectors   DW 1
bpbNumberOfFATs      DB 2
bpbRootEntries       DW 112; 224
bpbTotalSectors      DW 1440; 2880
bpbMedia             DB 0F9H; 0F0h
bpbSectorsPerFAT     DW 3; 9
bpbSectorsPerTrack   DW 9; 18; different (18)
bpbHeadsPerCylinder  DW 2
bpbHiddenSectors     DD 0
bpbTotalSectorsBig   DD 0
bsDriveNumber        DB 0
bsUnused             DB 0
bsExtBootSignature   DB 29h
bsSerialNumber       DD 0a0a1a2a3h
bsVolumeLabel        DB "MOS FLOPPY "
bsFileSystem         DB "FAT12   "

;---------------------- initialize SS:SP

Boot1:  cli                     ;disable maskable interrupts
        xor     di,di
        mov     ss,di
        mov     sp,7C00h        ;SS:SP = 0000:7C00
        sti                     ;enable maskable interrupts

;---------------------- display 'A' character

        cld
        mov     ax,0B800h
        mov     es,ax
        mov     ax,1F41h
        stosw

;---------------------- wait for a keypress

        mov     ah,0
        int     16h

;---------------------- read the bootloader code

        mov     cx,5            ;retry count

Reset0: push    cx
        mov     ah,0            ;reset floppy disk function
        mov     dl,0            ;drive A:
        int     13h

        mov     ax,LoadSeg      ;read sector into address LoadSeg:LoadOfs
        mov     es,ax
        mov     bx,LoadOfs

        mov     cx,2            ;cylinder 0, sector 2
        xor     dx,dx           ;head 0, drive 0
        mov     ax,201h         ;read 1 sector
        int     13h
        pop     cx
        jnc     Exec0

        loop    Reset0

;---------------------- failed 5 times - halt
;---display 'F' character  to show the failure occured
mov ax, 0B800h
mov es, ax
mov Di,4
mov ax, 9c46h
stosw


Halt0:  hlt
      jmp     Halt0

;---------------------- execute the bootloader code


Exec0:
        db      0EAh            ;JMP FAR instruction
        dw      LoadOfs         ;offset
        dw      LoadSeg         ;segment

;---------------------- boot sector signature

        ORG     1FEh

        dw      0AA55h

;----------------------------------------------------------------------------------

        END     Boot0


I am getting foloowing text printed in white color with light blue background (bg) and its blinking.

We be bootin234!OS FLOPPY FAT12 (& ... garbage)

It should print only:

We be bootin234!

without blinking and not in light blue bg.

Can somebody plz help me with this.

Zulfi.


dedndave

hiya Zulfi
1) you should use CLD before the loop - the DF is probably clear, but no guarantee
2) mov si,offset msg0+LoadOfs - that way, it gets corrected if LoadOfs is changed
3) you are getting the blinking grey on ugly blue (cyan i think it is) because that is the color for attribute 0B8h - lol
     put the attribute you want in AH (7) before the loop
4) the loop displays a null-terminated string, but your string has no terminator - ...bootin234!",0

EDIT - oh - you can test that code by writing it in a .COM or .EXE program - that way, you don't have to boot a floppy every time   :bg

a handy animated GIF...


FORTRANS

Hi,

   The code you show is testing for a zero termination byte.
change your code like the following.


Msg0    db      "We be bootin234!", 0


Regards,

Steve N.

zak100

Thanks. Its working now. Whats the purpose of this gif? Is it the binary of my prog.?

Zulfi.

dedndave

no lol
it is an animated GIF for picking text-mode screen attributes
save it as reference material
if you want to know what attribute byte you need to make a certain color/blink combintation, refer to the pic
see what the char looks like to the left of 0B8h ? - lol

rags

that's pretty cool Dave, even though I don't work in 16-bit.
Did you make that gif?
God made Man, but the monkey applied the glue -DEVO

dedndave

lol - no - i cobbed it off some university site (Univ of Regina Canada)
i was thinking of making a similar one that has the characters, as well   :P
they wasted some space with 0's

MichaelW

The table does not show the high-intensity background colors available when the blink/intensity bit in the mode control register is set to zero. IMO high-intensity background colors are more useful than blinking characters.
eschew obfuscation

dedndave

oh - i thought they were underlined
but, now that you mention it, i do recall the intensity thing
that may be adapter specific

by re-mapping the upper 128 characters, you can do some interesting things with text mode graphics - lol
but - the normal graphics modes are much easier to use nowdays due to the vesa interface
this is something i haven't spent much time with, as yet   :bg

Zulfi's bug was just interesting because he had the remnant in AH from loading the ES register with 0B800h from AX - lol

FORTRANS

Hi,

   A quick cut-and-paste...


; - Attribute Byte defines colors (and blink) -
; - bit7 - bit6 - bit5 - bit4 + bit3 - bit2 - bit1 - bit0 -
; - Blink   red  green   blue  intense  red  green   blue -
; - fore -  background color  +      foreground color     -


   I have not seen high intensity backgrounds in "normal" use.

Steve

Edit:

   Ah, reread MichaelW's comment.  Right...  Oops.  It does
need a tweak though.

SRN

MichaelW

Quotethat may be adapter specific

It is standard for the EGA/VGA.

eschew obfuscation

dedndave

gawd - i must be thinking of MDA cards - talk about showing my age - lol

FORTRANS

Hi,

   Dave, there is a monochrome EGA/VGA video mode that
emulates an MDA.  Here on a Windows 2000 machine, I
cannot set video modes in any reasonable sense.  But it
works on other systems.  Maybe it would work on yours?

   Since MichaelW mentioned the intense background, and I
have been seting colors using escape sequences with the
ANSI.SYS device, I didn't see the intense background.  So
I coded one up to set things using the BIOS.  And I figured
I should share it.  Shows blinking characters, then goes on
to show the intense background.

Regards,

Steve N.

dedndave

#13
great Steve - lol
when i run that on mine, it is high-intensity BG and stays that way - no change between keypresses
seeing as how there is no source....................   :(

but - here's a little goodie for you
many years ago, i wrote a vga ansi.sys driver (config.sys type)

it has a dos screen-saver built in   :bg
i tried to keep it small and fast
you can also control the character re-map buffer size
let me see if i can find the doc file for it, as well

assemble it as though it were a .COM program, then rename to .SYS
i used masm v 5.10 back then
i don't know how well it would work under win 2k or XP - never tried it
but, i used to use it with win 98 and earlier OS's

EDIT - i was looking for the doc - it is on one of my (many) older/smaller drives

looking at this one, you can define:
the size of the sequence buffer
the size of the re-assignment buffer
the time-out for the screen-saver
and which interrupts bring you out of screen-save

i seem to recall a more recent version that also allowed int 33h to bring it out of screen-save
but, this is from memory

DEVICE=VGAANSI.SYS t300 s80 r128 i16 i10

screen saver time = 5 minutes (300 seconds - 3600 max - t0 disables screen-saver)
sequence buffer = 80 bytes
re-assignment buffer = 128 bytes
INT 16 or INT 10h bring you out of screen-save

i don't recall all the default values, but i know if you specify nothing, it works like the standard ANSI.SYS plus a 5 minute screen-saver

as i remember, the whole thing is like 384 bytes installed - lol

FORTRANS

Quote from: dedndave on December 15, 2009, 11:26:14 AM
great Steve - lol
when i run that on mine, it is high-intensity BG and stays that way - no change between keypresses
seeing as how there is no source....................   :(

Hi Dave,

   Bizarre.  I probavly shouldn't post one off code, but...
Uncomment lines to change operating behaviour.  (Bad.)
You can then play with the Monochrome display mode.
As far as no blinking, copy/paste the set attribute stuff
at the end up front and reverse the setting.  How the
cusom colors did not work is beyond me.  It has worked
on all machines I've tried it on.  Unless you do it in a
window?  It should/must be run full screen.

   Yep, it misperforms nicely in a window.  Sigh.  Go full
screen.  Do a "Mode 80,25".  And then run the silly thing.
Amazing what people come up with!

   Anyway, hold on to your breakfast, here's the code.
The stuff keyboard stuff works in DOS, but not in Windows
2000.  Masm 5.0 was used if that matters.


        PAGE ,132
        TITLE Check 16 Color Text
        NAME  ColorT16

        COMMENT *
6 December 2005
   Following a thread on comp.asm.x86, I looked into the 16 color video
modes of the EGA/VGA.  Main source was "Programmer's Guide to PC Video
Systems" by Richard Wilton.

   Also, one of the "bright" ideas was inspired by the ANSI color
changes observed in COLORS.TXT.  However, that is 16 color text mode.
*

        COMMENT *
14 December 2009, thread on MASM Forum, set Blink/Intensity.  Tried
keyboard stuffing "mode co80", but Win2k barfs.
        *

        .XCREF
        .XLIST
INCLUDE DEFMS.ASM   ; MACRO and MS-DOS definitions from Heath/Zenith software
        DOSF_GETPSP     EQU 62H         ; Get Program Segment Prefix
        .LIST
        .CREF

                ; DEBUG equates
DEBUG   EQU     0       ; Debug

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Stack segment:
STCKSG  SEGMENT STACK
        ASSUME  SS:STCKSG, CS:CODE
        DB      32 DUP('STACK   ')      ; Stack area, and filler (512 Bytes)
STCKSG  ENDS

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Data segment:
DATASG  SEGMENT PUBLIC
        ASSUME  DS:DATASG, SS:STCKSG, CS:CODE

MSG1    DB      ' Hit a key to continue. $'
MSG2    DB      ' Custom colors. $'
MSG3    DB      ' Altered lbink register. $'
Cmd     DB      'mode co80'
   
; - - - Display routines related data area - - -

RESET_DAT DB   0, 1, 2, 3, 4, 5, 38, 7, 56, 9, 18, 27, 36, 45, 54, 63

; - - - End display routines related data area - - -

DATASG  ENDS

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Code segment:
CODE    SEGMENT PUBLIC
        ASSUME  CS:CODE,DS:DATASG,ES:NOTHING,SS:STCKSG

START   PROC
        MOV     AX,SEG DATASG   ; Set DS for rest of code ...
        MOV     DS,AX
        MOV     AX,0B800H       ; Set ES to color text video page
;        MOV     AX,0B000H       ; Set ES to mono text video page
        MOV     ES,AX

        MOV    AX,3     ; Fn 0, set video mode
        INT    10H      ; Video BIOS

; - Attribute Byte defines colors (and blink) -
; - bit7 - bit6 - bit5 - bit4 + bit3 - bit2 - bit1 - bit0 -
; - Blink   red  green   blue  intense  red  green   blue -
; - fore -  background color  +      foreground color     -

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Draw a 16x16 block of all possible attributes

        MOV     DX,0    ; Line Counter
        MOV     DI,320  ; Point to second line of Video Page
CT_1:
        MOV     CX,16   ; 16 blocks
CT_2:
        XOR     AX,AX
        MOV     AL,DL
        SHL     AL,1
        SHL     AL,1
        SHL     AL,1
        SHL     AL,1
        ADD     AL,16
        SUB     AL,CL
        PUSH    AX
        CALL TOASCII

        POP     AX
        PUSH    AX
        XCHG    AL,AH
        MOV     AL,BH
        STOSW

        POP     AX
        XCHG    AL,AH
        MOV     AL,BL
        STOSW
        XOR     AX,AX
        STOSW

        LOOP    CT_2

        INC     DX      ; Line Counter
        ADD     DI,160-96 ; Point to Start of Next Line
        CMP     DX,16
        JB      CT_1

        MOV     DX,OFFSET Msg1
        SCALL OUTSTR

        XOR     AX,AX
        INT     16H

        XOR     SI,SI
RESET_V2:
        MOV     BX,SI   ; Palette register (0-15)
        MOV     BH,RESET_DAT[SI] ; rgbRGB
        MOV     AH,10H  ; Set EGA Palette BIOS function
        MOV     AL,0    ; Set EGA Palette
        INT     10H
        INC     SI
        CMP     SI,16
        JL      RESET_V2

        MOV     DX,OFFSET Msg2
        SCALL OUTSTR

        XOR     AX,AX
        INT     16H

        MOV     AH,10H  ; Set EGA Palette BIOS function
        MOV     AL,3H   ; Set Background Intensity/Blink state
        MOV     BL,0    ; 1 = blink, 0 intensity
        INT     10H

        MOV     DX,OFFSET Msg3
        SCALL OUTSTR

        XOR     AX,AX
        INT     16H

;        MOV     AX,SEG DATASG   ; Set ES for string instruction.
;        MOV     ES,AX
;        MOV     CX,9
;        MOV     SI,OFFSET CMD

;CT_3:
;        PUSH    CX
;        LODSB
;        PUSH    SI

;        MOV     CL,AL           ; ASCII value
;        MOV     CH,71           ; fake Scan Code
;        MOV     AH,5            ; Stuff keyboard buffer
;        INT     16H             ; Keyboard BIOS

;        POP     SI
;        POP     CX
;        LOOP    CT_3

;        MOV     CL,0            ; Non-ASCII
;        MOV     CH,71           ; Scan Code Home
;        MOV     AH,5            ; Stuff keyboard buffer
;        INT     16H             ; Keyboard BIOS

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

;       Close down
;       **********
        SCALL   EXIT    ; Enter dos

START   ENDP

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; THIS ROUTINE CONVERTS THE ONE BYTE BINARY NUMBER IN THE AL-REGISTER INTO
; ITS HEXADECIMAL ASCII REPRESENTATION AND places THESE TWO BYTES iNTO THE
; BX register.

TOASCII:
        PUSH   AX
        AND    AX,0F0H
        SHR    AX,1
        SHR    AX,1
        SHR    AX,1
        SHR    AX,1
        CALL   CONVERT
        MOV    BH,AL

        POP    AX
        AND    AX,0FH
        CALL   CONVERT
        MOV    BL,AL

        RET

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; THIS ROUTINE CONVERTS A SINGLE DIGIT HEX CODE IN THE RANGE 0 TO 15
; TO ITS ASCII 8 BIT BYTE EQUIVALENT.
; ENTER AND RETURN WITH THE ARGUEMENT IN THE AL-REG.

CONVERT:
        CMP AL,0AH      ; SEE IF NOT NUMERIC
        JC CON1         ; JUMP IF IN  RANGE 0 TO 9
        ADD AL,07H      ; LETTER "A" IS 7 AFTER NUMBER "9"
CON1:   ADD AL,30H      ; NUMBER "0" IS ASCII CODE 30H
        RET

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CODE    ENDS
        END     START


Quote
but - here's a little goodie for you
many years ago, i wrote a vga ansi.sys driver (config.sys type)

it has a dos screen-saver built in   :bg
i tried to keep it small and fast
you can also control the character re-map buffer size

   I will take a look.

Thanks,

Steve N.