Contents |
Keyboard Assignment |
NORMAL COMMAND SHIFT FUNCTION GRAPHICS ZX80/CMD ZX80/SHFT 1 1 <edit> -- 1000 1 NOT 2 2 AND -- 0100 2 AND 3 3 THEN -- 0001 3 THEN 4 4 TO -- 0010 4 TO 5 5 <left> -- 0101 5 <left> 6 6 <down> -- 0011 6 <down> 7 7 <up> -- 1100 7 <up> 8 8 <right> -- 0101 8 <right> 9 9 <graphics> -- -- 9 <hide???> 0 0 <rubout> -- -- 0 <rubout> Q PLOT "" SIN 0111 NEW 1010 W UNPLOT OR COS 1011 LOAD 0011 E REM STEP TAN 1110 SAVE 1000 R RUN <= INT 1101 RUN 0100 T RAND <> RND 0110 " " 0022 Y RETURN >= STR$ 1001 REM " U IF $ CHR$ -- IF $ I INPUT ( CODE -- INPUT ( O POKE ) PEEK -- PRINT ) P PRINT " TAB -- "?" * A NEW STOP ARCSIN 2222 LIST 2222 S SAVE LPRINT ARCCOS 2200 STOP 0110 D DIM SLOW ARCTAN 0022 DIM 0010 F FOR FAST SGN 2211 FOR 0001 G GOTO LLIST ABS 1122 GO TO 2200 H GOSUB ** SQR 2222 POKE ** J LOAD - VAL -- RANDOMISE - K LIST + LEN -- LET + L LET = USR -- "?" = ENTER newline function -- newline <edit> SHIFT -- -- -- -- -- -- Z COPY : LN -- "?" : X CLEAR ; EXP -- CLEAR ; C CONT ? AT -- CLS ? V CLS / -- -- GO SUB / B SCROLL * INKEY$ -- RETURN OR N NEXT < NOT -- NEXT < M PAUSE > PI -- "?" > . , -- -- "." , SPACE BREAK pound -- 1111 BREAK pound |
ZX81 ZX80 PC EDIT NOT ! AND AND & THEN THEN # TO TO % |
General Specifications |
SPECs Machine Code Programs |
LET N=USR <startaddress> Note that only decimal addresses are supported. |
BC may contain returned value, if any (loaded into N in above example). IY must be 4000h upon return (pointer to the System Area) I must be 1Eh upon return (pointer to the Character set in ROM) return by RET opcode |
In SLOW mode, the AF' and IX' and R registers are used by the video interrupt handler and should not be modified. |
SPECs I/O Ports |
Bit Expl. 0-4 Keyboard column bits (0=Pressed) 5 Not used (1) 6 Display Refresh Rate (0=60Hz, 1=50Hz) 7 Cassette input (0=Normal, 1=Pulse) |
__Line____Bit__0____1____2____3____4__ 0 (A8) SHIFT Z X C V 1 (A9) A S D F G 2 (A10) Q W E R T 3 (A11) 1 2 3 4 5 4 (A12) 0 9 8 7 6 5 (A13) P O I U Y 6 (A14) ENTER L K J H 7 (A15) SPC . M N B |
Bit Expl. 0 Data Request (0=Busy, 1=Ready/DRQ) 1-5 Not used 6 Printer Detect (0=Okay, 1=None) 7 Printer Online (0=Nope, 1=Ready/Online) |
Bit Expl. 0-6 ??? Somewhat one or more bits for linefeed and/or else... 7 Pixel Output (0=White, 1=Black) |
SPECs Memory Map and System Area |
0000-1FFF BIOS ROM (8KBytes) 2000-3FFF not used 4000-43FF Internal RAM (1 KByte) 4000-7FFF External RAM (16 KBytes) |
4000 System Area (see below) 407D BASIC Program D_FILE Video Memory (BG Map) VARS BASIC Variables E_LINE-1 Byte 80h E_LINE Input Buffer/Workspace STKBOT BASIC Calculator Stack STKEND Machine Stack/Free Memory SP Machine Stack/In Use (SP is meant to be the CPUs SP register) ERR_SP GOSUB Stack RAMTOP USR Programs (Begin of unused/reserved memory) |
Addr. Name Expl 4000 ERR_NR Errorcode-1 4001 FLAGS Various BASIC Control flags Bit0=? Bit1=Redirect Output to printer Bit2-7=? 4002 ERR_SP Pointer to top of Machine Stack / Bottom of GOSUB Stack 4004 RAMTOP Pointer to unused/free memory (Changes realized at next NEW or CLS) 4006 MODE Selects [K], [L], [F], or [G] Cursor 4007 PPC Line Number of most recently executed BASIC line ---Begin of Save Area--- 4009 VERSN Should be 00h to identify ZX81 cassette files 400A E_PPC Line Number of currently selected line [>] Cursor 400C D_File Pointer to Video Memory (BG Map) / End of Basic Program 400E DF_CC Pointer to VRAM Address for PRINT 4010 VARS Pointer to BASIC Variables Area 4012 DEST Pointer to Variable when assigning a value to it 4014 E_LINE Pointer to Input Buffer/Workspace, and to --End of Save Area-- 4016 CH_ADD Pointer to next interpreted character 4018 X_PTR Pointer to character prior to [S] Symbol (=Syntax Error) (or ptr to aborted/breaked line) 401A STKBOT Pointer to BASIC Calculator Stack / End of Input Buffer/Workspace 401C STKEND Pointer to bottom of Machine Stack / End of Calculator Stack 401E BERG Calculator B-Register 401F MEM Pointer to Calculator Memory (usually same as MEMBOT) 4021 - Not used 4022 DF_SZ Number of lines in lower display section (including 1 blank line) 4023 S_TOP Line Number of first line for automatic LISTing 4025 LAST_K Keyboard - Recently pressed key (4025=row, 4026=shift/column) 4027 - Keyboard - Debounce State 4028 MARGIN Vertical Border Height (55 lines at top/bottom for 50Hz, 31 for 60Hz) 4029 NXTLIN Address of next BASIC line which is to be executed, pointing to a byte >=40h when stopped, indicates autostart address in cassette files. 402B OLDPPC Line Number for CONT 402D FLAGX Various Flags Bit 0-7:? 402E STRLEN Length of string during assignment 4030 T_ADDR Pointer to next item in Syntax Table 4032 SEED Random Number Seed 4034 FRAMES Decrementing Video Frame Counter (Bit15: 0=PAUSE, ie. display ON, program PAUSEd) 4036 COORDS X-Coordinate of last PLOT, Y-Coordinate of last PLOT 4038 PR_CC Least significant byte of PRBUFF printer buffer pointer 4039 S_POSN X-Coordinate for PRINT, Y-Coordinate for PRINT 403B CDFLAG Various Flags Bit7: Current Speed (1=SLOW (Display Enable), 0=FAST) Bit6: Requested Speed (or old speed during pause/cassette io, etc) Bit5-1: Not used Bit0: Keystroke (0=None, 1=Yes) 403C PRBUFF Printer Buffer 32 characters + NEWLINE (76h) 405D MEMBOT Default workspace for BASIC Calculator 407B - Not used (2 bytes) |
4000..4027 System Area 4028..(4008)-1 Basic Program (4008)..(4004 or 400A)-1 VARS (4004 or 400A)..(400C)-1 Input Buffer, and probably something else ??? (400C)... VRAM ... |
4000 byte error code 4001 byte (flags) 4002 word line number which is to be executed next (bit 15: 1=stopped) 4004 word pointer (similiar as 400A ???, probably there is sth that can be inserted between either one..) 4006 word line number for LIST 4008 word pointer to VARS / end of BASIC PROGRAM 400A word pointer to INPUT BUFFER / end of VARS (-save area end-) 400C word D_FILE pointer to VRAM / end of INPUT BUFFER 400E word pointer to ??? 4010 word pointer to ??? 4012 byte 4013 word 4015 word 4017 word line number for CONTINUE 4019 byte (flags) 401A word 401C word SEED random generator seed 401E word FRAMES incrementing frames counter 4020 word ---Active/Basic: 4022 word 4024 word // 4025 byte 4026 word CH_ADD BASIC program pointer ---Pause/Input: 4022 byte keyboard 'Debounce' 4023 byte MARGIN screen border height 4024 word // 4025 byte 4026 word LAST_K last key pressed |
SPECs Memory Mirrors and Expansions |
address code read write 0000..1FFF ROM ROM --- 2000..3FFF RAM4 RAM4 RAM4 4000..7FFF RAM1 RAM1 RAM1 8000..BFFF VRAM2 RAM2 RAM2 C000..FFFF VRAM1 RAM3 RAM3 |
SPECs What is... |
SPECs Internal Hardware |
CPU: NEC P1X108-144 D780C-1 (Z80 compatible) 3.25MHz The clock frequency is gained from a high tolerance 6.5MHz chewing gum, not exactly a quartz oscillator, in fact, my oscilloscope tells me that my ZX81 is running at 3.33Mhz. Effective CPU Speed in SLOW mode (when Display is enabled) For 50Hz Display Refresh: 0.820800 MHz For 60Hz Display Refresh: 0.547200 MHz Custom: FERRANTI ULA 2C184E 8147 Combines the ZX80 video circuit in one chip, plus NMI-generator Video Tech Data Video: 32x24 Characters (256x192 pixels), 64x48 Dots Block Graphics Characters: 64 Characters, defined in ROM area Attributes: Normal and Inverted (separately for each char) Memory 8 Kbytes ROM 1 KByte RAM built-in Expanision RAM: 16KBytes (most popular) up to 56KBytes |
SPECs ZX80 vs ZX81 Compatibility |
Display Output |
Video Text and Blockgraphics |
Video Pseudo Hi-Res Graphics |
Video True Hi-Res Graphics |
Video Blanking and Retrace |
Video Interrupts (INTs and NMIs) |
Video Display Timings |
Horizontal Display 128 cycles (32 characters, 256 pixels) Horizontal Blanking 64 cycles (left and right screen border) Horizontal Retrace 15 cycles Total Scanline Time 207 cycles |
Upper Blanking 11592 cycles 56 scanlines (7 charlines) Display Area 39744 cycles 192 scanlines (24 charlines) Lower Blanking ca.11592 cycles ca. 56 scanlines (or a bit less) Vertical Retrace 1235 cycles ca. 6 scanlines |
Upper Blanking 6624 cycles 32 scanlines (4 charlines) Display Area 39744 cycles 192 scanlines (24 charlines) Lower Blanking ca. 6624 cycles ca. 32 scanlines (or a bit less) Vertical Retrace 1235 cycles ca. 6 scanlines |
Total scanline time 207 cycles NMI WAITs/CALL 66h ca. 23 cycles NMI handler 32 cycles Remaining user time ca. 152 cycles |
SLOW, 50Hz Effective Speed 0.820800 MHz (54*2*152 cycles, 50 frames) SLOW, 60Hz Effective Speed 0.547200 MHz (30*2*152 cycles, 60 frames) FAST, Total CPU Speed 3.250000 MHz (display disabled) ZX80/PAUSE/INPUT 0.0 MHz |
Video Character Set |
____0___1___2___3___4___5___6___7___8___9___A___B___C___D___E___F____ 00 SPC GRA GRA GRA GRA GRA GRA GRA GRA GRA GRA " GBP $ : ? 0F 10 ( ) > < = + - * / ; , . 0 1 2 3 1F 20 4 5 6 7 8 9 A B C D E F G H I J 2F 30 K L M N O P Q R S T U V W X Y Z 3F |
____0___1___2___3___4___5___6___7___8___9___A___B___C___D___E___F____ 00 SPC " GRA GRA GRA GRA GRA GRA GRA GRA GRA GRA GBP $ : ? 0F 10 ( ) - + * / = > < ; , . 0 1 2 3 1F 20 4 5 6 7 8 9 A B C D E F G H I J 2F 30 K L M N O P Q R S T U V W X Y Z 3F |
00__01__02__03__04__05__06__07__08__09__0A__0B ;"."=blank .. #. .# ## .. #. .# ## %% .. %% ,, ;"#"=solid .. .. .. .. #. #. #. #. %% %% .. ;"%"=dithered |
00__01__02__03__04__05__06__07__08__09__0A__0B ;"."=blank .. ,, #. .. #. .# .. .. .# %% .. %% ;"#"=solid .. #. ## .. .. #. .# #. %% %% .. ;"%"=dithered |
The BASIC Interpreter |
BASIC Editor |
Key Name Expl. Equivalent/emulated PC Key Ret NEWLINE Confirm Input Enter Space BREAK Stops the program! Space Shift+0 RUBOUT Deletes a character Backspace Shift+1 EDIT Edits [>] Cursor selected line - Shift+5/8 <CURSOR> Moves Cursor left/right in input buffer Cursor Keys Shift+7/6 <CURSOR> Moves [>] Cursor up/down in listing Cursor Keys Shift+9 GRAPHICS Switches to [G] Graphics Cursor Mode Alt Shift+Ret FUNCTION Switches to [F] Function Cursor Mode Control |
BASIC Commands |
a) nothing b) a numeric expression, displayed either as normal decimal number (if in range 10^-5 .. 10^13) otherwise as nnEmm indicating nn*10^mm leading zeroes are displayed only if the first digit after the "." is not zero, ie. 0.3 and .03 are displayed as such. c) a string. undefined charcters are displayed as question marks. d) AT m,n - moves the PRINT position to the specified screen location, 0,0 is upper left. e) TAB n - moves the PRINT position to the specified horizontal location. If this is to the left of the current location, then the vertical position is incremented. |
BASIC Functions |
ACS n Arcus Cosinus. ASN n Arcus Sinus. ATN n Arcus Tangens. COS n Cosinus. EXP n Exponent e^n. INT n Returns an integer value (rounded DOWN). LN n Logarhytmn of n (base e). PI 3.14159265... SIN n Sinus. SQR n Square root. TAN n Tangens. |
Op. Prio. Expl. a+b 6 Addition a-b 6 Subtraction a*b 8 Multiplication a/b 8 Division -a 9 Invert sign a**b 10 a^b |
Op. Prio. Expl. a=b 5 Equal a>b 5 Greater than a<b 5 Less than a<=b 5 Less or equal a>=b 5 Greater or equal a<>b 5 Not equal |
Op. Prio. Expl. a OR b 2 b<>0: Returns 1; b=0: Returns a. a[$] AND b 3 b<>0: Returns a (or a$); b=0: Returns 0 (or ""). NOT b 4 b<>0: Returns 0; b=0: Returns 1. |
LET A$(5 TO 7) = "***" ;overwrites 5th-7th character of A$ LET A$ = B$(TO 4) ;copies 1st-4th character of B$ to A$ |
BASIC Error Codes |
0 No Error, program terminated succesfully. 1 Encountered NEXT without FOR. 2 Undefined Variable. 3 DIM Index out of range. May also return error B if 16bit exceeded. 4 Memory full. 5 Screen full. Type CONT to continue with cleared screen. 6 Arithmetic Overflow, a value is greater than 10^38. 7 Encountered RETURN without GOSUB. 8 Attempted to use INPUT as command (without line number). 9 Program halted by STOP command, may continue by CONT. A Function with bad argument. B Integer out of range. C Failed VAL function. D Program aborted by BREAK (SPACE KEY), or entered STOP at begin of INPUT. E Not used. F Attempted to SAVE a file with empty "" name. |
0 program completed (or breaked), no error 1 NEXT without FOR 2 variable not defined 3 dimension out of range (DIM) 4 memory or gosub stack full 5 (???) 6 integer overflow (value exceeds -32768..+32767) 7 RETURN without GOSUB 8 attempted INPUT but program isn't running 9 STOP command |
Z80 Usage in ZX Models |
Z80 CPU Specifications |
Z80 Register Set |
16bit Hi Lo Name/Function --------------------------------------- AF A - Accumulator & Flags BC B C BC DE D E DE HL H L HL AF' - - Second AF BC' - - Second BC DE' - - Second DE HL' - - Second HL IX IXH IXL Index register 1 IY IYH IYL Index register 2 SP - - Stack Pointer PC - - Program Counter/Pointer - I R Interrupt & Refresh |
Z80 Flags |
Bit Name Set Clr Expl. 0 C C NC Carry Flag 1 N - - Add/Sub-Flag (BCD) 2 P/V PE PO Parity/Overflow-Flag 3 - - - Undocumented 4 H - - Half-Carry Flag (BCD) 5 - - - Undocumented 6 Z Z NZ Zero-Flag 7 S M P Sign-Flag |
Z80 Instruction Format |
r 8bit register A,B,C,D,E,H,L rr 16bit register BC, DE, HL/IX/IY, AF/SP (as described) i 8bit register A,B,C,D,E,IXH/IYH,IXL/IYL ii 16bit register IX,IY n 8bit immediate 00-FFh (unless described else) nn 16bit immediate 0000-FFFFh d 8bit signed offset -128..+127 f flag condition nz,z,nc,c AND/OR po,pe,p,m (as described) (..) 16bit pointer to byte/word in memory |
s Indicates Signed result z Indicates Zero h Indicates Halfcarry o Indicates Overflow p Indicates Parity c Indicates Carry - Flag is not affected 0 Flag is cleared 1 Flag is set x Flag is destroyed (unspecified) i State of IFF2 e Indicates BC<>0 for LDX(R) and CPX(R), or B=0 for INX(R) and OUTX(R) |
Z80 8bit Load Commands |
Instruction Opcode Cycles Flags Notes ld r,r xx 4 ------ r=r ld i,i pD xx 8 ------ i=i ld r,n xx nn 7 ------ r=n ld i,n pD xx nn 11 ------ i=n ld r,(HL) xx 7 ------ r=(HL) ld r,(ii+d) pD xx dd 19 ------ r=(ii+d) ld (HL),r 7x 7 ------ (HL)=r ld (ii+d),r pD 7x dd 19 ------ ld (HL),n 36 nn 10 ------ ld (ii+d),n pD 36 dd nn 19 ------ ld A,(BC) 0A 7 ------ ld A,(DE) 1A 7 ------ ld A,(nn) 3A nn nn 13 ------ ld (BC),A 02 7 ------ ld (DE),A 12 7 ------ ld (nn),A 32 nn nn 13 ------ ld A,I ED 57 9 sz0i0- A=I ;Interrupt Register ld A,R ED 5F 9 sz0i0- A=R ;Refresh Register ld I,A ED 47 9 ------ ld R,A ED 4F 9 ------ |
Z80 16bit Load Commands |
Instruction Opcode Cycles Flags Notes ld rr,nn x1 nn nn 10 ------ rr=nn ;rr may be BC,DE,HL or SP ld ii,nn pD 21 nn nn 13 ------ ii=nn ld HL,(nn) 2A nn nn 16 ------ HL=(nn) ld ii,(nn) pD 2A nn nn 20 ------ ii=(nn) ld rr,(nn) ED xB nn nn 20 ------ rr=(nn) ;rr may be BC,DE,HL or SP ld (nn),HL 22 nn nn 16 ------ (nn)=HL ld (nn),ii pD 22 nn nn 20 ------ (nn)=ii ld (nn),rr ED x3 nn nn 20 ------ (nn)=rr ;rr may be BC,DE,HL or SP ld SP,HL F9 6 ------ SP=HL ld SP,ii pD F9 10 ------ SP=ii push rr x5 11 ------ SP=SP-2, (SP)=rr ;rr may be BC,DE,HL,AF push ii pD E5 15 ------ SP=SP-2, (SP)=ii pop rr x1 10 (-AF-) rr=(SP), SP=SP+2 ;rr may be BC,DE,HL,AF pop ii pD E1 14 ------ ii=(SP), SP=SP+2 ex DE,HL EB 4 ------ exchange DE <--> HL ex AF,AF 08 4 xxxxxx exchange AF <--> AF' exx D9 4 ------ exchange BC,DE,HL <--> BC',DE',HL' ex (SP),HL E3 19 ------ exchange (SP) <--> HL ex (SP),ii pD E3 23 ------ exchange (SP) <--> ii |
Z80 Blocktransfer- and Searchcommands |
Instruction Opcode Cycles Flags Notes ldi ED A0 16 --0e0- (DE)=(HL), HL=HL+1, DE=DE+1, BC=BC-1 ldd ED A8 16 --0e0- (DE)=(HL), HL=HL-1, DE=DE-1, BC=BC-1 cpi ED A1 16 szhe1- compare A-(HL), HL=HL+1, DE=DE+1, BC=BC-1 cpd ED A9 16 szhe1- compare A-(HL), HL=HL-1, DE=DE-1, BC=BC-1 ldir ED B0 bc*21-5 --0?0- ldi-repeat until BC=0 lddr ED B8 bc*21-5 --0?0- ldd-repeat until BC=0 cpir ED B1 x*21-5 szhe1- cpi-repeat until BC=0 or compare fits cpdr ED B9 x*21-5 szhe1- cpd-repeat until BC=0 or compare fits |
Z80 8bit Arithmetic/Logical Commands |
Instruction Opcode Cycles Flags Notes daa 27 4 szxp-x decimal adjust akku cpl 2F 4 --1-1- A = A xor FF neg ED 44 8 szho1c A = 00-A <arit> r xx 4 szhonc see below <arit> i pD xx 8 szhonc see below, UNDOCUMENTED <arit> n xx nn 7 szhonc see below <arit> (HL) xx 7 szhonc see below <arit> (ii+d) pD xx dd 19 szhonc see below <cnt> r xx 4 szhon- see below <cnt> i pD xx 8 szhon- see below, UNDOCUMENTED <cnt> (HL) xx 11 szhon- see below <cnt> (ii+d) pD xx dd 23 szhon- see below <logi> r xx 4 szhp00 see below <logi> i pD xx 8 szhp00 see below, UNDOCUMENTED <logi> n xx nn 7 szhp00 see below <logi> (HL) xx 7 szhp00 see below <logi> (ii+d) pD xx dd 19 szhp00 see below |
add A,op see above 4-19 szho0c A=A+op adc A,op see above 4-19 szho0c A=A+op+cy sub op see above 4-19 szho1c A=A-op sbc A,op see above 4-19 szho1c A=A-op-cy cp op see above 4-19 szho1c compare, ie. VOID=A-op |
inc op see above 4-23 szho0- op=op+1 dec op see above 4-23 szho1- op=op-1 |
and op see above 4-19 sz1p00 A=A & op xor op see above 4-19 sz0p00 A=A XOR op or op see above 4-19 sz0p00 A=A | op |
Z80 16bit Arithmetic Commands |
Instruction Opcode Cycles Flags Notes add HL,rr x9 11 --h-0c HL = HL+rr ;rr may be BC,DE,HL,SP add ii,rr pD x9 15 --h-0c ii = ii+rr ;rr may be BC,DE,ii,SP (!) adc HL,rr ED xA 15 szho0c HL = HL+rr+cy ;rr may be BC,DE,HL,SP sbc HL,rr ED x2 15 szho1c HL = HL-rr-cy ;rr may be BC,DE,HL,SP inc rr x3 6 ------ rr = rr+1 ;rr may be BC,DE,HL,SP inc ii pD 23 10 ------ ii = ii+1 dec rr xB 6 ------ rr = rr-1 ;rr may be BC,DE,HL,SP dec ii pD 2B 10 ------ ii = ii-1 |
Z80 Rotate and Shift Commands |
Instruction Opcode Cycles Flags Notes rlca 07 4 --0-0c rotate akku left rla 17 4 --0-0c rotate akku left through carry rrca 0F 4 --0-0c rotate akku right rra 1F 4 --0-0c rotate akku right through carry rld ED 6F 18 sz0p0- rotate left low digit of A through (HL) rrd ED 67 18 sz0p0- rotate right low digit of A through (HL) <cmd> r CB xx 8 sz0p0c see below <cmd> (HL) CB xx 15 sz0p0c see below <cmd> (ii+d) pD CB dd xx 23 sz0p0c see below <cmd> r,(ii+d) pD CB dd xx 23 sz0p0c see below, UNDOCUMENTED modify and load |
rlc rotate left rl rotate left through carry rrc rotate right rr rotate right through carry sla shift left arithmetic (b0=0) sll UNDOCUMENTED shift left (b0=1) sra shift right arithmetic (b7=b7) srl shift right logical (b7=0) |
Z80 Singlebit Operations and CPU-Control Commands |
Instruction Opcode Cycles Flags Notes bit n,r CB xx 8 xz1x0- test bit n ;n=0..7 bit n,(HL) CB xx 12 xz1x0- bit n,(ii+d) pD CB dd xx 20 xz1x0- set n,r CB xx 8 ------ set bit n ;n=0..7 set n,(HL) CB xx 15 ------ set n,(ii+d) pD CB dd xx 23 ------ set r,n,(ii+d) pD CB dd xx 23 ------ UNDOCUMENTED set n,(ii+d) and ld r,(ii+d) res n,r CB xx 8 ------ reset bit n ;n=0..7 res n,(HL) CB xx 15 ------ res n,(ii+d) pD CB dd xx 23 ------ res r,n,(ii+d) pD CB dd xx 23 ------ UNDOCUMENTED res n,(ii+d) and ld r,(ii+d) ccf 3F 4 --h-0c h=cy, cy=cy xor 1 scf 37 4 --0-01 cy=1 nop 00 4 ------ no operation halt 76 4 ------ repeat until interrupt occurs di F3 4 ------ IFF1=0, IFF2=0 ;disable interrupts ei FB 4 ------ IFF1=1, IFF2=1 ;enable interrupts im 0 ED 46 8 ------ read opcode from databus on interrupt im 1 ED 56 8 ------ execute call 0038h on interrupt im 2 ED 5E 8 ------ execute call (i*100h+databus) on int. |
Z80 Jumpcommands |
Instruction Opcode Cycles Flags Notes jp nn C3 nn nn 10 ------ jump to nn, ie. PC=nn jp HL E9 4 ------ jump to HL, ie. PC=HL jp ii pD E9 8 ------ jump to ii, ie. PC=ii jp f,nn xx nn nn 10;10 ------ jump to nn if nz,z,nc,c,po,pe,p,m jr nn 18 dd 12 ------ relative jump to nn, ie. PC=PC+d jr f,nn xx dd 12;7 ------ relative jump to nn if nz,z,nc,c djnz nn 10 dd 13;8 ------ B=B-1 and relative jump to nn if B<>0 call nn CD nn nn 17 ------ call nn ie. SP=SP-2, (SP)=PC, PC=nn call f,nn xx nn nn 17;10 ------ call nn if nz,z,nc,c,po,pe,p,m ret C9 10 ------ pop PC ie. PC=(SP), SP=SP+2 ret f xx 11;5 ------ pop PC if nz,z,nc,c,po,pe,p,m reti ED 4D 14 ------ pop PC, IFF1=IFF2, ACK (ret from INT) retn ED 45 14 ------ pop PC, IFF1=IFF2 (ret from NMI) rst n xx 11 ------ call n ;n=00,08,10,18,20,28,30,38 |
Z80 I/O Commands |
Instruction Opcode Cycles Flags Notes in A,(n) DB nn 11 ------ A=PORT(A*100h+n) in r,(C) ED xx 12 sz0p0- r=PORT(BC) in (C) ED 70 12 sz0p0- **undoc/illegal** VOID=PORT(BC) out (n),A D3 nn 11 ------ PORT(A*100h+n)=A out (C),r ED xx 12 ------ PORT(BC)=r out (C),0 ED 71 12 ------ **undoc/illegal** PORT(BC)=00 ini ED A2 16 xexxxx MEM(HL)=PORT(BC), HL=HL+1, B=B-1 ind ED AA 16 xexxxx MEM(HL)=PORT(BC), HL=HL-1, B=B-1 outi ED A3 16 xexxxx B=B-1, PORT(BC)=MEM(HL), HL=HL+1 outd ED AB 16 xexxxx B=B-1, PORT(BC)=MEM(HL), HL=HL-1 inir ED B2 b*21-5 x1xxxx same than ini, repeat until b=0 indr ED BA b*21-5 x1xxxx same than ind, repeat until b=0 otir ED B3 b*21-5 x1xxxx same than outi, repeat until b=0 otdr ED BB b*21-5 x1xxxx same than outd, repeat until b=0 |
Z80 Interrupts |
EI IFF1=1, IFF2=1 DI IFF1=0, IFF2=0 <INT> IFF1=0, IFF2=0 <NMI> IFF1=0 RETI IFF1=IFF2 RETN IFF1=IFF2 |
Mode Cycles Refresh Operation 0 1+var 0+var IFF=0, read and execute opcode from databus 1 12 1 IFF=0, CALL 0038h 2 18 1 IFF=0, CALL (I*100h+databus) |
Z80 Meaningless and Duplicated Opcodes |
Z80 Garbage in Flag Register |
RLD; CPL; RLCA; RLA; LD A,I; ADD OP; ADC OP; XOR OP; AND OP; RRD; NEG; RRCA; RRA; LD A,R; SUB OP; SBC OP; OR OP ; DAA. |
RLC OP; RL OP; SLA OP; SLL OP; INC OP; IN OP,(C); RRC OP; RR OP; SRA OP; SRL OP; DEC OP |
ADD RR,XX; ADC RR,XX; SBC RR,XX. |
DUMMY = "REG_C+DATA+1" ;for INI/INIR DUMMY = "REG_C+DATA-1" ;for IND/INDR DUMMY = "REG_L+DATA" ;for OUTI,OUTD,OTIR,OTDR FLG_C = Carry of above "DUMMY" calculation FLG_H = Carry of above "DUMMY" calculation (same as FLG_C) FLG_N = Sign of "DATA" FLG_P = Parity of "REG_B XOR (DUMMY AND 07h)" FLG_S = Sign of "REG_B" UNDOC = Bit3,5 of "REG_B AND 28h" |
FLG_H = (OLD_A AND 0Fh) > 09h FLG_C = Carry of result |
FLG_H = (NEW_A AND 0Fh) > 09h FLG_C = OLD_CARRY OR (OLD_A>99h) |
Content Instruction A*100h LD (xx),A ;xx=BC,DE,nn xx+1 LD A,(xx) ;xx=BC,DE,nn nn+1 LD (nn),rr; LD rr,(nn) ;rr=BC,DE,HL,IX,IY rr EX (SP),rr ;rr=HL,IX,IY (MEMPTR=new value of rr) rr+1 ADD/ADC/SBC rr,xx ;rr=HL,IX,IY (MEMPTR=old value of rr+1) HL+1 RLD and RRD dest JP nn; CALL nn; JR nn ;dest=nn dest JP f,nn; CALL f,nn ;regardless of condition true/false dest RET; RETI; RETN ;dest=value read from (sp) dest RET f; JR f,nn; DJNZ nn ;only if condition=true 00XX RST n adr+1 IN A,(n) ;adr=A*100h+n, memptr=A*100h+n+1 bc+1 IN r,(BC); OUT (BC),r ;adr=bc ii+d All instructions with operand (ii+d) |
OUT (N),A and block commands LDXX, CPXX, INXX, OUTXX and probably interrupts in IM 0, 1, 2 |
Z80 Compatibility |
Data Structures |
ZX81 BASIC Programs and Variables |
Bytes Expl. 2 Line Number (MSB,LSB) (!) 2 Line Length (LSB,MSB) LEN-1 Text 1 Newline (76h) |
Bytes Expl. 1 60h + Letter (5bit) 1 Exponent 4 Sign-Bit and Value |
Bytes Expl. 1 A0h + First Letter (5bit) NN 00h + Further Characters (6bit) 1 80h + Last Character (6bit) 1 Exponent 4 Sign-Bit and Value |
Bytes Expl. 1 80h + Letter (5bit) 2 Total Length of all following data 1 Number of Dimensions D*2 Range of each of the Dimension(s) N*5 Values |
Bytes Expl. 1 E0h + Letter (5bit) 5 Current Value 5 Target Value 5 Step 2 Loop Linenumber (MSB,LSB) (!) |
Bytes Expl. 1 40h + Letter (5bit) 2 String Length (0 if empty) LEN Character String (none if empty) |
Bytes Expl. 1 C0h + Letter (5bit) 2 Total Length of all following data 1 Number of Dimensions D*2 Range of each of the Dimension(s) N*1 Characters |
ZX80 BASIC Programs and Variables |
Bytes Expl. 2 Line Number (MSB,LSB) (!) ... Text 1 Newline (76h) |
Bytes Expl. 1 60h + Letter (5bit) 2 Signed Integer |
Bytes Expl. 1 40h + First Letter (5bit) NN 00h + Further Characters (6bit) 1 80h + Last Character (6bit) 2 Signed Integer |
Bytes Expl. 1 A0h + Letter (5bit) 1 Range (Counted from 0 to N) (N+1)*2 Signed Integers |
Bytes Expl. 1 E0h + Letter (5bit) 2 Current Value 2 Target Value 2 Loop Linenumber (normal LSB,MSB for ZX80) |
Bytes Expl. 1 80h + Letter (5bit) ... Character String (none if empty) 1 Ending Quotes (01h) |
Cassette File Images |
Cassette File Content |
4014h defines the end address (used to calculate the file length) 4029h points to the next executed (autostarted) BASIC line 403Bh indicates if program runs in SLOW or FAST mode (bit 6) |
Cassette Signals |
x seconds your voice, saying "filename" (optional) x seconds video noise 5 seconds silence 1-127 bytes filename (bit7 set in last char) LEN bytes data, loaded to address 4009h, LEN=(4014h)-4009h. 1 pulse video retrace signal (only if display was enabled) x seconds silence / video noise |
x seconds your voice, saying "filename" (optional) x seconds video noise 5 seconds silence LEN bytes data, loaded to address 4000h, LEN=(400Ah)-4000h. x seconds silence / video noise |
0: /\/\/\/\________ 1: /\/\/\/\/\/\/\/\/\________ |
Hardware, Connectors, Upgrading |
Hardware - External Connectors |
Ring: Shield Tip: TV Signal |
Ring: Ground Tip: Cassette Input |
Ring: Ground Tip: Cassette Output |
Ring: Ground Tip: 9V DC |
Upper Side Lower Side 1A D7 1B 5V 2A /RAM CS 2B 9V 3A ---SLOT--- 3B ---SLOT--- 4A D0 4B 0V 5A D1 5B 0V 6A D2 6B CLK 7A D6 7B A0 8A D5 8B A1 9A D3 9B A2 10A D4 10B A3 11A /INT 11B A15 12A /NAY ??? NMI 12B A14 13A /HALT 13B A13 14A /MREQ 14B A12 15A /IORQ 15B A11 16A /RD 16B A10 17A /WR 17B A9 18A /BUSAK 18B A8 19A /WAIT 19B A7 20A /BUSRQ 20B A6 21A /RESET 21B A5 22A /MI 22B A4 23A /REFSH 23B /ROM CS |
Hardware - Internal Pins |
Pin 1-8: A15, A14, A8, A13, A9, A12, A10, A11. Pin 9-13: KBD0, KBD1, KBD2, KBD3, KBD4. |
0V sync 2.5V black 5V white |
Hardware - Modifications |
MODs Replacing the ZX81 ROM by an EPROM |
MODs Connecting a Joystick |
MODs Upgrading RamPaks for True Hi-Res Graphics |
+5V | 1N34A [4.7K] connector RD _______|/|______|_____________ RD of RAMPACK |\| | | connector RFSH _______|/|______| +5V_____ RFSH of RAMPACK |\| 1N34A |
MODs Connecting a Monitor |
MODs Getting rid of the 9V DC Power Supply |
MODs Uploading Programs from the PC to the ZX81 |
1 PC with Parallel Port, and a normal Centronics Printer Cable 1 Centronics plug (36 pins, female) 1 EPROM (2764 non-CMOS) and EPROM burner (optional) 6 Diodes (for example 1N4148, ie. the most cheapest standard ones) and some short isolated wires |
F3 ED 56 3E 1E ED 47 21 00 40 E5 FD E1 11 01 40 75 01 FF 3F ED B0 21 02 40 75 24 F2 19 03 26 40 35 28 07 35 20 04 24 F2 20 03 2E 00 F9 22 04 40 21 FF 80 22 00 40 21 00 3E E5 21 76 06 E5 ED 73 02 40 DB FE E6 1F FE 13 C2 E5 03 01 01 00 CD 59 03 ED 4B 09 40 21 07 02 E5 21 08 40 DB FE 0F 38 FB D3 FF 23 0B 77 DB FE 0F 30 FB ED 6F A8 FA 5C 03 C9 |
Internet Resources |