Re: A83: Resize a program...


[Prev][Next][Index][Thread]

Re: A83: Resize a program...




Look for my comments in-line. I suggest
that you check for enough free memory
before inserting, the insert routine
does not check.

I only took a quick look so I may have
screwed up.

below is the header file for it:

;---------------------------------------------------------
;   INSERTMEM : INSERT SOME FREE MEMORY INTO USER OR     |
;               TEMP MEM. THIS ROUTINE WILL ONLY OPEN    |
;               THE WHOLE IN MEMORY, IT WILL NOT INIT    |
;               THE MEMORY, OR ADJUST ANY SIZE BYTES OF  |
;               DATA, THAT MUST BE DONE EXTERNAL TO THIS |
;               ROUTINE.                                 |
;                                                        |
;               DO NOT INSERT WITH THE START OF THE INSERT
;               POINTING TO THE 1ST BYTE OF THE DATA TYPE I WANT TO INSERT ON.
;               IF I DO THIS I WILL ADJUST THE PTR IN THE SYM TABLE
;               THINKING IT MOVED. SO I SHOULD SEND THE POINTER AT THE
;               END OF THE DATA, MIDDLE OR 2ND BYTE WHICH EVER IS
;               BEST FOR THE ROUTINE CALLING INSERT MEM.
;
;
;           INPUT :                                      |
;                   HL = # BYTES TO INSERT               |
;                   DE = ADDRESS OF 1ST BYTE FOR INSERTION
;                   ENOUGH MEM WAS DONE ALREADY, SO THERE|
;                   SHOULD BE SUFFICIENT RAM. I CANNOT HAVE
;                   GARBAGE COLLECTION DONE DURING THIS ROUTINE
;
;           OUTPUT:                                      |
;                   ERROR IF NOT ENOUGH MEM              |
;                   ELSE                                 |
;                   DE = ADDRESS OF 1ST BYTE OF INSERTION
;                   MEMORY INSERTED                      |
;                   ALL DATA PTRS ADJUSTED FOR INSERTION.|
;                                                        |
;                                                        |
;          



Sebastiaan Roodenburg wrote:
> 
> Hi!
> 
> I want to resize a file from within a program, for dynamicly memory
> allocating.
> To increse the filesize of an file with 20 bytes, i've wrote the
> folowing code:
> 
> Main:           ld hl,file
>         rst 20h                 ; copy 9 bytes from (hl) to (OP1)
>         call _chkfindsym
>         push hl
>         push de
>         ld h,d
>         ld l,e
>         call _ldhlind           ; ld hl,(hl)
>         push hl
>         inc de
>         inc de
>         add hl,de
>         ex de,hl

DE = BYTE AFTER THE EXISING PROGRAM, POINT OF INSERTION.

>         ld hl,20
>         call _insertmem         ; insert 20(=hl) bytes from de to 9327h
>         pop hl
>         pop de
>         ex de,hl


WHY ARE YOU DOING THIS?
YOU INSERTED AT THE END OF THE PROGRAM.


>         ld bc,-20
>         add hl,bc


>         ex de,hl
>         push de
>         ld bc,20
>         add hl,bc
>         ld a,l
>         ld (de),a
>         inc de
>         ld a,h
>         ld (de),a
>         pop de
>         pop hl

YOU DON'T NEED TO WRITE TO THE SYMBOL
ENTRY. IT WILL BE MODIFIED FOR YOU IF 
NEEDED.

>         dec hl
>         ld (hl),e
>         dec hl
>         ld (hl),d
>         ret
> file:   .db     05,"TEST",0
> 
> When i run this program, the file 'TEST' gets 20 bytes larger, but not
> the way i want it: it writes a new size-word 20 bytes before the start
> and updates the vat, but the insertmem doesn't work: it just overlaps a
> file/data before prgmTEST...
> 
> Can someone tell me what's wrong or help me with an working resizer????
> 
> Thanx for any help,
> 
> Sebastiaan Roodenburg
> sebastiaan@rimsystems.nl
> 
>   -------------------------------------------------------------------------------
> 
>    Part 1.2    Type: application/ms-tnef
>            Encoding: base64


References: