Author Topic: OS 16Bits Load Programss Issue (4bh & 4ach) Help!  (Read 14269 times)

Offline dtoca

  • Jr. Member
  • *
  • Posts: 8
OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« on: January 05, 2013, 10:48:45 PM »
We have been working on a 16-bit OS. The OS can read text file, print bmp images(with limited colors). The problem we have is load the programs .exe, for some reason apparently overwrites the main program memory or not returned correctly PSP because when control returns to the main program the read file section does not work properly

Here is the complete project. It's called pixel
http://sdrv.ms/RvXsHZ

You need DOSBOX for run the program pixel.com/exe. You go to File-->Archivos and select a alfin.exe (alfin.exe print a number on screen)

The problem is when the subprogram finish if you go again to (File-->Archivo) will only show the program you selected in this case on alfin.exe.

Example if we have in the directory
ALFIN.EXE
PIXEL.EXE
TRES.EXE

When you select ALFIN.EXE and then you try (File--> Archivos) again the program will show
ALFIN.EXE
ALFIN.EXE
ALFIN.EXE


We have several libraries to manage functions. In "openf.inc" is the code for load programs in "BEGIN P1". Hope you can help. graciass
The main program is pixel.asm

Here is the BEGIN P1

Code: [Select]
;BEGIN: P1 (Ejecutar .EXE)
;--------------------------------------------------
;P1 load the selected program  '.exe' using the function '4Bh'
;of the int '21h', sending a 'al,0' for load and run the program
;-----------------------
p1:

mov [cs:savess],ss
mov [cs:savesp],sp
push ss
push sp

   jmp tam1
   next1:
   mov ah,4bh
   mov al,0h                  ; The 0 indicate Load and Run El '0' indica como se va a ejecutar el programa en este caso se carga
   mov cx,0h                  ;y se ejecuta inmediatamente.
   mov dx,filename            ;Run Selected Selected program
   push ds
   pop es                     ;
   mov bx,finalvar
   int 21h
   

mov     ss, [cs:savess]   ;Restore SS:SP from saved
mov     sp, [cs:savesp]   ;locations.
ret
   
;tam1 create the enveiroment to run the program (4ach or 4a00h)
tam1:

   add  bx,15
   mov  cl,4
   shr  bx,cl
   mov  ax,cs
   add  bx,ax
   mov  ax,4a00h
   int  21h
   jmp next1
ret

;--------------------------------------------------
;END: P1 (Ejecutar .EXE)
;--------------------------------------------------

PS: There is a PUSHA and POPA on openf.inc
« Last Edit: January 06, 2013, 02:52:43 AM by Frank Kotler »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #1 on: January 06, 2013, 04:57:11 AM »
Oh, maaan! Been a long time since I did anything with dos. I vaguely recall that int 21h/4Bh was quite troublesome to get working properly - problem with the parameter block, I think. Unfortunately, I'm not able to download your complete project from the link you give - probably because I'm running an obsolete browser. Got anything with less JavaScript in it?

The only thing I see right off is that you don't check the return value from int 21h/4Ah. If your "resize memory block" fails, you don't stand a chance of being able to continue! Doesn't sound like that's your problem, though...

From your description of the problem, it sounds like the code you show above is working, and the problem is elsewhere. You describe this as an "OS", but it depends on DosBox... that's confusing!

I edited your post to put "code tags" around your code. That may be the only help I'm able to give, but I'm willing to look at it some more...

Best,
Frank


Offline dtoca

  • Jr. Member
  • *
  • Posts: 8
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #2 on: January 06, 2013, 06:49:14 AM »
Thanks for the reply, hope you can help

Here is another link
http://www.mediafire.com/download.php?spr5qmd5ddu6pr1

We are planning to remove any dependence in the future. The part where the program reads the directory is "dir.inc"

Another question there is another way to run a program without 4bh int 21h?

Thanks!

PS: I attach the link here too

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #3 on: January 06, 2013, 08:36:58 AM »
is another way to run a program without 4bh int 21h?

Absolutely.  That being said, there are many different ways of accomplishing this, but simply have your program allocate a block of memory or have an area that is statically reserved for overlays and then which ever one you want to use, load it in that area and then call it like you would any other subroutine or procedure.

If you can statically load all overlays lets say @ 1000H, then it is quite simple, but if not, you might have to write a relocating loader in your application so references are resolved correctly. Hence, this is exactly what the loader does with EXE headers and the purpose of function 4B @ int 21H.

I would venture to say, if ALFIN, PIXEL & TRES were actually executables and not COM files, your  function P1 might work.

It's too bad I don't have a better understanding of Spanish, then I'd be able to understand the essence of your program better through its comments.  The logic of your example is somewhat hard to get a grip on, as I don't really understand the purpose of jumping to tam1 and then jumping to next1.  Code could look something like this.

Code: [Select]
;--------------------------------------------------
;P1 load the selected program  '.exe' using the function '4Bh'
;of the int '21h', sending a 'al,0' for load and run the program
;-----------------------
p1:

mov [cs:savess],ss
mov [cs:savesp],sp

; What is the purpose to this.

push ss
push sp

    add bx,15
    mov cl,4
    shr bx,cl
    mov ax,cs
    add bx,ax
    mov ax,4a00h
    int 21h

    ; mov ah,4bh
    ; mov al,0h
   
    mov ax, 0x4b00 ; The 0 indicate Load and Run El '0' indica como se va a ejecutar el programa en este caso se carga
    mov cx,0h ;y se ejecuta inmediatamente.
    mov dx,filename ;Run Selected Selected program
    push ds
    pop es
    mov bx,finalvar
    int 21h
   

mov     ss, [cs:savess] ;Restore SS:SP from saved
mov     sp, [cs:savesp] ;locations.
ret
   
;--------------------------------------------------
;END: P1 (Ejecutar .EXE)
;--------------------------------------------------

I've tried to run your program, but get nothing but a blank screen.  This is because files needed are missing from your download or the fact I'm not running a pure DOS box, but rather the emulator in XP.

Nice to see a 25,378 byte application done in assembly.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #4 on: January 06, 2013, 12:19:40 PM »
Got it. Thanks!

I agree with TightCoderEx. I don't speak Spanish either. And I haven't got DosBox. I copied the files to a dos partition (FreeDos) and tried it there. I got a little bit farther - instead of a blank screen, I get a green bar across the top, with some options on it (so far, so good!). Depending on which options I booted with, the mouse cursor (mouse enabled - cool!) is either hung, or leaves a "trail" behind it - kind of like an etch-a-sketch. If it moves, "exit" seems to work - but not cleanly back to dos, hangs the machine. I couldn't get much out of the other options. I tried running it in DEBUG, but that gets really tedious once you get into graphics mode - takes a long time to update the screen. I didn't spend too much time with it. Shows promise, but it isn't a "Windows beater" quite yet. :)

As TightCoderEx says, you should be able to run another program without depending on a dos interrupt fairly easily. From a "real boot", all the memory is "yours", so you shouldn't have to worry about "resize memory block" or "malloc". This should be "mostly true" even running in DosBox. You could just "pick a segment" - add 1000h to your current segment to leave the full 64k for your "kernel" (or move the stack down... but you shouldn't need to) - and... I'd load your "new" program at offset 100h in that segment, just like a .com file (which seems to be what you've got) so you wouldn't have to worry about relocations. The real problem is getting back to your "shell".

What dos does is to push a zero when loading your .com file, so when you "ret" you go to offset 0 in "that segment". Dos has put an int 20h as the first two bytes of the PSP. What I've done, since I didn't have dos available, was to put an int19h there, causing a reboot. A very crude way to get back to the "shell"... but it kinda worked...

This doesn't address the problem you're actually having, the directory listing not working after int 21h/4Bh returns. I haven't looked at the relevant code much. Your "finalvar" doesn't look like a proper "executable parameter block" to me - just a single dword 0 - but I don't know if that's the problem or not. If your "other program" runs and returns... at all... that part may be okay. I'll try to study it some more, if I can get "in the mood". Don't hesitate to "nudge" me if I forget... Good start!

Best,
Frank




Offline rapito

  • Jr. Member
  • *
  • Posts: 3
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #5 on: January 06, 2013, 05:07:08 PM »
Hi guys,
Thanks for taking some time to read this.
I'm working with dtoca on this project as well..
We've tried not using interruptions to load the program too but it doen't even run.

As you have suggested, we have already tried loading it on some memory and then moving our IP there but no luck...
Not sure though if we are doing it correctly :s

Here's the code that does that:

Code: [Select]
;--------------------------------------------------
;BEGIN: Leer .* (Cualquier Archivo)
;--------------------------------------------------
loadExe:

;Clean Screen

pintar_cuadro 0,21,100,40,[color_fondo_pant]
pintar_cuadro 0,100,340,400,[color_fondo_pant]

;We read One byte each time

mov ah,03Dh        ; the open-existing-file function
    mov al,0            ; open mode 0=read,1=write,2=both
    mov dx,filename    ; address of zero-terminated string
    int 021h            ; call on Good Old Dos
    mov [filehndl],ax  ; we'll reuse the filehndl variable,
; but use a different one if you open
; more than one :)
    mov ah,03Fh        ; the read-from-a-file function
    mov bx,[filehndl]  ; our new (same as old, probably) file handle
    mov cx,01h      ; max bytes to read
    mov dx,iobuf        ; address of a buffer to read into
    int 021h            ; call on Good Old Dos
    dec word[bothersomTR]

;Aqui se toman precauciones de data 'basura' y verificacion de final de archivo
;se pregunta si hemos leido hasta el limite y se coloca la data que esta en la siguiente posicion
; de la que se acaba de leer en 0.
;En caso de que halllamos llegado al limite, entonces se sale del ciclo.
againEXE:
cmp word[bothersomTR],0
je endEXE

;Se escribe lo que esta en el buffer leido


mov dx,[iobuf]
mov bx,bufferIDX
mov [startEXE+bx],dx
add byte[bufferIDX],1


;Este es el ciclo que le el siguiente byte del archivo.
goonEXE:


mov ah,03Fh        ; the read-from-a-file function
    mov bx,[filehndl]  ; our new (same as old, probably) file handle
    mov cx,01h       ; max bytes to read
    mov dx,iobuf        ; address of a buffer to read into
    int 021h           
dec word[bothersomTR]

;Si no se ha leido lo que se ha pedido leer, entonces salimos del ciclo
;de lo contrario continuamos
cmp ax,cx
je againEXE
jne endEXE

;Finalmente cerramos el archivo.
endEXE:
mov ah,03Eh      ;close the file
    mov bx,[filehndl] ;yeah, file handle in bx
    int 021h            ;call on Good Old Dos

switchEXE:


; mov dx,startEXE
; add dx,bufferIDX
; pushChar dx,[x_pos],[y_pos]
mov word[iobuf],startEXE
add word[iobuf],bufferIDX
mov ax,startEXE
mov bx,bufferIDX
push ax
push bx
ret
iret

ret

;--------------------------------------------------
;END: Leer .* (Cualquier Archivo)
;--------------------------------------------------




Thanks Again!

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #6 on: January 06, 2013, 06:08:34 PM »
Where there is much detail missing in a post, it's hard to give an answer, but on the surface it looks like you may be overwriting previous code because I don't see anywhere that iobuf is being incremented.  To be of any real assistance I need to know all the details of your benchmark.

1. Filename & contents
2. Where are variables being defined and intialized, particularly bothersomeTR & bufferIDX

Offline rapito

  • Jr. Member
  • *
  • Posts: 3
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #7 on: January 06, 2013, 06:24:49 PM »
Sorry,
The variables are being declared on the "pixel.asm" file right at the bottom of it [section .bss/.data].
"openf.inc" is the file that start the operation to read a clicked file. There it checks the extension, if it is a '.exe' terminated file
then it will call 'loadExe' on "ExE.inc" file.

All these files are available on the package dtoca uploaded a while back.
Not sure if ExE.inc is included though. (That's the one I posted on my last reply).

Offline dtoca

  • Jr. Member
  • *
  • Posts: 8
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #8 on: January 06, 2013, 06:53:58 PM »
TightCoderEx

Here is the pixel.asm where variable are defined in the end of [section .data]

Code: [Select]
; Compilado usando nasm:
; nasm -fbin pixel.asm -o pixel.exe
;===========================================================

org 100h

section .text
jmp main

%include "print.inc"
%include "mouse.inc"
%include "fuente.inc"
%include "pintar.inc"
%include "dir.inc"
%include "ExE.inc"
%include "openf.inc"

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

main:

mov ax, 4f02h ;establece el modo de video SVGA 800x600
mov bx, 103h
int 10h

;--------------------------------------------------
;BEGIN: Pintar Interfaz de usuario
;--------------------------------------------------

pintar_cuadro 0,0,800,21,[color_fondo_menu] ;Coloreamos la barra de menu


pushString boton_file,0,0 ;Dibujamos todos los Strings de las funciones del
pushString boton_edit,60,0 ;Menu en su lugar corresponiente
pushString boton_view,120,0
pushString boton_seq,180,0
pushString boton_help,460,0
pushString boton_exit,520,0
;--------------------------------------------------
;END: Pintar Interfaz de usuario
;--------------------------------------------------

;-------------------------------------------------------
;Llamada a la funcion que inicializa nuestro mouse/cursor
call set_mouse
;-------------------------------------------------------

;--------------------------------------------------
;BEGIN: Bucle Principial del Sistema
;--------------------------------------------------
;El parametro ah = 08h utilizado con la interrupcion
;int21h, nos permite continuar con el procesamiento
;del sistema
bucle:

mov ah,08h
int 21h

cmp byte[sacame],1 ;Si el FLAG = 1 podemos llamar a la salida
je _exit_ ;del programa

cmp al,'x' ;Compara el input de teclado almacenado en
je _exit_ ;al y llama a salir si fue igual a 'X'

jmp bucle
;--------------------------------------------------
;END: Bucle Principial del Sistema
;--------------------------------------------------



;--------------------------------------------------
;BEGIN: On-Click Actions-Handlers (Manejadores de Clic)
;--------------------------------------------------

; Las siguientes funciones se utilizan para encontrar
; el último clic del mouse y la posición donde se realizó
; para llamar a la 'funcion' correspondiente de cada 'menu item'

;Primero guardamos todos los valores de los registros en stack
;y preguntamos si la posicion y del mouse esta dentro de las dimensiones del menu,
;en caso de no estarlo, finalizamos.
find:
pusha
cmp word[y_clic],20
jg finalizar

;Verificamos que le dimos clic al item 'file'
;Para esto comparamos la posicion de x del clic
;Si esta posicion se encuentra entre el rango que ocupan
;todas las letras del item desde su posicion inicial,
;entonces llamamos a la funcion correspondiente del item.
;Para saber si esta dentro del rango del item se dan valores
;fijos en donde empezará el item y donde terminara, de la forma:
; ITEM_X_POS+(LETRA_TAMANO*TOTAL_LETRAS)
;-----------
;En caso de que el clic sea en una posicon anterior o posterior al
;rango, llamamos a la funcion del menu correspondiente que se
;encuentra al lado del actual.
find_file:

cmp word[x_clic],40 ;Comparamos si el clic sobrepasa el limite derecho
jg find_edit ;de ser asi saltamos al 'find' del siguiente
pintar_cuadro 0,21,100,61,[color_fondo_menu] ;limpiamos la pantalla
    call imprime_file ;llamamos la funcion correspondiente del item
jmp finalizar ;finalizamos

find_edit:

cmp word[x_clic],60
jl finalizar
cmp word[x_clic],100
jg find_view
;pintar_cuadro 300,200,70,20
call imprime_edit
jmp finalizar

find_view:
cmp word[x_clic],120
jl finalizar
cmp word[x_clic],160
jg find_seq
call imprime_view
jmp finalizar

find_seq:
cmp word[x_clic],180
jl finalizar
cmp word[x_clic],440
jg find_help
call imprime_seq255
jmp finalizar

find_help:
cmp word[x_clic],460
jl finalizar
cmp word[x_clic],500
jg find_exit
call imprime_help
jmp finalizar

find_exit:
cmp word[x_clic],520
jl finalizar
cmp word[x_clic],560
jg finalizar
mov byte[sacame],1

;--Para finalizar solo devolvemos los valores de los registros desde el stack
;y retornamos a la posicion original.
finalizar:
popa
ret

;--------------------------------------------------
;END: On-Click Actions-Handlers (Manejadores de Clic)
;--------------------------------------------------


;--------------------------------------------------
;BEGIN: On-Click Actions (Acciones de cada item)
;--------------------------------------------------
;Se utilizan 'estados' para saber que accion se realizara antes de
;llamar a una funcion a la que se dio clic en un item del menu.
;Estos estados estan enumerados del 1-7 y cada uno
;corresponde al menu item que se le dio clic.

imprime_file:
pusha

cmp byte[estado_menus],1 ;Si estamos en el estado=1 continuamos con la funcion
je continua
cmp byte[estado_menus],7 ;Si estamos en el estado=7 entonces limpiamos la pantalla
je do_clean
jmp continua
do_clean:
call clear_screen

continua:

pushString file,30,200 ;Imprimimos la accion que se realizó
pushString file_archivo,0,21 ;Imprimimos el submenu 'Archivo'
mov byte[estado_menus],1         ;mueve un 1 a estado_menus si file está activado

popa
ret

imprime_edit:
pusha

;Verificacion de Estados y limpieza de pantalla
cmp byte[estado_menus],0
je _continua
cmp byte[estado_menus],1
pintar_cuadro 0,21,100,40,[color_fondo_pant]
pintar_cuadro 0,100,800,400,[color_fondo_pant]
cmp byte[estado_menus],7
je _do_clean
jmp _continua

_do_clean:
call clear_screen

_continua: ;Accion del Item
pushString edit,30,200
mov byte[estado_menus],2

popa
ret

imprime_view:
pusha

;Verificacion de Estados y limpieza de pantalla
cmp byte[estado_menus],0
je .continua
cmp byte[estado_menus],1
pintar_cuadro 0,21,100,40,[color_fondo_pant]
pintar_cuadro 0,100,800,400,[color_fondo_pant]
cmp byte[estado_menus],7
je .do_clean
jmp .continua

.do_clean:
call clear_screen

;Accion del Item
.continua:
pushString view,30,200
mov byte[estado_menus],3

popa
ret


imprime_help:
pusha 

;Verificacion de Estados y limpieza de pantalla
cmp byte[estado_menus],0
je __continua
cmp byte[estado_menus],1
pintar_cuadro 0,21,100,40,[color_fondo_pant]
pintar_cuadro 0,100,800,400,[color_fondo_pant]
cmp byte[estado_menus],7
je __do_clean
jmp _continua

__do_clean:
call clear_screen

;Accion del Item
__continua:
pushString help,30,200
mov byte[estado_menus],4

popa
ret

;--------------------------------------------------
;END: On-Click Actions (Acciones de cada item)
;--------------------------------------------------


;--------------------------------------------------
;BEGIN: Sub Menu Query (Clic al sub menu)
;--------------------------------------------------

;Aqui identificamos si se le dio clic a un submenu
;actualmente solo tenemos 'archivo' del menu item 'file'
;Se pregunta si el clic en 'Y' y en 'X' esta en el rango
;donde se dibujo el submenu-item y llamamos su funcion correspondiente.
find_sub_menu:
pusha

;En estas comparaciones verificamos qe estemos dentro del rango
;en el caso de no estarlo, entonces salimos de la seleccion
cmp word[y_clic],41
jg sal_find_sel
cmp word[y_clic],20
jl sal_find_sel
cmp word[x_clic],100
jg sal_find_sel

;Limpiamos la pantalla y llamamos a la funcion que nos muestra los
;archivos en un directorio, y ponemos el estado del menu = 6
pintar_cuadro 0,21,340,300,[color_fondo_pant]
call view_dir
mov byte[estado_menus],6

popa
ret

;--------------------------------------------------
;END: Sub Menu Query (Clic al sub menu)
;--------------------------------------------------

;--------------------------------------------------
;BEGIN: (Encontrar el archivo seleccionado)
;--------------------------------------------------

;Aqui se busca secuencialmente el archivo que fue seleccionado para ser abierto,
;ejecutado o pintado.
;Funciona revisando si la posicion del clic del mouse esta en el rango del directorio
;listado, de ser asi, entonces se itera comparando la posicion del clic en Y, con
;un contador que se aumenta con el Tamaño de la altura de el texto por cada ciclo.
;De esta manera se guarda el 'numero' del archivo en una variable 'file_num', que luego
;es utilizada para abrir el archivo numero 'file_num'.
find_selected:
pusha

;Verificacion del rango del clic
cmp word[y_clic],130
jl sal_find_sel
cmp word[x_clic],150
jg sal_find_sel
mov word[y_sel_file],130

;Si el estado del menu sigue siendo 0, entonces se seguira revisando.
cmp byte[estado_menus],0
je try_again

;Iteracion principal
;donde se aumente Y en 20 y se pregunta si el clic fue en el archivo que
;esta mostrado a partir de esa posicion.
;En caso de ser asi, se llama a la funcion 'openfile' que abre el archivo
try_again:
inc word[file_num]
add word[y_sel_file],20
mov ax,[y_sel_file]
cmp word[y_clic],ax
jg try_again
dec word[file_num]
pintar_cuadro 0,21,340,600,[color_fondo_pant]
call openfile
jmp endingsel

;Marcamos el final de la seleccion y se colocan los estados
;definidos para esto.
endingsel:
mov word[file_num],0
mov word[estado_menus],7
jmp sal_find_sel

sal_find_sel:
popa
ret

;--------------------------------------------------
;END: (Encontrar el archivo seleccionado)
;-----------------------------


;--------------------------------------------------
;BEGIN: Secuencia  (0-255)
;--------------------------------------------------

;-----Imprimir secuencia
imprime_seq255:

pusha 
call clear_screen
__continua2:

mov si,0
mov cx,1
mov ax,1
mov bp,25  ;Y position
seqcont:

;--centenas
centenas_seq:
cmp cx,100
jl decenas_seq
mov bh,100 ;divisor
div bh ;dividimos

mov [di],ah
add ax,48

mov [char],ax
call fixFila2
mov [x_origen],si
mov [y_origen],bp
call print_char
add si,12
sub ax,48

mov ax,[di]
;-- fin centenas

;--decenas
decenas_seq:
mov bh,10 ;divisor
div bh ;dividimos

cmp cx,0
je unidades_seq
add ax,48

mov [char],ax
call fixFila1
mov [x_origen],si
mov [y_origen],bp
call print_char
add si,12
sub ax,48
;--fin decena

;--unidades
unidades_seq:
add ah,48
mov [char],ah
call fixFila
mov [x_origen],si
mov [y_origen],bp
call print_char
cmp ax,100
;--fin unidades

inc cx
mov ax,cx
add si,32
cmp ax,256
jne seqcont

mov byte[estado_menus],7
mov si,0
mov cx,0
mov ax,0
mov bp,0
popa
ret
;-----fin imprimir secuencia

;--Aumentar en y si nos pasamos del borde de la pantalla
;unidad
fixFila:
cmp si,800
jg action_fixFila
ret
action_fixFila:
mov si,0
add bp,22
ret

;decena
fixFila1:
cmp si,780
jg action_fixFila1
ret
action_fixFila1:
mov si,0
add bp,22
ret

;centena
fixFila2:
cmp si,760
jg action_fixFila2
ret
action_fixFila2:
mov si,0
add bp,22
ret
;--

;--------------------------------------------------
;END: Secuencia  (0-255)
;--------------------------------------------------


;Este 'metodo' limpia la pantalla sin incluir el menu.
clear_screen:
pusha
pintar_cuadro 21,21,800,580,[color_fondo_pant]
popa
ret

;Aqui hacemos la finalizacion del programa.
_exit_:
mov ax,00h      ;restaura el ratón a sus valores predeterminados
int 33h
mov ah,00h
mov al,03h
int 10h
ret

;----------------------------------------------------------------------------------
;Seccion de inicializacion de variables que se van a utilizar en el programa.


section .data

savess dw 0
savesp dw 0
ancho_letra dw 10
alto_letra  dw 20
xmax dw 799
y_sel_file    dw 0
file_num dw 0
sacame db 0
color_forma_char db 0x00f
color_fondo_pant    db 0x000
color_fondo_menu db 0x002
color_cursor db 0x006
color_pintar        db 0x000
estado_menus       db 0
openstatus        db 0
char db 0
letra  times 200 db 0
pixels times 200 db 0
cadena times 81 db 0

cursor           db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
db 0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0
db 0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0
db 0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0
db 0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0
db 0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
db 0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
db 0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0
db 0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0
db 0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0


MarginBMP_X dw 5
MarginBMP_Y dw 200
boton_file          db 'FILE',0
len dw $-boton_file
boton_edit          db 'EDIT',0
boton_view          db 'VIEW',0
boton_seq          db 'IMPRIMIR_SECUENCIA_NUMEROS',0
boton_help          db 'HELP',0
boton_exit          db 'EXIT',0
file                db 'USTED SELECCIONO LA OPCION FILE',0
edit db 'USTED SELECCIONO LA OPCION EDIT',0
view db 'USTED SELECCIONO LA OPCION VIEW',0
seq db 'USTED SELECCIONO LA OPCION IMPRIMIR_SECUENCIA_NUMEROS',0
help db 'USTED SELECCIONO LA OPCION HELP',0
exit db 'USTED SELECCIONO LA OPCION EXIT',0
archivo              db 'Usted selecciono la opcion Archivo',0
file_archivo        db 'Archivo   ',0
file_program      db 'Programa    ',0
file_vacio          db '          ',0
salir                 db 0
x_origen  dw 0
res    db '5120',0
y_origen  dw 0
x_pixel             dw 0
y_pixel             dw 0
x_clic dw 0
y_clic dw 0
x_origen_cadena dw 0
y_origen_cadena dw 0
x_pintar            dw 0
y_pintar            dw 0
ancho_pintar        dw 0
alto_pintar         dw 0
filename times 81 db 0
bothersomTR dw 01000h
bmpIndex dw 0
bmpW dw 0 ;0x12
bmpH dw 0 ;0x16
bmpData dw 0 ;ah
RED db 0
GREEN db 0
BLUE db 0
DataSET db 0

;pos for file text
x_ini dw 40h
y_ini dw 40h
finalvar dw 0

bufferIDX db 0h

;--------------------------------------------------------------------------
;Seccion de variables no inicializadas que usaremos en el programa.
section .bss
    read_len resw 01h
    filehndl resw 01h
    x_pos resw 01h
    y_pos resw 01h
iobuf resb 03h
startEXE resw 0h



Offline dtoca

  • Jr. Member
  • *
  • Posts: 8
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #9 on: January 06, 2013, 06:56:54 PM »
openf.inc  [Go to "extension" method]

Code: [Select]
;--------------------------------------------------
;BEGIN: Open file
;--------------------------------------------------
;En la siguiente seccion del codigo se utiliza un llamado a interrupcion para leer todos los archivos
;que cumplan con los parametros especificados en la variable 'file_query' la cual
;tiene almacenada los tipos de archivos que se deben encontrar/buscar
openfile:
pusha

mov ax,5
mov [MarginBMP_X],ax
mov ax,200
mov [MarginBMP_Y],ax

mov ax,[x_ini]
mov word[x_pos],ax
mov ax,[y_ini]
mov word[y_pos],ax

mov ax, cs
mov ds, ax

mov ah, 4eh
xor cx, cx ; no attributes
mov dx, file_query
int 21h

;Coloca en filename el nombre del archivo que se encuentra en la
;posición actual del directorio
movcadena filename,9eh
mov word[y_origen_cadena],23

;Este método se encarga de buscar el archivo al que se le dio click,
;hace un loop hasta que lo encuentre.
keep_looking:
cmp word[file_num],0
je extension ;Si es el que estamos bucando verificamos la extensión
dec word[file_num]

mov ah,4fh ;Función para moverse al siguiente archivo
mov dx, file_query ; Filtro de búsqueda
int 21h ; Interrupción, siguiente archivo a buscar

movcadena filename,9eh
jmp keep_looking
;--------------------------------------------------
;END: open file
;--------------------------------------------------

;--------------------------
;Al finalizar la parte anterior se preguntan por la extension del archivo, y asi
;ejecutarlo, mostrar su contenido o dibujar su contenido
;(.BMP,.EXE.*)

;Para verificar la extensión lo que se hace es recorrer la cadena (filename) hasta que se encuentre un '.', a partir de este punto
;se comenzará a comparar las proxima tres letras para saber si cumplen con los requisitos de la extensión ej. EXE 'E','X','E'. Para
;poder comparar debe ser en Mayúscula la extensión. Ej. Si se pone 'e','x','e' no va a funcionar
;--------------------------


extension:

movcadena cadena, filename
add word[x_origen_cadena],150
call print_string


XOR SI,SI    ;Seteamos los registros SI AX Y CX A 0
XOR Cl,Cl
XOR AX,AX
LEA SI,[filename] ;Movemos la palabra a si (SourceIndex) que es un registro para trabajar con cadenas
bucle1:
LODSB ;Extraemos el ultimo caracter de SI y lo colocamos en AL
CMP AL,'.' ;SI ES IGUAL A . SE ACABO LA PALABRA
je seguir
INC Cl    ;INCREMENTAMOS EL CONTADOR, para movernos a la siguiente posición
JMP bucle1  ;volvemos al bucle

;Cuando ya estamos en el '.' se va incrementando el registo CL
;e ir recorriendo el string
seguir:
INC CL
lea si,[ES:filename]
add si,cx ;Sumamos cx a al para que se coloque en la posición deseado
mov dl,[si] ;Ej. Si se definió que el '.' está en la posición '7' le suma 7 a SI y estará en esa posición
cmp dl, "E"
jne _readit_

;Se incrementa para ir a la otra letra y hacer la comparación
INC CL
lea si,[ES:filename]
add si,cx
mov dl,[si]
cmp dl, "X"
jne _readit_


INC CL
lea si,[ES:filename]
add si,cx
mov dl,[si]
cmp dl, "E"
jne _readit_


call p1  ;Switch to loadExe to run program without 4Bh (What Rapito said) and then look on ExE.inc
popa
ret

;--------------------------------------------------
;BEGIN: P1 (Ejecutar .EXE)
;--------------------------------------------------
;P1 Ejecute el programa selecciona '.exe' utilizando la función '4Bh'
;de la interrupción '21h', se le envía 'al,0' indicando que el programa
;se va cargar y ejecutar de inmediato
;-----------------------
p1:

mov [cs:savess],ss
mov [cs:savesp],sp
push ss
push sp

jmp tam1
next1:
mov ah,4bh
mov al,0h ;El '0' indica como se va a ejecutar el programa en este caso se carga
mov cx,0h ;y se ejecuta inmediatamente.
mov dx,filename ;Indico que programa es que se va a ejecutar, en este caso el que se seleccionó
push ds
pop es ;Marco la posición donde se cargará, debe ser en la última variable para que no sobre escriba el programa principal
mov bx,finalvar
int 21h


mov     ss, [cs:savess]   ;Restore SS:SP from saved
mov     sp, [cs:savesp] ;locations.
ret

;tam1 se encarga de crear las condiciones para cargar el programa
;La función '4ach o 400h' es la función que define el tamaño en memoria que va a tener el programa
;y lo reserva para cuando se ejecute la función 4Bh (que se encuentra en p1)
tam1:

add  bx,15
mov  cl,4
shr  bx,cl
mov  ax,cs
add  bx,ax
mov  ax,4a00h
int  21h
jmp next1
ret

;--------------------------------------------------
;END: P1 (Ejecutar .EXE)
;--------------------------------------------------

_readit_:

;-----------------------------------
;Inicio Comparacion .BMP
;-----------------------------------
cmp dl, "B"
jne readcont

INC CL
lea si,[ES:filename]
add si,cx
mov dl,[si]
cmp dl, "M"
jne readcont


INC CL
lea si,[ES:filename]
add si,cx
mov dl,[si]
cmp dl, "P"
jne readcont
;-----------------------------------
;Fin Comparacion .BMP
;-----------------------------------

;--------------------------------------------------
;BEGIN: Leer BMP
;--------------------------------------------------

mov si,200
mov [y_pos],si
mov si,0
mov [DataSET],si ;FLAG DEL HEADER
mov [bmpIndex],si ;Index de bytes leidos
pintar_cuadro 0,21,100,40,[color_fondo_pant]
pintar_cuadro 0,100,340,400,[color_fondo_pant]

mov ah,03Dh        ; the open-existing-file function
mov al,0            ; open mode 0=read,1=write,2=both
mov dx,filename    ; address of zero-terminated string
int 021h            ; call on Good Old Dos
mov [filehndl],ax  ; we'll reuse the filehndl variable,
; but use a different one if you open
; more than one :)
mov ah,03Fh        ; the read-from-a-file function
mov bx,[filehndl]  ; our new (same as old, probably) file handle
mov cx,01h          ; max bytes to read
mov dx,iobuf        ; address of a buffer to read into
int 021h            ; call on Good Old Dos
;mov al,2
;add [bmpIndex],al

againBMP:

;Iteramos hasta encontrar el valor del DataOffset del Pixel Data Array
mov al,10
cmp [bmpIndex],al
jl goonBMP
cmp [bmpIndex],al
je setData

;Iteramos hasta encontrar el valor del WIDTH
mov al,18
cmp [bmpIndex],al
jl goonBMP
cmp [bmpIndex],al
je setW

;Iteramos hasta encontrar el valor del HEIGHT
mov al,22
cmp [bmpIndex],al
jl goonBMP
cmp [bmpIndex],al
je setH

;Preguntamos si estamos en la misma posicion del Pixel Data Array
mov ax,[bmpData]
cmp [bmpIndex],ax
jl goonBMP

;Ponemos verdadero un flag para saber si ya leimos los datos del header
mov al,1
mov [DataSET],al

; Ponemos la posicion donde empezaremos a pintar en Y y en X
push dx
mov dx,[bmpH]
mov [y_pintar],dx
mov dx,[MarginBMP_Y]
add [y_pintar],dx
mov dx,[MarginBMP_X]
mov [x_pintar],dx
pop dx
; -----------------------------------



;Ahora solo volveremos aqui, debido a que ya obtuvimos la informacion
;del header del BMP
againBMP2:

; Guardamos a RED GREEN BLUE
mov ax,[bmpIndex]
cmp [bmpData],ax
je  setBLUE

seteadoBlue:

mov ax,[bmpIndex]
mov dx,[bmpData]
add dx,1
cmp dx,ax
je  setGREEN

mov ax,[bmpIndex]
mov dx,[bmpData]
add dx,2
cmp dx,ax
je  setRED
; --------------------------------------------------

; mov cx,[bmpIndex]
; pushChar cx,20,20
; jmp endBMP

; Reiniciamos el BmpDataOffset del Pixel Data Array
;mov ax,[bmpIndex]
;mov dx,[bmpData]
;add dx,4
;cmp dx,ax
;je  resetIndex
; --------------------------------

resetIndex:
mov ax,0
mov [bmpIndex],ax
mov ax,0
mov [bmpData],ax
jmp readyDraw


readyDraw:
; --Sumamos y obtenemos un color
pusha
mov ax,0
mov ax,[RED]
add ax,[BLUE]
add ax,[GREEN]
mov cx,255
div cx

mov ax,[RED]
cmp ax,0
jg paintRED

mov ax,[GREEN]
cmp ax,0
jg paintGREEN

mov ax,[BLUE]
cmp ax, 0
jg paintBLUE



pintarPIX:
; mov cx,[x_pintar]
; add cx,44
; pushChar cx,20,20

; mov [color_pintar],ax
; pintar_cuadro 5,241,1,1,[color_pintar]
; popa
; jmp endBMP

mov cx,[x_pintar]
sub cx,[MarginBMP_X]
cmp cx,[bmpW]
je incY

mov [color_pintar],ax

pintar_cuadro [x_pintar],[y_pintar],1,1,[color_pintar]
contDRAW:
mov ax,1
add [x_pintar],ax


popa
jmp setBLUE
;---------------------------------------------


jmp endBMP

paintRED:
mov ax,4
jmp pintarPIX
paintGREEN:
mov ax,2
jmp pintarPIX
paintBLUE:
mov ax,1
jmp pintarPIX


setBLUE:
mov al,[iobuf]
mov [BLUE],al
jmp goonBMP
setGREEN:
mov al,[iobuf]
mov [GREEN],al
jmp goonBMP
setRED:
mov al,[iobuf]
mov [RED],al
jmp goonBMP
setData:
mov al,[iobuf]
mov [bmpData],al
jmp goonBMP
setW:
mov al,[iobuf]
mov [bmpW],al
jmp goonBMP
setH:
mov al,[iobuf]
mov [bmpH],al
goonBMP:
mov ah,03Fh        ; the read-from-a-file function
mov bx,[filehndl]  ; our new (same as old, probably) file handle
mov cx,01h      ; max bytes to read
mov dx,iobuf        ; address of a buffer to read into
int 021h           
mov dl,1
add [bmpIndex],dl

;Preguntamos por el Flag
mov dl,[DataSET]
cmp dl,0
je againBMP

cmp cx,ax
je againBMP2
jne endBMP


endBMP:

;pintar_cuadro 120,200,[bmpW],[bmpH],1 ;al lado

mov ah,03Eh        ; close the file
mov bx,[filehndl]  ; yeah, file handle in bx
int 021h          ; call on Good Old Dos
popa
ret


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

incY:
jmp seekEND
incY2:
push dx
mov dx,1
sub [y_pintar],dx
mov dx,[MarginBMP_X]
mov [x_pintar],dx
pop dx
jmp contDRAW


seekEND:
push di
mov di,200
cmp [y_pintar],di
je endBMP2
pop di
jmp incY2

endBMP2:
pop di
popa
jmp endBMP

; pusha
; mov cx,0
; mov [color_pintar],cx

; lup1:

; pintar_cuadro [x_pintar],[y_pintar],3,3,[color_pintar]
; inc cx
; mov [color_pintar],cx
; mov dx,3
; add [x_pintar],dx
; cmp cx,255

; jl lup1
; popa

; jmp endBMP

; ponerBlanco:
; push cx
; mov cl,2
; mov[color_pintar],cl
; pop cx
; jmp contBlanco

;--------------------------------------------------
;END: Leer BMP
;--------------------------------------------------

Offline dtoca

  • Jr. Member
  • *
  • Posts: 8
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #10 on: January 06, 2013, 07:00:51 PM »
ExE.inc [What Rapito posted]


Code: [Select]
;--------------------------------------------------
;BEGIN: Leer .* (Cualquier Archivo)
;--------------------------------------------------
;Dentro de esta sección se lee y se muestra el contenido de un archivo.
;Para realizar esto se hace una iteración donde cada ciclo lee un byte en
;el archivo...
;En cada ciclo se escribe en la posicion siguiente el valor ascii del byte.

readcont:

;Primero que nada se limpia la pantalla
pintar_cuadro 0,21,100,40,[color_fondo_pant]
pintar_cuadro 0,100,340,400,[color_fondo_pant]

;Aqui se usa un llamad a interrupcion para leer 1 byte del archivo.
;El cual esta almacenado en la variable 'filename'

mov ah,03Dh        ; the open-existing-file function
    mov al,0            ; open mode 0=read,1=write,2=both
    mov dx,filename    ; address of zero-terminated string
    int 021h            ; call on Good Old Dos
    mov [filehndl],ax  ; we'll reuse the filehndl variable,
; but use a different one if you open
; more than one :)
    mov ah,03Fh        ; the read-from-a-file function
    mov bx,[filehndl]  ; our new (same as old, probably) file handle
    mov cx,01h      ; max bytes to read
    mov dx,iobuf        ; address of a buffer to read into
    int 021h            ; call on Good Old Dos
    dec word[bothersomTR]

;Aqui se toman precauciones de data 'basura' y verificacion de final de archivo
;se pregunta si hemos leido hasta el limite y se coloca la data que esta en la siguiente posicion
; de la que se acaba de leer en 0.
;En caso de que halllamos llegado al limite, entonces se sale del ciclo.
_again_:
mov byte[iobuf+1],0
cmp word[bothersomTR],0
je _endit_

;Aqui se hace una comparacion de lo que se encuentra en el byte leido
;Si es una tabulacion en ASCII entonces se llama a un metodo que se encarga de
;simular un tab. Al igual con una nueva linea.
cmp byte[iobuf],0Dh
je _newline_
cmp byte[iobuf],09h
je _tab_

;Se escribe lo que esta en el buffer leido
movcadena  cadena,iobuf
mov ax,[x_pos]
mov word[x_origen_cadena],ax
mov ax,[y_pos]
mov word[y_origen_cadena],ax
call print_string

;Se mueve el espaciado.
mov ax,[ancho_letra]
add word[x_pos],ax

;Este es el ciclo que le el siguiente byte del archivo.
_goon_:

mov ah,03Fh        ; the read-from-a-file function
    mov bx,[filehndl]  ; our new (same as old, probably) file handle
    mov cx,01h       ; max bytes to read
    mov dx,iobuf        ; address of a buffer to read into
    int 021h           
dec word[bothersomTR]

;Si no se ha leido lo que se ha pedido leer, entonces salimos del ciclo
;de lo contrario continuamos
cmp ax,cx
je _again_
jne _endit_

;Aqui se mueve el cursor de escritura a una nueva fila y se coloca las columnas en la
;posicion inicial de escritura, tambien se lee el siguiente byte y se continua el loop.
_newline_:
pusha

mov ah,03Fh
mov bx,[filehndl]
mov cx,01h
mov dx,iobuf
int 021h

mov ax,[x_ini]
mov word[x_pos],ax
mov ax,[alto_letra]
add word[y_pos],ax

popa
jmp _goon_

;Para el tab, se escribe el tab y se amentan la posicion de la columna
_tab_:
mov byte[iobuf],020h

movcadena  cadena,iobuf
mov ax,[x_pos]
mov word[x_origen_cadena],ax
mov ax,[y_pos]
mov word[y_origen_cadena],ax
call print_string
mov ax,[ancho_letra]
add word[x_pos],ax
mov ax,[x_pos]
mov word[x_origen_cadena],ax
mov ax,[y_pos]
mov word[y_origen_cadena],ax
call print_string
mov ax,[ancho_letra]
add word[x_pos],ax

jmp _goon_

;Finalmente cerramos el archivo.
_endit_:
mov ah,03Eh      ;close the file
    mov bx,[filehndl] ;yeah, file handle in bx
    int 021h            ;call on Good Old Dos

popa
ret

;--------------------------------------------------
;END: Leer .* (Cualquier Archivo)
;--------------------------------------------------


Thanks for your help.I hope this help you understand ours ideas

Offline dtoca

  • Jr. Member
  • *
  • Posts: 8
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #11 on: January 06, 2013, 07:11:41 PM »
dir.inc Here is where we read the directory   [When you select file -->Archivos]

Code: [Select]
;Es activado cuando el usuario hace click a 'File --> Archivo' y tiene la función se presentar los archivos en el directorio
;La variable 'file_query' se encarga filtrar los archivos que se quieren obtener al ponerse '*.*' se dice que tome
;cualquier nombre y cualquier extensión en caso de que se coloque '*.exe*' sólo se tomarán los .exe
;Las variables 'x_dir' y 'y_dir' son para ubicar el texto en una posición x,y de la pantalla

file_query          db '*.*',0 ; search query, must end with zero, it means -> "*.*" = actual directory but it allows specified the directory...
contenido db 'Contenido',0
size db 'Size (bytes)',0
x_dir dw 0
y_dir dw 100

view_dir:
mov ax, cs
mov ds, ax


;La función 4eh de la interrupción 21h busca la primera entrada en el directorio (handle)
mov ah, 4eh
xor cx, cx ;  Se reicia el registro cx a 0
mov dx, file_query ; En el registro dx se coloca los requisitos de la consulta
int 21h ;Activar Interrupción
jc the_end ; No se encontraron archivos coincidentes con file_query

mov di,[y_dir] ;Para facilidad y rapidez el contenido de [y_dir] lo muevo a di (DestinationSource)

;A Continuación se comenzará a imprimir el encabezado
movcadena cadena,contenido
mov word[x_origen_cadena],0
mov word[y_origen_cadena],di
call print_string

movcadena cadena,size
mov word[x_origen_cadena],150
mov word[y_origen_cadena],di
call print_string

add di,30

movcadena cadena,9eh
mov word[x_origen_cadena],0
mov word[y_origen_cadena],di
call print_string

mov ax,[9ah]   ; 9AH contiene el registro IP
mov [parte_baja_num],ax
mov ax,[9ch]  ;La instrucción 9ch empuja las banderas del registro en la pila
mov [parte_alta_num],ax
call bin_to_ascii ;Convierte el numero de 32 bits del size del archivo en cadena ascii-z
                                    ;devuelve la cadena en numero_ascii

movcadena cadena,numero_ascii
mov word[x_origen_cadena],150
mov word[y_origen_cadena],di
call print_string

call borrar_numero_ascii

;Este método va recorriendo el directorio e imprimiendo los datos hasta que no haya más
find_next:
mov ah,4fh ;La función 4fh busca la siguiente entrada del directorio
mov dx, file_query
int 21h ; Activa la interrupción para buscar el siguiente archivo a buscar
jc the_end ; No hay más archivos que buscar

add di,20 ;Me voy moviendo verticalmente para imprimir cada archivo
movcadena cadena,9eh
mov word[x_origen_cadena],0
mov word[y_origen_cadena],di
call print_string

mov ax,[9ah]
mov [parte_baja_num],ax
mov ax,[9ch]
mov [parte_alta_num],ax
call bin_to_ascii

movcadena cadena,numero_ascii
mov word[x_origen_cadena],150
mov word[y_origen_cadena],di
call print_string

call borrar_numero_ascii

jmp find_next ;Moverse al siguiente

the_end:
ret

borrar_numero_ascii:
push ax
push cx
push si

xor si,si
xor al,al
mov cx,5
ciclo_borrar:
mov [numero_ascii+si],al
inc si
loop ciclo_borrar

pop si
pop cx
pop ax
ret

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #12 on: January 06, 2013, 07:50:11 PM »
Hi Rapito! I don't think it's any part of your problem, but since I noticed it, I'll mention it. You've got bufferIDX defined as "db 0", but you're using it as a word. Being at the end of "section .data", there's probably a "spare zero" after it... but in the case where there's no padding between .data and .bss, it would overwrite "read_len". This is the kind of "come and go" bug that can drive ya crazy! So I thought I'd mention it...

You guys have got a pile of code there! It's going to take a while to digest...

Later,
Frank


Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #13 on: January 06, 2013, 07:51:58 PM »
To begin with in the type of programming your doing, sections are unnecessary. COM files originate @ 100H and data is mixed in with code, so;

Code: [Select]
        [bits 16]

       org      100H
       
       section  .text
       mov      ax, cx
       mov      bx, [filehndl]
       mov      si, startEXE
       mov      di, x_pos
       nop
       ret
       
        section .bss        [bits 16]

       org      100H
       
       section  .text
       mov      ax, cx
       mov      bx, [filehndl]
       mov      si, startEXE
       mov      di, x_pos
       nop
       ret
       
        section .bss
    read_len         resw 01h
    filehndl resw 01h
    startEXE         resw 0h
       x_pos resw 01h
       y_pos resw 01h
       iobuf resb 03h
       

    read_len         resw 01h
    filehndl resw 01h
    startEXE         resw 0h
       x_pos resw 01h
       y_pos resw 01h
       iobuf resb 03h

results in a listing like this


     1                                          [bits 16]
     2                                 
     3                                         org      100H
     4                                         
     5                                         section  .text
     6 00 89C8                           mov      ax, cx
     7 02 8B1E[0200]                     mov      bx, [filehndl]
     8 06 BE[0400]                       mov      si, startEXE
     9 09 BF[0400]                       mov      di, x_pos
    10 0C 90                             nop
    11 0D C3                             ret
    12                                         
    13                                          section .bss
    14 00 <res 00000002>              read_len           resw 01h
    15 02 <res 00000002>              filehndl       resw 01h
    16                                startEXE          resw 0h
    17 04 <res 00000002>                 x_pos       resw 01h
    18 06 <res 00000002>                 y_pos       resw 01h
    19 08 <res 00000003>                 iobuf       resb 03h


and this object code

00  89C8              mov ax,cx
02  8B1E1201          mov bx,[0x112]
06  BE1401            mov si,0x114
09  BF1401            mov di,0x114
0C  90                nop
0D  C3                ret


Note that the data comes immediately after code, regardless section declarations.  Also, because startEXE has nothing reserved it becomes a pointer to x_pos.  Now it does work the way it's in pixel.asm because it's on the last line, but the point I'm trying to make, not good practice. Should be;


    read_len    resw 01h
    filehndl       resw 01h
    x_pos       resw 01h
    y_pos       resw 01h
   iobuf       resb 02h
   startEXE   resw 1


I'm still not clear on which program you're trying to overlay as the examples your giving are already coded into pixel.com. Is it another COM file or EXE.  If it is an EXE and because they have special headers, your code will never work.


Offline rapito

  • Jr. Member
  • *
  • Posts: 3
Re: OS 16Bits Load Programss Issue (4bh & 4ach) Help!
« Reply #14 on: January 06, 2013, 09:45:20 PM »
We just tried with '.ovl' and it works, not really sure why though.
As far as your question goes TightCoderEx, we were trying to load a .COM.

About the section stuff Frank Kotler, thanks a bunch... been fighting a lot with it.