BBS: Inland Empire Archive Date: 03-11-92 (01:11) Number: 78 From: JEAN CREPEAU Refer#: NONE To: TIM LAWING Recvd: NO Subj: Bsave Conf: (2) Quik_Bas
In a message to ALL, TIM LAWING wrote: TL=> I have a screen that I want to save. I have tried to understand this from a couple different manuals, still not clear. The screen is Screen 0. Someone please explain to me the process of reading the screen and placing it into a file. Please explain Def Seg to thanks. The video image is stored somewhere in memory of your computer. This area of the memory is usually called video RAM. First of all, you must understand how the memory works and how your micro-processor can access it. The memory is divided into 'cells'. Each cell has a different adress and can hold a byte. A byte is a collection of 8 binary digits (bits)... Thus each cell can hold a value between 00000000 to 11111111 (binary) or 0 to 255 (decimal). With the old 8086, the CPU (micro-processor) can access up to 1Meg (2^20 = 1 048 576) bytes of memory. Then you need 1 048 576 different adresses to access each of these bytes. A full adress needs 20 bits to be represented. Physically, that means that your micro-processor has 20 electrical nets that tells the memory "Hey! I want to know what is the content of that cell". The memory then returns the specified byte to the CPU. In the 8086, you have no registers (hardware variable) of 20 bits that could hold a complete adress. Intel had to use an indirect way to get these adresses of 20 bits with the registers available. Usually a register is 8 or 16 bits wide. So Intel took two registers of 16 bits (a segment register and an index (offset) register. The final adress was computed with the following formula: Adress = Segment * 16 + Offset Usually, we do not specify adresses (segments or offsets) in decimal... Binary is more direct, but it is much too long to write 20 0's or 1's every time we need to specify an adress!!! So we use hexadecimal that is closely related to binary. Bits are grouped four-by-four to form a single hexadecimal (base 16) digit. This is the translation table bin2hex: 0000 - 0 0100 - 4 1000 - 8 1100 - C 0001 - 1 0101 - 5 1001 - 9 1101 - D 0010 - 2 0110 - 6 1010 - A 1110 - E 0011 - 3 0111 - 7 1011 - B 1111 - F If we write the adress formula into hexadecimal, we have: Adress = Segment * 10h + Offset 10h means 10 in hexadecimal and it is equal to 00010000 in binary and 16 in decimal. Now! The video RAM is always located at the same adress in memory. This adress is B0000h for monochrome cards B8000h for color cards To translate these adress into segment and offset, a simple simple way to do so, is to take the 4 first digits as the segment and the last one as the offset. Then B0000h = B000h:0000h and B8000h = B800h:0000h. We usually write an adress either in the full 5-digit form or with the segment:offset form, which is more explicit. Now you know everything about segments! When you want to do a BSAVE or BLOAD, you must specify in which segment these commands take place. Since it is to be used with your video RAM, you either do DEF SEG = &hB000 ' for mono cards or DEF SEG = &hB800 ' for color cards With BLOAD/BSAVE, you cannot specify full adress, you can only specify the offsets. All the adresses have to be in the same segment. Screen 0 is at the offset 0 (0000h). The syntax for BLOAD/BSAVE are: BLOAD filename$ [,offset] This command loads a command saved with BSAVE. If you specify no offset, the segment and offset saved into the file are used. If you specify offset, the file is loaded at the adress specified by the last DEF SEG definition and the offset. BSAVE filename$,offset,lenght This commands save the memory area beginning with the adress specified by the last DEF SEG and the offset for the number of BYTES specified. To save screen 0, you must save 4000 bytes (80*25*2 = 4000) from the adress B000:0 or B800:0. For examples: DEF SEG = &hB800 ' defines segment of video RAM (color) BSAVE "SCREEN0",0,4000 ' saves screen 0 to file "SCREEN0" DEF SEG = &hB000 ' defines segment of video RAM (monochrome) BLOAD "SCREEN0" ' loads SCREEN0 at the adresse saved by BSAVE (B800:0) BLOAD "SCREEN0",0 ' loads SCREEN0 at the adresse B000:0. It is necessay to specify the offset 0 if you want QuickBASIC to use the correct segment. DEF SEG = &hB800 ' def video RAM seg (color) BLOAD "SCREEN0" ' loads SCREEN0 into screen 0 BLOAD "SCREEN0",&h1000 ' loads SCREEN0 into screen 1 BLOAD "SCREEN0",&h2000 ' loads SCREEN0 into screen 2 BLOAD "SCREEN0",&h3000 ' loads SCREEN0 into screen 3 Hope it helps you to understand! Jean --- * Origin: INTERACESS Montreal (QC) Canada (514) 528-1415 (1:167/280)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET