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 8

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 8 gdevic
; Several options on which values we want to dump, uncomment only one:
136 3 gdevic
    ld  hl, text+5
137 8 gdevic
;   ld  a,(stack+1)     ; Dump stack pointer (useful to check SP)
138
    ld  a, i            ; Show IR register
139 3 gdevic
    call tohex
140
    ld  hl, text+7
141 8 gdevic
;   ld  a,(stack)       ; Dump stack pointer (useful to check SP)
142
    ld  a, r            ; Show IR register
143 3 gdevic
    call tohex
144
 
145
; Two versions of the code: either keep printing the text indefinitely (which
146
; can be used for interrupt testing), or print it only once and die
147
die:
148
    jr exec
149
;    jr die
150
 
151
tohex:
152
    ; HL = Address to store a hex value
153
    ; A  = Hex value 00-FF
154
    push af
155
    and  a,0fh
156
    cmp  a,10
157
    jc   skip1
158
    add  a, 'A'-'9'-1
159
skip1:
160
    add  a, '0'
161
    inc  hl
162
    ld   (hl),a
163
    dec  hl
164
    pop  af
165
    rra
166
    rra
167
    rra
168
    rra
169
    and  a,0fh
170
    cmp  a,10
171
    jc   skip2
172
    add  a, 'A'-'9'-1
173
skip2:
174
    add  a, '0'
175
    ld   (hl),a
176
    ret
177
 
178
; Print a counter before Hello, World so we can see if the
179
; processor rebooted during one of the interrupts. Also, print the content
180
; of the SP register which should stay fixed and "uninterrupted"
181
counter: dw 0
182
stack: dw 0
183
 
184
hello:
185
    db  13,10
186
text:
187 8 gdevic
    db '---- ---- Hello, World!$'
188
 
189 3 gdevic
end

powered by: WebSVN 2.1.0

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