# File 2K_ROM_2.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.2",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 80 ld b,080h ;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 ;Bet byte from port 0, display on output 005d 77 ld (hl),a ;Store it in RAM 005e 23 inc hl ;Point to next location in RAM 005f 3e ff ld a,0ffh ;Turn port 1 lights on (signal that 0061 d3 01 out (1),a ;a byte was stored) 0063 db 01 Loop_5: in a,(1) ;Wait for switch to open 0065 e6 01 and 001h 0067 c2 63 00 jp nz,Loop_5 006a 06 80 ld b,080h ;Switch open, debounce 006c 10 fe djnz $+0 006e 3e 00 ld a,000h ;Turn off port 1 lights 0070 d3 01 out (1),a 0072 c3 49 00 jp Loop_4 ;Do it again 0075 21 00 08 Memory_test: ld hl,Start_of_RAM ;check RAM by writing and reading each location 0078 db 01 Loop_6: in a,(1) ;read port 1 to get a bit pattern 007a 47 ld b,a ;copy it to register b 007b 77 ld (hl),a ;store it in memory 007c 7e ld a,(hl) ;read back the same location 007d b8 cp b ;same as reg b? 007e c2 85 00 jp nz,Exit_1 ;no, test failed, exit 0081 23 inc hl ;yes, RAM location OK 0082 c3 78 00 jp Loop_6 ;keep going 0085 7c Exit_1: ld a,h ;display the address 0086 d3 01 out (1),a ;where the test failed 0088 7d ld a,l ;should be 4K (cycled around to ROM) 0089 d3 00 out (0),a ;any other value means bad RAM 008b c3 75 00 jp Memory_test ;do it again (use a different bit pattern) 008e # End of file 2K_ROM_2.asm 008e