# File 2K_ROM_6.asm 0000 org 00000h 0000 Start_of_RAM: equ 0x0800 0000 c3 18 00 jp Get_address ;Skip over message 0003 .. 00 defm "Cpuville Z80 ROM v.6",0 0018 db 00 Get_address: in a,(0) ;Get address from input ports 001a 6f ld l,a 001b db 01 in a,(1) 001d 67 ld h,a 001e e9 jp (hl) ;Jump to the address 001f db 00 Port_Reflector: in a,(0) ;Simple program to test ports 0021 d3 00 out (0),a 0023 db 01 in a,(1) 0025 d3 01 out (1),a 0027 c3 1f 00 jp Port_Reflector 002a 3e 00 Simple_Counter: ld a,000h ;One-byte counter for slow clock 002c d3 00 Loop_1: out (0),a 002e 3c inc a 002f c3 2c 00 jp Loop_1 0032 2e 00 Count_to_a_million: ld l,000h ;Two-byte (16-bit) counter 0034 26 00 ld h,000h ;Clear registers 0036 3e 10 Loop_2: ld a,010h ;Count 16 times, then 0038 3d Loop_3: dec a 0039 c2 38 00 jp nz,Loop_3 003c 23 inc hl ;increment the 16-bit number 003d 7d ld a,l 003e d3 00 out (0),a ;Output the 16-bit number 0040 7c ld a,h 0041 d3 01 out (1),a 0043 c3 36 00 jp Loop_2 ;Do it again 0046 21 00 08 Program_loader: ld hl,Start_of_RAM ;Load a program in RAM 0049 db 01 Loop_4: in a,(1) 004b e6 81 and 081h ;Check input port 1 004d ca 49 00 jp z,Loop_4 ;If switches 0 and 7 open, loop 0050 3e 10 ld a, 010h ;OK, at least one switch closed 0052 06 ff Loop_5: ld b,0ffh ;Debounce loop 0054 10 fe djnz $+0 0056 3d dec a 0057 c2 52 00 jp nz,Loop_5 005a db 01 in a,(1) ;Get input port byte again 005c e6 80 and 080h ;Is the left switch (bit 7) closed? 005e c2 00 08 jp nz,Start_of_RAM ;Yes, run loaded program 0061 db 00 in a,(0) ;No, then right switch (bit 0) closed. 0063 d3 00 out (0),a ;Get byte from port 0, display on output 0065 77 ld (hl),a ;Store it in RAM 0066 3e ff ld a,0ffh ;Turn port 1 lights on (signal that 0068 d3 01 out (1),a ;a byte was stored) 006a db 01 Loop_6: in a,(1) ;Wait for switch to open 006c e6 01 and 001h 006e c2 6a 00 jp nz,Loop_6 0071 3e 10 ld a, 010h ;Switch open, debounce 0073 06 ff Loop_7: ld b,0ffh ;Debounce loop 0075 10 fe djnz $+0 0077 3d dec a 0078 c2 73 00 jp nz,Loop_7 007b 7d ld a,l ;Put low byte of address on port 1 007c d3 01 out (1),a 007e 23 inc hl ;Point to next location in RAM 007f c3 49 00 jp Loop_4 ;Do it again 0082 21 00 08 Memory_test: ld hl,Start_of_RAM ;check RAM by writing and reading each location 0085 db 01 Loop_8: in a,(1) ;read port 1 to get a bit pattern 0087 47 ld b,a ;copy it to register b 0088 77 ld (hl),a ;store it in memory 0089 7e ld a,(hl) ;read back the same location 008a b8 cp b ;same as reg b? 008b c2 92 00 jp nz,Exit_1 ;no, test failed, exit 008e 23 inc hl ;yes, RAM location OK 008f c3 85 00 jp Loop_8 ;keep going 0092 7c Exit_1: ld a,h ;display the address 0093 d3 01 out (1),a ;where the test failed 0095 7d ld a,l ;should be 4K (cycled around to ROM) 0096 d3 00 out (0),a ;any other value means bad RAM 0098 c3 82 00 jp Memory_test ;do it again (use a different bit pattern) 009b db 00 Peek: in a,(0) ;Get low byte 009d 6f ld l,a ;Put in reg L 009e db 01 in a,(1) ;Get hi byte 00a0 67 ld h,a ;Put in reg H 00a1 7e ld a,(hl) ;Get byte from memory 00a2 d3 00 out (0),a ;Display on port 0 LEDs 00a4 c3 9b 00 jp Peek ;Do it again 00a7 3e 00 Poke: ld a,000h ;Clear output port LEDs 00a9 d3 00 out (0),a 00ab d3 01 out (1),a 00ad db 01 Loop_9: in a,(1) ;Look for switch closure 00af e6 01 and 001h 00b1 ca ad 00 jp z,Loop_9 00b4 3e 10 ld a, 010h ;Switch close, debounce 00b6 06 ff Loop_10: ld b,0ffh 00b8 10 fe djnz $+0 00ba 3d dec a 00bb c2 b6 00 jp nz,Loop_10 00be 3e ff ld a,0ffh ;Light port 1 LEDs 00c0 d3 01 out (1),a 00c2 db 00 in a,(0) ;Get hi byte 00c4 67 ld h,a ;Put in reg H 00c5 db 01 Loop_11: in a,(1) ;Look for switch open 00c7 e6 01 and 001h 00c9 c2 c5 00 jp nz,Loop_11 00cc 3e 10 ld a,010h 00ce 06 ff Loop_12: ld b,0ffh ;Debounce loop 00d0 10 fe djnz $+0 00d2 3d dec a 00d3 c2 ce 00 jp nz,Loop_12 00d6 7c ld a,h ;Show hi byte on port 1 00d7 d3 01 out (1),a 00d9 db 01 Loop_13: in a,(1) ;Look for switch closure 00db e6 01 and 001h 00dd ca d9 00 jp z,Loop_13 00e0 3e 10 ld a, 010h ;Switch closed, debounce 00e2 06 ff Loop_14: ld b,0ffh ;Debounce loop 00e4 10 fe djnz $+0 00e6 3d dec a 00e7 c2 e2 00 jp nz,Loop_14 00ea 3e ff ld a,0ffh ;Light port 0 LEDs 00ec d3 00 out (0),a 00ee db 00 in a,(0) ;Get lo byte 00f0 6f ld l,a ;Put in reg L 00f1 db 01 Loop_15: in a,(1) ;Look for switch open 00f3 e6 01 and 001h 00f5 c2 f1 00 jp nz,Loop_15 00f8 3e 10 ld a,010h ;Switch open, debounce 00fa 06 ff Loop_16: ld b,0ffh ;Debounce loop 00fc 10 fe djnz $+0 00fe 3d dec a 00ff c2 fa 00 jp nz,Loop_16 0102 7d ld a,l ;Show lo byte on port 0 0103 d3 00 out (0),a 0105 db 01 Loop_17: in a,(1) ;Look for switch closure 0107 e6 01 and 001h 0109 ca 05 01 jp z,Loop_17 010c 3e 10 ld a,010h ;Switch closed, debounce 010e 06 ff Loop_18: ld b,0ffh ;Debounce loop 0110 10 fe djnz $+0 0112 3d dec a 0113 c2 0e 01 jp nz,Loop_18 0116 db 00 in a,(0) ;Get byte to load 0118 77 ld (hl),a ;Store in memory 0119 db 01 Loop_19: in a,(1) ;Look for switch open 011b e6 01 and 001h 011d c2 19 01 jp nz,Loop_19 0120 3e 10 ld a,010h ;Switch open, debounce 0122 06 ff Loop_20: ld b,0ffh ;Debounce loop 0124 10 fe djnz $+0 0126 3d dec a 0127 c2 22 01 jp nz,Loop_20 012a c3 a7 00 jp Poke ;Start over 012d # End of file 2K_ROM_6.asm 012d