OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [tools/] [zmac/] [hello_world.asm] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 gdevic
;==============================================================================
2
; Test code for the A-Z80 CPU that prints "Hello, World!"
3
; Also used to test responses to interrupts.
4
;==============================================================================
5
    org 0
6
start:
7
    jmp boot
8
 
9
    ; BDOS entry point for various functions
10
    ; We implement subfunctions:
11
    ;  C=2  Print a character given in E
12
    ;  C=9  Print a string pointed to by DE; string ends with '$'
13
    org 5
14
    ld  a,c
15
    cp  a,2
16
    jz  bdos_ascii
17
    cp  a,9
18
    jz  bdos_msg
19
    ret
20
 
21
bdos_ascii:
22
    ld  bc,10*256   ; Port to check for busy
23
    in  a,(c)       ; Poll until the port is not busy
24
    bit 0,a
25
    jnz bdos_ascii
26
    ld  bc,8*256    ; Port to write a character out
27
    out (c),e
28
    ret
29
 
30
bdos_msg:
31
    push de
32
    pop hl
33
lp0:
34
    ld  e,(hl)
35
    ld  a,e
36
    cp  a,'$'
37
    ret z
38
    call bdos_ascii
39
    inc hl
40
    jmp lp0
41
 
42
;---------------------------------------------------------------------
43
; RST38 (also INT M0)  handler
44
;---------------------------------------------------------------------
45
    org 038h
46
    push de
47
    ld  de,int_msg
48
int_common:
49
    push af
50
    push bc
51
    push hl
52
    ld  c,9
53
    call 5
54
    pop hl
55
    pop bc
56
    pop af
57
    pop de
58
    ei
59
    reti
60
int_msg:
61
    db  "_INT_",'$'
62
 
63
;---------------------------------------------------------------------
64
; NMI handler
65
;---------------------------------------------------------------------
66
    org 066h
67
    push af
68
    push bc
69
    push de
70
    push hl
71
    ld  de,nmi_msg
72
    ld  c,9
73
    call 5
74
    pop hl
75
    pop de
76
    pop bc
77
    pop af
78
    retn
79
nmi_msg:
80
    db  "_NMI_",'$'
81
 
82
;---------------------------------------------------------------------
83
; IM2 vector address and the handler (to push 0x80 by the IORQ)
84
;---------------------------------------------------------------------
85
    org 080h
86
    dw  im2_handler
87
im2_handler:
88
    push de
89
    ld  de,int_im2_msg
90
    jmp int_common
91
int_im2_msg:
92
    db  "_IM2_",'$'
93
boot:
94
    ; Set the stack pointer
95
    ld  sp, 16384    ; 16 Kb of RAM
96
    ; Set up for interrupt testing: see Z80\cpu\toplevel\test_top.sv
97
    ; IMPORTANT: To test IM0, Verilog test code needs to put 0xFF on the bus
98
    ;            To test IM2, the test code needs to put a vector of 0x80 !!
99
    ;            This is done in tb_iorq.sv
100
    im  2
101
    ld  a,0
102
    ld  i,a
103
    ei
104
    ;halt
105
    ; Jump into the executable at 100h
106
    jmp 100h
107
 
108
;==============================================================================
109
;
110
; Prints "Hello, World!"
111
;
112
;==============================================================================
113
    org 100h
114
    ld  hl,0
115
    ld  (counter),hl
116
exec:
117
    ld  de,hello
118
    ld  c,9
119
    call 5
120
 
121
    ; Print the counter and the stack pointer to make sure it does not change
122
    ld  hl, (counter)
123
    inc hl
124
    ld  (counter),hl
125
 
126
    ld  hl, text
127
    ld  a,(counter+1)
128
    call tohex
129
    ld  hl, text+2
130
    ld  a,(counter)
131
    call tohex
132
 
133
    ld  (stack),sp
134
 
135
    ld  hl, text+5
136
    ld  a,(stack+1)
137
    call tohex
138
    ld  hl, text+7
139
    ld  a,(stack)
140
    call tohex
141
 
142
; Two versions of the code: either keep printing the text indefinitely (which
143
; can be used for interrupt testing), or print it only once and die
144
die:
145
    jr exec
146
;    jr die
147
 
148
tohex:
149
    ; HL = Address to store a hex value
150
    ; A  = Hex value 00-FF
151
    push af
152
    and  a,0fh
153
    cmp  a,10
154
    jc   skip1
155
    add  a, 'A'-'9'-1
156
skip1:
157
    add  a, '0'
158
    inc  hl
159
    ld   (hl),a
160
    dec  hl
161
    pop  af
162
    rra
163
    rra
164
    rra
165
    rra
166
    and  a,0fh
167
    cmp  a,10
168
    jc   skip2
169
    add  a, 'A'-'9'-1
170
skip2:
171
    add  a, '0'
172
    ld   (hl),a
173
    ret
174
 
175
; Print a counter before Hello, World so we can see if the
176
; processor rebooted during one of the interrupts. Also, print the content
177
; of the SP register which should stay fixed and "uninterrupted"
178
counter: dw 0
179
stack: dw 0
180
 
181
hello:
182
    db  13,10
183
text:
184
    db '0000 0000 Hello, World!',13,10,'$'
185
end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.