Info Guide #02 |
|
Assembler - A short lesson in assembler for lamer (continued)
Lesson assembler lamer. (Continued) Today I'm going to tell you about methods of interrogation keyboard interrupt, and also try to fix their mistakes, which made the previous issue. 1. I'll start with the error. The last time I was so scared uploaded a description of the assembler directives, and very incomplete and misleading description. But if you read carefully the text of ALASM, it is more likely to have missed this nonsense by ushey.Dalneyshee refers to those others who believe this delirious and did not read opisaniya.Vo avoid. We can not say that the directive does not take place in pamyati.Vzyat least DEFB (DB): She, of course, not a command processor, but the memory of eating honest: as much as bytes of information after it zapisano.Ili another directive: DUP 8 RR C RLA EDUP After compiling this piece will look like this: RR C RLA RR C RLA RR C RLA RR C RLA RR C RLA RR C RLA RR C RLA RR C RLA Moreover, it takes more memory than RR C RLA After all, while all of this memory is populated entirely processor commands! About the directive ENT I wrote a full erundu.Skazhu honest: it's because I was yet once it does not really ispolzoval.Na this directive goes in tandem with DISP and the lower limit a piece that DISP top ascribed to work in other address (es not to the address on which this piece compiled). Example: ORG # 6000 LD HL, KUSOK LD DE, # 4000 PUSH DE LD BC, KUSEND-KUSOK LDIR RET KUSOK DISP # 4000 <Kind of a program completely stuffed CALL, JP, etc., and because conflicts between> ENT KUSEND By the way, if you tag KUSOK KUSEND and insert inside a block DISP-ENT, these tags just like everyone else in this block, will be recalculated and, naturally, will not contain those values which we would wanted. The directive ORG is permissible two parameters, and if the two of them, then the second - is the number of pages, where we compile. And the program is run, incidentally, is not the first ORG, and the last! Directive INCLUDE <name> [] used to load modules for the long programs. When compiling an assembler, stumbling on this directive loads the appropriate file (if it's not in memory) compiles it, and then continues compile the main program to the point where it was interrupted. Directive INCBIN <name> [ ] loads the code file (by the way, you can ukazyat extension through the point) on the current at compile time, and moves this address compiled at the end of this file. 2. Poll keyboard. The keyboard of the old ZX Spectrum 48k klavish.Ostalnye contained 40 key enhanced keyboard are a combination of both, For example BREAK = CAPS / SPACE, EXTEND = CAPS / SYMBOL, TRUE VIDEO = CAPS / 3, etc. 40 keys are collected at 8 poluryadov 5 keys in each: # F7FE: January 2 3 4 5 # EFFE: 6 7 8 9 0 # FBFE: Q W E R T # DFFE: Y U I O P # FDFE: A S D F G # BFFE: H J K L Enter # FEFE: CapsZ X C V # 7FFE: B N MSymSpace After a while I explain what it is for the number on the left, but first tell you about how the processor works with peripheral devices (ie, generally with all devices except memory). ____ Devices are selected IORQ = 0 (ie When this signal is active). Then the device v_kotorye record must verify that WR = 0 (t.e.aktiven recorded signal) and device iz_kotoryh receive data, check that RD = 0 (active signal reading), and afterwards, all devices are checked certain combination of address signals, which have each device has its own. For example, the beeper (BEEPER) is selected when A0 = 0. Where are these signals? Naturally from the processor. Combination ____ __ IORQ = 0, WR = 0 produced by teams OUT, and kombinatsiya____ __ IORQ = 0, RD = 0 - When teams IN. Like, we are on these teams have not talked about. So: OUT (), A - burn the battery in the port, whose address is: A (Senior B) * 256 + (Low byte). Contents the battery is displayed on the data bus. Port address, of course, is displayed on the bus address. OUT (C), <register> - write register in port, whose address is contained in the register pair BC. Register can be: A, B, C, D, E, H, L. OUT (C), 0 - to record a zero in the port BC.Komanda undocumented, many assemblers are not supported. On the processor Z180 resets. IN A, () - read data from port in the battery. Port Address = A * 256 + . IN <register>, (C) - to consider a case data from the port of BC. IN F, (C) - read data from the port of BC without remembering. Instead, appropriately set the bits of the flag register. (In what way they are set, not znayu.U Larchenko and Rodionov not specified.) Team undocumented. In some assemblers, it is written as IN (HL), (C). Teams IN r, (C) and OUT (C), r are called appeal to the port with complete addressing, in Unlike incomplete address OUT (b), A. Ko many ports (including a musical coprocessor AY) can only be accessed with fully addressed. There are also commands to access block portam.Mne somehow did not have to use them. Those mysterious numbers that I cited against the names of the keys to poluryadah are just addresses relevant portov.A read from these ports are the following: bit 7 - not defined; Bit 6 - reading from the tape. In many computers is not implemented. In some it is implemented so that there is read random values (due to the fact that I forgot mask this bit of AND, in the first issue terribly sausage arrow); bit 5 - not defined; Bits 4-0 - key state poluryada. If a key is pressed, read 0, and otherwise - 1.Bolee lower bits are more extreme keys. Example of use: START CALL <routine> LD A, 239; byte poluryada 6-0 IN A, (254), reads data RRA; 0-th bit goes into CY JR C, START; cool, until they click 0 In fact, every keyboard port chosen for two thrown down bits: bit 0 and even to some in the range of 8 to 15.Esli to lose a few bits, will choose Several poluryadov, and their contents will overlap by AND. Example: LOOP XOR A; all bits cleared IN A, (254); polls all poluryady CPL; almost equivalent to a combination of: AND 31; AND 31: CP 31, but shorter JR Z, LOOP; until they click ANY KEY Another method is to survey key the use of sub-ROMs and the results of interruption of IM 1.Naprimer, the procedure for 8020 resets CY, if pressed BREAK. And working with an IM can be as follows: RES 5, (IY +1); reset flag "ANY KEY" NOKEY HALT; if you remove HALT, can stock BIT 5, (IY +1); Snooty on the neck. com! JR Z, NOKEY; until they click something LD A, (23560); sist.peremennaya LAST_K As a result, the battery will be code the last key pressed. Be careful: If you set CapsLock, then you will be read out completely big letters! A set CapsLock can be as follows: LD (IY +48), 8; sist.peremennaya FLAGS2 In his AC Edit I successfully combine both ways of polling keys. 3. Some of the other ports. The same port (254), is selected to record responsible for the color change curb, squeaker and output to tape. Bits of it are: Bits 7-5 - not used; Bit 4 - state pischalki.Chtoby cause sound, you need to constantly switch on bits; Bit 3 - output to tape; Bits 2-0 - Color bordyura.U curb may be 8 different colors. Brightness in these colors otklyuchena.Chtoby get on the curb static images, you need every time from the beginning of human interruption in some way to change this color, while the electronic beam draws the screen. Example: XOR A; black OUT (254), A; border turns black Port 31 (# 1F) to read the story about state Kempston joystick: Bits 7-5 - is always equal to 0 if the joystick connected, and otherwise on their status can not say anything definite; Bit 4 - fire (1 - pressed, 0 - released); Bit 3 - down (similar); Bit 2 - up; bit 1 - right; Bit 0 - left. Port 32765 (# 7FFD) - Expansion Port memory (on record). Impossible to read (In addition to several pathologists). Appointment bits: Bits 7-6 - on the 128k not being used; Bit 5 - snap the port # 7FFD. If this bit is set, the computer becomes forty eighth with all the ensuing posledstviyami.Posle reset everything back to normal; Bit 4 - If 0, the address will stick 0-16383 128-e PZU.Obychno do not need it, and this bit is set to 1, whereas in the lower addresses will have 48 e-ROM; bit 3 - the number of the screen: if 0 - then the usual "first" screen 16384-23295 of page number 5, otherwise - "second" screen from the pages of Number 7; Bits 2-0 - number of pages of memory to be placed in the region 49152-65535. Here you need more detail. All at 128k, you guessed it, 8 pages of memory to 16k. From 16384 to 32767 always page number 5, from 32768 to 49,151 - Page number 2, but the above - has any, what you like (including 2 or 5). Upon leaving the assembly is installed Account number 0, the assembler itself in number 4, the monitor in the number 7, and the text of your program is likely to number 6. Page № 3 assembler uses a table of labels. So: If you're not going to use the monitor, feel free to be overwritten by page number 3 and number 7. (Just do not Assemble at number 3 and number 7 with # C000 on # C8FF, since it is used as buffer at podgruzku Disk.) Pages number number 0, 1, unconditionally free. And if you become really quite closely, you can overwrite and assembler with sources (respectively number number 4, 6). , There are, of course, Spectrum'y and with great memory (up to 2 Mb), but distributed they are small. So what to write for them is not worth the more so still you can not fully use all the features of extended memory, not having any. Due to the large number and variety of pathologists with different versions of the decryption port # 7FFD, there was a so-called problem of port # FD.Nazvanie it due to the fact that computers "Pentagon-128" decoding port extended memory is only 2 bits: A1 and A15, as a result of this port was made possible refer to incomplete address: LD A, 23, 7-I Page OUT (# FD), A; write its number in the port You will not find it more convenient than LD A, 23 LD BC, 32765 OUT (C), A That's how many, and thought, and in many programs (eg, by CodeBusters) is it is part addressing the port. Of course, on some computers, such programs do not work. For example, the above example of the "Scorpio" will perceive as appealing to the port # 1FFD, and this is, of course, quite a different port (switching TURBO, inclusion in the region 0-16383 page shadow RAM № 8, shifting shadow pages RAM, ROM, and still do not know why). I believe (and many others also think so) that all Spectrum equal, and if program does not work in some places because of that trifles as incomplete decoding ports, this is a bad program. Of course, some things, such as digital music with high quality can be realized only in certain types of Spectrum ("Pentagon", KAY, ATM, etc.), but that's another problem. It let you Uncle Zonov explains why in its computer processor brake general field pamyati.A speaking on joint account, if the only support "Pentagon" (I say this despite the fact that I myself "Pentagon"), then sinkleristy who use other types of Spectrum (and their not less than 40%) could be seriously offended and withdraw from the Spectrum. Good for us from this be? That's it. Incidentally, even the demo now working on "Scorpio". Learn! Ports 65533 (# FFFD), 49149 (# BFFD) are responsible for access to music coprocessor AY.U coprocessor 16 registers for different purposes. In order to write something any of them, you need to send its number to port 65533, and then data to this register, go down to the port 49149.Esli should, conversely, to read the data, then after recording the number in the register of port 65533 to read data from the same port 65533. All analyzers, the volume in all sorts of boot ' oh it was based on the reading of the AY. The appointment of separate registers: Number number 0, 1 - contains 12-bit period (Not the frequency, namely, period!) Notes in channel A. And register 1 - Senior; Number number 2, 3 - the period of the channel B; Number number 4, 5 - the period of the channel C; № 6 - Five digit period of noise; № 7 - Sound Control: Bits 6,7 - indicate the direction of exchange on the parallel port, and therefore we not interested; Bits 3-5 - if 1, then allowed the conclusion noise, respectively, in channel A, B, C; Bits 0-2 - if 1, then allowed the conclusion Notes to the channel A, B, C. But instead, if you manipulate the volume in the corresponding channel, we can get digital music! A If the envelope is included, then it will sound by itself! № 8 - 4-bit channel volume A. Note that the scale of loudness is not linear, but rather, logarifmicheskaya.Esli set 4-th bits of this register, then the volume will not be, and instead of coming on the envelope; № № 9,10 - and similarly for channels B, C; № № 11,12 - the period of the envelope. When playing audio on the envelope used only the lower byte (№ 11); № 13 - 4-bit form of the envelope: 0 - fade to zero; 12 - sawtooth sound; 13 - smooth increase to a maximum; 14 - zigzag sound an octave lower than 12; № № 14,15 - used for the exchange of parallel ports. Of course, it is unlikely you'll play themselves music through a direct appeal to AY, so that As an example, show just how off the sound: LD DE, # E00 LD C, # FD OFF0 LD B, # FF DEC D OUT (C), D; select number register LD B, # BF OUT (C), E; writes a zero JR NZ, OFF0; and so on until the 0-th register 4. Interrupts. Every 20 milliseconds (1 / 50 seconds) to CPU staff come preryvaniya.Eto reflected in the fact that, at the foot INT served negative pulse. Pulse length, as usual, each has its own pathologist, but do not talk about it. If, during the pulse were enabled interrupt (command EI, off they command DI), then, depending the current mode interrupts, the processor will perform the following: a) (IM mode 0) command, which came with the data bus (not used); b) (IM mode 1) subroutine RST 56; c) (IM 2 mode) subroutine, the address which he read from a cell with address: I * 256 + , where I - register interrupt vectors. In any case, before entering the interrupt routine the processor disables interrupts. At the moment we are most interested in regime IM 2, t.k.v this mode, you can insert your own handler. Since the state of the data bus is not defined in the general case (ie, not at all computer read out stably 255), it is desirable that the address of the handler not dependent on the state of the data bus:). This achieved a uniform filling of the same numbers of so-called interrupt table, length 257 bytes (for each of the 256 possible states of the SM from the table is read the same two bytes). Moreover, this table should be placed in the so-called fast memory (page number 0 or number 2), and some pathologists may podvisnut ... Example: MUZ EQU # C000 ORG MUZ + INCBIN "MUSIC" ORG # 6000 DI CALL MUZ; initialize music LD HL, # FE00 LD A, H LD I, A; I = # FE LD DE, # FE01 LD BC, # 100 LD (HL), # 5C LDIR; fill in the interrupt table LD L, (HL) LD H, L; HL = # 5C5C LD (HL), 195; JP INC HL LD (HL), IMER INC HL LD (HL), 'IMER IM 2 EI <More program will work the music> IM 1; turn off IM 2 JP MUZ; turning off the music and leave IMER PUSH AF PUSH BC PUSH DE PUSH HL PUSH IX PUSH IY CALL MUZ +5; call music POP IY POP IX POP HL POP DE POP BC POP AF EI RET That is, if you hang on to interrupt any action (such as playing music), the program no longer has to be this is followed, and we get a kind of multitasking (many, but not two-, because nothing prevents us to hang on interruption of several different tasks, such as music and multicolor). With enabled interrupt can not be included in TR-DOS, except at the first call TR-DOS interrupt disappears and in its place will BASIC.I when returning from interrupt we get a little bit the wrong way:). Way to get around this, given in the book "TR-DOS for users and programmers. "In fact, this is not nuzhno.Prosto disables interrupts at the entrance to TR-DOS. If you do not have enough space under the table break, put it in slow memory, For example, at # 5B00.No note that if your program will not work vezde.Esli and slow is not enough memory, you can leave the table only 2 bytes of at I * 256 255 (as done in TLW2). This you have greatly reduces the number of its polzovateley.Samy latest version: I = 59. Then the table (the length of 257 bytes to 48k, or 2 bytes to 128k) will be in ROM, and the procedure interrupt handling - at 65535.Postavte there JR, and at 65,524 (to indicates JR) put the handler. Now performance of your program, in addition to computer model, is limited more and version Rom ... 5. Useful tips. It is best to start typing program with the lines: ORG # 6000 LD (QUIT +1), SP QUIT LD SP, 0 LD IY, 23610 IM 1 LD HL, 10072 EXX EI RET END Who knows what registers can ruin your program while it's still buggy? A END tag allows you to always know the length of the programmy.Dlya after assembly in command mode, type: COUNT END-# 6000 The Council is also put into the program subroutine print 16-digit numbers and call her from time to time in the main loop program. This will allow you to control the crash. Subroutine sm.v Section "Etudes". Write a program beautiful and convenient for ispravleniya.Chasche use CALL.Vydelyayte complete functional block in the subroutine, even if it is invoked only a raz.Sohranyayte registers podprogrammah.Ne think about shifting ability, use instead of JP JR. All address tables, music, sprites, etc. record in EQU.Eto allows you to easily change these addresses, if that. Recent experiments have shown that even numbers are used memory pages can change, and they, too, must enter in EQU. When your program exceeds 4k (as in I have 3 such programs), the text will not be placed in the 16k-buffer. Have to select a module and load it on the directive: INCLUDE "MYUNIT", a It will be loaded into another page and this will allow you to simultaneously edit both teksta.Dlya module should be selected routines that you do not have to fix a long time (I call their "immortal"). Loads INCBIN'om data pages except that only during otladki.Luchshe just load them directly onto tail of the program, and then flip LDIR'om. Then the program will be easier to ship in compiled form and zapakovat.Stoit to say that prog, scattered the page, to pack at all in any packer can not? To be continued ...
Similar articles:
В этот день... 21 November