My code works fine in ROM. All my code does is display some text and then accept text from the keyboard and echos it via teraterm.
My memory map is as follows:
0000H-7FFFH ROM
8000H-FFFFH RAM
Teraterm Output:
**** WELCOME TO 8085 BASIC V1 ****
32K ROM, 32K RAM SYSTEM, 32768 BASIC BYTES FREE
READY.
abc123
abc123
I tried to use some entry points in ROM for char in and out routines in a program I placed in RAM but it doesn't work, it just reboots my 8085 computer? I jump to the ram code from the rom code:
Fragment of ROM CODE:
Code: Select all
.
.
.
LXI H, WELCOME_MSG
CALL PRINT_STRING
BASIC_CMD_LOOP:
LXI H, READY_MSG
CALL PRINT_STRING
CALL READ_LINE
LXI H,9000H
CALL PRINT_STRING
JMP 8000H
.
.
.
Teraterm Output:
**** WELCOME TO 8085 BASIC V1 ****
32K ROM, 32K RAM SYSTEM, 32768 BASIC BYTES FREE
READY.
Details:
World2.c
Code: Select all
#include <stdio.h>
int main()
{
printf("Hello from z88dk!\n");
while ( 1 ) {
int c = getchar();
printf("<%c>=%d ", c,c);
}
}
Code: Select all
#include <stdio.h>
int fputc_cons_native(char c) __naked
{
__asm
pop b ;return address
pop h ;character to print in l
push h
push b
MOV a,l
call $00D0
ret
__endasm;
}
int fgetc_cons() __naked
{
__asm
call $00FB
mov l,a ;Return the result in hl
mvi h,0
ret
__endasm;
}
Code: Select all
zcc +z80 -clib=8085 world2.c mon2.c -pragma-define:CRT_ORG_CODE=0x8000 -pragma-define:CRT_ORG_BSS=0x8000 -pragma-define:REGISTER_SP=0xFFFE -create-app -m8085
Code: Select all
z88dk-dis -o 0x8000 -x a.map a.rom
ld sp,$fffe ;[8000] 31 fe ff
ld hl,$ffc0 ;[8003] 21 c0 ff
add hl,sp ;[8006] 39
ld sp,hl ;[8007] f9
call $8025 ;[8008] cd 25 80
ld hl,$0000 ;[800b] 21 00 00
add hl,sp ;[800e] 39
ld ($8067),hl ;[800f] 22 67 80
call $8127 ;[8012] cd 27 81
call $8057 ;[8015] cd 57 80
halt ;[8018] 76
jp $8018 ;[8019] c3 18 80
jp (hl) ;[801c] e9
ld h,h ;[801d] 64
daa ;[801e] 27
add d ;[801f] 82
ld h,e ;[8020] 63
dec de ;[8021] 1b
add d ;[8022] 82
nop ;[8023] 00
nop ;[8024] 00
xor a ;[8025] af
ld hl,$8000 ;[8026] 21 00 80
ld bc,$006c ;[8029] 01 6c 00
inc b ;[802c] 04
inc c ;[802d] 0c
ld (hl),a ;[802e] 77
inc hl ;[802f] 23
dec c ;[8030] 0d
jp nz,$802e ;[8031] c2 2e 80
dec b ;[8034] 05
jp nz,$802e ;[8035] c2 2e 80
ld ($8069),a ;[8038] 32 69 80
ld hl,$8003 ;[803b] 21 03 80
ld (hl),$13 ;[803e] 36 13
ld hl,$800d ;[8040] 21 0d 80
ld (hl),$15 ;[8043] 36 15
ld hl,$8017 ;[8045] 21 17 80
ld (hl),$15 ;[8048] 36 15
ld hl,$85f0 ;[804a] 21 f0 85
ld de,$806c ;[804d] 11 6c 80
ld bc,$0001 ;[8050] 01 01 00
call $85b9 ;[8053] cd b9 85
ret ;[8056] c9
ret ;[8057] c9
ld a,l ;[8058] 7d
cpl ;[8059] 2f
ld l,a ;[805a] 6f
ld a,h ;[805b] 7c
cpl ;[805c] 2f
ld h,a ;[805d] 67
ld a,e ;[805e] 7b
cpl ;[805f] 2f
ld e,a ;[8060] 5f
ld a,d ;[8061] 7a
cpl ;[8062] 2f
ld d,a ;[8063] 57
inc l ;[8064] 2c
ret nz ;[8065] c0
inc h ;[8066] 24
ret nz ;[8067] c0
inc de ;[8068] 13
ret ;[8069] c9
ld a,d ;[806a] 7a
or e ;[806b] b3
or h ;[806c] b4
or l ;[806d] b5
jp z,$8095 ;[806e] ca 95 80
push de ;[8071] d5
push hl ;[8072] e5
ld bc,$0000 ;[8073] 01 00 00
push bc ;[8076] c5
push bc ;[8077] c5
push bc ;[8078] c5
call $809f ;[8079] cd 9f 80
jr c,$808c ;[807c] 38 0e
neg ;[807e] ed 44
ld c,l ;[8080] 4d
jr c,$808d ;[8081] 38 0a
nop ;[8083] ed 38
ld c,$d9 ;[8085] 0e d9
jr c,$808b ;[8087] 38 02
ld a,(de) ;[8089] 1a
jr c,$8098 ;[808a] 38 0c
nop ;[808c] ed 38
ld c,$eb ;[808e] 0e eb
ld sp,hl ;[8090] f9
ex de,hl ;[8091] eb
ld d,b ;[8092] 50
ld e,c ;[8093] 59
ret ;[8094] c9
pop bc ;[8095] c1
pop hl ;[8096] e1
pop de ;[8097] d1
push bc ;[8098] c5
ld de,$ffff ;[8099] 11 ff ff
ld h,d ;[809c] 62
ld l,e ;[809d] 6b
ret ;[809e] c9
ld b,$20 ;[809f] 06 20
jr c,$80b1 ;[80a1] 38 0e
ld a,(de) ;[80a3] 1a
rla ;[80a4] 17
ld (de),a ;[80a5] 12
inc de ;[80a6] 13
ld a,(de) ;[80a7] 1a
rla ;[80a8] 17
ld (de),a ;[80a9] 12
inc de ;[80aa] 13
ld a,(de) ;[80ab] 1a
rla ;[80ac] 17
ld (de),a ;[80ad] 12
inc de ;[80ae] 13
ld a,(de) ;[80af] 1a
rla ;[80b0] 17
ld (de),a ;[80b1] 12
jr c,$80b8 ;[80b2] 38 04
ld a,(de) ;[80b4] 1a
rla ;[80b5] 17
ld (de),a ;[80b6] 12
inc de ;[80b7] 13
ld a,(de) ;[80b8] 1a
rla ;[80b9] 17
ld (de),a ;[80ba] 12
inc de ;[80bb] 13
ld a,(de) ;[80bc] 1a
rla ;[80bd] 17
ld (de),a ;[80be] 12
inc de ;[80bf] 13
ld a,(de) ;[80c0] 1a
rla ;[80c1] 17
ld (de),a ;[80c2] 12
jr c,$80cd ;[80c3] 38 08
ex de,hl ;[80c5] eb
jr c,$80cc ;[80c6] 38 04
ld a,(de) ;[80c8] 1a
sub (hl) ;[80c9] 96
inc de ;[80ca] 13
inc hl ;[80cb] 23
ld a,(de) ;[80cc] 1a
sbc (hl) ;[80cd] 9e
inc de ;[80ce] 13
inc hl ;[80cf] 23
ld a,(de) ;[80d0] 1a
sbc (hl) ;[80d1] 9e
inc de ;[80d2] 13
inc hl ;[80d3] 23
ld a,(de) ;[80d4] 1a
sbc (hl) ;[80d5] 9e
jp c,$80f0 ;[80d6] da f0 80
jr c,$80e3 ;[80d9] 38 08
ex de,hl ;[80db] eb
jr c,$80e2 ;[80dc] 38 04
ld a,(de) ;[80de] 1a
sub (hl) ;[80df] 96
ld (de),a ;[80e0] 12
inc de ;[80e1] 13
inc hl ;[80e2] 23
ld a,(de) ;[80e3] 1a
sbc (hl) ;[80e4] 9e
ld (de),a ;[80e5] 12
inc de ;[80e6] 13
inc hl ;[80e7] 23
ld a,(de) ;[80e8] 1a
sbc (hl) ;[80e9] 9e
ld (de),a ;[80ea] 12
inc de ;[80eb] 13
inc hl ;[80ec] 23
ld a,(de) ;[80ed] 1a
sbc (hl) ;[80ee] 9e
ld (de),a ;[80ef] 12
ccf ;[80f0] 3f
dec b ;[80f1] 05
jp nz,$80a1 ;[80f2] c2 a1 80
jr c,$8105 ;[80f5] 38 0e
ld a,(de) ;[80f7] 1a
rla ;[80f8] 17
ld (de),a ;[80f9] 12
inc de ;[80fa] 13
ld a,(de) ;[80fb] 1a
rla ;[80fc] 17
ld (de),a ;[80fd] 12
inc de ;[80fe] 13
ld a,(de) ;[80ff] 1a
rla ;[8100] 17
ld (de),a ;[8101] 12
inc de ;[8102] 13
ld a,(de) ;[8103] 1a
rla ;[8104] 17
ld (de),a ;[8105] 12
ret ;[8106] c9
ld de,$0000 ;[8107] 11 00 00
ld a,h ;[810a] 7c
rlca ;[810b] 07
ret nc ;[810c] d0
dec de ;[810d] 1b
ret ;[810e] c9
ld a,h ;[810f] 7c
add $80 ;[8110] c6 80
ld b,a ;[8112] 47
ld a,d ;[8113] 7a
add $80 ;[8114] c6 80
cp b ;[8116] b8
ccf ;[8117] 3f
jp nz,$8121 ;[8118] c2 21 81
ld a,e ;[811b] 7b
cp l ;[811c] bd
ccf ;[811d] 3f
jp $8121 ;[811e] c3 21 81
ld hl,$0000 ;[8121] 21 00 00
ret nc ;[8124] d0
inc hl ;[8125] 23
ret ;[8126] c9
ld hl,$85d4 ;[8127] 21 d4 85
push hl ;[812a] e5
ld a,$01 ;[812b] 3e 01
call $8596 ;[812d] cd 96 85
pop bc ;[8130] c1
ld hl,$8001 ;[8131] 21 01 80
push hl ;[8134] e5
call $8162 ;[8135] cd 62 81
pop bc ;[8138] c1
ex de,hl ;[8139] eb
ld hl,$85e7 ;[813a] 21 e7 85
push de ;[813d] d5
push hl ;[813e] e5
ex de,hl ;[813f] eb
push hl ;[8140] e5
jr c,$8147 ;[8141] 38 04
nop ;[8143] ed e5
ld a,$03 ;[8145] 3e 03
call $8596 ;[8147] cd 96 85
pop bc ;[814a] c1
pop bc ;[814b] c1
pop bc ;[814c] c1
pop bc ;[814d] c1
jp $8131 ;[814e] c3 31 81
ret ;[8151] c9
pop bc ;[8152] c1
pop hl ;[8153] e1
push hl ;[8154] e5
push bc ;[8155] c5
ld a,l ;[8156] 7d
[b] call $00d0 [/b] ;[8157] cd d0 00
ret ;[815a] c9
[b]call $00fb[/b] ;[815b] cd fb 00
ld l,a ;[815e] 6f
ld h,$00 ;[815f] 26 00
ret ;[8161] c9
pop bc ;[8162] c1
pop de ;[8163] d1
push de ;[8164] d5
push bc ;[8165] c5
ld hl,$ffff ;[8166] 21 ff ff
inc de ;[8169] 13
inc de ;[816a] 13
ld a,(de) ;[816b] 1a
and a ;[816c] a7
ret z ;[816d] c8
.
.
.
Please assist.
Thanks, Andrew