# File 2K_ROM_5.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.5",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 06 ff ld b,0ffh ;OK, at least one switch closed 0052 10 fe djnz $+0 ;Debounce loop 0054 e6 80 and 080h ;Is the left switch (bit 7) closed? 0056 c2 00 08 jp nz,Start_of_RAM ;Yes, run loaded program 0059 db 00 in a,(0) ;No, then right switch (bit 0) closed. 005b d3 00 out (0),a ;Get byte from port 0, display on output 005d 77 ld (hl),a ;Store it in RAM 005e 3e ff ld a,0ffh ;Turn port 1 lights on (signal that 0060 d3 01 out (1),a ;a byte was stored) 0062 db 01 Loop_5: in a,(1) ;Wait for switch to open 0064 e6 01 and 001h 0066 c2 62 00 jp nz,Loop_5 0069 06 ff ld b,0ffh ;Switch open, debounce 006b 10 fe djnz $+0 006d 7d ld a,l ;Put low byte of address on port 1 006e d3 01 out (1),a 0070 23 inc hl ;Point to next location in RAM 0071 c3 49 00 jp Loop_4 ;Do it again 0074 21 00 08 Memory_test: ld hl,Start_of_RAM ;check RAM by writing and reading each location 0077 db 01 Loop_6: in a,(1) ;read port 1 to get a bit pattern 0079 47 ld b,a ;copy it to register b 007a 77 ld (hl),a ;store it in memory 007b 7e ld a,(hl) ;read back the same location 007c b8 cp b ;same as reg b? 007d c2 84 00 jp nz,Exit_1 ;no, test failed, exit 0080 23 inc hl ;yes, RAM location OK 0081 c3 77 00 jp Loop_6 ;keep going 0084 7c Exit_1: ld a,h ;display the address 0085 d3 01 out (1),a ;where the test failed 0087 7d ld a,l ;should be 4K (cycled around to ROM) 0088 d3 00 out (0),a ;any other value means bad RAM 008a c3 74 00 jp Memory_test ;do it again (use a different bit pattern) 008d db 00 Peek: in a,(0) ;Get low byte 008f 6f ld l,a ;Put in reg L 0090 db 01 in a,(1) ;Get hi byte 0092 67 ld h,a ;Put in reg H 0093 7e ld a,(hl) ;Get byte from memory 0094 d3 00 out (0),a ;Display on port 0 LEDs 0096 c3 8d 00 jp Peek ;Do it again 0099 3e 00 Poke: ld a,000h ;Clear output port LEDs 009b d3 00 out (0),a 009d d3 01 out (1),a 009f db 01 Loop_7: in a,(1) ;Look for switch closure 00a1 e6 01 and 001h 00a3 ca 9f 00 jp z,Loop_7 00a6 3e ff ld a,0ffh ;Debounce loop 00a8 47 ld b,a 00a9 10 fe Loop_8: djnz Loop_8 00ab 3e ff ld a,0ffh ;Light port 1 LEDs 00ad d3 01 out (1),a 00af db 00 in a,(0) ;Get hi byte 00b1 67 ld h,a ;Put in reg H 00b2 db 01 Loop_9: in a,(1) ;Look for switch open 00b4 e6 01 and 001h 00b6 c2 b2 00 jp nz,Loop_9 00b9 3e ff ld a,0ffh ;Debounce loop 00bb 47 ld b,a 00bc 10 fe Loop_10: djnz Loop_10 00be 7c ld a,h ;Show hi byte on port 1 00bf d3 01 out (1),a 00c1 db 01 Loop_11: in a,(1) ;Look for switch closure 00c3 e6 01 and 001h 00c5 ca c1 00 jp z,Loop_11 00c8 3e ff ld a,0ffh ;Debounce loop 00ca 47 ld b,a 00cb 10 fe Loop_12: djnz Loop_12 00cd 3e ff ld a,0ffh ;Light port 0 LEDs 00cf d3 00 out (0),a 00d1 db 00 in a,(0) ;Get lo byte 00d3 6f ld l,a ;Put in reg L 00d4 db 01 Loop_13: in a,(1) ;Look for switch open 00d6 e6 01 and 001h 00d8 c2 d4 00 jp nz,Loop_13 00db 3e ff ld a,0ffh ;Debounce loop 00dd 47 ld b,a 00de 10 fe Loop_14: djnz Loop_14 00e0 7d ld a,l ;Show lo byte on port 0 00e1 d3 00 out (0),a 00e3 db 01 Loop_15: in a,(1) ;Look for switch closure 00e5 e6 01 and 001h 00e7 ca e3 00 jp z,Loop_15 00ea 3e ff ld a,0ffh ;Debounce loop 00ec 47 ld b,a 00ed 10 fe Loop_16: djnz Loop_16 00ef db 00 in a,(0) ;Get byte to load 00f1 77 ld (hl),a ;Store in memory 00f2 db 01 Loop_17: in a,(1) ;Look for switch open 00f4 e6 01 and 001h 00f6 c2 f2 00 jp nz,Loop_17 00f9 3e ff ld a,0ffh ;Debounce loop 00fb 47 ld b,a 00fc 10 fe Loop_18: djnz Loop_18 00fe c3 99 00 jp Poke ;Start over 0101 # End of file 2K_ROM_5.asm 0101