ZX Review #5-6
04 ноября 1997 |
|
Authoring - Trampoline (S. Veremeenko).
Authoring (C) S. Veremeenko DIVING BOARDS The software package Springboard designed to programmistovlyubiteley who have mastered programming in assembler or Z80 I8080. It allows you to immediately only on the basis of the knowledge that acquired programming practice for Spectrum (Orion, Vector, Specialist, etc.). write a quite a full program for the IBM PC. Hobbyists, even in to master programming for 8-bit machines faces significant difficulties in the transition to a more promising and a perfect platform for PC. It These difficulties have caused many spektrumistov to mistrust PC, the illusion of incredible complexity and even the cleverness of this, in general, a good car. Main difficulties faced by "virtuoso balalaika 8-bit" when trying to develop PC: 1. The complex structure of the segmentation and memory-related these problems of distribution and memory management. Has no analogue in any of the 8-bit computers. 2. The need for sufficient complete study of DOS "inside" at the level of interrupt vectors UP How you write your first program, since even the most Simple programm of the 10-15 teams are already required to interact with DOS. 3. Unusual and complex syntax assembler processor I86 (So I'll continue to call all the family PC-shnyh processors). 4. New to spektrumista command system. It is the smallest problem, and it could be and not to mention, since I86 and Z80 fairly close relatives, and for most teams Z80 have complete analogues in the system I86 (but not vice versa!) Tramlin can stretch time solution to all these problems. Its first program on the springboard you can write, even using mnemonics Z80, Although this stage is better to step immediately. Use of the rich and extremely useful system commands I86 only those that have counterparts in the set Z80 - anyway, what to eat soup with tweezers, ignoring lying near spoon. Characteristic features Jumping A program written to assemble a springboard for its structure is not very different from a program written for the Spectrum. It should start heading type: include "keyboard.lib" include "standard.fnt" include "disk.lib" include "s320_200.lib" PROGRAMM Z80 And then write how would write on GENS-4. Header means that you plan to use the keyboard will refer to the floppy drive, hard drive or RAM disk, something you want to display in video mode 13h and meet the standard fonts. The argument of PROGRAMM According to Springboard, that you have have not mastered the command system I86, and he may run into a mnemonic Z80. In this mode, Springboard will pick up for teams Z80 the most suitable replacement of the arsenal of I86, although the use of teams is welcome and I86 in this mode. You can randomly shuffle the team of both sets, Springboard will understand. When the use of mnemonics Z80 is for you to be passed stage, the argument in the function of Z80 PROGRAMM can omit, but the function itself can not be disposed of. Among other things, it allocates memory, sets up equipment machines, prepares information for subsequent correct exit from your program, in short - makes all the grunt work that should make the programmer PC, but to which the unused spektrumisty. If the combined entity of different sets of commands could without too much difficulty, then combine the two syntaxes, you know, is impossible. Since Trampoline use involves a gradual transition from programming style Spectrum programming PC, preference was given to the assembler syntax I86. Most major differences occur at selection stage model of memory and initialization, and it all makes trampoline itself, without your participation, so remember to quite a bit. 1. Where in assembler Z80 You put parentheses to indicate indirect addressing, Requires a square trampoline. Example: gens-4 LD A, (HL) Springboard LD A, [HL] or MOV AL, [BX] 2. Labels and variable names - different objects. The label can be placed only an executable command, and must end with a colon and the name variable might indicate only data and not a colon ends. Example: gens-4 Springboard CALL PROC1 CALL PROC1 ........... ............ PROC1 LD HL, (DATA) PROC1: LD HL, [DATA] RET RET DATA DW # 4000 DATA DW 4000h Note the difference in designation HEX-numbers. 3. Labels and variable names are not constant and can not be directly used in expressions. For translation label or variable name in constant is the operator offset. Example: gens-4 Springboard LD HL, NAME LD HL, offset NAME NAME LD DE, DATA NAME: LD DE, offset DATA .............. ...................... DATA DW 15000 15000 DATA DW 4. Since I86 is 16-bit (minimum) processor, sometimes there is uncertainty when the context of the program can not determine the size of the operand. In such cases have to refine it. Example: wrong INC [HL]; that increment, byte or word? correctly INC [BYTE HL]; increment byte at the address in HL INC [WORD HL]; increment word address of the HL Such situations occur infrequently and are tracked by assembler, so if you are asked to clarify the type of the operand, do not be surprised very much. That is, in fact, all the differences in syntax that you need to remember to start work in the jump. There are other, but with them you will encounter Even then, when the trampoline will you passed stage. From the perspective of a programmer operating in a trampoline in his disposal of computer RAM 65536 bytes, a simple disk interface and coordinate display medium resolution operating mode of the available 255 colors from a palette of 262144 colors. Stack imposed for outside your accessible address space and automatically initialized at startup program. Screen break implemented as a Spectrum, but I register and set interrupt vector in memory is not necessary. Enough to anywhere in the program place interrupt handling routine with a reserved name INTERRUPT, and the team will switch IM2 interruption. Stored in the stack registers interrupt routine is also not needed. Trampoline about such trifles takes care of itself. Interrupt routine must be terminated by a team of RETF. There is another reserved label BEGIN. It should be awarded the team with which your program will start. The command HALT, as usual, makes a pause before the interruption, regardless of what trap mode (IM 0 and IM 2) installed. Disable interruptions can not. When you try to ban interrupt you paralizuete MSDOS, And it will not be tolerated. Correct exit to DOS by team-EXIT. Library Functions Accessing external devices to the PC more often performed by software interrupts. BIOS and DOS provide for this great opportunity, and you can use them almost without restriction, but for beginners it is quite difficult. Therefore, in the "Springboard" introduced a much simpler and more convenient commands to access external devices sold by the drivers, plug-teams include in the header. Despite significant amount of these drivers do not take away from you no bytes of the available address space of your program (65536 bytes). All of them are located in another memory segment, as and stack. Consider some additional commands that You can use by connecting the appropriate driver. Keyboard (keyboard.lib) keyboard.lib complements teams with two teams: KEYBOARDKEY KEYBOARD command sets mode of the keyboard. KEYBOARD 0 - waiting press keys. KEYBOARD 1 - read the key code without waiting. KEYBOARD 2 - joystick mode. Team-KEY at work in zero mode, the program stops and waits for a keypress. If you press in the battery transferred to ASCII. In the first mode command KEY do not stop the program, and immediately produces ASCII thrown down with the flag of Z, if any key is pressed, or 0FFh to set Z, if at this moment do not press any key. Similarly, the function INKEY BASIC. In the second mode command KEY has an argument that can take values from 0 to 13. The argument indicates the group analyzed the keys. For example, in the zero group includes key Left-arrow, right arrow, up arrow, the arrow down "," Left CTRL "," Left SHIFT "," left ALT "and" SPACE ". As you can see, this is similar discharges Kempston-way controller, and the team KEY 0 in the second mode completely analogous to the team read joystick port Spectrum. Keystroke sets 1 in the corresponding a low battery. Simultaneously may be pressed a few buttons. Bit 7 6 5 4 3 2 1 0 0 Space Alt l. Shift l. Ctrl l. Down Up Right Left 1 Enter Back Pg. DW. End Delete Pg.Up Home INSERT 2 7 6 5 4 3 2 1 ~ 3 Alt r. Ctrl r. Shift r. + - 0 8 September 4 UYTREWQ Tab May nothing Pr.Scr. \] [P O I 6 JHGFDSA Caps Sh. 7 nothing nothing nothing nothing ": LK 8 <MNBVCXZ 9 nothing nothing nothing nothing nothing nothing? > klav.tsifr. 10 5 4 9 8 7 * / Num lock 11 + -. 0 3 2 1 6 12 F7 F6 F5 F4 F3 F2 F1 Esc 13 Pause EnterDig ScrLock F12 F11 F10 F9 F8 Screen (s320_200.lib and s256_240.lib) In principle, you can set any video mode and work with him. Driver s320_256.lib establishes a standard video mode 13h, with the resolution 320 * 200 pixels with 256 colors, used in most video games PC. Driver s256_240.lib establishes a non-standard, but convenient to work with 8-bit data mode 256 * 240 with 256 colors. This mode has square pixels, ie circle looks like a circle, but not elongated horizontal ellipse and simple determination. Taken together, this can improve performance of the program 2-3 times due to the exclusion necessary geometric correction and calculation of coordinates pixels. This is important because spektrumisty for the most part people are not rich, and really have to bear in mind the 386SX-33, which is already cheaper SCORPION or profit, if not purchase expensive SVGA-monitor and limit TV-card and work with a TV or reworked CGA-Monitor. Drivers and s320_200.lib s256_240.lib give the programmer a great opportunity. Consider a system of graphic commands. BORDER R, G, B This command sets color of the frame around the screen and has a three parameters, each of which opreredelyaet intensity the corresponding primary color. Parameters can take values from 0 to 5, all of which gives 216 colors. COLOR R, G, B Transmits to the battery code appropriate to order flowers. Meaning of the parameters are the same. In addition, there is another form of This command has one parameter. We will consider it when we get to the "user palette. PLOT Without parameter sets on-screen pixel color is determined by the contents of the battery. In the driver s256 * 240.lib coordinate X is defined by register L, coordinate Y - register H. In driver s320_200.lib calculation of coordinates is more complicated. Contents of register HL (BX) is determined according to the formula HL = X +320 * Y, where X and Y - coordinates of the pixel. In the calculation of the coordinates is difficult to do without the relatively slow teams of multiplication and division, and this mode, the speed drops, although spektrumistu accustomed to the snail's pace of its favorite car, even in this case, the performance seems fantastic. If the battery code 0FFh, pixel color is not changed. This allows you to display sprites on background without distortion. Those pixels of the sprite, through which must translucent background, must be set to 0FFh. PLOT T Similarly, PLOT, but the color of the battery is added to the pixel color. Command displays translucent objects - ghosts, bottles with drinks and stuff. PLOT? Reading in the battery package color from the specified HL pixel. AT X, Y Sets the position to derive the symbol commands PRINT and PRINT T. X and Y can be given directly, the variables in memory or the contents of any registers from the group HL, BC, DE (BX, CX, DX). Drivers s320_200.lib options for 16-bit, because X coordinate in one bytes does not fit, and for s256_240.lib - 8 bit. For example, we give the AT command B, H. In this case, the contents of register B to determine the coordinates X, and H - Y. INK R, G, B Color for subsequent withdrawal characters. PRINT Displays a symbol in the position of AT. ASCII character in the accumulator, font and character size are defined by the activated fonts. Following the withdrawal of the next character position is shifted to the right by an amount determined by the width of the symbol, which is installed when activated font. The background of the symbols and between symbols is preserved (command PAPER no). PRINT T Conclusion translucent characters. The rest is similar to PRINT. FONT <name> Activation of the font. After this team font and size of the characters defined by this font. Whole teams include You can enter multiple fonts, the only restriction - the total of the amount should not exceed 30 - 40 kB. Font 8 * 8 pixels takes 2 kB, and 9 * 16 - about 5kB. PALET <label>, <number programmable color> An extremely powerful team provides a simple means achieve amazing results. All commands have arguments <R>, <G>, , except BORDER, have another form. If you give an argument from 0 to 38, the color of the pixel will be determined by the "user palette, which includes only 39 colors, but they can be reused redefined in the course of the program. To use the palette of the user, must be somewhere create a structure like this: TABCOLOR DB n, R0, G0, B0 DB m, R1, G1, B1 .................. DB z, Ri, Gi, Bi where n, m ,.... z - the number of your color, which appears in teams INK, COLOR, and others, as Ri, Gi, Bi - the intensity of the color components of color. They can range from 0 to 63. It is easy to calculate that a palette of user you are get access to 262,144 colors. To enable the user palette, enough to give the command PALET TABCOLOR, 5 if you want, for example, set 5 colors in your palette. Huge number of colors - not The main advantage of the team PALET. Imagine the picture: night city, against the facade of night club is a police car, leaning on the hood of a police officer and smokes. Twinkling stars that periodically change the color of neon advertising establishments in the windows are visible reflections color music, hanging flasher machines, from time to time flashes a light cigarette. And while does not redraw the screen or one bit! Just in the process interrupt operates a small podprogrammka using Team PALET. How - you already seem to understand. Work with disks (disk.lib) MSDOS provides a very great opportunity to work with disk drives. However, use functions MSDOS requires some training. A complete study of the disk service MSDOS can take a long time. Therefore, at first, better to use a much simpler and more understandable to driver commands disk.lib. Commands are simplified to the extent possible. Of course, disk.lib does not use 10% of capacity MSDOS, but for those who only yesterday spitting, trying to squeeze something from TR-DOS, its ability to impress. At first, enumerate limitations disk.lib compared with MSDOS. All work is performed in a single directory, and precisely in the fact of which was running your program. If program was started from a floppy disk, hard disk in the directory C: \ GAMES \ DIZZY or electronic disk, the read and write it will only get there. This is quite a natural restriction for game programs, electronic magazines and so beloved hobbyists "DEMO". At the same time allowed to work with only one file. This is typical for TR-DOS, so that spektrumisty special inconveniences are not feel. Maximum file size is limited to 16 MB. On a floppy disk so file, of course, will not be included because that this restriction is not so scary. Not supported by work with file attributes. You can only use regular files. Now consider the commands disk.lib. FILE <file name> This team, we indicate with which file are going to work. If the filename is omitted, then as the name used string pointed to by register pair DE (DX). DELETE <file name> Deletes the specified file. Condition defaults the same. CREATE <file name> Creates a new file of zero length with the specified name. Condition defaults the same. LOAD A, B, C, D Reading from the file specified the last team FILE. Parameters: A - the address where will be reading. May be a sign, a variable name or the most variable. Absolute assignment addresses may not have sense. Why? Few think and understand. B - number of read bytes. Can be defined absolutely, as a difference of marks or the contents of the variable. Maximum - 65535. C and D. Determine the displacement start reading from the beginning of the file. If omitted, the file read from the beginning. The entire file is composed of a number of pages to 256 bytes, the same sectors in TR-DOS. C - the page number (the word, the range 0-65535), D - displacement within the page (byte, range 0-255). These parameters can be set directly or as variable names. If your set shift exceeds the real file will install the flag C and give the battery code errors. So do all the teams with too disk.lib familiarity. SAVE A, B, C, D Writing to a file. Meaning of the parameters are the same. If you write in the file, there exist data replaced writeable. If length of an existing file does not allows you to record the demanded number of bytes, or if you set the offset close to his end or even at the end of the length file will automatically increase until required. So you can safely write 60 kB to the newly created file with zero length. Jobs at Springboard To begin a trampoline, you must first run it. He has a name tramplin. com. Once launched, you will see on screen menu with the following items: 1. Editor 2. Assembler, without listing 3. Assembler with listing 4. Trial run 5. Conditions of registration Exit to DOS is carried out on ESC. If you press 1, y You will be asked to enter a filename, with you are going to work. The name of the file is stored on the fly work session, and all programs package will use it, until you enter a new one. After enter the name you enter the editor where you can get started with new file or continue with the existing ones. After exiting the editor, you can try proassemblirovat program selecting 2 or 3. If you working with the hard disk - no problems, but if there is no hard drive, Think twice before choosing assemble with the listing. Listing a large program can have a size of 1.5-2 MB, and check on the possibility of placing file is not performed, because advance this size is not known. Could be trouble ... If you have not admitted error can then assemble give a trial run and see what do you navayal. If your program does not "hang" the computer, and you have not forgotten about the need dependence to complete any of your program command EXIT (required!), then exit are returned to the trampoline and will continue. Near-term prospects Currently we are working to create a new library Modules: drivers, mouse, printer, sound, built-in RAM disk. Will write a new Display Driver with Buffered screen, which uses the method "Dirty squares. Appendix: examples of the use of library functions. KEYBOARD 0 ............... KEY CMP AL, 27 JZ KEY_ESC; pressed Esc ............... KEY_ESC: EXIT KEYBOARD 2 ............... KEY 0 CMP AL, 00010110b JZ UP_RIGHT_FIRE; if both are pressed , Up, Right, Ctrl-left COLOR 0,5,0 MOV BL, 128; X-coordinate MOV BH, 120; Y-coordinate PLOT; yarkozelenaya point ; In the middle of the screen INC BL PLOT? ; AL = color code the next ; Horizontal BORDER 1,2,3; curb olive FONT MICRO; set the font , (If you have one) ; INK 0,1,3; we print color ; Navy AT 30,52; the upper left corner of the symbol ; Will coord. X = 30, Y = 52 PRINT T; print transparent font PALET NIGHT, 5; lips. May a palette registers , "Night" ............... NIGHT DB 0,0,10,22; 0 Reg. blue star DB 1,10,0,0; a reg. smoldering cigarette , In the teeth of a bully DB 5,0,20,0; 5 reg. cat eyes DB 11,17,17,17; 11 Reg. gray cat DB 4,0,47,0; 4 Reg. green light NIGHT1 DB 0 WPAL DW offset PFL3 CREATE 'NIGHT.PAL'; create a file SAVE NIGHT, NIGHT1-NIGHT; record there palette LOAD [WPAL], 4,0,7; read from the file ; A variable PFL3 4 bytes starting at 8 from the beginning of the file MOV DX, offset F_NAME DELETE ; Remove a file whose name in the variable F_NAME ......................... F_NAME DB "NIGHT.PAL", 0 WARNING: the program itself DIVING BOARDS you'll find in the catalog ZX REVIEW. *
Other articles:
Similar articles:
В этот день... 21 November