Page 1 of 1

Help! how to take input on console

Posted: Mon Jul 12, 2004 11:00 pm
by shadowscape
Hi, Im new to the scene and I was wondering ive got a kernel, I can type text and such but how would i create a console/shell type feature and how would i create a scanf type function?

RE:Help! how to take input on console

Posted: Mon Jul 12, 2004 11:00 pm
by ASHLEY4
Like this:
[code]
[BITS 32]               ;Set code generation to 32 bit mode
[ORG 0x0100]            ;Set code start address to 0100h


[SEGMENT .text]         ;Main code segment

main:
mov ah, 46
call clear_screen
call welcome_msg
jmp disp_prompt

welcome_msg:
mov al, 4
mov edi, welcome_str
int 0x20
ret

disp_prompt:
mov al, 4
mov edi, prompt_str
int 0x20

user_input:
mov al, 40
mov edi, input_str
int 0x20
call upper_case

test_input:
;Begin test for directory command
mov esi, dir_test_str
mov edi, input_str
mov al, 30
int 0x20
test al, al
jz dir_command

;Begin test for reboot command
mov esi, reboot_str
mov edi, input_str
mov al, 30
int 0x20
test al, al
jz reboot_command

;Begin test for exit command
mov esi, exit_str
mov edi, input_str
mov al, 30
int 0x20
test al, al
jz exit

;Begin test for cls command
mov esi, cls_str
mov edi, input_str
mov al, 30
int 0x20
test al, al
jz cls_command

;Begin test for help command
mov esi, help_str
mov edi, input_str
mov al, 30
int 0x20
test al, al
jz help_command

execute_input:
mov al, 4
mov edi, temp_msg
int 0x20
jmp disp_prompt

reboot_command:
mov al, 13
int 0x20

help_command:
mov al, 4
mov edi, help_msg
int 0x20
jmp disp_prompt

cls_command:
mov ah, 46
call clear_screen
jmp disp_prompt

dir_command:
mov al, 25
mov edi, dir
int 0x20
jmp disp_prompt

upper_case:
mov esi, input_str
mov al, 31
int 0x20
ret

clear_screen:
mov al, 4
mov edi, blank
int 0x20
dec ah
jnz clear_screen
ret

exit:
retf

[SEGMENT .data]         ;Initialised data segment
prompt_str:   db 'A:\>',0
temp_msg:     db 'Bad command or file name',13,10,0
dir:          db 'files',0
dir_test_str: db 'DIR',0
exit_str:     db 'EXIT',0
reboot_str:   db 'REBOOT',0
cls_str:      db 'CLS',0
help_str:     db 'HELP',0
input_str:    times 256 db 0
blank:        db ' ',13,10,0
;temp_buff:    times 255 db 0
welcome_str:  db 13,10,'ÛßßßßßßßßßßßßßßßßßßßßÛ',13,10
              db 'Û Welcome to V2-DOS. Û',13,10
              db 'Û                    Û',13,10
              db 'Û        by:         Û',13,10
              db 'Û      Stalin        Û',13,10
              db 'ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ',13,10,13,10,0

help_msg:     db 13,10,'ÛßßßßßßßßßßßßßßßßßßßßßßÛ',13,10
              db 'Û dir: list files      Û',13,10
              db 'Û cls: clear screen    Û',13,10
              db 'Û exit: exit shell     Û',13,10
              db 'Û reboot: quick reboot Û',13,10
              db 'ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ',13,10,13,10,0

[/code]

ASHLEY4.

RE:Help! how to take input on console

Posted: Mon Jul 12, 2004 11:00 pm
by shadowscape
WOW! Thank you so much im gonna work on converting this to C, Thanks so much!

RE:Help! how to take input on console Dont Understand Please

Posted: Mon Jul 12, 2004 11:00 pm
by shadowscape
If any body has one in C then maybe i could understand im not to good with large chunks of asm

RE:Help! how to take input on console Dont Understand Please

Posted: Tue Jul 13, 2004 11:00 pm
by ASHLEY4
Hi, I do not do c programming, but i found this on a floppy of demo os, it may help ?.
;************************************************************************************************************
[code]
#include "Minit.h"

int i;
int ver;

int main(void)
{
  printf("Hello World\n\r");
  ver=strdef("pre-1a");
  while(true)
  {
    printf("[Minit] : ");
    i=scanf();
    printf("\n\r");
    if(strcmp(i,"run")==true){
      run("LOADME  COM");
    }else if(strcmp(i,"restart")==true){
      reboot();
    }else if(strcmp(i,"help")==true){
  printf("\n\rMinit v");
  printf(ver);
  printf("\n\r\t help          Displays this screen");
  printf("\n\r\t restart       Restarts the computer");
  printf("\n\r\t run           Runs the graphics demo\n\r\n\r");
}else if(strcmp(i,"")==false){
  printf("Command Unknown\n\r");
}
  }
  pause();
}

[/code]
;************************************************************************************************************
You can get the full code for this here:     http://www.groovyweb.20m.com/easyos.htm

Also found this:
;************************************************************************************************************
[code]
#include <kernel.h>
#include <stdarg.h>
#include <gdt.h>
#include <string.h>
#include <stdlib.h>

#include <timer.h>
#include <time.h>

#include "../version.h"

char *prompt = "#:/";

void newline() {
     printk("\n%s",prompt);
}


void init_shell()
{ /* Currently don't do alot... */
printk("\eRLoading LittleOS Basic ShellProcessor: ");
printk("\eNOK!\n");
        printk("Welcome to LittleOS, type `help' for help\n");
newline();
}

void proccmd(char *cmd) {
printk("\n");
if ( (strcmp(cmd, "ver")) == 0) {
printk("\eRLittle\eBOS\eN "VERSION"\n\eRBuildIN Command processor by: Eran Rundstein\eN\n");
} else
if ( (strcmp(cmd, "clear")) == 0) {
clrscr();
gotoxy(0,0);
} else
        if ( (strcmp(cmd, "info")) == 0) {
         printk("\e14System information:\n\eN");
                io_stats();
                delay(2*hz);
                irq_stats();
                delay(1*hz);
        } else
        if ( (strcmp(cmd, "reboot")) == 0) {
         printk("\nRebooting... ");
                delay(100); printk("NOW!"); delay(5);
         reboot();
        } else
        if ( (strncmp(cmd, "va2pa", 5)) == 0) {
                ulong addr = strtoul(cmd+6, NULL, 0);
                printk("va = 0x%08lX, pa = 0x%08lX\n", addr, va_to_pa(addr));
        } else
        if ( (strcmp(cmd, "time")) == 0) {
         struct time t;
         printk("Current time: ");
                gettime(&t);
                printk("%02d:%02d:%02d\n", t.hour, t.min, t.sec);
        } else
        if ( (strcmp(cmd, "date")) == 0) {
         struct date d;
                printk("Current date: ");
                getdate(&d);
                printk("%02d %02d %04d\n", d.day, d.month, d.year);
        } else
        if ( (strcmp(cmd, "help")) == 0) {
         printk("\eNShell help:\nknown commands:\n");
                printk("\tver           - display OS version\n");
                printk("\tclear         - clear the screen\n");
                printk("\tinfo          - print some info about irqs and io\n");
                printk("\thelp          - print this help\n");
                printk("\treboot        - reboot the PC\n");
                printk("\tva2pa addr    - will print the physical address of the virtual\n");
                printk("\ttime          - print the current time\n");
                printk("\tdate          - print the current date\n");
        } else
         printk("unknown command\n");
}

[/code]
;***********************************************************************************************************
ASHLEY4.

RE:Help! how to take input on console Dont Understand Please

Posted: Tue Jul 13, 2004 11:00 pm
by Shadowscape
Yes, thanks a lot... I looked at the full source and got the function and how they implementes this in to it thanks a lot! ;-)