# File memory_test.asm 0000 ;Memory testing program for 64-K RAM expansion 0000 ;Program initially loaded at 0x0800 0000 ;Starts in configuration 0, tests RAM from 0x0B00 to 0xFFFF 0000 ;Program re-locates to 0x0B00, switches to configuration 1, tests 0x0000 to 0x0AFF 0000 ;If memory error, quits and displays memory contents and test byte 0000 write_char: equ 0x000c 0000 write_string: equ 0x0018 0000 byte_to_hex_string: equ 0x0088 0000 write_newline: equ 0x0289 0000 monitor_warm_start: equ 0x046f 0000 org 0x0800 ;start of RAM, config. 0 0800 cd 89 02 call write_newline 0803 3e 00 ld a,0x00 ;first test pattern 0805 32 a2 08 ld (test_byte_0),a ;store 0808 21 00 0b ld hl,0x0B00 ;start of test, config 0 080b 3a a2 08 loop_1: ld a,(test_byte_0) ;get test byte 080e 77 ld (hl),a ;store test byte 080f 23 inc hl ;inc counter 0810 7c ld a,h ;need to test for zero this way 0811 b5 or l 0812 c2 0b 08 jp nz,loop_1 0815 21 00 0b ld hl,0x0B00 ;start of test loop 0818 3a a2 08 loop_2: ld a,(test_byte_0) 081b be cp (hl) 081c c2 50 08 jp nz,done_error_0 081f 23 inc hl 0820 7c ld a,h 0821 b5 or l 0822 c2 18 08 jp nz,loop_2 0825 3e ff ld a,0xff ;second test pattern 0827 32 a2 08 ld (test_byte_0),a ;store 082a 21 00 0b ld hl,0x0B00 ;start of test, config 0 082d 3a a2 08 loop_3: ld a,(test_byte_0) ;get test byte 0830 77 ld (hl),a ;store test byte 0831 23 inc hl ;inc counter 0832 7c ld a,h ;need to test for zero this way 0833 b5 or l 0834 c2 2d 08 jp nz,loop_3 0837 21 00 0b ld hl,0x0B00 ;start of test loop 083a 3a a2 08 loop_4: ld a,(test_byte_0) 083d be cp (hl) 083e c2 50 08 jp nz,done_error_0 0841 23 inc hl 0842 7c ld a,h 0843 b5 or l 0844 c2 3a 08 jp nz,loop_4 0847 21 de 08 ld hl,done_configuration_0 084a cd 18 00 call write_string 084d c3 f9 08 jp configuration_1 0850 22 a0 08 done_error_0: ld (current_location_0),hl 0853 21 ae 08 ld hl,error_msg_0 0856 cd 18 00 call write_string 0859 3a a1 08 ld a,(current_location_0+1) ;msb of address 085c 21 a3 08 ld hl, location_string_0 085f cd 88 00 call byte_to_hex_string 0862 3a a0 08 ld a,(current_location_0) ;lsb of address 0865 21 a5 08 ld hl,location_string_0+2 0868 cd 88 00 call byte_to_hex_string 086b 2a a0 08 ld hl,(current_location_0) 086e 7e ld a,(hl) 086f 21 a8 08 ld hl,contents_string_0 0872 cd 88 00 call byte_to_hex_string 0875 3a a2 08 ld a,(test_byte_0) 0878 21 ab 08 ld hl,test_byte_string_0 087b cd 88 00 call byte_to_hex_string 087e 21 a3 08 ld hl,location_string_0 0881 cd 18 00 call write_string 0884 3e 20 ld a,0x20 ;space char 0886 cd 0c 00 call write_char 0889 21 a8 08 ld hl,contents_string_0 088c cd 18 00 call write_string 088f 3e 20 ld a,0x20 0891 cd 0c 00 call write_char 0894 21 ab 08 ld hl,test_byte_string_0 0897 cd 18 00 call write_string 089a cd 89 02 call write_newline 089d c3 6f 04 jp monitor_warm_start 08a0 00 00 current_location_0: dw 0x0000 ;current memory location being tested 08a2 00 test_byte_0: db 0x00 08a3 00 00 00 00 00 location_string_0: db 0,0,0,0,0 ;will be address of memory error 08a8 00 00 00 contents_string_0: db 0,0,0 08ab 00 00 00 test_byte_string_0: db 0,0,0 08ae .. 00 error_msg_0: db "Error: memory contents do not match test byte: ",0 08de .. 00 done_configuration_0: db "Configuration 0 test OK.\r\n",0 08f9 ; 08f9 ;Switch to configuration 1, test memory from 0x0000 to 0x09FF 08f9 ; 08f9 ;Code to move to higher memory 08f9 ; 08f9 21 07 09 configuration_1: ld hl,code_origin ;start of code to transfer 08fc 01 2d 01 ld bc,code_end-code_start+1 ;length of code to transfer 08ff 11 00 0b ld de,0x0B00 ;target of transfer 0902 ed b0 ldir ;Z80 transfer instruction 0904 c3 00 0b jp 0x0B00 0907 code_origin: ;address of first byte of code before transfer 0907 ; 0907 org 0x0B00 0b00 code_start: 0b00 d3 01 out (1),a ;switch to configuration 1 0b02 3e 00 ld a,0x00 ;first test pattern 0b04 32 b2 0b ld (test_byte_1),a ;store 0b07 21 00 00 ld hl,0x0000 ;start of test, config 1 0b0a 3a b2 0b loop_5: ld a,(test_byte_1) ;get test byte 0b0d 77 ld (hl),a ;store test byte 0b0e 23 inc hl ;inc counter 0b0f 7c ld a,h 0b10 fe 0b cp 0x0B ;MSB of space to test 0b12 c2 0a 0b jp nz,loop_5 0b15 21 00 00 ld hl,0x0000 ;start of test loop 0b18 3a b2 0b loop_6: ld a,(test_byte_1) 0b1b be cp (hl) 0b1c c2 4d 0b jp nz,done_error_1 0b1f 23 inc hl 0b20 7c ld a,h 0b21 fe 0b cp 0x0B 0b23 c2 18 0b jp nz,loop_6 0b26 3e ff ld a,0xff ;second test pattern 0b28 32 b2 0b ld (test_byte_1),a ;store 0b2b 21 00 00 ld hl,0x0000 ;start of test, config 1 0b2e 3a b2 0b loop_7: ld a,(test_byte_1) ;get test byte 0b31 77 ld (hl),a ;store test byte 0b32 23 inc hl ;inc counter 0b33 7c ld a,h 0b34 fe 0b cp 0x0B 0b36 c2 2e 0b jp nz,loop_7 0b39 21 00 00 ld hl,0x0000 ;start of test loop 0b3c 3a b2 0b loop_8: ld a,(test_byte_1) 0b3f be cp (hl) 0b40 c2 4d 0b jp nz,done_error_1 0b43 23 inc hl 0b44 7c ld a,h 0b45 fe 0b cp 0x0B 0b47 c2 3c 0b jp nz,loop_8 0b4a c3 9f 0b jp done_success 0b4d d3 00 done_error_1: out (0),a 0b4f 22 b0 0b ld (current_location_1),hl 0b52 21 fc 0b ld hl,error_msg_1 0b55 cd 18 00 call write_string 0b58 3a b1 0b ld a,(current_location_1+1) ;msb of address 0b5b 21 b3 0b ld hl, location_string_1 0b5e cd 88 00 call byte_to_hex_string 0b61 3a b0 0b ld a,(current_location_1) ;lsb of address 0b64 21 b5 0b ld hl,location_string_1+2 0b67 cd 88 00 call byte_to_hex_string 0b6a 2a b0 0b ld hl,(current_location_1) 0b6d 7e ld a,(hl) 0b6e 21 b8 0b ld hl,contents_string_1 0b71 cd 88 00 call byte_to_hex_string 0b74 3a b2 0b ld a,(test_byte_1) 0b77 21 bb 0b ld hl,test_byte_string_1 0b7a cd 88 00 call byte_to_hex_string 0b7d 21 b3 0b ld hl,location_string_1 0b80 cd 18 00 call write_string 0b83 3e 20 ld a,0x20 ;space char 0b85 cd 0c 00 call write_char 0b88 21 b8 0b ld hl,contents_string_1 0b8b cd 18 00 call write_string 0b8e 3e 20 ld a,0x20 0b90 cd 0c 00 call write_char 0b93 21 bb 0b ld hl,test_byte_string_1 0b96 cd 18 00 call write_string 0b99 cd 89 02 call write_newline 0b9c c3 6f 04 jp monitor_warm_start 0b9f d3 00 done_success: out (0),a 0ba1 21 be 0b ld hl,done_configuration_1 0ba4 cd 18 00 call write_string 0ba7 21 d9 0b ld hl,success_msg 0baa cd 18 00 call write_string 0bad c3 6f 04 jp monitor_warm_start 0bb0 00 00 current_location_1: dw 0x0000 ;current memory location being tested 0bb2 00 test_byte_1: db 0x00 0bb3 00 00 00 00 00 location_string_1: db 0,0,0,0,0 ;will be address of memory error 0bb8 00 00 00 contents_string_1: db 0,0,0 0bbb 00 00 00 test_byte_string_1: db 0,0,0 0bbe .. 00 done_configuration_1: db "Configuration 1 test OK.\r\n",0 0bd9 .. 00 success_msg: db "Memory test complete, no errors.\r\n",0 0bfc .. 00 error_msg_1: db "Error: memory contents do not match test byte: ",0 0c2c code_end: 0c2c end # End of file memory_test.asm 0c2c